@stripe/stripe-react-native 0.44.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/.clang-format +90 -0
  2. package/.editorconfig +3 -0
  3. package/CHANGELOG.md +13 -1
  4. package/README.md +0 -3
  5. package/android/.gradle/8.11.1/checksums/checksums.lock +0 -0
  6. package/android/.gradle/8.11.1/checksums/md5-checksums.bin +0 -0
  7. package/android/.gradle/8.11.1/checksums/sha1-checksums.bin +0 -0
  8. package/android/.gradle/8.11.1/executionHistory/executionHistory.bin +0 -0
  9. package/android/.gradle/8.11.1/executionHistory/executionHistory.lock +0 -0
  10. package/android/.gradle/8.11.1/fileHashes/fileHashes.bin +0 -0
  11. package/android/.gradle/8.11.1/fileHashes/fileHashes.lock +0 -0
  12. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  13. package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
  14. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  15. package/android/.gradle/config.properties +2 -0
  16. package/android/.gradle/file-system.probe +0 -0
  17. package/android/.idea/caches/deviceStreaming.xml +619 -0
  18. package/android/.idea/compiler.xml +6 -0
  19. package/android/.idea/gradle.xml +19 -0
  20. package/android/.idea/migrations.xml +10 -0
  21. package/android/.idea/misc.xml +10 -0
  22. package/android/.idea/runConfigurations.xml +17 -0
  23. package/android/.idea/vcs.xml +6 -0
  24. package/android/build.gradle +90 -18
  25. package/android/gradle.properties +1 -1
  26. package/android/local.properties +8 -0
  27. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormViewManager.kt +15 -6
  28. package/android/src/main/java/com/reactnativestripesdk/CardChangeEvent.kt +56 -0
  29. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +4 -4
  30. package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +55 -45
  31. package/android/src/main/java/com/reactnativestripesdk/{CardFocusEvent.kt → CardFocusChangeEvent.kt} +2 -2
  32. package/android/src/main/java/com/reactnativestripesdk/CardFormCompleteEvent.kt +17 -16
  33. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +5 -5
  34. package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +39 -33
  35. package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +35 -36
  36. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +224 -0
  37. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +238 -0
  38. package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +11 -26
  39. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +14 -6
  40. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +3 -17
  41. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +20 -6
  42. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +63 -44
  43. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +3 -1
  44. package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +17 -0
  45. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +266 -0
  46. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +25 -33
  47. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +113 -0
  48. package/android/src/main/java/com/reactnativestripesdk/StripeContainerManager.kt +11 -3
  49. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +180 -65
  50. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +34 -4
  51. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +3 -17
  52. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +33 -27
  53. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +49 -24
  54. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +19 -24
  55. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +11 -29
  56. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +36 -12
  57. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +5 -3
  58. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +4 -0
  59. package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +2 -2
  60. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +21 -0
  61. package/android/src/main/java/com/reactnativestripesdk/utils/StripeFragment.kt +52 -0
  62. package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerDelegate.java +49 -0
  63. package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerInterface.java +25 -0
  64. package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerDelegate.java +64 -0
  65. package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerInterface.java +30 -0
  66. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerDelegate.java +41 -0
  67. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java +20 -0
  68. package/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerDelegate.java +36 -0
  69. package/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerInterface.java +20 -0
  70. package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerDelegate.java +73 -0
  71. package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerInterface.java +31 -0
  72. package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerDelegate.java +67 -0
  73. package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerInterface.java +29 -0
  74. package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerDelegate.java +49 -0
  75. package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java +21 -0
  76. package/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerDelegate.java +38 -0
  77. package/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerInterface.java +19 -0
  78. package/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerDelegate.java +32 -0
  79. package/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerInterface.java +17 -0
  80. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +310 -0
  81. package/ios/AddressSheet/AddressSheetUtils.swift +21 -19
  82. package/ios/AddressSheet/AddressSheetView.swift +23 -17
  83. package/ios/ApplePayButtonManager.m +0 -1
  84. package/ios/ApplePayButtonManager.swift +1 -3
  85. package/ios/ApplePayButtonView.swift +25 -20
  86. package/ios/ApplePayViewController.swift +22 -22
  87. package/ios/AuBECSDebitFormView.swift +14 -8
  88. package/ios/CardFieldManager.swift +1 -4
  89. package/ios/CardFieldView.swift +28 -25
  90. package/ios/CardFormManager.swift +1 -4
  91. package/ios/CardFormView.swift +25 -16
  92. package/ios/CustomerSheet/CustomerSheetUtils.swift +12 -16
  93. package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +8 -8
  94. package/ios/EmbeddedPaymentElementManager.m +6 -0
  95. package/ios/EmbeddedPaymentElementView.swift +49 -0
  96. package/ios/NewArch/AddToWalletButtonComponentView.h +10 -0
  97. package/ios/NewArch/AddToWalletButtonComponentView.mm +93 -0
  98. package/ios/NewArch/AddressSheetViewComponentView.h +10 -0
  99. package/ios/NewArch/AddressSheetViewComponentView.mm +109 -0
  100. package/ios/NewArch/ApplePayButtonComponentView.h +10 -0
  101. package/ios/NewArch/ApplePayButtonComponentView.mm +124 -0
  102. package/ios/NewArch/AuBECSDebitFormComponentView.h +10 -0
  103. package/ios/NewArch/AuBECSDebitFormComponentView.mm +95 -0
  104. package/ios/NewArch/CardFieldComponentView.h +10 -0
  105. package/ios/NewArch/CardFieldComponentView.mm +125 -0
  106. package/ios/NewArch/CardFormComponentView.h +10 -0
  107. package/ios/NewArch/CardFormComponentView.mm +108 -0
  108. package/ios/NewArch/EmbeddedPaymentElementViewComponentView.h +10 -0
  109. package/ios/NewArch/EmbeddedPaymentElementViewComponentView.mm +81 -0
  110. package/ios/NewArch/StripeContainerComponentView.h +10 -0
  111. package/ios/NewArch/StripeContainerComponentView.mm +74 -0
  112. package/ios/NewArch/StripeNewArchConversions.h +20 -0
  113. package/ios/NewArch/StripeNewArchConversions.mm +47 -0
  114. package/ios/OldArch/StripeSdkEventEmitterCompat.h +27 -0
  115. package/ios/OldArch/StripeSdkEventEmitterCompat.m +105 -0
  116. package/ios/PaymentOptionDisplayData+ReactNative.swift +55 -0
  117. package/ios/PaymentSheetAppearance.swift +194 -1
  118. package/ios/PushProvisioning/AddToWalletButtonView.swift +19 -13
  119. package/ios/StripeContainerView.swift +5 -3
  120. package/ios/StripeSdk.h +21 -0
  121. package/ios/StripeSdk.mm +415 -0
  122. package/ios/StripeSdkEmitter.swift +19 -0
  123. package/ios/{StripeSdk+CustomerSheet.swift → StripeSdkImpl+CustomerSheet.swift} +24 -25
  124. package/ios/StripeSdkImpl+Embedded.swift +327 -0
  125. package/ios/{StripeSdk+PaymentSheet.swift → StripeSdkImpl+PaymentSheet.swift} +18 -29
  126. package/ios/{StripeSdk.swift → StripeSdkImpl.swift} +50 -72
  127. package/ios/StripeSwiftInterop.h +25 -0
  128. package/ios/stripe_react_native.h +2 -0
  129. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  130. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  131. package/lib/commonjs/components/AddressSheet.js +1 -1
  132. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  133. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  134. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  135. package/lib/commonjs/components/CardField.js +1 -1
  136. package/lib/commonjs/components/CardField.js.map +1 -1
  137. package/lib/commonjs/components/CardForm.js +1 -1
  138. package/lib/commonjs/components/CardForm.js.map +1 -1
  139. package/lib/commonjs/components/CustomerSheet.js +1 -1
  140. package/lib/commonjs/components/CustomerSheet.js.map +1 -1
  141. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  142. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  143. package/lib/commonjs/components/StripeContainer.js +1 -1
  144. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  145. package/lib/commonjs/components/StripeProvider.js +1 -1
  146. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  147. package/lib/commonjs/events.js +2 -0
  148. package/lib/commonjs/events.js.map +1 -0
  149. package/lib/commonjs/functions.js +1 -1
  150. package/lib/commonjs/functions.js.map +1 -1
  151. package/lib/commonjs/index.js +1 -1
  152. package/lib/commonjs/index.js.map +1 -1
  153. package/lib/commonjs/specs/NativeAddToWalletButton.js +2 -0
  154. package/lib/commonjs/specs/NativeAddToWalletButton.js.map +1 -0
  155. package/lib/commonjs/specs/NativeAddressSheet.js +2 -0
  156. package/lib/commonjs/specs/NativeAddressSheet.js.map +1 -0
  157. package/lib/commonjs/specs/NativeApplePayButton.js +2 -0
  158. package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -0
  159. package/lib/commonjs/specs/NativeAuBECSDebitForm.js +2 -0
  160. package/lib/commonjs/specs/NativeAuBECSDebitForm.js.map +1 -0
  161. package/lib/commonjs/specs/NativeCardField.js +2 -0
  162. package/lib/commonjs/specs/NativeCardField.js.map +1 -0
  163. package/lib/commonjs/specs/NativeCardForm.js +2 -0
  164. package/lib/commonjs/specs/NativeCardForm.js.map +1 -0
  165. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +2 -0
  166. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -0
  167. package/lib/commonjs/specs/NativeGooglePayButton.js +2 -0
  168. package/lib/commonjs/specs/NativeGooglePayButton.js.map +1 -0
  169. package/lib/commonjs/specs/NativeStripeContainer.js +2 -0
  170. package/lib/commonjs/specs/NativeStripeContainer.js.map +1 -0
  171. package/lib/commonjs/specs/NativeStripeSdkModule.js +2 -0
  172. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -0
  173. package/lib/commonjs/specs/utils.js +2 -0
  174. package/lib/commonjs/specs/utils.js.map +1 -0
  175. package/lib/commonjs/types/EmbeddedPaymentElement.js +2 -0
  176. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -0
  177. package/lib/commonjs/types/PaymentSheet.js +1 -1
  178. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  179. package/lib/module/components/AddToWalletButton.js +1 -1
  180. package/lib/module/components/AddToWalletButton.js.map +1 -1
  181. package/lib/module/components/AddressSheet.js +1 -1
  182. package/lib/module/components/AddressSheet.js.map +1 -1
  183. package/lib/module/components/AuBECSDebitForm.js +1 -1
  184. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  185. package/lib/module/components/CardField.js +1 -1
  186. package/lib/module/components/CardField.js.map +1 -1
  187. package/lib/module/components/CardForm.js +1 -1
  188. package/lib/module/components/CardForm.js.map +1 -1
  189. package/lib/module/components/CustomerSheet.js +1 -1
  190. package/lib/module/components/CustomerSheet.js.map +1 -1
  191. package/lib/module/components/PlatformPayButton.js +1 -1
  192. package/lib/module/components/PlatformPayButton.js.map +1 -1
  193. package/lib/module/components/StripeContainer.js +1 -1
  194. package/lib/module/components/StripeContainer.js.map +1 -1
  195. package/lib/module/components/StripeProvider.js +1 -1
  196. package/lib/module/components/StripeProvider.js.map +1 -1
  197. package/lib/module/events.js +2 -0
  198. package/lib/module/events.js.map +1 -0
  199. package/lib/module/functions.js +1 -1
  200. package/lib/module/functions.js.map +1 -1
  201. package/lib/module/index.js +1 -1
  202. package/lib/module/index.js.map +1 -1
  203. package/lib/module/specs/NativeAddToWalletButton.js +2 -0
  204. package/lib/module/specs/NativeAddToWalletButton.js.map +1 -0
  205. package/lib/module/specs/NativeAddressSheet.js +2 -0
  206. package/lib/module/specs/NativeAddressSheet.js.map +1 -0
  207. package/lib/module/specs/NativeApplePayButton.js +2 -0
  208. package/lib/module/specs/NativeApplePayButton.js.map +1 -0
  209. package/lib/module/specs/NativeAuBECSDebitForm.js +2 -0
  210. package/lib/module/specs/NativeAuBECSDebitForm.js.map +1 -0
  211. package/lib/module/specs/NativeCardField.js +2 -0
  212. package/lib/module/specs/NativeCardField.js.map +1 -0
  213. package/lib/module/specs/NativeCardForm.js +2 -0
  214. package/lib/module/specs/NativeCardForm.js.map +1 -0
  215. package/lib/module/specs/NativeEmbeddedPaymentElement.js +2 -0
  216. package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -0
  217. package/lib/module/specs/NativeGooglePayButton.js +2 -0
  218. package/lib/module/specs/NativeGooglePayButton.js.map +1 -0
  219. package/lib/module/specs/NativeStripeContainer.js +2 -0
  220. package/lib/module/specs/NativeStripeContainer.js.map +1 -0
  221. package/lib/module/specs/NativeStripeSdkModule.js +2 -0
  222. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -0
  223. package/lib/module/specs/utils.js +2 -0
  224. package/lib/module/specs/utils.js.map +1 -0
  225. package/lib/module/types/EmbeddedPaymentElement.js +2 -0
  226. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -0
  227. package/lib/module/types/PaymentSheet.js +1 -1
  228. package/lib/module/types/PaymentSheet.js.map +1 -1
  229. package/lib/typescript/src/components/AddToWalletButton.d.ts.map +1 -1
  230. package/lib/typescript/src/components/AddressSheet.d.ts.map +1 -1
  231. package/lib/typescript/src/components/AuBECSDebitForm.d.ts.map +1 -1
  232. package/lib/typescript/src/components/CardField.d.ts +1 -1
  233. package/lib/typescript/src/components/CardField.d.ts.map +1 -1
  234. package/lib/typescript/src/components/CardForm.d.ts +1 -1
  235. package/lib/typescript/src/components/CardForm.d.ts.map +1 -1
  236. package/lib/typescript/src/components/CustomerSheet.d.ts +1 -1
  237. package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -1
  238. package/lib/typescript/src/components/StripeContainer.d.ts.map +1 -1
  239. package/lib/typescript/src/events.d.ts +13 -0
  240. package/lib/typescript/src/events.d.ts.map +1 -0
  241. package/lib/typescript/src/functions.d.ts.map +1 -1
  242. package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +4 -4
  243. package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts.map +1 -1
  244. package/lib/typescript/src/hooks/useStripe.d.ts +2 -2
  245. package/lib/typescript/src/hooks/useStripe.d.ts.map +1 -1
  246. package/lib/typescript/src/index.d.ts +2 -0
  247. package/lib/typescript/src/index.d.ts.map +1 -1
  248. package/lib/typescript/src/specs/NativeAddToWalletButton.d.ts +27 -0
  249. package/lib/typescript/src/specs/NativeAddToWalletButton.d.ts.map +1 -0
  250. package/lib/typescript/src/specs/NativeAddressSheet.d.ts +34 -0
  251. package/lib/typescript/src/specs/NativeAddressSheet.d.ts.map +1 -0
  252. package/lib/typescript/src/specs/NativeApplePayButton.d.ts +28 -0
  253. package/lib/typescript/src/specs/NativeApplePayButton.d.ts.map +1 -0
  254. package/lib/typescript/src/specs/NativeAuBECSDebitForm.d.ts +19 -0
  255. package/lib/typescript/src/specs/NativeAuBECSDebitForm.d.ts.map +1 -0
  256. package/lib/typescript/src/specs/NativeCardField.d.ts +33 -0
  257. package/lib/typescript/src/specs/NativeCardField.d.ts.map +1 -0
  258. package/lib/typescript/src/specs/NativeCardForm.d.ts +31 -0
  259. package/lib/typescript/src/specs/NativeCardForm.d.ts.map +1 -0
  260. package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts +17 -0
  261. package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts.map +1 -0
  262. package/lib/typescript/src/specs/NativeGooglePayButton.d.ts +11 -0
  263. package/lib/typescript/src/specs/NativeGooglePayButton.d.ts.map +1 -0
  264. package/lib/typescript/src/specs/NativeStripeContainer.d.ts +8 -0
  265. package/lib/typescript/src/specs/NativeStripeContainer.d.ts.map +1 -0
  266. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +93 -0
  267. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -0
  268. package/lib/typescript/src/specs/utils.d.ts +20 -0
  269. package/lib/typescript/src/specs/utils.d.ts.map +1 -0
  270. package/lib/typescript/src/types/CustomerSheet.d.ts +1 -5
  271. package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -1
  272. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +161 -0
  273. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -0
  274. package/lib/typescript/src/types/PaymentSheet.d.ts +97 -4
  275. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  276. package/lib/typescript/src/types/components/CardFieldInput.d.ts +3 -2
  277. package/lib/typescript/src/types/components/CardFieldInput.d.ts.map +1 -1
  278. package/lib/typescript/src/types/components/CardFormView.d.ts +3 -1
  279. package/lib/typescript/src/types/components/CardFormView.d.ts.map +1 -1
  280. package/package.json +22 -2
  281. package/src/components/AddToWalletButton.tsx +2 -5
  282. package/src/components/AddressSheet.tsx +5 -16
  283. package/src/components/AuBECSDebitForm.tsx +3 -12
  284. package/src/components/CardField.tsx +20 -30
  285. package/src/components/CardForm.tsx +14 -29
  286. package/src/components/CustomerSheet.tsx +23 -25
  287. package/src/components/PlatformPayButton.tsx +6 -6
  288. package/src/components/StripeContainer.tsx +5 -12
  289. package/src/components/StripeProvider.tsx +1 -1
  290. package/src/events.ts +49 -0
  291. package/src/functions.ts +13 -24
  292. package/src/hooks/useFinancialConnectionsSheet.tsx +2 -2
  293. package/src/hooks/useStripe.tsx +2 -2
  294. package/src/index.tsx +3 -0
  295. package/src/specs/NativeAddToWalletButton.ts +40 -0
  296. package/src/specs/NativeAddressSheet.ts +50 -0
  297. package/src/specs/NativeApplePayButton.ts +40 -0
  298. package/src/specs/NativeAuBECSDebitForm.ts +24 -0
  299. package/src/specs/NativeCardField.ts +51 -0
  300. package/src/specs/NativeCardForm.ts +43 -0
  301. package/src/specs/NativeEmbeddedPaymentElement.ts +28 -0
  302. package/src/specs/NativeGooglePayButton.ts +20 -0
  303. package/src/specs/NativeStripeContainer.ts +12 -0
  304. package/src/specs/NativeStripeSdkModule.ts +219 -0
  305. package/src/specs/utils.ts +22 -0
  306. package/src/types/CustomerSheet.ts +1 -5
  307. package/src/types/EmbeddedPaymentElement.tsx +467 -0
  308. package/src/types/PaymentSheet.ts +114 -4
  309. package/src/types/components/CardFieldInput.ts +1 -2
  310. package/src/types/components/CardFormView.ts +1 -1
  311. package/stripe-react-native.podspec +27 -2
  312. package/android/src/main/java/com/reactnativestripesdk/CardChangedEvent.kt +0 -54
  313. package/ios/StripeSdk.m +0 -244
  314. package/lib/commonjs/NativeStripeSdk.js +0 -2
  315. package/lib/commonjs/NativeStripeSdk.js.map +0 -1
  316. package/lib/commonjs/components/ApplePayButtonNative.js +0 -2
  317. package/lib/commonjs/components/ApplePayButtonNative.js.map +0 -1
  318. package/lib/commonjs/components/GooglePayButtonNative.js +0 -2
  319. package/lib/commonjs/components/GooglePayButtonNative.js.map +0 -1
  320. package/lib/module/NativeStripeSdk.js +0 -2
  321. package/lib/module/NativeStripeSdk.js.map +0 -1
  322. package/lib/module/components/ApplePayButtonNative.js +0 -2
  323. package/lib/module/components/ApplePayButtonNative.js.map +0 -1
  324. package/lib/module/components/GooglePayButtonNative.js +0 -2
  325. package/lib/module/components/GooglePayButtonNative.js.map +0 -1
  326. package/lib/typescript/src/NativeStripeSdk.d.ts +0 -58
  327. package/lib/typescript/src/NativeStripeSdk.d.ts.map +0 -1
  328. package/lib/typescript/src/components/ApplePayButtonNative.d.ts +0 -4
  329. package/lib/typescript/src/components/ApplePayButtonNative.d.ts.map +0 -1
  330. package/lib/typescript/src/components/GooglePayButtonNative.d.ts +0 -4
  331. package/lib/typescript/src/components/GooglePayButtonNative.d.ts.map +0 -1
  332. package/src/NativeStripeSdk.tsx +0 -159
  333. package/src/components/ApplePayButtonNative.tsx +0 -5
  334. package/src/components/GooglePayButtonNative.tsx +0 -7
