@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
@@ -12,9 +12,19 @@ import android.view.View
12
12
  import android.view.ViewGroup
13
13
  import android.widget.FrameLayout
14
14
  import androidx.fragment.app.Fragment
15
- import com.facebook.react.bridge.*
15
+ import com.facebook.react.bridge.Arguments
16
+ import com.facebook.react.bridge.Promise
17
+ import com.facebook.react.bridge.ReactApplicationContext
18
+ import com.facebook.react.bridge.WritableMap
19
+ import com.facebook.react.bridge.WritableNativeMap
16
20
  import com.reactnativestripesdk.customersheet.ReactNativeCustomerAdapter
17
- import com.reactnativestripesdk.utils.*
21
+ import com.reactnativestripesdk.utils.CreateTokenErrorType
22
+ import com.reactnativestripesdk.utils.ErrorType
23
+ import com.reactnativestripesdk.utils.KeepJsAwakeTask
24
+ import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
25
+ import com.reactnativestripesdk.utils.createError
26
+ import com.reactnativestripesdk.utils.mapFromPaymentMethod
27
+ import com.reactnativestripesdk.utils.mapToPreferredNetworks
18
28
  import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
19
29
  import com.stripe.android.customersheet.CustomerAdapter
20
30
  import com.stripe.android.customersheet.CustomerEphemeralKey
@@ -22,12 +32,11 @@ import com.stripe.android.customersheet.CustomerSheet
22
32
  import com.stripe.android.customersheet.CustomerSheetResult
23
33
  import com.stripe.android.customersheet.PaymentOptionSelection
24
34
  import com.stripe.android.model.PaymentMethod
25
- import com.stripe.android.paymentsheet.*
35
+ import com.stripe.android.paymentsheet.PaymentSheet
26
36
  import kotlinx.coroutines.CoroutineScope
27
37
  import kotlinx.coroutines.Dispatchers
28
38
  import kotlinx.coroutines.launch
29
39
 
30
-
31
40
  @OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
