@stripe/stripe-react-native 0.42.0 → 0.44.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 (309) hide show
  1. package/.husky/pre-commit +0 -3
  2. package/CHANGELOG.md +26 -0
  3. package/android/.gradle/8.11.1/checksums/checksums.lock +0 -0
  4. package/android/.gradle/8.11.1/checksums/md5-checksums.bin +0 -0
  5. package/android/.gradle/8.11.1/checksums/sha1-checksums.bin +0 -0
  6. package/android/.gradle/8.11.1/executionHistory/executionHistory.lock +0 -0
  7. package/android/.gradle/8.11.1/fileHashes/fileHashes.lock +0 -0
  8. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  9. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  10. package/android/.project +0 -11
  11. package/android/.settings/org.eclipse.buildship.core.prefs +3 -3
  12. package/android/build.gradle +8 -1
  13. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  14. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  15. package/android/gradle.properties +4 -1
  16. package/android/gradlew +249 -0
  17. package/android/gradlew.bat +92 -0
  18. package/android/spotless.gradle +19 -0
  19. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +30 -34
  20. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormViewManager.kt +20 -10
  21. package/android/src/main/java/com/reactnativestripesdk/CardChangedEvent.kt +12 -13
  22. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +242 -105
  23. package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +58 -20
  24. package/android/src/main/java/com/reactnativestripesdk/CardFocusEvent.kt +8 -11
  25. package/android/src/main/java/com/reactnativestripesdk/CardFormCompleteEvent.kt +10 -12
  26. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +135 -87
  27. package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +57 -22
  28. package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +33 -24
  29. package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +107 -85
  30. package/android/src/main/java/com/reactnativestripesdk/FormCompleteEvent.kt +9 -11
  31. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +16 -9
  32. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +36 -28
  33. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +67 -43
  34. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +21 -16
  35. package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +101 -56
  36. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +244 -166
  37. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +137 -156
  38. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +181 -57
  39. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +422 -258
  40. package/android/src/main/java/com/reactnativestripesdk/StripeContainerManager.kt +11 -4
  41. package/android/src/main/java/com/reactnativestripesdk/StripeContainerView.kt +5 -1
  42. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +656 -299
  43. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +12 -14
  44. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +42 -37
  45. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetEvent.kt +12 -11
  46. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +29 -29
  47. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +50 -18
  48. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +227 -147
  49. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +15 -18
  50. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +33 -15
  51. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +63 -37
  52. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletCompleteEvent.kt +9 -13
  53. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/EphemeralKeyProvider.kt +15 -17
  54. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxy.kt +76 -60
  55. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +71 -47
  56. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +117 -51
  57. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +4 -3
  58. package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +39 -0
  59. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +295 -258
  60. package/android/src/main/java/com/reactnativestripesdk/utils/PostalCodeUtilities.kt +2 -11
  61. package/ios/CustomerSheet/CustomerSheetUtils.swift +13 -7
  62. package/ios/FinancialConnections.swift +6 -2
  63. package/ios/StripeSdk+CustomerSheet.swift +3 -1
  64. package/ios/StripeSdk+PaymentSheet.swift +86 -21
  65. package/ios/StripeSdk.m +2 -0
  66. package/ios/StripeSdk.swift +72 -11
  67. package/lib/commonjs/NativeStripeSdk.js +1 -1
  68. package/lib/commonjs/NativeStripeSdk.js.map +1 -1
  69. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  70. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  71. package/lib/commonjs/components/AddressSheet.js +1 -1
  72. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  73. package/lib/commonjs/components/ApplePayButtonNative.js +1 -1
  74. package/lib/commonjs/components/ApplePayButtonNative.js.map +1 -1
  75. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  76. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  77. package/lib/commonjs/components/CardField.js +1 -1
  78. package/lib/commonjs/components/CardField.js.map +1 -1
  79. package/lib/commonjs/components/CardForm.js +1 -1
  80. package/lib/commonjs/components/CardForm.js.map +1 -1
  81. package/lib/commonjs/components/CustomerSheet.js +1 -1
  82. package/lib/commonjs/components/CustomerSheet.js.map +1 -1
  83. package/lib/commonjs/components/GooglePayButtonNative.js +1 -1
  84. package/lib/commonjs/components/GooglePayButtonNative.js.map +1 -1
  85. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  86. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  87. package/lib/commonjs/components/StripeContainer.js +1 -1
  88. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  89. package/lib/commonjs/components/StripeProvider.js +1 -1
  90. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  91. package/lib/commonjs/functions.js +1 -1
  92. package/lib/commonjs/functions.js.map +1 -1
  93. package/lib/commonjs/helpers.js +1 -1
  94. package/lib/commonjs/helpers.js.map +1 -1
  95. package/lib/commonjs/hooks/useConfirmPayment.js.map +1 -1
  96. package/lib/commonjs/hooks/useConfirmSetupIntent.js.map +1 -1
  97. package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -1
  98. package/lib/commonjs/hooks/usePaymentSheet.js.map +1 -1
  99. package/lib/commonjs/hooks/usePlatformPay.js.map +1 -1
  100. package/lib/commonjs/hooks/useStripe.js.map +1 -1
  101. package/lib/commonjs/index.js.map +1 -1
  102. package/lib/commonjs/package.json +1 -0
  103. package/lib/commonjs/plugin/withStripe.js +1 -1
  104. package/lib/commonjs/plugin/withStripe.js.map +1 -1
  105. package/lib/commonjs/types/ApplePay.js.map +1 -1
  106. package/lib/commonjs/types/Common.js +1 -1
  107. package/lib/commonjs/types/Common.js.map +1 -1
  108. package/lib/commonjs/types/CustomerSheet.js.map +1 -1
  109. package/lib/commonjs/types/Errors.js +1 -1
  110. package/lib/commonjs/types/Errors.js.map +1 -1
  111. package/lib/commonjs/types/FinancialConnections.js +1 -1
  112. package/lib/commonjs/types/FinancialConnections.js.map +1 -1
  113. package/lib/commonjs/types/NextAction.js.map +1 -1
  114. package/lib/commonjs/types/PaymentIntent.js +1 -1
  115. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  116. package/lib/commonjs/types/PaymentMethod.js.map +1 -1
  117. package/lib/commonjs/types/PaymentSheet.js +1 -1
  118. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  119. package/lib/commonjs/types/PlatformPay.js +1 -1
  120. package/lib/commonjs/types/PlatformPay.js.map +1 -1
  121. package/lib/commonjs/types/PushProvisioning.js +1 -1
  122. package/lib/commonjs/types/PushProvisioning.js.map +1 -1
  123. package/lib/commonjs/types/SetupIntent.js +1 -1
  124. package/lib/commonjs/types/SetupIntent.js.map +1 -1
  125. package/lib/commonjs/types/ThreeDSecure.js +1 -1
  126. package/lib/commonjs/types/ThreeDSecure.js.map +1 -1
  127. package/lib/commonjs/types/Token.js.map +1 -1
  128. package/lib/commonjs/types/components/ApplePayButtonComponent.js.map +1 -1
  129. package/lib/commonjs/types/components/AuBECSDebitFormComponent.js.map +1 -1
  130. package/lib/commonjs/types/components/CardFieldInput.js +1 -1
  131. package/lib/commonjs/types/components/CardFieldInput.js.map +1 -1
  132. package/lib/commonjs/types/components/CardFormView.js.map +1 -1
  133. package/lib/commonjs/types/components/GooglePayButtonComponent.js.map +1 -1
  134. package/lib/commonjs/types/index.js +1 -1
  135. package/lib/commonjs/types/index.js.map +1 -1
  136. package/lib/module/NativeStripeSdk.js +1 -1
  137. package/lib/module/NativeStripeSdk.js.map +1 -1
  138. package/lib/module/components/AddToWalletButton.js +1 -1
  139. package/lib/module/components/AddToWalletButton.js.map +1 -1
  140. package/lib/module/components/AddressSheet.js +1 -1
  141. package/lib/module/components/AddressSheet.js.map +1 -1
  142. package/lib/module/components/ApplePayButtonNative.js +1 -1
  143. package/lib/module/components/ApplePayButtonNative.js.map +1 -1
  144. package/lib/module/components/AuBECSDebitForm.js +1 -1
  145. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  146. package/lib/module/components/CardField.js +1 -1
  147. package/lib/module/components/CardField.js.map +1 -1
  148. package/lib/module/components/CardForm.js +1 -1
  149. package/lib/module/components/CardForm.js.map +1 -1
  150. package/lib/module/components/CustomerSheet.js +1 -1
  151. package/lib/module/components/CustomerSheet.js.map +1 -1
  152. package/lib/module/components/GooglePayButtonNative.js +1 -1
  153. package/lib/module/components/GooglePayButtonNative.js.map +1 -1
  154. package/lib/module/components/PlatformPayButton.js +1 -1
  155. package/lib/module/components/PlatformPayButton.js.map +1 -1
  156. package/lib/module/components/StripeContainer.js +1 -1
  157. package/lib/module/components/StripeContainer.js.map +1 -1
  158. package/lib/module/components/StripeProvider.js +1 -1
  159. package/lib/module/components/StripeProvider.js.map +1 -1
  160. package/lib/module/functions.js +1 -1
  161. package/lib/module/functions.js.map +1 -1
  162. package/lib/module/helpers.js +1 -1
  163. package/lib/module/helpers.js.map +1 -1
  164. package/lib/module/hooks/useConfirmPayment.js.map +1 -1
  165. package/lib/module/hooks/useConfirmSetupIntent.js.map +1 -1
  166. package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -1
  167. package/lib/module/hooks/usePaymentSheet.js.map +1 -1
  168. package/lib/module/hooks/usePlatformPay.js.map +1 -1
  169. package/lib/module/hooks/useStripe.js.map +1 -1
  170. package/lib/module/index.js.map +1 -1
  171. package/lib/module/package.json +1 -0
  172. package/lib/module/plugin/withStripe.js +1 -1
  173. package/lib/module/plugin/withStripe.js.map +1 -1
  174. package/lib/module/types/ApplePay.js.map +1 -1
  175. package/lib/module/types/Common.js +1 -1
  176. package/lib/module/types/Common.js.map +1 -1
  177. package/lib/module/types/CustomerSheet.js.map +1 -1
  178. package/lib/module/types/Errors.js +1 -1
  179. package/lib/module/types/Errors.js.map +1 -1
  180. package/lib/module/types/FinancialConnections.js +1 -1
  181. package/lib/module/types/FinancialConnections.js.map +1 -1
  182. package/lib/module/types/NextAction.js.map +1 -1
  183. package/lib/module/types/PaymentIntent.js +1 -1
  184. package/lib/module/types/PaymentIntent.js.map +1 -1
  185. package/lib/module/types/PaymentMethod.js.map +1 -1
  186. package/lib/module/types/PaymentSheet.js +1 -1
  187. package/lib/module/types/PaymentSheet.js.map +1 -1
  188. package/lib/module/types/PlatformPay.js +1 -1
  189. package/lib/module/types/PlatformPay.js.map +1 -1
  190. package/lib/module/types/PushProvisioning.js +1 -1
  191. package/lib/module/types/PushProvisioning.js.map +1 -1
  192. package/lib/module/types/SetupIntent.js +1 -1
  193. package/lib/module/types/SetupIntent.js.map +1 -1
  194. package/lib/module/types/ThreeDSecure.js +1 -1
  195. package/lib/module/types/ThreeDSecure.js.map +1 -1
  196. package/lib/module/types/Token.js.map +1 -1
  197. package/lib/module/types/components/ApplePayButtonComponent.js.map +1 -1
  198. package/lib/module/types/components/AuBECSDebitFormComponent.js.map +1 -1
  199. package/lib/module/types/components/CardFieldInput.js +1 -1
  200. package/lib/module/types/components/CardFieldInput.js.map +1 -1
  201. package/lib/module/types/components/CardFormView.js.map +1 -1
  202. package/lib/module/types/components/GooglePayButtonComponent.js.map +1 -1
  203. package/lib/module/types/index.js +1 -1
  204. package/lib/module/types/index.js.map +1 -1
  205. package/lib/typescript/src/NativeStripeSdk.d.ts +4 -3
  206. package/lib/typescript/src/NativeStripeSdk.d.ts.map +1 -0
  207. package/lib/typescript/src/components/AddToWalletButton.d.ts +3 -1
  208. package/lib/typescript/src/components/AddToWalletButton.d.ts.map +1 -0
  209. package/lib/typescript/src/components/AddressSheet.d.ts +4 -2
  210. package/lib/typescript/src/components/AddressSheet.d.ts.map +1 -0
  211. package/lib/typescript/src/components/ApplePayButtonNative.d.ts +1 -0
  212. package/lib/typescript/src/components/ApplePayButtonNative.d.ts.map +1 -0
  213. package/lib/typescript/src/components/AuBECSDebitForm.d.ts +3 -1
  214. package/lib/typescript/src/components/AuBECSDebitForm.d.ts.map +1 -0
  215. package/lib/typescript/src/components/CardField.d.ts +1 -0
  216. package/lib/typescript/src/components/CardField.d.ts.map +1 -0
  217. package/lib/typescript/src/components/CardForm.d.ts +1 -0
  218. package/lib/typescript/src/components/CardForm.d.ts.map +1 -0
  219. package/lib/typescript/src/components/CustomerSheet.d.ts +2 -1
  220. package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -0
  221. package/lib/typescript/src/components/GooglePayButtonNative.d.ts +1 -0
  222. package/lib/typescript/src/components/GooglePayButtonNative.d.ts.map +1 -0
  223. package/lib/typescript/src/components/PlatformPayButton.d.ts +3 -1
  224. package/lib/typescript/src/components/PlatformPayButton.d.ts.map +1 -0
  225. package/lib/typescript/src/components/StripeContainer.d.ts +2 -1
  226. package/lib/typescript/src/components/StripeContainer.d.ts.map +1 -0
  227. package/lib/typescript/src/components/StripeProvider.d.ts +3 -2
  228. package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -0
  229. package/lib/typescript/src/functions.d.ts +6 -5
  230. package/lib/typescript/src/functions.d.ts.map +1 -0
  231. package/lib/typescript/src/helpers.d.ts +1 -0
  232. package/lib/typescript/src/helpers.d.ts.map +1 -0
  233. package/lib/typescript/src/hooks/useConfirmPayment.d.ts +2 -1
  234. package/lib/typescript/src/hooks/useConfirmPayment.d.ts.map +1 -0
  235. package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts +1 -0
  236. package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts.map +1 -0
  237. package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +3 -2
  238. package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts.map +1 -0
  239. package/lib/typescript/src/hooks/usePaymentSheet.d.ts +2 -1
  240. package/lib/typescript/src/hooks/usePaymentSheet.d.ts.map +1 -0
  241. package/lib/typescript/src/hooks/usePlatformPay.d.ts +4 -3
  242. package/lib/typescript/src/hooks/usePlatformPay.d.ts.map +1 -0
  243. package/lib/typescript/src/hooks/useStripe.d.ts +11 -8
  244. package/lib/typescript/src/hooks/useStripe.d.ts.map +1 -0
  245. package/lib/typescript/src/index.d.ts +1 -0
  246. package/lib/typescript/src/index.d.ts.map +1 -0
  247. package/lib/typescript/src/plugin/withStripe.d.ts +2 -1
  248. package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -0
  249. package/lib/typescript/src/types/ApplePay.d.ts +6 -5
  250. package/lib/typescript/src/types/ApplePay.d.ts.map +1 -0
  251. package/lib/typescript/src/types/Common.d.ts +4 -1
  252. package/lib/typescript/src/types/Common.d.ts.map +1 -0
  253. package/lib/typescript/src/types/CustomerSheet.d.ts +16 -4
  254. package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -0
  255. package/lib/typescript/src/types/Errors.d.ts +2 -1
  256. package/lib/typescript/src/types/Errors.d.ts.map +1 -0
  257. package/lib/typescript/src/types/FinancialConnections.d.ts +21 -17
  258. package/lib/typescript/src/types/FinancialConnections.d.ts.map +1 -0
  259. package/lib/typescript/src/types/NextAction.d.ts +9 -8
  260. package/lib/typescript/src/types/NextAction.d.ts.map +1 -0
  261. package/lib/typescript/src/types/PaymentIntent.d.ts +16 -15
  262. package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -0
  263. package/lib/typescript/src/types/PaymentMethod.d.ts +21 -16
  264. package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -0
  265. package/lib/typescript/src/types/PaymentSheet.d.ts +91 -22
  266. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -0
  267. package/lib/typescript/src/types/PlatformPay.d.ts +22 -21
  268. package/lib/typescript/src/types/PlatformPay.d.ts.map +1 -0
  269. package/lib/typescript/src/types/PushProvisioning.d.ts +5 -4
  270. package/lib/typescript/src/types/PushProvisioning.d.ts.map +1 -0
  271. package/lib/typescript/src/types/SetupIntent.d.ts +4 -3
  272. package/lib/typescript/src/types/SetupIntent.d.ts.map +1 -0
  273. package/lib/typescript/src/types/ThreeDSecure.d.ts +1 -0
  274. package/lib/typescript/src/types/ThreeDSecure.d.ts.map +1 -0
  275. package/lib/typescript/src/types/Token.d.ts +10 -9
  276. package/lib/typescript/src/types/Token.d.ts.map +1 -0
  277. package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts +3 -2
  278. package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts.map +1 -0
  279. package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts +1 -0
  280. package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts.map +1 -0
  281. package/lib/typescript/src/types/components/CardFieldInput.d.ts +8 -5
  282. package/lib/typescript/src/types/components/CardFieldInput.d.ts.map +1 -0
  283. package/lib/typescript/src/types/components/CardFormView.d.ts +9 -6
  284. package/lib/typescript/src/types/components/CardFormView.d.ts.map +1 -0
  285. package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts +1 -0
  286. package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts.map +1 -0
  287. package/lib/typescript/src/types/index.d.ts +24 -23
  288. package/lib/typescript/src/types/index.d.ts.map +1 -0
  289. package/package.json +32 -40
  290. package/src/NativeStripeSdk.tsx +4 -2
  291. package/src/components/CardField.tsx +1 -1
  292. package/src/components/CardForm.tsx +12 -9
  293. package/src/components/CustomerSheet.tsx +4 -6
  294. package/src/components/StripeProvider.tsx +17 -0
  295. package/src/functions.ts +13 -14
  296. package/src/helpers.ts +2 -1
  297. package/src/types/Common.ts +3 -0
  298. package/src/types/CustomerSheet.ts +11 -0
  299. package/src/types/FinancialConnections.ts +3 -0
  300. package/src/types/PaymentMethod.ts +5 -1
  301. package/src/types/PaymentSheet.ts +85 -4
  302. package/src/types/components/CardFieldInput.ts +8 -4
  303. package/src/types/components/CardFormView.ts +8 -4
  304. package/stripe-react-native.podspec +2 -1
  305. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  306. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  307. package/android/.gradle/8.9/gc.properties +0 -0
  308. /package/android/.gradle/{8.9 → 8.11.1}/fileChanges/last-build.bin +0 -0
  309. /package/android/.gradle/{8.9/dependencies-accessors → 8.11.1}/gc.properties +0 -0
