Issue #3112812: Add logging for payment failures during checkout
Merge request reports
Activity
added 1 commit
added 1 commit
added 1 commit
added 8 commits
- 0647c0a5 - Revert "Issue #3348311 by rhovland: Add Payment link on order view page."
- afca0210 - Issue #3347295 by tBKoT, jsacksick, AdamPS: Indicate resend of order receipt mail.
- c2301517 - Issue #3348945 by jsacksick: Call to a member function setFormClass() on null...
- 57baa7ac - Issue #2845321 followup by jsacksick: Improvement the log templates introduced...
- 6a807314 - Issue #2924159 by fenstrat, gmem, DamienMcKenna, lisastreeter, jsacksick:...
- 17ebea9a - Issue #2924159 followup by jsacksick: Properly access the profile view builder.
- 36960cd0 - Issue #3351156 by jsacksick, ericchew: Order Items IEF default settings can cause orphaned items.
- 01055051 - Issue #3349465 by tBKoT, jsacksick, bojanz: Update several VAT rates and setup...
Toggle commit listadded 9 commits
-
01055051...e1389f0f - 8 commits from branch
project:8.x-2.x
- 9a754fdd - Issue #3112812 by tBKoT: Add logging for failed payment
-
01055051...e1389f0f - 8 commits from branch
added 15 commits
-
9a754fdd...8dae4ffd - 14 commits from branch
project:8.x-2.x
- 1aa3e8bf - Issue #3112812 by tBKoT: Add logging for failed payment
-
9a754fdd...8dae4ffd - 14 commits from branch
added 19 commits
-
1aa3e8bf...f4c37ceb - 18 commits from branch
project:8.x-2.x
- b9bd5980 - Issue #3112812 by tBKoT: Add logging for failed payment
-
1aa3e8bf...f4c37ceb - 18 commits from branch
added 45 commits
-
b9bd5980...f27f1227 - 44 commits from branch
project:8.x-2.x
- 04abbf13 - Issue #3112812 by tBKoT: Add logging for failed payment
-
b9bd5980...f27f1227 - 44 commits from branch
- Resolved by Dmytrii Kaiun
19 * The event dispatcher. 20 */ 21 protected EventDispatcherInterface $eventDispatcher; 22 23 /** 24 * The order. 25 */ 26 protected ?OrderInterface $order = NULL; 27 28 /** 29 * {@inheritdoc} 30 */ 31 public static function create(ContainerInterface $container) { 32 $instance = parent::create($container); 33 $instance->eventDispatcher = $container->get('event_dispatcher'); 34 $instance->order = $container->get('current_route_match')->getParameter('commerce_order'); changed this line in version 11 of the diff
83 109 $payment_gateway_plugin->createPaymentMethod($payment_method, $values['payment_details']); 84 110 } 85 111 catch (DeclineException $e) { 112 if ( 113 $this->order instanceof OrderInterface && 114 $payment_method->getPaymentGateway() instanceof PaymentGatewayInterface 115 ) { 116 $event = new FailedPaymentEvent($this->order, $payment_method->getPaymentGateway(), $e); 117 $this->eventDispatcher->dispatch($event, PaymentEvents::PAYMENT_FAILURE); - Comment on lines +112 to +117
I believe this should be moved to PaymentGatewayForm::submitInlineForm() which catches the exception. This will make sure exceptions throwns by all payment method add forms will be caught...
Edited by Jonathan Sacksick changed this line in version 11 of the diff
180 154 $this->checkoutFlow->redirectToStep($next_step_id); 181 155 } 182 156 catch (DeclineException $e) { 157 $event = new FailedPaymentEvent($this->order, $payment_gateway, $e, $payment); 158 $this->eventDispatcher->dispatch($event, PaymentEvents::PAYMENT_FAILURE); changed this line in version 12 of the diff
added 3 commits
-
04abbf13...f15f5177 - 2 commits from branch
project:8.x-2.x
- b3a04461 - Issue #3112812 by tBKoT: Add logging for failed payment
-
04abbf13...f15f5177 - 2 commits from branch
added 1 commit
165 165 public function submitInlineForm(array &$inline_form, FormStateInterface $form_state) { 166 166 parent::submitInlineForm($inline_form, $form_state); 167 167 168 $payment_gateway = $this->entity->getPaymentGateway(); 169 $order = $this->routeMatch->getParameter('commerce_order'); changed this line in version 12 of the diff
232 212 $this->checkoutFlow->redirectToStep($next_step_id); 233 213 } 234 214 catch (PaymentGatewayException $e) { 215 $event = new FailedPaymentEvent($this->order, $payment_gateway, $e, $payment); changed this line in version 12 of the diff
145 147 ])->save(); 146 148 } 147 149 150 /** 151 * Creates a log when payment failed. 152 * 153 * @param \Drupal\commerce_payment\Event\FailedPaymentEvent $event 154 * The failed payment event. 155 */ 156 public function onPaymentFailure(FailedPaymentEvent $event): void { 157 $this->logStorage->generate($event->getOrder(), 'payment_failed', [ 158 'error_message' => $event->getGatewayException()->getMessage(), 159 'gateway' => $event->getPaymentGateway()->label(), 160 'amount' => $event->getPayment()?->getBalance(), 161 ])->save(); - Comment on lines +157 to +161
Can we also add the payment id to this information. This would allow reports to build a much detailed picture of what is going on here. Maybe we can look at \Drupal\commerce_log\EventSubscriber\PaymentEventSubscriber::onPaymentInsert() as inspiration... so something like:
162 $this->logStorage->generate($event->getOrder(), 'payment_failed', [ 163 'error_message' => $event->getGatewayException()->getMessage(), 164 'gateway' => $event->getPaymentGateway()->label(), 165 'amount' => $event->getPayment()?->getBalance(), 166 ])->save(); 162 $this->logStorage->generate($event->getOrder(), 'payment_failed', [ 163 'id' => $payment->id(), 164 'remote_id' => $payment->getRemoteId(), 165 'method' => $payment->getPaymentMethod()?->label(), 166 'error_message' => $event->getGatewayException()->getMessage(), 167 'gateway' => $event->getPaymentGateway()->label(), 168 'amount' => $event->getPayment()?->getBalance(), 169 ])->save(); changed this line in version 18 of the diff
19 * Constructs a new FailedPaymentEvent. 20 * 21 * @param \Drupal\commerce_order\Entity\OrderInterface $order 22 * The order entity. 23 * @param \Drupal\commerce_payment\Entity\PaymentGatewayInterface $paymentGateway 24 * The payment gateway. 25 * @param \Drupal\commerce_payment\Exception\PaymentGatewayException $gatewayException 26 * The payment gateway exception. 27 * @param \Drupal\commerce_payment\Entity\PaymentInterface|null $payment 28 * The payment. 29 */ 30 public function __construct( 31 protected OrderInterface $order, 32 protected PaymentGatewayInterface $paymentGateway, 33 protected PaymentGatewayException $gatewayException, 34 protected ?PaymentInterface $payment = NULL 72 98 $payment_method->save(); 73 99 } 74 100 catch (DeclineException $e) { 101 if ( 102 $this->order instanceof OrderInterface && 103 $payment_method->getPaymentGateway() instanceof PaymentGatewayInterface 104 ) { 105 $event = new FailedPaymentEvent($this->order, $payment_method->getPaymentGateway(), $e); 106 $this->eventDispatcher->dispatch($event, PaymentEvents::PAYMENT_FAILURE); - Comment on lines +105 to +106
added 6 commits
-
fceaef13...e7f1f3f3 - 2 commits from branch
project:8.x-2.x
- 250c1fdd - Merge branch '8.x-2.x' into 3112812-add-logging-for
- 615fae0e - Move to catch as suggested by @jsacksick
- 33843a9c - refactor to use a single try/catch to make consistent logic easier to follow
- dd741768 - Add more info to payment_failed log
Toggle commit list-
fceaef13...e7f1f3f3 - 2 commits from branch