Skip to content

Commit e66c987

Browse files
authored
fix(stripe): show app name in express checkout (#949)
## Summary - pass the branding app name to Stripe Express Checkout creation options so Apple Pay shows the app name instead of the connected account business name - add focused coverage for app-name option construction
1 parent 4569872 commit e66c987

5 files changed

Lines changed: 51 additions & 5 deletions

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import type { StripeExpressCheckoutElementOptions } from "@stripe/stripe-js/dist/stripe-js/elements/express-checkout";
22

33
export type StripeExpressCheckoutConfiguration =
4-
Partial<StripeExpressCheckoutElementOptions>;
4+
Partial<StripeExpressCheckoutElementOptions> & {
5+
business?: {
6+
name: string;
7+
};
8+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, expect, test } from "vitest";
2+
import { toExpressPurchaseOptions } from "../../../ui/express-purchase-button/stripe-helpers";
3+
import { Translator } from "../../../ui/localization/translator";
4+
import { rcPackage } from "../../../stories/fixtures";
5+
6+
describe("toExpressPurchaseOptions", () => {
7+
const translator = new Translator();
8+
const purchaseOption = rcPackage.webBillingProduct.defaultPurchaseOption;
9+
const managementUrl = "https://example.com/manage/subscriptions/123";
10+
11+
test("sets the business name when an app name is provided", () => {
12+
const result = toExpressPurchaseOptions(
13+
rcPackage,
14+
purchaseOption,
15+
managementUrl,
16+
translator,
17+
"Test App",
18+
);
19+
20+
expect(result.business).toStrictEqual({ name: "Test App" });
21+
});
22+
23+
test("does not set the business name when an app name is not provided", () => {
24+
const result = toExpressPurchaseOptions(
25+
rcPackage,
26+
purchaseOption,
27+
managementUrl,
28+
translator,
29+
null,
30+
);
31+
32+
expect(result.business).toBeUndefined();
33+
});
34+
});

src/ui/express-purchase-button/express-purchase-button.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
rcPackage,
136136
purchaseOption,
137137
translator,
138+
brandingInfo,
138139
walletButtonTheme,
139140
);
140141
expressCheckoutOptions = expOptions;
@@ -315,6 +316,7 @@
315316
rcPackage,
316317
purchaseOption,
317318
translator,
319+
brandingInfo,
318320
walletButtonTheme,
319321
);
320322

src/ui/express-purchase-button/stripe-helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const toExpressPurchaseOptions = (
7878
purchaseOption: PurchaseOption,
7979
managementUrl: string,
8080
translator: Translator,
81+
appName?: string | null,
8182
walletButtonTheme?: WalletButtonTheme,
8283
) => {
8384
const productDetails: Product = rcPackage.webBillingProduct;
@@ -126,6 +127,10 @@ export const toExpressPurchaseOptions = (
126127
};
127128
}
128129

130+
if (appName) {
131+
options.business = { name: appName };
132+
}
133+
129134
return options;
130135
};
131136

@@ -136,6 +141,7 @@ export const updateStripe = (
136141
rcPackage: Package,
137142
purchaseOption: PurchaseOption,
138143
translator: Translator,
144+
brandingInfo: BrandingInfoResponse | null,
139145
walletButtonTheme?: WalletButtonTheme,
140146
) => {
141147
if (!gatewayParams.elements_configuration) {
@@ -152,6 +158,7 @@ export const updateStripe = (
152158
purchaseOption,
153159
managementUrl,
154160
translator,
161+
brandingInfo?.app_name,
155162
walletButtonTheme,
156163
);
157164
return { expOptions: options };
@@ -225,6 +232,7 @@ export const initStripe = async (
225232
purchaseOption,
226233
managementUrl,
227234
translator,
235+
brandingInfo?.app_name,
228236
walletButtonTheme,
229237
);
230238

src/ui/molecules/stripe-express-checkout-element.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@
7171
const onClickCallback = async (
7272
event: StripeExpressCheckoutElementClickEvent,
7373
) => {
74-
const options = {
75-
...(expressCheckoutOptions ? expressCheckoutOptions : {}),
76-
} as ClickResolveDetails;
74+
const { business: _business, ...options } = expressCheckoutOptions ?? {};
7775
onClick && onClick(event);
78-
event.resolve(options);
76+
event.resolve(options as ClickResolveDetails);
7977
};
8078
8179
const onLoadErrorCallback = async (event: {

0 commit comments

Comments
 (0)