@stripe/stripe-react-native 0.55.1 → 0.57.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 (126) hide show
  1. package/android/gradle.properties +1 -1
  2. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +4 -3
  3. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +7 -6
  4. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +11 -11
  5. package/android/src/main/java/com/reactnativestripesdk/{CollectBankAccountLauncherFragment.kt → CollectBankAccountLauncherManager.kt} +21 -44
  6. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +17 -24
  7. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +8 -0
  8. package/android/src/main/java/com/reactnativestripesdk/{FinancialConnectionsSheetFragment.kt → FinancialConnectionsSheetManager.kt} +30 -77
  9. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +107 -0
  10. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherManager.kt +37 -0
  11. package/android/src/main/java/com/reactnativestripesdk/{PaymentLauncherFragment.kt → PaymentLauncherManager.kt} +39 -77
  12. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +8 -20
  13. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +366 -483
  14. package/android/src/main/java/com/reactnativestripesdk/{PaymentSheetFragment.kt → PaymentSheetManager.kt} +79 -88
  15. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +3 -2
  16. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +213 -210
  17. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherManager.kt +78 -0
  18. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +48 -35
  19. package/android/src/main/java/com/reactnativestripesdk/customersheet/{CustomerSheetFragment.kt → CustomerSheetManager.kt} +127 -104
  20. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +35 -0
  21. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +47 -12
  22. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +87 -142
  23. package/android/src/main/java/com/reactnativestripesdk/utils/StripeUIManager.kt +62 -0
  24. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerDelegate.java +12 -0
  25. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java +4 -0
  26. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +8 -64
  27. package/ios/AddressSheet/AddressSheetView.swift +1 -1
  28. package/ios/ApplePayButtonManager.m +1 -1
  29. package/ios/ApplePayButtonView.swift +2 -2
  30. package/ios/FinancialConnections.swift +2 -2
  31. package/ios/Mappers.swift +2 -4
  32. package/ios/NewArch/ApplePayButtonComponentView.mm +1 -1
  33. package/ios/OldArch/StripeSdkEventEmitterCompat.h +2 -0
  34. package/ios/OldArch/StripeSdkEventEmitterCompat.m +12 -0
  35. package/ios/PaymentMethodFactory.swift +0 -17
  36. package/ios/PushProvisioning/AddToWalletButtonView.swift +1 -1
  37. package/ios/StripeSdk.mm +14 -0
  38. package/ios/StripeSdkEmitter.swift +2 -0
  39. package/ios/StripeSdkImpl+CustomerSheet.swift +71 -20
  40. package/ios/StripeSdkImpl+PaymentSheet.swift +29 -13
  41. package/ios/StripeSdkImpl.swift +9 -7
  42. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  43. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  44. package/lib/commonjs/components/AddressSheet.js +1 -1
  45. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  46. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  47. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  48. package/lib/commonjs/components/CardField.js +1 -1
  49. package/lib/commonjs/components/CardField.js.map +1 -1
  50. package/lib/commonjs/components/CardForm.js +1 -1
  51. package/lib/commonjs/components/CardForm.js.map +1 -1
  52. package/lib/commonjs/components/CustomerSheet.js +1 -1
  53. package/lib/commonjs/components/CustomerSheet.js.map +1 -1
  54. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  55. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  56. package/lib/commonjs/components/StripeContainer.js +1 -1
  57. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  58. package/lib/commonjs/events.js.map +1 -1
  59. package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
  60. package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
  61. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  62. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  63. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  64. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  65. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  66. package/lib/module/components/AddToWalletButton.js +1 -1
  67. package/lib/module/components/AddToWalletButton.js.map +1 -1
  68. package/lib/module/components/AddressSheet.js +1 -1
  69. package/lib/module/components/AddressSheet.js.map +1 -1
  70. package/lib/module/components/AuBECSDebitForm.js +1 -1
  71. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  72. package/lib/module/components/CardField.js +1 -1
  73. package/lib/module/components/CardField.js.map +1 -1
  74. package/lib/module/components/CardForm.js +1 -1
  75. package/lib/module/components/CardForm.js.map +1 -1
  76. package/lib/module/components/CustomerSheet.js +1 -1
  77. package/lib/module/components/CustomerSheet.js.map +1 -1
  78. package/lib/module/components/PlatformPayButton.js +1 -1
  79. package/lib/module/components/PlatformPayButton.js.map +1 -1
  80. package/lib/module/components/StripeContainer.js +1 -1
  81. package/lib/module/components/StripeContainer.js.map +1 -1
  82. package/lib/module/events.js.map +1 -1
  83. package/lib/module/specs/NativeApplePayButton.js +1 -1
  84. package/lib/module/specs/NativeApplePayButton.js.map +1 -1
  85. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  86. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  87. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  88. package/lib/module/types/PaymentIntent.js.map +1 -1
  89. package/lib/module/types/PaymentSheet.js.map +1 -1
  90. package/lib/typescript/src/components/CustomerSheet.d.ts +1 -1
  91. package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -1
  92. package/lib/typescript/src/events.d.ts +2 -0
  93. package/lib/typescript/src/events.d.ts.map +1 -1
  94. package/lib/typescript/src/specs/NativeApplePayButton.d.ts +1 -1
  95. package/lib/typescript/src/specs/NativeApplePayButton.d.ts.map +1 -1
  96. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -1
  97. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  98. package/lib/typescript/src/types/ConfirmationToken.d.ts +0 -3
  99. package/lib/typescript/src/types/ConfirmationToken.d.ts.map +1 -1
  100. package/lib/typescript/src/types/CustomerSheet.d.ts +70 -12
  101. package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -1
  102. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +2 -4
  103. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
  104. package/lib/typescript/src/types/PaymentIntent.d.ts +1 -9
  105. package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
  106. package/lib/typescript/src/types/PaymentMethod.d.ts +2 -8
  107. package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
  108. package/lib/typescript/src/types/PaymentSheet.d.ts +1 -6
  109. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  110. package/package.json +1 -1
  111. package/src/components/CustomerSheet.tsx +65 -9
  112. package/src/components/PlatformPayButton.tsx +1 -1
  113. package/src/events.ts +2 -0
  114. package/src/specs/NativeApplePayButton.ts +1 -1
  115. package/src/specs/NativeStripeSdkModule.ts +7 -0
  116. package/src/types/ConfirmationToken.ts +0 -3
  117. package/src/types/CustomerSheet.ts +80 -12
  118. package/src/types/EmbeddedPaymentElement.tsx +2 -4
  119. package/src/types/PaymentIntent.ts +0 -10
  120. package/src/types/PaymentMethod.ts +0 -9
  121. package/src/types/PaymentSheet.ts +1 -6
  122. package/stripe-react-native.podspec +1 -1
  123. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +0 -146
  124. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +0 -68
  125. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +0 -102
  126. package/android/src/main/java/com/reactnativestripesdk/utils/StripeFragment.kt +0 -52
