@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
@@ -3,15 +3,18 @@ package com.reactnativestripesdk.pushprovisioning
3
3
  import android.content.Context
4
4
  import com.bumptech.glide.Glide
5
5
  import com.facebook.react.bridge.ReadableMap
6
- import com.facebook.react.common.MapBuilder
6
+ import com.facebook.react.module.annotations.ReactModule
7
7
  import com.facebook.react.uimanager.SimpleViewManager
8
8
  import com.facebook.react.uimanager.ThemedReactContext
9
9
  import com.facebook.react.uimanager.annotations.ReactProp
10
10
 
11
-
12
- class AddToWalletButtonManager(applicationContext: Context) : SimpleViewManager<AddToWalletButtonView>() {
11
+ @ReactModule(name = AddToWalletButtonManager.REACT_CLASS)
12
+ class AddToWalletButtonManager(
13
+ applicationContext: Context,
14
+ ) : SimpleViewManager<AddToWalletButtonView>() {
13
15
  private val requestManager = Glide.with(applicationContext)
14
- override fun getName() = "AddToWalletButton"
16
+
17
+ override fun getName() = REACT_CLASS
15
18
 
16
19
  override fun onDropViewInstance(view: AddToWalletButtonView) {
17
20
  view.onDropViewInstance()
@@ -23,33 +26,48 @@ class AddToWalletButtonManager(applicationContext: Context) : SimpleViewManager<
23
26
  view.onAfterUpdateTransaction()
24
27
  }
25
28
 
26
- override fun createViewInstance(reactContext: ThemedReactContext): AddToWalletButtonView {
27
- return AddToWalletButtonView(reactContext, requestManager)
28
- }
29
+ override fun createViewInstance(reactContext: ThemedReactContext): AddToWalletButtonView =
30
+ AddToWalletButtonView(reactContext, requestManager)
29
31
 
30
- override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
31
- return MapBuilder.of(
32
- AddToWalletCompleteEvent.EVENT_NAME, MapBuilder.of("registrationName", "onCompleteAction")
32
+ override fun getExportedCustomDirectEventTypeConstants() =
33
+ mutableMapOf(
34
+ AddToWalletCompleteEvent.EVENT_NAME to
35
+ mutableMapOf("registrationName" to "onCompleteAction"),
33
36
  )
34
- }
35
37
 
36
38
  @ReactProp(name = "androidAssetSource")
37
- fun source(view: AddToWalletButtonView, source: ReadableMap) {
39
+ fun source(
40
+ view: AddToWalletButtonView,
41
+ source: ReadableMap,
42
+ ) {
38
43
  view.setSourceMap(source)
39
44
  }
40
45
 
41
46
  @ReactProp(name = "cardDetails")
42
- fun cardDetails(view: AddToWalletButtonView, cardDetails: ReadableMap) {
47
+ fun cardDetails(
48
+ view: AddToWalletButtonView,
49
+ cardDetails: ReadableMap,
50
+ ) {
43
51
  view.setCardDetails(cardDetails)
44
52
  }
45
53
 
46
54
  @ReactProp(name = "ephemeralKey")
47
- fun ephemeralKey(view: AddToWalletButtonView, ephemeralKey: ReadableMap) {
55
+ fun ephemeralKey(
56
+ view: AddToWalletButtonView,
57
+ ephemeralKey: ReadableMap,
58
+ ) {
48
59
  view.setEphemeralKey(ephemeralKey)
49
60
  }
50
61
 
51
62
  @ReactProp(name = "token")
52
- fun token(view: AddToWalletButtonView, token: ReadableMap?) {
63
+ fun token(
64
+ view: AddToWalletButtonView,
65
+ token: ReadableMap?,
66
+ ) {
53
67
  view.setToken(token)
54
68
  }
69
+
70
+ companion object {
71
+ const val REACT_CLASS = "AddToWalletButton"
72
+ }
55
73
  }
@@ -1,5 +1,6 @@
1
1
  package com.reactnativestripesdk.pushprovisioning
2
2
 
3
+ import android.annotation.SuppressLint
3
4
  import android.content.res.ColorStateList
4
5
  import android.graphics.Color
5
6
  import android.graphics.drawable.Drawable
@@ -16,18 +17,19 @@ import com.bumptech.glide.request.target.Target
16
17
  import com.facebook.react.bridge.ReadableMap
17
18
  import com.facebook.react.bridge.WritableMap
18
19
  import com.facebook.react.uimanager.ThemedReactContext
19
- import com.facebook.react.uimanager.UIManagerModule
20
- import com.facebook.react.uimanager.events.EventDispatcher
20
+ import com.facebook.react.uimanager.UIManagerHelper
21
21
  import com.reactnativestripesdk.utils.createError
22
22
 
23
-
24
- class AddToWalletButtonView(private val context: ThemedReactContext, private val requestManager: RequestManager) : AppCompatImageView(context) {
23
+ @SuppressLint("ViewConstructor")
24
+ class AddToWalletButtonView(
25
+ private val context: ThemedReactContext,
26
+ private val requestManager: RequestManager,
27
+ ) : AppCompatImageView(context) {
25
28
  private var cardDetails: ReadableMap? = null
26
29
  private var ephemeralKey: String? = null
27
30
  private var sourceMap: ReadableMap? = null
28
31
  private var token: ReadableMap? = null
29
32
 
30
- private var eventDispatcher: EventDispatcher? = context.getNativeModule(UIManagerModule::class.java)?.eventDispatcher
31
33
  private var loadedSource: Any? = null
32
34
  private var heightOverride: Int = 0
33
35
  private var widthOverride: Int = 0
@@ -42,17 +44,26 @@ class AddToWalletButtonView(private val context: ThemedReactContext, private val
42
44
  this,
43
45
  cardDescription,
44
46
  ephemeralKey,
45
- token)
46
- } ?: run {
47
- dispatchEvent(
48
- createError("Failed", "Missing parameters. `ephemeralKey` must be supplied in the props to <AddToWalletButton />")
47
+ token,
49
48
  )
50
49
  }
51
- } ?: run {
52
- dispatchEvent(
53
- createError("Failed", "Missing parameters. `cardDetails.cardDescription` must be supplied in the props to <AddToWalletButton />")
54
- )
50
+ ?: run {
51
+ dispatchEvent(
52
+ createError(
53
+ "Failed",
54
+ "Missing parameters. `ephemeralKey` must be supplied in the props to <AddToWalletButton />",
55
+ ),
56
+ )
57
+ }
55
58
  }
59
+ ?: run {
60
+ dispatchEvent(
61
+ createError(
62
+ "Failed",
63
+ "Missing parameters. `cardDetails.cardDescription` must be supplied in the props to <AddToWalletButton />",
64
+ ),
65
+ )
66
+ }
56
67
  return true
57
68
  }
58
69
 
@@ -78,23 +89,38 @@ class AddToWalletButtonView(private val context: ThemedReactContext, private val
78
89
 
79
90
  requestManager
80
91
  .load(sourceToLoad)
81
- .addListener(object : RequestListener<Drawable> {
82
- override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
83
- dispatchEvent(
84
- createError("Failed", "Failed to load the source from $sourceToLoad")
85
- )
86
- return true
87
- }
88
- override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
89
- setImageDrawable(
90
- RippleDrawable(
91
- ColorStateList.valueOf(Color.parseColor("#e0e0e0")),
92
- resource,
93
- null))
94
- return true
95
- }
96
- })
97
- .centerCrop()
92
+ .addListener(
93
+ object : RequestListener<Drawable> {
94
+ override fun onLoadFailed(
95
+ e: GlideException?,
96
+ model: Any?,
97
+ target: Target<Drawable>?,
98
+ isFirstResource: Boolean,
99
+ ): Boolean {
100
+ dispatchEvent(
101
+ createError("Failed", "Failed to load the source from $sourceToLoad"),
102
+ )
103
+ return true
104
+ }
105
+
106
+ override fun onResourceReady(
107
+ resource: Drawable?,
108
+ model: Any?,
109
+ target: Target<Drawable>?,
110
+ dataSource: DataSource?,
111
+ isFirstResource: Boolean,
112
+ ): Boolean {
113
+ setImageDrawable(
114
+ RippleDrawable(
115
+ ColorStateList.valueOf(Color.parseColor("#e0e0e0")),
116
+ resource,
117
+ null,
118
+ ),
119
+ )
120
+ return true
121
+ }
122
+ },
123
+ ).centerCrop()
98
124
  .override((widthOverride * scale).toInt(), (heightOverride * scale).toInt())
99
125
  .into(this)
100
126
  }
@@ -113,7 +139,12 @@ class AddToWalletButtonView(private val context: ThemedReactContext, private val
113
139
  return null
114
140
  }
115
141
 
116
- override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
142
+ override fun onSizeChanged(
143
+ w: Int,
144
+ h: Int,
145
+ oldw: Int,
146
+ oldh: Int,
147
+ ) {
117
148
  super.onSizeChanged(w, h, oldw, oldh)
118
149
  if (w > 0 && h > 0) {
119
150
  heightOverride = h
@@ -145,11 +176,6 @@ class AddToWalletButtonView(private val context: ThemedReactContext, private val
145
176
  }
146
177
 
147
178
  fun dispatchEvent(error: WritableMap?) {
148
- eventDispatcher?.dispatchEvent(
149
- AddToWalletCompleteEvent(
150
- id,
151
- error
152
- )
153
- )
179
+ UIManagerHelper.getEventDispatcherForReactTag(context, id)?.dispatchEvent(AddToWalletCompleteEvent(context.surfaceId, id, error))
154
180
  }
155
181
  }
@@ -1,22 +1,18 @@
1
1
  package com.reactnativestripesdk.pushprovisioning
2
+
2
3
  import com.facebook.react.bridge.WritableMap
3
4
  import com.facebook.react.uimanager.events.Event
4
- import com.facebook.react.uimanager.events.RCTEventEmitter
5
5
 
6
- internal class AddToWalletCompleteEvent constructor(viewTag: Int, private val error: WritableMap?) : Event<AddToWalletCompleteEvent>(viewTag) {
7
- override fun getEventName(): String {
8
- return EVENT_NAME
9
- }
6
+ internal class AddToWalletCompleteEvent(
7
+ surfaceId: Int,
8
+ viewTag: Int,
9
+ private val error: WritableMap?,
10
+ ) : Event<AddToWalletCompleteEvent>(surfaceId, viewTag) {
11
+ override fun getEventName(): String = EVENT_NAME
10
12
 
11
- override fun dispatch(rctEventEmitter: RCTEventEmitter) {
12
- rctEventEmitter.receiveEvent(viewTag, eventName, serializeEventData())
13
- }
14
-
15
- private fun serializeEventData(): WritableMap? {
16
- return error
17
- }
13
+ override fun getEventData() = error
18
14
 
19
15
  companion object {
20
- const val EVENT_NAME = "onCompleteAction"
16
+ const val EVENT_NAME = "topCompleteAction"
21
17
  }
22
18
  }
@@ -4,32 +4,30 @@ import android.os.Parcel
4
4
  import android.os.Parcelable
5
5
  import com.stripe.android.pushProvisioning.PushProvisioningEphemeralKeyProvider
6
6
 
7
+ class EphemeralKeyProvider(
8
+ private val ephemeralKey: String,
9
+ ) : PushProvisioningEphemeralKeyProvider {
10
+ private constructor(parcel: Parcel) : this(ephemeralKey = parcel.readString() ?: "")
7
11
 
8
- class EphemeralKeyProvider(private val ephemeralKey: String) : PushProvisioningEphemeralKeyProvider {
12
+ override fun describeContents(): Int = hashCode()
9
13
 
10
- private constructor(parcel: Parcel) : this(
11
- ephemeralKey = parcel.readString() ?: ""
12
- )
13
-
14
- override fun describeContents(): Int {
15
- return hashCode()
16
- }
17
-
18
- override fun writeToParcel(dest: Parcel, flags: Int) {
14
+ override fun writeToParcel(
15
+ dest: Parcel,
16
+ flags: Int,
17
+ ) {
19
18
  dest.writeString(ephemeralKey)
20
19
  }
21
20
 
22
- override fun createEphemeralKey(apiVersion: String, keyUpdateListener: com.stripe.android.pushProvisioning.EphemeralKeyUpdateListener) {
21
+ override fun createEphemeralKey(
22
+ apiVersion: String,
23
+ keyUpdateListener: com.stripe.android.pushProvisioning.EphemeralKeyUpdateListener,
24
+ ) {
23
25
  keyUpdateListener.onKeyUpdate(ephemeralKey)
24
26
  }
25
27
 
26
28
  companion object CREATOR : Parcelable.Creator<EphemeralKeyProvider> {
27
- override fun createFromParcel(parcel: Parcel): EphemeralKeyProvider {
28
- return EphemeralKeyProvider(parcel)
29
- }
29
+ override fun createFromParcel(parcel: Parcel): EphemeralKeyProvider = EphemeralKeyProvider(parcel)
30
30
 
31
- override fun newArray(size: Int): Array<EphemeralKeyProvider?> {
32
- return arrayOfNulls(size)
33
- }
31
+ override fun newArray(size: Int): Array<EphemeralKeyProvider?> = arrayOfNulls(size)
34
32
  }
35
33
  }
@@ -14,37 +14,34 @@ import com.reactnativestripesdk.utils.mapError
14
14
  import com.stripe.android.pushProvisioning.PushProvisioningActivity
15
15
  import com.stripe.android.pushProvisioning.PushProvisioningActivityStarter
16
16
 
17
-
18
17
  object PushProvisioningProxy {
19
18
  private const val TAG = "StripePushProvisioning"
20
19
  private var description = "Added by Stripe"
21
20
  private var tokenRequiringTokenization: ReadableMap? = null
22
21
 
23
- fun getApiVersion(): String {
24
- return try {
22
+ fun getApiVersion(): String =
23
+ try {
25
24
  Class.forName("com.stripe.android.pushProvisioning.PushProvisioningActivity")
26
25
  PushProvisioningActivity.API_VERSION
27
26
  } catch (e: Exception) {
28
27
  Log.e(TAG, "PushProvisioning dependency not found")
29
28
  ""
30
29
  }
31
- }
32
30
 
33
- fun isNFCEnabled(context: ReactApplicationContext): Boolean {
34
- return if (context.packageManager.hasSystemFeature(PackageManager.FEATURE_NFC)) {
31
+ fun isNFCEnabled(context: ReactApplicationContext): Boolean =
32
+ if (context.packageManager.hasSystemFeature(PackageManager.FEATURE_NFC)) {
35
33
  val adapter = NfcAdapter.getDefaultAdapter(context)
36
34
  adapter?.isEnabled ?: false
37
35
  } else {
38
36
  false
39
37
  }
40
- }
41
38
 
42
39
  fun invoke(
43
- context: ReactApplicationContext,
44
- view: AddToWalletButtonView,
45
- cardDescription: String,
46
- ephemeralKey: String,
47
- token: ReadableMap?
40
+ context: ReactApplicationContext,
41
+ view: AddToWalletButtonView,
42
+ cardDescription: String,
43
+ ephemeralKey: String,
44
+ token: ReadableMap?,
48
45
  ) {
49
46
  try {
50
47
  Class.forName("com.stripe.android.pushProvisioning.PushProvisioningActivityStarter")
@@ -52,65 +49,84 @@ object PushProvisioningProxy {
52
49
  tokenRequiringTokenization = token
53
50
  createActivityEventListener(context, view)
54
51
  context.currentActivity?.let {
55
- DefaultPushProvisioningProxy().beginPushProvisioning(
56
- it,
57
- description,
58
- EphemeralKeyProvider(ephemeralKey)
59
- )
60
- } ?: run {
61
- view.dispatchEvent(
62
- createError(
63
- "Failed",
64
- "Activity doesn't exist yet. You can safely retry.")
65
- )
52
+ DefaultPushProvisioningProxy()
53
+ .beginPushProvisioning(it, description, EphemeralKeyProvider(ephemeralKey))
66
54
  }
55
+ ?: run {
56
+ view.dispatchEvent(
57
+ createError("Failed", "Activity doesn't exist yet. You can safely retry."),
58
+ )
59
+ }
67
60
  } catch (e: Exception) {
68
61
  Log.e(TAG, "There was a problem using Stripe Android PushProvisioning: " + e.message)
69
62
  }
70
63
  }
71
64
 
72
- fun isCardInWallet(activity: Activity, cardLastFour: String, callback: TokenCheckHandler) {
65
+ fun isCardInWallet(
66
+ activity: Activity,
67
+ cardLastFour: String,
68
+ callback: TokenCheckHandler,
69
+ ) {
73
70
  TapAndPayProxy.findExistingToken(activity, cardLastFour, callback)
74
71
  }
75
72
 
76
- private fun createActivityEventListener(context: ReactApplicationContext, view: AddToWalletButtonView) {
77
- val listener = object : BaseActivityEventListener() {
78
- override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
79
- super.onActivityResult(activity, requestCode, resultCode, data)
80
- if (requestCode == TapAndPayProxy.REQUEST_CODE_TOKENIZE) {
81
- view.dispatchEvent(
82
- if (resultCode == RESULT_OK) null else mapError("Failed", "Failed to verify identity.", null, null, null, null)
83
- )
84
- } else if (requestCode == PushProvisioningActivityStarter.REQUEST_CODE) {
85
- if (resultCode == PushProvisioningActivity.RESULT_OK) {
86
- tokenRequiringTokenization?.let { tokenRequiringTokenization ->
87
- val tokenReferenceId = tokenRequiringTokenization.getString("id")
88
- if (tokenReferenceId.isNullOrBlank()) {
89
- view.dispatchEvent(
90
- mapError("Failed", "Token object passed to `<AddToWalletButton />` is missing the `id` field.", null, null, null, null)
91
- )
73
+ private fun createActivityEventListener(
74
+ context: ReactApplicationContext,
75
+ view: AddToWalletButtonView,
76
+ ) {
77
+ val listener =
78
+ object : BaseActivityEventListener() {
79
+ override fun onActivityResult(
80
+ activity: Activity,
81
+ requestCode: Int,
82
+ resultCode: Int,
83
+ data: Intent?,
84
+ ) {
85
+ super.onActivityResult(activity, requestCode, resultCode, data)
86
+ if (requestCode == TapAndPayProxy.REQUEST_CODE_TOKENIZE) {
87
+ view.dispatchEvent(
88
+ if (resultCode == RESULT_OK) {
89
+ null
92
90
  } else {
93
- TapAndPayProxy.tokenize(
94
- activity,
95
- tokenReferenceId,
96
- tokenRequiringTokenization,
97
- description
91
+ mapError("Failed", "Failed to verify identity.", null, null, null, null)
92
+ },
93
+ )
94
+ } else if (requestCode == PushProvisioningActivityStarter.REQUEST_CODE) {
95
+ if (resultCode == PushProvisioningActivity.RESULT_OK) {
96
+ tokenRequiringTokenization?.let { tokenRequiringTokenization ->
97
+ val tokenReferenceId = tokenRequiringTokenization.getString("id")
98
+ if (tokenReferenceId.isNullOrBlank()) {
99
+ view.dispatchEvent(
100
+ mapError(
101
+ "Failed",
102
+ "Token object passed to `<AddToWalletButton />` is missing the `id` field.",
103
+ null,
104
+ null,
105
+ null,
106
+ null,
107
+ ),
108
+ )
109
+ } else {
110
+ TapAndPayProxy.tokenize(
111
+ activity,
112
+ tokenReferenceId,
113
+ tokenRequiringTokenization,
114
+ description,
115
+ )
116
+ }
117
+ } ?: run { view.dispatchEvent(null) }
118
+ } else if (resultCode == PushProvisioningActivity.RESULT_ERROR) {
119
+ data?.let {
120
+ val error: PushProvisioningActivityStarter.Error =
121
+ PushProvisioningActivityStarter.Error.fromIntent(data)
122
+ view.dispatchEvent(
123
+ mapError(error.code.toString(), error.message, null, null, null, null),
98
124
  )
99
125
  }
100
- } ?: run {
101
- view.dispatchEvent(null)
102
- }
103
- } else if (resultCode == PushProvisioningActivity.RESULT_ERROR) {
104
- data?.let {
105
- val error: PushProvisioningActivityStarter.Error = PushProvisioningActivityStarter.Error.fromIntent(data)
106
- view.dispatchEvent(
107
- mapError(error.code.toString(), error.message, null, null, null, null)
108
- )
109
126
  }
110
127
  }
111
128
  }
112
129
  }
113
- }
114
130
  context.addActivityEventListener(listener)
115
131
  }
116
132
  }
@@ -119,11 +135,11 @@ class DefaultPushProvisioningProxy {
119
135
  fun beginPushProvisioning(
120
136
  activity: Activity,
121
137
  description: String,
122
- provider: EphemeralKeyProvider
138
+ provider: EphemeralKeyProvider,
123
139
  ) {
124
- PushProvisioningActivityStarter(
125
- activity,
126
- PushProvisioningActivityStarter.Args(description, provider, false)
127
- ).startForResult()
140
+ PushProvisioningActivityStarter(
141
+ activity,
142
+ PushProvisioningActivityStarter.Args(description, provider, false),
143
+ ).startForResult()
128
144
  }
129
145
  }