By alexpott on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x-2.x
Introduced in version:
8.x-2.39
Issue links:
Description:
When throwing PaymentGatewayException, HardDeclineException, SoftDeclineException or DeclineException exceptions the payment or payment method information can be attached by using the new ::createForPayment() method. This enables the FailedPaymentEvent to have more information available for reporting and logging.
Also, if your payment gateway sets the card type and other information on the payment method then it best if this happens before the exception is thrown. See modules/payment_example/src/Plugin/Commerce/PaymentGateway/Onsite.php for an example.
Before
throw new HardDeclineException($decline_message);
After
throw HardDeclineException::createForPayment($payment, $decline_message);
Impacts:
Module developers