From b71c4965e237d3989a0870e7d5498bf10e76c29c Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Tue, 26 Oct 2021 17:54:42 +0200 Subject: [PATCH 1/2] Fixes for Stripe Webhook --- app/PaymentDrivers/StripePaymentDriver.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 93cc87f8cd85..1c07e5d82895 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -519,7 +519,12 @@ class StripePaymentDriver extends BaseDriver ->where('transaction_reference', $transaction['id']) ->where('company_id', $request->getCompany()->id) ->first(); - + if (empty($payment)){ + $payment = Payment::query() + ->where('transaction_reference', $transaction['payment_intent']) + ->where('company_id', $request->getCompany()->id) + ->first(); + } if ($payment) { $payment->status_id = Payment::STATUS_COMPLETED; $payment->save(); @@ -540,7 +545,12 @@ class StripePaymentDriver extends BaseDriver ->where('transaction_reference', $transaction['id']) ->where('company_id', $request->getCompany()->id) ->first(); - + if (empty($payment)){ + $payment = Payment::query() + ->where('transaction_reference', $transaction['payment_intent']) + ->where('company_id', $request->getCompany()->id) + ->first(); + } if ($payment) { $payment->status_id = Payment::STATUS_COMPLETED; $payment->save(); From c259e25bb9998205bafaadfb4fd4664605aac7c2 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Wed, 27 Oct 2021 20:59:50 +0200 Subject: [PATCH 2/2] Updated query --- app/PaymentDrivers/StripePaymentDriver.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 1c07e5d82895..100be75dd9dc 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -516,15 +516,13 @@ class StripePaymentDriver extends BaseDriver foreach ($request->data as $transaction) { $payment = Payment::query() - ->where('transaction_reference', $transaction['id']) - ->where('company_id', $request->getCompany()->id) - ->first(); - if (empty($payment)){ - $payment = Payment::query() ->where('transaction_reference', $transaction['payment_intent']) ->where('company_id', $request->getCompany()->id) + ->where(function ($query) use ($transaction) { + $query->where('transaction_reference', $transaction['payment_intent']) + ->orWhere('transaction_reference', $transaction['id']); + }) ->first(); - } if ($payment) { $payment->status_id = Payment::STATUS_COMPLETED; $payment->save(); @@ -541,16 +539,14 @@ class StripePaymentDriver extends BaseDriver ], $this->stripe_connect_auth); if ($charge->captured) { - $payment = Payment::query() - ->where('transaction_reference', $transaction['id']) - ->where('company_id', $request->getCompany()->id) - ->first(); - if (empty($payment)){ $payment = Payment::query() ->where('transaction_reference', $transaction['payment_intent']) ->where('company_id', $request->getCompany()->id) + ->where(function ($query) use ($transaction) { + $query->where('transaction_reference', $transaction['payment_intent']) + ->orWhere('transaction_reference', $transaction['id']); + }) ->first(); - } if ($payment) { $payment->status_id = Payment::STATUS_COMPLETED; $payment->save();