[
{
"name": "stripe: the portal home page for a customer, with a configuration, locale and idempotency key",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"configuration": "bpc_1MAhNDLkdIwHu7ix",
"locale": "en-GB",
"idempotencyKey": "portal-u42-1"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions",
"headers": {
"authorization": "Bearer sk_test_51NcFakeKeyForContractTests0000",
"content-type": "application/x-www-form-urlencoded",
"idempotency-key": "portal-u42-1"
},
"form": {
"customer": "cus_NffrFeUfNV2Hib",
"return_url": "https://app.example/account",
"configuration": "bpc_1MAhNDLkdIwHu7ix",
"locale": "en-GB"
}
},
"response": {
"status": 200,
"json": {
"id": "bps_1MAhNDLkdIwHu7ixckACO1Jq",
"object": "billing_portal.session",
"configuration": "bpc_1MAhNDLkdIwHu7ix",
"created": 1772366400,
"customer": "cus_NffrFeUfNV2Hib",
"livemode": false,
"locale": "en-GB",
"return_url": "https://app.example/account",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100"
}
}
}
],
"expect": {
"provider": "stripe",
"id": "bps_1MAhNDLkdIwHu7ixckACO1Jq",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100",
"returnUrl": "https://app.example/account"
}
},
{
"name": "stripe: nothing optional, the exact form body",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/billing?tab=plan"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions",
"body": "customer=cus_NffrFeUfNV2Hib&return_url=https%3A%2F%2Fapp.example%2Fbilling%3Ftab%3Dplan"
},
"response": {
"status": 200,
"json": {
"id": "bps_1PzPlain",
"object": "billing_portal.session",
"configuration": "bpc_1MAhNDLkdIwHu7ix",
"created": 1772366400,
"customer": "cus_NffrFeUfNV2Hib",
"livemode": false,
"locale": null,
"return_url": "https://app.example/billing?tab=plan",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100"
}
}
}
],
"expect": {
"provider": "stripe",
"id": "bps_1PzPlain",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100",
"returnUrl": "https://app.example/billing?tab=plan"
}
},
{
"name": "stripe: straight into cancelling one subscription",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"flow": "subscription_cancel",
"subscription": "sub_1MowQVLkdIwHu7ixeRlqHVzs"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions",
"form": {
"customer": "cus_NffrFeUfNV2Hib",
"return_url": "https://app.example/account",
"flow_data[type]": "subscription_cancel",
"flow_data[subscription_cancel][subscription]": "sub_1MowQVLkdIwHu7ixeRlqHVzs"
}
},
"response": {
"status": 200,
"json": {
"id": "bps_1PzCancel",
"object": "billing_portal.session",
"configuration": "bpc_1MAhNDLkdIwHu7ix",
"created": 1772366400,
"customer": "cus_NffrFeUfNV2Hib",
"livemode": false,
"locale": null,
"return_url": "https://app.example/account",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100",
"flow": {
"type": "subscription_cancel"
}
}
}
}
],
"expect": {
"provider": "stripe",
"id": "bps_1PzCancel",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100",
"returnUrl": "https://app.example/account"
}
},
{
"name": "stripe: straight into updating the card, no subscription sent",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"flow": "payment_method_update"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions",
"form": {
"customer": "cus_NffrFeUfNV2Hib",
"return_url": "https://app.example/account",
"flow_data[type]": "payment_method_update"
}
},
"response": {
"status": 200,
"json": {
"id": "bps_1PzCard",
"object": "billing_portal.session",
"configuration": "bpc_1MAhNDLkdIwHu7ix",
"created": 1772366400,
"customer": "cus_NffrFeUfNV2Hib",
"livemode": false,
"locale": null,
"return_url": "https://app.example/account",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100"
}
}
}
],
"expect": {
"provider": "stripe",
"id": "bps_1PzCard",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OZmZyR3ZjS2xsZW1oQ0NUbE1Ec1NNTUxIb3VtZGt60100",
"returnUrl": "https://app.example/account"
}
},
{
"name": "stripe: an unknown customer is thrown with Stripe's code, message and parameter",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_Missing",
"returnUrl": "https://app.example/account"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions"
},
"response": {
"status": 400,
"json": {
"error": {
"type": "invalid_request_error",
"code": "resource_missing",
"message": "No such customer: 'cus_Missing'",
"param": "customer"
}
}
}
}
],
"expectError": "stripe refused the portal session (400 resource_missing, param customer): No such customer: 'cus_Missing'"
},
{
"name": "stripe: the portal not yet set up in test mode",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions"
},
"response": {
"status": 400,
"json": {
"error": {
"type": "invalid_request_error",
"message": "No configuration provided and your test mode default configuration has not been created. Provide a configuration or create your default by saving your customer portal settings in test mode at https://dashboard.stripe.com/test/settings/billing/portal."
}
}
}
}
],
"expectError": "stripe refused the portal session (400 invalid_request_error): No configuration provided"
},
{
"name": "stripe: a refused key names the variable",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_revoked"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions",
"headers": {
"authorization": "Bearer sk_test_revoked"
}
},
"response": {
"status": 401,
"json": {
"error": {
"type": "invalid_request_error",
"message": "Invalid API Key provided: sk_test_*******oked"
}
}
}
}
],
"expectError": "stripe refused STRIPE_SECRET_KEY (401): Invalid API Key provided"
},
{
"name": "stripe: rate limited says to retry with the same key",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"idempotencyKey": "portal-u42-2"
}
],
"exchanges": [
{
"request": {
"method": "POST",
"url": "https://api.stripe.com/v1/billing_portal/sessions"
},
"response": {
"status": 429,
"json": {
"error": {
"type": "rate_limit_error",
"message": "Too many requests"
}
}
}
}
],
"expectError": "stripe is rate limiting this key (429)"
},
{
"name": "stripe: no secret key set",
"provider": "stripe",
"env": {},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account"
}
],
"expectError": "STRIPE_SECRET_KEY is not set"
},
{
"name": "local: a session on the machine, the default portal page",
"provider": "local",
"random": "a1b2c3d4e5f60718293a4b5c",
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account"
}
],
"expect": {
"provider": "local",
"id": "bps_local_a1b2c3d4e5f60718293a4b5c",
"url": "http://localhost:3000/dev/billing-portal?session=bps_local_a1b2c3d4e5f60718293a4b5c&customer=cus_NffrFeUfNV2Hib&return_url=https%3A%2F%2Fapp.example%2Faccount",
"returnUrl": "https://app.example/account"
}
},
{
"name": "local: a flow and its subscription passed to the app's own page",
"provider": "local",
"env": {
"LOCAL_PORTAL_URL": "http://localhost:5173/dev/portal?theme=dark"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"flow": "subscription_update",
"subscription": "sub_1MowQVLkdIwHu7ixeRlqHVzs"
}
],
"expect": {
"provider": "local",
"id": "bps_local_000102030405060708090a0b",
"url": "http://localhost:5173/dev/portal?theme=dark&session=bps_local_000102030405060708090a0b&customer=cus_NffrFeUfNV2Hib&return_url=https%3A%2F%2Fapp.example%2Faccount&flow=subscription_update&subscription=sub_1MowQVLkdIwHu7ixeRlqHVzs",
"returnUrl": "https://app.example/account"
}
},
{
"name": "local: a portal page that is not a URL is reported",
"provider": "local",
"env": {
"LOCAL_PORTAL_URL": "/dev/billing-portal"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account"
}
],
"expectError": "LOCAL_PORTAL_URL is not an absolute http(s) URL"
},
{
"name": "a customer that is not a cus_ id is refused before anything is sent",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "user_42",
"returnUrl": "https://app.example/account"
}
],
"expectError": "customer \"user_42\" is not a Customer id (cus_...)"
},
{
"name": "a relative return URL",
"provider": "local",
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "/account"
}
],
"expectError": "returnUrl is an absolute http(s) URL"
},
{
"name": "a cancel flow without its subscription",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"flow": "subscription_cancel"
}
],
"expectError": "flow subscription_cancel needs the subscription (sub_...)"
},
{
"name": "an unknown flow",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"flow": "invoice_history"
}
],
"expectError": "flow is one of payment_method_update, subscription_cancel, subscription_update"
},
{
"name": "a configuration that is not a bpc_ id",
"provider": "stripe",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"configuration": "default"
}
],
"expectError": "configuration \"default\" is not a portal configuration id (bpc_...)"
},
{
"name": "a malformed locale",
"provider": "local",
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account",
"locale": "english"
}
],
"expectError": "locale \"english\" is not a locale such as en, en-GB or auto"
},
{
"name": "no provider chosen",
"env": {
"STRIPE_SECRET_KEY": "sk_test_51NcFakeKeyForContractTests0000"
},
"args": [
{
"customer": "cus_NffrFeUfNV2Hib",
"returnUrl": "https://app.example/account"
}
],
"expectError": "PAYMENTS_PROVIDER is not set; set it to one of stripe, local"
}
]