@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
@@ -9,18 +9,26 @@ import androidx.fragment.app.Fragment
9
9
  import androidx.fragment.app.FragmentActivity
10
10
  import com.facebook.react.bridge.Promise
11
11
  import com.facebook.react.bridge.ReactApplicationContext
12
- import com.reactnativestripesdk.utils.*
12
+ import com.reactnativestripesdk.utils.ConfirmPaymentErrorType
13
+ import com.reactnativestripesdk.utils.ConfirmSetupIntentErrorType
14
+ import com.reactnativestripesdk.utils.ErrorType
13
15
  import com.reactnativestripesdk.utils.createError
14
16
  import com.reactnativestripesdk.utils.createMissingActivityError
17
+ import com.reactnativestripesdk.utils.createResult
18
+ import com.reactnativestripesdk.utils.mapFromPaymentIntentResult
19
+ import com.reactnativestripesdk.utils.mapFromSetupIntentResult
20
+ import com.reactnativestripesdk.utils.removeFragment
15
21
  import com.stripe.android.ApiResultCallback
16
22
  import com.stripe.android.Stripe
17
- import com.stripe.android.model.*
23
+ import com.stripe.android.model.ConfirmPaymentIntentParams
24
+ import com.stripe.android.model.ConfirmSetupIntentParams
25
+ import com.stripe.android.model.PaymentIntent
26
+ import com.stripe.android.model.SetupIntent
27
+ import com.stripe.android.model.StripeIntent
18
28
  import com.stripe.android.payments.paymentlauncher.PaymentLauncher
19
29
  import com.stripe.android.payments.paymentlauncher.PaymentResult
20
30
 
