@stripe/stripe-react-native 0.57.0 → 0.57.1

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 (294) hide show
  1. package/android/build.gradle +76 -118
  2. package/android/gradle.properties +1 -1
  3. package/android/settings.gradle +2 -0
  4. package/android/spotless.gradle +1 -1
  5. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +20 -17
  6. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +13 -11
  7. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +17 -21
  8. package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherManager.kt +2 -0
  9. package/android/src/main/java/com/reactnativestripesdk/CustomPaymentMethodActivity.kt +2 -0
  10. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +4 -11
  11. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +46 -119
  12. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +0 -8
  13. package/android/src/main/java/com/reactnativestripesdk/FakeOnrampSdkModule.kt +154 -0
  14. package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetManager.kt +13 -15
  15. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +1 -1
  16. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +1 -1
  17. package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +7 -5
  18. package/android/src/main/java/com/reactnativestripesdk/NavigationBarManager.kt +31 -0
  19. package/android/src/main/java/com/reactnativestripesdk/NavigationBarView.kt +120 -0
  20. package/android/src/main/java/com/reactnativestripesdk/PaymentElementConfig.kt +228 -0
  21. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherManager.kt +1 -0
  22. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +3 -0
  23. package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +4 -6
  24. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +73 -30
  25. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +19 -245
  26. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +53 -17
  27. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +52 -14
  28. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +21 -2
  29. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +4 -4
  30. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +2 -2
  31. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +15 -35
  32. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +2 -1
  33. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +5 -10
  34. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +90 -77
  35. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +6 -4
  36. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +13 -3
  37. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +41 -0
  38. package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +1 -1
  39. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +92 -44
  40. package/android/src/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +118 -0
  41. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +4 -0
  42. package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +922 -0
  43. package/android/src/test/java/com/facebook/testutils/shadows/ShadowArguments.kt +29 -0
  44. package/android/src/test/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManagerTest.kt +163 -0
  45. package/android/src/test/java/com/reactnativestripesdk/PaymentElementConfigTest.kt +976 -0
  46. package/android/src/test/java/com/reactnativestripesdk/PaymentSheetAppearanceTest.kt +801 -0
  47. package/android/src/test/java/com/reactnativestripesdk/PaymentSheetManagerTest.kt +523 -0
  48. package/android/src/test/java/com/reactnativestripesdk/addresssheet/AddressSheetViewTest.kt +551 -0
  49. package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +567 -0
  50. package/android/src/test/java/com/reactnativestripesdk/mappers/PaymentOptionDisplayDataMapperTest.kt +456 -0
  51. package/android/src/test/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxyTest.kt +43 -0
  52. package/android/src/test/resources/robolectric.properties +2 -0
  53. package/ios/AddressSheet/AddressSheetUtils.swift +3 -3
  54. package/ios/AddressSheet/AddressSheetView.swift +25 -25
  55. package/ios/AddressSheet/AddressSheetViewManager.swift +2 -2
  56. package/ios/ApplePayButtonManager.swift +1 -1
  57. package/ios/ApplePayButtonView.swift +9 -10
  58. package/ios/ApplePayUtils.swift +51 -51
  59. package/ios/ApplePayViewController.swift +25 -29
  60. package/ios/AuBECSDebitFormManager.swift +1 -1
  61. package/ios/AuBECSDebitFormView.swift +13 -15
  62. package/ios/CardFieldManager.swift +4 -4
  63. package/ios/CardFieldView.swift +9 -9
  64. package/ios/CardFormManager.swift +3 -3
  65. package/ios/CardFormView.swift +28 -28
  66. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingView.swift +97 -0
  67. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewController.swift +133 -0
  68. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.m +16 -0
  69. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.swift +17 -0
  70. package/ios/CustomerSheet/CustomerSheetUtils.swift +15 -16
  71. package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +19 -19
  72. package/ios/EmbeddedPaymentElementView.swift +2 -2
  73. package/ios/Errors.swift +22 -23
  74. package/ios/FinancialConnections.swift +37 -37
  75. package/ios/Mappers.swift +210 -71
  76. package/ios/NavigationBarManager.m +13 -0
  77. package/ios/NavigationBarManager.swift +17 -0
  78. package/ios/NavigationBarView.swift +65 -0
  79. package/ios/NewArch/NavigationBarComponentView.h +10 -0
  80. package/ios/NewArch/NavigationBarComponentView.mm +86 -0
  81. package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
  82. package/ios/OldArch/StripeSdkEventEmitterCompat.m +7 -1
  83. package/ios/PaymentMethodFactory.swift +24 -24
  84. package/ios/PaymentOptionDisplayData+ReactNative.swift +4 -4
  85. package/ios/PaymentPassFinder.swift +9 -10
  86. package/ios/PaymentSheetAppearance.swift +137 -138
  87. package/ios/PushProvisioning/AddToWalletButtonManager.swift +2 -2
  88. package/ios/PushProvisioning/AddToWalletButtonView.swift +15 -17
  89. package/ios/PushProvisioning/PushProvisioningUtils.swift +11 -11
  90. package/ios/StripeContainerManager.swift +1 -1
  91. package/ios/StripeContainerView.swift +3 -3
  92. package/ios/StripeOnrampSdk.h +17 -0
  93. package/ios/StripeOnrampSdk.mm +158 -0
  94. package/ios/StripeSdk.mm +8 -0
  95. package/ios/StripeSdkEmitter.swift +4 -0
  96. package/ios/StripeSdkImpl+CustomerSheet.swift +30 -25
  97. package/ios/StripeSdkImpl+Embedded.swift +11 -9
  98. package/ios/StripeSdkImpl+PaymentSheet.swift +36 -34
  99. package/ios/StripeSdkImpl.swift +913 -185
  100. package/ios/UIColorExtension.swift +72 -0
  101. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  102. package/lib/commonjs/components/AddressSheet.js +1 -1
  103. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  104. package/lib/commonjs/components/CardField.js +1 -1
  105. package/lib/commonjs/components/CardField.js.map +1 -1
  106. package/lib/commonjs/components/CardForm.js +1 -1
  107. package/lib/commonjs/components/CardForm.js.map +1 -1
  108. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  109. package/lib/commonjs/components/StripeContainer.js +1 -1
  110. package/lib/commonjs/components/StripeProvider.js +1 -1
  111. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  112. package/lib/commonjs/connect/Components.js +2 -0
  113. package/lib/commonjs/connect/Components.js.map +1 -0
  114. package/lib/commonjs/connect/ConnectComponentsProvider.js +2 -0
  115. package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -0
  116. package/lib/commonjs/connect/EmbeddedComponent.js +19 -0
  117. package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -0
  118. package/lib/commonjs/connect/ModalCloseButton.js +2 -0
  119. package/lib/commonjs/connect/ModalCloseButton.js.map +1 -0
  120. package/lib/commonjs/connect/NavigationBar.js +2 -0
  121. package/lib/commonjs/connect/NavigationBar.js.map +1 -0
  122. package/lib/commonjs/connect/connectTypes.js +2 -0
  123. package/lib/commonjs/connect/connectTypes.js.map +1 -0
  124. package/lib/commonjs/events.js +1 -1
  125. package/lib/commonjs/events.js.map +1 -1
  126. package/lib/commonjs/helpers.js +1 -1
  127. package/lib/commonjs/helpers.js.map +1 -1
  128. package/lib/commonjs/hooks/useOnramp.js +2 -0
  129. package/lib/commonjs/hooks/useOnramp.js.map +1 -0
  130. package/lib/commonjs/index.js +1 -1
  131. package/lib/commonjs/index.js.map +1 -1
  132. package/lib/commonjs/plugin/withStripe.js +1 -1
  133. package/lib/commonjs/plugin/withStripe.js.map +1 -1
  134. package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
  135. package/lib/commonjs/specs/NativeAddToWalletButton.js.map +1 -1
  136. package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
  137. package/lib/commonjs/specs/NativeAddressSheet.js.map +1 -1
  138. package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
  139. package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
  140. package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
  141. package/lib/commonjs/specs/NativeAuBECSDebitForm.js.map +1 -1
  142. package/lib/commonjs/specs/NativeCardField.js +1 -1
  143. package/lib/commonjs/specs/NativeCardField.js.map +1 -1
  144. package/lib/commonjs/specs/NativeCardForm.js +1 -1
  145. package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
  146. package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +2 -0
  147. package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js.map +1 -0
  148. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
  149. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  150. package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
  151. package/lib/commonjs/specs/NativeGooglePayButton.js.map +1 -1
  152. package/lib/commonjs/specs/NativeNavigationBar.js +2 -0
  153. package/lib/commonjs/specs/NativeNavigationBar.js.map +1 -0
  154. package/lib/commonjs/specs/NativeOnrampSdkModule.js +2 -0
  155. package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -0
  156. package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
  157. package/lib/commonjs/specs/NativeStripeContainer.js.map +1 -1
  158. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  159. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  160. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  161. package/lib/commonjs/types/Errors.js +1 -1
  162. package/lib/commonjs/types/Errors.js.map +1 -1
  163. package/lib/commonjs/types/Onramp.js +2 -0
  164. package/lib/commonjs/types/Onramp.js.map +1 -0
  165. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  166. package/lib/commonjs/types/index.js +1 -1
  167. package/lib/commonjs/types/index.js.map +1 -1
  168. package/lib/module/components/AddToWalletButton.js +1 -1
  169. package/lib/module/components/AddressSheet.js +1 -1
  170. package/lib/module/components/AuBECSDebitForm.js +1 -1
  171. package/lib/module/components/CardField.js +1 -1
  172. package/lib/module/components/CardField.js.map +1 -1
  173. package/lib/module/components/CardForm.js +1 -1
  174. package/lib/module/components/CardForm.js.map +1 -1
  175. package/lib/module/components/PlatformPayButton.js +1 -1
  176. package/lib/module/components/StripeContainer.js +1 -1
  177. package/lib/module/components/StripeProvider.js +1 -1
  178. package/lib/module/components/StripeProvider.js.map +1 -1
  179. package/lib/module/connect/Components.js +2 -0
  180. package/lib/module/connect/Components.js.map +1 -0
  181. package/lib/module/connect/ConnectComponentsProvider.js +2 -0
  182. package/lib/module/connect/ConnectComponentsProvider.js.map +1 -0
  183. package/lib/module/connect/EmbeddedComponent.js +19 -0
  184. package/lib/module/connect/EmbeddedComponent.js.map +1 -0
  185. package/lib/module/connect/ModalCloseButton.js +2 -0
  186. package/lib/module/connect/ModalCloseButton.js.map +1 -0
  187. package/lib/module/connect/NavigationBar.js +2 -0
  188. package/lib/module/connect/NavigationBar.js.map +1 -0
  189. package/lib/module/connect/connectTypes.js +2 -0
  190. package/lib/module/connect/connectTypes.js.map +1 -0
  191. package/lib/module/events.js +1 -1
  192. package/lib/module/events.js.map +1 -1
  193. package/lib/module/helpers.js +1 -1
  194. package/lib/module/helpers.js.map +1 -1
  195. package/lib/module/hooks/useOnramp.js +2 -0
  196. package/lib/module/hooks/useOnramp.js.map +1 -0
  197. package/lib/module/index.js +1 -1
  198. package/lib/module/index.js.map +1 -1
  199. package/lib/module/plugin/withStripe.js +1 -1
  200. package/lib/module/plugin/withStripe.js.map +1 -1
  201. package/lib/module/specs/NativeAddToWalletButton.js +1 -1
  202. package/lib/module/specs/NativeAddToWalletButton.js.map +1 -1
  203. package/lib/module/specs/NativeAddressSheet.js +1 -1
  204. package/lib/module/specs/NativeAddressSheet.js.map +1 -1
  205. package/lib/module/specs/NativeApplePayButton.js +1 -1
  206. package/lib/module/specs/NativeApplePayButton.js.map +1 -1
  207. package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
  208. package/lib/module/specs/NativeAuBECSDebitForm.js.map +1 -1
  209. package/lib/module/specs/NativeCardField.js +1 -1
  210. package/lib/module/specs/NativeCardField.js.map +1 -1
  211. package/lib/module/specs/NativeCardForm.js +1 -1
  212. package/lib/module/specs/NativeCardForm.js.map +1 -1
  213. package/lib/module/specs/NativeConnectAccountOnboardingView.js +2 -0
  214. package/lib/module/specs/NativeConnectAccountOnboardingView.js.map +1 -0
  215. package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
  216. package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  217. package/lib/module/specs/NativeGooglePayButton.js +1 -1
  218. package/lib/module/specs/NativeGooglePayButton.js.map +1 -1
  219. package/lib/module/specs/NativeNavigationBar.js +2 -0
  220. package/lib/module/specs/NativeNavigationBar.js.map +1 -0
  221. package/lib/module/specs/NativeOnrampSdkModule.js +2 -0
  222. package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -0
  223. package/lib/module/specs/NativeStripeContainer.js +1 -1
  224. package/lib/module/specs/NativeStripeContainer.js.map +1 -1
  225. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  226. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  227. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  228. package/lib/module/types/Errors.js +1 -1
  229. package/lib/module/types/Errors.js.map +1 -1
  230. package/lib/module/types/Onramp.js +2 -0
  231. package/lib/module/types/Onramp.js.map +1 -0
  232. package/lib/module/types/PaymentSheet.js.map +1 -1
  233. package/lib/module/types/index.js +1 -1
  234. package/lib/module/types/index.js.map +1 -1
  235. package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -1
  236. package/lib/typescript/src/connect/Components.d.ts +23 -0
  237. package/lib/typescript/src/connect/Components.d.ts.map +1 -0
  238. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts +22 -0
  239. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts.map +1 -0
  240. package/lib/typescript/src/connect/EmbeddedComponent.d.ts +18 -0
  241. package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -0
  242. package/lib/typescript/src/connect/ModalCloseButton.d.ts +7 -0
  243. package/lib/typescript/src/connect/ModalCloseButton.d.ts.map +1 -0
  244. package/lib/typescript/src/connect/NavigationBar.d.ts +8 -0
  245. package/lib/typescript/src/connect/NavigationBar.d.ts.map +1 -0
  246. package/lib/typescript/src/connect/connectTypes.d.ts +464 -0
  247. package/lib/typescript/src/connect/connectTypes.d.ts.map +1 -0
  248. package/lib/typescript/src/events.d.ts +3 -0
  249. package/lib/typescript/src/events.d.ts.map +1 -1
  250. package/lib/typescript/src/functions.d.ts.map +1 -1
  251. package/lib/typescript/src/helpers.d.ts.map +1 -1
  252. package/lib/typescript/src/hooks/useOnramp.d.ts +158 -0
  253. package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -0
  254. package/lib/typescript/src/index.d.ts +4 -0
  255. package/lib/typescript/src/index.d.ts.map +1 -1
  256. package/lib/typescript/src/plugin/withStripe.d.ts +15 -0
  257. package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -1
  258. package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts +14 -0
  259. package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts.map +1 -0
  260. package/lib/typescript/src/specs/NativeNavigationBar.d.ts +11 -0
  261. package/lib/typescript/src/specs/NativeNavigationBar.d.ts.map +1 -0
  262. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +28 -0
  263. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -0
  264. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -0
  265. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  266. package/lib/typescript/src/types/Errors.d.ts +5 -0
  267. package/lib/typescript/src/types/Errors.d.ts.map +1 -1
  268. package/lib/typescript/src/types/Onramp.d.ts +275 -0
  269. package/lib/typescript/src/types/Onramp.d.ts.map +1 -0
  270. package/lib/typescript/src/types/PaymentSheet.d.ts +7 -0
  271. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  272. package/lib/typescript/src/types/index.d.ts +7 -1
  273. package/lib/typescript/src/types/index.d.ts.map +1 -1
  274. package/package.json +24 -12
  275. package/src/components/StripeProvider.tsx +5 -0
  276. package/src/connect/Components.tsx +279 -0
  277. package/src/connect/ConnectComponentsProvider.tsx +93 -0
  278. package/src/connect/EmbeddedComponent.tsx +407 -0
  279. package/src/connect/ModalCloseButton.tsx +44 -0
  280. package/src/connect/NavigationBar.tsx +29 -0
  281. package/src/connect/connectTypes.ts +626 -0
  282. package/src/events.ts +22 -0
  283. package/src/hooks/useOnramp.tsx +334 -0
  284. package/src/index.tsx +13 -0
  285. package/src/plugin/withStripe.ts +104 -7
  286. package/src/specs/NativeConnectAccountOnboardingView.ts +19 -0
  287. package/src/specs/NativeNavigationBar.ts +16 -0
  288. package/src/specs/NativeOnrampSdkModule.ts +47 -0
  289. package/src/specs/NativeStripeSdkModule.ts +5 -0
  290. package/src/types/Errors.ts +6 -0
  291. package/src/types/Onramp.ts +317 -0
  292. package/src/types/PaymentSheet.ts +7 -0
  293. package/src/types/index.ts +8 -0
  294. package/stripe-react-native.podspec +20 -7
