@stripe/stripe-react-native 0.41.0 → 0.43.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 (314) hide show
  1. package/.husky/pre-commit +0 -3
  2. package/CHANGELOG.md +27 -0
  3. package/README.md +3 -0
  4. package/android/.gradle/8.11.1/checksums/checksums.lock +0 -0
  5. package/android/.gradle/8.11.1/checksums/md5-checksums.bin +0 -0
  6. package/android/.gradle/8.11.1/checksums/sha1-checksums.bin +0 -0
  7. package/android/.gradle/8.11.1/executionHistory/executionHistory.lock +0 -0
  8. package/android/.gradle/8.11.1/fileChanges/last-build.bin +0 -0
  9. package/android/.gradle/8.11.1/fileHashes/fileHashes.lock +0 -0
  10. package/android/.gradle/8.11.1/gc.properties +0 -0
  11. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  12. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  13. package/android/.gradle/vcs-1/gc.properties +0 -0
  14. package/android/build.gradle +7 -1
  15. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  16. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  17. package/android/gradle.properties +4 -1
  18. package/android/gradlew +249 -0
  19. package/android/gradlew.bat +92 -0
  20. package/android/spotless.gradle +19 -0
  21. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +30 -34
  22. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormViewManager.kt +20 -10
  23. package/android/src/main/java/com/reactnativestripesdk/CardChangedEvent.kt +12 -13
  24. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +242 -105
  25. package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +58 -20
  26. package/android/src/main/java/com/reactnativestripesdk/CardFocusEvent.kt +8 -11
  27. package/android/src/main/java/com/reactnativestripesdk/CardFormCompleteEvent.kt +10 -12
  28. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +135 -87
  29. package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +57 -22
  30. package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +53 -23
  31. package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +125 -83
  32. package/android/src/main/java/com/reactnativestripesdk/FormCompleteEvent.kt +9 -11
  33. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +16 -9
  34. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +36 -28
  35. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +67 -43
  36. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +21 -16
  37. package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +101 -56
  38. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +244 -166
  39. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +183 -123
  40. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +181 -57
  41. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +402 -258
  42. package/android/src/main/java/com/reactnativestripesdk/StripeContainerManager.kt +11 -4
  43. package/android/src/main/java/com/reactnativestripesdk/StripeContainerView.kt +5 -1
  44. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +654 -299
  45. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +12 -14
  46. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +42 -37
  47. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetEvent.kt +12 -11
  48. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +29 -29
  49. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +50 -18
  50. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +227 -147
  51. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +15 -18
  52. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +33 -15
  53. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +63 -37
  54. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletCompleteEvent.kt +9 -13
  55. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/EphemeralKeyProvider.kt +15 -17
  56. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxy.kt +76 -60
  57. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +71 -47
  58. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +117 -51
  59. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +4 -3
  60. package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +39 -0
  61. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +337 -250
  62. package/android/src/main/java/com/reactnativestripesdk/utils/PostalCodeUtilities.kt +2 -11
  63. package/ios/CustomerSheet/CustomerSheetUtils.swift +3 -1
  64. package/ios/FinancialConnections.swift +18 -2
  65. package/ios/Mappers.swift +23 -0
  66. package/ios/PaymentMethodFactory.swift +31 -29
  67. package/ios/StripeSdk+CustomerSheet.swift +2 -1
  68. package/ios/StripeSdk+PaymentSheet.swift +42 -0
  69. package/ios/StripeSdk.m +2 -0
  70. package/ios/StripeSdk.swift +116 -24
  71. package/lib/commonjs/NativeStripeSdk.js +1 -1
  72. package/lib/commonjs/NativeStripeSdk.js.map +1 -1
  73. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  74. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  75. package/lib/commonjs/components/AddressSheet.js +1 -1
  76. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  77. package/lib/commonjs/components/ApplePayButtonNative.js +1 -1
  78. package/lib/commonjs/components/ApplePayButtonNative.js.map +1 -1
  79. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  80. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  81. package/lib/commonjs/components/CardField.js +1 -1
  82. package/lib/commonjs/components/CardField.js.map +1 -1
  83. package/lib/commonjs/components/CardForm.js +1 -1
  84. package/lib/commonjs/components/CardForm.js.map +1 -1
  85. package/lib/commonjs/components/CustomerSheet.js +1 -1
  86. package/lib/commonjs/components/CustomerSheet.js.map +1 -1
  87. package/lib/commonjs/components/GooglePayButtonNative.js +1 -1
  88. package/lib/commonjs/components/GooglePayButtonNative.js.map +1 -1
  89. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  90. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  91. package/lib/commonjs/components/StripeContainer.js +1 -1
  92. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  93. package/lib/commonjs/components/StripeProvider.js +1 -1
  94. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  95. package/lib/commonjs/functions.js +1 -1
  96. package/lib/commonjs/functions.js.map +1 -1
  97. package/lib/commonjs/helpers.js +1 -1
  98. package/lib/commonjs/helpers.js.map +1 -1
  99. package/lib/commonjs/hooks/useConfirmPayment.js.map +1 -1
  100. package/lib/commonjs/hooks/useConfirmSetupIntent.js.map +1 -1
  101. package/lib/commonjs/hooks/useFinancialConnectionsSheet.js +1 -1
  102. package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -1
  103. package/lib/commonjs/hooks/usePaymentSheet.js.map +1 -1
  104. package/lib/commonjs/hooks/usePlatformPay.js.map +1 -1
  105. package/lib/commonjs/hooks/useStripe.js +1 -1
  106. package/lib/commonjs/hooks/useStripe.js.map +1 -1
  107. package/lib/commonjs/index.js.map +1 -1
  108. package/lib/commonjs/package.json +1 -0
  109. package/lib/commonjs/plugin/withStripe.js +1 -1
  110. package/lib/commonjs/plugin/withStripe.js.map +1 -1
  111. package/lib/commonjs/types/ApplePay.js.map +1 -1
  112. package/lib/commonjs/types/Common.js +1 -1
  113. package/lib/commonjs/types/Common.js.map +1 -1
  114. package/lib/commonjs/types/CustomerSheet.js.map +1 -1
  115. package/lib/commonjs/types/Errors.js +1 -1
  116. package/lib/commonjs/types/Errors.js.map +1 -1
  117. package/lib/commonjs/types/FinancialConnections.js +1 -1
  118. package/lib/commonjs/types/FinancialConnections.js.map +1 -1
  119. package/lib/commonjs/types/NextAction.js.map +1 -1
  120. package/lib/commonjs/types/PaymentIntent.js +1 -1
  121. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  122. package/lib/commonjs/types/PaymentMethod.js.map +1 -1
  123. package/lib/commonjs/types/PaymentSheet.js +1 -1
  124. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  125. package/lib/commonjs/types/PlatformPay.js +1 -1
  126. package/lib/commonjs/types/PlatformPay.js.map +1 -1
  127. package/lib/commonjs/types/PushProvisioning.js +1 -1
  128. package/lib/commonjs/types/PushProvisioning.js.map +1 -1
  129. package/lib/commonjs/types/SetupIntent.js +1 -1
  130. package/lib/commonjs/types/SetupIntent.js.map +1 -1
  131. package/lib/commonjs/types/ThreeDSecure.js +1 -1
  132. package/lib/commonjs/types/ThreeDSecure.js.map +1 -1
  133. package/lib/commonjs/types/Token.js.map +1 -1
  134. package/lib/commonjs/types/components/ApplePayButtonComponent.js.map +1 -1
  135. package/lib/commonjs/types/components/AuBECSDebitFormComponent.js.map +1 -1
  136. package/lib/commonjs/types/components/CardFieldInput.js +1 -1
  137. package/lib/commonjs/types/components/CardFieldInput.js.map +1 -1
  138. package/lib/commonjs/types/components/CardFormView.js.map +1 -1
  139. package/lib/commonjs/types/components/GooglePayButtonComponent.js.map +1 -1
  140. package/lib/commonjs/types/index.js +1 -1
  141. package/lib/commonjs/types/index.js.map +1 -1
  142. package/lib/module/NativeStripeSdk.js +1 -1
  143. package/lib/module/NativeStripeSdk.js.map +1 -1
  144. package/lib/module/components/AddToWalletButton.js +1 -1
  145. package/lib/module/components/AddToWalletButton.js.map +1 -1
  146. package/lib/module/components/AddressSheet.js +1 -1
  147. package/lib/module/components/AddressSheet.js.map +1 -1
  148. package/lib/module/components/ApplePayButtonNative.js +1 -1
  149. package/lib/module/components/ApplePayButtonNative.js.map +1 -1
  150. package/lib/module/components/AuBECSDebitForm.js +1 -1
  151. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  152. package/lib/module/components/CardField.js +1 -1
  153. package/lib/module/components/CardField.js.map +1 -1
  154. package/lib/module/components/CardForm.js +1 -1
  155. package/lib/module/components/CardForm.js.map +1 -1
  156. package/lib/module/components/CustomerSheet.js +1 -1
  157. package/lib/module/components/CustomerSheet.js.map +1 -1
  158. package/lib/module/components/GooglePayButtonNative.js +1 -1
  159. package/lib/module/components/GooglePayButtonNative.js.map +1 -1
  160. package/lib/module/components/PlatformPayButton.js +1 -1
  161. package/lib/module/components/PlatformPayButton.js.map +1 -1
  162. package/lib/module/components/StripeContainer.js +1 -1
  163. package/lib/module/components/StripeContainer.js.map +1 -1
  164. package/lib/module/components/StripeProvider.js +1 -1
  165. package/lib/module/components/StripeProvider.js.map +1 -1
  166. package/lib/module/functions.js +1 -1
  167. package/lib/module/functions.js.map +1 -1
  168. package/lib/module/helpers.js +1 -1
  169. package/lib/module/helpers.js.map +1 -1
  170. package/lib/module/hooks/useConfirmPayment.js.map +1 -1
  171. package/lib/module/hooks/useConfirmSetupIntent.js.map +1 -1
  172. package/lib/module/hooks/useFinancialConnectionsSheet.js +1 -1
  173. package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -1
  174. package/lib/module/hooks/usePaymentSheet.js.map +1 -1
  175. package/lib/module/hooks/usePlatformPay.js.map +1 -1
  176. package/lib/module/hooks/useStripe.js +1 -1
  177. package/lib/module/hooks/useStripe.js.map +1 -1
  178. package/lib/module/index.js.map +1 -1
  179. package/lib/module/package.json +1 -0
  180. package/lib/module/plugin/withStripe.js +1 -1
  181. package/lib/module/plugin/withStripe.js.map +1 -1
  182. package/lib/module/types/ApplePay.js.map +1 -1
  183. package/lib/module/types/Common.js +1 -1
  184. package/lib/module/types/Common.js.map +1 -1
  185. package/lib/module/types/CustomerSheet.js.map +1 -1
  186. package/lib/module/types/Errors.js +1 -1
  187. package/lib/module/types/Errors.js.map +1 -1
  188. package/lib/module/types/FinancialConnections.js +1 -1
  189. package/lib/module/types/FinancialConnections.js.map +1 -1
  190. package/lib/module/types/NextAction.js.map +1 -1
  191. package/lib/module/types/PaymentIntent.js +1 -1
  192. package/lib/module/types/PaymentIntent.js.map +1 -1
  193. package/lib/module/types/PaymentMethod.js.map +1 -1
  194. package/lib/module/types/PaymentSheet.js +1 -1
  195. package/lib/module/types/PaymentSheet.js.map +1 -1
  196. package/lib/module/types/PlatformPay.js +1 -1
  197. package/lib/module/types/PlatformPay.js.map +1 -1
  198. package/lib/module/types/PushProvisioning.js +1 -1
  199. package/lib/module/types/PushProvisioning.js.map +1 -1
  200. package/lib/module/types/SetupIntent.js +1 -1
  201. package/lib/module/types/SetupIntent.js.map +1 -1
  202. package/lib/module/types/ThreeDSecure.js +1 -1
  203. package/lib/module/types/ThreeDSecure.js.map +1 -1
  204. package/lib/module/types/Token.js.map +1 -1
  205. package/lib/module/types/components/ApplePayButtonComponent.js.map +1 -1
  206. package/lib/module/types/components/AuBECSDebitFormComponent.js.map +1 -1
  207. package/lib/module/types/components/CardFieldInput.js +1 -1
  208. package/lib/module/types/components/CardFieldInput.js.map +1 -1
  209. package/lib/module/types/components/CardFormView.js.map +1 -1
  210. package/lib/module/types/components/GooglePayButtonComponent.js.map +1 -1
  211. package/lib/module/types/index.js +1 -1
  212. package/lib/module/types/index.js.map +1 -1
  213. package/lib/typescript/src/NativeStripeSdk.d.ts +5 -4
  214. package/lib/typescript/src/NativeStripeSdk.d.ts.map +1 -0
  215. package/lib/typescript/src/components/AddToWalletButton.d.ts +3 -1
  216. package/lib/typescript/src/components/AddToWalletButton.d.ts.map +1 -0
  217. package/lib/typescript/src/components/AddressSheet.d.ts +4 -2
  218. package/lib/typescript/src/components/AddressSheet.d.ts.map +1 -0
  219. package/lib/typescript/src/components/ApplePayButtonNative.d.ts +1 -0
  220. package/lib/typescript/src/components/ApplePayButtonNative.d.ts.map +1 -0
  221. package/lib/typescript/src/components/AuBECSDebitForm.d.ts +3 -1
  222. package/lib/typescript/src/components/AuBECSDebitForm.d.ts.map +1 -0
  223. package/lib/typescript/src/components/CardField.d.ts +1 -0
  224. package/lib/typescript/src/components/CardField.d.ts.map +1 -0
  225. package/lib/typescript/src/components/CardForm.d.ts +1 -0
  226. package/lib/typescript/src/components/CardForm.d.ts.map +1 -0
  227. package/lib/typescript/src/components/CustomerSheet.d.ts +2 -1
  228. package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -0
  229. package/lib/typescript/src/components/GooglePayButtonNative.d.ts +1 -0
  230. package/lib/typescript/src/components/GooglePayButtonNative.d.ts.map +1 -0
  231. package/lib/typescript/src/components/PlatformPayButton.d.ts +3 -1
  232. package/lib/typescript/src/components/PlatformPayButton.d.ts.map +1 -0
  233. package/lib/typescript/src/components/StripeContainer.d.ts +2 -1
  234. package/lib/typescript/src/components/StripeContainer.d.ts.map +1 -0
  235. package/lib/typescript/src/components/StripeProvider.d.ts +3 -2
  236. package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -0
  237. package/lib/typescript/src/functions.d.ts +12 -7
  238. package/lib/typescript/src/functions.d.ts.map +1 -0
  239. package/lib/typescript/src/helpers.d.ts +1 -0
  240. package/lib/typescript/src/helpers.d.ts.map +1 -0
  241. package/lib/typescript/src/hooks/useConfirmPayment.d.ts +2 -1
  242. package/lib/typescript/src/hooks/useConfirmPayment.d.ts.map +1 -0
  243. package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts +1 -0
  244. package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts.map +1 -0
  245. package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +5 -2
  246. package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts.map +1 -0
  247. package/lib/typescript/src/hooks/usePaymentSheet.d.ts +2 -1
  248. package/lib/typescript/src/hooks/usePaymentSheet.d.ts.map +1 -0
  249. package/lib/typescript/src/hooks/usePlatformPay.d.ts +4 -3
  250. package/lib/typescript/src/hooks/usePlatformPay.d.ts.map +1 -0
  251. package/lib/typescript/src/hooks/useStripe.d.ts +11 -8
  252. package/lib/typescript/src/hooks/useStripe.d.ts.map +1 -0
  253. package/lib/typescript/src/index.d.ts +1 -0
  254. package/lib/typescript/src/index.d.ts.map +1 -0
  255. package/lib/typescript/src/plugin/withStripe.d.ts +2 -1
  256. package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -0
  257. package/lib/typescript/src/types/ApplePay.d.ts +6 -5
  258. package/lib/typescript/src/types/ApplePay.d.ts.map +1 -0
  259. package/lib/typescript/src/types/Common.d.ts +4 -1
  260. package/lib/typescript/src/types/Common.d.ts.map +1 -0
  261. package/lib/typescript/src/types/CustomerSheet.d.ts +12 -4
  262. package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -0
  263. package/lib/typescript/src/types/Errors.d.ts +2 -1
  264. package/lib/typescript/src/types/Errors.d.ts.map +1 -0
  265. package/lib/typescript/src/types/FinancialConnections.d.ts +82 -14
  266. package/lib/typescript/src/types/FinancialConnections.d.ts.map +1 -0
  267. package/lib/typescript/src/types/NextAction.d.ts +9 -8
  268. package/lib/typescript/src/types/NextAction.d.ts.map +1 -0
  269. package/lib/typescript/src/types/PaymentIntent.d.ts +41 -14
  270. package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -0
  271. package/lib/typescript/src/types/PaymentMethod.d.ts +27 -15
  272. package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -0
  273. package/lib/typescript/src/types/PaymentSheet.d.ts +72 -22
  274. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -0
  275. package/lib/typescript/src/types/PlatformPay.d.ts +22 -21
  276. package/lib/typescript/src/types/PlatformPay.d.ts.map +1 -0
  277. package/lib/typescript/src/types/PushProvisioning.d.ts +5 -4
  278. package/lib/typescript/src/types/PushProvisioning.d.ts.map +1 -0
  279. package/lib/typescript/src/types/SetupIntent.d.ts +4 -3
  280. package/lib/typescript/src/types/SetupIntent.d.ts.map +1 -0
  281. package/lib/typescript/src/types/ThreeDSecure.d.ts +1 -0
  282. package/lib/typescript/src/types/ThreeDSecure.d.ts.map +1 -0
  283. package/lib/typescript/src/types/Token.d.ts +10 -9
  284. package/lib/typescript/src/types/Token.d.ts.map +1 -0
  285. package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts +3 -2
  286. package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts.map +1 -0
  287. package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts +1 -0
  288. package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts.map +1 -0
  289. package/lib/typescript/src/types/components/CardFieldInput.d.ts +8 -5
  290. package/lib/typescript/src/types/components/CardFieldInput.d.ts.map +1 -0
  291. package/lib/typescript/src/types/components/CardFormView.d.ts +9 -6
  292. package/lib/typescript/src/types/components/CardFormView.d.ts.map +1 -0
  293. package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts +1 -0
  294. package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts.map +1 -0
  295. package/lib/typescript/src/types/index.d.ts +24 -23
  296. package/lib/typescript/src/types/index.d.ts.map +1 -0
  297. package/package.json +33 -42
  298. package/src/NativeStripeSdk.tsx +5 -3
  299. package/src/components/CardField.tsx +1 -1
  300. package/src/components/CardForm.tsx +12 -9
  301. package/src/components/CustomerSheet.tsx +4 -6
  302. package/src/components/StripeProvider.tsx +17 -0
  303. package/src/functions.ts +70 -16
  304. package/src/hooks/useFinancialConnectionsSheet.tsx +12 -4
  305. package/src/hooks/useStripe.tsx +10 -4
  306. package/src/types/Common.ts +3 -0
  307. package/src/types/CustomerSheet.ts +7 -0
  308. package/src/types/FinancialConnections.ts +72 -0
  309. package/src/types/PaymentIntent.ts +30 -1
  310. package/src/types/PaymentMethod.ts +13 -1
  311. package/src/types/PaymentSheet.ts +65 -5
  312. package/src/types/components/CardFieldInput.ts +8 -4
  313. package/src/types/components/CardFormView.ts +8 -4
  314. package/stripe-react-native.podspec +2 -1
