User not upgraded after purchasing a subscription with stripe ( Race condition )

K a M a L

Active member
Affected version
2.2.10
Today I got a report that a user has paid a recurring subscription via stripe but his account was not upgraded .. checking his payment log entry it shows
Error: Event data received from Stripe does not contain the expected values. and Purchase request key was N/A.
Checking the database I found that Purchase Request provider_metadata has the correct subscription_id and everything looks fine there.
Going through the code to find a probable reason for the issue I figured out it may be a race condition that could occur when the webhook notification is received/processed before purchase request is updated
$purchaseRequest->fastUpdate('provider_metadata', $subscriptionId);

P.S. This is not a duplicate of https://xenforo.com/community/threa...-does-not-contain-the-expected-values.204069/
which seems to be caused by deleted payment profile
 

K a M a L

Active member
Below after
$purchaseRequest->fastUpdate('provider_metadata', $subscriptionId);
Xenforo checks for payment success
$paymentStatus = $latestInvoice->payment_intent->status; if ($paymentStatus !== 'succeeded') { }

it could be a good Idea to upgrade user there using the payment status from API instead of relying on the webhook notification
 
Top