@stripe/stripe-react-native 0.56.0 → 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 (84) 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/{FinancialConnectionsSheetFragment.kt → FinancialConnectionsSheetManager.kt} +30 -77
  8. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +107 -0
  9. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherManager.kt +37 -0
  10. package/android/src/main/java/com/reactnativestripesdk/{PaymentLauncherFragment.kt → PaymentLauncherManager.kt} +39 -77
  11. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +8 -20
  12. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +366 -483
  13. package/android/src/main/java/com/reactnativestripesdk/{PaymentSheetFragment.kt → PaymentSheetManager.kt} +79 -88
  14. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +176 -219
  15. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherManager.kt +78 -0
  16. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +48 -35
  17. package/android/src/main/java/com/reactnativestripesdk/customersheet/{CustomerSheetFragment.kt → CustomerSheetManager.kt} +70 -85
  18. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +0 -2
  19. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +47 -12
  20. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +87 -142
  21. package/android/src/main/java/com/reactnativestripesdk/utils/StripeUIManager.kt +62 -0
  22. package/ios/AddressSheet/AddressSheetView.swift +1 -1
  23. package/ios/FinancialConnections.swift +2 -2
  24. package/ios/Mappers.swift +2 -4
  25. package/ios/PaymentMethodFactory.swift +0 -17
  26. package/ios/PushProvisioning/AddToWalletButtonView.swift +1 -1
  27. package/ios/StripeSdkImpl+CustomerSheet.swift +1 -1
  28. package/ios/StripeSdkImpl+PaymentSheet.swift +15 -8
  29. package/ios/StripeSdkImpl.swift +6 -6
  30. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  31. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  32. package/lib/commonjs/components/AddressSheet.js +1 -1
  33. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  34. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  35. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  36. package/lib/commonjs/components/CardField.js +1 -1
  37. package/lib/commonjs/components/CardField.js.map +1 -1
  38. package/lib/commonjs/components/CardForm.js +1 -1
  39. package/lib/commonjs/components/CardForm.js.map +1 -1
  40. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  41. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  42. package/lib/commonjs/components/StripeContainer.js +1 -1
  43. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  44. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  45. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  46. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  47. package/lib/module/components/AddToWalletButton.js +1 -1
  48. package/lib/module/components/AddToWalletButton.js.map +1 -1
  49. package/lib/module/components/AddressSheet.js +1 -1
  50. package/lib/module/components/AddressSheet.js.map +1 -1
  51. package/lib/module/components/AuBECSDebitForm.js +1 -1
  52. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  53. package/lib/module/components/CardField.js +1 -1
  54. package/lib/module/components/CardField.js.map +1 -1
  55. package/lib/module/components/CardForm.js +1 -1
  56. package/lib/module/components/CardForm.js.map +1 -1
  57. package/lib/module/components/PlatformPayButton.js +1 -1
  58. package/lib/module/components/PlatformPayButton.js.map +1 -1
  59. package/lib/module/components/StripeContainer.js +1 -1
  60. package/lib/module/components/StripeContainer.js.map +1 -1
  61. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  62. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  63. package/lib/module/types/PaymentIntent.js.map +1 -1
  64. package/lib/typescript/src/types/PaymentIntent.d.ts +1 -9
  65. package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
  66. package/lib/typescript/src/types/PaymentMethod.d.ts +2 -8
  67. package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
  68. package/package.json +1 -1
  69. package/src/types/PaymentIntent.ts +0 -10
  70. package/src/types/PaymentMethod.ts +0 -9
  71. package/stripe-react-native.podspec +1 -1
  72. package/android/.idea/AndroidProjectSystem.xml +0 -6
  73. package/android/.idea/caches/deviceStreaming.xml +0 -703
  74. package/android/.idea/compiler.xml +0 -6
  75. package/android/.idea/gradle.xml +0 -18
  76. package/android/.idea/migrations.xml +0 -10
  77. package/android/.idea/misc.xml +0 -10
  78. package/android/.idea/runConfigurations.xml +0 -17
  79. package/android/.idea/vcs.xml +0 -6
  80. package/android/local.properties +0 -8
  81. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +0 -146
  82. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +0 -68
  83. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +0 -102
  84. 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