@@ -3,7 +3,7 @@ package com.reactnativestripesdk
3
3
  import android.annotation.SuppressLint
4
4
  import android.content.Context
5
5
  import android.content.res.Configuration
6
- import android.graphics.Color
6
+ import androidx.core.graphics.toColorInt
7
7
  import com.facebook.react.bridge.Arguments
8
8
  import com.facebook.react.bridge.ReadableMap
9
9
  import com.facebook.react.bridge.ReadableType
@@ -34,8 +34,8 @@ fun buildPaymentSheetAppearance(
34
34
 
35
35
  val builder = PaymentSheet.Appearance.Builder()
36
36
  builder.typography(buildTypography(userParams?.getMap(PaymentSheetAppearanceKeys.FONT), context))
37
- builder.colorsLight(buildColorsBuilder(lightColorParams).buildLight())
38
- builder.colorsDark(buildColorsBuilder(darkColorParams).buildDark())
37
+ builder.colorsLight(buildColorsBuilder(isLightMode = true, lightColorParams).build())
38
+ builder.colorsDark(buildColorsBuilder(isLightMode = false, darkColorParams).build())
39
39
  builder.shapes(buildShapes(userParams?.getMap(PaymentSheetAppearanceKeys.SHAPES)))
40
40
  builder.primaryButton(
41
41
  buildPrimaryButton(
@@ -48,6 +48,7 @@ fun buildPaymentSheetAppearance(
48
48
  return builder.build()
49
49
  }
50
50
 
51
+ @SuppressLint("RestrictedApi")
51
52
  @OptIn(AppearanceAPIAdditionsPreview::class)
52
53
  private fun buildTypography(
53
54
  fontParams: ReadableMap?,
@@ -74,7 +75,7 @@ private fun buildTypography(
74
75
  private fun colorFromHex(hexString: String?): Int? =
75
76
  hexString?.trim()?.replace("#", "")?.let {
76
77
  if (it.length == 6 || it.length == 8) {
77
- Color.parseColor("#$it")
78
+ "#$it".toColorInt()
78
79
  } else {
79
80
  throw PaymentSheetAppearanceException(
80
81
  "Failed to set Payment Sheet appearance. Expected hex string of length 6 or 8, but received: $it",
@@ -82,8 +83,17 @@ private fun colorFromHex(hexString: String?): Int? =
82
83
  }
83
84
  }
84
85
 
85
- private fun buildColorsBuilder(colorParams: ReadableMap?): PaymentSheet.Colors.Builder {
86
- val builder = PaymentSheet.Colors.Builder()
86
+ @SuppressLint("RestrictedApi")
87
+ private fun buildColorsBuilder(
88
+ isLightMode: Boolean,
89
+ colorParams: ReadableMap?,
90
+ ): PaymentSheet.Colors.Builder {
91
+ val builder =
92
+ if (isLightMode) {
93
+ PaymentSheet.Colors.Builder.light()
94
+ } else {
95
+ PaymentSheet.Colors.Builder.dark()
96
+ }
87
97
 
88
98
  colorFromHex(colorParams?.getString(PaymentSheetAppearanceKeys.PRIMARY))?.let {
89
99
  builder.primary(it)
@@ -132,6 +142,7 @@ private fun buildColorsBuilder(colorParams: ReadableMap?): PaymentSheet.Colors.B
132
142
  return builder
133
143
  }
134
144
 
145
+ @SuppressLint("RestrictedApi")
135
146
  private fun buildShapes(shapeParams: ReadableMap?): PaymentSheet.Shapes {
136
147
  val builder = PaymentSheet.Shapes.Builder()
137
148
 
@@ -146,6 +157,7 @@ private fun buildShapes(shapeParams: ReadableMap?): PaymentSheet.Shapes {
146
157
  return builder.build()
147
158
  }
148
159
 
160
+ @SuppressLint("RestrictedApi")
149
161
  private fun buildPrimaryButton(
150
162
  params: ReadableMap?,
151
163
  context: Context,
@@ -162,9 +174,9 @@ private fun buildPrimaryButton(
162
174
 
163
175
  return PaymentSheet.PrimaryButton(
164
176
  colorsLight =
165
- buildPrimaryButtonColors(lightColorParams, context).buildLight(),
177
+ buildPrimaryButtonColors(true, lightColorParams, context).build(),
166
178
  colorsDark =
167
- buildPrimaryButtonColors(darkColorParams, context).buildDark(),
179
+ buildPrimaryButtonColors(false, darkColorParams, context).build(),
168
180
  shape =
169
181
  PaymentSheet.PrimaryButtonShape(
170
182
  cornerRadiusDp =
@@ -181,12 +193,19 @@ private fun buildPrimaryButton(
181
193
  )
182
194
  }
183
195
 
196
+ @SuppressLint("RestrictedApi")
184
197
  @Throws(PaymentSheetAppearanceException::class)
185
198
  private fun buildPrimaryButtonColors(
199
+ isLightMode: Boolean,
186
200
  colorParams: ReadableMap,
187
201
  context: Context,
188
202
  ): PaymentSheet.PrimaryButtonColors.Builder {
189
- val builder = PaymentSheet.PrimaryButtonColors.Builder()
203
+ val builder =
204
+ if (isLightMode) {
205
+ PaymentSheet.PrimaryButtonColors.Builder.light()
206
+ } else {
207
+ PaymentSheet.PrimaryButtonColors.Builder.dark()
208
+ }
190
209
 
191
210
  // TODO: Why is background a string but successBackgroundColor a "dynamic" color?
192
211
  // https://stripe.dev/stripe-react-native/api-reference/types/PaymentSheet.PrimaryButtonColorConfig.html
@@ -236,16 +255,23 @@ private fun buildEmbeddedAppearance(
236
255
  val separatorInsetsParams =
237
256
  flatParams?.getMap(PaymentSheetAppearanceKeys.SEPARATOR_INSETS)
238
257
 
239
- val flatRadioColorsBuilder =
258
+ val flatRadioLightColorsBuilder =
240
259
  PaymentSheet.Appearance.Embedded.RowStyle.FlatWithRadio.Colors
241
- .Builder()
260
+ .Builder
261
+ .light()
262
+
263
+ val flatRadioDarkColorsBuilder =
264
+ PaymentSheet.Appearance.Embedded.RowStyle.FlatWithRadio.Colors
265
+ .Builder
266
+ .dark()
242
267
 
243
268
  dynamicColorFromParams(
244
269
  context,
245
270
  flatParams,
246
271
  PaymentSheetAppearanceKeys.SEPARATOR_COLOR,
247
272
  )?.let {
248
- flatRadioColorsBuilder.separatorColor(it)
273
+ flatRadioLightColorsBuilder.separatorColor(it)
274
+ flatRadioDarkColorsBuilder.separatorColor(it)
249
275
  }
250
276
 
251
277
  dynamicColorFromParams(
@@ -253,7 +279,8 @@ private fun buildEmbeddedAppearance(
253
279
  radioParams,
254
280
  PaymentSheetAppearanceKeys.SELECTED_COLOR,
255
281
  )?.let {
256
- flatRadioColorsBuilder.selectedColor(it)
282
+ flatRadioLightColorsBuilder.selectedColor(it)
283
+ flatRadioDarkColorsBuilder.selectedColor(it)
257
284
  }
258
285
 
259
286
  dynamicColorFromParams(
@@ -261,7 +288,8 @@ private fun buildEmbeddedAppearance(
261
288
  radioParams,
262
289
  PaymentSheetAppearanceKeys.UNSELECTED_COLOR,
263
290
  )?.let {
264
- flatRadioColorsBuilder.unselectedColor(it)
291
+ flatRadioLightColorsBuilder.unselectedColor(it)
292
+ flatRadioDarkColorsBuilder.unselectedColor(it)
265
293
  }
266
294
 
267
295
  val rowStyleBuilder =
@@ -292,32 +320,39 @@ private fun buildEmbeddedAppearance(
292
320
  rowStyleBuilder.additionalVerticalInsetsDp(it)
293
321
  }
294
322
 
295
- rowStyleBuilder.colorsLight(flatRadioColorsBuilder.buildLight())
296
- rowStyleBuilder.colorsDark(flatRadioColorsBuilder.buildDark())
323
+ rowStyleBuilder.colorsLight(flatRadioLightColorsBuilder.build())
324
+ rowStyleBuilder.colorsDark(flatRadioDarkColorsBuilder.build())
297
325
 
298
326
  embeddedBuilder.rowStyle(rowStyleBuilder.build())
299
327
  }
300
328
 
301
329
  "flatWithCheckmark" -> {
302
- val flatParams = rowParams?.getMap(PaymentSheetAppearanceKeys.FLAT)
330
+ val flatParams = rowParams.getMap(PaymentSheetAppearanceKeys.FLAT)
303
331
  val checkmarkParams = flatParams?.getMap(PaymentSheetAppearanceKeys.CHECKMARK)
304
332
  val separatorInsetsParams =
305
333
  flatParams?.getMap(PaymentSheetAppearanceKeys.SEPARATOR_INSETS)
306
334
 
307
- val flatCheckmarkColorsBuilder =
335
+ val flatCheckmarkLightColorsBuilder =
308
336
  PaymentSheet.Appearance.Embedded.RowStyle.FlatWithCheckmark.Colors
309
- .Builder()
337
+ .Builder
338
+ .light()
339
+ val flatCheckmarkDarkColorsBuilder =
340
+ PaymentSheet.Appearance.Embedded.RowStyle.FlatWithCheckmark.Colors
341
+ .Builder
342
+ .dark()
310
343
 
311
344
  dynamicColorFromParams(
312
345
  context,
313
346
  flatParams,
314
347
  PaymentSheetAppearanceKeys.SEPARATOR_COLOR,
315
348
  )?.let {
316
- flatCheckmarkColorsBuilder.separatorColor(it)
349
+ flatCheckmarkLightColorsBuilder.separatorColor(it)
350
+ flatCheckmarkDarkColorsBuilder.separatorColor(it)
317
351
  }
318
352
 
319
353
  dynamicColorFromParams(context, checkmarkParams, PaymentSheetAppearanceKeys.COLOR)?.let {
320
- flatCheckmarkColorsBuilder.checkmarkColor(it)
354
+ flatCheckmarkLightColorsBuilder.checkmarkColor(it)
355
+ flatCheckmarkDarkColorsBuilder.checkmarkColor(it)
321
356
  }
322
357
 
323
358
  val rowStyleBuilder =
@@ -353,31 +388,38 @@ private fun buildEmbeddedAppearance(
353
388
  }
354
389
 
355
390
  // TODO: The theme is so crazy long, why does each Color thing has the same redundant Theme...
356
- rowStyleBuilder.colorsLight(flatCheckmarkColorsBuilder.buildLight())
357
- rowStyleBuilder.colorsDark(flatCheckmarkColorsBuilder.buildDark())
391
+ rowStyleBuilder.colorsLight(flatCheckmarkLightColorsBuilder.build())
392
+ rowStyleBuilder.colorsDark(flatCheckmarkDarkColorsBuilder.build())
358
393
  embeddedBuilder.rowStyle(rowStyleBuilder.build())
359
394
  }
360
395
 
361
396
  "flatWithDisclosure" -> {
362
- val flatParams = rowParams?.getMap(PaymentSheetAppearanceKeys.FLAT)
397
+ val flatParams = rowParams.getMap(PaymentSheetAppearanceKeys.FLAT)
363
398
  val disclosureParams = flatParams?.getMap(PaymentSheetAppearanceKeys.DISCLOSURE)
364
399
  val separatorInsetsParams =
365
400
  flatParams?.getMap(PaymentSheetAppearanceKeys.SEPARATOR_INSETS)
366
401
 
367
- val flatDisclosureColorsBuilder =
402
+ val flatDisclosureLightColorsBuilder =
368
403
  PaymentSheet.Appearance.Embedded.RowStyle.FlatWithDisclosure.Colors
369
- .Builder()
404
+ .Builder
405
+ .light()
406
+ val flatDisclosureDarkColorsBuilder =
407
+ PaymentSheet.Appearance.Embedded.RowStyle.FlatWithDisclosure.Colors
408
+ .Builder
409
+ .dark()
370
410
 
371
411
  dynamicColorFromParams(
372
412
  context,
373
413
  flatParams,
374
414
  PaymentSheetAppearanceKeys.SEPARATOR_COLOR,
375
415
  )?.let {
376
- flatDisclosureColorsBuilder.separatorColor(it)
416
+ flatDisclosureLightColorsBuilder.separatorColor(it)
417
+ flatDisclosureDarkColorsBuilder.separatorColor(it)
377
418
  }
378
419
 
379
420
  dynamicColorFromParams(context, disclosureParams, PaymentSheetAppearanceKeys.COLOR)?.let {
380
- flatDisclosureColorsBuilder.disclosureColor(it)
421
+ flatDisclosureLightColorsBuilder.disclosureColor(it)
422
+ flatDisclosureDarkColorsBuilder.disclosureColor(it)
381
423
  }
382
424
 
383
425
  val rowStyleBuilder =
@@ -408,8 +450,8 @@ private fun buildEmbeddedAppearance(
408
450
  rowStyleBuilder.additionalVerticalInsetsDp(it)
409
451
  }
410
452
 
411
- rowStyleBuilder.colorsLight(flatDisclosureColorsBuilder.buildLight())
412
- rowStyleBuilder.colorsDark(flatDisclosureColorsBuilder.buildDark())
453
+ rowStyleBuilder.colorsLight(flatDisclosureLightColorsBuilder.build())
454
+ rowStyleBuilder.colorsDark(flatDisclosureDarkColorsBuilder.build())
413
455
 
414
456
  embeddedBuilder.rowStyle(rowStyleBuilder.build())
415
457
  }
@@ -516,6 +558,7 @@ private fun getFontResId(
516
558
  )
517
559
  }
518
560
 
561
+ @SuppressLint("DiscouragedApi")
519
562
  val id = context.resources.getIdentifier(fontFileName, "font", context.packageName)
520
563
  if (id == 0) {
521
564
  throw PaymentSheetAppearanceException("$fontErrorPrefix Failed to find font: $fontFileName")
@@ -3,7 +3,6 @@ package com.reactnativestripesdk
3
3
  import android.annotation.SuppressLint
4
4
  import android.app.Activity
5
5
  import android.app.Application
6
- import android.content.Context
7
6
  import android.content.Intent
8
7
  import android.graphics.Bitmap
9
8
  import android.graphics.Canvas
@@ -14,14 +13,13 @@ import android.os.Handler
14
13
  import android.os.Looper
15
14
  import android.util.Base64
16
15
  import android.util.Log
17
- import androidx.appcompat.content.res.AppCompatResources
16
+ import androidx.core.graphics.createBitmap
18
17
  import androidx.core.graphics.drawable.DrawableCompat
19
18
  import com.facebook.react.bridge.Arguments
20
19
  import com.facebook.react.bridge.Promise
21
20
  import com.facebook.react.bridge.ReactApplicationContext
22
21
  import com.facebook.react.bridge.ReadableMap
23
22
  import com.facebook.react.bridge.WritableMap
24
- import com.facebook.react.bridge.WritableNativeMap
25
23
  import com.reactnativestripesdk.addresssheet.AddressSheetView
26
24
  import com.reactnativestripesdk.utils.ErrorType
27
25
  import com.reactnativestripesdk.utils.KeepJsAwakeTask
@@ -33,8 +31,8 @@ import com.reactnativestripesdk.utils.createError
33
31
  import com.reactnativestripesdk.utils.createResult
34
32
  import com.reactnativestripesdk.utils.forEachKey
35
33
  import com.reactnativestripesdk.utils.getBooleanOr
36
- import com.reactnativestripesdk.utils.getIntOr
37
- import com.reactnativestripesdk.utils.isEmpty
34
+ import com.reactnativestripesdk.utils.getIntegerList
35
+ import com.reactnativestripesdk.utils.getStringList
38
36
  import com.reactnativestripesdk.utils.mapFromConfirmationToken
39
37
  import com.reactnativestripesdk.utils.mapFromCustomPaymentMethod
40
38
  import com.reactnativestripesdk.utils.mapFromPaymentMethod
@@ -103,7 +101,7 @@ class PaymentSheetManager(
103
101
  val allowsDelayedPaymentMethods = arguments.getBooleanOr("allowsDelayedPaymentMethods", false)
104
102
  val billingDetailsMap = arguments.getMap("defaultBillingDetails")
105
103
  val billingConfigParams = arguments.getMap("billingDetailsCollectionConfiguration")
106
- val paymentMethodOrder = arguments.getStringArrayList("paymentMethodOrder")
104
+ val paymentMethodOrder = arguments.getStringList("paymentMethodOrder")
107
105
  val allowsRemovalOfLastSavedPaymentMethod =
108
106
  arguments.getBooleanOr("allowsRemovalOfLastSavedPaymentMethod", true)
109
107
  paymentIntentClientSecret = arguments.getString("paymentIntentClientSecret").orEmpty()
@@ -144,9 +142,9 @@ class PaymentSheetManager(
144
142
  PaymentOptionResultCallback { paymentOptionResult ->
145
143
  val result =
146
144
  paymentOptionResult.paymentOption?.let {
147
- val bitmap = getBitmapFromVectorDrawable(context, it.drawableResourceId)
145
+ val bitmap = getBitmapFromDrawable(it.icon())
148
146
  val imageString = getBase64FromBitmap(bitmap)
149
- val option: WritableMap = WritableNativeMap()
147
+ val option: WritableMap = Arguments.createMap()
150
148
  option.putString("label", it.label)
151
149
  option.putString("image", imageString)
152
150
  val additionalFields: Map<String, Any> = mapOf("didCancel" to paymentOptionResult.didCancel)
@@ -191,7 +189,7 @@ class PaymentSheetManager(
191
189
  }
192
190
 
193
191
  is PaymentSheetResult.Completed -> {
194
- resolvePaymentResult(WritableNativeMap())
192
+ resolvePaymentResult(Arguments.createMap())
195
193
  paymentSheet = null
196
194
  flowController = null
197
195
  }
@@ -252,36 +250,9 @@ class PaymentSheetManager(
252
250
  }
253
251
  }
254
252
 
255
- val billingDetailsConfig =
256
- PaymentSheet.BillingDetailsCollectionConfiguration(
257
- name = mapToCollectionMode(billingConfigParams?.getString("name")),
258
- phone = mapToCollectionMode(billingConfigParams?.getString("phone")),
259
- email = mapToCollectionMode(billingConfigParams?.getString("email")),
260
- address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
261
- attachDefaultsToPaymentMethod =
262
- billingConfigParams?.getBooleanOr("attachDefaultsToPaymentMethod", false) ?: false,
263
- )
253
+ val billingDetailsConfig = buildBillingDetailsCollectionConfiguration(billingConfigParams)
264
254
 
265
- var defaultBillingDetails: PaymentSheet.BillingDetails? = null
266
- if (billingDetailsMap != null) {
267
- val addressMap = billingDetailsMap.getMap("address")
268
- val address =
269
- PaymentSheet.Address(
270
- addressMap?.getString("city"),
271
- addressMap?.getString("country"),
272
- addressMap?.getString("line1"),
273
- addressMap?.getString("line2"),
274
- addressMap?.getString("postalCode"),
275
- addressMap?.getString("state"),
276
- )
277
- defaultBillingDetails =
278
- PaymentSheet.BillingDetails(
279
- address,
280
- billingDetailsMap.getString("email"),
281
- billingDetailsMap.getString("name"),
282
- billingDetailsMap.getString("phone"),
283
- )
284
- }
255
+ val defaultBillingDetails = buildBillingDetails(billingDetailsMap)
285
256
  val configurationBuilder =
286
257
  PaymentSheet.Configuration
287
258
  .Builder(merchantDisplayName)
@@ -294,7 +265,7 @@ class PaymentSheetManager(
294
265
  .link(linkConfig)
295
266
  .billingDetailsCollectionConfiguration(billingDetailsConfig)
296
267
  .preferredNetworks(
297
- mapToPreferredNetworks(arguments.getIntegerArrayList("preferredNetworks")),
268
+ mapToPreferredNetworks(arguments.getIntegerList("preferredNetworks")),
298
269
  ).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
299
270
  .cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
300
271
  .customPaymentMethods(parseCustomPaymentMethods(arguments.getMap("customPaymentMethodConfiguration")))
@@ -308,7 +279,7 @@ class PaymentSheetManager(
308
279
 
309
280
  paymentSheetConfiguration = configurationBuilder.build()
310
281
 
311
- if (arguments.getBoolean("customFlow") == true) {
282
+ if (arguments.getBooleanOr("customFlow", false)) {
312
283
  flowController =
313
284
  if (intentConfiguration != null) {
314
285
  val builder =
@@ -354,7 +325,7 @@ class PaymentSheetManager(
354
325
  .confirmCustomPaymentMethodCallback(this)
355
326
  .build(activity, signal)
356
327
  }
357
- initPromise.resolve(WritableNativeMap())
328
+ initPromise.resolve(Arguments.createMap())
358
329
  }
359
330
  }
360
331
 
@@ -444,13 +415,13 @@ class PaymentSheetManager(
444
415
  PaymentSheet.FlowController.ConfigCallback { _, _ ->
445
416
  val result =
446
417
  flowController?.getPaymentOption()?.let {
447
- val bitmap = getBitmapFromVectorDrawable(context, it.drawableResourceId)
418
+ val bitmap = getBitmapFromDrawable(it.icon())
448
419
  val imageString = getBase64FromBitmap(bitmap)
449
- val option: WritableMap = WritableNativeMap()
420
+ val option: WritableMap = Arguments.createMap()
450
421
  option.putString("label", it.label)
451
422
  option.putString("image", imageString)
452
423
  createResult("paymentOption", option)
453
- } ?: run { WritableNativeMap() }
424
+ } ?: run { Arguments.createMap() }
454
425
  initPromise.resolve(result)
455
426
  }
456
427
 
@@ -571,165 +542,21 @@ class PaymentSheetManager(
571
542
  }
572
543
 
573
544
  companion object {
574
- private val mapIntToButtonType =
575
- mapOf(
576
- 1 to PaymentSheet.GooglePayConfiguration.ButtonType.Buy,
577
- 6 to PaymentSheet.GooglePayConfiguration.ButtonType.Book,
578
- 5 to PaymentSheet.GooglePayConfiguration.ButtonType.Checkout,
579
- 4 to PaymentSheet.GooglePayConfiguration.ButtonType.Donate,
580
- 11 to PaymentSheet.GooglePayConfiguration.ButtonType.Order,
581
- 1000 to PaymentSheet.GooglePayConfiguration.ButtonType.Pay,
582
- 7 to PaymentSheet.GooglePayConfiguration.ButtonType.Subscribe,
583
- 1001 to PaymentSheet.GooglePayConfiguration.ButtonType.Plain,
584
- )
585
-
586
545
  internal fun createMissingInitError(): WritableMap =
587
546
  createError(
588
547
  PaymentSheetErrorType.Failed.toString(),
589
548
  "No payment sheet has been initialized yet. You must call `initPaymentSheet` before `presentPaymentSheet`.",
590
549
  )
591
-
592
- internal fun buildGooglePayConfig(params: ReadableMap?): PaymentSheet.GooglePayConfiguration? {
593
- if (params == null || params.isEmpty()) {
594
- return null
595
- }
596
-
597
- val countryCode = params.getString("merchantCountryCode").orEmpty()
598
- val currencyCode = params.getString("currencyCode").orEmpty()
599
- val testEnv = params.getBoolean("testEnv")
600
- val amount = params.getString("amount")?.toLongOrNull()
601
- val label = params.getString("label")
602
- val buttonType =
603
- mapIntToButtonType.get(params.getIntOr("buttonType", 0))
604
- ?: PaymentSheet.GooglePayConfiguration.ButtonType.Pay
605
-
606
- return PaymentSheet.GooglePayConfiguration(
607
- environment =
608
- if (testEnv) {
609
- PaymentSheet.GooglePayConfiguration.Environment.Test
610
- } else {
611
- PaymentSheet.GooglePayConfiguration.Environment.Production
612
- },
613
- countryCode = countryCode,
614
- currencyCode = currencyCode,
615
- amount = amount,
616
- label = label,
617
- buttonType = buttonType,
618
- )
619
- }
620
-
621
- internal fun buildLinkConfig(params: ReadableMap?): PaymentSheet.LinkConfiguration {
622
- if (params == null) {
623
- return PaymentSheet.LinkConfiguration()
624
- }
625
-
626
- val display = mapStringToLinkDisplay(params.getString("display"))
627
-
628
- return PaymentSheet.LinkConfiguration(
629
- display = display,
630
- )
631
- }
632
-
633
- private fun mapStringToLinkDisplay(value: String?): PaymentSheet.LinkConfiguration.Display =
634
- when (value) {
635
- "automatic" -> PaymentSheet.LinkConfiguration.Display.Automatic
636
- "never" -> PaymentSheet.LinkConfiguration.Display.Never
637
- else -> PaymentSheet.LinkConfiguration.Display.Automatic
638
- }
639
-
640
- @Throws(PaymentSheetException::class)
641
- internal fun buildIntentConfiguration(intentConfigurationParams: ReadableMap?): PaymentSheet.IntentConfiguration? {
642
- if (intentConfigurationParams == null) {
643
- return null
644
- }
645
- val modeParams =
646
- intentConfigurationParams.getMap("mode")
647
- ?: throw PaymentSheetException(
648
- "If `intentConfiguration` is provided, `intentConfiguration.mode` is required",
649
- )
650
-
651
- return PaymentSheet.IntentConfiguration(
652
- mode = buildIntentConfigurationMode(modeParams),
653
- paymentMethodTypes =
654
- intentConfigurationParams.getStringArrayList("paymentMethodTypes")?.toList()
655
- ?: emptyList(),
656
- )
657
- }
658
-
659
- @OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
660
- private fun buildIntentConfigurationMode(modeParams: ReadableMap): PaymentSheet.IntentConfiguration.Mode =
661
- if (modeParams.hasKey("amount")) {
662
- val currencyCode =
663
- modeParams.getString("currencyCode")
664
- ?: throw PaymentSheetException(
665
- "You must provide a value to intentConfiguration.mode.currencyCode",
666
- )
667
- PaymentSheet.IntentConfiguration.Mode.Payment(
668
- amount = modeParams.getInt("amount").toLong(),
669
- currency = currencyCode,
670
- setupFutureUse = mapToSetupFutureUse(modeParams.getString("setupFutureUsage")),
671
- captureMethod = mapToCaptureMethod(modeParams.getString("captureMethod")),
672
- paymentMethodOptions = mapToPaymentMethodOptions(modeParams.getMap("paymentMethodOptions")),
673
- )
674
- } else {
675
- val setupFutureUsage =
676
- mapToSetupFutureUse(modeParams.getString("setupFutureUsage"))
677
- ?: throw PaymentSheetException(
678
- "You must provide a value to intentConfiguration.mode.setupFutureUsage",
679
- )
680
- PaymentSheet.IntentConfiguration.Mode.Setup(
681
- currency = modeParams.getString("currencyCode"),
682
- setupFutureUse = setupFutureUsage,
683
- )
684
- }
685
-
686
- @Throws(PaymentSheetException::class)
687
- internal fun buildCustomerConfiguration(map: ReadableMap?): PaymentSheet.CustomerConfiguration? {
688
- val customerId = map?.getString("customerId").orEmpty()
689
- val customerEphemeralKeySecret = map?.getString("customerEphemeralKeySecret").orEmpty()
690
- val customerSessionClientSecret = map?.getString("customerSessionClientSecret").orEmpty()
691
- return if (customerSessionClientSecret.isNotEmpty() &&
692
- customerEphemeralKeySecret.isNotEmpty()
693
- ) {
694
- throw PaymentSheetException(
695
- "`customerEphemeralKeySecret` and `customerSessionClientSecret` cannot both be set",
696
- )
697
- } else if (customerId.isNotEmpty() && customerSessionClientSecret.isNotEmpty()) {
698
- PaymentSheet.CustomerConfiguration.createWithCustomerSession(
699
- id = customerId,
700
- clientSecret = customerSessionClientSecret,
701
- )
702
- } else if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) {
703
- PaymentSheet.CustomerConfiguration(
704
- id = customerId,
705
- ephemeralKeySecret = customerEphemeralKeySecret,
706
- )
707
- } else {
708
- null
709
- }
710
- }
711
550
  }
712
551
  }
713
552
 
714
- fun getBitmapFromVectorDrawable(
715
- context: Context?,
716
- drawableId: Int,
717
- ): Bitmap? {
718
- val drawable = AppCompatResources.getDrawable(context!!, drawableId) ?: return null
719
- return getBitmapFromDrawable(drawable)
720
- }
721
-
722
553
  fun getBitmapFromDrawable(drawable: Drawable): Bitmap? {
723
554
  val drawableCompat = DrawableCompat.wrap(drawable).mutate()
724
555
  if (drawableCompat.intrinsicWidth <= 0 || drawableCompat.intrinsicHeight <= 0) {
725
556
  return null
726
557
  }
727
558
  val bitmap =
728
- Bitmap.createBitmap(
729
- drawableCompat.intrinsicWidth,
730
- drawableCompat.intrinsicHeight,
731
- Bitmap.Config.ARGB_8888,
732
- )
559
+ createBitmap(drawableCompat.intrinsicWidth, drawableCompat.intrinsicHeight)
733
560
  bitmap.eraseColor(Color.TRANSPARENT)
734
561
  val canvas = Canvas(bitmap)
735
562
  drawable.setBounds(0, 0, canvas.width, canvas.height)
@@ -747,14 +574,6 @@ fun getBase64FromBitmap(bitmap: Bitmap?): String? {
747
574
  return Base64.encodeToString(imageBytes, Base64.DEFAULT)
748
575
  }
749
576
 
750
- fun mapToCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode =
751
- when (str) {
752
- "automatic" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
753
- "never" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Never
754
- "always" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
755
- else -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
756
- }
757
-
758
577
  fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout =
759
578
  when (str) {
760
579
  "Horizontal" -> PaymentSheet.PaymentMethodLayout.Horizontal
@@ -762,17 +581,7 @@ fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout =
762
581
  else -> PaymentSheet.PaymentMethodLayout.Automatic
763
582
  }
764
583
 
765
- fun mapToAddressCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode =
766
- when (str) {
767
- "automatic" ->
768
- PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
769
-
770
- "never" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Never
771
- "full" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
772
- else -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
773
- }
774
-
775
- fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse? =
584
+ internal fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse? =
776
585
  when (type) {
777
586
  "OffSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OffSession
778
587
  "OnSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OnSession
@@ -780,7 +589,7 @@ fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFu
780
589
  else -> null
781
590
  }
782
591
 
783
- fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureMethod =
592
+ internal fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureMethod =
784
593
  when (type) {
785
594
  "Automatic" -> PaymentSheet.IntentConfiguration.CaptureMethod.Automatic
786
595
  "Manual" -> PaymentSheet.IntentConfiguration.CaptureMethod.Manual
@@ -789,7 +598,7 @@ fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureM
789
598
  }
790
599
 
791
600
  @OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
792
- fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfiguration.Mode.Payment.PaymentMethodOptions? {
601
+ internal fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfiguration.Mode.Payment.PaymentMethodOptions? {
793
602
  val sfuMap = options?.getMap("setupFutureUsageValues")
794
603
  val paymentMethodToSfuMap = mutableMapOf<PaymentMethod.Type, PaymentSheet.IntentConfiguration.SetupFutureUse>()
795
604
  sfuMap?.forEachKey { code ->
@@ -807,38 +616,3 @@ fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfigu
807
616
  null
808
617
  }
809
618
  }
810
-
811
- fun mapToCardBrandAcceptance(params: ReadableMap?): PaymentSheet.CardBrandAcceptance {
812
- val cardBrandAcceptanceParams = params?.getMap("cardBrandAcceptance") ?: return PaymentSheet.CardBrandAcceptance.all()
813
- val filter = cardBrandAcceptanceParams.getString("filter") ?: return PaymentSheet.CardBrandAcceptance.all()
814
-
815
- return when (filter) {
816
- "all" -> PaymentSheet.CardBrandAcceptance.all()
817
- "allowed" -> {
818
- val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
819
- val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
820
- if (brandCategories.isEmpty()) {
821
- return PaymentSheet.CardBrandAcceptance.all()
822
- }
823
- PaymentSheet.CardBrandAcceptance.allowed(brandCategories)
824
- }
825
- "disallowed" -> {
826
- val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
827
- val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
828
- if (brandCategories.isEmpty()) {
829
- return PaymentSheet.CardBrandAcceptance.all()
830
- }
831
- PaymentSheet.CardBrandAcceptance.disallowed(brandCategories)
832
- }
833
- else -> PaymentSheet.CardBrandAcceptance.all()
834
- }
835
- }
836
-
837
- fun mapToCardBrandCategory(brand: String): PaymentSheet.CardBrandAcceptance.BrandCategory? =
838
- when (brand) {
839
- "visa" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Visa
840
- "mastercard" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Mastercard
841
- "amex" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Amex
842
- "discover" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Discover
843
- else -> null
844
- }