Skip to content
Snippets Groups Projects

Issue #3112812: Add logging for payment failures during checkout

Merged Dmytrii Kaiun requested to merge issue/commerce-3112812:3112812-add-logging-for into 8.x-2.x
3 files
+ 56
3
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -156,14 +156,24 @@ class PaymentEventSubscriber implements EventSubscriberInterface {
public function onPaymentFailure(FailedPaymentEvent $event): void {
$payment = $event->getPayment();
$payment_method = $payment?->getPaymentMethod() ?? $event->getPaymentMethod();
// Allow payment methods to add additional information to the commerce log.
// These value will not be used by the log template but can allow contrib
// and custom code to provide additional reports based on failed payment
// data.
if ($payment_method?->getType() instanceof FailedPaymentDetailsInterface) {
$params = $payment_method->getType()->failedPaymentDetails($payment_method);
}
else {
$params = [];
}
$this->logStorage->generate($event->getOrder(), 'payment_failed', [
'id' => $payment?->id(),
'remote_id' => $payment?->getRemoteId(),
'method' => $payment_method?->label(),
'error_message' => $event->getGatewayException()->getMessage(),
'gateway' => $event->getPaymentGateway()->label(),
'amount' => $payment?->getBalance(),
])->save();
] + $params)->save();
}
}
Loading