@@ -1,19 +1,17 @@
1
1
  package com.reactnativestripesdk
2
+
2
3
  import com.facebook.react.bridge.Arguments
3
4
  import com.facebook.react.bridge.WritableMap
4
5
  import com.facebook.react.uimanager.events.Event
5
- import com.facebook.react.uimanager.events.RCTEventEmitter
6
6
 
7
- internal class CardFocusEvent constructor(viewTag: Int, private val focusField: String?) : Event<CardFocusEvent>(viewTag) {
8
- override fun getEventName(): String {
9
- return EVENT_NAME
10
- }
7
+ internal class CardFocusEvent(
8
+ surfaceId: Int,
9
+ viewTag: Int,
10
+ private val focusField: String?,
11
+ ) : Event<CardFocusEvent>(surfaceId, viewTag) {
12
+ override fun getEventName() = EVENT_NAME
11
13
 
12
- override fun dispatch(rctEventEmitter: RCTEventEmitter) {
13
- rctEventEmitter.receiveEvent(viewTag, eventName, serializeEventData())
14
- }
15
-
16
- private fun serializeEventData(): WritableMap {
14
+ override fun getEventData(): WritableMap? {
17
15
  val eventData = Arguments.createMap()
18
16
  eventData.putString("focusedField", focusField)
19
17
 
@@ -23,5 +21,4 @@ internal class CardFocusEvent constructor(viewTag: Int, private val focusField:
23
21
  companion object {
24
22
  const val EVENT_NAME = "topFocusChange"
25
23
  }
26
-
27
24
  }
@@ -3,18 +3,17 @@ package com.reactnativestripesdk
3
3
  import com.facebook.react.bridge.Arguments
4
4
  import com.facebook.react.bridge.WritableMap
5
5
  import com.facebook.react.uimanager.events.Event
6
- import com.facebook.react.uimanager.events.RCTEventEmitter
7
6
 
8
- internal class CardFormCompleteEvent constructor(viewTag: Int, private val cardDetails: MutableMap<String, Any>?, private val complete: Boolean, private val dangerouslyGetFullCardDetails: Boolean) : Event<CardChangedEvent>(viewTag) {
9
- override fun getEventName(): String {
10
- return EVENT_NAME
11
- }
12
-
13
- override fun dispatch(rctEventEmitter: RCTEventEmitter) {
14
- rctEventEmitter.receiveEvent(viewTag, eventName, serializeEventData())
15
- }
7
+ internal class CardFormCompleteEvent(
8
+ surfaceId: Int,
9
+ viewTag: Int,
10
+ private val cardDetails: MutableMap<String, Any>?,
11
+ private val complete: Boolean,
12
+ private val dangerouslyGetFullCardDetails: Boolean,
13
+ ) : Event<CardChangedEvent>(surfaceId, viewTag) {
14
+ override fun getEventName() = EVENT_NAME
16
15
 
17
- private fun serializeEventData(): WritableMap {
16
+ override fun getEventData(): WritableMap? {
18
17
  val eventData = Arguments.createMap()
19
18
 
20
19
  if (cardDetails == null) {
@@ -37,7 +36,6 @@ internal class CardFormCompleteEvent constructor(viewTag: Int, private val cardD
37
36
  }
38
37
 
39
38
  companion object {
40
- const val EVENT_NAME = "onFormComplete"
39
+ const val EVENT_NAME = "topFormComplete"
41
40
  }
42
-
43
41
  }
@@ -12,36 +12,46 @@ import androidx.core.view.setMargins
12
12
  import com.facebook.react.bridge.ReadableMap
13
13
  import com.facebook.react.uimanager.PixelUtil
14
14
  import com.facebook.react.uimanager.ThemedReactContext
15
- import com.facebook.react.uimanager.UIManagerModule
16
- import com.facebook.react.uimanager.events.EventDispatcher
15
+ import com.facebook.react.uimanager.UIManagerHelper
17
16
  import com.facebook.react.views.text.ReactTypefaceUtils
18
17
  import com.google.android.material.shape.CornerFamily
19
18
  import com.google.android.material.shape.MaterialShapeDrawable
20
19
  import com.google.android.material.shape.ShapeAppearanceModel
21
- import com.reactnativestripesdk.utils.*
20
+ import com.reactnativestripesdk.utils.PostalCodeUtilities
21
+ import com.reactnativestripesdk.utils.getIntOrNull
22
+ import com.reactnativestripesdk.utils.getValOr
23
+ import com.reactnativestripesdk.utils.hideSoftKeyboard
22
24
  import com.reactnativestripesdk.utils.mapCardBrand
25
+ import com.reactnativestripesdk.utils.mapToPreferredNetworks
26
+ import com.reactnativestripesdk.utils.showSoftKeyboard
23
27
  import com.stripe.android.core.model.CountryCode
24
- import com.stripe.android.databinding.StripeCardMultilineWidgetBinding
25
28
  import com.stripe.android.databinding.StripeCardFormViewBinding
29
+ import com.stripe.android.databinding.StripeCardMultilineWidgetBinding
26
30
  import com.stripe.android.model.Address
27
31
  import com.stripe.android.model.PaymentMethodCreateParams
28
32
  import com.stripe.android.view.CardFormView
29
33
  import com.stripe.android.view.CardInputListener
30
34
 
31
- class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
32
- private var cardForm: CardFormView = CardFormView(context, null, com.stripe.android.R.style.StripeCardFormView_Borderless)
33
- private var mEventDispatcher: EventDispatcher? = context.getNativeModule(UIManagerModule::class.java)?.eventDispatcher
35
+ @SuppressLint("ViewConstructor")
36
+ class CardFormView(
37
+ private val context: ThemedReactContext,
38
+ ) : FrameLayout(context) {
39
+ private var cardForm: CardFormView =
40
+ CardFormView(context, null, com.stripe.android.R.style.StripeCardFormView_Borderless)
34
41
  private var dangerouslyGetFullCardDetails: Boolean = false
35
42
  private var currentFocusedField: String? = null
36
43
  var cardParams: PaymentMethodCreateParams.Card? = null
37
44
  var cardAddress: Address? = null
38
45
  private val cardFormViewBinding = StripeCardFormViewBinding.bind(cardForm)
39
- private val multilineWidgetBinding = StripeCardMultilineWidgetBinding.bind(cardFormViewBinding.cardMultilineWidget)
46
+ private val multilineWidgetBinding =
47
+ StripeCardMultilineWidgetBinding.bind(cardFormViewBinding.cardMultilineWidget)
40
48
 
41
49
  init {
42
50
  cardFormViewBinding.cardMultilineWidgetContainer.isFocusable = true
43
51
  cardFormViewBinding.cardMultilineWidgetContainer.isFocusableInTouchMode = true
44
- (cardFormViewBinding.cardMultilineWidgetContainer.layoutParams as MarginLayoutParams).setMargins(0)
52
+ (cardFormViewBinding.cardMultilineWidgetContainer.layoutParams as MarginLayoutParams).setMargins(
53
+ 0,
54
+ )
45
55
  addView(cardForm)
46
56
  setListeners()
47
57
 
@@ -124,8 +134,9 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
124
134
  }
125
135
 
126
136
  private fun onChangeFocus() {
127
- mEventDispatcher?.dispatchEvent(
128
- CardFocusEvent(id, currentFocusedField))
137
+ UIManagerHelper
138
+ .getEventDispatcherForReactTag(context, id)
139
+ ?.dispatchEvent(CardFocusEvent(context.surfaceId, id, currentFocusedField))
129
140
  }
130
141
 
131
142
  @SuppressLint("RestrictedApi")
@@ -141,18 +152,20 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
141
152
  val textErrorColor = getValOr(value, "textErrorColor", null)
142
153
  val cursorColor = getValOr(value, "cursorColor", null)
143
154
 
144
- val editTextBindings = setOf(
145
- cardFormViewBinding.cardMultilineWidget.cardNumberEditText,
146
- cardFormViewBinding.cardMultilineWidget.cvcEditText,
147
- cardFormViewBinding.cardMultilineWidget.expiryDateEditText,
148
- cardFormViewBinding.postalCode
149
- )
150
- val placeholderTextBindings = setOf(
151
- multilineWidgetBinding.tlExpiry,
152
- multilineWidgetBinding.tlCardNumber,
153
- multilineWidgetBinding.tlCvc,
154
- cardFormViewBinding.postalCodeContainer,
155
- )
155
+ val editTextBindings =
156
+ setOf(
157
+ cardFormViewBinding.cardMultilineWidget.cardNumberEditText,
158
+ cardFormViewBinding.cardMultilineWidget.cvcEditText,
159
+ cardFormViewBinding.cardMultilineWidget.expiryDateEditText,
160
+ cardFormViewBinding.postalCode,
161
+ )
162
+ val placeholderTextBindings =
163
+ setOf(
164
+ multilineWidgetBinding.tlExpiry,
165
+ multilineWidgetBinding.tlCardNumber,
166
+ multilineWidgetBinding.tlCvc,
167
+ cardFormViewBinding.postalCodeContainer,
168
+ )
156
169
 
157
170
  textColor?.let {
158
171
  for (binding in editTextBindings) {
@@ -178,7 +191,8 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
178
191
  }
179
192
  fontFamily?.let {
180
193
  // Load custom font from assets, and fallback to default system font
181
- val typeface = ReactTypefaceUtils.applyStyles(null, -1, -1, it.takeIf { it.isNotEmpty() }, context.assets)
194
+ val typeface =
195
+ ReactTypefaceUtils.applyStyles(null, -1, -1, it.takeIf { it.isNotEmpty() }, context.assets)
182
196
  for (binding in editTextBindings) {
183
197
  binding.typeface = typeface
184
198
  }
@@ -202,25 +216,26 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
202
216
  }
203
217
  }
204
218
 
205
- cardFormViewBinding.cardMultilineWidgetContainer.background = MaterialShapeDrawable(
206
- ShapeAppearanceModel()
207
- .toBuilder()
208
- .setAllCorners(CornerFamily.ROUNDED, PixelUtil.toPixelFromDIP(borderRadius.toDouble()))
209
- .build()
210
- ).also { shape ->
211
- shape.strokeWidth = 0.0f
212
- shape.strokeColor = ColorStateList.valueOf(Color.parseColor("#000000"))
213
- shape.fillColor = ColorStateList.valueOf(Color.parseColor("#FFFFFF"))
214
- borderWidth?.let {
215
- shape.strokeWidth = PixelUtil.toPixelFromDIP(it.toDouble())
216
- }
217
- borderColor?.let {
218
- shape.strokeColor = ColorStateList.valueOf(Color.parseColor(it))
219
- }
220
- backgroundColor?.let {
221
- shape.fillColor = ColorStateList.valueOf(Color.parseColor(it))
219
+ cardFormViewBinding.cardMultilineWidgetContainer.background =
220
+ MaterialShapeDrawable(
221
+ ShapeAppearanceModel()
222
+ .toBuilder()
223
+ .setAllCorners(CornerFamily.ROUNDED, PixelUtil.toPixelFromDIP(borderRadius.toDouble()))
224
+ .build(),
225
+ ).also { shape ->
226
+ shape.strokeWidth = 0.0f
227
+ shape.strokeColor = ColorStateList.valueOf(Color.parseColor("#000000"))
228
+ shape.fillColor = ColorStateList.valueOf(Color.parseColor("#FFFFFF"))
229
+ borderWidth?.let {
230
+ shape.strokeWidth = PixelUtil.toPixelFromDIP(it.toDouble())
231
+ }
232
+ borderColor?.let {
233
+ shape.strokeColor = ColorStateList.valueOf(Color.parseColor(it))
234
+ }
235
+ backgroundColor?.let {
236
+ shape.fillColor = ColorStateList.valueOf(Color.parseColor(it))
237
+ }
222
238
  }
223
- }
224
239
  }
225
240
 
226
241
  fun setDangerouslyGetFullCardDetails(isEnabled: Boolean) {
@@ -232,35 +247,58 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
232
247
  if (isValid) {
233
248
  cardForm.cardParams?.let {
234
249
  val cardParamsMap = it.toParamMap()["card"] as HashMap<*, *>
235
- val cardDetails: MutableMap<String, Any> = mutableMapOf(
236
- "expiryMonth" to cardParamsMap["exp_month"] as Int,
237
- "expiryYear" to cardParamsMap["exp_year"] as Int,
238
- "last4" to it.last4,
239
- "brand" to mapCardBrand(it.brand),
240
- "postalCode" to (it.address?.postalCode ?: ""),
241
- "country" to (it.address?.country ?: "")
242
- )
250
+ val cardDetails: MutableMap<String, Any> =
251
+ mutableMapOf(
252
+ "expiryMonth" to cardParamsMap["exp_month"] as Int,
253
+ "expiryYear" to cardParamsMap["exp_year"] as Int,
254
+ "last4" to it.last4,
255
+ "brand" to mapCardBrand(it.brand),
256
+ "postalCode" to (it.address?.postalCode ?: ""),
257
+ "country" to (it.address?.country ?: ""),
258
+ )
243
259
 
244
260
  if (dangerouslyGetFullCardDetails) {
245
261
  cardDetails["number"] = cardParamsMap["number"] as String
246
262
  cardDetails["cvc"] = cardParamsMap["cvc"] as String
247
263
  }
248
264
 
249
- mEventDispatcher?.dispatchEvent(
250
- CardFormCompleteEvent(id, cardDetails, isValid, dangerouslyGetFullCardDetails))
251
-
252
- cardAddress = Address.Builder()
253
- .setPostalCode(it.address?.postalCode)
254
- .setCountry(it.address?.country)
255
- .build()
256
-
257
- cardFormViewBinding.cardMultilineWidget.paymentMethodCard?.let { params -> cardParams = params }
265
+ UIManagerHelper
266
+ .getEventDispatcherForReactTag(context, id)
267
+ ?.dispatchEvent(
268
+ CardFormCompleteEvent(
269
+ context.surfaceId,
270
+ id,
271
+ cardDetails,
272
+ isValid,
273
+ dangerouslyGetFullCardDetails,
274
+ ),
275
+ )
276
+
277
+ cardAddress =
278
+ Address
279
+ .Builder()
280
+ .setPostalCode(it.address?.postalCode)
281
+ .setCountry(it.address?.country)
282
+ .build()
283
+
284
+ cardFormViewBinding.cardMultilineWidget.paymentMethodCard?.let { params ->
285
+ cardParams = params
286
+ }
258
287
  }
259
288
  } else {
260
289
  cardParams = null
261
290
  cardAddress = null
262
- mEventDispatcher?.dispatchEvent(
263
- CardFormCompleteEvent(id, null, isValid, dangerouslyGetFullCardDetails))
291
+ UIManagerHelper
292
+ .getEventDispatcherForReactTag(context, id)
293
+ ?.dispatchEvent(
294
+ CardFormCompleteEvent(
295
+ context.surfaceId,
296
+ id,
297
+ null,
298
+ isValid,
299
+ dangerouslyGetFullCardDetails,
300
+ ),
301
+ )
264
302
  }
265
303
  }
266
304
 
@@ -269,29 +307,37 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
269
307
  val expiryEditText = multilineWidgetBinding.etExpiry
270
308
  val postalCodeEditText = cardFormViewBinding.postalCode
271
309
 
272
- cardNumberEditText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
273
- currentFocusedField = if (hasFocus) CardInputListener.FocusField.CardNumber.toString() else null
274
- onChangeFocus()
275
- }
276
- cvcEditText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
277
- currentFocusedField = if (hasFocus) CardInputListener.FocusField.Cvc.toString() else null
278
- onChangeFocus()
279
- }
280
- expiryEditText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
281
- currentFocusedField = if (hasFocus) CardInputListener.FocusField.ExpiryDate.toString() else null
282
- onChangeFocus()
283
- }
284
- postalCodeEditText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
285
- currentFocusedField = if (hasFocus) CardInputListener.FocusField.PostalCode.toString() else null
286
- onChangeFocus()
287
- }
310
+ cardNumberEditText.onFocusChangeListener =
311
+ OnFocusChangeListener { _, hasFocus ->
312
+ currentFocusedField =
313
+ if (hasFocus) CardInputListener.FocusField.CardNumber.toString() else null
314
+ onChangeFocus()
315
+ }
316
+ cvcEditText.onFocusChangeListener =
317
+ OnFocusChangeListener { _, hasFocus ->
318
+ currentFocusedField = if (hasFocus) CardInputListener.FocusField.Cvc.toString() else null
319
+ onChangeFocus()
320
+ }
321
+ expiryEditText.onFocusChangeListener =
322
+ OnFocusChangeListener { _, hasFocus ->
323
+ currentFocusedField =
324
+ if (hasFocus) CardInputListener.FocusField.ExpiryDate.toString() else null
325
+ onChangeFocus()
326
+ }
327
+ postalCodeEditText.onFocusChangeListener =
328
+ OnFocusChangeListener { _, hasFocus ->
329
+ currentFocusedField =
330
+ if (hasFocus) CardInputListener.FocusField.PostalCode.toString() else null
331
+ onChangeFocus()
332
+ }
288
333
  }
289
334
 
290
335
  private fun setPostalCodeFilter() {
291
- cardFormViewBinding.postalCode.filters = arrayOf(
292
- *cardFormViewBinding.postalCode.filters,
293
- createPostalCodeInputFilter()
294
- )
336
+ cardFormViewBinding.postalCode.filters =
337
+ arrayOf(
338
+ *cardFormViewBinding.postalCode.filters,
339
+ createPostalCodeInputFilter(),
340
+ )
295
341
  }
296
342
 
297
343
  @SuppressLint("RestrictedApi")
@@ -316,10 +362,12 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
316
362
  post(mLayoutRunnable)
317
363
  }
318
364
 
319
- private val mLayoutRunnable = Runnable {
320
- measure(
321
- MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
322
- MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY))
323
- layout(left, top, right, bottom)
324
- }
365
+ private val mLayoutRunnable =
366
+ Runnable {
367
+ measure(
368
+ MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
369
+ MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY),
370
+ )
371
+ layout(left, top, right, bottom)
372
+ }
325
373
  }
