From ca2932862dfd9dfb46899b20a55edae1c2b74ba4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 30 Nov 2021 20:53:38 +1100 Subject: [PATCH] Fixes for mollie webhooks if a payment isn't created --- app/PaymentDrivers/Mollie/Bancontact.php | 4 +++- app/PaymentDrivers/Mollie/BankTransfer.php | 4 +++- app/PaymentDrivers/Mollie/CreditCard.php | 2 +- app/PaymentDrivers/Mollie/IDEAL.php | 4 +++- app/PaymentDrivers/Mollie/KBC.php | 4 +++- app/PaymentDrivers/MolliePaymentDriver.php | 22 ++++++++++++++++++++-- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/Mollie/Bancontact.php b/app/PaymentDrivers/Mollie/Bancontact.php index 0a9e26e6be2e..fa87eba8d9b1 100644 --- a/app/PaymentDrivers/Mollie/Bancontact.php +++ b/app/PaymentDrivers/Mollie/Bancontact.php @@ -86,7 +86,9 @@ class Bancontact implements MethodInterface 'webhookUrl' => $this->mollie->company_gateway->webhookUrl(), 'metadata' => [ 'client_id' => $this->mollie->client->hashed_id, - 'hash' => $this->mollie->payment_hash->hash + 'hash' => $this->mollie->payment_hash->hash, + 'gateway_type_id' => GatewayType::BANCONTACT, + 'payment_type_id' => PaymentType::BANCONTACT, ], ]); diff --git a/app/PaymentDrivers/Mollie/BankTransfer.php b/app/PaymentDrivers/Mollie/BankTransfer.php index 41ccb4b5eb58..42cbf8719b3b 100644 --- a/app/PaymentDrivers/Mollie/BankTransfer.php +++ b/app/PaymentDrivers/Mollie/BankTransfer.php @@ -89,7 +89,9 @@ class BankTransfer implements MethodInterface 'webhookUrl' => $this->mollie->company_gateway->webhookUrl(), 'metadata' => [ 'client_id' => $this->mollie->client->hashed_id, - 'hash' => $this->mollie->payment_hash->hash + 'hash' => $this->mollie->payment_hash->hash, + 'gateway_type_id' => GatewayType::BANK_TRANSFER, + 'payment_type_id' => PaymentType::MOLLIE_BANK_TRANSFER, ], ]); diff --git a/app/PaymentDrivers/Mollie/CreditCard.php b/app/PaymentDrivers/Mollie/CreditCard.php index 7efbd17c915c..8a6af3dd2daf 100644 --- a/app/PaymentDrivers/Mollie/CreditCard.php +++ b/app/PaymentDrivers/Mollie/CreditCard.php @@ -114,7 +114,7 @@ class CreditCard 'name' => $this->mollie->client->name, 'email' => $this->mollie->client->present()->email(), 'metadata' => [ - 'id' => $this->mollie->client->hashed_id, + 'id' => $this->mollie->client->hashed_id ], ]); diff --git a/app/PaymentDrivers/Mollie/IDEAL.php b/app/PaymentDrivers/Mollie/IDEAL.php index b3a4ccfa8747..1274087eb532 100644 --- a/app/PaymentDrivers/Mollie/IDEAL.php +++ b/app/PaymentDrivers/Mollie/IDEAL.php @@ -86,7 +86,9 @@ class IDEAL implements MethodInterface 'webhookUrl' => $this->mollie->company_gateway->webhookUrl(), 'metadata' => [ 'client_id' => $this->mollie->client->hashed_id, - 'hash' => $this->mollie->payment_hash->hash + 'hash' => $this->mollie->payment_hash->hash, + 'gateway_type_id' => GatewayType::IDEAL, + 'payment_type_id' => PaymentType::IDEAL, ], ]); diff --git a/app/PaymentDrivers/Mollie/KBC.php b/app/PaymentDrivers/Mollie/KBC.php index 3dbc53772b29..c5a63c275924 100644 --- a/app/PaymentDrivers/Mollie/KBC.php +++ b/app/PaymentDrivers/Mollie/KBC.php @@ -86,7 +86,9 @@ class KBC implements MethodInterface 'webhookUrl' => $this->mollie->company_gateway->webhookUrl(), 'metadata' => [ 'client_id' => $this->mollie->client->hashed_id, - 'hash' => $this->mollie->payment_hash->hash + 'hash' => $this->mollie->payment_hash->hash, + 'gateway_type_id' => GatewayType::KBC, + 'payment_type_id' => PaymentType::KBC, ], ]); diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index be77b8bef2b5..3c6f785d39b5 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -312,14 +312,32 @@ class MolliePaymentDriver extends BaseDriver $client = $record->client; } else{ - nlog("mollie webhook"); - nlog($payment); $client = Client::withTrashed()->find($this->decodePrimaryKey($payment->metadata->client_id)); // sometimes if the user is not returned to the site with a response from Mollie // we may not have a payment record - in these cases we need to re-construct the payment // record from the meta data in the payment hash. + + if($payment && $payment->metadata->payment_hash){ + + /* Harvest Payment Hash*/ + $payment_hash = PaymentHash::where('hash', $payment->metadata->hash)->first(); + + + $data = [ + 'gateway_type_id' => $payment->metadata->gateway_type_id, + '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, + ]; + + $record = $this->createPayment( + $data, + $codes[$payment->status] + ); + + } } $message = [