32
41
  class CustomerSheetFragment : Fragment() {
33
42
  private var customerSheet: CustomerSheet? = null
@@ -35,28 +44,38 @@ class CustomerSheetFragment : Fragment() {
35
44
  internal var context: ReactApplicationContext? = null
36
45
  internal var initPromise: Promise? = null
37
46
  private var presentPromise: Promise? = null
47
+ private var keepJsAwake: KeepJsAwakeTask? = null
38
48
 
39
49
  override fun onCreateView(
40
50
  inflater: LayoutInflater,
41
51
  container: ViewGroup?,
42
- savedInstanceState: Bundle?
43
- ): View {
44
- return FrameLayout(requireActivity()).also {
45
- it.visibility = View.GONE
46
- }
47
- }
52
+ savedInstanceState: Bundle?,
53
+ ): View = FrameLayout(requireActivity()).also { it.visibility = View.GONE }
48
54
 
49
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
55
+ override fun onViewCreated(
56
+ view: View,
57
+ savedInstanceState: Bundle?,
58
+ ) {
50
59
  super.onViewCreated(view, savedInstanceState)
51
60
 
52
- val context = context ?: run {
53
- Log.e("StripeReactNative", "No context found during CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues")
54
- return
55
- }
56
- val initPromise = initPromise ?: run {
57
- Log.e("StripeReactNative", "No promise found for CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues")
58
- return
59
- }
61
+ val context =
62
+ context
63
+ ?: run {
64
+ Log.e(
65
+ "StripeReactNative",
66
+ "No context found during CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
67
+ )
68
+ return
69
+ }
70
+ val initPromise =
71
+ initPromise
72
+ ?: run {
73
+ Log.e(
74
+ "StripeReactNative",
75
+ "No promise found for CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
76
+ )
77
+ return
78
+ }
60
79
 
61
80
  val headerTextForSelectionScreen = arguments?.getString("headerTextForSelectionScreen")
62
81
  val merchantDisplayName = arguments?.getString("merchantDisplayName")
@@ -67,52 +86,69 @@ class CustomerSheetFragment : Fragment() {
67
86
  val customerId = arguments?.getString("customerId")
68
87
  val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret")
69
88
  val customerAdapterOverrideParams = arguments?.getBundle("customerAdapter")
70
- val allowsRemovalOfLastSavedPaymentMethod = arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod", true) ?: true
89
+ val allowsRemovalOfLastSavedPaymentMethod =
90
+ arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod", true) ?: true
71
91
  val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
72
92
  if (customerId == null) {
73
- initPromise.resolve(createError(ErrorType.Failed.toString(), "You must provide a value for `customerId`"))
93
+ initPromise.resolve(
94
+ createError(ErrorType.Failed.toString(), "You must provide a value for `customerId`"),
95
+ )
74
96
  return
75
97
  }
76
98
  if (customerEphemeralKeySecret == null) {
77
- initPromise.resolve(createError(ErrorType.Failed.toString(), "You must provide a value for `customerEphemeralKeySecret`"))
78
- return
79
- }
80
-
81
- val appearance = try {
82
- buildPaymentSheetAppearance(arguments?.getBundle("appearance"), context)
83
- } catch (error: PaymentSheetAppearanceException) {
84
- initPromise.resolve(createError(ErrorType.Failed.toString(), error))
99
+ initPromise.resolve(
100
+ createError(
101
+ ErrorType.Failed.toString(),
102
+ "You must provide a value for `customerEphemeralKeySecret`",
103
+ ),
104
+ )
85
105
  return
86
106
  }
87
107
 
88
- val configuration = CustomerSheet.Configuration.builder(merchantDisplayName ?: "")
89
- .appearance(appearance)
90
- .googlePayEnabled(googlePayEnabled)
91
- .headerTextForSelectionScreen(headerTextForSelectionScreen)
92
- .preferredNetworks(mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")))
93
- .allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
108
+ val appearance =
109
+ try {
110
+ buildPaymentSheetAppearance(arguments?.getBundle("appearance"), context)
111
+ } catch (error: PaymentSheetAppearanceException) {
112
+ initPromise.resolve(createError(ErrorType.Failed.toString(), error))
113
+ return
114
+ }
94
115
 
95
- paymentMethodOrder?.let {
96
- configuration.paymentMethodOrder(it)
97
- }
116
+ val configuration =
117
+ CustomerSheet.Configuration
118
+ .builder(merchantDisplayName ?: "")
119
+ .appearance(appearance)
120
+ .googlePayEnabled(googlePayEnabled)
121
+ .headerTextForSelectionScreen(headerTextForSelectionScreen)
122
+ .preferredNetworks(
123
+ mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")),
124
+ ).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
125
+ .cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
126
+
127
+ paymentMethodOrder?.let { configuration.paymentMethodOrder(it) }
98
128
  billingDetailsBundle?.let {
99
129
  configuration.defaultBillingDetails(createDefaultBillingDetails(billingDetailsBundle))
100
130
  }
101
131
  billingConfigParams?.let {
102
- configuration.billingDetailsCollectionConfiguration(createBillingDetailsCollectionConfiguration(billingConfigParams))
103
- }
104
-
105
- val customerAdapter = createCustomerAdapter(
106
- context, customerId, customerEphemeralKeySecret, setupIntentClientSecret, customerAdapterOverrideParams
107
- ).also {
108
- this.customerAdapter = it
132
+ configuration.billingDetailsCollectionConfiguration(
133
+ createBillingDetailsCollectionConfiguration(billingConfigParams),
134
+ )
109
135
  }
110
136
 
111
- customerSheet = CustomerSheet.create(
112
- fragment = this,
113
- customerAdapter = customerAdapter,
114
- callback = ::handleResult
115
- )
137
+ val customerAdapter =
138
+ createCustomerAdapter(
139
+ context,
140
+ customerId,
141
+ customerEphemeralKeySecret,
142
+ setupIntentClientSecret,
143
+ customerAdapterOverrideParams,
144
+ ).also { this.customerAdapter = it }
145
+
146
+ customerSheet =
147
+ CustomerSheet.create(
148
+ fragment = this,
149
+ customerAdapter = customerAdapter,
150
+ callback = ::handleResult,
151
+ )
116
152
 
117
153
  customerSheet?.configure(configuration.build())
118
154
 
@@ -120,85 +156,98 @@ class CustomerSheetFragment : Fragment() {
120
156
  }
121
157
 
122
158
  private fun handleResult(result: CustomerSheetResult) {
123
- val presentPromise = presentPromise ?: run {
124
- Log.e("StripeReactNative", "No promise found for CustomerSheet.present")
125
- return
126
- }
127
-
128
159
  var promiseResult = Arguments.createMap()
129
160
  when (result) {
130
161
  is CustomerSheetResult.Failed -> {
131
- presentPromise.resolve(createError(ErrorType.Failed.toString(), result.exception))
162
+ resolvePresentPromise(createError(ErrorType.Failed.toString(), result.exception))
132
163
  }
133
164
  is CustomerSheetResult.Selected -> {
134
165
  promiseResult = createPaymentOptionResult(result.selection)
135
166
  }
136
167
  is CustomerSheetResult.Canceled -> {
137
168
  promiseResult = createPaymentOptionResult(result.selection)
138
- promiseResult.putMap("error", Arguments.createMap().also { it.putString("code", ErrorType.Canceled.toString()) })
169
+ promiseResult.putMap(
170
+ "error",
171
+ Arguments.createMap().also { it.putString("code", ErrorType.Canceled.toString()) },
172
+ )
139
173
  }
140
174
  }
141
- presentPromise.resolve(promiseResult)
175
+ resolvePresentPromise(promiseResult)
142
176
  }
143
177
 
144
- fun present(timeout: Long?, promise: Promise) {
178
+ fun present(
179
+ timeout: Long?,
180
+ promise: Promise,
181
+ ) {
182
+ keepJsAwake = context?.let { KeepJsAwakeTask(it).apply { start() } }
145
183
  presentPromise = promise
146
184
  if (timeout != null) {
147
- presentWithTimeout(timeout, promise)
148
- }
149
- customerSheet?.present() ?: run {
150
- promise.resolve(createMissingInitError())
185
+ presentWithTimeout(timeout)
151
186
  }
187
+ customerSheet?.present() ?: run { resolvePresentPromise(createMissingInitError()) }
152
188
  }
153
189
 
154
- private fun presentWithTimeout(timeout: Long, promise: Promise) {
190
+ private fun presentWithTimeout(timeout: Long) {
155
191
  var customerSheetActivity: Activity? = null
156
192
  var activities: MutableList<Activity> = mutableListOf()
157
- val activityLifecycleCallbacks = object : Application.ActivityLifecycleCallbacks {
158
- override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
159
- customerSheetActivity = activity
160
- activities.add(activity)
161
- }
162
-
163
- override fun onActivityStarted(activity: Activity) {}
193
+ val activityLifecycleCallbacks =
194
+ object : Application.ActivityLifecycleCallbacks {
195
+ override fun onActivityCreated(
196
+ activity: Activity,
197
+ savedInstanceState: Bundle?,
198
+ ) {
199
+ customerSheetActivity = activity
200
+ activities.add(activity)
201
+ }
164
202
 
165
- override fun onActivityResumed(activity: Activity) {}
203
+ override fun onActivityStarted(activity: Activity) {}
166
204
 
167
- override fun onActivityPaused(activity: Activity) {}
205
+ override fun onActivityResumed(activity: Activity) {}
168
206
 
169
- override fun onActivityStopped(activity: Activity) {}
207
+ override fun onActivityPaused(activity: Activity) {}
170
208
 
171
- override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
209
+ override fun onActivityStopped(activity: Activity) {}
172
210
 
173
- override fun onActivityDestroyed(activity: Activity) {
174
- customerSheetActivity = null
175
- activities = mutableListOf()
176
- context?.currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
177
- }
178
- }
211
+ override fun onActivitySaveInstanceState(
212
+ activity: Activity,
213
+ outState: Bundle,
214
+ ) {}
179
215
 
180
- Handler(Looper.getMainLooper()).postDelayed({
181
- //customerSheetActivity?.finish()
182
- for (a in activities) {
183
- a.finish()
216
+ override fun onActivityDestroyed(activity: Activity) {
217
+ customerSheetActivity = null
218
+ activities = mutableListOf()
219
+ context?.currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
184
220
  }
185
- }, timeout)
221
+ }
186
222
 
223
+ Handler(Looper.getMainLooper())
224
+ .postDelayed(
225
+ {
226
+ // customerSheetActivity?.finish()
227
+ for (a in activities) {
228
+ a.finish()
229
+ }
230
+ },
231
+ timeout,
232
+ )
187
233
 
188
- context?.currentActivity?.application?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
234
+ context
235
+ ?.currentActivity
236
+ ?.application
237
+ ?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
189
238
 
190
- customerSheet?.present() ?: run {
191
- promise.resolve(createMissingInitError())
192
- }
239
+ customerSheet?.present() ?: run { resolvePresentPromise(createMissingInitError()) }
193
240
  }
194
241
 
195
242
  internal fun retrievePaymentOptionSelection(promise: Promise) {
196
243
  CoroutineScope(Dispatchers.IO).launch {
197
244
  runCatching {
198
- val result = customerSheet?.retrievePaymentOptionSelection() ?: run {
199
- promise.resolve(createMissingInitError())
200
- return@launch
201
- }
245
+ val result =
246
+ customerSheet?.retrievePaymentOptionSelection()
247
+ ?: run {
248
+ promise.resolve(createMissingInitError())
249
+ return@launch
250
+ }
202
251
  var promiseResult = Arguments.createMap()
203
252
  when (result) {
204
253
  is CustomerSheetResult.Failed -> {
@@ -209,7 +258,12 @@ class CustomerSheetFragment : Fragment() {
209
258
  }
210
259
  is CustomerSheetResult.Canceled -> {
211
260
  promiseResult = createPaymentOptionResult(result.selection)
212
- promiseResult.putMap("error", Arguments.createMap().also { it.putString("code", ErrorType.Canceled.toString()) })
261
+ promiseResult.putMap(
262
+ "error",
263
+ Arguments.createMap().also {
264
+ it.putString("code", ErrorType.Canceled.toString())
265
+ },
266
+ )
213
267
  }
214
268
  }
215
269
  promise.resolve(promiseResult)
@@ -219,38 +273,51 @@ class CustomerSheetFragment : Fragment() {
219
273
  }
220
274
  }
221
275
 
276
+ private fun resolvePresentPromise(value: Any?) {
277
+ val presentPromise =
278
+ presentPromise
279
+ ?: run {
280
+ Log.e("StripeReactNative", "No promise found for CustomerSheet.present")
281
+ return
282
+ }
283
+ keepJsAwake?.stop()
284
+ keepJsAwake = null
285
+ presentPromise.resolve(value)
286
+ }
287
+
222
288
  companion object {
223
289
  internal const val TAG = "customer_sheet_launch_fragment"
224
290
 
225
- internal fun createMissingInitError(): WritableMap {
226
- return createError(ErrorType.Failed.toString(), "No customer sheet has been initialized yet.")
227
- }
291
+ internal fun createMissingInitError(): WritableMap =
292
+ createError(ErrorType.Failed.toString(), "No customer sheet has been initialized yet.")
228
293
 
229
294
  internal fun createDefaultBillingDetails(bundle: Bundle): PaymentSheet.BillingDetails {
230
295
  val addressBundle = bundle.getBundle("address")
231
- val address = PaymentSheet.Address(
232
- addressBundle?.getString("city"),
233
- addressBundle?.getString("country"),
234
- addressBundle?.getString("line1"),
235
- addressBundle?.getString("line2"),
236
- addressBundle?.getString("postalCode"),
237
- addressBundle?.getString("state"))
296
+ val address =
297
+ PaymentSheet.Address(
298
+ addressBundle?.getString("city"),
299
+ addressBundle?.getString("country"),
300
+ addressBundle?.getString("line1"),
301
+ addressBundle?.getString("line2"),
302
+ addressBundle?.getString("postalCode"),
303
+ addressBundle?.getString("state"),
304
+ )
238
305
  return PaymentSheet.BillingDetails(
239
306
  address,
240
307
  bundle.getString("email"),
241
308
  bundle.getString("name"),
242
- bundle.getString("phone"))
309
+ bundle.getString("phone"),
310
+ )
243
311
  }
244
312
 
245
- internal fun createBillingDetailsCollectionConfiguration(bundle: Bundle): PaymentSheet.BillingDetailsCollectionConfiguration {
246
- return PaymentSheet.BillingDetailsCollectionConfiguration(
313
+ internal fun createBillingDetailsCollectionConfiguration(bundle: Bundle): PaymentSheet.BillingDetailsCollectionConfiguration =
314
+ PaymentSheet.BillingDetailsCollectionConfiguration(
247
315
  name = mapToCollectionMode(bundle.getString("name")),
248
316
  phone = mapToCollectionMode(bundle.getString("phone")),
249
317
  email = mapToCollectionMode(bundle.getString("email")),
250
318
  address = mapToAddressCollectionMode(bundle.getString("address")),
251
- attachDefaultsToPaymentMethod = bundle.getBoolean("attachDefaultsToPaymentMethod")
319
+ attachDefaultsToPaymentMethod = bundle.getBoolean("attachDefaultsToPaymentMethod"),
252
320
  )
253
- }
254
321
 
255
322
  internal fun createCustomerAdapter(
256
323
  context: ReactApplicationContext,
@@ -264,36 +331,44 @@ class CustomerSheetFragment : Fragment() {
264
331
  CustomerEphemeralKey.create(
265
332
  customerId = customerId,
266
333
  ephemeralKey = customerEphemeralKeySecret,
267
- )
268
- )
269
- }
270
- val customerAdapter = if (setupIntentClientSecret != null) {
271
- CustomerAdapter.create(
272
- context,
273
- customerEphemeralKeyProvider = ephemeralKeyProvider,
274
- setupIntentClientSecretProvider = {
275
- CustomerAdapter.Result.success(
276
- setupIntentClientSecret,
277
- )
278
- }
279
- )
280
- } else {
281
- CustomerAdapter.create(
282
- context,
283
- customerEphemeralKeyProvider = ephemeralKeyProvider,
284
- setupIntentClientSecretProvider = null
334
+ ),
285
335
  )
286
336
  }
337
+ val customerAdapter =
338
+ if (setupIntentClientSecret != null) {
339
+ CustomerAdapter.create(
340
+ context,
341
+ customerEphemeralKeyProvider = ephemeralKeyProvider,
342
+ setupIntentClientSecretProvider = {
343
+ CustomerAdapter.Result.success(
344
+ setupIntentClientSecret,
345
+ )
346
+ },
347
+ )
348
+ } else {
349
+ CustomerAdapter.create(
350
+ context,
351
+ customerEphemeralKeyProvider = ephemeralKeyProvider,
352
+ setupIntentClientSecretProvider = null,
353
+ )
354
+ }
287
355
 
288
356
  return ReactNativeCustomerAdapter(
289
357
  context = context,
290
358
  adapter = customerAdapter,
291
- overridesFetchPaymentMethods = customerAdapterOverrideParams?.getBoolean("fetchPaymentMethods") ?: false,
292
- overridesAttachPaymentMethod = customerAdapterOverrideParams?.getBoolean("attachPaymentMethod") ?: false,
293
- overridesDetachPaymentMethod = customerAdapterOverrideParams?.getBoolean("detachPaymentMethod") ?: false,
294
- overridesSetSelectedPaymentOption = customerAdapterOverrideParams?.getBoolean("setSelectedPaymentOption") ?: false,
295
- overridesFetchSelectedPaymentOption = customerAdapterOverrideParams?.getBoolean("fetchSelectedPaymentOption") ?: false,
296
- overridesSetupIntentClientSecretForCustomerAttach = customerAdapterOverrideParams?.getBoolean("setupIntentClientSecretForCustomerAttach") ?: false
359
+ overridesFetchPaymentMethods =
360
+ customerAdapterOverrideParams?.getBoolean("fetchPaymentMethods") ?: false,
361
+ overridesAttachPaymentMethod =
362
+ customerAdapterOverrideParams?.getBoolean("attachPaymentMethod") ?: false,
363
+ overridesDetachPaymentMethod =
364
+ customerAdapterOverrideParams?.getBoolean("detachPaymentMethod") ?: false,
365
+ overridesSetSelectedPaymentOption =
366
+ customerAdapterOverrideParams?.getBoolean("setSelectedPaymentOption") ?: false,
367
+ overridesFetchSelectedPaymentOption =
368
+ customerAdapterOverrideParams?.getBoolean("fetchSelectedPaymentOption") ?: false,
369
+ overridesSetupIntentClientSecretForCustomerAttach =
370
+ customerAdapterOverrideParams?.getBoolean("setupIntentClientSecretForCustomerAttach")
371
+ ?: false,
297
372
  )
298
373
  }
299
374
 
@@ -302,16 +377,16 @@ class CustomerSheetFragment : Fragment() {
302
377
 
303
378
  when (selection) {
304
379
  is PaymentOptionSelection.GooglePay -> {
305
- paymentOptionResult = buildResult(
306
- selection.paymentOption.label,
307
- selection.paymentOption.icon(),
308
- null)
380
+ paymentOptionResult =
381
+ buildResult(selection.paymentOption.label, selection.paymentOption.icon(), null)
309
382
  }
310
383
  is PaymentOptionSelection.PaymentMethod -> {
311
- paymentOptionResult = buildResult(
312
- selection.paymentOption.label,
313
- selection.paymentOption.icon(),
314
- selection.paymentMethod)
384
+ paymentOptionResult =
385
+ buildResult(
386
+ selection.paymentOption.label,
387
+ selection.paymentOption.icon(),
388
+ selection.paymentMethod,
389
+ )
315
390
  }
316
391
  null -> {}
317
392
  }
@@ -319,12 +394,17 @@ class CustomerSheetFragment : Fragment() {
319
394
  return paymentOptionResult
320
395
  }
321
396
 
322
- private fun buildResult(label: String, drawable: Drawable, paymentMethod: PaymentMethod?): WritableMap {
397
+ private fun buildResult(
398
+ label: String,
399
+ drawable: Drawable,
400
+ paymentMethod: PaymentMethod?,
401
+ ): WritableMap {
323
402
  val result = Arguments.createMap()
324
- val paymentOption = Arguments.createMap().also {
325
- it.putString("label", label)
326
- it.putString("image", getBase64FromBitmap(getBitmapFromDrawable(drawable)))
327
- }
403
+ val paymentOption =
404
+ Arguments.createMap().also {
405
+ it.putString("label", label)
406
+ it.putString("image", getBase64FromBitmap(getBitmapFromDrawable(drawable)))
407
+ }
328
408
  result.putMap("paymentOption", paymentOption)
329
409
  if (paymentMethod != null) {
330
410
  result.putMap("paymentMethod", mapFromPaymentMethod(paymentMethod))
@@ -3,14 +3,13 @@ package com.reactnativestripesdk.customersheet
3
3
  import android.util.Log
4
4
  import com.facebook.react.bridge.Arguments
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.bridge.ReadableMap
7
6
  import com.facebook.react.bridge.WritableMap
8
7
  import com.reactnativestripesdk.StripeSdkModule
9
8
  import com.stripe.android.customersheet.CustomerAdapter
10
9
  import com.stripe.android.model.PaymentMethod
11
10
  import kotlinx.coroutines.CompletableDeferred
12
11
 
13
- class ReactNativeCustomerAdapter (
12
+ class ReactNativeCustomerAdapter(
14
13
  private val context: ReactApplicationContext,
15
14
  private val adapter: CustomerAdapter,
16
15
  private val overridesFetchPaymentMethods: Boolean,
@@ -18,7 +17,7 @@ class ReactNativeCustomerAdapter (
18
17
  private val overridesDetachPaymentMethod: Boolean,
19
18
  private val overridesSetSelectedPaymentOption: Boolean,
20
19
  private val overridesFetchSelectedPaymentOption: Boolean,
21
- private val overridesSetupIntentClientSecretForCustomerAttach: Boolean
20
+ private val overridesSetupIntentClientSecretForCustomerAttach: Boolean,
22
21
  ) : CustomerAdapter by adapter {
23
22
  internal var fetchPaymentMethodsCallback: CompletableDeferred<List<PaymentMethod>>? = null
24
23
  internal var attachPaymentMethodCallback: CompletableDeferred<PaymentMethod>? = null
@@ -44,9 +43,7 @@ class ReactNativeCustomerAdapter (
44
43
  if (overridesAttachPaymentMethod) {
45
44
  CompletableDeferred<PaymentMethod>().also {
46
45
  attachPaymentMethodCallback = it
47
- val params = Arguments.createMap().also {
48
- it.putString("paymentMethodId", paymentMethodId)
49
- }
46
+ val params = Arguments.createMap().also { it.putString("paymentMethodId", paymentMethodId) }
50
47
  emitEvent("onCustomerAdapterAttachPaymentMethodCallback", params)
51
48
  val resultFromJavascript = it.await()
52
49
  return CustomerAdapter.Result.success(resultFromJavascript)
@@ -60,9 +57,7 @@ class ReactNativeCustomerAdapter (
60
57
  if (overridesDetachPaymentMethod) {
61
58
  CompletableDeferred<PaymentMethod>().also {
62
59
  detachPaymentMethodCallback = it
63
- val params = Arguments.createMap().also {
64
- it.putString("paymentMethodId", paymentMethodId)
65
- }
60
+ val params = Arguments.createMap().also { it.putString("paymentMethodId", paymentMethodId) }
66
61
  emitEvent("onCustomerAdapterDetachPaymentMethodCallback", params)
67
62
  val resultFromJavascript = it.await()
68
63
  return CustomerAdapter.Result.success(resultFromJavascript)
@@ -76,9 +71,7 @@ class ReactNativeCustomerAdapter (
76
71
  if (overridesSetSelectedPaymentOption) {
77
72
  CompletableDeferred<Unit>().also {
78
73
  setSelectedPaymentOptionCallback = it
79
- val params = Arguments.createMap().also {
80
- it.putString("paymentOption", paymentOption?.id)
81
- }
74
+ val params = Arguments.createMap().also { it.putString("paymentOption", paymentOption?.id) }
82
75
  emitEvent("onCustomerAdapterSetSelectedPaymentOptionCallback", params)
83
76
  val resultFromJavascript = it.await()
84
77
  return CustomerAdapter.Result.success(resultFromJavascript)
@@ -99,7 +92,7 @@ class ReactNativeCustomerAdapter (
99
92
  CustomerAdapter.PaymentOption.fromId(resultFromJavascript)
100
93
  } else {
101
94
  null
102
- }
95
+ },
103
96
  )
104
97
  }
105
98
  }
@@ -111,7 +104,10 @@ class ReactNativeCustomerAdapter (
111
104
  if (overridesSetupIntentClientSecretForCustomerAttach) {
112
105
  CompletableDeferred<String>().also {
113
106
  setupIntentClientSecretForCustomerAttachCallback = it
114
- emitEvent("onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback", Arguments.createMap())
107
+ emitEvent(
108
+ "onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback",
109
+ Arguments.createMap(),
110
+ )
115
111
  val resultFromJavascript = it.await()
116
112
  return CustomerAdapter.Result.success(resultFromJavascript)
117
113
  }
@@ -120,17 +116,18 @@ class ReactNativeCustomerAdapter (
120
116
  return adapter.setupIntentClientSecretForCustomerAttach()
121
117
  }
122
118
 
123
- private fun emitEvent(eventName: String, params: WritableMap) {
119
+ private fun emitEvent(
120
+ eventName: String,
121
+ params: WritableMap,
122
+ ) {
124
123
  val stripeSdkModule: StripeSdkModule? = context.getNativeModule(StripeSdkModule::class.java)
125
124
  if (stripeSdkModule == null || stripeSdkModule.eventListenerCount == 0) {
126
125
  Log.e(
127
126
  "StripeReactNative",
128
- "Tried to call $eventName, but no callback was found. Please file an issue: https://github.com/stripe/stripe-react-native/issues"
127
+ "Tried to call $eventName, but no callback was found. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
129
128
  )
130
129
  }
131
130
 
132
131
  stripeSdkModule?.sendEvent(context, eventName, params)
133
132
  }
134
133
  }
135
-
136
-