Every Stripe request runs against one API version: your account's default, or the version your code sets with apiVersion. A newer version can remove or reshape fields, and nothing in your code changes to tell you. This post walks through one real upgrade, 2022-08-01 to 2022-11-15, with the GitGo CLI and a small TypeScript file.
What changed between the two versions
Three changes in 2022-11-15 touch PaymentIntents and Charges:
chargeswas removed from PaymentIntent responses. Code that reads it getsundefined.latest_chargewas added to PaymentIntent responses. Read it instead.- A Charge no longer includes
refundsunless you expand it.
To list every change between two versions, run gitgo diff on their OpenAPI descriptions. It labels each change breaking, risky or info.
Where it breaks in your code
A diff tells you what changed, not which of your lines it affects. gitgo scan takes the same two descriptions and lists each line of your TypeScript, JavaScript or Python code that the change affects. Take this file:
import Stripe from 'stripe';
const stripe = new Stripe('sk_test', { apiVersion: '2022-08-01' });
export async function latestCharge(id: string) {
const pi = await stripe.paymentIntents.retrieve(id);
const chargeId = pi.charges.data[0].id;
const { charges, latest_charge: latest } = await stripe.paymentIntents.retrieve(id);
console.log(charges.total_count, latest);
const status = (await stripe.paymentIntents.retrieve(id)).status;
const list = await stripe.paymentIntents.list({ limit: 3 });
for (const item of list.data) {
console.log(item.charges.url);
}
return [chargeId, status];
}$ gitgo scan --from stripe-2022-08-01.json --to stripe-2022-11-15.json ./src
responses.ts:7:20 BREAKING response-property-removed $.charges in response 200 (application/json) was removed (GET /v1/payment_intents/{intent})
responses.ts:8:11 BREAKING response-property-removed $.charges in response 200 (application/json) was removed (GET /v1/payment_intents/{intent})
responses.ts:8:20 INFO response-required-property-added new required property $.latest_charge in response 200 (application/json) (GET /v1/payment_intents/{intent})
responses.ts:9:15 BREAKING response-property-removed $.charges in response 200 (application/json) was removed (GET /v1/payment_intents/{intent})
responses.ts:13:17 BREAKING response-property-removed $.data[].charges in response 200 (application/json) was removed (GET /v1/payment_intents)
5 impacts (4 breaking, 0 risky, 1 info) in 1 file; 6 files scanned, 0 skipped, 31 API usages; spec 2022-08-01 -> 2022-11-15Each read of charges is listed with its line and column. A text search for charges would find these lines too, along with every unrelated charges in your codebase. The scan lists only reads of the field Stripe removed.
How to fix it
Replace each read of charges with latest_charge. It holds the ID of the most recent charge, or the full Charge object if you expand it. If you need every charge on a PaymentIntent, list them with stripe.charges.list({ payment_intent: id }).
- const chargeId = pi.charges.data[0].id;
+ const chargeId = typeof pi.latest_charge === 'string' ? pi.latest_charge : pi.latest_charge?.id;Then run the scan again. When it reports no breaking impacts, change the apiVersion your client pins. A hosted GitGo service that writes these edits as a pull request is in development.
Try it on your code
Download the OpenAPI descriptions for your current version and the one you want, then scan the directory that calls Stripe. The CLI runs on your machine and sends nothing anywhere. See install the CLI.
gitgo scan --from stripe-current.json --to stripe-target.json ./src