21
- /**
22
- * Instances of this class should only be initialized with the companion's helper methods.
23
- */
31
+ /** Instances of this class should only be initialized with the companion's helper methods. */
24
32
  class PaymentLauncherFragment(
25
33
  private val context: ReactApplicationContext,
26
34
  private val stripe: Stripe,
@@ -41,113 +49,123 @@ class PaymentLauncherFragment(
41
49
  private lateinit var paymentLauncher: PaymentLauncher
42
50
 
43
51
  companion object {
44
- /**
45
- * Helper-constructor used for confirming payment intents
46
- */
47
- fun forPayment(context: ReactApplicationContext,
48
- stripe: Stripe,
49
- publishableKey: String,
50
- stripeAccountId: String?,
51
- promise: Promise,
52
- paymentIntentClientSecret: String,
53
- confirmPaymentParams: ConfirmPaymentIntentParams): PaymentLauncherFragment {
54
- val paymentLauncherFragment = PaymentLauncherFragment(
55
- context,
56
- stripe,
57
- publishableKey,
58
- stripeAccountId,
59
- promise,
60
- paymentIntentClientSecret = paymentIntentClientSecret,
61
- confirmPaymentParams = confirmPaymentParams
62
- )
52
+ /** Helper-constructor used for confirming payment intents */
53
+ fun forPayment(
54
+ context: ReactApplicationContext,
55
+ stripe: Stripe,
56
+ publishableKey: String,
57
+ stripeAccountId: String?,
58
+ promise: Promise,
59
+ paymentIntentClientSecret: String,
60
+ confirmPaymentParams: ConfirmPaymentIntentParams,
61
+ ): PaymentLauncherFragment {
62
+ val paymentLauncherFragment =
63
+ PaymentLauncherFragment(
64
+ context,
65
+ stripe,
66
+ publishableKey,
67
+ stripeAccountId,
68
+ promise,
69
+ paymentIntentClientSecret = paymentIntentClientSecret,
70
+ confirmPaymentParams = confirmPaymentParams,
71
+ )
63
72
  addFragment(paymentLauncherFragment, context, promise)
64
73
  return paymentLauncherFragment
65
74
  }
66
75
 
67
- /**
68
- * Helper-constructor used for confirming setup intents
69
- */
70
- fun forSetup(context: ReactApplicationContext,
71
- stripe: Stripe,
72
- publishableKey: String,
73
- stripeAccountId: String?,
74
- promise: Promise,
75
- setupIntentClientSecret: String,
76
- confirmSetupParams: ConfirmSetupIntentParams): PaymentLauncherFragment {
77
- val paymentLauncherFragment = PaymentLauncherFragment(
78
- context,
79
- stripe,
80
- publishableKey,
81
- stripeAccountId,
82
- promise,
83
- setupIntentClientSecret = setupIntentClientSecret,
84
- confirmSetupParams = confirmSetupParams
85
- )
76
+ /** Helper-constructor used for confirming setup intents */
77
+ fun forSetup(
78
+ context: ReactApplicationContext,
79
+ stripe: Stripe,
80
+ publishableKey: String,
81
+ stripeAccountId: String?,
82
+ promise: Promise,
83
+ setupIntentClientSecret: String,
84
+ confirmSetupParams: ConfirmSetupIntentParams,
85
+ ): PaymentLauncherFragment {
86
+ val paymentLauncherFragment =
87
+ PaymentLauncherFragment(
88
+ context,
89
+ stripe,
90
+ publishableKey,
91
+ stripeAccountId,
92
+ promise,
93
+ setupIntentClientSecret = setupIntentClientSecret,
94
+ confirmSetupParams = confirmSetupParams,
95
+ )
86
96
  addFragment(paymentLauncherFragment, context, promise)
87
97
  return paymentLauncherFragment
88
98
  }
89
99
 
90
- /**
91
- * Helper-constructor used for handling the next action on a payment intent
92
- */
93
- fun forNextActionPayment(context: ReactApplicationContext,
94
- stripe: Stripe,
95
- publishableKey: String,
96
- stripeAccountId: String?,
97
- promise: Promise,
98
- handleNextActionPaymentIntentClientSecret: String): PaymentLauncherFragment {
99
- val paymentLauncherFragment = PaymentLauncherFragment(
100
- context,
101
- stripe,
102
- publishableKey,
103
- stripeAccountId,
104
- promise,
105
- handleNextActionPaymentIntentClientSecret = handleNextActionPaymentIntentClientSecret,
106
- )
100
+ /** Helper-constructor used for handling the next action on a payment intent */
101
+ fun forNextActionPayment(
102
+ context: ReactApplicationContext,
103
+ stripe: Stripe,
104
+ publishableKey: String,
105
+ stripeAccountId: String?,
106
+ promise: Promise,
107
+ handleNextActionPaymentIntentClientSecret: String,
108
+ ): PaymentLauncherFragment {
109
+ val paymentLauncherFragment =
110
+ PaymentLauncherFragment(
111
+ context,
112
+ stripe,
113
+ publishableKey,
114
+ stripeAccountId,
115
+ promise,
116
+ handleNextActionPaymentIntentClientSecret = handleNextActionPaymentIntentClientSecret,
117
+ )
107
118
  addFragment(paymentLauncherFragment, context, promise)
108
119
  return paymentLauncherFragment
109
120
  }
110
121
 
111
- /**
112
- * Helper-constructor used for handling the next action on a setup intent
113
- */
114
- fun forNextActionSetup(context: ReactApplicationContext,
115
- stripe: Stripe,
116
- publishableKey: String,
117
- stripeAccountId: String?,
118
- promise: Promise,
119
- handleNextActionSetupIntentClientSecret: String): PaymentLauncherFragment {
120
- val paymentLauncherFragment = PaymentLauncherFragment(
121
- context,
122
- stripe,
123
- publishableKey,
124
- stripeAccountId,
125
- promise,
126
- handleNextActionSetupIntentClientSecret = handleNextActionSetupIntentClientSecret,
127
- )
122
+ /** Helper-constructor used for handling the next action on a setup intent */
123
+ fun forNextActionSetup(
124
+ context: ReactApplicationContext,
125
+ stripe: Stripe,
126
+ publishableKey: String,
127
+ stripeAccountId: String?,
128
+ promise: Promise,
129
+ handleNextActionSetupIntentClientSecret: String,
130
+ ): PaymentLauncherFragment {
131
+ val paymentLauncherFragment =
132
+ PaymentLauncherFragment(
133
+ context,
134
+ stripe,
135
+ publishableKey,
136
+ stripeAccountId,
137
+ promise,
138
+ handleNextActionSetupIntentClientSecret = handleNextActionSetupIntentClientSecret,
139
+ )
128
140
  addFragment(paymentLauncherFragment, context, promise)
129
141
  return paymentLauncherFragment
130
142
  }
131
143
 
132
- private fun addFragment(fragment: PaymentLauncherFragment, context: ReactApplicationContext, promise: Promise) {
144
+ private fun addFragment(
145
+ fragment: PaymentLauncherFragment,
146
+ context: ReactApplicationContext,
147
+ promise: Promise,
148
+ ) {
133
149
  (context.currentActivity as? FragmentActivity)?.let {
134
150
  try {
135
- it.supportFragmentManager.beginTransaction()
151
+ it.supportFragmentManager
152
+ .beginTransaction()
136
153
  .add(fragment, TAG)
137
154
  .commit()
138
155
  } catch (error: IllegalStateException) {
139
156
  promise.resolve(createError(ErrorType.Failed.toString(), error.message))
140
157
  }
141
- } ?: run {
142
- promise.resolve(createMissingActivityError())
143
- }
158
+ } ?: run { promise.resolve(createMissingActivityError()) }
144
159
  }
145
160
 
146
161
  internal const val TAG = "payment_launcher_fragment"
147
162
  }
148
163
 
149
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
150
- savedInstanceState: Bundle?): View {
164
+ override fun onCreateView(
165
+ inflater: LayoutInflater,
166
+ container: ViewGroup?,
167
+ savedInstanceState: Bundle?,
168
+ ): View {
151
169
  paymentLauncher = createPaymentLauncher()
152
170
  if (paymentIntentClientSecret != null && confirmPaymentParams != null) {
153
171
  paymentLauncher.confirm(confirmPaymentParams)
@@ -158,15 +176,15 @@ class PaymentLauncherFragment(
158
176
  } else if (handleNextActionSetupIntentClientSecret != null) {
159
177
  paymentLauncher.handleNextActionForSetupIntent(handleNextActionSetupIntentClientSecret)
160
178
  } else {
161
- throw Exception("Invalid parameters provided to PaymentLauncher. Ensure that you are providing the correct client secret and setup params (if necessary).")
162
- }
163
- return FrameLayout(requireActivity()).also {
164
- it.visibility = View.GONE
179
+ throw Exception(
180
+ "Invalid parameters provided to PaymentLauncher. Ensure that you are providing the correct client secret and setup params (if necessary).",
181
+ )
165
182
  }
183
+ return FrameLayout(requireActivity()).also { it.visibility = View.GONE }
166
184
  }
167
185
 
168
- private fun createPaymentLauncher(): PaymentLauncher {
169
- return PaymentLauncher.create(this, publishableKey, stripeAccountId) { paymentResult ->
186
+ private fun createPaymentLauncher(): PaymentLauncher =
187
+ PaymentLauncher.create(this, publishableKey, stripeAccountId) { paymentResult ->
170
188
  when (paymentResult) {
171
189
  is PaymentResult.Completed -> {
172
190
  if (paymentIntentClientSecret != null) {
@@ -186,106 +204,167 @@ class PaymentLauncherFragment(
186
204
  removeFragment(context)
187
205
  }
188
206
  is PaymentResult.Failed -> {
189
- promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), paymentResult.throwable))
207
+ promise.resolve(
208
+ createError(ConfirmPaymentErrorType.Failed.toString(), paymentResult.throwable),
209
+ )
190
210
  removeFragment(context)
191
211
  }
192
212
  }
193
213
  }
194
- }
195
214
 
196
- private fun retrieveSetupIntent(clientSecret: String, stripeAccountId: String?) {
197
- stripe.retrieveSetupIntent(clientSecret, stripeAccountId, expand = listOf("payment_method"), object : ApiResultCallback<SetupIntent> {
198
- override fun onError(e: Exception) {
199
- promise.resolve(createError(ConfirmSetupIntentErrorType.Failed.toString(), e))
200
- removeFragment(context)
201
- }
215
+ private fun retrieveSetupIntent(
216
+ clientSecret: String,
217
+ stripeAccountId: String?,
218
+ ) {
219
+ stripe.retrieveSetupIntent(
220
+ clientSecret,
221
+ stripeAccountId,
222
+ expand = listOf("payment_method"),
223
+ object : ApiResultCallback<SetupIntent> {
224
+ override fun onError(e: Exception) {
225
+ promise.resolve(createError(ConfirmSetupIntentErrorType.Failed.toString(), e))
226
+ removeFragment(context)
227
+ }
202
228
 
203
- override fun onSuccess(result: SetupIntent) {
204
- when (result.status) {
205
- StripeIntent.Status.Succeeded,
206
- StripeIntent.Status.Processing,
207
- StripeIntent.Status.RequiresConfirmation,
208
- StripeIntent.Status.RequiresCapture -> {
209
- promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
210
- }
211
- StripeIntent.Status.RequiresAction -> {
212
- if (isNextActionSuccessState(result.nextActionType)) {
229
+ override fun onSuccess(result: SetupIntent) {
230
+ when (result.status) {
231
+ StripeIntent.Status.Succeeded,
232
+ StripeIntent.Status.Processing,
233
+ StripeIntent.Status.RequiresConfirmation,
234
+ StripeIntent.Status.RequiresCapture,
235
+ -> {
213
236
  promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
214
- } else {
215
- (result.lastSetupError)?.let {
216
- promise.resolve(createError(ConfirmSetupIntentErrorType.Canceled.toString(), it))
217
- } ?: run {
218
- promise.resolve(createError(ConfirmSetupIntentErrorType.Canceled.toString(), "Setup has been canceled"))
237
+ }
238
+ StripeIntent.Status.RequiresAction -> {
239
+ if (isNextActionSuccessState(result.nextActionType)) {
240
+ promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
241
+ } else {
242
+ (result.lastSetupError)?.let {
243
+ promise.resolve(
244
+ createError(ConfirmSetupIntentErrorType.Canceled.toString(), it),
245
+ )
246
+ }
247
+ ?: run {
248
+ promise.resolve(
249
+ createError(
250
+ ConfirmSetupIntentErrorType.Canceled.toString(),
251
+ "Setup has been canceled",
252
+ ),
253
+ )
254
+ }
219
255
  }
220
256
  }
257
+ StripeIntent.Status.RequiresPaymentMethod -> {
258
+ promise.resolve(
259
+ createError(
260
+ ConfirmSetupIntentErrorType.Failed.toString(),
261
+ result.lastSetupError,
262
+ ),
263
+ )
264
+ }
265
+ StripeIntent.Status.Canceled -> {
266
+ promise.resolve(
267
+ createError(
268
+ ConfirmSetupIntentErrorType.Canceled.toString(),
269
+ result.lastSetupError,
270
+ ),
271
+ )
272
+ }
273
+ else -> {
274
+ promise.resolve(
275
+ createError(
276
+ ConfirmSetupIntentErrorType.Unknown.toString(),
277
+ "unhandled error: ${result.status}",
278
+ ),
279
+ )
280
+ }
221
281
  }
222
- StripeIntent.Status.RequiresPaymentMethod -> {
223
- promise.resolve(createError(ConfirmSetupIntentErrorType.Failed.toString(), result.lastSetupError))
224
- }
225
- StripeIntent.Status.Canceled -> {
226
- promise.resolve(createError(ConfirmSetupIntentErrorType.Canceled.toString(), result.lastSetupError))
227
- }
228
- else -> {
229
- promise.resolve(createError(ConfirmSetupIntentErrorType.Unknown.toString(), "unhandled error: ${result.status}"))
230
- }
282
+ removeFragment(context)
231
283
  }
232
- removeFragment(context)
233
- }
234
- })
284
+ },
285
+ )
235
286
  }
236
287
 
237
- private fun retrievePaymentIntent(clientSecret: String, stripeAccountId: String?) {
238
- stripe.retrievePaymentIntent(clientSecret, stripeAccountId, expand = listOf("payment_method"), object : ApiResultCallback<PaymentIntent> {
239
- override fun onError(e: Exception) {
240
- promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), e))
241
- removeFragment(context)
242
- }
288
+ private fun retrievePaymentIntent(
289
+ clientSecret: String,
290
+ stripeAccountId: String?,
291
+ ) {
292
+ stripe.retrievePaymentIntent(
293
+ clientSecret,
294
+ stripeAccountId,
295
+ expand = listOf("payment_method"),
296
+ object : ApiResultCallback<PaymentIntent> {
297
+ override fun onError(e: Exception) {
298
+ promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), e))
299
+ removeFragment(context)
300
+ }
243
301
 
244
- override fun onSuccess(result: PaymentIntent) {
245
- when (result.status) {
246
- StripeIntent.Status.Succeeded,
247
- StripeIntent.Status.Processing,
248
- StripeIntent.Status.RequiresConfirmation,
249
- StripeIntent.Status.RequiresCapture -> {
250
- promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(result)))
251
- }
252
- StripeIntent.Status.RequiresAction -> {
253
- if (isNextActionSuccessState(result.nextActionType)) {
302
+ override fun onSuccess(result: PaymentIntent) {
303
+ when (result.status) {
304
+ StripeIntent.Status.Succeeded,
305
+ StripeIntent.Status.Processing,
306
+ StripeIntent.Status.RequiresConfirmation,
307
+ StripeIntent.Status.RequiresCapture,
308
+ -> {
254
309
  promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(result)))
255
- } else {
256
- (result.lastPaymentError)?.let {
257
- promise.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), it))
258
- } ?: run {
259
- promise.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), "The payment has been canceled"))
310
+ }
311
+ StripeIntent.Status.RequiresAction -> {
312
+ if (isNextActionSuccessState(result.nextActionType)) {
313
+ promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(result)))
314
+ } else {
315
+ (result.lastPaymentError)?.let {
316
+ promise.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), it))
317
+ }
318
+ ?: run {
319
+ promise.resolve(
320
+ createError(
321
+ ConfirmPaymentErrorType.Canceled.toString(),
322
+ "The payment has been canceled",
323
+ ),
324
+ )
325
+ }
260
326
  }
261
327
  }
328
+ StripeIntent.Status.RequiresPaymentMethod -> {
329
+ promise.resolve(
330
+ createError(ConfirmPaymentErrorType.Failed.toString(), result.lastPaymentError),
331
+ )
332
+ }
333
+ StripeIntent.Status.Canceled -> {
334
+ promise.resolve(
335
+ createError(
336
+ ConfirmPaymentErrorType.Canceled.toString(),
337
+ result.lastPaymentError,
338
+ ),
339
+ )
340
+ }
341
+ else -> {
342
+ promise.resolve(
343
+ createError(
344
+ ConfirmPaymentErrorType.Unknown.toString(),
345
+ "unhandled error: ${result.status}",
346
+ ),
347
+ )
348
+ }
262
349
  }
263
- StripeIntent.Status.RequiresPaymentMethod -> {
264
- promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), result.lastPaymentError))
265
- }
266
- StripeIntent.Status.Canceled -> {
267
- promise.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), result.lastPaymentError))
268
- }
269
- else -> {
270
- promise.resolve(createError(ConfirmPaymentErrorType.Unknown.toString(), "unhandled error: ${result.status}"))
271
- }
350
+ removeFragment(context)
272
351
  }