@@ -2,20 +2,63 @@ package com.reactnativestripesdk
2
2
 
3
3
  import android.app.Activity
4
4
  import android.content.Intent
5
- import android.os.Parcelable
6
5
  import android.util.Log
7
6
  import androidx.fragment.app.FragmentActivity
8
- import com.facebook.react.bridge.*
7
+ import com.facebook.react.bridge.BaseActivityEventListener
8
+ import com.facebook.react.bridge.Promise
9
+ import com.facebook.react.bridge.ReactApplicationContext
10
+ import com.facebook.react.bridge.ReactContext
11
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
12
+ import com.facebook.react.bridge.ReactMethod
13
+ import com.facebook.react.bridge.ReadableArray
14
+ import com.facebook.react.bridge.ReadableMap
15
+ import com.facebook.react.bridge.WritableMap
16
+ import com.facebook.react.bridge.WritableNativeMap
9
17
  import com.facebook.react.module.annotations.ReactModule
10
18
  import com.facebook.react.modules.core.DeviceEventManagerModule
11
19
  import com.reactnativestripesdk.addresssheet.AddressLauncherFragment
12
20
  import com.reactnativestripesdk.pushprovisioning.PushProvisioningProxy
13
- import com.reactnativestripesdk.utils.*
14
- import com.stripe.android.*
21
+ import com.reactnativestripesdk.utils.ConfirmPaymentErrorType
22
+ import com.reactnativestripesdk.utils.CreateTokenErrorType
23
+ import com.reactnativestripesdk.utils.ErrorType
24
+ import com.reactnativestripesdk.utils.GooglePayErrorType
25
+ import com.reactnativestripesdk.utils.createCanAddCardResult
26
+ import com.reactnativestripesdk.utils.createError
27
+ import com.reactnativestripesdk.utils.createMissingActivityError
28
+ import com.reactnativestripesdk.utils.createMissingInitError
29
+ import com.reactnativestripesdk.utils.createResult
30
+ import com.reactnativestripesdk.utils.getBooleanOr
31
+ import com.reactnativestripesdk.utils.getBooleanOrFalse
32
+ import com.reactnativestripesdk.utils.getMapOrNull
33
+ import com.reactnativestripesdk.utils.getValOr
34
+ import com.reactnativestripesdk.utils.mapFromPaymentIntentResult
35
+ import com.reactnativestripesdk.utils.mapFromPaymentMethod
36
+ import com.reactnativestripesdk.utils.mapFromSetupIntentResult
37
+ import com.reactnativestripesdk.utils.mapFromToken
38
+ import com.reactnativestripesdk.utils.mapToAddress
39
+ import com.reactnativestripesdk.utils.mapToBankAccountType
40
+ import com.reactnativestripesdk.utils.mapToPaymentMethodType
41
+ import com.reactnativestripesdk.utils.mapToReturnURL
42
+ import com.reactnativestripesdk.utils.mapToShippingDetails
43
+ import com.reactnativestripesdk.utils.mapToUICustomization
44
+ import com.reactnativestripesdk.utils.removeFragment
45
+ import com.reactnativestripesdk.utils.toBundleObject
46
+ import com.stripe.android.ApiResultCallback
47
+ import com.stripe.android.GooglePayJsonFactory
48
+ import com.stripe.android.PaymentAuthConfig
49
+ import com.stripe.android.PaymentConfiguration
50
+ import com.stripe.android.Stripe
15
51
  import com.stripe.android.core.ApiVersion
