Race condition with Payment Gateways using onNotify

Created on 28 March 2024, 8 months ago

Problem/Motivation

When running this module with commerce_stripe, I found that the purchase event was not triggering.

Steps to reproduce

Set up commerce to run with commerce_stripe so that payment is via stripe.
Take an order through the checkout and complete the stripe payment page.
Expected outcome: A purchase event is triggered and added to the dataLayer.
Actual outcome: The purchase event was not added to the dataLayer

Proposed resolution

The purchase event is triggered currently by and event responding to 'commerce_orders.place.post_transition'. In this case this event does not get triggered if the Stripe webhook calls onNotify first. I presume it will happen with other similar gateways.
I propose changing it to be triggered by KernalEvents::REQUEST. The issue is to prevent it getting resent if the completion page is refreshed. So I have added a session variable where the name includes the order ID to ensure it does not fire twice.
I supply a patch for consideration.

Remaining tasks

Review this patch and this concern to see if it is the correct approach or if it will cause other issues in other scenarios.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Component

Code

Created by

🇬🇧United Kingdom Rory Downes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024