@@ -1,12 +1,9 @@
1
1
  package com.reactnativestripesdk.utils
2
2
 
3
3
  import android.annotation.SuppressLint
4
- import android.os.Bundle
5
- import android.util.Log
6
4
  import com.facebook.react.bridge.Arguments
7
5
  import com.facebook.react.bridge.ReadableArray
8
6
  import com.facebook.react.bridge.ReadableMap
9
- import com.facebook.react.bridge.ReadableType
10
7
  import com.facebook.react.bridge.WritableArray
11
8
  import com.facebook.react.bridge.WritableMap
12
9
  import com.facebook.react.bridge.WritableNativeMap
@@ -30,6 +27,7 @@ import com.stripe.android.model.StripeIntent.NextActionType
30
27
  import com.stripe.android.model.Token
31
28
  import com.stripe.android.paymentelement.ExperimentalCustomPaymentMethodsApi
32
29
  import com.stripe.android.paymentsheet.PaymentSheet
30
+ import java.lang.IllegalArgumentException
33
31
 
34
32
  internal fun createResult(
35
33
  key: String,
@@ -138,7 +136,6 @@ internal fun mapPaymentMethodType(type: PaymentMethod.Type?): String =
138
136
  PaymentMethod.Type.CardPresent -> "CardPresent"
139
137
  PaymentMethod.Type.Eps -> "Eps"
140
138
  PaymentMethod.Type.Fpx -> "Fpx"
141
- PaymentMethod.Type.Giropay -> "Giropay"
142
139
  PaymentMethod.Type.GrabPay -> "GrabPay"
143
140
  PaymentMethod.Type.Ideal -> "Ideal"
144
141
  PaymentMethod.Type.Netbanking -> "Netbanking"
@@ -171,7 +168,6 @@ internal fun mapToPaymentMethodType(type: String?): PaymentMethod.Type? =
171
168
  "CardPresent" -> PaymentMethod.Type.CardPresent
172
169
  "Eps" -> PaymentMethod.Type.Eps
173
170
  "Fpx" -> PaymentMethod.Type.Fpx
174
- "Giropay" -> PaymentMethod.Type.Giropay
175
171
  "GrabPay" -> PaymentMethod.Type.GrabPay
176
172
  "Netbanking" -> PaymentMethod.Type.Netbanking
177
173
  "Oxxo" -> PaymentMethod.Type.Oxxo
@@ -665,7 +661,7 @@ internal fun mapToBillingDetails(
665
661
  if (billingDetails == null && cardAddress == null) {
666
662
  return null
667
663
  }
668
- val address = mapToAddress(getMapOrNull(billingDetails, "address"), cardAddress)
664
+ val address = mapToAddress(billingDetails?.getMap("address"), cardAddress)
669
665
  val paymentMethodBillingDetailsBuilder = PaymentMethod.BillingDetails.Builder()
670
666
 
671
667
  if (billingDetails != null) {
@@ -686,7 +682,7 @@ internal fun mapToShippingDetails(shippingDetails: ReadableMap?): ConfirmPayment
686
682
  return null
687
683
  }
688
684
 
689
- val address = mapToAddress(getMapOrNull(shippingDetails, "address"), null)
685
+ val address = mapToAddress(shippingDetails?.getMap("address"), null)
690
686
 
691
687
  return ConfirmPaymentIntentParams.Shipping(
692
688
  name = getValOr(shippingDetails, "name") ?: "",
@@ -694,37 +690,17 @@ internal fun mapToShippingDetails(shippingDetails: ReadableMap?): ConfirmPayment
694
690
  )
695
691
  }
696
692
 
697
- private fun getStringOrNull(
698
- map: ReadableMap?,
699
- key: String,
700
- ): String? = if (map?.hasKey(key) == true) map.getString(key) else null
701
-
702
- fun getIntOrNull(
703
- map: ReadableMap?,
704
- key: String,
705
- ): Int? = if (map?.hasKey(key) == true) map.getInt(key) else null
706
-
707
- fun getMapOrNull(
708
- map: ReadableMap?,
709
- key: String,
710
- ): ReadableMap? = if (map?.hasKey(key) == true) map.getMap(key) else null
711
-
712
- fun getBooleanOrFalse(
713
- map: ReadableMap?,
714
- key: String,
715
- ): Boolean = if (map?.hasKey(key) == true) map.getBoolean(key) else false
716
-
717
693
  private fun convertToUnixTimestamp(timestamp: Long): String = (timestamp * 1000).toString()
718
694
 
719
695
  fun mapToUICustomization(params: ReadableMap): PaymentAuthConfig.Stripe3ds2UiCustomization {
720
- val labelCustomization = getMapOrNull(params, "label")
696
+ val labelCustomization = params.getMap("label")
721
697
  val navigationBarCustomization = params.getMap("navigationBar")
722
- val textBoxCustomization = getMapOrNull(params, "textField")
723
- val submitButtonCustomization = getMapOrNull(params, "submitButton")
724
- val cancelButtonCustomization = getMapOrNull(params, "cancelButton")
725
- val nextButtonCustomization = getMapOrNull(params, "nextButton")
726
- val continueButtonCustomization = getMapOrNull(params, "continueButton")
727
- val resendButtonCustomization = getMapOrNull(params, "resendButton")
698
+ val textBoxCustomization = params.getMap("textField")
699
+ val submitButtonCustomization = params.getMap("submitButton")
700
+ val cancelButtonCustomization = params.getMap("cancelButton")
701
+ val nextButtonCustomization = params.getMap("nextButton")
702
+ val continueButtonCustomization = params.getMap("continueButton")
703
+ val resendButtonCustomization = params.getMap("resendButton")
728
704
 
729
705
  val labelCustomizationBuilder = PaymentAuthConfig.Stripe3ds2LabelCustomization.Builder()
730
706
  val toolbarCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ToolbarCustomization.Builder()
@@ -736,121 +712,121 @@ fun mapToUICustomization(params: ReadableMap): PaymentAuthConfig.Stripe3ds2UiCus
736
712
  val continueButtonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()
737
713
  val resendButtonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()
738
714
 
739
- getStringOrNull(labelCustomization, "headingTextColor")?.let {
715
+ labelCustomization?.getString("headingTextColor")?.let {
740
716
  labelCustomizationBuilder.setHeadingTextColor(it)
741
717
  }
742
- getStringOrNull(labelCustomization, "textColor")?.let {
718
+ labelCustomization?.getString("textColor")?.let {
743
719
  labelCustomizationBuilder.setTextColor(it)
744
720
  }
745
- getIntOrNull(labelCustomization, "headingFontSize")?.let {
721
+ labelCustomization.getIntOrNull("headingFontSize")?.let {
746
722
  labelCustomizationBuilder.setHeadingTextFontSize(it)
747
723
  }
748
- getIntOrNull(labelCustomization, "textFontSize")?.let {
724
+ labelCustomization.getIntOrNull("textFontSize")?.let {
749
725
  labelCustomizationBuilder.setTextFontSize(it)
750
726
  }
751
727
 
752
- getStringOrNull(navigationBarCustomization, "headerText")?.let {
728
+ navigationBarCustomization?.getString("headerText")?.let {
753
729
  toolbarCustomizationBuilder.setHeaderText(it)
754
730
  }
755
- getStringOrNull(navigationBarCustomization, "buttonText")?.let {
731
+ navigationBarCustomization?.getString("buttonText")?.let {
756
732
  toolbarCustomizationBuilder.setButtonText(it)
757
733
  }
758
- getStringOrNull(navigationBarCustomization, "textColor")?.let {
734
+ navigationBarCustomization?.getString("textColor")?.let {
759
735
  toolbarCustomizationBuilder.setTextColor(it)
760
736
  }
761
- getStringOrNull(navigationBarCustomization, "statusBarColor")?.let {
737
+ navigationBarCustomization?.getString("statusBarColor")?.let {
762
738
  toolbarCustomizationBuilder.setStatusBarColor(it)
763
739
  }
764
- getStringOrNull(navigationBarCustomization, "backgroundColor")?.let {
740
+ navigationBarCustomization?.getString("backgroundColor")?.let {
765
741
  toolbarCustomizationBuilder.setBackgroundColor(it)
766
742
  }
767
- getIntOrNull(navigationBarCustomization, "textFontSize")?.let {
743
+ navigationBarCustomization.getIntOrNull("textFontSize")?.let {
768
744
  toolbarCustomizationBuilder.setTextFontSize(it)
769
745
  }
770
746
 
771
- getStringOrNull(textBoxCustomization, "borderColor")?.let {
747
+ textBoxCustomization?.getString("borderColor")?.let {
772
748
  textBoxCustomizationBuilder.setBorderColor(it)
773
749
  }
774
- getStringOrNull(textBoxCustomization, "textColor")?.let {
750
+ textBoxCustomization?.getString("textColor")?.let {
775
751
  textBoxCustomizationBuilder.setTextColor(it)
776
752
  }
777
- getIntOrNull(textBoxCustomization, "borderWidth")?.let {
753
+ textBoxCustomization.getIntOrNull("borderWidth")?.let {
778
754
  textBoxCustomizationBuilder.setBorderWidth(it)
779
755
  }
780
- getIntOrNull(textBoxCustomization, "borderRadius")?.let {
756
+ textBoxCustomization.getIntOrNull("borderRadius")?.let {
781
757
  textBoxCustomizationBuilder.setCornerRadius(it)
782
758
  }
783
- getIntOrNull(textBoxCustomization, "textFontSize")?.let {
759
+ textBoxCustomization.getIntOrNull("textFontSize")?.let {
784
760
  textBoxCustomizationBuilder.setTextFontSize(it)
785
761
  }
786
762
 
787
763
  // Submit button
788
- getStringOrNull(submitButtonCustomization, "backgroundColor")?.let {
764
+ submitButtonCustomization?.getString("backgroundColor")?.let {
789
765
  submitButtonCustomizationBuilder.setBackgroundColor(it)
790
766
  }
791
- getIntOrNull(submitButtonCustomization, "borderRadius")?.let {
767
+ submitButtonCustomization.getIntOrNull("borderRadius")?.let {
792
768
  submitButtonCustomizationBuilder.setCornerRadius(it)
793
769
  }
794
- getStringOrNull(submitButtonCustomization, "textColor")?.let {
770
+ submitButtonCustomization?.getString("textColor")?.let {
795
771
  submitButtonCustomizationBuilder.setTextColor(it)
796
772
  }
797
- getIntOrNull(submitButtonCustomization, "textFontSize")?.let {
773
+ submitButtonCustomization.getIntOrNull("textFontSize")?.let {
798
774
  submitButtonCustomizationBuilder.setTextFontSize(it)
799
775
  }
800
776
 
801
777
  // Cancel button
802
- getStringOrNull(cancelButtonCustomization, "backgroundColor")?.let {
778
+ cancelButtonCustomization?.getString("backgroundColor")?.let {
803
779
  cancelButtonCustomizationBuilder.setBackgroundColor(it)
804
780
  }
805
- getIntOrNull(cancelButtonCustomization, "borderRadius")?.let {
781
+ cancelButtonCustomization.getIntOrNull("borderRadius")?.let {
806
782
  cancelButtonCustomizationBuilder.setCornerRadius(it)
807
783
  }
808
- getStringOrNull(cancelButtonCustomization, "textColor")?.let {
784
+ cancelButtonCustomization?.getString("textColor")?.let {
809
785
  cancelButtonCustomizationBuilder.setTextColor(it)
810
786
  }
811
- getIntOrNull(cancelButtonCustomization, "textFontSize")?.let {
787
+ cancelButtonCustomization.getIntOrNull("textFontSize")?.let {
812
788
  cancelButtonCustomizationBuilder.setTextFontSize(it)
813
789
  }
814
790
 
815
791
  // Continue button
816
- getStringOrNull(continueButtonCustomization, "backgroundColor")?.let {
792
+ continueButtonCustomization?.getString("backgroundColor")?.let {
817
793
  continueButtonCustomizationBuilder.setBackgroundColor(it)
818
794
  }
819
- getIntOrNull(continueButtonCustomization, "borderRadius")?.let {
795
+ continueButtonCustomization.getIntOrNull("borderRadius")?.let {
820
796
  continueButtonCustomizationBuilder.setCornerRadius(it)
821
797
  }
822
- getStringOrNull(continueButtonCustomization, "textColor")?.let {
798
+ continueButtonCustomization?.getString("textColor")?.let {
823
799
  continueButtonCustomizationBuilder.setTextColor(it)
824
800
  }
825
- getIntOrNull(continueButtonCustomization, "textFontSize")?.let {
801
+ continueButtonCustomization.getIntOrNull("textFontSize")?.let {
826
802
  continueButtonCustomizationBuilder.setTextFontSize(it)
827
803
  }
828
804
 
829
805
  // Next button
830
- getStringOrNull(nextButtonCustomization, "backgroundColor")?.let {
806
+ nextButtonCustomization?.getString("backgroundColor")?.let {
831
807
  nextButtonCustomizationBuilder.setBackgroundColor(it)
832
808
  }
833
- getIntOrNull(nextButtonCustomization, "borderRadius")?.let {
809
+ nextButtonCustomization.getIntOrNull("borderRadius")?.let {
834
810
  nextButtonCustomizationBuilder.setCornerRadius(it)
835
811
  }
836
- getStringOrNull(nextButtonCustomization, "textColor")?.let {
812
+ nextButtonCustomization?.getString("textColor")?.let {
837
813
  nextButtonCustomizationBuilder.setTextColor(it)
838
814
  }
839
- getIntOrNull(nextButtonCustomization, "textFontSize")?.let {
815
+ nextButtonCustomization.getIntOrNull("textFontSize")?.let {
840
816
  nextButtonCustomizationBuilder.setTextFontSize(it)
841
817
  }
842
818
 
843
819
  // Resend button
844
- getStringOrNull(resendButtonCustomization, "backgroundColor")?.let {
820
+ resendButtonCustomization?.getString("backgroundColor")?.let {
845
821
  resendButtonCustomizationBuilder.setBackgroundColor(it)
846
822
  }
847
- getIntOrNull(resendButtonCustomization, "borderRadius")?.let {
823
+ resendButtonCustomization.getIntOrNull("borderRadius")?.let {
848
824
  resendButtonCustomizationBuilder.setCornerRadius(it)
849
825
  }
850
- getStringOrNull(resendButtonCustomization, "textColor")?.let {
826
+ resendButtonCustomization?.getString("textColor")?.let {
851
827
  resendButtonCustomizationBuilder.setTextColor(it)
852
828
  }
853
- getIntOrNull(resendButtonCustomization, "textFontSize")?.let {
829
+ resendButtonCustomization.getIntOrNull("textFontSize")?.let {
854
830
  resendButtonCustomizationBuilder.setTextFontSize(it)
855
831
  }
856
832
 
@@ -876,7 +852,7 @@ fun mapToUICustomization(params: ReadableMap): PaymentAuthConfig.Stripe3ds2UiCus
876
852
  PaymentAuthConfig.Stripe3ds2UiCustomization.ButtonType.RESEND,
877
853
  )
878
854
 
879
- getStringOrNull(params, "accentColor")?.let { uiCustomization.setAccentColor(it) }
855
+ params.getString("accentColor")?.let { uiCustomization.setAccentColor(it) }
880
856
 
881
857
  return uiCustomization.build()
882
858
  }
@@ -936,55 +912,6 @@ fun mapToPaymentIntentFutureUsage(type: String?): ConfirmPaymentIntentParams.Set
936
912
  else -> null
937
913
  }
938
914
 
939
- fun toBundleObject(readableMap: ReadableMap?): Bundle {
940
- val result = Bundle()
941
- if (readableMap == null) {
942
- return result
943
- }
944
- val iterator = readableMap.keySetIterator()
945
- while (iterator.hasNextKey()) {
946
- val key = iterator.nextKey()
947
- when (readableMap.getType(key)) {
948
- ReadableType.Null -> result.putString(key, null)
949
- ReadableType.Boolean -> result.putBoolean(key, readableMap.getBoolean(key))
950
- ReadableType.Number ->
951
- try {
952
- val numAsInt = readableMap.getInt(key)
953
- val numAsDouble = readableMap.getDouble(key)
954
- if (numAsDouble - numAsInt != 0.0) {
955
- result.putDouble(key, numAsDouble)
956
- } else {
957
- result.putInt(key, numAsInt)
958
- }
959
- } catch (e: Exception) {
960
- Log.e("toBundleException", "Failed to add number to bundle. Failed on: $key.")
961
- }
962
- ReadableType.String -> result.putString(key, readableMap.getString(key))
963
- ReadableType.Map -> result.putBundle(key, toBundleObject(readableMap.getMap(key)))
964
- ReadableType.Array -> {
965
- val list = readableMap.getArray(key)?.toArrayList()
966
- if (list == null) {
967
- result.putString(key, null)
968
- } else if (list.isEmpty()) {
969
- result.putStringArrayList(key, ArrayList())
970
- } else {
971
- when (list.first()) {
972
- is String -> result.putStringArrayList(key, list as java.util.ArrayList<String>)
973
- is Int -> result.putIntegerArrayList(key, list as java.util.ArrayList<Int>)
974
- else ->
975
- Log.e(
976
- "toBundleException",
977
- "Cannot put arrays of objects into bundles. Failed on: $key.",
978
- )
979
- }
980
- }
981
- }
982
- else -> Log.e("toBundleException", "Could not convert object with key: $key.")
983
- }
984
- }
985
- return result
986
- }
987
-
988
915
  internal fun mapFromShippingContact(googlePayResult: GooglePayResult): WritableMap {
989
916
  val map = WritableNativeMap()
990
917
  map.putString("emailAddress", googlePayResult.email)
@@ -1008,7 +935,7 @@ internal fun mapFromShippingContact(googlePayResult: GooglePayResult): WritableM
1008
935
  return map
1009
936
  }
1010
937
 
1011
- internal fun mapToPreferredNetworks(networksAsInts: ArrayList<Int>?): List<CardBrand> {
938
+ internal fun mapToPreferredNetworks(networksAsInts: List<Int>?): List<CardBrand> {
1012
939
  if (networksAsInts == null) {
1013
940
  return emptyList()
1014
941
  }
@@ -1084,34 +1011,31 @@ private fun Map<String, Any?>.toReadableMap(): ReadableMap {
1084
1011
 
1085
1012
  @OptIn(ExperimentalCustomPaymentMethodsApi::class)
1086
1013
  @SuppressLint("RestrictedApi")
1087
- internal fun parseCustomPaymentMethods(customPaymentMethodConfig: Bundle?): List<PaymentSheet.CustomPaymentMethod> {
1014
+ internal fun parseCustomPaymentMethods(customPaymentMethodConfig: ReadableMap?): List<PaymentSheet.CustomPaymentMethod> {
1088
1015
  if (customPaymentMethodConfig == null) {
1089
1016
  return emptyList()
1090
1017
  }
1091
1018
 
1092
- val configHashMap = customPaymentMethodConfig.getSerializable("customPaymentMethodConfigurationReadableMap") as? HashMap<String, Any>
1093
- if (configHashMap != null) {
1094
- val customPaymentMethods = configHashMap["customPaymentMethods"] as? List<HashMap<String, Any>>
1095
- if (customPaymentMethods != null) {
1096
- val result = mutableListOf<PaymentSheet.CustomPaymentMethod>()
1097
-
1098
- for (customPaymentMethodMap in customPaymentMethods) {
1099
- val id = customPaymentMethodMap["id"] as? String
1100
- if (id != null) {
1101
- val subtitle = customPaymentMethodMap["subtitle"] as? String
1102
- val disableBillingDetailCollection = customPaymentMethodMap["disableBillingDetailCollection"] as? Boolean ?: false
1103
- result.add(
1104
- PaymentSheet.CustomPaymentMethod(
1105
- id = id,
1106
- subtitle = subtitle,
1107
- disableBillingDetailCollection = disableBillingDetailCollection,
1108
- ),
1109
- )
1110
- }
1019
+ val customPaymentMethods = customPaymentMethodConfig.getArray("customPaymentMethods")
1020
+ if (customPaymentMethods != null) {
1021
+ val result = mutableListOf<PaymentSheet.CustomPaymentMethod>()
1022
+
1023
+ customPaymentMethods.forEachMap { customPaymentMethodMap ->
1024
+ val id = customPaymentMethodMap.getString("id")
1025
+ if (id != null) {
1026
+ val subtitle = customPaymentMethodMap.getString("subtitle")
1027
+ val disableBillingDetailCollection = customPaymentMethodMap.getBooleanOr("disableBillingDetailCollection", false)
1028
+ result.add(
1029
+ PaymentSheet.CustomPaymentMethod(
1030
+ id = id,
1031
+ subtitle = subtitle,
1032
+ disableBillingDetailCollection = disableBillingDetailCollection,
1033
+ ),
1034
+ )
1111
1035
  }
1112
-
1113
- return result
1114
1036
  }
1037
+
1038
+ return result
1115
1039
  }
1116
1040
 
1117
1041
  return emptyList()
@@ -1201,3 +1125,24 @@ private fun mapFromAllowRedisplay(allowRedisplay: PaymentMethod.AllowRedisplay?)
1201
1125
  PaymentMethod.AllowRedisplay.UNSPECIFIED -> "unspecified"
1202
1126
  null -> null
1203
1127
  }
1128
+
1129
+ fun readableMapOf(vararg pairs: Pair<String, Any?>): ReadableMap =
1130
+ Arguments.createMap().apply {
1131
+ for ((key, value) in pairs) {
1132
+ when (value) {
1133
+ null -> putNull(key)
1134
+ is String -> putString(key, value)
1135
+ is Boolean -> putBoolean(key, value)
1136
+ is Double -> putDouble(key, value)
1137
+ is Float -> putDouble(key, value.toDouble())
1138
+ is Int -> putInt(key, value)
1139
+ is Long -> putLong(key, value)
1140
+ is ReadableMap -> putMap(key, value)
1141
+ is ReadableArray -> putArray(key, value)
1142
+ else -> {
1143
+ val valueType = value.javaClass.canonicalName
1144
+ throw IllegalArgumentException("Illegal value type $valueType for key \"$key\"")
1145
+ }
1146
+ }
1147
+ }
1148
+ }
@@ -0,0 +1,62 @@
1
+ package com.reactnativestripesdk.utils
2
+
3
+ import android.annotation.SuppressLint
4
+ import androidx.fragment.app.FragmentActivity
5
+ import com.facebook.react.bridge.Promise
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.UiThreadUtil
8
+ import com.stripe.android.core.reactnative.ReactNativeSdkInternal
9
+ import com.stripe.android.core.reactnative.UnregisterSignal
10
+
11
+ @ReactNativeSdkInternal
12
+ @SuppressLint("RestrictedApi")
13
+ abstract class StripeUIManager(
14
+ protected val context: ReactApplicationContext,
15
+ ) {
16
+ protected val signal = UnregisterSignal()
17
+ protected var promise: Promise? = null
18
+ protected var timeout: Long? = null
19
+
20
+ protected open fun onCreate() {}
21
+
22
+ protected abstract fun onPresent()
23
+
24
+ protected open fun onDestroy() {
25
+ signal.unregister()
26
+ }
27
+
28
+ fun create() {
29
+ UiThreadUtil.runOnUiThread {
30
+ onCreate()
31
+ }
32
+ }
33
+
34
+ fun present(
35
+ promise: Promise? = null,
36
+ timeout: Long? = null,
37
+ ) {
38
+ UiThreadUtil.runOnUiThread {
39
+ this.promise = promise
40
+ this.timeout = timeout
41
+ onPresent()
42
+ }
43
+ }
44
+
45
+ fun destroy() {
46
+ UiThreadUtil.runOnUiThread {
47
+ onDestroy()
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Safely get and cast the current activity as an AppCompatActivity. If that fails, the promise
53
+ * provided will be resolved with an error message instructing the user to retry the method.
54
+ */
55
+ protected fun getCurrentActivityOrResolveWithError(promise: Promise?): FragmentActivity? {
56
+ (context.currentActivity as? FragmentActivity)?.let {
57
+ return it
58
+ }
59
+ promise?.resolve(createMissingActivityError())
60
+ return null
61
+ }
62
+ }
@@ -34,6 +34,18 @@ public class ApplePayButtonManagerDelegate<T extends View, U extends BaseViewMan
34
34
  case "borderRadius":
35
35
  mViewManager.setBorderRadius(view, value == null ? 4 : ((Double) value).intValue());
36
36
  break;
37
+ case "hasShippingMethodCallback":
38
+ mViewManager.setHasShippingMethodCallback(view, value == null ? false : (boolean) value);
39
+ break;
40
+ case "hasShippingContactCallback":
41
+ mViewManager.setHasShippingContactCallback(view, value == null ? false : (boolean) value);
42
+ break;
43
+ case "hasCouponCodeCallback":
44
+ mViewManager.setHasCouponCodeCallback(view, value == null ? false : (boolean) value);
45
+ break;
46
+ case "hasOrderTrackingCallback":
47
+ mViewManager.setHasOrderTrackingCallback(view, value == null ? false : (boolean) value);
48
+ break;
37
49
  default:
38
50
  super.setProperty(view, propName, value);
39
51
  }
@@ -16,4 +16,8 @@ public interface ApplePayButtonManagerInterface<T extends View> {
16
16
  void setType(T view, int value);
17
17
  void setButtonStyle(T view, int value);
18
18
  void setBorderRadius(T view, int value);
19
+ void setHasShippingMethodCallback(T view, boolean value);
20
+ void setHasShippingContactCallback(T view, boolean value);
21
+ void setHasCouponCodeCallback(T view, boolean value);
22
+ void setHasOrderTrackingCallback(T view, boolean value);
19
23
  }
@@ -54,70 +54,6 @@ public abstract class NativeStripeSdkModuleSpec extends ReactContextBaseJavaModu
54
54
  invoke(eventName, null);
55
55
  }
56
56
 
57
- protected final void emitOnConfirmHandlerCallback(ReadableMap value) {
58
- invoke("onConfirmHandlerCallback", value);
59
- }
60
-
61
- protected final void emitOnFinancialConnectionsEvent(ReadableMap value) {
62
- invoke("onFinancialConnectionsEvent", value);
63
- }
64
-
65
- protected final void emitOnOrderTrackingCallback() {
66
- invoke("onOrderTrackingCallback");
67
- }
68
-
69
- protected final void emitOnCustomerAdapterFetchPaymentMethodsCallback() {
70
- invoke("onCustomerAdapterFetchPaymentMethodsCallback");
71
- }
72
-
73
- protected final void emitOnCustomerAdapterAttachPaymentMethodCallback(ReadableMap value) {
74
- invoke("onCustomerAdapterAttachPaymentMethodCallback", value);
75
- }
76
-
77
- protected final void emitOnCustomerAdapterDetachPaymentMethodCallback(ReadableMap value) {
78
- invoke("onCustomerAdapterDetachPaymentMethodCallback", value);
79
- }
80
-
81
- protected final void emitOnCustomerAdapterSetSelectedPaymentOptionCallback(ReadableMap value) {
82
- invoke("onCustomerAdapterSetSelectedPaymentOptionCallback", value);
83
- }
84
-
85
- protected final void emitOnCustomerAdapterFetchSelectedPaymentOptionCallback() {
86
- invoke("onCustomerAdapterFetchSelectedPaymentOptionCallback");
87
- }
88
-
89
- protected final void emitOnCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback() {
90
- invoke("onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback");
91
- }
92
-
93
- protected final void emitEmbeddedPaymentElementDidUpdateHeight(ReadableMap value) {
94
- invoke("embeddedPaymentElementDidUpdateHeight", value);
95
- }
96
-
97
- protected final void emitEmbeddedPaymentElementWillPresent() {
98
- invoke("embeddedPaymentElementWillPresent");
99
- }
100
-
101
- protected final void emitEmbeddedPaymentElementDidUpdatePaymentOption(ReadableMap value) {
102
- invoke("embeddedPaymentElementDidUpdatePaymentOption", value);
103
- }
104
-
105
- protected final void emitEmbeddedPaymentElementFormSheetConfirmComplete(ReadableMap value) {
106
- invoke("embeddedPaymentElementFormSheetConfirmComplete", value);
107
- }
108
-
109
- protected final void emitEmbeddedPaymentElementRowSelectionImmediateAction() {
110
- invoke("embeddedPaymentElementRowSelectionImmediateAction");
111
- }
112
-
113
- protected final void emitEmbeddedPaymentElementLoadingFailed(ReadableMap value) {
114
- invoke("embeddedPaymentElementLoadingFailed", value);
115
- }
116
-
117
- protected final void emitOnCustomPaymentMethodConfirmHandlerCallback(ReadableMap value) {
118
- invoke("onCustomPaymentMethodConfirmHandlerCallback", value);
119
- }
120
-
121
57
  @ReactMethod
122
58
  @DoNotStrip
123
59
  public abstract void initialise(ReadableMap params, Promise promise);
@@ -304,6 +240,14 @@ public abstract class NativeStripeSdkModuleSpec extends ReactContextBaseJavaModu
304
240
  @DoNotStrip
305
241
  public abstract void customerAdapterSetupIntentClientSecretForCustomerAttachCallback(String clientSecret, Promise promise);
306
242
 
243
+ @ReactMethod
244
+ @DoNotStrip
245
+ public abstract void clientSecretProviderSetupIntentClientSecretCallback(String setupIntentClientSecret, Promise promise);
246
+
247
+ @ReactMethod
248
+ @DoNotStrip
249
+ public abstract void clientSecretProviderCustomerSessionClientSecretCallback(ReadableMap customerSessionClientSecret, Promise promise);
250
+
307
251
  @ReactMethod
308
252
  @DoNotStrip
309
253
  public abstract void createEmbeddedPaymentElement(ReadableMap intentConfig, ReadableMap configuration, Promise promise);
@@ -76,7 +76,7 @@ public class AddressSheetView: UIView {
76
76
  let navigationController = UINavigationController(rootViewController: addressViewController!)
77
77
  navigationController.modalPresentationStyle = getModalPresentationStyle()
78
78
  navigationController.modalTransitionStyle = getModalTransitionStyle()
79
- let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
79
+ let vc = findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
80
80
  vc.present(navigationController, animated: true)
81
81
  }
82
82
 
@@ -5,7 +5,7 @@
5
5
  @interface RCT_EXTERN_MODULE(ApplePayButtonManager, RCTViewManager)
6
6
  RCT_EXPORT_VIEW_PROPERTY(type, NSNumber)
7
7
  RCT_EXPORT_VIEW_PROPERTY(buttonStyle, NSNumber)
8
- RCT_EXPORT_VIEW_PROPERTY(borderRadius, NSNumber)
8
+ RCT_EXPORT_VIEW_PROPERTY(buttonBorderRadius, NSNumber)
9
9
  RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL)
10
10
  RCT_EXPORT_VIEW_PROPERTY(onShippingMethodSelectedAction, RCTDirectEventBlock)
11
11
  RCT_EXPORT_VIEW_PROPERTY(onShippingContactSelectedAction, RCTDirectEventBlock)
@@ -18,7 +18,7 @@ public class ApplePayButtonView: UIView {
18
18
 
19
19
  @objc public var type: NSNumber?
20
20
  @objc public var buttonStyle: NSNumber?
21
- @objc public var borderRadius: NSNumber?
21
+ @objc public var buttonBorderRadius: NSNumber?
22
22
  @objc public var disabled = false
23
23
 
24
24
  @objc func handleApplePayButtonTapped() {
@@ -37,7 +37,7 @@ public class ApplePayButtonView: UIView {
37
37
  let paymentButtonStyle = PKPaymentButtonStyle(rawValue: self.buttonStyle as? Int ?? 2) ?? .black
38
38
  self.applePayButton = PKPaymentButton(paymentButtonType: paymentButtonType, paymentButtonStyle: paymentButtonStyle)
39
39
  if #available(iOS 12.0, *) {
40
- self.applePayButton?.cornerRadius = self.borderRadius as? CGFloat ?? 4.0
40
+ self.applePayButton?.cornerRadius = self.buttonBorderRadius as? CGFloat ?? 4.0
41
41
  }
42
42
 
43
43
  if let applePayButton = self.applePayButton {
@@ -26,7 +26,7 @@ class FinancialConnections {
26
26
  )
27
27
  financialConnectionsSheet.onEvent = onEvent
28
28
  financialConnectionsSheet.present(
29
- from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()),
29
+ from: findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()),
30
30
  completion: { result in
31
31
  switch result {
32
32
  case .completed(session: let session):
@@ -55,7 +55,7 @@ class FinancialConnections {
55
55
  )
56
56
  financialConnectionsSheet.onEvent = onEvent
57
57
  financialConnectionsSheet.presentForToken(
58
- from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()),
58
+ from: findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()),
59
59
  completion: { result in
60
60
  switch result {
61
61
  case .completed(result: let result):