@stripe/stripe-react-native 0.56.0 → 0.57.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.
Files changed (328) hide show
  1. package/android/build.gradle +76 -118
  2. package/android/gradle.properties +1 -1
  3. package/android/settings.gradle +2 -0
  4. package/android/spotless.gradle +1 -1
  5. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +24 -20
  6. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +20 -17
  7. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +28 -32
  8. package/android/src/main/java/com/reactnativestripesdk/{CollectBankAccountLauncherFragment.kt → CollectBankAccountLauncherManager.kt} +23 -44
  9. package/android/src/main/java/com/reactnativestripesdk/CustomPaymentMethodActivity.kt +2 -0
  10. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +4 -11
  11. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +52 -132
  12. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +0 -8
  13. package/android/src/main/java/com/reactnativestripesdk/FakeOnrampSdkModule.kt +154 -0
  14. package/android/src/main/java/com/reactnativestripesdk/{FinancialConnectionsSheetFragment.kt → FinancialConnectionsSheetManager.kt} +43 -92
  15. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +1 -1
  16. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +107 -0
  17. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherManager.kt +37 -0
  18. package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +7 -5
  19. package/android/src/main/java/com/reactnativestripesdk/NavigationBarManager.kt +31 -0
  20. package/android/src/main/java/com/reactnativestripesdk/NavigationBarView.kt +120 -0
  21. package/android/src/main/java/com/reactnativestripesdk/PaymentElementConfig.kt +228 -0
  22. package/android/src/main/java/com/reactnativestripesdk/{PaymentLauncherFragment.kt → PaymentLauncherManager.kt} +40 -77
  23. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +11 -20
  24. package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +4 -6
  25. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +409 -483
  26. package/android/src/main/java/com/reactnativestripesdk/{PaymentSheetFragment.kt → PaymentSheetManager.kt} +65 -300
  27. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +53 -17
  28. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +227 -232
  29. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +21 -2
  30. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherManager.kt +78 -0
  31. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +52 -39
  32. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +2 -2
  33. package/android/src/main/java/com/reactnativestripesdk/customersheet/{CustomerSheetFragment.kt → CustomerSheetManager.kt} +64 -99
  34. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +2 -3
  35. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +5 -10
  36. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +90 -77
  37. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +6 -4
  38. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +13 -3
  39. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +87 -11
  40. package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +1 -1
  41. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +178 -185
  42. package/android/src/main/java/com/reactnativestripesdk/utils/StripeUIManager.kt +62 -0
  43. package/android/src/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +118 -0
  44. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +4 -0
  45. package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +922 -0
  46. package/android/src/test/java/com/facebook/testutils/shadows/ShadowArguments.kt +29 -0
  47. package/android/src/test/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManagerTest.kt +163 -0
  48. package/android/src/test/java/com/reactnativestripesdk/PaymentElementConfigTest.kt +976 -0
  49. package/android/src/test/java/com/reactnativestripesdk/PaymentSheetAppearanceTest.kt +801 -0
  50. package/android/src/test/java/com/reactnativestripesdk/PaymentSheetManagerTest.kt +523 -0
  51. package/android/src/test/java/com/reactnativestripesdk/addresssheet/AddressSheetViewTest.kt +551 -0
  52. package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +567 -0
  53. package/android/src/test/java/com/reactnativestripesdk/mappers/PaymentOptionDisplayDataMapperTest.kt +456 -0
  54. package/android/src/test/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxyTest.kt +43 -0
  55. package/android/src/test/resources/robolectric.properties +2 -0
  56. package/ios/AddressSheet/AddressSheetUtils.swift +3 -3
  57. package/ios/AddressSheet/AddressSheetView.swift +26 -26
  58. package/ios/AddressSheet/AddressSheetViewManager.swift +2 -2
  59. package/ios/ApplePayButtonManager.swift +1 -1
  60. package/ios/ApplePayButtonView.swift +9 -10
  61. package/ios/ApplePayUtils.swift +51 -51
  62. package/ios/ApplePayViewController.swift +25 -29
  63. package/ios/AuBECSDebitFormManager.swift +1 -1
  64. package/ios/AuBECSDebitFormView.swift +13 -15
  65. package/ios/CardFieldManager.swift +4 -4
  66. package/ios/CardFieldView.swift +9 -9
  67. package/ios/CardFormManager.swift +3 -3
  68. package/ios/CardFormView.swift +28 -28
  69. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingView.swift +97 -0
  70. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewController.swift +133 -0
  71. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.m +16 -0
  72. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.swift +17 -0
  73. package/ios/CustomerSheet/CustomerSheetUtils.swift +15 -16
  74. package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +19 -19
  75. package/ios/EmbeddedPaymentElementView.swift +2 -2
  76. package/ios/Errors.swift +22 -23
  77. package/ios/FinancialConnections.swift +37 -37
  78. package/ios/Mappers.swift +212 -75
  79. package/ios/NavigationBarManager.m +13 -0
  80. package/ios/NavigationBarManager.swift +17 -0
  81. package/ios/NavigationBarView.swift +65 -0
  82. package/ios/NewArch/NavigationBarComponentView.h +10 -0
  83. package/ios/NewArch/NavigationBarComponentView.mm +86 -0
  84. package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
  85. package/ios/OldArch/StripeSdkEventEmitterCompat.m +7 -1
  86. package/ios/PaymentMethodFactory.swift +24 -41
  87. package/ios/PaymentOptionDisplayData+ReactNative.swift +4 -4
  88. package/ios/PaymentPassFinder.swift +9 -10
  89. package/ios/PaymentSheetAppearance.swift +137 -138
  90. package/ios/PushProvisioning/AddToWalletButtonManager.swift +2 -2
  91. package/ios/PushProvisioning/AddToWalletButtonView.swift +16 -18
  92. package/ios/PushProvisioning/PushProvisioningUtils.swift +11 -11
  93. package/ios/StripeContainerManager.swift +1 -1
  94. package/ios/StripeContainerView.swift +3 -3
  95. package/ios/StripeOnrampSdk.h +17 -0
  96. package/ios/StripeOnrampSdk.mm +158 -0
  97. package/ios/StripeSdk.mm +8 -0
  98. package/ios/StripeSdkEmitter.swift +4 -0
  99. package/ios/StripeSdkImpl+CustomerSheet.swift +31 -26
  100. package/ios/StripeSdkImpl+Embedded.swift +11 -9
  101. package/ios/StripeSdkImpl+PaymentSheet.swift +51 -42
  102. package/ios/StripeSdkImpl.swift +919 -191
  103. package/ios/UIColorExtension.swift +72 -0
  104. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  105. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  106. package/lib/commonjs/components/AddressSheet.js +1 -1
  107. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  108. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  109. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  110. package/lib/commonjs/components/CardField.js +1 -1
  111. package/lib/commonjs/components/CardField.js.map +1 -1
  112. package/lib/commonjs/components/CardForm.js +1 -1
  113. package/lib/commonjs/components/CardForm.js.map +1 -1
  114. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  115. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  116. package/lib/commonjs/components/StripeContainer.js +1 -1
  117. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  118. package/lib/commonjs/components/StripeProvider.js +1 -1
  119. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  120. package/lib/commonjs/connect/Components.js +2 -0
  121. package/lib/commonjs/connect/Components.js.map +1 -0
  122. package/lib/commonjs/connect/ConnectComponentsProvider.js +2 -0
  123. package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -0
  124. package/lib/commonjs/connect/EmbeddedComponent.js +19 -0
  125. package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -0
  126. package/lib/commonjs/connect/ModalCloseButton.js +2 -0
  127. package/lib/commonjs/connect/ModalCloseButton.js.map +1 -0
  128. package/lib/commonjs/connect/NavigationBar.js +2 -0
  129. package/lib/commonjs/connect/NavigationBar.js.map +1 -0
  130. package/lib/commonjs/connect/connectTypes.js +2 -0
  131. package/lib/commonjs/connect/connectTypes.js.map +1 -0
  132. package/lib/commonjs/events.js +1 -1
  133. package/lib/commonjs/events.js.map +1 -1
  134. package/lib/commonjs/helpers.js +1 -1
  135. package/lib/commonjs/helpers.js.map +1 -1
  136. package/lib/commonjs/hooks/useOnramp.js +2 -0
  137. package/lib/commonjs/hooks/useOnramp.js.map +1 -0
  138. package/lib/commonjs/index.js +1 -1
  139. package/lib/commonjs/index.js.map +1 -1
  140. package/lib/commonjs/plugin/withStripe.js +1 -1
  141. package/lib/commonjs/plugin/withStripe.js.map +1 -1
  142. package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
  143. package/lib/commonjs/specs/NativeAddToWalletButton.js.map +1 -1
  144. package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
  145. package/lib/commonjs/specs/NativeAddressSheet.js.map +1 -1
  146. package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
  147. package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
  148. package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
  149. package/lib/commonjs/specs/NativeAuBECSDebitForm.js.map +1 -1
  150. package/lib/commonjs/specs/NativeCardField.js +1 -1
  151. package/lib/commonjs/specs/NativeCardField.js.map +1 -1
  152. package/lib/commonjs/specs/NativeCardForm.js +1 -1
  153. package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
  154. package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +2 -0
  155. package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js.map +1 -0
  156. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
  157. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  158. package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
  159. package/lib/commonjs/specs/NativeGooglePayButton.js.map +1 -1
  160. package/lib/commonjs/specs/NativeNavigationBar.js +2 -0
  161. package/lib/commonjs/specs/NativeNavigationBar.js.map +1 -0
  162. package/lib/commonjs/specs/NativeOnrampSdkModule.js +2 -0
  163. package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -0
  164. package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
  165. package/lib/commonjs/specs/NativeStripeContainer.js.map +1 -1
  166. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  167. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  168. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  169. package/lib/commonjs/types/Errors.js +1 -1
  170. package/lib/commonjs/types/Errors.js.map +1 -1
  171. package/lib/commonjs/types/Onramp.js +2 -0
  172. package/lib/commonjs/types/Onramp.js.map +1 -0
  173. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  174. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  175. package/lib/commonjs/types/index.js +1 -1
  176. package/lib/commonjs/types/index.js.map +1 -1
  177. package/lib/module/components/AddToWalletButton.js +1 -1
  178. package/lib/module/components/AddToWalletButton.js.map +1 -1
  179. package/lib/module/components/AddressSheet.js +1 -1
  180. package/lib/module/components/AddressSheet.js.map +1 -1
  181. package/lib/module/components/AuBECSDebitForm.js +1 -1
  182. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  183. package/lib/module/components/CardField.js +1 -1
  184. package/lib/module/components/CardField.js.map +1 -1
  185. package/lib/module/components/CardForm.js +1 -1
  186. package/lib/module/components/CardForm.js.map +1 -1
  187. package/lib/module/components/PlatformPayButton.js +1 -1
  188. package/lib/module/components/PlatformPayButton.js.map +1 -1
  189. package/lib/module/components/StripeContainer.js +1 -1
  190. package/lib/module/components/StripeContainer.js.map +1 -1
  191. package/lib/module/components/StripeProvider.js +1 -1
  192. package/lib/module/components/StripeProvider.js.map +1 -1
  193. package/lib/module/connect/Components.js +2 -0
  194. package/lib/module/connect/Components.js.map +1 -0
  195. package/lib/module/connect/ConnectComponentsProvider.js +2 -0
  196. package/lib/module/connect/ConnectComponentsProvider.js.map +1 -0
  197. package/lib/module/connect/EmbeddedComponent.js +19 -0
  198. package/lib/module/connect/EmbeddedComponent.js.map +1 -0
  199. package/lib/module/connect/ModalCloseButton.js +2 -0
  200. package/lib/module/connect/ModalCloseButton.js.map +1 -0
  201. package/lib/module/connect/NavigationBar.js +2 -0
  202. package/lib/module/connect/NavigationBar.js.map +1 -0
  203. package/lib/module/connect/connectTypes.js +2 -0
  204. package/lib/module/connect/connectTypes.js.map +1 -0
  205. package/lib/module/events.js +1 -1
  206. package/lib/module/events.js.map +1 -1
  207. package/lib/module/helpers.js +1 -1
  208. package/lib/module/helpers.js.map +1 -1
  209. package/lib/module/hooks/useOnramp.js +2 -0
  210. package/lib/module/hooks/useOnramp.js.map +1 -0
  211. package/lib/module/index.js +1 -1
  212. package/lib/module/index.js.map +1 -1
  213. package/lib/module/plugin/withStripe.js +1 -1
  214. package/lib/module/plugin/withStripe.js.map +1 -1
  215. package/lib/module/specs/NativeAddToWalletButton.js +1 -1
  216. package/lib/module/specs/NativeAddToWalletButton.js.map +1 -1
  217. package/lib/module/specs/NativeAddressSheet.js +1 -1
  218. package/lib/module/specs/NativeAddressSheet.js.map +1 -1
  219. package/lib/module/specs/NativeApplePayButton.js +1 -1
  220. package/lib/module/specs/NativeApplePayButton.js.map +1 -1
  221. package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
  222. package/lib/module/specs/NativeAuBECSDebitForm.js.map +1 -1
  223. package/lib/module/specs/NativeCardField.js +1 -1
  224. package/lib/module/specs/NativeCardField.js.map +1 -1
  225. package/lib/module/specs/NativeCardForm.js +1 -1
  226. package/lib/module/specs/NativeCardForm.js.map +1 -1
  227. package/lib/module/specs/NativeConnectAccountOnboardingView.js +2 -0
  228. package/lib/module/specs/NativeConnectAccountOnboardingView.js.map +1 -0
  229. package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
  230. package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  231. package/lib/module/specs/NativeGooglePayButton.js +1 -1
  232. package/lib/module/specs/NativeGooglePayButton.js.map +1 -1
  233. package/lib/module/specs/NativeNavigationBar.js +2 -0
  234. package/lib/module/specs/NativeNavigationBar.js.map +1 -0
  235. package/lib/module/specs/NativeOnrampSdkModule.js +2 -0
  236. package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -0
  237. package/lib/module/specs/NativeStripeContainer.js +1 -1
  238. package/lib/module/specs/NativeStripeContainer.js.map +1 -1
  239. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  240. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  241. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  242. package/lib/module/types/Errors.js +1 -1
  243. package/lib/module/types/Errors.js.map +1 -1
  244. package/lib/module/types/Onramp.js +2 -0
  245. package/lib/module/types/Onramp.js.map +1 -0
  246. package/lib/module/types/PaymentIntent.js.map +1 -1
  247. package/lib/module/types/PaymentSheet.js.map +1 -1
  248. package/lib/module/types/index.js +1 -1
  249. package/lib/module/types/index.js.map +1 -1
  250. package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -1
  251. package/lib/typescript/src/connect/Components.d.ts +23 -0
  252. package/lib/typescript/src/connect/Components.d.ts.map +1 -0
  253. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts +22 -0
  254. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts.map +1 -0
  255. package/lib/typescript/src/connect/EmbeddedComponent.d.ts +18 -0
  256. package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -0
  257. package/lib/typescript/src/connect/ModalCloseButton.d.ts +7 -0
  258. package/lib/typescript/src/connect/ModalCloseButton.d.ts.map +1 -0
  259. package/lib/typescript/src/connect/NavigationBar.d.ts +8 -0
  260. package/lib/typescript/src/connect/NavigationBar.d.ts.map +1 -0
  261. package/lib/typescript/src/connect/connectTypes.d.ts +464 -0
  262. package/lib/typescript/src/connect/connectTypes.d.ts.map +1 -0
  263. package/lib/typescript/src/events.d.ts +3 -0
  264. package/lib/typescript/src/events.d.ts.map +1 -1
  265. package/lib/typescript/src/functions.d.ts.map +1 -1
  266. package/lib/typescript/src/helpers.d.ts.map +1 -1
  267. package/lib/typescript/src/hooks/useOnramp.d.ts +158 -0
  268. package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -0
  269. package/lib/typescript/src/index.d.ts +4 -0
  270. package/lib/typescript/src/index.d.ts.map +1 -1
  271. package/lib/typescript/src/plugin/withStripe.d.ts +15 -0
  272. package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -1
  273. package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts +14 -0
  274. package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts.map +1 -0
  275. package/lib/typescript/src/specs/NativeNavigationBar.d.ts +11 -0
  276. package/lib/typescript/src/specs/NativeNavigationBar.d.ts.map +1 -0
  277. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +28 -0
  278. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -0
  279. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -0
  280. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  281. package/lib/typescript/src/types/Errors.d.ts +5 -0
  282. package/lib/typescript/src/types/Errors.d.ts.map +1 -1
  283. package/lib/typescript/src/types/Onramp.d.ts +275 -0
  284. package/lib/typescript/src/types/Onramp.d.ts.map +1 -0
  285. package/lib/typescript/src/types/PaymentIntent.d.ts +1 -9
  286. package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
  287. package/lib/typescript/src/types/PaymentMethod.d.ts +2 -8
  288. package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
  289. package/lib/typescript/src/types/PaymentSheet.d.ts +7 -0
  290. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  291. package/lib/typescript/src/types/index.d.ts +7 -1
  292. package/lib/typescript/src/types/index.d.ts.map +1 -1
  293. package/package.json +24 -12
  294. package/src/components/StripeProvider.tsx +5 -0
  295. package/src/connect/Components.tsx +279 -0
  296. package/src/connect/ConnectComponentsProvider.tsx +93 -0
  297. package/src/connect/EmbeddedComponent.tsx +407 -0
  298. package/src/connect/ModalCloseButton.tsx +44 -0
  299. package/src/connect/NavigationBar.tsx +29 -0
  300. package/src/connect/connectTypes.ts +626 -0
  301. package/src/events.ts +22 -0
  302. package/src/hooks/useOnramp.tsx +334 -0
  303. package/src/index.tsx +13 -0
  304. package/src/plugin/withStripe.ts +104 -7
  305. package/src/specs/NativeConnectAccountOnboardingView.ts +19 -0
  306. package/src/specs/NativeNavigationBar.ts +16 -0
  307. package/src/specs/NativeOnrampSdkModule.ts +47 -0
  308. package/src/specs/NativeStripeSdkModule.ts +5 -0
  309. package/src/types/Errors.ts +6 -0
  310. package/src/types/Onramp.ts +317 -0
  311. package/src/types/PaymentIntent.ts +0 -10
  312. package/src/types/PaymentMethod.ts +0 -9
  313. package/src/types/PaymentSheet.ts +7 -0
  314. package/src/types/index.ts +8 -0
  315. package/stripe-react-native.podspec +21 -8
  316. package/android/.idea/AndroidProjectSystem.xml +0 -6
  317. package/android/.idea/caches/deviceStreaming.xml +0 -703
  318. package/android/.idea/compiler.xml +0 -6
  319. package/android/.idea/gradle.xml +0 -18
  320. package/android/.idea/migrations.xml +0 -10
  321. package/android/.idea/misc.xml +0 -10
  322. package/android/.idea/runConfigurations.xml +0 -17
  323. package/android/.idea/vcs.xml +0 -6
  324. package/android/local.properties +0 -8
  325. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +0 -146
  326. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +0 -68
  327. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +0 -102
  328. package/android/src/main/java/com/reactnativestripesdk/utils/StripeFragment.kt +0 -52
