Import PM's that are us_bank_accounts

This commit is contained in:
David Bomba 2023-02-19 11:32:40 +11:00
parent 4739bd3dc7
commit 308e938ce0

View File

@ -74,6 +74,61 @@ class UpdatePaymentMethods
}
$this->importBankAccounts($customer, $client);
$this->importPMBankAccounts($customer, $client);
}
/* ACH may also be nested inside Payment Methods.*/
public function importPMBankAccounts($customer, $client)
{
$bank_methods = \Stripe\PaymentMethod::all(
[
'customer' => $customer->id,
'type' => 'us_bank_account',
],
$this->stripe->stripe_connect_auth
);
foreach($bank_methods->data as $method)
{
$token_exists = ClientGatewayToken::where([
'gateway_customer_reference' => $customer->id,
'token' => $method->id,
'client_id' => $client->id,
'company_id' => $client->company_id,
])->exists();
/* Already exists return */
if ($token_exists) {
continue;
}
$bank_account = $method['us_bank_account'];
$payment_meta = new \stdClass;
$payment_meta->brand = (string) \sprintf('%s (%s)', $bank_account->bank_name, ctrans('texts.ach'));
$payment_meta->last4 = (string) $bank_account->last4;
$payment_meta->type = GatewayType::BANK_TRANSFER;
$payment_meta->state = 'authorized';
$data = [
'payment_meta' => $payment_meta,
'token' => $method->id,
'payment_method_id' => GatewayType::BANK_TRANSFER,
];
$additional_data = ['gateway_customer_reference' => $customer->id];
if ($customer->default_source === $method->id) {
$additional_data = ['gateway_customer_reference' => $customer->id, 'is_default' => 1];
}
$this->stripe->storeGatewayToken($data, $additional_data);
}
}
public function importBankAccounts($customer, $client)