From 308e938ce093463cd6e168bd6f95591f134cac53 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 19 Feb 2023 11:32:40 +1100 Subject: [PATCH] Import PM's that are us_bank_accounts --- .../Stripe/UpdatePaymentMethods.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php index c52a43ea63bf..70f01f81cbba 100644 --- a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php +++ b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php @@ -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)