Fixes for mollie webhooks if a payment isn't created

This commit is contained in:
David Bomba 2021-11-30 20:53:38 +11:00
parent 6c7e150bec
commit ca2932862d
6 changed files with 33 additions and 7 deletions

View File

@ -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,
],
]);

View File

@ -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,
],
]);

View File

@ -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
],
]);

View File

@ -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,
],
]);

View File

@ -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,
],
]);

View File

@ -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 = [