diff --git a/app/Livewire/BillingPortalPurchase.php b/app/Livewire/BillingPortalPurchase.php index 0a15710018c6..079a36325e80 100644 --- a/app/Livewire/BillingPortalPurchase.php +++ b/app/Livewire/BillingPortalPurchase.php @@ -188,6 +188,10 @@ class BillingPortalPurchase extends Component public ?string $contact_email; + public ?string $client_city; + + public ?string $client_postal_code; + public function mount() { MultiDB::setDb($this->db); @@ -203,7 +207,7 @@ class BillingPortalPurchase extends Component if (request()->query('coupon')) { $this->coupon = request()->query('coupon'); $this->handleCoupon(); - } elseif (strlen($this->subscription->promo_code) == 0 && $this->subscription->promo_discount > 0) { + } elseif (strlen($this->subscription->promo_code ?? '') == 0 && $this->subscription->promo_discount > 0) { $this->price = $this->subscription->promo_price; } @@ -335,10 +339,6 @@ class BillingPortalPurchase extends Component { $this->contact = $contact; - if ($contact->showRff()) { - return $this->rff(); - } - Auth::guard('contact')->loginUsingId($contact->id, true); if ($this->subscription->trial_enabled) { @@ -351,11 +351,20 @@ class BillingPortalPurchase extends Component if ((int)$this->price == 0) { $this->steps['payment_required'] = false; } else { - $this->steps['fetched_payment_methods'] = true; + // $this->steps['fetched_payment_methods'] = true; } $this->methods = $contact->client->service()->getPaymentMethods($this->price); + foreach($this->methods as $method){ + + if($method['is_paypal'] == '1' && !$this->steps['check_rff']){ + $this->rff(); + break; + } + + } + $this->heading_text = ctrans('texts.payment_methods'); return $this; @@ -366,6 +375,8 @@ class BillingPortalPurchase extends Component $this->contact_first_name = $this->contact->first_name; $this->contact_last_name = $this->contact->last_name; $this->contact_email = $this->contact->email; + $this->client_city = $this->contact->client->city; + $this->client_postal_code = $this->contact->client->postal_code; $this->steps['check_rff'] = true; @@ -377,13 +388,20 @@ class BillingPortalPurchase extends Component $validated = $this->validate([ 'contact_first_name' => ['required'], 'contact_last_name' => ['required'], + 'client_city' => ['required'], + 'client_postal_code' => ['required'], 'contact_email' => ['required', 'email'], ]); $this->contact->first_name = $validated['contact_first_name']; $this->contact->last_name = $validated['contact_last_name']; $this->contact->email = $validated['contact_email']; - $this->contact->save(); + $this->contact->client->postal_code = $validated['client_postal_code']; + $this->contact->client->city = $validated['client_city']; + + $this->contact->pushQuietly(); + + $this->steps['fetched_payment_methods'] = true; return $this->getPaymentMethods($this->contact); } @@ -395,13 +413,13 @@ class BillingPortalPurchase extends Component * @param $company_gateway_id * @param $gateway_type_id */ - public function handleMethodSelectingEvent($company_gateway_id, $gateway_type_id) + public function handleMethodSelectingEvent($company_gateway_id, $gateway_type_id, $is_paypal = false) { $this->company_gateway_id = $company_gateway_id; $this->payment_method_id = $gateway_type_id; $this->handleBeforePaymentEvents(); - + } /** diff --git a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php index 56824c840269..e7f6fe01c145 100644 --- a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php +++ b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php @@ -251,11 +251,11 @@ class PayPalBasePaymentDriver extends BaseDriver [ "address" => [ - "address_line_1" => strlen($this->client->shipping_address1) > 1 ? $this->client->shipping_address1 : $this->client->address1, + "address_line_1" => strlen($this->client->shipping_address1 ?? '') > 1 ? $this->client->shipping_address1 : $this->client->address1, "address_line_2" => $this->client->shipping_address2, - "admin_area_2" => strlen($this->client->shipping_city) > 1 ? $this->client->shipping_city : $this->client->city, - "admin_area_1" => strlen($this->client->shipping_state) > 1 ? $this->client->shipping_state : $this->client->state, - "postal_code" => strlen($this->client->shipping_postal_code) > 1 ? $this->client->shipping_postal_code : $this->client->postal_code, + "admin_area_2" => strlen($this->client->shipping_city ?? '') > 1 ? $this->client->shipping_city : $this->client->city, + "admin_area_1" => strlen($this->client->shipping_state ?? '') > 1 ? $this->client->shipping_state : $this->client->state, + "postal_code" => strlen($this->client->shipping_postal_code ?? '') > 1 ? $this->client->shipping_postal_code : $this->client->postal_code, "country_code" => $this->client->present()->shipping_country_code(), ], ] diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index da88156c8d70..af1ea653f64e 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -88,7 +88,7 @@ class SubscriptionService // if we have a recurring product - then generate a recurring invoice - if (strlen($this->subscription->recurring_product_ids) >= 1) { + if (strlen($this->subscription->recurring_product_ids ?? '') >= 1) { if (isset($payment_hash->data->billing_context->bundle)) { $recurring_invoice = $this->convertInvoiceToRecurringBundle($payment_hash->payment->client_id, $payment_hash->data->billing_context->bundle); } else { @@ -1024,10 +1024,10 @@ class SubscriptionService $invoice->subscription_id = $this->subscription->id; $invoice->is_proforma = true; - if (strlen($data['coupon']) >= 1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0) { + if (strlen($data['coupon'] ?? '') >= 1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0) { $invoice->discount = $this->subscription->promo_discount; $invoice->is_amount_discount = $this->subscription->is_amount_discount; - } elseif (strlen($this->subscription->promo_code) == 0 && $this->subscription->promo_discount > 0) { + } elseif (strlen($this->subscription->promo_code ?? '') == 0 && $this->subscription->promo_discount > 0) { $invoice->discount = $this->subscription->promo_discount; $invoice->is_amount_discount = $this->subscription->is_amount_discount; } @@ -1118,7 +1118,7 @@ class SubscriptionService */ public function triggerWebhook($context) { - if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url']) < 1) { //@phpstan-ignore-line + if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url'] ?? '') < 1) { //@phpstan-ignore-line return ["message" => "Success", "status_code" => 200]; } @@ -1436,7 +1436,7 @@ class SubscriptionService */ public function handleNoPaymentFlow(Invoice $invoice, $bundle, ClientContact $contact) { - if (strlen($this->subscription->recurring_product_ids) >= 1) { + if (strlen($this->subscription->recurring_product_ids ?? '') >= 1) { $recurring_invoice = $this->convertInvoiceToRecurringBundle($contact->client_id, collect($bundle)->map(function ($bund) { return (object) $bund; })); @@ -1492,7 +1492,7 @@ class SubscriptionService */ private function handleRedirect($default_redirect) { - if (array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url']) >= 1) { + if (array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url'] ?? '') >= 1) { return method_exists(redirect(), "send") ? redirect($this->subscription->webhook_configuration['return_url'])->send() : redirect($this->subscription->webhook_configuration['return_url']); } 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 3c97e48959be..4af98edc0409 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 @@ -141,12 +141,15 @@ + + + @if($steps['started_payment'] == false) @foreach($this->methods as $method) @@ -189,27 +192,41 @@
@csrf - @if(strlen($contact->first_name) === 0) + @if(strlen($contact->first_name ?? '') === 0)
@endif - @if(strlen($contact->last_name) === 0) + @if(strlen($contact->last_name ?? '') === 0) @endif - @if(strlen($contact->email) === 0) + @if(strlen($contact->email ?? '') === 0) @endif + @if(strlen($client_postal_code ?? '') === 0) + + @endif + + @if(strlen($client_city ?? '') === 0) + + @endif + diff --git a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php index 91520780ad8c..b67881b60065 100644 --- a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php @@ -83,7 +83,7 @@ @if(!$state['payment_initialised']) @foreach($this->methods as $method)