From 44cd3692564399dd8cd0d582cf617f5e126852c1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 27 Nov 2022 17:15:16 +1100 Subject: [PATCH 1/5] Fixes for client number race conditions when importing stripe clients --- app/PaymentDrivers/Stripe/ImportCustomers.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 377d2d53d386..a6aacdcc0fe6 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -26,6 +26,7 @@ use App\PaymentDrivers\StripePaymentDriver; use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\MakesHash; +use Illuminate\Database\QueryException; use Stripe\Customer; use Stripe\PaymentMethod; @@ -37,6 +38,8 @@ class ImportCustomers /** @var StripePaymentDriver */ public $stripe; + private bool $completed = true; + public $update_payment_methods; public function __construct(StripePaymentDriver $stripe) @@ -132,10 +135,30 @@ class ImportCustomers $client->name = $customer->name ? $customer->name : $customer->email; if (! isset($client->number) || empty($client->number)) { - $client->number = $this->getNextClientNumber($client); - } - $client->save(); + $x = 1; + + do { + try { + $client->number = $this->getNextClientNumber($client); + $client->saveQuietly(); + + $this->completed = false; + } catch (QueryException $e) { + $x++; + + if ($x > 10) { + $this->completed = false; + } + } + } while ($this->completed); + + + + } + else{ + $client->save(); + } $contact = ClientContactFactory::create($client->company_id, $client->user_id); $contact->client_id = $client->id; From 85c40de5de6eb09fe99f3b5dc7e79db23ccaa8ad Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 27 Nov 2022 17:33:43 +1100 Subject: [PATCH 2/5] Return early if no hash found --- app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php b/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php index 6d781670cf0e..d7cab34fab4e 100644 --- a/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php +++ b/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php @@ -138,6 +138,9 @@ class PaymentIntentWebhook implements ShouldQueue $hash = isset($charge['metadata']['payment_hash']) ? $charge['metadata']['payment_hash'] : false; + if(!$hash) + return; + $payment_hash = PaymentHash::where('hash', $hash)->first(); if(!$payment_hash) From 26bb11d6e3f3a0138723fd8c92c48ee535d63ae4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 27 Nov 2022 17:39:10 +1100 Subject: [PATCH 3/5] Fixes for stripe importing customers --- app/PaymentDrivers/Stripe/ImportCustomers.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index a6aacdcc0fe6..5ca8ef65fbeb 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -67,10 +67,13 @@ class ImportCustomers } //handle - if(is_array($customers->data) && end($customers->data) && array_key_exists('id', end($customers->data))) - $starting_after = end($customers->data)['id']; - else - break; + // if(is_array($customers->data) && end($customers->data) && array_key_exists('id', end($customers->data))) + // $starting_after = end($customers->data)['id']; + // else + // break; + + $starting_after = end($customers->data)['id']; + } while ($customers->has_more); } From 1dffb04d8c775e14544bb460860c175b213e2098 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 27 Nov 2022 17:47:22 +1100 Subject: [PATCH 4/5] Fixes for breaking out of stripe import customers --- app/PaymentDrivers/Stripe/ImportCustomers.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 5ca8ef65fbeb..90d1eb83842f 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -72,8 +72,10 @@ class ImportCustomers // else // break; - $starting_after = end($customers->data)['id']; + $starting_after = isset(end($customers->data)['id']) ? end($customers->data)['id'] : false; + if(!$starting_after) + break; } while ($customers->has_more); } From b138630d39723587c294b2aad8cf5f707f4d801e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 27 Nov 2022 18:47:48 +1100 Subject: [PATCH 5/5] Wind back some changes for configuration: --- config/ninja.php | 3 +-- config/queue.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/config/ninja.php b/config/ninja.php index 45ec406ae11d..8583baa84408 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -211,5 +211,4 @@ return [ 'dev_mode' => env("YODLEE_DEV_MODE", false), 'config_name' => env("YODLEE_CONFIG_NAME", false), ], - 'dbs' => ['db-ninja-01','db-ninja-02'] -]; +]; \ No newline at end of file diff --git a/config/queue.php b/config/queue.php index 18666fc43454..412282299176 100644 --- a/config/queue.php +++ b/config/queue.php @@ -67,7 +67,7 @@ return [ 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), 'queue' => env('REDIS_QUEUE', 'default'), 'retry_after' => 90000000, - 'block_for' => 1, + 'block_for' => null, 'after_commit' => false, ],