From 0ba05bc985ecb28a28302f40145410ee4e3e8797 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 13:19:34 +1000 Subject: [PATCH] Update customer for stripe --- app/PaymentDrivers/Stripe/CreditCard.php | 3 +++ app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index c4939c889e4b..1b8525c2f8a1 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -20,6 +20,7 @@ use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\StripePaymentDriver; +use App\PaymentDrivers\Stripe\Jobs\UpdateCustomer; use Stripe\PaymentIntent; use Stripe\PaymentMethod; @@ -129,6 +130,8 @@ class CreditCard public function processSuccessfulPayment() { + UpdateCustomer::dispatch($this->stripe->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); + $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); $data = [ diff --git a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php index bc4fd8e9a234..46c8646f562b 100644 --- a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php +++ b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php @@ -44,21 +44,18 @@ class UpdateCustomer implements ShouldQueue private int $client_id; - private string $customer_id; - - public function __construct(string $company_key, int $company_gateway_id, int $client_id, string $customer_id) + public function __construct(string $company_key, int $company_gateway_id, int $client_id) { $this->company_key = $company_key; $this->company_gateway_id = $company_gateway_id; $this->client_id = $client_id; - $this->customer_id = $customer_id; } public function handle() { if($this->company->id !== config('ninja.ninja_default_company_id')) return; - + MultiDB::findAndSetDbByCompanyKey($this->company_key); $company = Company::where('company_key', $this->company_key)->first(); @@ -67,7 +64,7 @@ class UpdateCustomer implements ShouldQueue $stripe = $company_gateway->driver()->init(); - $customer = $company_gateway->getCustomer($this->customer_id); + $customer = $stripe->findOrCreateCustomer(); $client = Client::withTrashed()->find($this->client_id); @@ -82,7 +79,7 @@ class UpdateCustomer implements ShouldQueue $data['address']['state'] = $client->state; $data['address']['country'] = $client->country ? $client->country->iso_3166_2 : ''; - \Stripe\Customer::update($this->customer_id, $data, $stripe->stripe_connect_auth); + \Stripe\Customer::update($customer->id, $data, $stripe->stripe_connect_auth); } }