@@ -2,23 +2,28 @@ package com.reactnativestripesdk
2
2
 
3
3
  import com.facebook.react.bridge.ReadableArray
4
4
  import com.facebook.react.bridge.ReadableMap
5
- import com.facebook.react.common.MapBuilder
5
+ import com.facebook.react.module.annotations.ReactModule
6
6
  import com.facebook.react.uimanager.SimpleViewManager
7
7
  import com.facebook.react.uimanager.ThemedReactContext
8
8
  import com.facebook.react.uimanager.annotations.ReactProp
9
9
 
10
+ @ReactModule(name = CardFormViewManager.REACT_CLASS)
10
11
  class CardFormViewManager : SimpleViewManager<CardFormView>() {
11
- override fun getName() = "CardForm"
12
+ override fun getName() = REACT_CLASS
12
13
 
13
14
  private var reactContextRef: ThemedReactContext? = null
14
15
 
15
- override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
16
- return MapBuilder.of(
17
- CardFocusEvent.EVENT_NAME, MapBuilder.of("registrationName", "onFocusChange"),
18
- CardFormCompleteEvent.EVENT_NAME, MapBuilder.of("registrationName", "onFormComplete"))
19
- }
20
-
21
- override fun receiveCommand(root: CardFormView, commandId: String?, args: ReadableArray?) {
16
+ override fun getExportedCustomDirectEventTypeConstants() =
17
+ mutableMapOf(
18
+ CardFocusEvent.EVENT_NAME to mutableMapOf("registrationName" to "onFocusChange"),
19
+ CardFormCompleteEvent.EVENT_NAME to mutableMapOf("registrationName" to "onFormComplete"),
20
+ )
21
+
22
+ override fun receiveCommand(
23
+ root: CardFormView,
24
+ commandId: String?,
25
+ args: ReadableArray?,
26
+ ) {
22
27
  when (commandId) {
23
28
  "focus" -> root.requestFocusFromJS()
24
29
  "blur" -> root.requestBlurFromJS()
@@ -27,48 +32,73 @@ class CardFormViewManager : SimpleViewManager<CardFormView>() {
27
32
  }
28
33
 
29
34
  @ReactProp(name = "dangerouslyGetFullCardDetails")
30
- fun setDangerouslyGetFullCardDetails(view: CardFormView, dangerouslyGetFullCardDetails: Boolean = false) {
35
+ fun setDangerouslyGetFullCardDetails(
36
+ view: CardFormView,
37
+ dangerouslyGetFullCardDetails: Boolean = false,
38
+ ) {
31
39
  view.setDangerouslyGetFullCardDetails(dangerouslyGetFullCardDetails)
32
40
  }
33
41
 
34
42
  @ReactProp(name = "postalCodeEnabled")
35
- fun setPostalCodeEnabled(view: CardFormView, postalCodeEnabled: Boolean = false) {
43
+ fun setPostalCodeEnabled(
44
+ view: CardFormView,
45
+ postalCodeEnabled: Boolean = false,
46
+ ) {
36
47
  view.setPostalCodeEnabled(postalCodeEnabled)
37
48
  }
38
49
 
39
- @ReactProp(name = "placeholders")
40
- fun setPlaceHolders(view: CardFormView, placeholders: ReadableMap) {
41
- view.setPlaceHolders(placeholders)
42
- }
50
+ @ReactProp(name = "placeholders")
51
+ fun setPlaceHolders(
52
+ view: CardFormView,
53
+ placeholders: ReadableMap,
54
+ ) {
55
+ view.setPlaceHolders(placeholders)
56
+ }
43
57
 
44
58
  @ReactProp(name = "autofocus")
45
- fun setAutofocus(view: CardFormView, autofocus: Boolean = false) {
59
+ fun setAutofocus(
60
+ view: CardFormView,
61
+ autofocus: Boolean = false,
62
+ ) {
46
63
  view.setAutofocus(autofocus)
47
64
  }
48
65
 
49
66
  @ReactProp(name = "cardStyle")
50
- fun setCardStyle(view: CardFormView, cardStyle: ReadableMap) {
67
+ fun setCardStyle(
68
+ view: CardFormView,
69
+ cardStyle: ReadableMap,
70
+ ) {
51
71
  view.setCardStyle(cardStyle)
52
72
  }
53
73
 
54
74
  @ReactProp(name = "defaultValues")
55
- fun setDefaultValues(view: CardFormView, defaults: ReadableMap) {
75
+ fun setDefaultValues(
76
+ view: CardFormView,
77
+ defaults: ReadableMap,
78
+ ) {
56
79
  view.setDefaultValues(defaults)
57
80
  }
58
81
 
59
82
  @ReactProp(name = "disabled")
60
- fun setDisabled(view: CardFormView, isDisabled: Boolean) {
83
+ fun setDisabled(
84
+ view: CardFormView,
85
+ isDisabled: Boolean,
86
+ ) {
61
87
  view.setDisabled(isDisabled)
62
88
  }
63
89
 
64
90
  @ReactProp(name = "preferredNetworks")
65
- fun setPreferredNetworks(view: CardFormView, preferredNetworks: ReadableArray?) {
91
+ fun setPreferredNetworks(
92
+ view: CardFormView,
93
+ preferredNetworks: ReadableArray?,
94
+ ) {
66
95
  val networks = preferredNetworks?.toArrayList()?.filterIsInstance<Int>()?.let { ArrayList(it) }
67
96
  view.setPreferredNetworks(networks)
68
97
  }
69
98
 
70
99
  override fun createViewInstance(reactContext: ThemedReactContext): CardFormView {
71
- val stripeSdkModule: StripeSdkModule? = reactContext.getNativeModule(StripeSdkModule::class.java)
100
+ val stripeSdkModule: StripeSdkModule? =
101
+ reactContext.getNativeModule(StripeSdkModule::class.java)
72
102
  val view = CardFormView(reactContext)
73
103
 
74
104
  reactContextRef = reactContext
@@ -80,8 +110,13 @@ class CardFormViewManager : SimpleViewManager<CardFormView>() {
80
110
  override fun onDropViewInstance(view: CardFormView) {
81
111
  super.onDropViewInstance(view)
82
112
 
83
- val stripeSdkModule: StripeSdkModule? = reactContextRef?.getNativeModule(StripeSdkModule::class.java)
113
+ val stripeSdkModule: StripeSdkModule? =
114
+ reactContextRef?.getNativeModule(StripeSdkModule::class.java)
84
115
  stripeSdkModule?.cardFormView = null
85
116
  reactContextRef = null
86
117
  }
118
+
119
+ companion object {
120
+ const val REACT_CLASS = "CardForm"
121
+ }
87
122
  }
@@ -5,15 +5,17 @@ import android.view.LayoutInflater
5
5
  import android.view.View
6
6
  import android.view.ViewGroup
7
7
  import android.widget.FrameLayout
8
- import androidx.appcompat.app.AppCompatActivity
9
8
  import androidx.fragment.app.Fragment
10
9
  import com.facebook.react.bridge.Promise
11
10
  import com.facebook.react.bridge.ReactApplicationContext
12
- import com.reactnativestripesdk.utils.*
11
+ import com.reactnativestripesdk.utils.ErrorType
13
12
  import com.reactnativestripesdk.utils.createError
14
13
  import com.reactnativestripesdk.utils.createResult
14
+ import com.reactnativestripesdk.utils.mapFromFinancialConnectionsEvent
15
15
  import com.reactnativestripesdk.utils.mapFromPaymentIntentResult
16
16
  import com.reactnativestripesdk.utils.mapFromSetupIntentResult
17
+ import com.reactnativestripesdk.utils.removeFragment
18
+ import com.stripe.android.financialconnections.FinancialConnections
17
19
  import com.stripe.android.model.PaymentIntent
18
20
  import com.stripe.android.model.SetupIntent
19
21
  import com.stripe.android.model.StripeIntent
@@ -27,60 +29,89 @@ class CollectBankAccountLauncherFragment(
27
29
  private val stripeAccountId: String?,
28
30
  private val clientSecret: String,
29
31
  private val isPaymentIntent: Boolean,
30
- private val collectParams: CollectBankAccountConfiguration.USBankAccount,
31
- private val promise: Promise
32
+ private val collectParams: CollectBankAccountConfiguration.USBankAccount,
33
+ private val promise: Promise,
32
34
  ) : Fragment() {
33
35
  private lateinit var collectBankAccountLauncher: CollectBankAccountLauncher
34
36
 
35
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
36
- savedInstanceState: Bundle?): View {
37
- collectBankAccountLauncher = createBankAccountLauncher()
37
+ override fun onCreate(savedInstanceState: Bundle?) {
38
+ super.onCreate(savedInstanceState)
38
39
 
39
- return FrameLayout(requireActivity()).also {
40
- it.visibility = View.GONE
40
+ val stripeSdkModule: StripeSdkModule? = context.getNativeModule(StripeSdkModule::class.java)
41
+ if (stripeSdkModule != null && stripeSdkModule.eventListenerCount > 0) {
42
+ FinancialConnections.setEventListener { event ->
43
+ val params = mapFromFinancialConnectionsEvent(event)
44
+ stripeSdkModule.sendEvent(context, "onFinancialConnectionsEvent", params)
45
+ }
41
46
  }
42
47
  }
43
48
 
44
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
45
- super.onViewCreated(
46
- view,
47
- savedInstanceState)
49
+ override fun onCreateView(
50
+ inflater: LayoutInflater,
51
+ container: ViewGroup?,
52
+ savedInstanceState: Bundle?,
53
+ ): View {
54
+ collectBankAccountLauncher = createBankAccountLauncher()
55
+
56
+ return FrameLayout(requireActivity()).also { it.visibility = View.GONE }
57
+ }
58
+
59
+ override fun onViewCreated(
60
+ view: View,
61
+ savedInstanceState: Bundle?,
62
+ ) {
63
+ super.onViewCreated(view, savedInstanceState)
48
64
 
49
65
  if (isPaymentIntent) {
50
66
  collectBankAccountLauncher.presentWithPaymentIntent(
51
67
  publishableKey,
52
68
  stripeAccountId,
53
69
  clientSecret,
54
- collectParams
70
+ collectParams,
55
71
  )
56
72
  } else {
57
73
  collectBankAccountLauncher.presentWithSetupIntent(
58
74
  publishableKey,
59
75
  stripeAccountId,
60
76
  clientSecret,
61
- collectParams
77
+ collectParams,
62
78
  )
63
79
  }
64
80
  }
65
81
 
66
- private fun createBankAccountLauncher(): CollectBankAccountLauncher {
67
- return CollectBankAccountLauncher.create(this) { result ->
82
+ override fun onDestroy() {
83
+ super.onDestroy()
84
+
85
+ // Remove any event listener that might be set
86
+ FinancialConnections.clearEventListener()
87
+ }
88
+
89
+ private fun createBankAccountLauncher(): CollectBankAccountLauncher =
90
+ CollectBankAccountLauncher.create(this) { result ->
68
91
  when (result) {
69
92
  is CollectBankAccountResult.Completed -> {
70
93
  val intent = result.response.intent
71
94
  if (intent.status === StripeIntent.Status.RequiresPaymentMethod) {
72
- promise.resolve(createError(ErrorType.Canceled.toString(), "Bank account collection was canceled."))
95
+ promise.resolve(
96
+ createError(ErrorType.Canceled.toString(), "Bank account collection was canceled."),
97
+ )
73
98
  } else if (intent.status === StripeIntent.Status.RequiresConfirmation) {
74
99
  promise.resolve(
75
- if (isPaymentIntent)
76
- createResult("paymentIntent", mapFromPaymentIntentResult(intent as PaymentIntent))
77
- else
100
+ if (isPaymentIntent) {
101
+ createResult(
102
+ "paymentIntent",
103
+ mapFromPaymentIntentResult(intent as PaymentIntent),
104
+ )
105
+ } else {
78
106
  createResult("setupIntent", mapFromSetupIntentResult(intent as SetupIntent))
107
+ },
79
108
  )
80
109
  }
81
110
  }
82
111
  is CollectBankAccountResult.Cancelled -> {
83
- promise.resolve(createError(ErrorType.Canceled.toString(), "Bank account collection was canceled."))
112
+ promise.resolve(
113
+ createError(ErrorType.Canceled.toString(), "Bank account collection was canceled."),
114
+ )
84
115
  }
85
116
  is CollectBankAccountResult.Failed -> {
86
117
  promise.resolve(createError(ErrorType.Failed.toString(), result.error))
@@ -88,7 +119,6 @@ class CollectBankAccountLauncherFragment(
88
119
  }
89
120
  removeFragment(context)
90
121
  }
91
- }
92
122
 
93
123
  companion object {
94
124
  internal const val TAG = "collect_bank_account_launcher_fragment"