@@ -9,8 +9,6 @@ import type {
9
9
StripeCardExpiryElementOptions ,
10
10
StripeCardNumberElementOptions ,
11
11
StripeConstructorOptions ,
12
- StripeCurrencySelectorElement ,
13
- StripeElement ,
14
12
StripeElementType ,
15
13
StripeElements ,
16
14
StripeElementsOptions ,
@@ -26,7 +24,6 @@ import type {
26
24
StripeIssuingCardExpiryDisplayElementOptions ,
27
25
StripeIssuingCardNumberDisplayElementOptions ,
28
26
StripeIssuingCardPinDisplayElementOptions ,
29
- StripeLinkAuthenticationElement ,
30
27
StripeP24BankElementOptions ,
31
28
StripePaymentElementOptions ,
32
29
StripePaymentMethodMessagingElementOptions ,
@@ -43,7 +40,6 @@ export type StripeElementOptions =
43
40
| StripeCardElementOptions
44
41
| StripeCardExpiryElementOptions
45
42
| StripeCardNumberElementOptions
46
- | StripeCurrencySelectorElement
47
43
| StripeEpsBankElementOptions
48
44
| StripeExpressCheckoutElementOptions
49
45
| StripeFpxBankElementOptions
@@ -54,14 +50,13 @@ export type StripeElementOptions =
54
50
| StripeIssuingCardExpiryDisplayElementOptions
55
51
| StripeIssuingCardNumberDisplayElementOptions
56
52
| StripeIssuingCardPinDisplayElementOptions
57
- | StripeLinkAuthenticationElement
58
53
| StripeP24BankElementOptions
59
54
| StripePaymentElementOptions
60
55
| StripePaymentMethodMessagingElementOptions
61
56
| StripePaymentRequestButtonElementOptions
62
57
| StripeShippingAddressElementOptions
63
58
64
- /* type StripeElementOptionsMap = {
59
+ export type StripeElementOptionsMap = {
65
60
address : StripeAddressElementOptions
66
61
affirmMessage : StripeAffirmMessageElementOptions
67
62
afterpayClearpayMessage : StripeAfterpayClearpayMessageElementOptions
@@ -87,12 +82,13 @@ export type StripeElementOptions =
87
82
paymentMethodMessaging : StripePaymentMethodMessagingElementOptions
88
83
paymentRequestButton : StripePaymentRequestButtonElementOptions
89
84
shippingAddress : StripeShippingAddressElementOptions
90
- } */
85
+ }
91
86
92
87
export const ERRORS = {
93
- STRIPE_NOT_LOADED : "Stripe script is not loaded" ,
88
+ STRIPE_NOT_LOADED :
89
+ "Stripe is not loaded. Include it as script or load using loadStripe method of @stripe/stripe-js" ,
94
90
INSTANCE_NOT_DEFINED :
95
- "Instance object is not defined. Initialize Stripe before creating elements" ,
91
+ "Stripe instance is not defined. Initialize Stripe before creating elements" ,
96
92
ELEMENTS_NOT_DEFINED :
97
93
"Elements object is not defined. You can't create stripe element without it" ,
98
94
ELEMENT_TYPE_NOT_DEFINED :
@@ -134,16 +130,16 @@ export const createElements = (
134
130
export const createElement = (
135
131
elements : StripeElements ,
136
132
elementType : StripeElementType ,
137
- options ?: StripeElementOptions ,
138
- ) : StripeElement | undefined => {
133
+ options ?: StripeElementOptionsMap [ StripeElementType ] ,
134
+ ) => {
139
135
try {
140
136
if ( ! elements ) {
141
137
throw new Error ( ERRORS . ELEMENTS_NOT_DEFINED )
142
138
}
143
139
if ( ! elementType ) {
144
140
throw new Error ( ERRORS . ELEMENT_TYPE_NOT_DEFINED )
145
141
}
146
- return elements . create ( elementType as any , options as any )
142
+ return elements . create ( elementType , options )
147
143
} catch ( error ) {
148
144
console . error ( error )
149
145
}
0 commit comments