@@ -19,11 +19,20 @@ class StripeSdkPackage : BaseReactPackage() {
19
19
  ): NativeModule? =
20
20
  when (name) {
21
21
  StripeSdkModule.NAME -> StripeSdkModule(reactContext)
22
+ NativeOnrampSdkModuleSpec.NAME -> {
23
+ val onrampModuleClass = getOnrampModuleClass()
24
+ val constructor = onrampModuleClass.getConstructor(ReactApplicationContext::class.java)
25
+ constructor.newInstance(reactContext) as NativeModule
26
+ }
22
27
  else -> null
23
28
  }
24
29
 
25
30
  override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
26
- val moduleList: Array<Class<out NativeModule?>> = arrayOf(StripeSdkModule::class.java)
31
+ val moduleList: Array<Class<out NativeModule?>> =
32
+ arrayOf(
33
+ StripeSdkModule::class.java,
34
+ getOnrampModuleClass(),
35
+ )
27
36
  val reactModuleInfoMap: MutableMap<String, ReactModuleInfo> = HashMap()
28
37
  for (moduleClass in moduleList) {
29
38
  val reactModule = moduleClass.getAnnotation(ReactModule::class.java) ?: continue
@@ -47,8 +56,18 @@ class StripeSdkPackage : BaseReactPackage() {
47
56
  StripeContainerManager(),
48
57
  CardFormViewManager(),
49
58
  GooglePayButtonManager(),
50
- AddToWalletButtonManager(reactContext),
59
+ AddToWalletButtonManager(),
51
60
  AddressSheetViewManager(),
52
61
  EmbeddedPaymentElementViewManager(),
62
+ NavigationBarManager(),
53
63
  )
64
+
65
+ private fun getOnrampModuleClass(): Class<out NativeModule?> {
66
+ if (BuildConfig.IS_ONRAMP_INCLUDED) {
67
+ @Suppress("UNCHECKED_CAST")
68
+ return Class.forName("com.reactnativestripesdk.OnrampSdkModule") as Class<out NativeModule?>
69
+ } else {
70
+ return FakeOnrampSdkModule::class.java
71
+ }
72
+ }
54
73
  }
