Skip to content

Commit 26925a0

Browse files
authored
Merge pull request #2847 from bigcommerce/feat/stripe_linkv2_script
feat(payment): upload Stripe client with custom options
2 parents eb526a7 + 04e497e commit 26925a0

File tree

2 files changed

+136
-11
lines changed

2 files changed

+136
-11
lines changed

packages/stripe-integration/src/stripe-upe/stripe-upe-script-loader.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ScriptLoader } from '@bigcommerce/script-loader';
33
import { PaymentMethodClientUnavailableError } from '@bigcommerce/checkout-sdk/payment-integration-api';
44

55
import {
6+
StripeConfigurationOptions,
67
StripeElements,
78
StripeElementsOptions,
89
StripeHostWindow,
@@ -19,13 +20,13 @@ export default class StripeUPEScriptLoader {
1920
stripePublishableKey: string,
2021
stripeAccount: string,
2122
locale?: string,
23+
options?: StripeConfigurationOptions,
2224
): Promise<StripeUPEClient> {
2325
let stripeClient = this.stripeWindow.bcStripeClient;
2426

2527
if (!stripeClient) {
2628
const stripe = await this.load();
27-
28-
stripeClient = stripe(stripePublishableKey, {
29+
const defaultOptions = {
2930
stripeAccount,
3031
locale,
3132
betas: [
@@ -36,7 +37,9 @@ export default class StripeUPEScriptLoader {
3637
'address_element_beta_1',
3738
],
3839
apiVersion: '2020-03-02;alipay_beta=v1;link_beta=v1',
39-
});
40+
};
41+
42+
stripeClient = stripe(stripePublishableKey, options || defaultOptions);
4043

4144
Object.assign(this.stripeWindow, { bcStripeClient: stripeClient });
4245
}

packages/stripe-integration/src/stripe-upe/stripe-upe.ts

Lines changed: 130 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,133 @@
1-
import {
2-
CustomFont,
3-
PaymentIntent,
4-
PaymentMethod,
5-
StripeConfigurationOptions,
6-
} from '../stripev3/stripev3';
7-
8-
export { StripeAdditionalAction } from '../stripev3/stripev3';
1+
/**
2+
* Initialization options.
3+
*/
4+
export interface StripeConfigurationOptions {
5+
/**
6+
* For usage with [Connect](https://stripe.com/docs/connect) only.
7+
* Specifying a connected account ID (e.g., acct_24BFMpJ1svR5A89k) allows you to perform actions on behalf of that account.
8+
*/
9+
stripeAccount: string;
10+
11+
/**
12+
* Override your account's [API version](https://stripe.com/docs/api/versioning)
13+
*/
14+
apiVersion?: string;
15+
16+
/**
17+
* A locale used to globally configure localization in Stripe. Setting the locale here will localize error strings for all Stripe.js methods. It will also configure the locale for Elements and Checkout. Default is auto (Stripe detects the locale of the browser).
18+
* Note that Checkout supports a slightly different set of locales than Stripe.js.
19+
*/
20+
locale?: string;
21+
22+
betas?: string[];
23+
}
24+
25+
export interface StripeAdditionalActionData {
26+
redirect_url?: string;
27+
intent?: string;
28+
}
29+
30+
export interface StripeAdditionalAction {
31+
type: string;
32+
data: StripeAdditionalActionData;
33+
}
34+
35+
/**
36+
* The PaymentIntent object.
37+
*/
38+
export interface PaymentIntent {
39+
/**
40+
* Unique identifier for the object.
41+
*/
42+
id: string;
43+
44+
/**
45+
* Status of this PaymentIntent. Read more about each PaymentIntent [status](https://stripe.com/docs/payments/intents#intent-statuses).
46+
*/
47+
status: 'succeeded' | string;
48+
49+
/**
50+
* The payment error encountered in the previous PaymentIntent confirmation. It will be cleared if the PaymentIntent is later updated for any reason.
51+
*/
52+
last_payment_error: LastPaymentError | null;
53+
}
54+
55+
/**
56+
* The payment error encountered in the previous PaymentIntent confirmation. It will be cleared if the PaymentIntent is later updated for any reason.
57+
*/
58+
export interface LastPaymentError {
59+
/**
60+
* A human-readable message providing more details about the error. For card errors, these messages can be shown to your users.
61+
*/
62+
message?: string;
63+
}
64+
65+
/**
66+
* The PaymentMethod object
67+
*/
68+
export interface PaymentMethod {
69+
/**
70+
* Unique identifier for the object.
71+
*/
72+
id: string;
73+
74+
/**
75+
* The type of the PaymentMethod. An additional hash is included on the PaymentMethod with a name matching this value.
76+
* It contains additional information specific to the PaymentMethod type.
77+
*/
78+
type: string;
79+
}
80+
81+
/**
82+
* This object is used to pass custom fonts when creating an [Elements](https://stripe.com/docs/js/elements_object/create) object.
83+
*/
84+
export interface CssFontSource {
85+
/**
86+
* A relative or absolute URL pointing to a CSS file with [@font-face](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face) definitions, for example:
87+
* `https://fonts.googleapis.com/css?family=Open+Sans`
88+
* Note that if you are using a [content security policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) (CSP),
89+
* [additional directives](https://stripe.com/docs/security#content-security-policy) may be necessary.
90+
*/
91+
cssSrc: string;
92+
}
93+
94+
/**
95+
* This object is used to pass custom fonts when creating an [Elements](https://stripe.com/docs/js/elements_object/create) object.
96+
*/
97+
export interface CustomFontSource {
98+
/**
99+
* The name to give the font.
100+
*/
101+
family: string;
102+
103+
/**
104+
* A valid [src](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src) value pointing to your
105+
* custom font file. This is usually (though not always) a link to a file with a .woff , .otf, or .svg suffix.
106+
*/
107+
src: string;
108+
109+
/**
110+
* A valid [font-display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display) value.
111+
*/
112+
display?: string;
113+
114+
/**
115+
* One of normal, italic, oblique. Defaults to normal.
116+
*/
117+
style?: string;
118+
119+
/**
120+
* A valid [unicode-range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range) value.
121+
*/
122+
unicodeRange?: string;
123+
124+
/**
125+
* A valid [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight). Note that this is a string, not a number.
126+
*/
127+
weight?: string;
128+
}
129+
130+
export type CustomFont = CssFontSource | CustomFontSource;
9131

10132
export interface StripeError {
11133
/**

0 commit comments

Comments
 (0)