@stripe/stripe-react-native 0.10.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +3 -3
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +46 -10
  5. package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +5 -0
  6. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +8 -0
  7. package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +6 -1
  8. package/android/src/main/java/com/reactnativestripesdk/Errors.kt +14 -1
  9. package/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt +68 -52
  10. package/android/src/main/java/com/reactnativestripesdk/Mappers.kt +5 -7
  11. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +127 -37
  12. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +173 -0
  13. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +60 -36
  14. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +67 -177
  15. package/ios/CardFieldManager.m +1 -0
  16. package/ios/CardFieldView.swift +6 -0
  17. package/ios/Mappers.swift +8 -9
  18. package/ios/PaymentSheetAppearance.swift +209 -0
  19. package/ios/StripeSdk.swift +141 -116
  20. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  21. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  22. package/lib/commonjs/components/ApplePayButton.js +1 -1
  23. package/lib/commonjs/components/ApplePayButton.js.map +1 -1
  24. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  25. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  26. package/lib/commonjs/components/CardField.js +1 -1
  27. package/lib/commonjs/components/CardField.js.map +1 -1
  28. package/lib/commonjs/components/CardForm.js +1 -1
  29. package/lib/commonjs/components/CardForm.js.map +1 -1
  30. package/lib/commonjs/components/GooglePayButton.js +1 -1
  31. package/lib/commonjs/components/GooglePayButton.js.map +1 -1
  32. package/lib/commonjs/components/StripeContainer.js +1 -1
  33. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  34. package/lib/commonjs/functions.js.map +1 -1
  35. package/lib/commonjs/types/components/CardFieldInput.js.map +1 -1
  36. package/lib/commonjs/types/index.js.map +1 -1
  37. package/lib/module/components/AddToWalletButton.js +1 -1
  38. package/lib/module/components/AddToWalletButton.js.map +1 -1
  39. package/lib/module/components/ApplePayButton.js +1 -1
  40. package/lib/module/components/ApplePayButton.js.map +1 -1
  41. package/lib/module/components/AuBECSDebitForm.js +1 -1
  42. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  43. package/lib/module/components/CardField.js +1 -1
  44. package/lib/module/components/CardField.js.map +1 -1
  45. package/lib/module/components/CardForm.js +1 -1
  46. package/lib/module/components/CardForm.js.map +1 -1
  47. package/lib/module/components/GooglePayButton.js +1 -1
  48. package/lib/module/components/GooglePayButton.js.map +1 -1
  49. package/lib/module/components/StripeContainer.js +1 -1
  50. package/lib/module/components/StripeContainer.js.map +1 -1
  51. package/lib/module/functions.js.map +1 -1
  52. package/lib/module/types/components/CardFieldInput.js.map +1 -1
  53. package/lib/module/types/index.js.map +1 -1
  54. package/lib/typescript/example/src/screens/PaymentSheetAppearance.d.ts +3 -0
  55. package/lib/typescript/src/components/CardField.d.ts +3 -0
  56. package/lib/typescript/src/components/CardForm.d.ts +2 -0
  57. package/lib/typescript/src/types/PaymentSheet.d.ts +154 -1
  58. package/lib/typescript/src/types/Token.d.ts +9 -1
  59. package/lib/typescript/src/types/components/CardFieldInput.d.ts +1 -0
  60. package/lib/typescript/src/types/components/CardFormView.d.ts +6 -0
  61. package/lib/typescript/src/types/index.d.ts +1 -4
  62. package/package.json +1 -1
  63. package/src/components/CardField.tsx +5 -0
  64. package/src/components/CardForm.tsx +6 -0
  65. package/src/functions.ts +1 -1
  66. package/src/types/PaymentSheet.ts +159 -2
  67. package/src/types/Token.ts +13 -1
  68. package/src/types/components/CardFieldInput.ts +1 -0
  69. package/src/types/components/CardFormView.ts +7 -0
  70. package/src/types/index.ts +1 -5
  71. package/stripe-react-native.podspec +1 -1
  72. package/android/src/main/java/com/reactnativestripesdk/Constants.kt +0 -10
@@ -37,6 +37,10 @@ export interface Placeholders {
37
37
  cvc?: string;
38
38
  postalCode?: string;
39
39
  }
40
+ export declare type DefaultValues = {
41
+ /** The 2-letter country code for the country selected by default on Android. If this is null, it is set by the device's configured region in the Settings app. */
42
+ countryCode?: string;
43
+ };
40
44
  /**
41
45
  * @ignore
42
46
  */
