diff --git a/app/Models/Client.php b/app/Models/Client.php index a58d7fb450c0..644124f4e70e 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -666,7 +666,7 @@ class Client extends BaseModel implements HasLocalePreference } } - if ($this->country && $this->country->iso_3166_3 == 'GBR' && in_array(GatewayType::DIRECT_DEBIT, array_column($pms, 'gateway_type_id'))) { + if (in_array(GatewayType::DIRECT_DEBIT, array_column($pms, 'gateway_type_id'))) { foreach ($pms as $pm) { if ($pm['gateway_type_id'] == GatewayType::DIRECT_DEBIT) { $cg = CompanyGateway::find($pm['company_gateway_id']); @@ -691,7 +691,7 @@ class Client extends BaseModel implements HasLocalePreference return GatewayType::SEPA; } - if ($this->currency()->code == 'GBP') { + if (in_array($this->currency()->code, ['EUR', 'GBP','DKK','SEK','AUD','NZD','USD'])) { return GatewayType::DIRECT_DEBIT; } } diff --git a/app/Models/Presenters/ClientPresenter.php b/app/Models/Presenters/ClientPresenter.php index 4a42cd2c1510..b0c30b107807 100644 --- a/app/Models/Presenters/ClientPresenter.php +++ b/app/Models/Presenters/ClientPresenter.php @@ -42,17 +42,17 @@ class ClientPresenter extends EntityPresenter public function first_name() { - return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name : $this->entity->contacts()->first()->first_name; + return $this->entity->primary_contact()->first()?->first_name ?: ($this->entity->contacts()->first()->first_name ?: ''); } public function last_name() { - return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->last_name : $this->entity->contacts()->first()->last_name; + return $this->entity->primary_contact()->first()?->last_name ?: ($this->entity->contacts()->first()->last_name ?: ''); } public function primary_contact_name() { - return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name.' '.$this->entity->primary_contact->first()->last_name : 'No primary contact set'; + return $this->entity?->primary_contact()?->first() ? $this->entity->primary_contact()->first()->first_name.' '.$this->entity->primary_contact()->first()->last_name : 'No primary contact set'; } public function email() diff --git a/app/PaymentDrivers/GoCardless/DirectDebit.php b/app/PaymentDrivers/GoCardless/DirectDebit.php index edb853ba3d85..2fec81223f84 100644 --- a/app/PaymentDrivers/GoCardless/DirectDebit.php +++ b/app/PaymentDrivers/GoCardless/DirectDebit.php @@ -67,6 +67,7 @@ class DirectDebit implements MethodInterface 'address_line1' => auth()->guard('contact')->user()->client->address1 ?: '', 'city' => auth()->guard('contact')->user()->client->city ?: '', 'postal_code' => auth()->guard('contact')->user()->client->postal_code ?: '', + 'country_code' => auth()->guard('contact')->user()->client->country->iso_3166_2, ], ], ]); @@ -124,7 +125,7 @@ class DirectDebit implements MethodInterface $data = [ 'payment_meta' => $payment_meta, 'token' => $redirect_flow->links->mandate, - 'payment_method_id' => GatewayType::DIRECT_DEBIT, + 'payment_method_id' => $this->resolveScheme($redirect_flow->scheme), ]; $payment_method = $this->go_cardless->storeGatewayToken($data, ['gateway_customer_reference' => $redirect_flow->links->customer]); @@ -135,6 +136,17 @@ class DirectDebit implements MethodInterface } } + private function resolveScheme(string $scheme): int + { + match($scheme){ + 'sepa_core' => $type = GatewayType::SEPA, + default => $type = GatewayType::DIRECT_DEBIT, + }; + + return $type; + } + + /** * Payment view for Direct Debit. * diff --git a/app/PaymentDrivers/GoCardless/SEPA.php b/app/PaymentDrivers/GoCardless/SEPA.php index df92a500b3a6..c4950314d491 100644 --- a/app/PaymentDrivers/GoCardless/SEPA.php +++ b/app/PaymentDrivers/GoCardless/SEPA.php @@ -62,12 +62,12 @@ class SEPA implements MethodInterface 'session_token' => $session_token, ]), 'prefilled_customer' => [ - 'given_name' => auth()->guard('contact')->user()->first_name, - 'family_name' => auth()->guard('contact')->user()->last_name, - 'email' => auth()->guard('contact')->user()->email, - 'address_line1' => auth()->guard('contact')->user()->client->address1, - 'city' => auth()->guard('contact')->user()->client->city, - 'postal_code' => auth()->guard('contact')->user()->client->postal_code, + 'given_name' => auth()->guard('contact')->user()->client->present()->first_name(), + 'family_name' => auth()->guard('contact')->user()->client->present()->last_name(), + 'email' => auth()->guard('contact')->user()->client->present()->email(), + 'address_line1' => auth()->guard('contact')->user()->client->address1 ?: '', + 'city' => auth()->guard('contact')->user()->client->city ?: '', + 'postal_code' => auth()->guard('contact')->user()->client->postal_code ?: '', ], ], ]); diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index 6b99492148c5..91d845997a3f 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -78,12 +78,13 @@ class GoCardlessPaymentDriver extends BaseDriver if ( $this->client && isset($this->client->country) - && in_array($this->client->country->iso_3166_3, ['GBR']) + // && in_array($this->client->country->iso_3166_3, ['GBR']) + && in_array($this->client->currency()->code, ['EUR', 'GBP','DKK','SEK','AUD','NZD','USD']) ) { $types[] = GatewayType::DIRECT_DEBIT; } - if (in_array($this->client->currency()->code, ['EUR'])) { + if (in_array($this->client->currency()->code, ['EUR', 'GBP'])) { $types[] = GatewayType::SEPA; } diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index 8f095ea22fa3..7f7d6c4933bc 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -197,7 +197,7 @@ class PaymentMethod 'gateway_type_id' => GatewayType::CREDIT, ]; } - + return $this; }