16
52
  import com.stripe.android.core.AppInfo
17
53
  import com.stripe.android.googlepaylauncher.GooglePayLauncher
18
- import com.stripe.android.model.*
54
+ import com.stripe.android.model.BankAccountTokenParams
55
+ import com.stripe.android.model.CardParams
56
+ import com.stripe.android.model.ConfirmPaymentIntentParams
57
+ import com.stripe.android.model.ConfirmSetupIntentParams
58
+ import com.stripe.android.model.PaymentIntent
59
+ import com.stripe.android.model.PaymentMethod
60
+ import com.stripe.android.model.SetupIntent
61
+ import com.stripe.android.model.Token
19
62
  import com.stripe.android.payments.bankaccount.CollectBankAccountConfiguration
20
63
  import com.stripe.android.paymentsheet.PaymentSheet
21
64
  import kotlinx.coroutines.CoroutineScope
@@ -23,12 +66,11 @@ import kotlinx.coroutines.Dispatchers
23
66
  import kotlinx.coroutines.launch
24
67
  import org.json.JSONObject
25
68
 
26
-
27
69
  @ReactModule(name = StripeSdkModule.NAME)
28
- class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
29
- override fun getName(): String {
30
- return "StripeSdk"
31
- }
70
+ class StripeSdkModule(
71
+ reactContext: ReactApplicationContext,
72
+ ) : ReactContextBaseJavaModule(reactContext) {
73
+ override fun getName(): String = NAME
32
74
 
33
75
  var cardFieldView: CardFieldView? = null
34
76
  var cardFormView: CardFormView? = null
@@ -38,8 +80,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
38
80
  private var stripeAccountId: String? = null
39
81
  private var urlScheme: String? = null
40
82
 
41
- private var confirmPromise: Promise? = null
42
- private var confirmPaymentClientSecret: String? = null
43
83
  private var createPlatformPayPaymentMethodPromise: Promise? = null
44
84
  private var platformPayUsesDeprecatedTokenFlow = false
45
85
 
@@ -54,40 +94,63 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
54
94
  // If you create a new Fragment, you must put the tag here, otherwise result callbacks for that
55
95
  // Fragment will not work on RN < 0.65
56
96
  private val allStripeFragmentTags: List<String>
57
- get() = listOf(
58
- PaymentSheetFragment.TAG,
59
- PaymentLauncherFragment.TAG,
60
- CollectBankAccountLauncherFragment.TAG,
61
- FinancialConnectionsSheetFragment.TAG,
62
- AddressLauncherFragment.TAG,
63
- GooglePayLauncherFragment.TAG,
64
- CustomerSheetFragment.TAG
65
- )
97
+ get() =
98
+ listOf(
99
+ PaymentSheetFragment.TAG,
100
+ PaymentLauncherFragment.TAG,
101
+ CollectBankAccountLauncherFragment.TAG,
102
+ FinancialConnectionsSheetFragment.TAG,
103
+ AddressLauncherFragment.TAG,
104
+ GooglePayLauncherFragment.TAG,
105
+ CustomerSheetFragment.TAG,
106
+ )
66
107
 
67
- private val mActivityEventListener = object : BaseActivityEventListener() {
68
- override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
69
- if (::stripe.isInitialized) {
70
- when (requestCode) {
71
- GooglePayRequestHelper.LOAD_PAYMENT_DATA_REQUEST_CODE -> {
72
- createPlatformPayPaymentMethodPromise?.let {
73
- GooglePayRequestHelper.handleGooglePaymentMethodResult(resultCode, data, stripe, platformPayUsesDeprecatedTokenFlow, it)
74
- createPlatformPayPaymentMethodPromise = null
75
- } ?: run { Log.d("StripeReactNative", "No promise was found, Google Pay result went unhandled,") }
76
- }
77
- else -> {
78
- dispatchActivityResultsToFragments(requestCode, resultCode, data)
108
+ private val mActivityEventListener =
109
+ object : BaseActivityEventListener() {
110
+ override fun onActivityResult(
111
+ activity: Activity,
112
+ requestCode: Int,
113
+ resultCode: Int,
114
+ data: Intent?,
115
+ ) {
116
+ if (::stripe.isInitialized) {
117
+ when (requestCode) {
118
+ GooglePayRequestHelper.LOAD_PAYMENT_DATA_REQUEST_CODE -> {
119
+ createPlatformPayPaymentMethodPromise?.let {
120
+ GooglePayRequestHelper.handleGooglePaymentMethodResult(
121
+ resultCode,
122
+ data,
123
+ stripe,
124
+ platformPayUsesDeprecatedTokenFlow,
125
+ it,
126
+ )
127
+ createPlatformPayPaymentMethodPromise = null
128
+ } ?: run {
129
+ Log.d(
130
+ "StripeReactNative",
131
+ "No promise was found, Google Pay result went unhandled,",
132
+ )
133
+ }
134
+ }
135
+
136
+ else -> {
137
+ dispatchActivityResultsToFragments(requestCode, resultCode, data)
138
+ }
79
139
  }
80
140
  }
81
141
  }
82
142
  }
83
- }
84
143
 
85
144
  init {
86
145
  reactContext.addActivityEventListener(mActivityEventListener)
87
146
  }
88
147
 
89
148
  // Necessary on older versions of React Native (~0.65 and below)
90
- private fun dispatchActivityResultsToFragments(requestCode: Int, resultCode: Int, data: Intent?) {
149
+ private fun dispatchActivityResultsToFragments(
150
+ requestCode: Int,
151
+ resultCode: Int,
152
+ data: Intent?,
153
+ ) {
91
154
  getCurrentActivityOrResolveWithError(null)?.supportFragmentManager?.let { fragmentManager ->
92
155
  for (tag in allStripeFragmentTags) {
93
156
  fragmentManager.findFragmentByTag(tag)?.let {
@@ -103,26 +166,30 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
103
166
  val uiCustomization = mapToUICustomization(params)
104
167
 
105
168
  PaymentAuthConfig.init(
106
- PaymentAuthConfig.Builder()
169
+ PaymentAuthConfig
170
+ .Builder()
107
171
  .set3ds2Config(
108
172
  stripe3dsConfigBuilder
109
173
  .setUiCustomization(uiCustomization)
110
- .build()
111
- )
112
- .build()
174
+ .build(),
175
+ ).build(),
113
176
  )
114
177
  }
115
178
 
116
179
  override fun getConstants(): MutableMap<String, Any> =
117
180
  hashMapOf(
118
- "API_VERSIONS" to hashMapOf(
119
- "CORE" to ApiVersion.API_VERSION_CODE,
120
- "ISSUING" to PushProvisioningProxy.getApiVersion(),
121
- )
181
+ "API_VERSIONS" to
182
+ hashMapOf(
183
+ "CORE" to ApiVersion.API_VERSION_CODE,
184
+ "ISSUING" to PushProvisioningProxy.getApiVersion(),
185
+ ),
122
186
  )
123
187
 
124
188
  @ReactMethod
125
- fun initialise(params: ReadableMap, promise: Promise) {
189
+ fun initialise(
190
+ params: ReadableMap,
191
+ promise: Promise,
192
+ ) {
126
193
  val publishableKey = getValOr(params, "publishableKey", null) as String
127
194
  val appInfo = getMapOrNull(params, "appInfo") as ReadableMap
128
195
  this.stripeAccountId = getValOr(params, "stripeAccountId", null)
@@ -150,15 +217,20 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
150
217
  }
151
218
 
152
219
  @ReactMethod
153
- fun initPaymentSheet(params: ReadableMap, promise: Promise) {
220
+ fun initPaymentSheet(
221
+ params: ReadableMap,
222
+ promise: Promise,
223
+ ) {
154
224
  getCurrentActivityOrResolveWithError(promise)?.let { activity ->
155
225
  paymentSheetFragment?.removeFragment(reactApplicationContext)
156
- paymentSheetFragment = PaymentSheetFragment(reactApplicationContext, promise).also {
157
- val bundle = toBundleObject(params)
158
- it.arguments = bundle
159
- }
226
+ paymentSheetFragment =
227
+ PaymentSheetFragment(reactApplicationContext, promise).also {
228
+ val bundle = toBundleObject(params)
229
+ it.arguments = bundle
230
+ }
160
231
  try {
161
- activity.supportFragmentManager.beginTransaction()
232
+ activity.supportFragmentManager
233
+ .beginTransaction()
162
234
  .add(paymentSheetFragment!!, PaymentSheetFragment.TAG)
163
235
  .commit()
164
236
  } catch (error: IllegalStateException) {
@@ -168,7 +240,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
168
240
  }
169
241
 
170
242
  @ReactMethod
171
- fun presentPaymentSheet(options: ReadableMap, promise: Promise) {
243
+ fun presentPaymentSheet(
244
+ options: ReadableMap,
245
+ promise: Promise,
246
+ ) {
172
247
  if (paymentSheetFragment == null) {
173
248
  promise.resolve(PaymentSheetFragment.createMissingInitError())
174
249
  return
@@ -177,7 +252,8 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
177
252
  val timeoutKey = "timeout"
178
253
  if (options.hasKey(timeoutKey)) {
179
254
  paymentSheetFragment?.presentWithTimeout(
180
- options.getInt(timeoutKey).toLong(), promise
255
+ options.getInt(timeoutKey).toLong(),
256
+ promise,
181
257
  )
182
258
  } else {
183
259
  paymentSheetFragment?.present(promise)
@@ -201,7 +277,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
201
277
  }
202
278
 
203
279
  @ReactMethod
204
- fun intentCreationCallback(params: ReadableMap, promise: Promise) {
280
+ fun intentCreationCallback(
281
+ params: ReadableMap,
282
+ promise: Promise,
283
+ ) {
205
284
  if (paymentSheetFragment == null) {
206
285
  promise.resolve(PaymentSheetFragment.createMissingInitError())
207
286
  return
@@ -211,27 +290,39 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
211
290
  }
212
291
 
213
292
  @ReactMethod
214
- fun createPaymentMethod(data: ReadableMap, options: ReadableMap, promise: Promise) {
215
- val paymentMethodType = getValOr(data, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
216
- promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), "You must provide paymentMethodType"))
217
- return
218
- }
293
+ fun createPaymentMethod(
294
+ data: ReadableMap,
295
+ options: ReadableMap,
296
+ promise: Promise,
297
+ ) {
298
+ val paymentMethodType =
299
+ getValOr(data, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
300
+ promise.resolve(
301
+ createError(
302
+ ConfirmPaymentErrorType.Failed.toString(),
303
+ "You must provide paymentMethodType",
304
+ ),
305
+ )
306
+ return
307
+ }
219
308
  val paymentMethodData = getMapOrNull(data, "paymentMethodData")
220
- val factory = PaymentMethodCreateParamsFactory(paymentMethodData, options, cardFieldView, cardFormView)
309
+ val factory =
310
+ PaymentMethodCreateParamsFactory(paymentMethodData, options, cardFieldView, cardFormView)
221
311
  try {
222
312
  val paymentMethodCreateParams = factory.createPaymentMethodParams(paymentMethodType)
223
313
  stripe.createPaymentMethod(
224
314
  paymentMethodCreateParams,
225
- callback = object : ApiResultCallback<PaymentMethod> {
226
- override fun onError(e: Exception) {
227
- promise.resolve(createError("Failed", e))
228
- }
315
+ callback =
316
+ object : ApiResultCallback<PaymentMethod> {
317
+ override fun onError(e: Exception) {
318
+ promise.resolve(createError("Failed", e))
319
+ }
229
320
 
230
- override fun onSuccess(result: PaymentMethod) {
231
- val paymentMethodMap: WritableMap = mapFromPaymentMethod(result)
232
- promise.resolve(createResult("paymentMethod", paymentMethodMap))
233
- }
234
- }
321
+ override fun onSuccess(result: PaymentMethod) {
322
+ val paymentMethodMap: WritableMap = mapFromPaymentMethod(result)
323
+ promise.resolve(createResult("paymentMethod", paymentMethodMap))
324
+ }
325
+ },
235
326
  )
236
327
  } catch (error: PaymentMethodCreateParamsException) {
237
328
  promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
@@ -239,10 +330,18 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
239
330
  }
240
331
 
241
332
  @ReactMethod
242
- fun createToken(params: ReadableMap, promise: Promise) {
333
+ fun createToken(
334
+ params: ReadableMap,
335
+ promise: Promise,
336
+ ) {
243
337
  val type = getValOr(params, "type", null)
244
338
  if (type == null) {
245
- promise.resolve(createError(CreateTokenErrorType.Failed.toString(), "type parameter is required"))
339
+ promise.resolve(
340
+ createError(
341
+ CreateTokenErrorType.Failed.toString(),
342
+ "type parameter is required",
343
+ ),
344
+ )
246
345
  return
247
346
  }
248
347
 
@@ -250,34 +349,53 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
250
349
  "BankAccount" -> {
251
350
  createTokenFromBankAccount(params, promise)
252
351
  }
352
+
253
353
  "Card" -> {
254
354
  createTokenFromCard(params, promise)
255
355
  }
356
+
256
357
  "Pii" -> {
257
358
  createTokenFromPii(params, promise)
258
359
  }
360
+
259
361
  else -> {
260
- promise.resolve(createError(CreateTokenErrorType.Failed.toString(), "$type type is not supported yet"))
362
+ promise.resolve(
363
+ createError(
364
+ CreateTokenErrorType.Failed.toString(),
365
+ "$type type is not supported yet",
366
+ ),
367
+ )
261
368
  }
262
369
  }
263
370
  }
264
371
 
265
- private fun createTokenFromPii(params: ReadableMap, promise: Promise) {
372
+ private fun createTokenFromPii(
373
+ params: ReadableMap,
374
+ promise: Promise,
375
+ ) {
266
376
  getValOr(params, "personalId", null)?.let {
267
377
  CoroutineScope(Dispatchers.IO).launch {
268
378
  runCatching {
269
- val token = stripe.createPiiToken(it, null, stripeAccountId)
379
+ val token = stripe.createPiiTokenSynchronous(it, null, stripeAccountId)
270
380
  promise.resolve(createResult("token", mapFromToken(token)))
271
381
  }.onFailure {
272
382
  promise.resolve(createError(CreateTokenErrorType.Failed.toString(), it.message))
273
383
  }
274
384
  }
275
385
  } ?: run {
276
- promise.resolve(createError(CreateTokenErrorType.Failed.toString(), "personalId parameter is required"))
386
+ promise.resolve(
387
+ createError(
388
+ CreateTokenErrorType.Failed.toString(),
389
+ "personalId parameter is required",
390
+ ),
391
+ )
277
392
  }
278
393
  }
279
394
 
280
- private fun createTokenFromBankAccount(params: ReadableMap, promise: Promise) {
395
+ private fun createTokenFromBankAccount(
396
+ params: ReadableMap,
397
+ promise: Promise,
398
+ ) {
281
399
  val accountHolderName = getValOr(params, "accountHolderName", null)
282
400
  val accountHolderType = getValOr(params, "accountHolderType", null)
283
401
  val accountNumber = getValOr(params, "accountNumber", null)
@@ -285,50 +403,62 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
285
403
  val currency = getValOr(params, "currency", null)
286
404
  val routingNumber = getValOr(params, "routingNumber", null)
287
405
 
288
- val bankAccountParams = BankAccountTokenParams(
289
- country = country!!,
290
- currency = currency!!,
291
- accountNumber = accountNumber!!,
292
- accountHolderName = accountHolderName,
293
- routingNumber = routingNumber,
294
- accountHolderType = mapToBankAccountType(accountHolderType)
295
- )
406
+ val bankAccountParams =
407
+ BankAccountTokenParams(
408
+ country = country!!,
409
+ currency = currency!!,
410
+ accountNumber = accountNumber!!,
411
+ accountHolderName = accountHolderName,
412
+ routingNumber = routingNumber,
413
+ accountHolderType = mapToBankAccountType(accountHolderType),
414
+ )
296
415
  CoroutineScope(Dispatchers.IO).launch {
297
416
  runCatching {
298
- val token = stripe.createBankAccountToken(bankAccountParams, null, stripeAccountId)
417
+ val token =
418
+ stripe.createBankAccountTokenSynchronous(bankAccountParams, null, stripeAccountId)
299
419
  promise.resolve(createResult("token", mapFromToken(token)))
300
420
  }.onFailure {
301
421
  promise.resolve(createError(CreateTokenErrorType.Failed.toString(), it.message))
302
422
  }
303
423
  }
304
-
305
424
  }
306
425
 
307
- private fun createTokenFromCard(params: ReadableMap, promise: Promise) {
308
- val cardParamsMap = (cardFieldView?.cardParams ?: cardFormView?.cardParams)?.toParamMap()
309
- ?: run {
310
- promise.resolve(createError(CreateTokenErrorType.Failed.toString(), "Card details not complete"))
311
- return
312
- }
426
+ private fun createTokenFromCard(
427
+ params: ReadableMap,
428
+ promise: Promise,
429
+ ) {
430
+ val cardParamsMap =
431
+ (cardFieldView?.cardParams ?: cardFormView?.cardParams)?.toParamMap()
432
+ ?: run {
433
+ promise.resolve(
434
+ createError(
435
+ CreateTokenErrorType.Failed.toString(),
436
+ "Card details not complete",
437
+ ),
438
+ )
439
+ return
440
+ }
313
441
 
314
442
  val cardAddress = cardFieldView?.cardAddress ?: cardFormView?.cardAddress
315
443
  val address = getMapOrNull(params, "address")
316
- val cardParams = CardParams(
317
- number = cardParamsMap["number"] as String,
318
- expMonth = cardParamsMap["exp_month"] as Int,
319
- expYear = cardParamsMap["exp_year"] as Int,
320
- cvc = cardParamsMap["cvc"] as String,
321
- address = mapToAddress(address, cardAddress),
322
- name = getValOr(params, "name", null),
323
- currency = getValOr(params, "currency", null),
324
- )
444
+ val cardParams =
445
+ CardParams(
446
+ number = cardParamsMap["number"] as String,
447
+ expMonth = cardParamsMap["exp_month"] as Int,
448
+ expYear = cardParamsMap["exp_year"] as Int,
449
+ cvc = cardParamsMap["cvc"] as String,
450
+ address = mapToAddress(address, cardAddress),
451
+ name = getValOr(params, "name", null),
452
+ currency = getValOr(params, "currency", null),
453
+ )
325
454
 
326
455
  CoroutineScope(Dispatchers.IO).launch {
327
456
  try {
328
- val token = stripe.createCardToken(
329
- cardParams = cardParams,
330
- stripeAccountId = stripeAccountId
331
- )
457
+ val token =
458
+ stripe.createCardTokenSynchronous(
459
+ cardParams = cardParams,
460
+ stripeAccountId = stripeAccountId,
461
+ )
332
462
  promise.resolve(createResult("token", mapFromToken(token)))
333
463
  } catch (e: Exception) {
334
464
  promise.resolve(createError(CreateTokenErrorType.Failed.toString(), e.message))
@@ -337,46 +467,58 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
337
467
  }
338
468
 
339
469
  @ReactMethod
340
- fun createTokenForCVCUpdate(cvc: String, promise: Promise) {
470
+ fun createTokenForCVCUpdate(
471
+ cvc: String,
472
+ promise: Promise,
473
+ ) {
341
474
  stripe.createCvcUpdateToken(
342
475
  cvc,
343
- callback = object : ApiResultCallback<Token> {
344
- override fun onSuccess(result: Token) {
345
- val tokenId = result.id
346
- val res = WritableNativeMap()
347
- res.putString("tokenId", tokenId)
348
- promise.resolve(res)
349
- }
476
+ callback =
477
+ object : ApiResultCallback<Token> {
478
+ override fun onSuccess(result: Token) {
479
+ val tokenId = result.id
480
+ val res = WritableNativeMap()
481
+ res.putString("tokenId", tokenId)
482
+ promise.resolve(res)
483
+ }
350
484
 
351
- override fun onError(e: Exception) {
352
- promise.resolve(createError("Failed", e))
353
- }
354
- }
485
+ override fun onError(e: Exception) {
486
+ promise.resolve(createError("Failed", e))
487
+ }
488
+ },
355
489
  )
356
490
  }
357
491
 
358
492
  @ReactMethod
359
- fun handleNextAction(paymentIntentClientSecret: String, promise: Promise) {
360
- paymentLauncherFragment = PaymentLauncherFragment.forNextActionPayment(
361
- context = reactApplicationContext,
362
- stripe,
363
- publishableKey,
364
- stripeAccountId,
365
- promise,
366
- paymentIntentClientSecret
367
- )
493
+ fun handleNextAction(
494
+ paymentIntentClientSecret: String,
495
+ promise: Promise,
496
+ ) {
497
+ paymentLauncherFragment =
498
+ PaymentLauncherFragment.forNextActionPayment(
499
+ context = reactApplicationContext,
500
+ stripe,
501
+ publishableKey,
502
+ stripeAccountId,
503
+ promise,
504
+ paymentIntentClientSecret,
505
+ )
368
506
  }
369
507
 
370
508
  @ReactMethod
371
- fun handleNextActionForSetup(setupIntentClientSecret: String, promise: Promise) {
372
- paymentLauncherFragment = PaymentLauncherFragment.forNextActionSetup(
373
- context = reactApplicationContext,
374
- stripe,
375
- publishableKey,
376
- stripeAccountId,
377
- promise,
378
- setupIntentClientSecret
379
- )
509
+ fun handleNextActionForSetup(
510
+ setupIntentClientSecret: String,
511
+ promise: Promise,
512
+ ) {
513
+ paymentLauncherFragment =
514
+ PaymentLauncherFragment.forNextActionSetup(
515
+ context = reactApplicationContext,
516
+ stripe,
517
+ publishableKey,
518
+ stripeAccountId,
519
+ promise,
520
+ setupIntentClientSecret,
521
+ )
380
522
  }
381
523
 
382
524
  // TODO: Uncomment when WeChat is re-enabled in stripe-ios
@@ -399,15 +541,27 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
399
541
  // }
400
542
 
401
543
  @ReactMethod
402
- fun confirmPayment(paymentIntentClientSecret: String, params: ReadableMap?, options: ReadableMap, promise: Promise) {
544
+ fun confirmPayment(
545
+ paymentIntentClientSecret: String,
546
+ params: ReadableMap?,
547
+ options: ReadableMap,
548
+ promise: Promise,
549
+ ) {
403
550
  val paymentMethodData = getMapOrNull(params, "paymentMethodData")
404
- val paymentMethodType = if (params != null)
405
- mapToPaymentMethodType(params.getString("paymentMethodType")) ?: run {
406
- promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), "You must provide paymentMethodType"))
407
- return
551
+ val paymentMethodType =
552
+ if (params != null) {
553
+ mapToPaymentMethodType(params.getString("paymentMethodType")) ?: run {
554
+ promise.resolve(
555
+ createError(
556
+ ConfirmPaymentErrorType.Failed.toString(),
557
+ "You must provide paymentMethodType",
558
+ ),
559
+ )
560
+ return
561
+ }
562
+ } else {
563
+ null // Expect that payment method was attached on the server
408
564
  }
409
- else
410
- null // Expect that payment method was attached on the server
411
565
 
412
566
  // if (paymentMethodType == PaymentMethod.Type.WeChatPay) {
413
567
  // val appId = getValOr(params, "appId") ?: run {
@@ -419,30 +573,41 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
419
573
  // return
420
574
  // }
421
575
 
422
- val factory = PaymentMethodCreateParamsFactory(paymentMethodData, options, cardFieldView, cardFormView)
576
+ val factory =
577
+ PaymentMethodCreateParamsFactory(paymentMethodData, options, cardFieldView, cardFormView)
423
578
 
424
579
  try {
425
- val confirmParams = factory.createParams(paymentIntentClientSecret, paymentMethodType, isPaymentIntent = true) as ConfirmPaymentIntentParams
580
+ val confirmParams =
581
+ factory.createParams(
582
+ paymentIntentClientSecret,
583
+ paymentMethodType,
584
+ isPaymentIntent = true,
585
+ ) as ConfirmPaymentIntentParams
426
586
  urlScheme?.let {
427
587
  confirmParams.returnUrl = mapToReturnURL(urlScheme)
428
588
  }
429
- confirmParams.shipping = mapToShippingDetails(getMapOrNull(paymentMethodData, "shippingDetails"))
430
- paymentLauncherFragment = PaymentLauncherFragment.forPayment(
431
- context = reactApplicationContext,
432
- stripe,
433
- publishableKey,
434
- stripeAccountId,
435
- promise,
436
- paymentIntentClientSecret,
437
- confirmParams
438
- )
589
+ confirmParams.shipping =
590
+ mapToShippingDetails(getMapOrNull(paymentMethodData, "shippingDetails"))
591
+ paymentLauncherFragment =
592
+ PaymentLauncherFragment.forPayment(
593
+ context = reactApplicationContext,
594
+ stripe,
595
+ publishableKey,
596
+ stripeAccountId,
597
+ promise,
598
+ paymentIntentClientSecret,
599
+ confirmParams,
600
+ )
439
601
  } catch (error: PaymentMethodCreateParamsException) {
440
602
  promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
441
603
  }
442
604
  }
443
605
 
444
606
  @ReactMethod
445
- fun retrievePaymentIntent(clientSecret: String, promise: Promise) {
607
+ fun retrievePaymentIntent(
608
+ clientSecret: String,
609
+ promise: Promise,
610
+ ) {
446
611
  CoroutineScope(Dispatchers.IO).launch {
447
612
  val paymentIntent = stripe.retrievePaymentIntentSynchronous(clientSecret)
448
613
  promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(paymentIntent)))
@@ -450,7 +615,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
450
615
  }
451
616
 
452
617
  @ReactMethod
453
- fun retrieveSetupIntent(clientSecret: String, promise: Promise) {
618
+ fun retrieveSetupIntent(
619
+ clientSecret: String,
620
+ promise: Promise,
621
+ ) {
454
622
  CoroutineScope(Dispatchers.IO).launch {
455
623
  val setupIntent = stripe.retrieveSetupIntentSynchronous(clientSecret)
456
624
  promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(setupIntent)))
@@ -458,46 +626,74 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
458
626
  }
459
627
 
460
628
  @ReactMethod
461
- fun confirmSetupIntent(setupIntentClientSecret: String, params: ReadableMap, options: ReadableMap, promise: Promise) {
462
- val paymentMethodType = getValOr(params, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
463
- promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), "You must provide paymentMethodType"))
464
- return
465
- }
629
+ fun confirmSetupIntent(
630
+ setupIntentClientSecret: String,
631
+ params: ReadableMap,
632
+ options: ReadableMap,
633
+ promise: Promise,
634
+ ) {
635
+ val paymentMethodType =
636
+ getValOr(params, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
637
+ promise.resolve(
638
+ createError(
639
+ ConfirmPaymentErrorType.Failed.toString(),
640
+ "You must provide paymentMethodType",
641
+ ),
642
+ )
643
+ return
644
+ }
466
645
 
467
- val factory = PaymentMethodCreateParamsFactory(getMapOrNull(params, "paymentMethodData"), options, cardFieldView, cardFormView)
646
+ val factory =
647
+ PaymentMethodCreateParamsFactory(
648
+ getMapOrNull(params, "paymentMethodData"),
649
+ options,
650
+ cardFieldView,
651
+ cardFormView,
652
+ )
468
653
 
469
654
  try {
470
- val confirmParams = factory.createParams(setupIntentClientSecret, paymentMethodType, isPaymentIntent = false) as ConfirmSetupIntentParams
655
+ val confirmParams =
656
+ factory.createParams(
657
+ setupIntentClientSecret,
658
+ paymentMethodType,
659
+ isPaymentIntent = false,
660
+ ) as ConfirmSetupIntentParams
471
661
  urlScheme?.let {
472
662
  confirmParams.returnUrl = mapToReturnURL(urlScheme)
473
663
  }
474
- paymentLauncherFragment = PaymentLauncherFragment.forSetup(
475
- context = reactApplicationContext,
476
- stripe,
477
- publishableKey,
478
- stripeAccountId,
479
- promise,
480
- setupIntentClientSecret,
481
- confirmParams
482
- )
664
+ paymentLauncherFragment =
665
+ PaymentLauncherFragment.forSetup(
666
+ context = reactApplicationContext,
667
+ stripe,
668
+ publishableKey,
669
+ stripeAccountId,
670
+ promise,
671
+ setupIntentClientSecret,
672
+ confirmParams,
673
+ )
483
674
  } catch (error: PaymentMethodCreateParamsException) {
484
675
  promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
485
676
  }
486
677
  }
487
678
 
488
679
  @ReactMethod
489
- fun isPlatformPaySupported(params: ReadableMap?, promise: Promise) {
680
+ fun isPlatformPaySupported(
681
+ params: ReadableMap?,
682
+ promise: Promise,
683
+ ) {
490
684
  val googlePayParams = params?.getMap("googlePay")
491
- val fragment = GooglePayPaymentMethodLauncherFragment(
492
- reactApplicationContext,
493
- getBooleanOrFalse(googlePayParams, "testEnv"),
494
- getBooleanOrFalse(googlePayParams, "existingPaymentMethodRequired"),
495
- promise
496
- )
685
+ val fragment =
686
+ GooglePayPaymentMethodLauncherFragment(
687
+ reactApplicationContext,
688
+ getBooleanOrFalse(googlePayParams, "testEnv"),
689
+ getBooleanOrFalse(googlePayParams, "existingPaymentMethodRequired"),
690
+ promise,
691
+ )
497
692
 
498
693
  getCurrentActivityOrResolveWithError(promise)?.let {
499
694
  try {
500
- it.supportFragmentManager.beginTransaction()
695
+ it.supportFragmentManager
696
+ .beginTransaction()
501
697
  .add(fragment, GooglePayPaymentMethodLauncherFragment.TAG)
502
698
  .commit()
503
699
  } catch (error: IllegalStateException) {
@@ -507,23 +703,34 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
507
703
  }
508
704
 
509
705
  @ReactMethod
510
- fun confirmPlatformPay(clientSecret: String, params: ReadableMap, isPaymentIntent: Boolean, promise: Promise) {
706
+ fun confirmPlatformPay(
707
+ clientSecret: String,
708
+ params: ReadableMap,
709
+ isPaymentIntent: Boolean,
710
+ promise: Promise,
711
+ ) {
511
712
  if (!::stripe.isInitialized) {
512
713
  promise.resolve(createMissingInitError())
513
714
  return
514
715
  }
515
716
 
516
- val googlePayParams: ReadableMap = params.getMap("googlePay") ?: run {
517
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), "You must provide the `googlePay` parameter."))
518
- return
519
- }
717
+ val googlePayParams: ReadableMap =
718
+ params.getMap("googlePay") ?: run {
719
+ promise.resolve(
720
+ createError(
721
+ GooglePayErrorType.Failed.toString(),
722
+ "You must provide the `googlePay` parameter.",
723
+ ),
724
+ )
725
+ return
726
+ }
520
727
 
521
728
  GooglePayLauncherFragment().also {
522
729
  it.presentGooglePaySheet(
523
730
  clientSecret,
524
731
  if (isPaymentIntent) GooglePayLauncherFragment.Mode.ForPayment else GooglePayLauncherFragment.Mode.ForSetup,
525
732
  googlePayParams,
526
- reactApplicationContext
733
+ reactApplicationContext,
527
734
  ) { launcherResult, errorMap ->
528
735
  if (errorMap != null) {
529
736
  promise.resolve(errorMap)
@@ -531,30 +738,59 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
531
738
  when (launcherResult) {
532
739
  GooglePayLauncher.Result.Completed -> {
533
740
  if (isPaymentIntent) {
534
- stripe.retrievePaymentIntent(clientSecret, stripeAccountId, expand = listOf("payment_method"), object : ApiResultCallback<PaymentIntent> {
535
- override fun onError(e: Exception) {
536
- promise.resolve(createResult("paymentIntent", WritableNativeMap()))
537
- }
538
- override fun onSuccess(result: PaymentIntent) {
539
- promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(result)))
540
- }
541
- })
741
+ stripe.retrievePaymentIntent(
742
+ clientSecret,
743
+ stripeAccountId,
744
+ expand = listOf("payment_method"),
745
+ object : ApiResultCallback<PaymentIntent> {
746
+ override fun onError(e: Exception) {
747
+ promise.resolve(createResult("paymentIntent", WritableNativeMap()))
748
+ }
749
+
750
+ override fun onSuccess(result: PaymentIntent) {
751
+ promise.resolve(
752
+ createResult(
753
+ "paymentIntent",
754
+ mapFromPaymentIntentResult(result),
755
+ ),
756
+ )
757
+ }
758
+ },
759
+ )
542
760
  } else {
543
- stripe.retrieveSetupIntent(clientSecret, stripeAccountId, expand = listOf("payment_method"), object : ApiResultCallback<SetupIntent> {
544
- override fun onError(e: Exception) {
545
- promise.resolve(createResult("setupIntent", WritableNativeMap()))
546
- }
547
- override fun onSuccess(result: SetupIntent) {
548
- promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
549
- }
550
- })
761
+ stripe.retrieveSetupIntent(
762
+ clientSecret,
763
+ stripeAccountId,
764
+ expand = listOf("payment_method"),
765
+ object : ApiResultCallback<SetupIntent> {
766
+ override fun onError(e: Exception) {
767
+ promise.resolve(createResult("setupIntent", WritableNativeMap()))
768
+ }
769
+
770
+ override fun onSuccess(result: SetupIntent) {
771
+ promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
772
+ }
773
+ },
774
+ )
551
775
  }
552
776
  }
777
+
553
778
  GooglePayLauncher.Result.Canceled -> {
554
- promise.resolve(createError(GooglePayErrorType.Canceled.toString(), "Google Pay has been canceled"))
779
+ promise.resolve(
780
+ createError(
781
+ GooglePayErrorType.Canceled.toString(),
782
+ "Google Pay has been canceled",
783
+ ),
784
+ )
555
785
  }
786
+
556
787
  is GooglePayLauncher.Result.Failed -> {
557
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), launcherResult.error))
788
+ promise.resolve(
789
+ createError(
790
+ GooglePayErrorType.Failed.toString(),
791
+ launcherResult.error,
792
+ ),
793
+ )
558
794
  }
559
795
  }
560
796
  }
@@ -563,73 +799,108 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
563
799
  }
564
800
 
565
801
  @ReactMethod
566
- fun createPlatformPayPaymentMethod(params: ReadableMap, usesDeprecatedTokenFlow: Boolean, promise: Promise) {
567
- val googlePayParams: ReadableMap = params.getMap("googlePay") ?: run {
568
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), "You must provide the `googlePay` parameter."))
569
- return
570
- }
802
+ fun createPlatformPayPaymentMethod(
803
+ params: ReadableMap,
804
+ usesDeprecatedTokenFlow: Boolean,
805
+ promise: Promise,
806
+ ) {
807
+ val googlePayParams: ReadableMap =
808
+ params.getMap("googlePay") ?: run {
809
+ promise.resolve(
810
+ createError(
811
+ GooglePayErrorType.Failed.toString(),
812
+ "You must provide the `googlePay` parameter.",
813
+ ),
814
+ )
815
+ return
816
+ }
571
817
  platformPayUsesDeprecatedTokenFlow = usesDeprecatedTokenFlow
572
818
  createPlatformPayPaymentMethodPromise = promise
573
819
  getCurrentActivityOrResolveWithError(promise)?.let {
574
- val request = GooglePayRequestHelper.createPaymentRequest(
575
- it,
576
- GooglePayJsonFactory(reactApplicationContext),
577
- googlePayParams
578
- )
820
+ val request =
821
+ GooglePayRequestHelper.createPaymentRequest(
822
+ it,
823
+ GooglePayJsonFactory(reactApplicationContext),
824
+ googlePayParams,
825
+ )
579
826
  GooglePayRequestHelper.createPaymentMethod(request, it)
580
827
  }
581
828
  }
582
829
 
583
830
  @ReactMethod
584
- fun canAddCardToWallet(params: ReadableMap, promise: Promise) {
585
- val last4 = getValOr(params, "cardLastFour", null) ?: run {
586
- promise.resolve(createError("Failed", "You must provide cardLastFour"))
587
- return
588
- }
831
+ fun canAddCardToWallet(
832
+ params: ReadableMap,
833
+ promise: Promise,
834
+ ) {
835
+ val last4 =
836
+ getValOr(params, "cardLastFour", null) ?: run {
837
+ promise.resolve(createError("Failed", "You must provide cardLastFour"))
838
+ return
839
+ }
589
840
 
590
- if (params.getBooleanOr("supportsTapToPay", true) && !PushProvisioningProxy.isNFCEnabled(reactApplicationContext)) {
841
+ if (params.getBooleanOr("supportsTapToPay", true) &&
842
+ !PushProvisioningProxy.isNFCEnabled(
843
+ reactApplicationContext,
844
+ )
845
+ ) {
591
846
  promise.resolve(createCanAddCardResult(false, "UNSUPPORTED_DEVICE"))
592
847
  return
593
848
  }
594
849
 
595
850
  getCurrentActivityOrResolveWithError(promise)?.let {
596
851
  PushProvisioningProxy.isCardInWallet(it, last4) { isCardInWallet, token, error ->
597
- val result = error?.let {
598
- createCanAddCardResult(false, "MISSING_CONFIGURATION", null)
599
- } ?: run {
600
- val status = if (isCardInWallet) "CARD_ALREADY_EXISTS" else null
601
- createCanAddCardResult(!isCardInWallet, status, token)
602
- }
852
+ val result =
853
+ error?.let {
854
+ createCanAddCardResult(false, "MISSING_CONFIGURATION", null)
855
+ } ?: run {
856
+ val status = if (isCardInWallet) "CARD_ALREADY_EXISTS" else null
857
+ createCanAddCardResult(!isCardInWallet, status, token)
858
+ }
603
859
  promise.resolve(result)
604
860
  }
605
861
  }
606
862
  }
607
863
 
608
864
  @ReactMethod
609
- fun isCardInWallet(params: ReadableMap, promise: Promise) {
610
- val last4 = getValOr(params, "cardLastFour", null) ?: run {
611
- promise.resolve(createError("Failed", "You must provide cardLastFour"))
612
- return
613
- }
865
+ fun isCardInWallet(
866
+ params: ReadableMap,
867
+ promise: Promise,
868
+ ) {
869
+ val last4 =
870
+ getValOr(params, "cardLastFour", null) ?: run {
871
+ promise.resolve(createError("Failed", "You must provide cardLastFour"))
872
+ return
873
+ }
614
874
  getCurrentActivityOrResolveWithError(promise)?.let {
615
875
  PushProvisioningProxy.isCardInWallet(it, last4) { isCardInWallet, token, error ->
616
- val result: WritableMap = error ?: run {
617
- val map = WritableNativeMap()
618
- map.putBoolean("isInWallet", isCardInWallet)
619
- map.putMap("token", token)
620
- map
621
- }
876
+ val result: WritableMap =
877
+ error ?: run {
878
+ val map = WritableNativeMap()
879
+ map.putBoolean("isInWallet", isCardInWallet)
880
+ map.putMap("token", token)
881
+ map
882
+ }
622
883
  promise.resolve(result)
623
884
  }
624
885
  }
625
886
  }
626
887
 
627
888
  @ReactMethod
628
- fun collectBankAccount(isPaymentIntent: Boolean, clientSecret: String, params: ReadableMap, promise: Promise) {
889
+ fun collectBankAccount(
890
+ isPaymentIntent: Boolean,
891
+ clientSecret: String,
892
+ params: ReadableMap,
893
+ promise: Promise,
894
+ ) {
629
895
  val paymentMethodData = getMapOrNull(params, "paymentMethodData")
630
896
  val paymentMethodType = mapToPaymentMethodType(getValOr(params, "paymentMethodType", null))
631
897
  if (paymentMethodType != PaymentMethod.Type.USBankAccount) {
632
- promise.resolve(createError(ErrorType.Failed.toString(), "collectBankAccount currently only accepts the USBankAccount payment method type."))
898
+ promise.resolve(
899
+ createError(
900
+ ErrorType.Failed.toString(),
901
+ "collectBankAccount currently only accepts the USBankAccount payment method type.",
902
+ ),
903
+ )
633
904
  return
634
905
  }
635
906
 
@@ -637,27 +908,35 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
637
908
 
638
909
  val name = billingDetails?.getString("name")
639
910
  if (name.isNullOrEmpty()) {
640
- promise.resolve(createError(ErrorType.Failed.toString(), "You must provide a name when collecting US bank account details."))
911
+ promise.resolve(
912
+ createError(
913
+ ErrorType.Failed.toString(),
914
+ "You must provide a name when collecting US bank account details.",
915
+ ),
916
+ )
641
917
  return
642
918
  }
643
919
 
644
- val collectParams = CollectBankAccountConfiguration.USBankAccount(
645
- name,
646
- billingDetails.getString("email")
647
- )
920
+ val collectParams =
921
+ CollectBankAccountConfiguration.USBankAccount(
922
+ name,
923
+ billingDetails.getString("email"),
924
+ )
648
925
 
649
- collectBankAccountLauncherFragment = CollectBankAccountLauncherFragment(
650
- reactApplicationContext,
651
- publishableKey,
652
- stripeAccountId,
653
- clientSecret,
654
- isPaymentIntent,
655
- collectParams,
656
- promise
657
- )
926
+ collectBankAccountLauncherFragment =
927
+ CollectBankAccountLauncherFragment(
928
+ reactApplicationContext,
929
+ publishableKey,
930
+ stripeAccountId,
931
+ clientSecret,
932
+ isPaymentIntent,
933
+ collectParams,
934
+ promise,
935
+ )
658
936
  getCurrentActivityOrResolveWithError(promise)?.let {
659
937
  try {
660
- it.supportFragmentManager.beginTransaction()
938
+ it.supportFragmentManager
939
+ .beginTransaction()
661
940
  .add(collectBankAccountLauncherFragment!!, "collect_bank_account_launcher_fragment")
662
941
  .commit()
663
942
  } catch (error: IllegalStateException) {
@@ -667,38 +946,55 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
667
946
  }
668
947
 
669
948
  @ReactMethod
670
- fun verifyMicrodeposits(isPaymentIntent: Boolean, clientSecret: String, params: ReadableMap, promise: Promise) {
949
+ fun verifyMicrodeposits(
950
+ isPaymentIntent: Boolean,
951
+ clientSecret: String,
952
+ params: ReadableMap,
953
+ promise: Promise,
954
+ ) {
671
955
  val amounts = params.getArray("amounts")
672
956
  val descriptorCode = params.getString("descriptorCode")
673
957
 
674
958
  if ((amounts != null && descriptorCode != null) || (amounts == null && descriptorCode == null)) {
675
- promise.resolve(createError(ErrorType.Failed.toString(), "You must provide either amounts OR descriptorCode, not both."))
959
+ promise.resolve(
960
+ createError(
961
+ ErrorType.Failed.toString(),
962
+ "You must provide either amounts OR descriptorCode, not both.",
963
+ ),
964
+ )
676
965
  return
677
966
  }
678
967
 
679
- val paymentCallback = object : ApiResultCallback<PaymentIntent> {
680
- override fun onError(e: Exception) {
681
- promise.resolve(createError(ErrorType.Failed.toString(), e))
682
- }
968
+ val paymentCallback =
969
+ object : ApiResultCallback<PaymentIntent> {
970
+ override fun onError(e: Exception) {
971
+ promise.resolve(createError(ErrorType.Failed.toString(), e))
972
+ }
683
973
 
684
- override fun onSuccess(result: PaymentIntent) {
685
- promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(result)))
974
+ override fun onSuccess(result: PaymentIntent) {
975
+ promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(result)))
976
+ }
686
977
  }
687
- }
688
978
 
689
- val setupCallback = object : ApiResultCallback<SetupIntent> {
690
- override fun onError(e: Exception) {
691
- promise.resolve(createError(ErrorType.Failed.toString(), e))
692
- }
979
+ val setupCallback =
980
+ object : ApiResultCallback<SetupIntent> {
981
+ override fun onError(e: Exception) {
982
+ promise.resolve(createError(ErrorType.Failed.toString(), e))
983
+ }
693
984
 
694
- override fun onSuccess(result: SetupIntent) {
695
- promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
985
+ override fun onSuccess(result: SetupIntent) {
986
+ promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
987
+ }
696
988
  }
697
- }
698
989
 
699
990
  amounts?.let {
700
991
  if (it.size() != 2) {
701
- promise.resolve(createError(ErrorType.Failed.toString(), "Expected 2 integers in the amounts array, but received ${it.size()}"))
992
+ promise.resolve(
993
+ createError(
994
+ ErrorType.Failed.toString(),
995
+ "Expected 2 integers in the amounts array, but received ${it.size()}",
996
+ ),
997
+ )
702
998
  return
703
999
  }
704
1000
 
@@ -707,14 +1003,14 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
707
1003
  clientSecret,
708
1004
  it.getInt(0),
709
1005
  it.getInt(1),
710
- paymentCallback
1006
+ paymentCallback,
711
1007
  )
712
1008
  } else {
713
1009
  stripe.verifySetupIntentWithMicrodeposits(
714
1010
  clientSecret,
715
1011
  it.getInt(0),
716
1012
  it.getInt(1),
717
- setupCallback
1013
+ setupCallback,
718
1014
  )
719
1015
  }
720
1016
  } ?: descriptorCode?.let {
@@ -722,42 +1018,68 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
722
1018
  stripe.verifyPaymentIntentWithMicrodeposits(
723
1019
  clientSecret,
724
1020
  it,
725
- paymentCallback
1021
+ paymentCallback,
726
1022
  )
727
1023
  } else {
728
1024
  stripe.verifySetupIntentWithMicrodeposits(
729
1025
  clientSecret,
730
1026
  it,
731
- setupCallback
1027
+ setupCallback,
732
1028
  )
733
1029
  }
734
1030
  }
735
1031
  }
736
1032
 
737
1033
  @ReactMethod
738
- fun collectBankAccountToken(clientSecret: String, promise: Promise) {
1034
+ fun collectBankAccountToken(
1035
+ clientSecret: String,
1036
+ params: ReadableMap,
1037
+ promise: Promise,
1038
+ ) {
739
1039
  if (!::stripe.isInitialized) {
740
1040
  promise.resolve(createMissingInitError())
741
1041
  return
742
1042
  }
743
1043
  FinancialConnectionsSheetFragment().also {
744
- it.presentFinancialConnectionsSheet(clientSecret, FinancialConnectionsSheetFragment.Mode.ForToken, publishableKey, stripeAccountId, promise, reactApplicationContext)
1044
+ it.presentFinancialConnectionsSheet(
1045
+ clientSecret,
1046
+ FinancialConnectionsSheetFragment.Mode.ForToken,
1047
+ publishableKey,
1048
+ stripeAccountId,
1049
+ promise,
1050
+ reactApplicationContext,
1051
+ )
745
1052
  }
746
1053
  }
747
1054
 
748
1055
  @ReactMethod
749
- fun collectFinancialConnectionsAccounts(clientSecret: String, promise: Promise) {
1056
+ fun collectFinancialConnectionsAccounts(
1057
+ clientSecret: String,
1058
+ params: ReadableMap,
1059
+ promise: Promise,
1060
+ ) {
750
1061
  if (!::stripe.isInitialized) {
751
1062
  promise.resolve(createMissingInitError())
752
1063
  return
753
1064
  }
754
1065
  FinancialConnectionsSheetFragment().also {
755
- it.presentFinancialConnectionsSheet(clientSecret, FinancialConnectionsSheetFragment.Mode.ForSession, publishableKey, stripeAccountId, promise, reactApplicationContext)
1066
+ it.presentFinancialConnectionsSheet(
1067
+ clientSecret,
1068
+ FinancialConnectionsSheetFragment.Mode.ForSession,
1069
+ publishableKey,
1070
+ stripeAccountId,
1071
+ promise,
1072
+ reactApplicationContext,
1073
+ )
756
1074
  }
757
1075
  }
758
1076
 
759
1077
  @ReactMethod
760
- fun initCustomerSheet(params: ReadableMap, customerAdapterOverrides: ReadableMap, promise: Promise) {
1078
+ fun initCustomerSheet(
1079
+ params: ReadableMap,
1080
+ customerAdapterOverrides: ReadableMap,
1081
+ promise: Promise,
1082
+ ) {
761
1083
  if (!::stripe.isInitialized) {
762
1084
  promise.resolve(createMissingInitError())
763
1085
  return
@@ -765,15 +1087,17 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
765
1087
 
766
1088
  getCurrentActivityOrResolveWithError(promise)?.let { activity ->
767
1089
  customerSheetFragment?.removeFragment(reactApplicationContext)
768
- customerSheetFragment = CustomerSheetFragment().also {
769
- it.context = reactApplicationContext
770
- it.initPromise = promise
771
- val bundle = toBundleObject(params)
772
- bundle.putBundle("customerAdapter", toBundleObject(customerAdapterOverrides))
773
- it.arguments = bundle
774
- }
1090
+ customerSheetFragment =
1091
+ CustomerSheetFragment().also {
1092
+ it.context = reactApplicationContext
1093
+ it.initPromise = promise
1094
+ val bundle = toBundleObject(params)
1095
+ bundle.putBundle("customerAdapter", toBundleObject(customerAdapterOverrides))
1096
+ it.arguments = bundle
1097
+ }
775
1098
  try {
776
- activity.supportFragmentManager.beginTransaction()
1099
+ activity.supportFragmentManager
1100
+ .beginTransaction()
777
1101
  .add(customerSheetFragment!!, CustomerSheetFragment.TAG)
778
1102
  .commit()
779
1103
  } catch (error: IllegalStateException) {
@@ -783,7 +1107,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
783
1107
  }
784
1108
 
785
1109
  @ReactMethod
786
- fun presentCustomerSheet(params: ReadableMap, promise: Promise) {
1110
+ fun presentCustomerSheet(
1111
+ params: ReadableMap,
1112
+ promise: Promise,
1113
+ ) {
787
1114
  var timeout: Long? = null
788
1115
  if (params.hasKey("timeout")) {
789
1116
  timeout = params.getInt("timeout").toLong()
@@ -801,14 +1128,20 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
801
1128
  }
802
1129
 
803
1130
  @ReactMethod
804
- fun customerAdapterFetchPaymentMethodsCallback(paymentMethodJsonObjects: ReadableArray, promise: Promise) {
1131
+ fun customerAdapterFetchPaymentMethodsCallback(
1132
+ paymentMethodJsonObjects: ReadableArray,
1133
+ promise: Promise,
1134
+ ) {
805
1135
  customerSheetFragment?.let { fragment ->
806
1136
  val paymentMethods = mutableListOf<PaymentMethod>()
807
1137
  for (paymentMethodJson in paymentMethodJsonObjects.toArrayList()) {
808
1138
  PaymentMethod.fromJson(JSONObject((paymentMethodJson as HashMap<*, *>)))?.let {
809
1139
  paymentMethods.add(it)
810
1140
  } ?: run {
811
- Log.e("StripeReactNative", "There was an error converting Payment Method JSON to a Stripe Payment Method")
1141
+ Log.e(
1142
+ "StripeReactNative",
1143
+ "There was an error converting Payment Method JSON to a Stripe Payment Method",
1144
+ )
812
1145
  }
813
1146
  }
814
1147
  fragment.customerAdapter?.fetchPaymentMethodsCallback?.complete(paymentMethods)
@@ -819,11 +1152,18 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
819
1152
  }
820
1153
 
821
1154
  @ReactMethod
822
- fun customerAdapterAttachPaymentMethodCallback(paymentMethodJson: ReadableMap, promise: Promise) {
1155
+ fun customerAdapterAttachPaymentMethodCallback(
1156
+ paymentMethodJson: ReadableMap,
1157
+ promise: Promise,
1158
+ ) {
823
1159
  customerSheetFragment?.let {
824
- val paymentMethod = PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
1160
+ val paymentMethod =
1161
+ PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
825
1162
  if (paymentMethod == null) {
826
- Log.e("StripeReactNative", "There was an error converting Payment Method JSON to a Stripe Payment Method")
1163
+ Log.e(
1164
+ "StripeReactNative",
1165
+ "There was an error converting Payment Method JSON to a Stripe Payment Method",
1166
+ )
827
1167
  return
828
1168
  }
829
1169
  it.customerAdapter?.attachPaymentMethodCallback?.complete(paymentMethod)
@@ -834,11 +1174,18 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
834
1174
  }
835
1175
 
836
1176
  @ReactMethod
837
- fun customerAdapterDetachPaymentMethodCallback(paymentMethodJson: ReadableMap, promise: Promise) {
1177
+ fun customerAdapterDetachPaymentMethodCallback(
1178
+ paymentMethodJson: ReadableMap,
1179
+ promise: Promise,
1180
+ ) {
838
1181
  customerSheetFragment?.let {
839
- val paymentMethod = PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
1182
+ val paymentMethod =
1183
+ PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
840
1184
  if (paymentMethod == null) {
841
- Log.e("StripeReactNative", "There was an error converting Payment Method JSON to a Stripe Payment Method")
1185
+ Log.e(
1186
+ "StripeReactNative",
1187
+ "There was an error converting Payment Method JSON to a Stripe Payment Method",
1188
+ )
842
1189
  return
843
1190
  }
844
1191
  it.customerAdapter?.detachPaymentMethodCallback?.complete(paymentMethod)
@@ -859,7 +1206,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
859
1206
  }
860
1207
 
861
1208
  @ReactMethod
862
- fun customerAdapterFetchSelectedPaymentOptionCallback(paymentOption: String?, promise: Promise) {
1209
+ fun customerAdapterFetchSelectedPaymentOptionCallback(
1210
+ paymentOption: String?,
1211
+ promise: Promise,
1212
+ ) {
863
1213
  customerSheetFragment?.let {
864
1214
  it.customerAdapter?.fetchSelectedPaymentOptionCallback?.complete(paymentOption)
865
1215
  } ?: run {
@@ -869,7 +1219,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
869
1219
  }
870
1220
 
871
1221
  @ReactMethod
872
- fun customerAdapterSetupIntentClientSecretForCustomerAttachCallback(clientSecret: String, promise: Promise) {
1222
+ fun customerAdapterSetupIntentClientSecretForCustomerAttachCallback(
1223
+ clientSecret: String,
1224
+ promise: Promise,
1225
+ ) {
873
1226
  customerSheetFragment?.let {
874
1227
  it.customerAdapter?.setupIntentClientSecretForCustomerAttachCallback?.complete(clientSecret)
875
1228
  } ?: run {
@@ -891,7 +1244,11 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
891
1244
  }
892
1245
  }
893
1246
 
894
- internal fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap) {
1247
+ internal fun sendEvent(
1248
+ reactContext: ReactContext,
1249
+ eventName: String,
1250
+ params: WritableMap,
1251
+ ) {
895
1252
  reactContext
896
1253
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
897
1254
  .emit(eventName, params)