273
- removeFragment(context)
274
- }
275
- })
352
+ },
353
+ )
276
354
  }
277
355
 
278
356
  /**
279
- * Check if paymentIntent.nextAction is out-of-band, such as voucher-based or waiting
280
- * on customer verification. If it is, then being in this state is considered "successful".
357
+ * Check if paymentIntent.nextAction is out-of-band, such as voucher-based or waiting on customer
358
+ * verification. If it is, then being in this state is considered "successful".
281
359
  */
282
- private fun isNextActionSuccessState(nextAction: StripeIntent.NextActionType?): Boolean {
283
- return when (nextAction) {
360
+ private fun isNextActionSuccessState(nextAction: StripeIntent.NextActionType?): Boolean =
361
+ when (nextAction) {
284
362
  StripeIntent.NextActionType.DisplayOxxoDetails,
285
363
  StripeIntent.NextActionType.DisplayBoletoDetails,
286
364
  StripeIntent.NextActionType.DisplayKonbiniDetails,
287
365
  StripeIntent.NextActionType.VerifyWithMicrodeposits,
288
- StripeIntent.NextActionType.DisplayMultibancoDetails -> true
366
+ StripeIntent.NextActionType.DisplayMultibancoDetails,
367
+ -> true
289
368
  StripeIntent.NextActionType.RedirectToUrl,
290
369
  StripeIntent.NextActionType.UseStripeSdk,
291
370
  StripeIntent.NextActionType.AlipayRedirect,
@@ -294,8 +373,7 @@ class PaymentLauncherFragment(
294
373
  StripeIntent.NextActionType.UpiAwaitNotification,
295
374
  StripeIntent.NextActionType.CashAppRedirect,
296
375
  StripeIntent.NextActionType.SwishRedirect,
297
- null, -> false
376
+ null,
377
+ -> false
298
378
  }
299
- }
300
379
  }
301
-