Braintree version of this bug T413982: Gravy newCheckoutSession running twice on form load
When working on T411673: Add in tracking (and graphs) for how long api calls to the payment processors take, I noticed the following double [braintree|venmo|createsession|request|time] log lines being recorded for each form load:
2026-01-27T21:59:49+00:00 38767923fe1f SmashPig-Braintree: braintree::788:788.1 | (APITimings) [braintree|venmo|createsession|request|time] 0.832070s | | 2026-01-27T21:59:50+00:00 38767923fe1f SmashPig-Braintree: braintree::788:788.1 | (APITimings) [braintree|venmo|createsession|request|time] 0.885093s | | 2026-01-27T22:01:21+00:00 38767923fe1f SmashPig-Braintree: braintree::788:788.1 | (APITimings) [braintree|paypal|createsession|request|time] 0.579835s | | 2026-01-27T22:01:22+00:00 38767923fe1f SmashPig-Braintree: braintree::788:788.1 | (APITimings) [braintree|paypal|createsession|request|time] 0.392347s | | 2026-01-27T22:02:02+00:00 38767923fe1f SmashPig-Braintree: braintree::788:788.1 | (APITimings) [braintree|paypal|authorize|request|time] 4.209867s | | 2026-01-27T22:02:05+00:00 38767923fe1f SmashPig-Braintree: braintree::788:788.1 | (APITimings) [braintree|paypal|capture|request|time] 2.999473s | |
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 getClientToken() 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.
Let's cache the client token so we only create one per session.