diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index 1dbe75e65be5..546817e2eb44 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -15,6 +15,7 @@ use App\Factory\ClientFactory; use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; use App\Mail\ContactPasswordlessLogin; +use App\Models\Client; use App\Models\Subscription; use App\Models\ClientContact; use App\Models\Invoice; @@ -220,6 +221,16 @@ class BillingPortalPurchase extends Component 'settings' => [], ]; + foreach ($this->request_data as $field => $value) { + if (in_array($field, Client::$subscriptions_fillable)) { + $data[$field] = $value; + } + + if (in_array($field, ClientContact::$subscription_fillable)) { + $data['contacts'][0][$field] = $value; + } + } + if (array_key_exists('locale', $this->request_data)) { $request = $this->request_data; @@ -391,6 +402,10 @@ class BillingPortalPurchase extends Component public function render() { + if (array_key_exists('email', $this->request_data)) { + $this->email = $this->request_data['email']; + } + if ($this->contact instanceof ClientContact) { $this->getPaymentMethods($this->contact); } diff --git a/app/Models/Client.php b/app/Models/Client.php index f2bca1a2012c..dbb2b12ba8af 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -99,6 +99,36 @@ class Client extends BaseModel implements HasLocalePreference protected $touches = []; + /** + * Whitelisted fields for using from query parameters on subscriptions request. + * + * @var string[] + */ + public static $subscriptions_fillable = [ + 'assigned_user_id', + 'address1', + 'address2', + 'city', + 'state', + 'postal_code', + 'country_id', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'shipping_address1', + 'shipping_address2', + 'shipping_city', + 'shipping_state', + 'shipping_postal_code', + 'shipping_country_id', + 'payment_terms', + 'vat_number', + 'id_number', + 'public_notes', + 'phone', + ]; + public function getEntityType() { return self::class; @@ -614,7 +644,7 @@ class Client extends BaseModel implements HasLocalePreference public function recurring_invoice_filepath() { - return $this->company->company_key.'/'.$this->client_hash.'/recurring_invoices/'; + return $this->company->company_key.'/'.$this->client_hash.'/recurring_invoices/'; } public function company_filepath() diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 22e5d6817834..d1ab21970362 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -95,6 +95,21 @@ class ClientContact extends Authenticatable implements HasLocalePreference 'client_id', ]; + /** + * Whitelisted fields for using from query parameters on subscriptions request. + * + * @var string[] + */ + public static $subscription_fillable = [ + 'first_name', + 'last_name', + 'phone', + 'custom_value1', + 'custom_value2', + 'custom_value3', + 'custom_value4', + 'email', + ]; /* V2 type of scope diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index b404eaa164dd..645aa504c375 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -57,8 +57,7 @@

- {{ ctrans('texts.total') }} - : {{ \App\Utils\Number::formatMoney($price, $subscription->company) }} + {{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($price, $subscription->company) }} @if($steps['discount_applied']) {{ \App\Utils\Number::formatMoney($subscription->price, $subscription->company) }}