@@ -46,6 +50,8 @@ export interface NativeProps {
46
50
  cardStyle?: Styles;
47
51
  /** Android only */
48
52
  placeholders?: Placeholders;
53
+ /** Android only */
54
+ defaultValues?: DefaultValues;
49
55
  onFocusChange(event: NativeSyntheticEvent<{
50
56
  focusedField: FieldName | null;
51
57
  }>): void;
@@ -83,10 +83,7 @@ export declare type InitPaymentSheetResult = {
83
83
  error: StripeError<PaymentSheetError>;
84
84
  };
85
85
  export declare type PresentPaymentSheetResult = {
86
- paymentOption?: undefined;
87
- error?: undefined;
88
- } | {
89
- paymentOption?: PaymentSheet.PaymentOption;
86
+ paymentOption: PaymentSheet.PaymentOption;
90
87
  error?: undefined;
91
88
  } | {
92
89
  paymentOption?: undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/stripe-react-native",
3
- "version": "0.10.0",
3
+ "version": "0.13.0",
4
4
  "author": "Stripe",
5
5
  "description": "Stripe SDK for React Native",
6
6
  "main": "lib/commonjs/index",
@@ -30,7 +30,10 @@ const CardFieldNative =
30
30
  */
31
31
  export interface Props extends AccessibilityProps {
32
32
  style?: StyleProp<ViewStyle>;
33
+ /** Controls if a postal code entry field can be displayed to the user. Defaults to false. If true, the type of code entry shown is controlled by the set countryCode prop. Some country codes may result in no postal code entry being shown if those countries do not commonly use postal codes. If false, no postal code entry will ever be displayed. */
33
34
  postalCodeEnabled?: boolean;
35
+ /** Controls the postal code entry shown (if the postalCodeEnabled prop is set to true). Defaults to the device's default locale. */
36
+ countryCode?: string;
34
37
  cardStyle?: CardFieldInput.Styles;
35
38
  placeholders?: CardFieldInput.Placeholders;
36
39
  autofocus?: boolean;
@@ -74,6 +77,7 @@ export const CardField = forwardRef<CardFieldInput.Methods, Props>(
74
77
  cardStyle,
75
78
  placeholders,
76
79
  postalCodeEnabled,
80
+ countryCode,
77
81
  ...props
78
82
  },
79
83
  ref
@@ -175,6 +179,7 @@ export const CardField = forwardRef<CardFieldInput.Methods, Props>(
175
179
  onCardChange={onCardChangeHandler}
176
180
  onFocusChange={onFocusHandler}
177
181
  postalCodeEnabled={postalCodeEnabled ?? true}
182
+ countryCode={countryCode ?? null}
178
183
  cardStyle={{
179
184
  backgroundColor: cardStyle?.backgroundColor,
180
185
  borderColor: cardStyle?.borderColor,
@@ -42,6 +42,8 @@ export interface Props extends AccessibilityProps {
42
42
 
43
43
  /** Android only */
44
44
  placeholders?: CardFormView.Placeholders;
45
+ /** Android only */
46
+ defaultValues?: CardFormView.DefaultValues;
45
47
  // onBlur?(): void;
46
48
  // onFocus?(focusedField: CardFormView.FieldNames | null): void;
47
49
  onFormComplete?(card: CardFormView.Details): void;
@@ -81,6 +83,7 @@ export const CardForm = forwardRef<CardFormView.Methods, Props>(
81
83
  // onFocus,
82
84
  // onBlur,
83
85
  placeholders,
86
+ defaultValues,
84
87
  ...props
85
88
  },
86
89
  ref
@@ -185,6 +188,9 @@ export const CardForm = forwardRef<CardFormView.Methods, Props>(
185
188
  cvc: placeholders?.cvc,
186
189
  postalCode: placeholders?.postalCode,
187
190
  }}
191
+ defaultValues={{
192
+ ...(defaultValues ?? {}),
193
+ }}
188
194
  onFocusChange={onFocusHandler}
189
195
  // postalCodeEnabled={postalCodeEnabled}
190
196
  {...props}
package/src/functions.ts CHANGED
@@ -406,7 +406,7 @@ export const presentPaymentSheet =
406
406
  };
407
407
  }
408
408
  return {
409
- paymentOption: paymentOption,
409
+ paymentOption: paymentOption!,
410
410
  };
411
411
  } catch (error: any) {
412
412
  return {
@@ -9,10 +9,9 @@ export type SetupParams = ClientSecretParams &
9
9
  merchantDisplayName?: string;
10
10
  style?: 'alwaysLight' | 'alwaysDark' | 'automatic';
11
11
  returnURL?: string;
12
- primaryButtonColor?: string;
13
12
  defaultBillingDetails?: BillingDetails;
14
13
  allowsDelayedPaymentMethods?: boolean;
15
- };
14
+ } & { appearance?: AppearanceParams };
16
15
 
17
16
  type ClientSecretParams =
18
17
  | {
@@ -47,6 +46,164 @@ type GooglePayParams =
47
46
  currencyCode?: string;
48
47
  testEnv?: boolean;
49
48
  };
49
+
50
+ /**
51
+ * Used to customize the appearance of your PaymentSheet
52
+ */
53
+ export type AppearanceParams = RecursivePartial<{
54
+ /** Describes the appearance of fonts in your PaymentSheet */
55
+ font: FontConfig;
56
+ /** Describes the colors in your PaymentSheet. Provide either a base config, or both `light` and `dark` configs, which will be useed based on whether the user is in Light or Dark mode. */
57
+ colors:
58
+ | GlobalColorConfig
59
+ | { light: GlobalColorConfig; dark: GlobalColorConfig };
60
+ /** Describes the appearance of shapes in the PaymentSheet, such as buttons, inputs, and tabs. */
61
+ shapes: {
62
+ /** The border radius used for buttons, inputs, and tabs in your PaymentSheet.
63
+ * @default 6.0
64
+ */
65
+ borderRadius: number;
66
+ /** The border width used for inputs and tabs in your PaymentSheet.
67
+ * @default 1.0
68
+ */
69
+ borderWidth: number;
70
+ /** iOS only. The shadow used for buttons, inputs, and tabs in your PaymentSheet */
71
+ shadow: ShadowConfig;
72
+ };
73
+ /** Describes the appearance of the primary "Pay" button at the bottom of your Payment Sheet */
74
+ primaryButton: PrimaryButtonConfig;
75
+ }>;
76
+
77
+ export type FontConfig = {
78
+ /**
79
+ * The font used for regular text. PaymentSheet will attempt to use medium and bold versions of this font if they exist.
80
+ *
81
+ * On iOS, this should be the "PostScript name" found in Font Book after installing the font.
82
+ * On Android, this should be the name of the font file (containing only lowercase alphanumeric characters) in android/app/src/main/res/font
83
+ *
84
+ * @default The OS's system font
85
+ */
86
+ family: string;
87
+ /** The scale factor for all fonts in your PaymentSheet. This value is required to be greater than 0. Font sizes are multiplied by this value before being displayed. For example, setting this to 1.2 increases the size of all text by 20%.
88
+ * @default 1.0
89
+ */
90
+ scale: number;
91
+ };
92
+
93
+ export type ShadowConfig = {
94
+ /** The color of the shadow.
95
+ * @default "#000000"
96
+ * */
97
+ color: string;
98
+ /** The alpha or opacity of the shadow.
99
+ * @default 0.05
100
+ */
101
+ opacity: number;
102
+ /** The positioning of the shadow relative to the component. For example, a negative x and y will result in a shadow placed below and to the left of the component.
103
+ * @default {x: 0, y: 2}
104
+ */
105
+ offset: { x: number; y: number };
106
+ /** The blur radius of the shadow.
107
+ * @default 4
108
+ */
109
+ blurRadius: number;
110
+ };
111
+
112
+ export type GlobalColorConfig = {
113
+ /** A primary color used throughout your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
114
+ * @default The System blue color on iOS, and "#007AFF" (light) / "#0074D4" (dark) on Android.
115
+ */
116
+ primary: string;
117
+ /** The color used for the background of your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
118
+ * @default The System background color on iOS, and "#ffffff" (light) / "#2e2e2e" (dark) on Android.
119
+ */
120
+ background: string;
121
+ /** The color used for the background of inputs, tabs, and other components in your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
122
+ * @default The System background color (light) / System secondary background color (dark) on iOS, and "#ffffff" (light) / "#a9a9a9" (dark) on Android.
123
+ */
124
+ componentBackground: string;
125
+ /** The color used for the external border of inputs, tabs, and other components in your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
126
+ * @default The System gray (3) color on iOS, and "#33787880" (light) / "#787880" (dark) on Android.
127
+ */
128
+ componentBorder: string;
129
+ /** The color used for the internal border (meaning the border is shared with another component) of inputs, tabs, and other components in your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
130
+ * @default The System gray (3) color on iOS, and "#33787880" (light) / "#787880" (dark) on Android.
131
+ */
132
+ componentDivider: string;
133
+ /** The color of the header text in your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
134
+ * @default The System label color on iOS, and "#000000" (light) / "#ffffff" (dark) on Android.
135
+ */
136
+ primaryText: string;
137
+ /** The color of the label text of input fields, represented as a hex string with format #RRGGBB or #AARRGGBB.
138
+ * @default The System seconday label color on iOS, and "#000000" (light) / "#ffffff" (dark) on Android.
139
+ */
140
+ secondaryText: string;
141
+ /** The color of the input text in your PaymentSheet components, such as the user's card number or zip code, represented as a hex string with format #RRGGBB or #AARRGGBB.
142
+ * @default "#000000"
143
+ */
144
+ componentText: string;
145
+ /** The color of the placeholder text of input fields, represented as a hex string with format #RRGGBB or #AARRGGBB.
146
+ * @default The System label color on iOS, and "#99000000" (light) / "#99ffffff" (dark) on Android.
147
+ */
148
+ placeholderText: string;
149
+ /** The color used for icons in your Payment Sheet, such as the close or back icons, represented as a hex string with format #RRGGBB or #AARRGGBB.
150
+ * @default The System seconday label color on iOS, and "#99000000" (light) / "#ffffff" (dark) on Android.
151
+ */
152
+ icon: string;
153
+ /** The color used to indicate errors or destructive actions in your Payment Sheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
154
+ * @default The System red color on iOS, and "#ff0000" (light) / "#ff0000" (dark) on Android.
155
+ */
156
+ error: string;
157
+ };
158
+
159
+ export type PrimaryButtonConfig = {
160
+ /** The font family used specifically for the primary button.
161
+ * @default The root `appearance.font.family`
162
+ */
163
+ font: Pick<FontConfig, 'family'>;
164
+ /** The colors used specifically for the primary button. Provide either a base config, or both `light` and `dark` configs, which will be useed based on whether the user is in Light or Dark mode. */
165
+ colors:
166
+ | PrimaryButtonColorConfig
167
+ | { light: PrimaryButtonColorConfig; dark: PrimaryButtonColorConfig };
168
+ /** Describes the border and shadow of the primary button. */
169
+ shapes: {
170
+ /** The border radius used for the primary button in your PaymentSheet
171
+ * @default The root `appearance.shapes.borderRadius`
172
+ */
173
+ borderRadius: number;
174
+ /** The border width used for the primary button in your PaymentSheet
175
+ * @default The root `appearance.shapes.borderWidth`
176
+ */
177
+ borderWidth: number;
178
+ /** iOS only. The shadow used for the primary button in your PaymentSheet
179
+ * @default The root `appearance.shapes.shadow`
180
+ */
181
+ shadow: ShadowConfig;
182
+ };
183
+ };
184
+
185
+ export type PrimaryButtonColorConfig = {
186
+ /** The background color used for the primary button in your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
187
+ * @default The root `appearance.colors.primary`
188
+ */
189
+ background: string;
190
+ /** The color of the text for the primary button in your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
191
+ * @default White or black, depending on the color of the button.
192
+ */
193
+ text: string;
194
+ /** The border color used for the primary button in your PaymentSheet, represented as a hex string with format #RRGGBB or #AARRGGBB.
195
+ * @default The System quaternary label on iOS, transparent on Android.
196
+ */
197
+ border: string;
198
+ };
199
+
200
+ type RecursivePartial<T> = {
201
+ [P in keyof T]?: T[P] extends (infer U)[]
202
+ ? RecursivePartial<U>[]
203
+ : T[P] extends object
204
+ ? RecursivePartial<T[P]>
205
+ : T[P];
206
+ };
50
207
  export interface PaymentOption {
51
208
  label: string;
52
209
  image: string;
@@ -50,8 +50,12 @@ export interface Card {
50
50
  name?: string;
51
51
  }
52
52
 
53
- export type CreateParams = CreateCardTokenParams | CreateBankAccountTokenParams;
53
+ export type CreateParams =
54
+ | CreateCardTokenParams
55
+ | CreateBankAccountTokenParams
56
+ | CreatePiiTokenParams;
54
57
 
58
+ /** Creates a single-use token that represents a credit card’s details. Use this in combination with either the CardField or CardForm components. This token can be used in place of a credit card object with any API method. See https://stripe.com/docs/api/tokens/create_card*/
55
59
  export type CreateCardTokenParams = {
56
60
  type: 'Card';
57
61
  address?: Address;
@@ -63,6 +67,7 @@ export type BankAcccountHolderType = 'Company' | 'Individual';
63
67
 
64
68
  export type BankAcccountType = 'Checking' | 'Savings';
65
69
 
70
+ /** Creates a single-use token that represents a bank account’s details. This token can be used with any API method in place of a bank account object. See https://stripe.com/docs/api/tokens/create_bank_account */
66
71
  export type CreateBankAccountTokenParams = {
67
72
  type: 'BankAccount';
68
73
  accountHolderName?: string;
@@ -72,3 +77,10 @@ export type CreateBankAccountTokenParams = {
72
77
  currency: string;
73
78
  routingNumber?: string;
74
79
  };
80
+
81
+ /** Creates a single-use token that represents the details of personally identifiable information (PII). See https://stripe.com/docs/api/tokens/create_pii */
82
+ export type CreatePiiTokenParams = {
83
+ type: 'Pii';
84
+ /** The user's personal ID number */
85
+ personalId: string;
86
+ };
@@ -59,6 +59,7 @@ export interface NativeProps {
59
59
  value?: Partial<Details>;
60
60
  postalCodeEnabled?: boolean;
61
61
  autofocus?: boolean;
62
+ countryCode: string | null;
62
63
  onCardChange(event: NativeSyntheticEvent<Details>): void;
63
64
  onFocusChange(
64
65
  event: NativeSyntheticEvent<{ focusedField: FieldName | null }>
@@ -44,6 +44,11 @@ export interface Placeholders {
44
44
  postalCode?: string;
45
45
  }
46
46
 
47
+ export type DefaultValues = {
48
+ /** The 2-letter country code for the country selected by default on Android. If this is null, it is set by the device's configured region in the Settings app. */
49
+ countryCode?: string;
50
+ };
51
+
47
52
  /**
48
53
  * @ignore
49
54
  */
@@ -54,6 +59,8 @@ export interface NativeProps {
54
59
  cardStyle?: Styles;
55
60
  /** Android only */
56
61
  placeholders?: Placeholders;
62
+ /** Android only */
63
+ defaultValues?: DefaultValues;
57
64
  // postalCodeEnabled: boolean;
58
65
  onFocusChange(
59
66
  event: NativeSyntheticEvent<{ focusedField: FieldName | null }>
@@ -140,11 +140,7 @@ export type InitPaymentSheetResult =
140
140
 
141
141
  export type PresentPaymentSheetResult =
142
142
  | {
143
- paymentOption?: undefined;
144
- error?: undefined;
145
- }
146
- | {
147
- paymentOption?: PaymentSheet.PaymentOption;
143
+ paymentOption: PaymentSheet.PaymentOption;
148
144
  error?: undefined;
149
145
  }
150
146
  | {
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
- stripe_version = '~> 22.3.0'
4
+ stripe_version = '~> 22.4.0'
5
5
 
6
6
  Pod::Spec.new do |s|
7
7
  s.name = 'stripe-react-native'
@@ -1,10 +0,0 @@
1
- package com.reactnativestripesdk
2
-
3
- var ON_PAYMENT_RESULT_ACTION = "com.reactnativestripesdk.PAYMENT_RESULT_ACTION"
4
- var ON_PAYMENT_OPTION_ACTION = "com.reactnativestripesdk.PAYMENT_OPTION_ACTION"
5
- var ON_CONFIGURE_FLOW_CONTROLLER = "com.reactnativestripesdk.CONFIGURE_FLOW_CONTROLLER_ACTION"
6
- var ON_INIT_PAYMENT_SHEET = "com.reactnativestripesdk.INIT_PAYMENT_SHEET"
7
-
8
- var ON_INIT_GOOGLE_PAY = "com.reactnativestripesdk.ON_INIT_GOOGLE_PAY"
9
- var ON_GOOGLE_PAY_RESULT = "com.reactnativestripesdk.ON_GOOGLE_PAY_RESULT"
10
- var ON_GOOGLE_PAYMENT_METHOD_RESULT = "com.reactnativestripesdk.ON_GOOGLE_PAYMENT_METHOD_RESULT"