From 1e5faf2ecd5b06d57e27f2b130390abf54ff190a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 26 Sep 2024 13:19:01 +1000 Subject: [PATCH] Fixes for duplicate mollie requests --- app/Import/Transformer/Csv/InvoiceTransformer.php | 1 + app/PaymentDrivers/Mollie/IDEAL.php | 13 +++++++++++++ app/PaymentDrivers/MolliePaymentDriver.php | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Import/Transformer/Csv/InvoiceTransformer.php b/app/Import/Transformer/Csv/InvoiceTransformer.php index 50a85a0922..bd7d254307 100644 --- a/app/Import/Transformer/Csv/InvoiceTransformer.php +++ b/app/Import/Transformer/Csv/InvoiceTransformer.php @@ -36,6 +36,7 @@ class InvoiceTransformer extends BaseTransformer $invoiceStatusMap = [ 'sent' => Invoice::STATUS_SENT, 'draft' => Invoice::STATUS_DRAFT, + 'paid' => Invoice::STATUS_PAID, ]; $transformed = [ diff --git a/app/PaymentDrivers/Mollie/IDEAL.php b/app/PaymentDrivers/Mollie/IDEAL.php index 134853a6fe..5645a23e78 100644 --- a/app/PaymentDrivers/Mollie/IDEAL.php +++ b/app/PaymentDrivers/Mollie/IDEAL.php @@ -176,6 +176,19 @@ class IDEAL implements MethodInterface, LivewireMethodInterface */ public function processSuccessfulPayment(\Mollie\Api\Resources\Payment $payment, string $status = 'paid'): RedirectResponse { + $p = \App\Models\Payment::query() + ->withTrashed() + ->where('company_id', $this->mollie->client->company_id) + ->where('transaction_reference', $payment->id) + ->first(); + + if($p) { + $p->status_id = Payment::STATUS_COMPLETED; + $p->save(); + + return redirect()->route('client.payments.show', ['payment' => $p->hashed_id]); + } + $data = [ 'gateway_type_id' => GatewayType::IDEAL, 'amount' => array_sum(array_column($this->mollie->payment_hash->invoices(), 'amount')) + $this->mollie->payment_hash->fee_total, diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index 8f98a2faeb..33e7fbb83c 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -287,7 +287,7 @@ class MolliePaymentDriver extends BaseDriver { // Allow app to catch up with webhook request. // sleep(4); - usleep(rand(2800000, 4000000)); + usleep(rand(1500000, 4000000)); $validator = Validator::make($request->all(), [ 'id' => ['required', 'starts_with:tr'],