@stripe/stripe-react-native 0.28.0 → 0.29.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 (106) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +2 -2
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +0 -5
  5. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +11 -27
  6. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +131 -6
  7. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +29 -6
  8. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +2 -0
  9. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +14 -1
  10. package/ios/ApplePayButtonView.swift +4 -18
  11. package/ios/ApplePayViewController.swift +1 -28
  12. package/ios/StripeSdk+PaymentSheet.swift +100 -10
  13. package/ios/StripeSdk.m +15 -29
  14. package/ios/StripeSdk.swift +27 -85
  15. package/jest/mock.js +0 -6
  16. package/lib/commonjs/NativeStripeSdk.js.map +1 -1
  17. package/lib/commonjs/components/ApplePayButtonNative.js.map +1 -1
  18. package/lib/commonjs/components/GooglePayButtonNative.js.map +1 -1
  19. package/lib/commonjs/functions.js +1 -1
  20. package/lib/commonjs/functions.js.map +1 -1
  21. package/lib/commonjs/hooks/useStripe.js +1 -1
  22. package/lib/commonjs/hooks/useStripe.js.map +1 -1
  23. package/lib/commonjs/index.js +1 -1
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/types/ApplePay.js.map +1 -1
  26. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  27. package/lib/commonjs/types/PaymentSheet.js +1 -1
  28. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  29. package/lib/commonjs/types/PlatformPay.js.map +1 -1
  30. package/lib/commonjs/types/components/GooglePayButtonComponent.js.map +1 -1
  31. package/lib/commonjs/types/index.js +1 -1
  32. package/lib/commonjs/types/index.js.map +1 -1
  33. package/lib/module/NativeStripeSdk.js.map +1 -1
  34. package/lib/module/components/ApplePayButtonNative.js.map +1 -1
  35. package/lib/module/components/GooglePayButtonNative.js.map +1 -1
  36. package/lib/module/functions.js +1 -1
  37. package/lib/module/functions.js.map +1 -1
  38. package/lib/module/hooks/useStripe.js +1 -1
  39. package/lib/module/hooks/useStripe.js.map +1 -1
  40. package/lib/module/index.js +1 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/types/ApplePay.js.map +1 -1
  43. package/lib/module/types/PaymentIntent.js.map +1 -1
  44. package/lib/module/types/PaymentSheet.js +1 -1
  45. package/lib/module/types/PaymentSheet.js.map +1 -1
  46. package/lib/module/types/PlatformPay.js.map +1 -1
  47. package/lib/module/types/components/GooglePayButtonComponent.js.map +1 -1
  48. package/lib/module/types/index.js +1 -1
  49. package/lib/module/types/index.js.map +1 -1
  50. package/lib/typescript/src/NativeStripeSdk.d.ts +4 -15
  51. package/lib/typescript/src/components/ApplePayButtonNative.d.ts +1 -1
  52. package/lib/typescript/src/components/GooglePayButtonNative.d.ts +1 -1
  53. package/lib/typescript/src/functions.d.ts +8 -27
  54. package/lib/typescript/src/hooks/usePlatformPay.d.ts +1 -1
  55. package/lib/typescript/src/hooks/useStripe.d.ts +2 -18
  56. package/lib/typescript/src/index.d.ts +0 -7
  57. package/lib/typescript/src/types/ApplePay.d.ts +0 -52
  58. package/lib/typescript/src/types/PaymentIntent.d.ts +3 -2
  59. package/lib/typescript/src/types/PaymentSheet.d.ts +48 -2
  60. package/lib/typescript/src/types/PlatformPay.d.ts +34 -4
  61. package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts +0 -1
  62. package/lib/typescript/src/types/index.d.ts +1 -4
  63. package/package.json +1 -1
  64. package/src/NativeStripeSdk.tsx +6 -31
  65. package/src/components/ApplePayButtonNative.tsx +1 -1
  66. package/src/components/GooglePayButtonNative.tsx +1 -1
  67. package/src/functions.ts +54 -200
  68. package/src/hooks/useStripe.tsx +2 -109
  69. package/src/index.tsx +0 -7
  70. package/src/types/ApplePay.ts +0 -71
  71. package/src/types/PaymentIntent.ts +4 -2
  72. package/src/types/PaymentSheet.ts +86 -2
  73. package/src/types/PlatformPay.ts +35 -4
  74. package/src/types/components/GooglePayButtonComponent.ts +0 -1
  75. package/src/types/index.ts +0 -6
  76. package/stripe-react-native.podspec +1 -1
  77. package/lib/commonjs/components/ApplePayButton.js +0 -2
  78. package/lib/commonjs/components/ApplePayButton.js.map +0 -1
  79. package/lib/commonjs/components/GooglePayButton.js +0 -2
  80. package/lib/commonjs/components/GooglePayButton.js.map +0 -1
  81. package/lib/commonjs/hooks/useApplePay.js +0 -2
  82. package/lib/commonjs/hooks/useApplePay.js.map +0 -1
  83. package/lib/commonjs/hooks/useGooglePay.js +0 -2
  84. package/lib/commonjs/hooks/useGooglePay.js.map +0 -1
  85. package/lib/commonjs/types/GooglePay.js +0 -2
  86. package/lib/commonjs/types/GooglePay.js.map +0 -1
  87. package/lib/module/components/ApplePayButton.js +0 -2
  88. package/lib/module/components/ApplePayButton.js.map +0 -1
  89. package/lib/module/components/GooglePayButton.js +0 -2
  90. package/lib/module/components/GooglePayButton.js.map +0 -1
  91. package/lib/module/hooks/useApplePay.js +0 -2
  92. package/lib/module/hooks/useApplePay.js.map +0 -1
  93. package/lib/module/hooks/useGooglePay.js +0 -2
  94. package/lib/module/hooks/useGooglePay.js.map +0 -1
  95. package/lib/module/types/GooglePay.js +0 -2
  96. package/lib/module/types/GooglePay.js.map +0 -1
  97. package/lib/typescript/src/components/ApplePayButton.d.ts +0 -31
  98. package/lib/typescript/src/components/GooglePayButton.d.ts +0 -26
  99. package/lib/typescript/src/hooks/useApplePay.d.ts +0 -54
  100. package/lib/typescript/src/hooks/useGooglePay.d.ts +0 -11
  101. package/lib/typescript/src/types/GooglePay.d.ts +0 -47
  102. package/src/components/ApplePayButton.tsx +0 -108
  103. package/src/components/GooglePayButton.tsx +0 -58
  104. package/src/hooks/useApplePay.tsx +0 -161
  105. package/src/hooks/useGooglePay.tsx +0 -72
  106. package/src/types/GooglePay.ts +0 -74
