From 5a53a65e39ea32cb8ddb76c53221abffb8852bba Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 2 Nov 2024 08:34:27 +1100 Subject: [PATCH] Use idempotency keys for mollie payments to prevent race conditions --- app/PaymentDrivers/BaseDriver.php | 3 +++ app/PaymentDrivers/Mollie/IDEAL.php | 1 + app/PaymentDrivers/MolliePaymentDriver.php | 1 + 3 files changed, 5 insertions(+) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 7a1f9b0d38..206551f56d 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -329,6 +329,9 @@ class BaseDriver extends AbstractPaymentDriver $client_contact = $this->getContact(); $client_contact_id = $client_contact ? $client_contact->id : $this->client->contacts()->first()->id; + if(isset($data['idempotency_key'])) + $payment->idempotency_key = $data['idempotency_key']; + $payment->amount = $data['amount']; $payment->type_id = $data['payment_type']; $payment->transaction_reference = $data['transaction_reference']; diff --git a/app/PaymentDrivers/Mollie/IDEAL.php b/app/PaymentDrivers/Mollie/IDEAL.php index e9f115a871..88c9b35fe4 100644 --- a/app/PaymentDrivers/Mollie/IDEAL.php +++ b/app/PaymentDrivers/Mollie/IDEAL.php @@ -194,6 +194,7 @@ class IDEAL implements MethodInterface, LivewireMethodInterface 'amount' => array_sum(array_column($this->mollie->payment_hash->invoices(), 'amount')) + $this->mollie->payment_hash->fee_total, 'payment_type' => PaymentType::IDEAL, 'transaction_reference' => $payment->id, + 'idempotency_key' => substr("{$payment->id}{$this->mollie->payment_hash}",0,64) ]; $payment_record = $this->mollie->createPayment( diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index 33e7fbb83c..ae0abf7f49 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -336,6 +336,7 @@ class MolliePaymentDriver extends BaseDriver 'amount' => $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total, 'payment_type' => $payment->metadata->payment_type_id, 'transaction_reference' => $payment->id, + 'idempotency_key' => substr("{$payment->id}{$payment_hash->hash}",0,64) ]; $this->confirmGatewayFee($data);