@@ -0,0 +1,238 @@
1
+ package com.reactnativestripesdk
2
+
3
+ import android.annotation.SuppressLint
4
+ import android.content.Context
5
+ import com.facebook.react.bridge.Dynamic
6
+ import com.facebook.react.bridge.ReadableArray
7
+ import com.facebook.react.bridge.ReadableMap
8
+ import com.facebook.react.bridge.ReadableType
9
+ import com.facebook.react.module.annotations.ReactModule
10
+ import com.facebook.react.uimanager.ThemedReactContext
11
+ import com.facebook.react.uimanager.ViewGroupManager
12
+ import com.facebook.react.uimanager.annotations.ReactProp
13
+ import com.facebook.react.viewmanagers.EmbeddedPaymentElementViewManagerDelegate
14
+ import com.facebook.react.viewmanagers.EmbeddedPaymentElementViewManagerInterface
15
+ import com.reactnativestripesdk.PaymentSheetFragment.Companion.buildCustomerConfiguration
16
+ import com.reactnativestripesdk.PaymentSheetFragment.Companion.buildGooglePayConfig
17
+ import com.reactnativestripesdk.addresssheet.AddressSheetView
18
+ import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
19
+ import com.reactnativestripesdk.utils.PaymentSheetException
20
+ import com.reactnativestripesdk.utils.mapToPreferredNetworks
21
+ import com.reactnativestripesdk.utils.toBundleObject
22
+ import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
23
+ import com.stripe.android.paymentelement.EmbeddedPaymentElement
24
+ import com.stripe.android.paymentelement.ExperimentalEmbeddedPaymentElementApi
25
+ import com.stripe.android.paymentsheet.PaymentSheet
26
+
27
+ @OptIn(ExperimentalEmbeddedPaymentElementApi::class)
28
+ @ReactModule(name = EmbeddedPaymentElementViewManager.NAME)
29
+ class EmbeddedPaymentElementViewManager :
30
+ ViewGroupManager<EmbeddedPaymentElementView>(),
31
+ EmbeddedPaymentElementViewManagerInterface<EmbeddedPaymentElementView> {
32
+ companion object {
33
+ const val NAME = "EmbeddedPaymentElementView"
34
+ }
35
+
36
+ private val delegate = EmbeddedPaymentElementViewManagerDelegate(this)
37
+
38
+ override fun getName() = NAME
39
+
40
+ override fun getDelegate() = delegate
41
+
42
+ override fun createViewInstance(ctx: ThemedReactContext): EmbeddedPaymentElementView = EmbeddedPaymentElementView(ctx)
43
+
44
+ override fun onDropViewInstance(view: EmbeddedPaymentElementView) {
45
+ super.onDropViewInstance(view)
46
+
47
+ view.handleOnDropViewInstance()
48
+ }
49
+
50
+ override fun needsCustomLayoutForChildren(): Boolean = true
51
+
52
+ @ReactProp(name = "configuration")
53
+ override fun setConfiguration(
54
+ view: EmbeddedPaymentElementView,
55
+ cfg: Dynamic,
56
+ ) {
57
+ val elementConfig = parseElementConfiguration(cfg.asMap(), view.context)
58
+ view.latestElementConfig = elementConfig
59
+ // if intentConfig is already set, configure immediately:
60
+ view.latestIntentConfig?.let { intentCfg ->
61
+ view.configure(elementConfig, intentCfg)
62
+ view.post {
63
+ view.requestLayout()
64
+ view.invalidate()
65
+ }
66
+ }
67
+ }
68
+
69
+ @ReactProp(name = "intentConfiguration")
70
+ override fun setIntentConfiguration(
71
+ view: EmbeddedPaymentElementView,
72
+ cfg: Dynamic,
73
+ ) {
74
+ val intentConfig = parseIntentConfiguration(cfg.asMap())
75
+ view.latestIntentConfig = intentConfig
76
+ view.latestElementConfig?.let { elemCfg ->
77
+ view.configure(elemCfg, intentConfig)
78
+ }
79
+ }
80
+
81
+ @SuppressLint("RestrictedApi")
82
+ @OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
83
+ private fun parseElementConfiguration(
84
+ map: ReadableMap,
85
+ context: Context,
86
+ ): EmbeddedPaymentElement.Configuration {
87
+ val merchantDisplayName = map.getString("merchantDisplayName").orEmpty()
88
+ val allowsDelayedPaymentMethods: Boolean =
89
+ if (map.hasKey("allowsDelayedPaymentMethods") &&
90
+ map.getType("allowsDelayedPaymentMethods") == ReadableType.Boolean
91
+ ) {
92
+ map.getBoolean("allowsDelayedPaymentMethods")
93
+ } else {
94
+ false // default
95
+ }
96
+ var defaultBillingDetails: PaymentSheet.BillingDetails? = null
97
+ val billingDetailsMap = map.getMap("defaultBillingDetails")
98
+ if (billingDetailsMap != null) {
99
+ val addressBundle = billingDetailsMap.getMap("address")
100
+ val address =
101
+ PaymentSheet.Address(
102
+ addressBundle?.getString("city"),
103
+ addressBundle?.getString("country"),
104
+ addressBundle?.getString("line1"),
105
+ addressBundle?.getString("line2"),
106
+ addressBundle?.getString("postalCode"),
107
+ addressBundle?.getString("state"),
108
+ )
109
+ defaultBillingDetails =
110
+ PaymentSheet.BillingDetails(
111
+ address,
112
+ billingDetailsMap.getString("email"),
113
+ billingDetailsMap.getString("name"),
114
+ billingDetailsMap.getString("phone"),
115
+ )
116
+ }
117
+
118
+ val customerConfiguration =
119
+ try {
120
+ buildCustomerConfiguration(toBundleObject(map))
121
+ } catch (error: PaymentSheetException) {
122
+ throw Error() // TODO handle error
123
+ }
124
+
125
+ val googlePayConfig = buildGooglePayConfig(toBundleObject(map.getMap("googlePay")))
126
+ val shippingDetails =
127
+ map.getMap("defaultShippingDetails")?.let {
128
+ AddressSheetView.buildAddressDetails(it)
129
+ }
130
+ val appearance =
131
+ try {
132
+ buildPaymentSheetAppearance(toBundleObject(map.getMap("appearance")), context)
133
+ } catch (error: PaymentSheetAppearanceException) {
134
+ throw Error() // TODO handle error
135
+ }
136
+ val billingConfigParams = map.getMap("billingDetailsCollectionConfiguration")
137
+ val billingDetailsConfig =
138
+ PaymentSheet.BillingDetailsCollectionConfiguration(
139
+ name = mapToCollectionMode(billingConfigParams?.getString("name")),
140
+ phone = mapToCollectionMode(billingConfigParams?.getString("phone")),
141
+ email = mapToCollectionMode(billingConfigParams?.getString("email")),
142
+ address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
143
+ attachDefaultsToPaymentMethod =
144
+ billingConfigParams?.getBoolean("attachDefaultsToPaymentMethod") ?: false,
145
+ )
146
+ val allowsRemovalOfLastSavedPaymentMethod =
147
+ if (map.hasKey("allowsRemovalOfLastSavedPaymentMethod")) {
148
+ map.getBoolean("allowsRemovalOfLastSavedPaymentMethod")
149
+ } else {
150
+ true
151
+ }
152
+ val primaryButtonLabel = map.getString("primaryButtonLabel")
153
+ val paymentMethodOrder = map.getStringArrayList("paymentMethodOrder")
154
+
155
+ val formSheetAction =
156
+ map
157
+ .getMap("formSheetAction")
158
+ ?.getString("type")
159
+ ?.let { type ->
160
+ when (type) {
161
+ "confirm" -> EmbeddedPaymentElement.FormSheetAction.Confirm
162
+ else -> EmbeddedPaymentElement.FormSheetAction.Continue
163
+ }
164
+ }
165
+ ?: EmbeddedPaymentElement.FormSheetAction.Continue
166
+
167
+ val configurationBuilder =
168
+ EmbeddedPaymentElement.Configuration
169
+ .Builder(merchantDisplayName)
170
+ .formSheetAction(formSheetAction)
171
+ .allowsDelayedPaymentMethods(allowsDelayedPaymentMethods ?: false)
172
+ .defaultBillingDetails(defaultBillingDetails)
173
+ .customer(customerConfiguration)
174
+ .googlePay(googlePayConfig)
175
+ .appearance(appearance)
176
+ .shippingDetails(shippingDetails)
177
+ .billingDetailsCollectionConfiguration(billingDetailsConfig)
178
+ .preferredNetworks(
179
+ mapToPreferredNetworks(
180
+ map
181
+ .getIntegerArrayList("preferredNetworks")
182
+ ?.let { ArrayList(it) },
183
+ ),
184
+ ).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
185
+ .cardBrandAcceptance(mapToCardBrandAcceptance(toBundleObject(map)))
186
+
187
+ primaryButtonLabel?.let { configurationBuilder.primaryButtonLabel(it) }
188
+ paymentMethodOrder?.let { configurationBuilder.paymentMethodOrder(it) }
189
+
190
+ return configurationBuilder.build()
191
+ }
192
+
193
+ private fun parseIntentConfiguration(map: ReadableMap): PaymentSheet.IntentConfiguration {
194
+ val intentConfig = PaymentSheetFragment.buildIntentConfiguration(toBundleObject(map))
195
+ return intentConfig ?: throw IllegalArgumentException("IntentConfiguration is null")
196
+ }
197
+
198
+ override fun confirm(view: EmbeddedPaymentElementView) {
199
+ view.confirm()
200
+ }
201
+
202
+ override fun clearPaymentOption(view: EmbeddedPaymentElementView) {
203
+ view.clearPaymentOption()
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Returns a List of Strings if the key exists and points to an array of strings, or null otherwise.
209
+ */
210
+ fun ReadableMap.getStringArrayList(key: String): List<String>? {
211
+ if (!hasKey(key) || getType(key) != ReadableType.Array) return null
212
+ val array: ReadableArray = getArray(key) ?: return null
213
+
214
+ val result = mutableListOf<String>()
215
+ for (i in 0 until array.size()) {
216
+ // getString returns null if the element isn't actually a string
217
+ array.getString(i)?.let { result.add(it) }
218
+ }
219
+ return result
220
+ }
221
+
222
+ /**
223
+ * Returns a List of Ints if the key exists and points to an array of numbers, or null otherwise.
224
+ */
225
+ fun ReadableMap.getIntegerArrayList(key: String): List<Int>? {
226
+ if (!hasKey(key) || getType(key) != ReadableType.Array) return null
227
+ val array: ReadableArray = getArray(key) ?: return null
228
+
229
+ val result = mutableListOf<Int>()
230
+ for (i in 0 until array.size()) {
231
+ // getType check to skip non-number entries
232
+ if (array.getType(i) == ReadableType.Number) {
233
+ // if it's actually a float/double, this will truncate; adjust as needed
234
+ result.add(array.getInt(i))
235
+ }
236
+ }
237
+ return result
238
+ }
@@ -1,11 +1,5 @@
1
1
  package com.reactnativestripesdk
2
2
 
3
- import android.os.Bundle
4
- import android.view.LayoutInflater
5
- import android.view.View
6
- import android.view.ViewGroup
7
- import android.widget.FrameLayout
8
- import androidx.fragment.app.Fragment
9
3
  import androidx.fragment.app.FragmentActivity
10
4
  import com.facebook.react.bridge.Arguments
11
5
  import com.facebook.react.bridge.Promise
@@ -15,6 +9,7 @@ import com.facebook.react.bridge.WritableArray
15
9
  import com.facebook.react.bridge.WritableMap
16
10
  import com.facebook.react.bridge.WritableNativeMap
17
11
  import com.reactnativestripesdk.utils.ErrorType
12
+ import com.reactnativestripesdk.utils.StripeFragment
18
13
  import com.reactnativestripesdk.utils.createError
19
14
  import com.reactnativestripesdk.utils.createMissingActivityError
20
15
  import com.reactnativestripesdk.utils.mapFromFinancialConnectionsEvent
@@ -29,7 +24,7 @@ import com.stripe.android.financialconnections.model.FinancialConnectionsAccount
29
24
  import com.stripe.android.financialconnections.model.FinancialConnectionsAccountList
30
25
  import com.stripe.android.financialconnections.model.FinancialConnectionsSession
31
26
 
32
- class FinancialConnectionsSheetFragment : Fragment() {
27
+ class FinancialConnectionsSheetFragment : StripeFragment() {
33
28
  enum class Mode {
34
29
  ForToken,
35
30
  ForSession,
@@ -40,28 +35,13 @@ class FinancialConnectionsSheetFragment : Fragment() {
40
35
  private lateinit var configuration: FinancialConnectionsSheet.Configuration
41
36
  private lateinit var mode: Mode
42
37
 
43
- override fun onCreate(savedInstanceState: Bundle?) {
44
- super.onCreate(savedInstanceState)
45
-
38
+ override fun prepare() {
46
39
  val stripeSdkModule: StripeSdkModule? = context.getNativeModule(StripeSdkModule::class.java)
47
- if (stripeSdkModule != null && stripeSdkModule.eventListenerCount > 0) {
48
- FinancialConnections.setEventListener { event ->
49
- val params = mapFromFinancialConnectionsEvent(event)
50
- stripeSdkModule.sendEvent(context, "onFinancialConnectionsEvent", params)
51
- }
40
+ FinancialConnections.setEventListener { event ->
41
+ val params = mapFromFinancialConnectionsEvent(event)
42
+ stripeSdkModule?.emitOnFinancialConnectionsEvent(params)
52
43
  }
53
- }
54
44
 
55
- override fun onCreateView(
56
- inflater: LayoutInflater,
57
- container: ViewGroup?,
58
- savedInstanceState: Bundle?,
59
- ): View = FrameLayout(requireActivity()).also { it.visibility = View.GONE }
60
-
61
- override fun onViewCreated(
62
- view: View,
63
- savedInstanceState: Bundle?,
64
- ) {
65
45
  when (mode) {
66
46
  Mode.ForToken -> {
67
47
  FinancialConnectionsSheet
@@ -70,6 +50,7 @@ class FinancialConnectionsSheetFragment : Fragment() {
70
50
  ::onFinancialConnectionsSheetForTokenResult,
71
51
  ).present(configuration = configuration)
72
52
  }
53
+
73
54
  Mode.ForSession -> {
74
55
  FinancialConnectionsSheet
75
56
  .create(this, ::onFinancialConnectionsSheetForDataResult)
@@ -90,9 +71,11 @@ class FinancialConnectionsSheetFragment : Fragment() {
90
71
  is FinancialConnectionsSheetForTokenResult.Canceled -> {
91
72
  promise.resolve(createError(ErrorType.Canceled.toString(), "The flow has been canceled"))
92
73
  }
74
+
93
75
  is FinancialConnectionsSheetForTokenResult.Failed -> {
94
76
  promise.resolve(createError(ErrorType.Failed.toString(), result.error))
95
77
  }
78
+
96
79
  is FinancialConnectionsSheetForTokenResult.Completed -> {
97
80
  promise.resolve(createTokenResult(result))
98
81
  (context.currentActivity as? FragmentActivity)
@@ -109,9 +92,11 @@ class FinancialConnectionsSheetFragment : Fragment() {
109
92
  is FinancialConnectionsSheetResult.Canceled -> {
110
93
  promise.resolve(createError(ErrorType.Canceled.toString(), "The flow has been canceled"))
111
94
  }
95
+
112
96
  is FinancialConnectionsSheetResult.Failed -> {
113
97
  promise.resolve(createError(ErrorType.Failed.toString(), result.error))
114
98
  }
99
+
115
100
  is FinancialConnectionsSheetResult.Completed -> {
116
101
  promise.resolve(
117
102
  WritableNativeMap().also {
@@ -4,11 +4,21 @@ import com.facebook.react.module.annotations.ReactModule
4
4
  import com.facebook.react.uimanager.SimpleViewManager
5
5
  import com.facebook.react.uimanager.ThemedReactContext
6
6
  import com.facebook.react.uimanager.annotations.ReactProp
7
+ import com.facebook.react.viewmanagers.GooglePayButtonManagerDelegate
8
+ import com.facebook.react.viewmanagers.GooglePayButtonManagerInterface
7
9
 
8
10
  @ReactModule(name = GooglePayButtonManager.REACT_CLASS)
9
- class GooglePayButtonManager : SimpleViewManager<GooglePayButtonView>() {
11
+ class GooglePayButtonManager :
12
+ SimpleViewManager<GooglePayButtonView>(),
13
+ GooglePayButtonManagerInterface<GooglePayButtonView> {
14
+ private val delegate = GooglePayButtonManagerDelegate(this)
15
+
10
16
  override fun getName() = REACT_CLASS
11
17
 
18
+ override fun getDelegate() = delegate
19
+
20
+ override fun createViewInstance(reactContext: ThemedReactContext): GooglePayButtonView = GooglePayButtonView(reactContext)
21
+
12
22
  override fun onAfterUpdateTransaction(view: GooglePayButtonView) {
13
23
  super.onAfterUpdateTransaction(view)
14
24
 
@@ -16,7 +26,7 @@ class GooglePayButtonManager : SimpleViewManager<GooglePayButtonView>() {
16
26
  }
17
27
 
18
28
  @ReactProp(name = "type")
19
- fun type(
29
+ override fun setType(
20
30
  view: GooglePayButtonView,
21
31
  buttonType: Int,
22
32
  ) {
@@ -24,7 +34,7 @@ class GooglePayButtonManager : SimpleViewManager<GooglePayButtonView>() {
24
34
  }
25
35
 
26
36
  @ReactProp(name = "appearance")
27
- fun appearance(
37
+ override fun setAppearance(
28
38
  view: GooglePayButtonView,
29
39
  appearance: Int,
30
40
  ) {
@@ -32,15 +42,13 @@ class GooglePayButtonManager : SimpleViewManager<GooglePayButtonView>() {
32
42
  }
33
43
 
34
44
  @ReactProp(name = "borderRadius")
35
- fun borderRadius(
45
+ override fun setBorderRadius(
36
46
  view: GooglePayButtonView,
37
47
  borderRadius: Int,
38
48
  ) {
39
49
  view.setBorderRadius(borderRadius)
40
50
  }
41
51
 
42
- override fun createViewInstance(reactContext: ThemedReactContext): GooglePayButtonView = GooglePayButtonView(reactContext)
43
-
44
52
  companion object {
45
53
  const val REACT_CLASS = "GooglePayButton"
46
54
  }
@@ -1,17 +1,12 @@
1
1
  package com.reactnativestripesdk
2
2
 
3
- import android.os.Bundle
4
- import android.view.LayoutInflater
5
- import android.view.View
6
- import android.view.ViewGroup
7
- import android.widget.FrameLayout
8
- import androidx.fragment.app.Fragment
9
3
  import androidx.fragment.app.FragmentActivity
10
4
  import com.facebook.react.bridge.ReactApplicationContext
11
5
  import com.facebook.react.bridge.ReadableMap
12
6
  import com.facebook.react.bridge.WritableMap
13
7
  import com.reactnativestripesdk.utils.ErrorType
14
8
  import com.reactnativestripesdk.utils.GooglePayErrorType
9
+ import com.reactnativestripesdk.utils.StripeFragment
15
10
  import com.reactnativestripesdk.utils.createError
16
11
  import com.reactnativestripesdk.utils.createMissingActivityError
17
12
  import com.reactnativestripesdk.utils.getBooleanOr
@@ -19,7 +14,7 @@ import com.reactnativestripesdk.utils.getIntOrNull
19
14
  import com.stripe.android.googlepaylauncher.GooglePayEnvironment
20
15
  import com.stripe.android.googlepaylauncher.GooglePayLauncher
21
16
 
22
- class GooglePayLauncherFragment : Fragment() {
17
+ class GooglePayLauncherFragment : StripeFragment() {
23
18
  enum class Mode {
24
19
  ForSetup,
25
20
  ForPayment,
@@ -34,16 +29,7 @@ class GooglePayLauncherFragment : Fragment() {
34
29
  private var label: String? = null
35
30
  private lateinit var callback: (result: GooglePayLauncher.Result?, error: WritableMap?) -> Unit
36
31
 
37
- override fun onCreateView(
38
- inflater: LayoutInflater,
39
- container: ViewGroup?,
40
- savedInstanceState: Bundle?,
41
- ): View = FrameLayout(requireActivity()).also { it.visibility = View.GONE }
42
-
43
- override fun onViewCreated(
44
- view: View,
45
- savedInstanceState: Bundle?,
46
- ) {
32
+ override fun prepare() {
47
33
  launcher =
48
34
  GooglePayLauncher(
49
35
  fragment = this,
@@ -12,12 +12,12 @@ import com.reactnativestripesdk.utils.removeFragment
12
12
  import com.stripe.android.googlepaylauncher.GooglePayEnvironment
13
13
  import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher
14
14
 
15
- class GooglePayPaymentMethodLauncherFragment(
16
- private val context: ReactApplicationContext,
17
- private val isTestEnv: Boolean,
18
- private val paymentMethodRequired: Boolean,
19
- private val promise: Promise,
20
- ) : Fragment() {
15
+ class GooglePayPaymentMethodLauncherFragment : Fragment() {
16
+ private lateinit var context: ReactApplicationContext
17
+ private var isTestEnv = false
18
+ private var paymentMethodRequired = false
19
+ private lateinit var promise: Promise
20
+
21
21
  override fun onCreateView(
22
22
  inflater: LayoutInflater,
23
23
  container: ViewGroup?,
@@ -50,5 +50,19 @@ class GooglePayPaymentMethodLauncherFragment(
50
50
 
51
51
  companion object {
52
52
  const val TAG = "google_pay_support_fragment"
53
+
54
+ fun create(
55
+ context: ReactApplicationContext,
56
+ isTestEnv: Boolean,
57
+ paymentMethodRequired: Boolean,
58
+ promise: Promise,
59
+ ): GooglePayPaymentMethodLauncherFragment {
60
+ val instance = GooglePayPaymentMethodLauncherFragment()
61
+ instance.context = context
62
+ instance.isTestEnv = isTestEnv
63
+ instance.paymentMethodRequired = paymentMethodRequired
64
+ instance.promise = promise
65
+ return instance
66
+ }
53
67
  }
54
68
  }
@@ -1,17 +1,12 @@
1
1
  package com.reactnativestripesdk
2
2
 
3
- import android.os.Bundle
4
- import android.view.LayoutInflater
5
- import android.view.View
6
- import android.view.ViewGroup
7
- import android.widget.FrameLayout
8
- import androidx.fragment.app.Fragment
9
3
  import androidx.fragment.app.FragmentActivity
10
4
  import com.facebook.react.bridge.Promise
11
5
  import com.facebook.react.bridge.ReactApplicationContext
12
6
  import com.reactnativestripesdk.utils.ConfirmPaymentErrorType
13
7
  import com.reactnativestripesdk.utils.ConfirmSetupIntentErrorType
14
8
  import com.reactnativestripesdk.utils.ErrorType
9
+ import com.reactnativestripesdk.utils.StripeFragment
15
10
  import com.reactnativestripesdk.utils.createError
16
11
  import com.reactnativestripesdk.utils.createMissingActivityError
17
12
  import com.reactnativestripesdk.utils.createResult
@@ -29,26 +24,57 @@ import com.stripe.android.payments.paymentlauncher.PaymentLauncher
29
24
  import com.stripe.android.payments.paymentlauncher.PaymentResult
30
25
 
31
26
  /** Instances of this class should only be initialized with the companion's helper methods. */
32
- class PaymentLauncherFragment(
33
- private val context: ReactApplicationContext,
34
- private val stripe: Stripe,
35
- private val publishableKey: String,
36
- private val stripeAccountId: String?,
37
- private val promise: Promise,
27
+ class PaymentLauncherFragment : StripeFragment() {
28
+ private lateinit var context: ReactApplicationContext
29
+ private lateinit var stripe: Stripe
30
+ private lateinit var publishableKey: String
31
+ private var stripeAccountId: String? = null
32
+ private lateinit var promise: Promise
33
+
38
34
  // Used when confirming a payment intent
39
- private val paymentIntentClientSecret: String? = null,
40
- private val confirmPaymentParams: ConfirmPaymentIntentParams? = null,
35
+ private var paymentIntentClientSecret: String? = null
36
+ private var confirmPaymentParams: ConfirmPaymentIntentParams? = null
37
+
41
38
  // Used when confirming a setup intent
42
- private val setupIntentClientSecret: String? = null,
43
- private val confirmSetupParams: ConfirmSetupIntentParams? = null,
39
+ private var setupIntentClientSecret: String? = null
40
+ private var confirmSetupParams: ConfirmSetupIntentParams? = null
41
+
44
42
  // Used when handling the next action on a payment intent
45
- private val handleNextActionPaymentIntentClientSecret: String? = null,
43
+ private var handleNextActionPaymentIntentClientSecret: String? = null
44
+
46
45
  // Used when handling the next action on a setup intent
47
- private val handleNextActionSetupIntentClientSecret: String? = null,
48
- ) : Fragment() {
46
+ private var handleNextActionSetupIntentClientSecret: String? = null
49
47
  private lateinit var paymentLauncher: PaymentLauncher
50
48
 
51
49
  companion object {
50
+ private fun create(
51
+ context: ReactApplicationContext,
52
+ stripe: Stripe,
53
+ publishableKey: String,
54
+ stripeAccountId: String?,
55
+ promise: Promise,
56
+ paymentIntentClientSecret: String? = null,
57
+ confirmPaymentParams: ConfirmPaymentIntentParams? = null,
58
+ setupIntentClientSecret: String? = null,
59
+ confirmSetupParams: ConfirmSetupIntentParams? = null,
60
+ handleNextActionPaymentIntentClientSecret: String? = null,
61
+ handleNextActionSetupIntentClientSecret: String? = null,
62
+ ): PaymentLauncherFragment {
63
+ val instance = PaymentLauncherFragment()
64
+ instance.context = context
65
+ instance.stripe = stripe
66
+ instance.publishableKey = publishableKey
67
+ instance.stripeAccountId = stripeAccountId
68
+ instance.promise = promise
69
+ instance.paymentIntentClientSecret = paymentIntentClientSecret
70
+ instance.confirmPaymentParams = confirmPaymentParams
71
+ instance.setupIntentClientSecret = setupIntentClientSecret
72
+ instance.confirmSetupParams = confirmSetupParams
73
+ instance.handleNextActionPaymentIntentClientSecret = handleNextActionPaymentIntentClientSecret
74
+ instance.handleNextActionSetupIntentClientSecret = handleNextActionSetupIntentClientSecret
75
+ return instance
76
+ }
77
+
52
78
  /** Helper-constructor used for confirming payment intents */
53
79
  fun forPayment(
54
80
  context: ReactApplicationContext,
@@ -60,7 +86,7 @@ class PaymentLauncherFragment(
60
86
  confirmPaymentParams: ConfirmPaymentIntentParams,
61
87
  ): PaymentLauncherFragment {
62
88
  val paymentLauncherFragment =
63
- PaymentLauncherFragment(
89
+ create(
64
90
  context,
65
91
  stripe,
66
92
  publishableKey,
@@ -84,7 +110,7 @@ class PaymentLauncherFragment(
84
110
  confirmSetupParams: ConfirmSetupIntentParams,
85
111
  ): PaymentLauncherFragment {
86
112
  val paymentLauncherFragment =
87
- PaymentLauncherFragment(
113
+ create(
88
114
  context,
89
115
  stripe,
90
116
  publishableKey,
@@ -107,7 +133,7 @@ class PaymentLauncherFragment(
107
133
  handleNextActionPaymentIntentClientSecret: String,
108
134
  ): PaymentLauncherFragment {
109
135
  val paymentLauncherFragment =
110
- PaymentLauncherFragment(
136
+ create(
111
137
  context,
112
138
  stripe,
113
139
  publishableKey,
@@ -129,7 +155,7 @@ class PaymentLauncherFragment(
129
155
  handleNextActionSetupIntentClientSecret: String,
130
156
  ): PaymentLauncherFragment {
131
157
  val paymentLauncherFragment =
132
- PaymentLauncherFragment(
158
+ create(
133
159
  context,
134
160
  stripe,
135
161
  publishableKey,
@@ -161,43 +187,36 @@ class PaymentLauncherFragment(
161
187
  internal const val TAG = "payment_launcher_fragment"
162
188
  }
163
189
 
164
- override fun onCreateView(
165
- inflater: LayoutInflater,
166
- container: ViewGroup?,
167
- savedInstanceState: Bundle?,
168
- ): View {
190
+ override fun prepare() {
169
191
  paymentLauncher = createPaymentLauncher()
170
192
  if (paymentIntentClientSecret != null && confirmPaymentParams != null) {
171
- paymentLauncher.confirm(confirmPaymentParams)
193
+ paymentLauncher.confirm(confirmPaymentParams!!)
172
194
  } else if (setupIntentClientSecret != null && confirmSetupParams != null) {
173
- paymentLauncher.confirm(confirmSetupParams)
195
+ paymentLauncher.confirm(confirmSetupParams!!)
174
196
  } else if (handleNextActionPaymentIntentClientSecret != null) {
175
- paymentLauncher.handleNextActionForPaymentIntent(handleNextActionPaymentIntentClientSecret)
197
+ paymentLauncher.handleNextActionForPaymentIntent(handleNextActionPaymentIntentClientSecret!!)
176
198
  } else if (handleNextActionSetupIntentClientSecret != null) {
177
- paymentLauncher.handleNextActionForSetupIntent(handleNextActionSetupIntentClientSecret)
199
+ paymentLauncher.handleNextActionForSetupIntent(handleNextActionSetupIntentClientSecret!!)
178
200
  } else {
179
201
  throw Exception(
180
202
  "Invalid parameters provided to PaymentLauncher. Ensure that you are providing the correct client secret and setup params (if necessary).",
181
203
  )
182
204
  }
183
- return FrameLayout(requireActivity()).also { it.visibility = View.GONE }
184
205
  }
185
206
 
186
207
  private fun createPaymentLauncher(): PaymentLauncher =
187
208
  PaymentLauncher.create(this, publishableKey, stripeAccountId) { paymentResult ->
188
209
  when (paymentResult) {
189
210
  is PaymentResult.Completed -> {
190
- if (paymentIntentClientSecret != null) {
191
- retrievePaymentIntent(paymentIntentClientSecret, stripeAccountId)
192
- } else if (handleNextActionPaymentIntentClientSecret != null) {
193
- retrievePaymentIntent(handleNextActionPaymentIntentClientSecret, stripeAccountId)
194
- } else if (setupIntentClientSecret != null) {
195
- retrieveSetupIntent(setupIntentClientSecret, stripeAccountId)
196
- } else if (handleNextActionSetupIntentClientSecret != null) {
197
- retrieveSetupIntent(handleNextActionSetupIntentClientSecret, stripeAccountId)
198
- } else {
199
- throw Exception("Failed to create Payment Launcher. No client secret provided.")
200
- }
211
+ paymentIntentClientSecret?.let {
212
+ retrievePaymentIntent(it, stripeAccountId)
213
+ } ?: handleNextActionPaymentIntentClientSecret?.let {
214
+ retrievePaymentIntent(it, stripeAccountId)
215
+ } ?: setupIntentClientSecret?.let {
216
+ retrieveSetupIntent(it, stripeAccountId)
217
+ } ?: handleNextActionSetupIntentClientSecret?.let {
218
+ retrieveSetupIntent(it, stripeAccountId)
219
+ } ?: throw Exception("Failed to create Payment Launcher. No client secret provided.")
201
220
  }
202
221
  is PaymentResult.Canceled -> {
203
222
  promise.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), message = null))
@@ -19,7 +19,7 @@ import com.stripe.android.model.PaymentMethodOptionsParams
19
19
 
20
20
  class PaymentMethodCreateParamsFactory(
21
21
  private val paymentMethodData: ReadableMap?,
22
- private val options: ReadableMap,
22
+ private val options: ReadableMap?,
23
23
  private val cardFieldView: CardFieldView?,
24
24
  private val cardFormView: CardFormView?,
25
25
  ) {
@@ -267,6 +267,7 @@ class PaymentMethodCreateParamsFactory(
267
267
  PaymentMethod.Type.Card -> createCardStripeIntentParams(clientSecret, isPaymentIntent)
268
268
  PaymentMethod.Type.USBankAccount ->
269
269
  createUSBankAccountStripeIntentParams(clientSecret, isPaymentIntent)
270
+
270
271
  PaymentMethod.Type.Affirm -> createAffirmStripeIntentParams(clientSecret, isPaymentIntent)
271
272
  PaymentMethod.Type.Ideal,
272
273
  PaymentMethod.Type.Alipay,
@@ -304,6 +305,7 @@ class PaymentMethodCreateParamsFactory(
304
305
  )
305
306
  }
306
307
  }
308
+
307
309
  null -> ConfirmPaymentIntentParams.create(clientSecret)
308
310
  else -> {
309
311
  throw Exception("This paymentMethodType is not supported yet")