@stripe/stripe-react-native 0.64.0 → 0.64.1
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.
- package/README.md +2 -2
- package/android/build.gradle +2 -2
- package/android/detekt/detekt-baseline.xml +81 -0
- package/android/detekt/detekt.gradle +45 -0
- package/android/detekt/detekt.yml +722 -0
- package/android/gradle.properties +4 -4
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +3 -1
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormViewManager.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +5 -1
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementView.kt +26 -0
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementViewManager.kt +42 -0
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +105 -49
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +72 -12
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetManager.kt +8 -4
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +26 -11
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/NavigationBarView.kt +14 -5
- package/android/src/main/java/com/reactnativestripesdk/PaymentElementConfig.kt +6 -2
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherManager.kt +2 -2
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodMessagingElementConfig.kt +7 -4
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodMessagingElementViewManager.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +8 -4
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +9 -3
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +110 -29
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +250 -12
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +1 -0
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherManager.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +3 -1
- package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +6 -2
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +3 -1
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutAddressUpdate.kt +45 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutMappers.kt +101 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +4 -2
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +5 -1
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +29 -17
- package/android/src/main/java/com/reactnativestripesdk/utils/PostalCodeUtilities.kt +2 -1
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerDelegate.java +6 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java +2 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeCurrencySelectorElementManagerDelegate.java +35 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeCurrencySelectorElementManagerInterface.java +18 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +44 -0
- package/android/src/test/java/com/reactnativestripesdk/PaymentMethodMessagingElementConfigTest.kt +3 -3
- package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +60 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/OnrampMappersTest.kt +38 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/PaymentOptionDisplayDataMapperTest.kt +9 -4
- package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutMappersTest.kt +89 -0
- package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutTestFixtures.java +49 -0
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewController.swift +6 -8
- package/ios/CurrencySelectorElementManager.m +9 -0
- package/ios/CurrencySelectorElementManager.swift +12 -0
- package/ios/CurrencySelectorElementView.swift +24 -0
- package/ios/Mappers+Checkout.swift +193 -0
- package/ios/Mappers.swift +0 -5
- package/ios/NewArch/EmbeddedPaymentElementViewComponentView.mm +16 -2
- package/ios/NewArch/StripeCurrencySelectorElementComponentView.h +10 -0
- package/ios/NewArch/StripeCurrencySelectorElementComponentView.mm +75 -0
- package/ios/PaymentMethodMessagingElementConfig.swift +6 -3
- package/ios/PaymentMethodMessagingElementView.swift +19 -0
- package/ios/StripeSdk.mm +123 -0
- package/ios/StripeSdkImpl+Checkout.swift +308 -0
- package/ios/StripeSdkImpl+Embedded.swift +108 -27
- package/ios/StripeSdkImpl+PaymentSheet.swift +18 -2
- package/ios/StripeSdkImpl.swift +3 -93
- package/jest/mock.js +14 -1
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/AddressSheet.js +1 -1
- package/lib/commonjs/components/AddressSheet.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/components/CardField.js +1 -1
- package/lib/commonjs/components/CardField.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/CurrencySelectorElement.js +2 -0
- package/lib/commonjs/components/CurrencySelectorElement.js.map +1 -0
- package/lib/commonjs/components/PaymentMethodMessagingElement.js +2 -0
- package/lib/commonjs/components/PaymentMethodMessagingElement.js.map +1 -0
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/connect/Components.js +1 -1
- package/lib/commonjs/connect/Components.js.map +1 -1
- package/lib/commonjs/connect/ConnectComponentsProvider.js +1 -1
- package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -1
- package/lib/commonjs/connect/EmbeddedComponent.js +1 -1
- package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -1
- package/lib/commonjs/connect/ModalCloseButton.js +1 -1
- package/lib/commonjs/connect/ModalCloseButton.js.map +1 -1
- package/lib/commonjs/connect/NavigationBar.js +1 -1
- package/lib/commonjs/connect/NavigationBar.js.map +1 -1
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/helpers.js +1 -1
- package/lib/commonjs/hooks/useCheckout.js +2 -0
- package/lib/commonjs/hooks/useCheckout.js.map +1 -0
- package/lib/commonjs/hooks/useOnramp.js +1 -1
- package/lib/commonjs/hooks/useOnramp.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
- package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js.map +1 -1
- package/lib/commonjs/specs/NativeCardForm.js +1 -1
- package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
- package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +1 -1
- package/lib/commonjs/specs/NativeCurrencySelectorElement.js +2 -0
- package/lib/commonjs/specs/NativeCurrencySelectorElement.js.map +1 -0
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
- package/lib/commonjs/specs/NativeNavigationBar.js +1 -1
- package/lib/commonjs/specs/NativePaymentMethodMessagingElement.js +1 -1
- package/lib/commonjs/specs/NativePaymentMethodMessagingElement.js.map +1 -1
- package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/commonjs/types/Checkout.js +2 -0
- package/lib/commonjs/types/Checkout.js.map +1 -0
- package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/AddressSheet.js +1 -1
- package/lib/module/components/AddressSheet.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.js.map +1 -1
- package/lib/module/components/CardField.js +1 -1
- package/lib/module/components/CardField.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/CurrencySelectorElement.js +2 -0
- package/lib/module/components/CurrencySelectorElement.js.map +1 -0
- package/lib/module/components/PaymentMethodMessagingElement.js +2 -0
- package/lib/module/components/PaymentMethodMessagingElement.js.map +1 -0
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/connect/Components.js +1 -1
- package/lib/module/connect/Components.js.map +1 -1
- package/lib/module/connect/ConnectComponentsProvider.js +1 -1
- package/lib/module/connect/ConnectComponentsProvider.js.map +1 -1
- package/lib/module/connect/EmbeddedComponent.js +1 -1
- package/lib/module/connect/EmbeddedComponent.js.map +1 -1
- package/lib/module/connect/ModalCloseButton.js +1 -1
- package/lib/module/connect/ModalCloseButton.js.map +1 -1
- package/lib/module/connect/NavigationBar.js +1 -1
- package/lib/module/connect/NavigationBar.js.map +1 -1
- package/lib/module/events.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/helpers.js +1 -1
- package/lib/module/hooks/useCheckout.js +2 -0
- package/lib/module/hooks/useCheckout.js.map +1 -0
- package/lib/module/hooks/useOnramp.js +1 -1
- package/lib/module/hooks/useOnramp.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js +1 -1
- package/lib/module/specs/NativeAddressSheet.js +1 -1
- package/lib/module/specs/NativeApplePayButton.js +1 -1
- package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/module/specs/NativeCardField.js +1 -1
- package/lib/module/specs/NativeCardField.js.map +1 -1
- package/lib/module/specs/NativeCardForm.js +1 -1
- package/lib/module/specs/NativeCardForm.js.map +1 -1
- package/lib/module/specs/NativeConnectAccountOnboardingView.js +1 -1
- package/lib/module/specs/NativeCurrencySelectorElement.js +2 -0
- package/lib/module/specs/NativeCurrencySelectorElement.js.map +1 -0
- package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/module/specs/NativeGooglePayButton.js +1 -1
- package/lib/module/specs/NativeNavigationBar.js +1 -1
- package/lib/module/specs/NativePaymentMethodMessagingElement.js +1 -1
- package/lib/module/specs/NativePaymentMethodMessagingElement.js.map +1 -1
- package/lib/module/specs/NativeStripeContainer.js +1 -1
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/module/types/Checkout.js +2 -0
- package/lib/module/types/Checkout.js.map +1 -0
- package/lib/module/types/EmbeddedPaymentElement.js +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/typescript/src/components/CurrencySelectorElement.d.ts +62 -0
- package/lib/typescript/src/components/CurrencySelectorElement.d.ts.map +1 -0
- package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts +41 -0
- package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts.map +1 -0
- package/lib/typescript/src/events.d.ts +11 -0
- package/lib/typescript/src/events.d.ts.map +1 -1
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCheckout.d.ts +21 -0
- package/lib/typescript/src/hooks/useCheckout.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useOnramp.d.ts +1 -0
- package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeCurrencySelectorElement.d.ts +25 -0
- package/lib/typescript/src/specs/NativeCurrencySelectorElement.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts +5 -1
- package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePaymentMethodMessagingElement.d.ts +1 -6
- package/lib/typescript/src/specs/NativePaymentMethodMessagingElement.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +16 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/types/Checkout.d.ts +336 -0
- package/lib/typescript/src/types/Checkout.d.ts.map +1 -0
- package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +36 -1
- package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentMethod.d.ts +1 -5
- package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentSheet.d.ts +22 -6
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
- package/lib/typescript/src/types/components/PaymentMethodMessagingElementComponent.d.ts +16 -1
- package/lib/typescript/src/types/components/PaymentMethodMessagingElementComponent.d.ts.map +1 -1
- package/package.json +21 -7
- package/src/components/CurrencySelectorElement.tsx +95 -0
- package/src/components/PaymentMethodMessagingElement.tsx +109 -0
- package/src/events.ts +11 -0
- package/src/functions.ts +30 -1
- package/src/hooks/useCheckout.tsx +207 -0
- package/src/hooks/useOnramp.tsx +9 -3
- package/src/index.tsx +4 -0
- package/src/specs/NativeCurrencySelectorElement.ts +35 -0
- package/src/specs/NativeEmbeddedPaymentElement.ts +12 -2
- package/src/specs/NativePaymentMethodMessagingElement.ts +0 -7
- package/src/specs/NativeStripeSdkModule.ts +58 -1
- package/src/types/Checkout.ts +377 -0
- package/src/types/EmbeddedPaymentElement.tsx +117 -26
- package/src/types/PaymentMethod.ts +0 -6
- package/src/types/PaymentSheet.ts +29 -6
- package/src/types/components/PaymentMethodMessagingElementComponent.tsx +17 -1
- package/stripe-react-native.podspec +8 -8
- package/android/spotless.gradle +0 -19
|
@@ -22,9 +22,24 @@ export declare enum PaymentMethodMessagingElementStyle {
|
|
|
22
22
|
/** A light style */
|
|
23
23
|
Light = "light"
|
|
24
24
|
}
|
|
25
|
+
export interface PaymentMethodMessagingElementFont {
|
|
26
|
+
/**
|
|
27
|
+
* The font used for the element text.
|
|
28
|
+
*
|
|
29
|
+
* On iOS, this should be the "PostScript name" found in Font Book after installing the font.
|
|
30
|
+
* On Android, this should be the name of the font file (containing only lowercase alphanumeric characters) in android/app/src/main/res/font
|
|
31
|
+
*
|
|
32
|
+
* @default The OS's system font
|
|
33
|
+
*/
|
|
34
|
+
family?: string;
|
|
35
|
+
/** The font size for text in the element. This value is required to be greater than 0.
|
|
36
|
+
* @default The OS's default text size.
|
|
37
|
+
*/
|
|
38
|
+
size?: number;
|
|
39
|
+
}
|
|
25
40
|
export interface PaymentMethodMessagingElementAppearance {
|
|
26
41
|
/** Font settings for the element. */
|
|
27
|
-
font?:
|
|
42
|
+
font?: PaymentMethodMessagingElementFont;
|
|
28
43
|
/** The color used for the element text. */
|
|
29
44
|
textColor?: PaymentSheetTypes.ThemedColor;
|
|
30
45
|
/** The color used for the text that links to available BNPL plans. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentMethodMessagingElementComponent.d.ts","sourceRoot":"","sources":["../../../../../src/types/components/PaymentMethodMessagingElementComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,KAAK,iBAAiB,MAAM,iBAAiB,CAAC;AAMrD;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC1C;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEvC,qDAAqD;AACrD,oBAAY,kCAAkC;IAC5C,mBAAmB;IACnB,IAAI,SAAS;IACb,mBAAmB;IACnB,IAAI,SAAS;IACb,oBAAoB;IACpB,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,uCAAuC;IACtD,qCAAqC;IACrC,IAAI,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"PaymentMethodMessagingElementComponent.d.ts","sourceRoot":"","sources":["../../../../../src/types/components/PaymentMethodMessagingElementComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,KAAK,iBAAiB,MAAM,iBAAiB,CAAC;AAMrD;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC1C;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEvC,qDAAqD;AACrD,oBAAY,kCAAkC;IAC5C,mBAAmB;IACnB,IAAI,SAAS;IACb,mBAAmB;IACnB,IAAI,SAAS;IACb,oBAAoB;IACpB,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,iCAAiC;IAChD;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,uCAAuC;IACtD,qCAAqC;IACrC,IAAI,CAAC,EAAE,iCAAiC,CAAC;IACzC,2CAA2C;IAC3C,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC;IAC1C,sEAAsE;IACtE,aAAa,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC;IAC9C,wDAAwD;IACxD,KAAK,CAAC,EAAE,kCAAkC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,0CAA0C;IACzD,sGAAsG;IACtG,MAAM,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2HAA2H;IAC3H,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;IACpD,MAAM,EAAE,kCAAkC,CAAC;CAC5C,CAAC,CAAC;AAEH,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,uCAAuC,CAAC;IACrD,aAAa,EAAE,0CAA0C,CAAC;IAC1D,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stripe/stripe-react-native",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.1",
|
|
4
4
|
"author": "Stripe",
|
|
5
5
|
"description": "Stripe SDK for React Native",
|
|
6
6
|
"main": "lib/commonjs/index",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"update-pods": "cd example/ios && pod update Stripe StripeApplePay StripeFinancialConnections StripePayments StripePaymentSheet StripePaymentsUI StripeCore StripeUICore StripeCryptoOnramp",
|
|
20
20
|
"bootstrap": "yarn example && yarn && yarn pods",
|
|
21
21
|
"bootstrap-no-pods": "yarn example && yarn",
|
|
22
|
-
"docs": "yarn typedoc ./src/index.tsx --out ./docs/api-reference --tsconfig ./tsconfig.json --readme none --sort source-order",
|
|
22
|
+
"docs": "yarn typedoc ./src/index.tsx --out ./docs/api-reference --tsconfig ./tsconfig.json --readme none --sort source-order --excludeInternal",
|
|
23
23
|
"run-example-ios": "cd example && yarn ios --simulator \"iPhone 16 Pro Max\"",
|
|
24
24
|
"run-example-ios:release": "cd example && yarn build:ios && yarn ios --mode Release --simulator \"iPhone 16 Pro Max\" --no-packager",
|
|
25
25
|
"run-example-android": "cd example && yarn android",
|
|
@@ -30,11 +30,15 @@
|
|
|
30
30
|
"test:unit:android": "cd example/android && ./gradlew :stripe_stripe-react-native:testDebugUnitTest",
|
|
31
31
|
"test-ios": "maestro test -e APP_ID=com.stripe.react.native",
|
|
32
32
|
"test-android": "maestro test -e APP_ID=com.stripe.react.native",
|
|
33
|
-
"format:android:check": "cd android && ./gradlew
|
|
34
|
-
"format:android:write": "cd android && ./gradlew
|
|
35
|
-
"lint:android": "cd android && ./gradlew
|
|
33
|
+
"format:android:check": "cd android && ./gradlew detekt",
|
|
34
|
+
"format:android:write": "cd android && ./gradlew detektFormat",
|
|
35
|
+
"lint:android": "cd android && ./gradlew detekt",
|
|
36
36
|
"format:ios:check": "swiftlint ios --config .swiftlint.yml --strict",
|
|
37
|
-
"format:ios:write": "./scripts/format-changed-ios"
|
|
37
|
+
"format:ios:write": "./scripts/format-changed-ios",
|
|
38
|
+
"test:package-types": "attw --pack .",
|
|
39
|
+
"prepublishOnly": "echo \"\\nPlease use ./scripts/publish instead\\n\" && exit 1",
|
|
40
|
+
"api-extractor:update": "bob build && api-extractor run --local --verbose",
|
|
41
|
+
"api-extractor:check": "bob build && api-extractor run --verbose"
|
|
38
42
|
},
|
|
39
43
|
"files": [
|
|
40
44
|
"src",
|
|
@@ -68,7 +72,9 @@
|
|
|
68
72
|
},
|
|
69
73
|
"homepage": "https://github.com/stripe/stripe-react-native/#readme",
|
|
70
74
|
"devDependencies": {
|
|
75
|
+
"@arethetypeswrong/cli": "^0.17.0",
|
|
71
76
|
"@expo/config-plugins": "^9.0.16",
|
|
77
|
+
"@microsoft/api-extractor": "^7.58.7",
|
|
72
78
|
"@react-native/babel-preset": "^0.81.0",
|
|
73
79
|
"@react-native/eslint-config": "^0.81.1",
|
|
74
80
|
"@testing-library/react-hooks": "^8.0.1",
|
|
@@ -80,6 +86,7 @@
|
|
|
80
86
|
"eslint-plugin-prettier": "^5.1.3",
|
|
81
87
|
"husky": "^9.1.7",
|
|
82
88
|
"jest": "^29.2.1",
|
|
89
|
+
"lint-staged": "^16.4.0",
|
|
83
90
|
"prettier": "^3.5.2",
|
|
84
91
|
"react": "19.1.0",
|
|
85
92
|
"react-native": "^0.81.0",
|
|
@@ -172,6 +179,12 @@
|
|
|
172
179
|
"typescript"
|
|
173
180
|
]
|
|
174
181
|
},
|
|
182
|
+
"lint-staged": {
|
|
183
|
+
"*.{js,ts,tsx}": "eslint --ignore-path .gitignore",
|
|
184
|
+
"*.{ts,tsx}": "bash -c 'yarn typescript'",
|
|
185
|
+
"*.kt": "bash -c 'yarn format:android:write'",
|
|
186
|
+
"*.swift": "bash -c 'yarn format:ios:write'"
|
|
187
|
+
},
|
|
175
188
|
"resolutions": {
|
|
176
189
|
"simple-plist": "1.3.1"
|
|
177
190
|
},
|
|
@@ -189,7 +202,8 @@
|
|
|
189
202
|
"CardForm": "CardFormComponentView",
|
|
190
203
|
"EmbeddedPaymentElementView": "EmbeddedPaymentElementViewComponentView",
|
|
191
204
|
"NavigationBar": "NavigationBarComponentView",
|
|
192
|
-
"StripeContainer": "StripeContainerComponentView"
|
|
205
|
+
"StripeContainer": "StripeContainerComponentView",
|
|
206
|
+
"StripeCurrencySelectorElement": "StripeCurrencySelectorElementComponentView"
|
|
193
207
|
}
|
|
194
208
|
},
|
|
195
209
|
"name": "rnstripe",
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
AccessibilityProps,
|
|
4
|
+
LayoutAnimation,
|
|
5
|
+
NativeSyntheticEvent,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import type { Checkout } from '../types/Checkout';
|
|
8
|
+
import NativeCurrencySelectorElement, {
|
|
9
|
+
type HeightChangeEvent,
|
|
10
|
+
} from '../specs/NativeCurrencySelectorElement';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Props for {@link CurrencySelectorElement}.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export interface CurrencySelectorElementProps extends AccessibilityProps {
|
|
17
|
+
/**
|
|
18
|
+
* The `Checkout` handle returned by `useCheckout`.
|
|
19
|
+
*
|
|
20
|
+
* The element reads currency options from this session and calls
|
|
21
|
+
* `selectCurrency` internally — you never call it yourself.
|
|
22
|
+
*/
|
|
23
|
+
checkout: Checkout;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* When `true`, the toggle is visible but does not respond to taps.
|
|
27
|
+
*
|
|
28
|
+
* Tip: pass `disabled={state?.status === 'loading'}` to freeze the
|
|
29
|
+
* selector while an unrelated mutation (e.g. applying a promo code)
|
|
30
|
+
* is in flight. The element also disables itself automatically
|
|
31
|
+
* during its own currency-selection network call.
|
|
32
|
+
*
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A self-contained currency selector for Adaptive Pricing.
|
|
40
|
+
*
|
|
41
|
+
* Place this element on your cart or checkout page **near the total price**,
|
|
42
|
+
* above the Payment Element. It automatically:
|
|
43
|
+
*
|
|
44
|
+
* - Reads currency options from the `Checkout` session
|
|
45
|
+
* - Renders a two-option toggle with exchange rate disclosure
|
|
46
|
+
* - Calls `selectCurrency` when the customer taps an option
|
|
47
|
+
* - Collapses to zero height when Adaptive Pricing is unavailable
|
|
48
|
+
* - Displays inline errors on failed selections
|
|
49
|
+
*
|
|
50
|
+
* Session state updates automatically through `useCheckout` — no extra
|
|
51
|
+
* wiring needed to keep your cart totals in sync.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const { state, checkout } = useCheckout(clientSecret, {
|
|
56
|
+
* adaptivePricing: { allowed: true },
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* return (
|
|
60
|
+
* <ScrollView>
|
|
61
|
+
* <CurrencySelectorElement checkout={checkout} />
|
|
62
|
+
* <Text>{formatTotal(state?.session.totals?.total, state?.session.currency)}</Text>
|
|
63
|
+
* </ScrollView>
|
|
64
|
+
* );
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param props {@link CurrencySelectorElementProps}
|
|
68
|
+
* @category ReactComponents
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export function CurrencySelectorElement({
|
|
72
|
+
checkout,
|
|
73
|
+
disabled = false,
|
|
74
|
+
...a11yProps
|
|
75
|
+
}: CurrencySelectorElementProps) {
|
|
76
|
+
const [height, setHeight] = useState<number>(0);
|
|
77
|
+
|
|
78
|
+
const handleHeightChange = useCallback(
|
|
79
|
+
(e: NativeSyntheticEvent<HeightChangeEvent>) => {
|
|
80
|
+
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
|
81
|
+
setHeight(e.nativeEvent.height);
|
|
82
|
+
},
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<NativeCurrencySelectorElement
|
|
88
|
+
sessionKey={checkout.sessionKey}
|
|
89
|
+
disabled={disabled}
|
|
90
|
+
style={{ width: '100%', height }}
|
|
91
|
+
onHeightChange={handleHeightChange}
|
|
92
|
+
{...a11yProps}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
AccessibilityProps,
|
|
4
|
+
HostComponent,
|
|
5
|
+
LayoutAnimation,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import {
|
|
8
|
+
PaymentMethodMessagingElementAppearance,
|
|
9
|
+
PaymentMethodMessagingElementState,
|
|
10
|
+
} from '../types/components/PaymentMethodMessagingElementComponent';
|
|
11
|
+
import { PaymentMethodMessagingElementConfiguration } from '../types/components/PaymentMethodMessagingElementComponent';
|
|
12
|
+
import NativePaymentMethodMessagingElement, {
|
|
13
|
+
NativeProps,
|
|
14
|
+
} from '../specs/NativePaymentMethodMessagingElement';
|
|
15
|
+
import { addListener } from '../events';
|
|
16
|
+
|
|
17
|
+
export interface Props extends AccessibilityProps {
|
|
18
|
+
appearance?: PaymentMethodMessagingElementAppearance;
|
|
19
|
+
configuration: PaymentMethodMessagingElementConfiguration;
|
|
20
|
+
onStateChange?(event: PaymentMethodMessagingElementState): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This feature is in Public Preview. It may not be feature complete and have breaking changes as we develop and update functionality.
|
|
25
|
+
* Payment Method Messaging Element to display promotional information about available BNPL plans.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <PaymentMethodMessagingElement
|
|
30
|
+
* appearance={{
|
|
31
|
+
* style: Style.Dark,
|
|
32
|
+
* textColor: '#FFFFFF',
|
|
33
|
+
* infoIconColor: '#CCCCCC',
|
|
34
|
+
* font: {
|
|
35
|
+
* family: 'Courier',
|
|
36
|
+
* size: 16,
|
|
37
|
+
* },
|
|
38
|
+
* }}
|
|
39
|
+
* configuration={{
|
|
40
|
+
* currencyCode: 'usd',
|
|
41
|
+
* amount: 5000,
|
|
42
|
+
* countryCode: 'US',
|
|
43
|
+
* }}
|
|
44
|
+
* onStateChange={(event) => {
|
|
45
|
+
* console.log('PMME loaded with result:', event);
|
|
46
|
+
* }
|
|
47
|
+
* />
|
|
48
|
+
* ```
|
|
49
|
+
* @param __namedParameters Props
|
|
50
|
+
* @returns JSX.Element
|
|
51
|
+
* @category ReactComponents
|
|
52
|
+
*/
|
|
53
|
+
export const PaymentMethodMessagingElement = forwardRef<any, Props>(
|
|
54
|
+
({ appearance, configuration, onStateChange, ...props }) => {
|
|
55
|
+
const viewRef =
|
|
56
|
+
useRef<React.ComponentRef<HostComponent<NativeProps>>>(null);
|
|
57
|
+
|
|
58
|
+
const [height, setHeight] = useState<number | undefined>();
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
// listen for height changes
|
|
62
|
+
const sub = addListener(
|
|
63
|
+
'paymentMethodMessagingElementDidUpdateHeight',
|
|
64
|
+
({ height: h }) => {
|
|
65
|
+
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
|
66
|
+
setHeight(h);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
return () => sub.remove();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
// listen for load complete
|
|
74
|
+
const sub = addListener(
|
|
75
|
+
'paymentMethodMessagingElementConfigureResult',
|
|
76
|
+
({ status: s }) => {
|
|
77
|
+
let state: PaymentMethodMessagingElementState;
|
|
78
|
+
|
|
79
|
+
if (s === 'loaded') {
|
|
80
|
+
state = { status: 'loaded' };
|
|
81
|
+
} else if (s === 'loading') {
|
|
82
|
+
state = { status: 'loading' };
|
|
83
|
+
} else if (s === 'no_content') {
|
|
84
|
+
state = { status: 'no_content' };
|
|
85
|
+
} else {
|
|
86
|
+
state = {
|
|
87
|
+
status: 'failed',
|
|
88
|
+
error: new Error(
|
|
89
|
+
'Failed to configure payment method messaging element'
|
|
90
|
+
),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
onStateChange?.(state);
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
return () => sub.remove();
|
|
97
|
+
}, [onStateChange]);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<NativePaymentMethodMessagingElement
|
|
101
|
+
appearance={appearance}
|
|
102
|
+
style={[{ width: '100%', height: height }]}
|
|
103
|
+
configuration={configuration}
|
|
104
|
+
{...props}
|
|
105
|
+
ref={viewRef}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
package/src/events.ts
CHANGED
|
@@ -66,6 +66,17 @@ type Events = {
|
|
|
66
66
|
onCustomPaymentMethodConfirmHandlerCallback: EventEmitter<UnsafeObject<any>>;
|
|
67
67
|
paymentMethodMessagingElementDidUpdateHeight: EventEmitter<UnsafeObject<any>>;
|
|
68
68
|
paymentMethodMessagingElementConfigureResult: EventEmitter<UnsafeObject<any>>;
|
|
69
|
+
/**
|
|
70
|
+
* Fired by native every time a `Checkout` instance's state transitions —
|
|
71
|
+
* regardless of whether the mutation was JS-driven (e.g. `applyPromotionCode`
|
|
72
|
+
* via `useCheckout`) or native-driven (e.g. `CurrencySelectorElement`).
|
|
73
|
+
* `useCheckout` mirrors this into its `state` so the entire React tree
|
|
74
|
+
* stays in sync with the underlying native session.
|
|
75
|
+
*/
|
|
76
|
+
checkoutSessionDidChangeState: EventEmitter<{
|
|
77
|
+
sessionKey: string;
|
|
78
|
+
state: UnsafeObject<any>;
|
|
79
|
+
}>;
|
|
69
80
|
};
|
|
70
81
|
|
|
71
82
|
export function addListener<EventT extends keyof Events>(
|
package/src/functions.ts
CHANGED
|
@@ -350,6 +350,33 @@ let financialConnectionsEventListener: EventSubscription | null = null;
|
|
|
350
350
|
let paymentSheetCustomPaymentMethodConfirmCallback: EventSubscription | null =
|
|
351
351
|
null;
|
|
352
352
|
|
|
353
|
+
type NativeCheckoutSetupParams = Omit<
|
|
354
|
+
PaymentSheet.CheckoutSetupParams,
|
|
355
|
+
'checkout'
|
|
356
|
+
> & {
|
|
357
|
+
checkout: {
|
|
358
|
+
sessionKey: string;
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const toNativePaymentSheetSetupParams = (
|
|
363
|
+
params: PaymentSheet.SetupParams
|
|
364
|
+
): PaymentSheet.SetupParams => {
|
|
365
|
+
if (!('checkout' in params)) {
|
|
366
|
+
return params;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const nativeCheckoutParams: NativeCheckoutSetupParams = {
|
|
370
|
+
...params,
|
|
371
|
+
// The native side already owns the Checkout instance, so only pass its opaque session key.
|
|
372
|
+
checkout: {
|
|
373
|
+
sessionKey: params.checkout.sessionKey,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
return nativeCheckoutParams as PaymentSheet.SetupParams;
|
|
378
|
+
};
|
|
379
|
+
|
|
353
380
|
export const initPaymentSheet = async (
|
|
354
381
|
params: PaymentSheet.SetupParams
|
|
355
382
|
): Promise<InitPaymentSheetResult> => {
|
|
@@ -431,7 +458,9 @@ export const initPaymentSheet = async (
|
|
|
431
458
|
`[@stripe/stripe-react-native] You have not provided the 'returnURL' field to 'initPaymentSheet', so payment methods that require redirects will not be shown in your iOS Payment Sheet. Visit https://stripe.com/docs/payments/accept-a-payment?platform=react-native&ui=payment-sheet#react-native-set-up-return-url to learn more.`
|
|
432
459
|
);
|
|
433
460
|
}
|
|
434
|
-
result = await NativeStripeSdk.initPaymentSheet(
|
|
461
|
+
result = await NativeStripeSdk.initPaymentSheet(
|
|
462
|
+
toNativePaymentSheetSetupParams(params)
|
|
463
|
+
);
|
|
435
464
|
|
|
436
465
|
if (result.error) {
|
|
437
466
|
return {
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
2
|
+
import NativeStripeSdk from '../specs/NativeStripeSdkModule';
|
|
3
|
+
import type { Checkout } from '../types/Checkout';
|
|
4
|
+
import { addListener } from '../events';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Initializes a Stripe Checkout Session and returns a reactive handle.
|
|
8
|
+
*
|
|
9
|
+
* The session is fetched from Stripe when the hook mounts. `state` is `null`
|
|
10
|
+
* until the initial load completes, then transitions between `loaded` and
|
|
11
|
+
* `loading` as mutations are performed.
|
|
12
|
+
*
|
|
13
|
+
* Pass the returned `checkout` to `initPaymentSheet` to complete the purchase.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export function useCheckout(
|
|
18
|
+
clientSecret: string,
|
|
19
|
+
configuration?: Checkout.Configuration
|
|
20
|
+
): {
|
|
21
|
+
/** The current loading state of the checkout session. `null` until the initial load completes. */
|
|
22
|
+
state: Checkout.State | null;
|
|
23
|
+
/** A handle to the session with methods for mutations. */
|
|
24
|
+
checkout: Checkout;
|
|
25
|
+
/** Set if the initial session load fails. Undefined otherwise. */
|
|
26
|
+
error?: Checkout.Error;
|
|
27
|
+
} {
|
|
28
|
+
const [state, setState] = useState<Checkout.State | null>(null);
|
|
29
|
+
const [error, setError] = useState<Checkout.Error | undefined>(undefined);
|
|
30
|
+
|
|
31
|
+
// Ref so mutation callbacks don't need it as a dependency.
|
|
32
|
+
const sessionKeyRef = useRef<string | null>(null);
|
|
33
|
+
|
|
34
|
+
// Load session on mount / clientSecret change.
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
let cancelled = false;
|
|
37
|
+
sessionKeyRef.current = null;
|
|
38
|
+
setState(null);
|
|
39
|
+
setError(undefined);
|
|
40
|
+
|
|
41
|
+
(async () => {
|
|
42
|
+
try {
|
|
43
|
+
const result = await NativeStripeSdk.initCheckoutSession(
|
|
44
|
+
clientSecret,
|
|
45
|
+
configuration ?? {}
|
|
46
|
+
);
|
|
47
|
+
if (cancelled) return;
|
|
48
|
+
sessionKeyRef.current = result.sessionKey;
|
|
49
|
+
setState(result.state);
|
|
50
|
+
} catch (e: any) {
|
|
51
|
+
if (cancelled) return;
|
|
52
|
+
setError({
|
|
53
|
+
code: e.code ?? 'Failed',
|
|
54
|
+
message: e.message ?? 'Failed to initialize checkout session',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
|
|
59
|
+
// Listen for state changes from native (e.g. currency selector taps)
|
|
60
|
+
// so we stay in sync even when mutations don't originate from JS.
|
|
61
|
+
const sub = addListener(
|
|
62
|
+
'checkoutSessionDidChangeState',
|
|
63
|
+
({ sessionKey, state: nextState }) => {
|
|
64
|
+
if (sessionKey !== sessionKeyRef.current) return;
|
|
65
|
+
setState(nextState as Checkout.State);
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// Ignore in-flight init if unmounted or clientSecret changed.
|
|
70
|
+
return () => {
|
|
71
|
+
cancelled = true;
|
|
72
|
+
sub.remove();
|
|
73
|
+
};
|
|
74
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
+
}, [clientSecret]);
|
|
76
|
+
|
|
77
|
+
// Sets `loading`, calls native, applies returned state. Reverts on error.
|
|
78
|
+
const withLoading = useCallback(
|
|
79
|
+
async (fn: (sessionKey: string) => Promise<Checkout.State>) => {
|
|
80
|
+
const key = sessionKeyRef.current;
|
|
81
|
+
if (!key) {
|
|
82
|
+
throw { code: 'Failed', message: 'Checkout session not initialized.' };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setState((prev) =>
|
|
86
|
+
prev ? { status: 'loading', session: prev.session } : prev
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const newState = await fn(key);
|
|
91
|
+
setState(newState);
|
|
92
|
+
} catch (e: any) {
|
|
93
|
+
setState((prev) =>
|
|
94
|
+
prev?.status === 'loading'
|
|
95
|
+
? { status: 'loaded', session: prev.session }
|
|
96
|
+
: prev
|
|
97
|
+
);
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// Mutation methods. Each is memoized so `checkout` has a stable identity.
|
|
105
|
+
const updateShippingAddress = useCallback<Checkout['updateShippingAddress']>(
|
|
106
|
+
(address, name, phone) =>
|
|
107
|
+
withLoading((key) =>
|
|
108
|
+
NativeStripeSdk.checkoutUpdateShippingAddress(
|
|
109
|
+
key,
|
|
110
|
+
address,
|
|
111
|
+
name ?? null,
|
|
112
|
+
phone ?? null
|
|
113
|
+
)
|
|
114
|
+
),
|
|
115
|
+
[withLoading]
|
|
116
|
+
);
|
|
117
|
+
const updateBillingAddress = useCallback<Checkout['updateBillingAddress']>(
|
|
118
|
+
(address, name, phone) =>
|
|
119
|
+
withLoading((key) =>
|
|
120
|
+
NativeStripeSdk.checkoutUpdateBillingAddress(
|
|
121
|
+
key,
|
|
122
|
+
address,
|
|
123
|
+
name ?? null,
|
|
124
|
+
phone ?? null
|
|
125
|
+
)
|
|
126
|
+
),
|
|
127
|
+
[withLoading]
|
|
128
|
+
);
|
|
129
|
+
const applyPromotionCode = useCallback<Checkout['applyPromotionCode']>(
|
|
130
|
+
(code) =>
|
|
131
|
+
withLoading((key) =>
|
|
132
|
+
NativeStripeSdk.checkoutApplyPromotionCode(key, code)
|
|
133
|
+
),
|
|
134
|
+
[withLoading]
|
|
135
|
+
);
|
|
136
|
+
const removePromotionCode = useCallback<Checkout['removePromotionCode']>(
|
|
137
|
+
() =>
|
|
138
|
+
withLoading((key) => NativeStripeSdk.checkoutRemovePromotionCode(key)),
|
|
139
|
+
[withLoading]
|
|
140
|
+
);
|
|
141
|
+
const updateLineItemQuantity = useCallback<
|
|
142
|
+
Checkout['updateLineItemQuantity']
|
|
143
|
+
>(
|
|
144
|
+
(lineItemId, quantity) =>
|
|
145
|
+
withLoading((key) =>
|
|
146
|
+
NativeStripeSdk.checkoutUpdateLineItemQuantity(
|
|
147
|
+
key,
|
|
148
|
+
lineItemId,
|
|
149
|
+
quantity
|
|
150
|
+
)
|
|
151
|
+
),
|
|
152
|
+
[withLoading]
|
|
153
|
+
);
|
|
154
|
+
const selectShippingOption = useCallback<Checkout['selectShippingOption']>(
|
|
155
|
+
(id) =>
|
|
156
|
+
withLoading((key) =>
|
|
157
|
+
NativeStripeSdk.checkoutSelectShippingOption(key, id)
|
|
158
|
+
),
|
|
159
|
+
[withLoading]
|
|
160
|
+
);
|
|
161
|
+
const updateTaxId = useCallback<Checkout['updateTaxId']>(
|
|
162
|
+
(type, value) =>
|
|
163
|
+
withLoading((key) =>
|
|
164
|
+
NativeStripeSdk.checkoutUpdateTaxId(key, type, value)
|
|
165
|
+
),
|
|
166
|
+
[withLoading]
|
|
167
|
+
);
|
|
168
|
+
const refresh = useCallback<Checkout['refresh']>(
|
|
169
|
+
() => withLoading((key) => NativeStripeSdk.checkoutRefresh(key)),
|
|
170
|
+
[withLoading]
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const checkout = useMemo<Checkout>(
|
|
174
|
+
() => ({
|
|
175
|
+
get sessionKey(): string {
|
|
176
|
+
if (!sessionKeyRef.current) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
'Checkout session not initialized. Wait for `state.status === "loaded"` ' +
|
|
179
|
+
'before passing `checkout` to `useEmbeddedPaymentElement` or calling a ' +
|
|
180
|
+
'mutation method (e.g. `applyPromotionCode`).'
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return sessionKeyRef.current;
|
|
184
|
+
},
|
|
185
|
+
updateShippingAddress,
|
|
186
|
+
updateBillingAddress,
|
|
187
|
+
applyPromotionCode,
|
|
188
|
+
removePromotionCode,
|
|
189
|
+
updateLineItemQuantity,
|
|
190
|
+
selectShippingOption,
|
|
191
|
+
updateTaxId,
|
|
192
|
+
refresh,
|
|
193
|
+
}),
|
|
194
|
+
[
|
|
195
|
+
updateShippingAddress,
|
|
196
|
+
updateBillingAddress,
|
|
197
|
+
applyPromotionCode,
|
|
198
|
+
removePromotionCode,
|
|
199
|
+
updateLineItemQuantity,
|
|
200
|
+
selectShippingOption,
|
|
201
|
+
updateTaxId,
|
|
202
|
+
refresh,
|
|
203
|
+
]
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
return { state, checkout, error };
|
|
207
|
+
}
|
package/src/hooks/useOnramp.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventSubscription } from 'react-native';
|
|
1
|
+
import { EventSubscription, Platform } from 'react-native';
|
|
2
2
|
import NativeOnrampSdk from '../specs/NativeOnrampSdkModule';
|
|
3
3
|
import { Onramp, OnrampError, StripeError } from '../types';
|
|
4
4
|
import type { Address } from '../types';
|
|
@@ -6,10 +6,16 @@ import { useCallback } from 'react';
|
|
|
6
6
|
import { addOnrampListener } from '../events';
|
|
7
7
|
import { CryptoPaymentToken } from '../types/Onramp';
|
|
8
8
|
|
|
9
|
-
function requireOnrampModule() {
|
|
9
|
+
export function requireOnrampModule() {
|
|
10
10
|
if (NativeOnrampSdk == null) {
|
|
11
11
|
throw new Error(
|
|
12
|
-
|
|
12
|
+
Platform.select({
|
|
13
|
+
ios: "Onramp module is not available. Add 'stripe-react-native/Onramp' to your Podfile.",
|
|
14
|
+
android:
|
|
15
|
+
"Onramp module is not available. Add 'StripeSdk_includeOnramp=true' to gradle.properties.",
|
|
16
|
+
default:
|
|
17
|
+
"Onramp module is not available. Enable the Onramp pod on iOS and set 'StripeSdk_includeOnramp=true' on Android.",
|
|
18
|
+
}) ?? 'Onramp module is not available.'
|
|
13
19
|
);
|
|
14
20
|
}
|
|
15
21
|
return NativeOnrampSdk;
|
package/src/index.tsx
CHANGED
|
@@ -36,6 +36,10 @@ export * from './types/EmbeddedPaymentElement';
|
|
|
36
36
|
export * from './types/PaymentSheet';
|
|
37
37
|
export * from './types/ConfirmationToken';
|
|
38
38
|
|
|
39
|
+
export * from './types/components/PaymentMethodMessagingElementComponent';
|
|
40
|
+
export type { Props as PaymentMethodMessagingElementProps } from './components/PaymentMethodMessagingElement';
|
|
41
|
+
export { PaymentMethodMessagingElement } from './components/PaymentMethodMessagingElement';
|
|
42
|
+
|
|
39
43
|
//connect components
|
|
40
44
|
export {
|
|
41
45
|
ConnectComponentsProvider,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { HostComponent, ViewProps } from 'react-native';
|
|
2
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
3
|
+
import type {
|
|
4
|
+
DirectEventHandler,
|
|
5
|
+
Double,
|
|
6
|
+
WithDefault,
|
|
7
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
8
|
+
|
|
9
|
+
export interface HeightChangeEvent {
|
|
10
|
+
height: Double;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NativeProps extends ViewProps {
|
|
14
|
+
/**
|
|
15
|
+
* Opaque key returned by `useCheckout`. The native side uses this to look
|
|
16
|
+
* up the matching `Checkout` instance and observe its state — there's no
|
|
17
|
+
* separate session-update event from this view, since `useCheckout`
|
|
18
|
+
* already subscribes to a single `checkoutSessionDidChangeState` channel
|
|
19
|
+
* that mirrors every native-driven mutation back into JS.
|
|
20
|
+
*/
|
|
21
|
+
sessionKey: string;
|
|
22
|
+
|
|
23
|
+
/** When true, the toggle is visible but ignores user interaction. */
|
|
24
|
+
disabled?: WithDefault<boolean, false>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Fired whenever the element's intrinsic height changes so the RN
|
|
28
|
+
* layout system can update the containing view.
|
|
29
|
+
*/
|
|
30
|
+
onHeightChange?: DirectEventHandler<HeightChangeEvent>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default codegenNativeComponent<NativeProps>(
|
|
34
|
+
'StripeCurrencySelectorElement'
|
|
35
|
+
) as HostComponent<NativeProps>;
|