@@ -0,0 +1,78 @@
1
+ package com.reactnativestripesdk.addresssheet
2
+
3
+ import android.annotation.SuppressLint
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.WritableMap
6
+ import com.reactnativestripesdk.utils.ErrorType
7
+ import com.reactnativestripesdk.utils.StripeUIManager
8
+ import com.reactnativestripesdk.utils.createError
9
+ import com.stripe.android.core.reactnative.ReactNativeSdkInternal
10
+ import com.stripe.android.paymentsheet.PaymentSheet
11
+ import com.stripe.android.paymentsheet.addresselement.AddressDetails
12
+ import com.stripe.android.paymentsheet.addresselement.AddressLauncher
13
+ import com.stripe.android.paymentsheet.addresselement.AddressLauncherResult
14
+
15
+ @OptIn(ReactNativeSdkInternal::class)
16
+ class AddressLauncherManager(
17
+ context: ReactApplicationContext,
18
+ appearance: PaymentSheet.Appearance,
19
+ defaultAddress: AddressDetails?,
20
+ allowedCountries: Set<String>,
21
+ buttonTitle: String?,
22
+ title: String?,
23
+ googlePlacesApiKey: String?,
24
+ autocompleteCountries: Set<String>,
25
+ additionalFields: AddressLauncher.AdditionalFieldsConfiguration?,
26
+ private var callback: ((error: WritableMap?, address: AddressDetails?) -> Unit),
27
+ ) : StripeUIManager(context) {
28
+ companion object {
29
+ internal var publishableKey: String? = null
30
+ }
31
+
32
+ private lateinit var addressLauncher: AddressLauncher
33
+ private var configuration =
34
+ AddressLauncher.Configuration(
35
+ appearance = appearance,
36
+ address = defaultAddress,
37
+ allowedCountries = allowedCountries,
38
+ buttonTitle = buttonTitle,
39
+ additionalFields = additionalFields,
40
+ title = title,
41
+ googlePlacesApiKey = googlePlacesApiKey,
42
+ autocompleteCountries = autocompleteCountries,
43
+ )
44
+
45
+ override fun onPresent() {
46
+ val activity = getCurrentActivityOrResolveWithError(promise) ?: return
47
+ publishableKey?.let { publishableKey ->
48
+ @SuppressLint("RestrictedApi")
49
+ addressLauncher =
50
+ AddressLauncher(activity, signal, ::onAddressLauncherResult).also {
51
+ it.present(publishableKey = publishableKey, configuration = configuration)
52
+ }
53
+ }
54
+ ?: run {
55
+ callback.invoke(
56
+ createError(
57
+ ErrorType.Failed.toString(),
58
+ "No publishable key set. Stripe has not been initialized. Initialize Stripe in your app with the StripeProvider component or the initStripe method.",
59
+ ),
60
+ null,
61
+ )
62
+ }
63
+ }
64
+
65
+ private fun onAddressLauncherResult(result: AddressLauncherResult) {
66
+ when (result) {
67
+ is AddressLauncherResult.Canceled -> {
68
+ callback.invoke(
69
+ createError(ErrorType.Canceled.toString(), "The flow has been canceled."),
70
+ null,
71
+ )
72
+ }
73
+ is AddressLauncherResult.Succeeded -> {
74
+ callback.invoke(null, result.address)
75
+ }
76
+ }
77
+ }
78
+ }
@@ -1,19 +1,18 @@
1
1
  package com.reactnativestripesdk.addresssheet