@@ -1,108 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import ApplePayButtonNative from './ApplePayButtonNative';
3
- import type { AccessibilityProps, StyleProp, ViewStyle } from 'react-native';
4
- import type { ApplePayButtonComponent } from '../types';
5
-
6
- /**
7
- * Apple Pay Button Component Props
8
- */
9
- export interface Props extends AccessibilityProps {
10
- style?: StyleProp<ViewStyle>;
11
- type?: ApplePayButtonComponent.Type;
12
- buttonStyle?: ApplePayButtonComponent.Style;
13
- borderRadius?: number;
14
- onPress(): void;
15
- testID?: string;
16
- }
17
-
18
- /**
19
- * Apple Pay Button Component
20
- *
21
- * @example
22
- * ```ts
23
- * <ApplePayButton
24
- * onPress={pay}
25
- * type="plain"
26
- * buttonStyle="black"
27
- * borderRadius={4}
28
- * style={styles.payButton}
29
- * />
30
- * ```
31
- * @param __namedParameters Props
32
- * @returns JSX.Element
33
- * @category ReactComponents
34
- */
35
- export function ApplePayButton({
36
- onPress,
37
- buttonStyle = 'black',
38
- type = 'plain',
39
- borderRadius = 4,
40
- ...props
41
- }: Props) {
42
- const buttonType = useMemo(() => mapButtonType(type), [type]);
43
- const style = useMemo(() => mapButtonStyle(buttonStyle), [buttonStyle]);
44
-
45
- return (
46
- <ApplePayButtonNative
47
- type={buttonType}
48
- buttonStyle={style}
49
- borderRadius={borderRadius}
50
- onPressAction={onPress}
51
- {...props}
52
- />
53
- );
54
- }
55
-
56
- function mapButtonType(type: ApplePayButtonComponent.Type) {
57
- switch (type) {
58
- case 'plain':
59
- return 0;
60
- case 'buy':
61
- return 1;
62
- case 'setUp':
63
- return 2;
64
- case 'inStore':
65
- return 3;
66
- case 'donate':
67
- return 4;
68
- case 'checkout':
69
- return 5;
70
- case 'book':
71
- return 6;
72
- case 'subscribe':
73
- return 7;
74
- case 'reload':
75
- return 8;
76
- case 'addMoney':
77
- return 9;
78
- case 'topUp':
79
- return 10;
80
- case 'order':
81
- return 11;
82
- case 'rent':
83
- return 12;
84
- case 'support':
85
- return 13;
86
- case 'contribute':
87
- return 14;
88
- case 'tip':
89
- return 15;
90
- default:
91
- return 0;
92
- }
93
- }
94
-
95
- function mapButtonStyle(type: ApplePayButtonComponent.Style) {
96
- switch (type) {
97
- case 'white':
98
- return 0;
99
- case 'whiteOutline':
100
- return 1;
101
- case 'black':
102
- return 2;
103
- case 'automatic':
104
- return 3;
105
- default:
106
- return 2;
107
- }
108
- }
@@ -1,58 +0,0 @@
1
- import React from 'react';
2
- import {
3
- AccessibilityProps,
4
- StyleProp,
5
- ViewStyle,
6
- TouchableOpacity,
7
- StyleSheet,
8
- } from 'react-native';
9
- import GooglePayButtonNative from './GooglePayButtonNative';
10
-
11
- /**
12
- * Google Pay Button Component Props
13
- */
14
- export interface Props extends AccessibilityProps {
15
- style?: StyleProp<ViewStyle>;
16
- type?: 'pay' | 'standard';
17
- onPress(): void;
18
- disabled?: boolean;
19
- testID?: string;
20
- }
21
-
22
- /**
23
- * Google Pay Button Component
24
- *
25
- * @example
26
- * ```ts
27
- * <GooglePayButton
28
- * onPress={pay}
29
- * style={styles.payButton}
30
- * />
31
- * ```
32
- * @param __namedParameters Props
33
- * @returns JSX.Element
34
- * @category ReactComponents
35
- */
36
- export function GooglePayButton({
37
- type = 'pay',
38
- onPress,
39
- disabled,
40
- ...props
41
- }: Props) {
42
- return (
43
- <TouchableOpacity
44
- disabled={disabled}
45
- activeOpacity={1}
46
- onPress={onPress}
47
- style={disabled ? styles.disabled : {}}
48
- >
49
- <GooglePayButtonNative buttonType={type} {...props} />
50
- </TouchableOpacity>
51
- );
52
- }
53
-
54
- const styles = StyleSheet.create({
55
- disabled: {
56
- opacity: 0.3,
57
- },
58
- });
@@ -1,161 +0,0 @@
1
- import type { ApplePay, ApplePayError, StripeError } from '../types';
2
- import { useCallback, useEffect, useState } from 'react';
3
- import { useStripe } from './useStripe';
4
- import { NativeEventEmitter, NativeModules } from 'react-native';
5
-
6
- export interface Props {
7
- /**
8
- *
9
- * @example
10
- * ```ts
11
- * const { presentApplePay } = useApplePay({
12
- * onShippingMethodSelected: (shippingMethod, handler) => {
13
- * handler([
14
- * { label: 'Example item name 1', amount: '11.00' },
15
- * { label: 'Example item name 2', amount: '25.00' },
16
- * ]);
17
- * }
18
- * })
19
- * ```
20
- */
21
- onShippingMethodSelected?: (
22
- shippingMethod: ApplePay.ShippingMethod,
23
- handler: (summaryItems: ApplePay.CartSummaryItem[]) => Promise<{
24
- error?: StripeError<ApplePayError>;
25
- }>
26
- ) => void;
27
- /**
28
- *
29
- * @example
30
- * ```ts
31
- * const { presentApplePay } = useApplePay({
32
- * onShippingContactSelected: (shippingContact, handler) => {
33
- * handler([
34
- * { label: 'Example item name 1', amount: '11.00' },
35
- * { label: 'Example item name 2', amount: '25.00' },
36
- * ], [
37
- * { field: 'city', message: 'city error' },
38
- * ]);
39
- * }
40
- * })
41
- * ```
42
- */
43
- onShippingContactSelected?: (
44
- shippingContact: ApplePay.ShippingContact,
45
- handler: (
46
- summaryItems: ApplePay.CartSummaryItem[],
47
- errorAddressFields?: Array<{
48
- field: ApplePay.AddressFields;
49
- message?: string;
50
- }>
51
- ) => Promise<{
52
- error?: StripeError<ApplePayError>;
53
- }>
54
- ) => void;
55
- }
56
-
57
- const SET_SHIPPING_METHOD_CALLBACK_NAME = 'onDidSetShippingMethod';
58
- const SET_SHIPPING_CONTACT_CALLBACK_NAME = 'onDidSetShippingContact';
59
-
60
- /**
61
- * useApplePay hook
62
- */
63
- export function useApplePay({
64
- onShippingMethodSelected,
65
- onShippingContactSelected,
66
- }: Props = {}) {
67
- const {
68
- isApplePaySupported,
69
- presentApplePay: _presentApplePay,
70
- confirmApplePayPayment: _confirmApplePayPayment,
71
- updateApplePaySummaryItems,
72
- openApplePaySetup: _openApplePaySetup,
73
- } = useStripe();
74
- const [items, setItems] = useState<ApplePay.CartSummaryItem[] | null>(null);
75
- const [loading, setLoading] = useState(false);
76
-
77
- const onDidSetShippingMethod = useCallback(
78
- (result: { shippingMethod: ApplePay.ShippingMethod }) => {
79
- if (onShippingMethodSelected) {
80
- onShippingMethodSelected(
81
- result.shippingMethod,
82
- updateApplePaySummaryItems
83
- );
84
- } else {
85
- updateApplePaySummaryItems(items as ApplePay.CartSummaryItem[]);
86
- }
87
- },
88
- [items, onShippingMethodSelected, updateApplePaySummaryItems]
89
- );
90
-
91
- const onDidSetShippingContact = useCallback(
92
- (result: { shippingContact: ApplePay.ShippingContact }) => {
93
- if (onShippingContactSelected) {
94
- onShippingContactSelected(
95
- result.shippingContact,
96
- updateApplePaySummaryItems
97
- );
98
- } else {
99
- updateApplePaySummaryItems(items as ApplePay.CartSummaryItem[]);
100
- }
101
- },
102
- [items, onShippingContactSelected, updateApplePaySummaryItems]
103
- );
104
-
105
- useEffect(() => {
106
- const eventEmitter = new NativeEventEmitter(NativeModules.StripeSdk);
107
- const didSetShippingMethodListener = eventEmitter.addListener(
108
- SET_SHIPPING_METHOD_CALLBACK_NAME,
109
- onDidSetShippingMethod
110
- );
111
- const didSetShippingContactListener = eventEmitter.addListener(
112
- SET_SHIPPING_CONTACT_CALLBACK_NAME,
113
- onDidSetShippingContact
114
- );
115
-
116
- return () => {
117
- didSetShippingMethodListener.remove();
118
- didSetShippingContactListener.remove();
119
- };
120
- }, [onDidSetShippingContact, onDidSetShippingMethod]);
121
-
122
- const presentApplePay = useCallback(
123
- async (params: ApplePay.PresentParams) => {
124
- setLoading(true);
125
- setItems(params.cartItems);
126
- const result = await _presentApplePay(params);
127
- if (result.error) {
128
- setItems(null);
129
- }
130
- setLoading(false);
131
- return result;
132
- },
133
- [_presentApplePay]
134
- );
135
-
136
- const openApplePaySetup = useCallback(async () => {
137
- setLoading(true);
138
- const result = await _openApplePaySetup();
139
- setLoading(false);
140
- return result;
141
- }, [_openApplePaySetup]);
142
-
143
- const confirmApplePayPayment = useCallback(
144
- async (clientSecret: string) => {
145
- setLoading(true);
146
- const result = await _confirmApplePayPayment(clientSecret);
147
- setItems(null);
148
- setLoading(false);
149
- return result;
150
- },
151
- [_confirmApplePayPayment]
152
- );
153
-
154
- return {
155
- loading,
156
- presentApplePay,
157
- confirmApplePayPayment,
158
- isApplePaySupported,
159
- openApplePaySetup,
160
- };
161
- }
@@ -1,72 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import type { GooglePay } from '../types';
3
- import { useStripe } from './useStripe';
4
-
5
- /**
6
- * useGooglePay hook
7
- */
8
- export function useGooglePay() {
9
- const {
10
- isGooglePaySupported,
11
- initGooglePay,
12
- presentGooglePay,
13
- createGooglePayPaymentMethod,
14
- } = useStripe();
15
- const [loading, setLoading] = useState(false);
16
-
17
- const _isGooglePaySupported = useCallback(
18
- async (params?: GooglePay.IsSupportedParams) => {
19
- setLoading(true);
20
-
21
- const result = await isGooglePaySupported(params);
22
- setLoading(false);
23
-
24
- return result;
25
- },
26
- [isGooglePaySupported]
27
- );
28
-
29
- const _initGooglePay = useCallback(
30
- async (params: GooglePay.InitParams) => {
31
- setLoading(true);
32
-
33
- const result = await initGooglePay(params);
34
- setLoading(false);
35
-
36
- return result;
37
- },
38
- [initGooglePay]
39
- );
40
-
41
- const _presentGooglePay = useCallback(
42
- async (params: GooglePay.PresentParams) => {
43
- setLoading(true);
44
-
45
- const result = await presentGooglePay(params);
46
- setLoading(false);
47
-
48
- return result;
49
- },
50
- [presentGooglePay]
51
- );
52
-
53
- const _createGooglePayPaymentMethod = useCallback(
54
- async (params: GooglePay.CreatePaymentMethodParams) => {
55
- setLoading(true);
56
-
57
- const result = await createGooglePayPaymentMethod(params);
58
- setLoading(false);
59
-
60
- return result;
61
- },
62
- [createGooglePayPaymentMethod]
63
- );
64
-
65
- return {
66
- loading,
67
- isGooglePaySupported: _isGooglePaySupported,
68
- initGooglePay: _initGooglePay,
69
- presentGooglePay: _presentGooglePay,
70
- createGooglePayPaymentMethod: _createGooglePayPaymentMethod,
71
- };
72
- }
@@ -1,74 +0,0 @@
1
- export type PresentParams = PresentType & {
2
- clientSecret: string;
3
- };
4
-
5
- export type PresentType =
6
- | {
7
- /*
8
- * Present Google Pay to collect customer payment details and use it to confirm the
9
- * [SetupIntent] represented by [clientSecret].
10
- */
11
- forSetupIntent?: true;
12
- /*
13
- * The Google Pay API requires a [currencyCode](https://developers.google.com/pay/api/android/reference/request-objects#TransactionInfo).
14
- * [currencyCode] is required even though the SetupIntent API does not require it.
15
- */
16
- currencyCode: string;
17
- }
18
- | {
19
- /*
20
- * Present Google Pay to collect customer payment details and use it to confirm the
21
- * [PaymentIntent] represented by [clientSecret].
22
- */
23
- forSetupIntent?: false;
24
- };
25
-
26
- export type InitParams = {
27
- merchantName: string;
28
- countryCode: string;
29
- /**
30
- * Billing address collection configuration.
31
- */
32
- billingAddressConfig?: BillingAddressConfig;
33
- /**
34
- * Flag to indicate whether Google Pay collect the customer's email address.
35
- *
36
- * Default to `false`.
37
- */
38
- isEmailRequired?: boolean;
39
- } & IsSupportedParams;
40
-
41
- export type IsSupportedParams = {
42
- /** Set to true to run in a test environment with relaxed application / merchant requirements. This environment is suggested for early development and for easily testing SDK. Defaults to false. */
43
- testEnv?: boolean;
44
- /**
45
- * If `true`, Google Pay is considered ready if the customer's Google Pay wallet
46
- * has an existing payment method. Defaults to false.
47
- */
48
- existingPaymentMethodRequired?: boolean;
49
- };
50
-
51
- export interface BillingAddressConfig {
52
- isRequired?: boolean;
53
- /**
54
- * Billing address format required to complete the transaction.
55
- */
56
- format?: 'FULL' | 'MIN';
57
- /**
58
- * Set to true if a phone number is required to process the transaction.
59
- */
60
- isPhoneNumberRequired?: boolean;
61
- }
62
-
63
- export interface CreatePaymentMethodParams {
64
- /*
65
- * ISO 4217 alphabetic currency code. (e.g. "USD", "EUR")
66
- */
67
- currencyCode: string;
68
- /*
69
- * Amount intended to be collected. A positive integer representing how much to
70
- * charge in the smallest currency unit (e.g., 100 cents to charge $1.00 or 100 to charge ¥100,
71
- * a zero-decimal currency).
72
- */
73
- amount: number;
74
- }