Page MenuHomePhabricator

Gravy newCheckoutSession running twice on form load
Closed, ResolvedPublic

Description

When working on T411673: Add in tracking (and graphs) for how long api calls to the payment processors take, I noticed the following double [gravy|cc|createpaymentsession|request|time] log lines being recorded for each form load:

2026-01-07T13:58:28+00:00 10e5a803c851 gravy_gateway: 740:740.1 session_addDonorData: Refreshing all donor data in session 'ccfja8cop5vcgi725gbcg4mdjrhdnjdt'
2026-01-07T13:58:28+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (RawData) New Checkout Session request [] |  | 
2026-01-07T13:58:29+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (APITimings) fn: newCheckoutSession, elapsed: 0.33797883987427 s |  | 
2026-01-07T13:58:29+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (RawData) newCheckoutSession response: {"cart_items":null,"metadata":null,"buyer":null,"airline":null,"amount":null,"currency":null,"payment_service_id":null,"type":"checkout-session","id":"ce57bab8-b201-4e98-8717-98973b2449e8","expires_at":"2026-01-07T14:58:29.047285+00:00","payment_method":null} |  | 
2026-01-07T13:58:29+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (APITimings) [gravy|cc|createpaymentsession|request|time] 0.338386s | {"tag":"[gravy|cc|createpaymentsession|request|time]","elapsed":0.33838605880737305} | 
2026-01-07T13:58:29+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (RawData) New Checkout Session request [] |  | 
2026-01-07T13:58:29+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (APITimings) fn: newCheckoutSession, elapsed: 0.29821014404297 s |  | 
2026-01-07T13:58:29+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (RawData) newCheckoutSession response: {"cart_items":null,"metadata":null,"buyer":null,"airline":null,"amount":null,"currency":null,"payment_service_id":null,"type":"checkout-session","id":"590e8fb2-66b5-4211-8536-fb583a18e201","expires_at":"2026-01-07T14:58:29.431487+00:00","payment_method":null} |  | 
2026-01-07T13:58:29+00:00 10e5a803c851 SmashPig-Gravy: gravy::740:740.1  | (APITimings) [gravy|cc|createpaymentsession|request|time] 0.298533s | {"tag":"[gravy|cc|createpaymentsession|request|time]","elapsed":0.29853296279907227} |

When I compared with the Adyen form load, which also makes an API call during the page load to see the available payment methods, I only see one API call timing logged:

2026-01-07T14:00:28+00:00 10e5a803c851 SmashPig-Adyen: adyen::741:741.1  | cURL response completed |  | 
2026-01-07T14:00:28+00:00 10e5a803c851 SmashPig-Adyen: adyen::741:741.1  | Successful request |  | 
2026-01-07T14:00:28+00:00 10e5a803c851 SmashPig-Adyen: adyen::741:741.1  | (APITimings) fn: getPaymentMethods, elapsed: 0.132909 s |  | 
2026-01-07T14:00:28+00:00 10e5a803c851 SmashPig-Adyen: adyen::741:741.1  | (APITimings) [adyen|cc|getpaymentmethods|request|time] 0.145734s | {"tag":"[adyen|cc|getpaymentmethods|request|time]","elapsed":0.14573407173156738}

Upon inspection, it looks like the setClientVariables() method, which wraps the newCheckoutSession call, is being called twice because a Mediawiki hook fires twice during the page render. We avoid the double run with Adyen because the payment methods are cached after the first API call.

I'm not sure if this has actually caused a problem, but it's meant that we've been creating two sessions for each form load since we added it.

Let's cache the session ID so we only create one per session.

Event Timeline

Change #1224087 had a related patch set uploaded (by Jgleeson; author: Jgleeson):

[mediawiki/extensions/DonationInterface@master] Cache Gravy checkout session ID to prevent duplicate API calls

https://gerrit.wikimedia.org/r/1224087

Change #1224087 merged by jenkins-bot:

[mediawiki/extensions/DonationInterface@master] Cache Gravy checkout session ID to prevent duplicate API calls

https://gerrit.wikimedia.org/r/1224087

XenoRyet set Final Story Points to 2.

This is also happening on Braintree. I'll apply the same fix.