2
2
 
3
3
  import android.annotation.SuppressLint
4
- import android.os.Bundle
5
4
  import android.util.Log
6
5
  import android.widget.FrameLayout
6
+ import com.facebook.react.bridge.Arguments
7
7
  import com.facebook.react.bridge.ReadableMap
8
8
  import com.facebook.react.bridge.WritableMap
9
- import com.facebook.react.bridge.WritableNativeMap
10
9
  import com.facebook.react.uimanager.ThemedReactContext
11
10
  import com.facebook.react.uimanager.UIManagerHelper
12
11
  import com.reactnativestripesdk.buildPaymentSheetAppearance
13
12
  import com.reactnativestripesdk.utils.ErrorType
14
13
  import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
15
14
  import com.reactnativestripesdk.utils.createError
16
- import com.reactnativestripesdk.utils.toBundleObject
15
+ import com.reactnativestripesdk.utils.getBooleanOr
17
16
  import com.stripe.android.paymentsheet.PaymentSheet
18
17
  import com.stripe.android.paymentsheet.addresselement.AddressDetails
19
18
  import com.stripe.android.paymentsheet.addresselement.AddressLauncher
@@ -31,6 +30,14 @@ class AddressSheetView(
31
30
  private var googlePlacesApiKey: String? = null
32
31
  private var autocompleteCountries: Set<String> = emptySet()
33
32
  private var additionalFields: AddressLauncher.AdditionalFieldsConfiguration? = null
33
+ private var addressSheetManager: AddressLauncherManager? = null
34
+
35
+ override fun onDetachedFromWindow() {
36
+ super.onDetachedFromWindow()
37
+
38
+ addressSheetManager?.destroy()
39
+ addressSheetManager = null
40
+ }
34
41
 
35
42
  private fun onSubmit(params: WritableMap) {
36
43
  UIManagerHelper.getEventDispatcherForReactTag(context, id)?.dispatchEvent(
@@ -59,29 +66,37 @@ class AddressSheetView(
59
66
  private fun launchAddressSheet() {
60
67
  val appearance =
61
68
  try {
62
- buildPaymentSheetAppearance(toBundleObject(appearanceParams), context)
69
+ buildPaymentSheetAppearance(appearanceParams, context)
63
70
  } catch (error: PaymentSheetAppearanceException) {
64
71
  onError(createError(ErrorType.Failed.toString(), error))
65
72
  return
66
73
  }
67
- AddressLauncherFragment().presentAddressSheet(
68
- context,
69
- appearance,
70
- defaultAddress,
71
- allowedCountries,
72
- buttonTitle,
73
- sheetTitle,
74
- googlePlacesApiKey,
75
- autocompleteCountries,
76
- additionalFields,
77
- ) { error, address ->
78
- if (address != null) {
79
- onSubmit(buildResult(address))
80
- } else {
81
- onError(error)
74
+ addressSheetManager?.destroy()
75
+ addressSheetManager =
76
+ AddressLauncherManager(
77
+ context.reactApplicationContext,
78
+ appearance,
79
+ defaultAddress,
80
+ allowedCountries,
81
+ buttonTitle,
82
+ sheetTitle,
83
+ googlePlacesApiKey,
84
+ autocompleteCountries,
85
+ additionalFields,
86
+ ) { error, address ->
87
+ addressSheetManager?.destroy()
88
+ addressSheetManager = null
89
+
90
+ if (address != null) {
91
+ onSubmit(buildResult(address))
92
+ } else {
93
+ onError(error)
94
+ }
95
+ isVisible = false
96
+ }.also {
97
+ it.create()
98
+ it.present()
82
99
  }
83
- isVisible = false
84
- }
85
100
  }
86
101
 
87
102
  fun setAppearance(appearanceParams: ReadableMap?) {
@@ -117,27 +132,25 @@ class AddressSheetView(
117
132
  }
118
133
 
119
134
  companion object {
120
- internal fun buildAddressDetails(bundle: Bundle): AddressDetails =
135
+ internal fun buildAddressDetails(map: ReadableMap): AddressDetails =
121
136
  AddressDetails(
122
- name = bundle.getString("name"),
123
- address = buildAddress(bundle.getBundle("address")),
124
- phoneNumber = bundle.getString("phone"),
125
- isCheckboxSelected = bundle.getBoolean("isCheckboxSelected"),
137
+ name = map.getString("name"),
138
+ address = buildAddress(map.getMap("address")),
139
+ phoneNumber = map.getString("phone"),
140
+ isCheckboxSelected = map.getBooleanOr("isCheckboxSelected", false),
126
141
  )
127
142
 
128
- internal fun buildAddressDetails(map: ReadableMap): AddressDetails = buildAddressDetails(toBundleObject(map))
129
-
130
- internal fun buildAddress(bundle: Bundle?): PaymentSheet.Address? {
131
- if (bundle == null) {
143
+ internal fun buildAddress(map: ReadableMap?): PaymentSheet.Address? {
144
+ if (map == null) {
132
145
  return null
133
146
  }
134
147
  return PaymentSheet.Address(
135
- city = bundle.getString("city"),
136
- country = bundle.getString("country"),
137
- line1 = bundle.getString("line1"),
138
- line2 = bundle.getString("line2"),
139
- state = bundle.getString("state"),
140
- postalCode = bundle.getString("postalCode"),
148
+ city = map.getString("city"),
149
+ country = map.getString("country"),
150
+ line1 = map.getString("line1"),
151
+ line2 = map.getString("line2"),
152
+ state = map.getString("state"),
153
+ postalCode = map.getString("postalCode"),
141
154
  )
142
155
  }
143
156
 
@@ -159,14 +172,14 @@ class AddressSheetView(
159
172
  }
160
173
 
161
174
  internal fun buildResult(addressDetails: AddressDetails): WritableMap =
162
- WritableNativeMap().apply {
175
+ Arguments.createMap().apply {
163
176
  putMap(
164
177
  "result",
165
- WritableNativeMap().apply {
178
+ Arguments.createMap().apply {
166
179
  putString("name", addressDetails.name)
167
180
  putMap(
168
181
  "address",
169
- WritableNativeMap().apply {
182
+ Arguments.createMap().apply {
170
183
  putString("city", addressDetails.address?.city)
171
184
  putString("country", addressDetails.address?.country)
172
185
  putString("line1", addressDetails.address?.line1)
@@ -41,7 +41,7 @@ class AddressSheetViewManager :
41
41
  view: AddressSheetView,
42
42
  appearance: Dynamic,
43
43
  ) {
44
- view.setAppearance(appearance.asMap())
44
+ view.setAppearance(appearance.asMapOrNull())
45
45
  }
46
46
 
47
47
  @ReactProp(name = "defaultValues")
@@ -49,7 +49,7 @@ class AddressSheetViewManager :
49
49
  view: AddressSheetView,
50
50
  defaults: Dynamic,
51
51
  ) {
52
- view.setDefaultValues(defaults.asMap())
52
+ view.setDefaultValues(defaults.asMapOrNull())
53
53
  }
54
54
 
55
55
  @ReactProp(name = "additionalFields")
@@ -10,79 +10,66 @@ import android.util.Log
10
10
  import com.facebook.react.bridge.Arguments
11
11
  import com.facebook.react.bridge.Promise
12
12
  import com.facebook.react.bridge.ReactApplicationContext
13
+ import com.facebook.react.bridge.ReadableMap
13
14
  import com.facebook.react.bridge.WritableMap
14
- import com.facebook.react.bridge.WritableNativeMap
15
15
  import com.reactnativestripesdk.ReactNativeCustomerAdapter
16
16
  import com.reactnativestripesdk.ReactNativeCustomerSessionProvider
17
+ import com.reactnativestripesdk.buildBillingDetails
18
+ import com.reactnativestripesdk.buildBillingDetailsCollectionConfiguration
17
19
  import com.reactnativestripesdk.buildPaymentSheetAppearance
18
20
  import com.reactnativestripesdk.getBase64FromBitmap
19
21
  import com.reactnativestripesdk.getBitmapFromDrawable
20
- import com.reactnativestripesdk.mapToAddressCollectionMode
21
22
  import com.reactnativestripesdk.mapToCardBrandAcceptance
22
- import com.reactnativestripesdk.mapToCollectionMode
23
23
  import com.reactnativestripesdk.utils.CreateTokenErrorType
24
24
  import com.reactnativestripesdk.utils.ErrorType
25
25
  import com.reactnativestripesdk.utils.KeepJsAwakeTask
26
26
  import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
27
- import com.reactnativestripesdk.utils.StripeFragment
27
+ import com.reactnativestripesdk.utils.StripeUIManager
28
28
  import com.reactnativestripesdk.utils.createError
29
+ import com.reactnativestripesdk.utils.getBooleanOr
30
+ import com.reactnativestripesdk.utils.getIntegerList
31
+ import com.reactnativestripesdk.utils.getStringList
29
32
  import com.reactnativestripesdk.utils.mapFromPaymentMethod
30
33
  import com.reactnativestripesdk.utils.mapToPreferredNetworks
31
34
  import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
35
+ import com.stripe.android.core.reactnative.ReactNativeSdkInternal
32
36
  import com.stripe.android.customersheet.CustomerAdapter
33
37
  import com.stripe.android.customersheet.CustomerEphemeralKey
34
38
  import com.stripe.android.customersheet.CustomerSheet
35
39
  import com.stripe.android.customersheet.CustomerSheetResult
36
40
  import com.stripe.android.customersheet.PaymentOptionSelection
37
41
  import com.stripe.android.model.PaymentMethod
38
- import com.stripe.android.paymentsheet.ExperimentalCustomerSessionApi
39
42
  import com.stripe.android.paymentsheet.PaymentSheet
40
43
  import kotlinx.coroutines.CoroutineScope
41
44
  import kotlinx.coroutines.Dispatchers
42
45
  import kotlinx.coroutines.launch
43
46
 
44
- @OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class, ExperimentalCustomerSessionApi::class)
45
- class CustomerSheetFragment : StripeFragment() {
47
+ @OptIn(ReactNativeSdkInternal::class, ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
48
+ class CustomerSheetManager(
49
+ context: ReactApplicationContext,
50
+ private var arguments: ReadableMap,
51
+ private var customerAdapterOverrides: ReadableMap,
52
+ private var initPromise: Promise,
53
+ ) : StripeUIManager(context) {
46
54
  private var customerSheet: CustomerSheet? = null
47
55
  internal var customerAdapter: ReactNativeCustomerAdapter? = null
48
56
  internal var customerSessionProvider: ReactNativeCustomerSessionProvider? = null
49
- internal var context: ReactApplicationContext? = null
50
- internal var initPromise: Promise? = null
51
57
  private var presentPromise: Promise? = null
52
58
  private var keepJsAwake: KeepJsAwakeTask? = null
53
59
 
54
- override fun prepare() {
55
- val context =
56
- context
57
- ?: run {
58
- Log.e(
59
- "StripeReactNative",
60
- "No context found during CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
61
- )
62
- return
63
- }
64
- val initPromise =
65
- initPromise
66
- ?: run {
67
- Log.e(
68
- "StripeReactNative",
69
- "No promise found for CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
70
- )
71
- return
72
- }
73
-
74
- val headerTextForSelectionScreen = arguments?.getString("headerTextForSelectionScreen")
75
- val merchantDisplayName = arguments?.getString("merchantDisplayName")
76
- val googlePayEnabled = arguments?.getBoolean("googlePayEnabled") ?: false
77
- val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
78
- val billingConfigParams = arguments?.getBundle("billingDetailsCollectionConfiguration")
60
+ override fun onCreate() {
61
+ val headerTextForSelectionScreen = arguments.getString("headerTextForSelectionScreen")
62
+ val merchantDisplayName = arguments.getString("merchantDisplayName")
63
+ val googlePayEnabled = arguments.getBooleanOr("googlePayEnabled", false)
64
+ val billingDetailsMap = arguments.getMap("defaultBillingDetails")
65
+ val billingConfigParams = arguments.getMap("billingDetailsCollectionConfiguration")
79
66
  val allowsRemovalOfLastSavedPaymentMethod =
80
- arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod", true) ?: true
81
- val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
67
+ arguments.getBooleanOr("allowsRemovalOfLastSavedPaymentMethod", true)
68
+ val paymentMethodOrder = arguments.getStringList("paymentMethodOrder")
82
69
 
83
70
  val appearance =
84
71
  try {
85
- buildPaymentSheetAppearance(arguments?.getBundle("appearance"), context)
72
+ buildPaymentSheetAppearance(arguments.getMap("appearance"), context)
86
73
  } catch (error: PaymentSheetAppearanceException) {
87
74
  initPromise.resolve(createError(ErrorType.Failed.toString(), error))
88
75
  return
@@ -95,13 +82,13 @@ class CustomerSheetFragment : StripeFragment() {
95
82
  .googlePayEnabled(googlePayEnabled)
96
83
  .headerTextForSelectionScreen(headerTextForSelectionScreen)
97
84
  .preferredNetworks(
98
- mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")),
85
+ mapToPreferredNetworks(arguments.getIntegerList("preferredNetworks")),
99
86
  ).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
100
87
  .cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
101
88
 
102
89
  paymentMethodOrder?.let { configuration.paymentMethodOrder(it) }
103
- billingDetailsBundle?.let {
104
- configuration.defaultBillingDetails(createDefaultBillingDetails(billingDetailsBundle))
90
+ billingDetailsMap?.let {
91
+ configuration.defaultBillingDetails(createDefaultBillingDetails(billingDetailsMap))
105
92
  }
106
93
  billingConfigParams?.let {
107
94
  configuration.billingDetailsCollectionConfiguration(
@@ -109,8 +96,10 @@ class CustomerSheetFragment : StripeFragment() {
109
96
  )
110
97
  }
111
98
 
112
- val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret")
113
- val intentConfiguration = createIntentConfiguration(arguments?.getBundle("intentConfiguration"))
99
+ val activity = getCurrentActivityOrResolveWithError(initPromise) ?: return
100
+
101
+ val customerEphemeralKeySecret = arguments.getString("customerEphemeralKeySecret")
102
+ val intentConfiguration = createIntentConfiguration(arguments.getMap("intentConfiguration"))
114
103
  if (customerEphemeralKeySecret == null && intentConfiguration == null) {
115
104
  initPromise.resolve(
116
105
  createError(
@@ -128,32 +117,34 @@ class CustomerSheetFragment : StripeFragment() {
128
117
 
129
118
  customerSheet =
130
119
  CustomerSheet.create(
131
- fragment = this,
120
+ activity = activity,
132
121
  customerSessionProvider = customerSessionProvider,
133
122
  callback = ::handleResult,
134
123
  )
135
124
  } else if (intentConfiguration == null) {
136
- val customerId = arguments?.getString("customerId")
125
+ val customerId = arguments.getString("customerId")
137
126
  if (customerId == null) {
138
127
  initPromise.resolve(
139
- createError(ErrorType.Failed.toString(), "When using `customerEphemeralKeySecret` you must provide a value for `customerId`"),
128
+ createError(
129
+ ErrorType.Failed.toString(),
130
+ "When using `customerEphemeralKeySecret` you must provide a value for `customerId`",
131
+ ),
140
132
  )
141
133
  return
142
134
  }
143
- val setupIntentClientSecret = arguments?.getString("setupIntentClientSecret")
144
- val customerAdapterOverrideParams = arguments?.getBundle("customerAdapter")
135
+ val setupIntentClientSecret = arguments.getString("setupIntentClientSecret")
145
136
  val customerAdapter =
146
137
  createCustomerAdapter(
147
138
  context,
148
- customerId!!,
139
+ customerId,
149
140
  customerEphemeralKeySecret,
150
141
  setupIntentClientSecret,
151
- customerAdapterOverrideParams,
142
+ customerAdapterOverrides,
152
143
  ).also { this.customerAdapter = it }
153
144
 
154
145
  customerSheet =
155
146
  CustomerSheet.create(
156
- fragment = this,
147
+ activity = activity,
157
148
  customerAdapter = customerAdapter,
158
149
  callback = ::handleResult,
159
150
  )
@@ -168,7 +159,7 @@ class CustomerSheetFragment : StripeFragment() {
168
159
 
169
160
  customerSheet?.configure(configuration.build())
170
161
 
171
- initPromise.resolve(WritableNativeMap())
162
+ initPromise.resolve(Arguments.createMap())
172
163
  }
173
164
 
174
165
  private fun handleResult(result: CustomerSheetResult) {
@@ -193,16 +184,15 @@ class CustomerSheetFragment : StripeFragment() {
193
184
  resolvePresentPromise(promiseResult)
194
185
  }
195
186
 
196
- fun present(
197
- timeout: Long?,
198
- promise: Promise,
199
- ) {
200
- keepJsAwake = context?.let { KeepJsAwakeTask(it).apply { start() } }
187
+ override fun onPresent() {
188
+ keepJsAwake = context.let { KeepJsAwakeTask(it).apply { start() } }
201
189
  presentPromise = promise
190
+ val timeout = timeout
202
191
  if (timeout != null) {
203
192
  presentWithTimeout(timeout)
193
+ } else {
194
+ customerSheet?.present() ?: run { resolvePresentPromise(createMissingInitError()) }
204
195
  }
205
- customerSheet?.present() ?: run { resolvePresentPromise(createMissingInitError()) }
206
196
  }
207
197
 
208
198
  private fun presentWithTimeout(timeout: Long) {
@@ -232,7 +222,7 @@ class CustomerSheetFragment : StripeFragment() {
232
222
 
233
223
  override fun onActivityDestroyed(activity: Activity) {
234
224
  activities = mutableListOf()
235
- context?.currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
225
+ context.currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
236
226
  }
237
227
  }
238
228
 
@@ -248,7 +238,7 @@ class CustomerSheetFragment : StripeFragment() {
248
238
  )
249
239
 
250
240
  context
251
- ?.currentActivity
241
+ .currentActivity
252
242
  ?.application
253
243
  ?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
254
244
 
@@ -304,45 +294,21 @@ class CustomerSheetFragment : StripeFragment() {
304
294
  }
305
295
 
306
296
  companion object {
307
- internal const val TAG = "customer_sheet_launch_fragment"
308
-
309
297
  internal fun createMissingInitError(): WritableMap =
310
298
  createError(ErrorType.Failed.toString(), "No customer sheet has been initialized yet.")
311
299
 
312
- internal fun createDefaultBillingDetails(bundle: Bundle): PaymentSheet.BillingDetails {
313
- val addressBundle = bundle.getBundle("address")
314
- val address =
315
- PaymentSheet.Address(
316
- addressBundle?.getString("city"),
317
- addressBundle?.getString("country"),
318
- addressBundle?.getString("line1"),
319
- addressBundle?.getString("line2"),
320
- addressBundle?.getString("postalCode"),
321
- addressBundle?.getString("state"),
322
- )
323
- return PaymentSheet.BillingDetails(
324
- address,
325
- bundle.getString("email"),
326
- bundle.getString("name"),
327
- bundle.getString("phone"),
328
- )
329
- }
300
+ internal fun createDefaultBillingDetails(map: ReadableMap): PaymentSheet.BillingDetails =
301
+ buildBillingDetails(map) ?: PaymentSheet.BillingDetails()
330
302
 
331
- internal fun createBillingDetailsCollectionConfiguration(bundle: Bundle): PaymentSheet.BillingDetailsCollectionConfiguration =
332
- PaymentSheet.BillingDetailsCollectionConfiguration(
333
- name = mapToCollectionMode(bundle.getString("name")),
334
- phone = mapToCollectionMode(bundle.getString("phone")),
335
- email = mapToCollectionMode(bundle.getString("email")),
336
- address = mapToAddressCollectionMode(bundle.getString("address")),
337
- attachDefaultsToPaymentMethod = bundle.getBoolean("attachDefaultsToPaymentMethod", false),
338
- )
303
+ internal fun createBillingDetailsCollectionConfiguration(map: ReadableMap): PaymentSheet.BillingDetailsCollectionConfiguration =
304
+ buildBillingDetailsCollectionConfiguration(map)
339
305
 
340
306
  internal fun createCustomerAdapter(
341
307
  context: ReactApplicationContext,
342
308
  customerId: String,
343
309
  customerEphemeralKeySecret: String,
344
310
  setupIntentClientSecret: String?,
345
- customerAdapterOverrideParams: Bundle?,
311
+ customerAdapterOverrideParams: ReadableMap?,
346
312
  ): ReactNativeCustomerAdapter {
347
313
  val ephemeralKeyProvider = {
348
314
  CustomerAdapter.Result.success(
@@ -375,18 +341,17 @@ class CustomerSheetFragment : StripeFragment() {
375
341
  context = context,
376
342
  adapter = customerAdapter,
377
343
  overridesFetchPaymentMethods =
378
- customerAdapterOverrideParams?.getBoolean("fetchPaymentMethods") ?: false,
344
+ customerAdapterOverrideParams.getBooleanOr("fetchPaymentMethods", false),
379
345
  overridesAttachPaymentMethod =
380
- customerAdapterOverrideParams?.getBoolean("attachPaymentMethod") ?: false,
346
+ customerAdapterOverrideParams.getBooleanOr("attachPaymentMethod", false),
381
347
  overridesDetachPaymentMethod =
382
- customerAdapterOverrideParams?.getBoolean("detachPaymentMethod") ?: false,
348
+ customerAdapterOverrideParams.getBooleanOr("detachPaymentMethod", false),
383
349
  overridesSetSelectedPaymentOption =
384
- customerAdapterOverrideParams?.getBoolean("setSelectedPaymentOption") ?: false,
350
+ customerAdapterOverrideParams.getBooleanOr("setSelectedPaymentOption", false),
385
351
  overridesFetchSelectedPaymentOption =
386
- customerAdapterOverrideParams?.getBoolean("fetchSelectedPaymentOption") ?: false,
352
+ customerAdapterOverrideParams.getBooleanOr("fetchSelectedPaymentOption", false),
387
353
  overridesSetupIntentClientSecretForCustomerAttach =
388
- customerAdapterOverrideParams?.getBoolean("setupIntentClientSecretForCustomerAttach")
389
- ?: false,
354
+ customerAdapterOverrideParams.getBooleanOr("setupIntentClientSecretForCustomerAttach", false),
390
355
  )
391
356
  }
392
357
 
@@ -414,15 +379,15 @@ class CustomerSheetFragment : StripeFragment() {
414
379
  return paymentOptionResult
415
380
  }
416
381
 
417
- internal fun createIntentConfiguration(intentConfigurationBundle: Bundle?): CustomerSheet.IntentConfiguration? =
382
+ internal fun createIntentConfiguration(intentConfigurationBundle: ReadableMap?): CustomerSheet.IntentConfiguration? =
418
383
  intentConfigurationBundle?.let { bundle ->
419
- val onBehalfOf = bundle?.getString("onBehalfOf")
384
+ val onBehalfOf = bundle.getString("onBehalfOf")
420
385
  CustomerSheet.IntentConfiguration
421
386
  .Builder()
422
- .paymentMethodTypes(bundle?.getStringArrayList("paymentMethodTypes") ?: emptyList())
387
+ .paymentMethodTypes(bundle.getStringList("paymentMethodTypes") ?: emptyList())
423
388
  .apply {
424
389
  if (onBehalfOf != null) {
425
- this.onBehalfOf(onBehalfOf!!)
390
+ this.onBehalfOf(onBehalfOf)
426
391
  }
427
392
  }.build()
428
393
  }
@@ -2,10 +2,8 @@ package com.reactnativestripesdk
2
2
 
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
4
  import com.stripe.android.customersheet.CustomerSheet
5
- import com.stripe.android.paymentsheet.ExperimentalCustomerSessionApi
6
5
  import kotlinx.coroutines.CompletableDeferred
7
6
 
8
- @OptIn(ExperimentalCustomerSessionApi::class)
9
7
  class ReactNativeCustomerSessionProvider(
10
8
  val context: ReactApplicationContext,
11
9
  val intentConfiguration: CustomerSheet.IntentConfiguration,
@@ -13,7 +11,8 @@ class ReactNativeCustomerSessionProvider(
13
11
  private val stripeSdkModule = context.getNativeModule(StripeSdkModule::class.java)
14
12
 
15
13
  internal var provideSetupIntentClientSecretCallback: CompletableDeferred<String>? = null
16
- internal var providesCustomerSessionClientSecretCallback: CompletableDeferred<CustomerSheet.CustomerSessionClientSecret>? = null
14
+ internal var providesCustomerSessionClientSecretCallback:
15
+ CompletableDeferred<CustomerSheet.CustomerSessionClientSecret>? = null
17
16
 
18
17
  override suspend fun intentConfiguration(): Result<CustomerSheet.IntentConfiguration> = Result.success(intentConfiguration)
19
18