+ }
@@ -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
 
@@ -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):
package/ios/Mappers.swift CHANGED
@@ -286,7 +286,6 @@ class Mappers {
286
286
  case STPPaymentMethodType.SEPADebit: return "SepaDebit"
287
287
  case STPPaymentMethodType.AUBECSDebit: return "AuBecsDebit"
288
288
  case STPPaymentMethodType.bacsDebit: return "BacsDebit"
289
- case STPPaymentMethodType.giropay: return "Giropay"
290
289
  case STPPaymentMethodType.przelewy24: return "P24"
291
290
  case STPPaymentMethodType.EPS: return "Eps"
292
291
  case STPPaymentMethodType.bancontact: return "Bancontact"
@@ -319,7 +318,6 @@ class Mappers {
319
318
  case "SepaDebit": return STPPaymentMethodType.SEPADebit
320
319
  case "AuBecsDebit": return STPPaymentMethodType.AUBECSDebit
321
320
  case "BacsDebit": return STPPaymentMethodType.bacsDebit
322
- case "Giropay": return STPPaymentMethodType.giropay
323
321
  case "P24": return STPPaymentMethodType.przelewy24
324
322
  case "Eps": return STPPaymentMethodType.EPS
325
323
  case "Bancontact": return STPPaymentMethodType.bancontact
@@ -666,7 +664,7 @@ class Mappers {
666
664
  "accountType": mapFromUSBankAccountType(type: paymentMethod.usBankAccount?.accountType),
667
665
  "last4": paymentMethod.usBankAccount?.last4 ?? NSNull(),
668
666
  "bankName": paymentMethod.usBankAccount?.bankName ?? NSNull(),
669
- "linkedAccount": paymentMethod.usBankAccount?.linkedAccount ?? NSNull(),
667
+ "linkedAccount": paymentMethod.usBankAccount?.financialConnectionsAccount ?? NSNull(),
670
668
  "fingerprint": paymentMethod.usBankAccount?.fingerprint ?? NSNull(),
671
669
  "preferredNetworks": paymentMethod.usBankAccount?.networks?.preferred ?? NSNull(),
672
670
  "supportedNetworks": paymentMethod.usBankAccount?.networks?.supported ?? NSNull(),
@@ -839,7 +837,7 @@ class Mappers {
839
837
 
840
838
 
841
839
  let types = setupIntent.paymentMethodTypes.map {
842
- mapPaymentMethodType(type: STPPaymentMethodType.init(rawValue: Int(truncating: $0))!)
840
+ mapPaymentMethodType(type: $0)
843
841
  }
844
842
 
845
843
  intent.setValue(types, forKey: "paymentMethodTypes")
@@ -39,8 +39,6 @@ class PaymentMethodFactory {
39
39
  return try createBilliePaymentMethodParams()
40
40
  case STPPaymentMethodType.SEPADebit:
41
41
  return try createSepaPaymentMethodParams()
42
- case STPPaymentMethodType.giropay:
43
- return try createGiropayPaymentMethodParams()
44
42
  case STPPaymentMethodType.EPS:
45
43
  return try createEPSPaymentMethodParams()
46
44
  case STPPaymentMethodType.grabPay:
@@ -96,8 +94,6 @@ class PaymentMethodFactory {
96
94
  return nil
97
95
  case STPPaymentMethodType.OXXO:
98
96
  return nil
99
- case STPPaymentMethodType.giropay:
100
- return nil
101
97
  case STPPaymentMethodType.grabPay:
102
98
  return nil
103
99
  case STPPaymentMethodType.przelewy24:
@@ -303,16 +299,6 @@ class PaymentMethodFactory {
303
299
  return STPPaymentMethodParams(oxxo: params, billingDetails: billingDetails, metadata: metadata)
304
300
  }
305
301
 
306
- private func createGiropayPaymentMethodParams() throws -> STPPaymentMethodParams {
307
- let params = STPPaymentMethodGiropayParams()
308
-
309
- guard let billingDetails = billingDetailsParams else {
310
- throw PaymentMethodError.giropayPaymentMissingParams
311
- }
312
-
313
- return STPPaymentMethodParams(giropay: params, billingDetails: billingDetails, metadata: metadata)
314
- }
315
-
316
302
  private func createEPSPaymentMethodParams() throws -> STPPaymentMethodParams {
317
303
  let params = STPPaymentMethodEPSParams()
318
304
 
@@ -419,7 +405,6 @@ enum PaymentMethodError: Error {
419
405
  case bancontactPaymentMissingParams
420
406
  case billiePaymentMissingParams
421
407
  case sepaPaymentMissingParams
422
- case giropayPaymentMissingParams
423
408
  case p24PaymentMissingParams
424
409
  case afterpayClearpayPaymentMissingParams
425
410
  // Klarna no longer requires email and country in billing details
@@ -434,8 +419,6 @@ extension PaymentMethodError: LocalizedError {
434
419
  switch self {
435
420
  case .cardPaymentMissingParams:
436
421
  return NSLocalizedString("Card details not complete", comment: "Create payment error")
437
- case .giropayPaymentMissingParams:
438
- return NSLocalizedString("You must provide billing details", comment: "Create payment error")
439
422
  case .idealPaymentMissingParams:
440
423
  return NSLocalizedString("You must provide bank name", comment: "Create payment error")
441
424
  case .p24PaymentMissingParams:
@@ -89,7 +89,7 @@ public class AddToWalletButtonView: UIView {
89
89
  return self.testEnv ? STPFakeAddPaymentPassViewController(requestConfiguration: config, delegate: self) : PKAddPaymentPassViewController(requestConfiguration: config, delegate: self)
90
90
  }()
91
91
 
92
- let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
92
+ let vc = findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
93
93
  vc.present(controller!, animated: true, completion: nil)
94
94
  }
95
95
 
@@ -107,7 +107,7 @@ extension StripeSdkImpl {
107
107
  }
108
108
 
109
109
  DispatchQueue.main.async {
110
- self.customerSheetViewController = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
110
+ self.customerSheetViewController = findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
111
111
  if let customerSheetViewController = self.customerSheetViewController {
112
112
  customerSheetViewController.modalPresentationStyle = CustomerSheetUtils.getModalPresentationStyle(params["presentationStyle"] as? String)
113
113
  customerSheetViewController.modalTransitionStyle = CustomerSheetUtils.getModalTransitionStyle(params["animationStyle"] as? String)
@@ -396,6 +396,20 @@ extension StripeSdkImpl {
396
396
  if (applePayParams["request"] == nil) {
397
397
  return nil
398
398
  }
399
+ let authorizationResultHandler: PaymentSheet.ApplePayConfiguration.Handlers.AuthorizationResultHandler? = {
400
+ guard applePayParams.object(forKey: "setOrderTracking") != nil else {
401
+ return nil
402
+ }
403
+ return { result in
404
+ await withCheckedContinuation { continuation in
405
+ // Set the handler first: this will be called from JS land after we `emitOnOrderTrackingCallback()`.
406
+ self.orderTrackingHandler = (result, { result in
407
+ continuation.resume(returning: result)
408
+ })
409
+ self.emitter?.emitOnOrderTrackingCallback()
410
+ }
411
+ }
412
+ }()
399
413
  return PaymentSheet.ApplePayConfiguration.Handlers(paymentRequestHandler: { request in
400
414
  do {
401
415
  try request.configureRequestType(requestParams: applePayParams)
@@ -404,14 +418,7 @@ extension StripeSdkImpl {
404
418
  RCTMakeAndLogError(error.localizedDescription, nil, nil)
405
419
  }
406
420
  return request
407
- }, authorizationResultHandler: { result, completion in
408
- if applePayParams.object(forKey: "setOrderTracking") != nil {
409
- self.orderTrackingHandler = (result, completion)
410
- self.emitter?.emitOnOrderTrackingCallback()
411
- } else {
412
- completion(result)
413
- }
414
- })
421
+ }, authorizationResultHandler: authorizationResultHandler)
415
422
  }
416
423
 
417
424
  internal static func mapToCollectionMode(str: String?) -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode {