1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Minor changes for GoCardless

This commit is contained in:
David Bomba 2023-03-18 09:56:03 +11:00
parent f5e582f75b
commit 9ca10fadb3
6 changed files with 28 additions and 15 deletions

View File

@ -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;
}
}

View File

@ -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()

View File

@ -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.
*

View File

@ -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 ?: '',
],
],
]);

View File

@ -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;
}

View File

@ -197,7 +197,7 @@ class PaymentMethod
'gateway_type_id' => GatewayType::CREDIT,
];
}
return $this;
}