@stripe/stripe-react-native 0.30.0 → 0.31.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 (58) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +41 -10
  4. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +10 -3
  5. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +129 -82
  6. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +329 -0
  7. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +138 -0
  8. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +8 -2
  9. package/ios/CustomerSheet/CustomerSheetUtils.swift +181 -0
  10. package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +173 -0
  11. package/ios/Mappers.swift +1 -1
  12. package/ios/StripeSdk+CustomerSheet.swift +166 -0
  13. package/ios/StripeSdk+PaymentSheet.swift +2 -2
  14. package/ios/StripeSdk.m +53 -0
  15. package/ios/StripeSdk.swift +14 -1
  16. package/jest/mock.js +0 -37
  17. package/lib/commonjs/NativeStripeSdk.js.map +1 -1
  18. package/lib/commonjs/components/CustomerSheet.js +2 -0
  19. package/lib/commonjs/components/CustomerSheet.js.map +1 -0
  20. package/lib/commonjs/functions.js +1 -1
  21. package/lib/commonjs/functions.js.map +1 -1
  22. package/lib/commonjs/index.js +1 -1
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/types/CustomerSheet.js +2 -0
  25. package/lib/commonjs/types/CustomerSheet.js.map +1 -0
  26. package/lib/commonjs/types/Errors.js +1 -1
  27. package/lib/commonjs/types/Errors.js.map +1 -1
  28. package/lib/commonjs/types/index.js +1 -1
  29. package/lib/commonjs/types/index.js.map +1 -1
  30. package/lib/module/NativeStripeSdk.js.map +1 -1
  31. package/lib/module/components/CustomerSheet.js +2 -0
  32. package/lib/module/components/CustomerSheet.js.map +1 -0
  33. package/lib/module/functions.js +1 -1
  34. package/lib/module/functions.js.map +1 -1
  35. package/lib/module/index.js +1 -1
  36. package/lib/module/index.js.map +1 -1
  37. package/lib/module/types/CustomerSheet.js +2 -0
  38. package/lib/module/types/CustomerSheet.js.map +1 -0
  39. package/lib/module/types/Errors.js +1 -1
  40. package/lib/module/types/Errors.js.map +1 -1
  41. package/lib/module/types/index.js +1 -1
  42. package/lib/module/types/index.js.map +1 -1
  43. package/lib/typescript/src/NativeStripeSdk.d.ts +14 -1
  44. package/lib/typescript/src/components/CustomerSheet.d.ts +59 -0
  45. package/lib/typescript/src/index.d.ts +2 -0
  46. package/lib/typescript/src/types/CustomerSheet.d.ts +94 -0
  47. package/lib/typescript/src/types/Errors.d.ts +4 -0
  48. package/lib/typescript/src/types/index.d.ts +1 -0
  49. package/package.json +1 -1
  50. package/src/NativeStripeSdk.tsx +31 -0
  51. package/src/components/CustomerSheet.tsx +327 -0
  52. package/src/functions.ts +5 -0
  53. package/src/index.tsx +3 -0
  54. package/src/types/CustomerSheet.ts +111 -0
  55. package/src/types/Errors.ts +5 -0
  56. package/src/types/index.ts +1 -0
  57. package/stripe-react-native.podspec +1 -1
  58. package/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt +0 -211
@@ -1,211 +0,0 @@
1
- package com.reactnativestripesdk
2
-
3
- import android.os.Bundle
4
- import android.view.LayoutInflater
5
- import android.view.View
6
- import android.view.ViewGroup
7
- import android.widget.FrameLayout
8
- import androidx.fragment.app.Fragment
9
- import com.facebook.react.bridge.Promise
10
- import com.facebook.react.bridge.WritableNativeMap
11
- import com.reactnativestripesdk.utils.GooglePayErrorType
12
- import com.reactnativestripesdk.utils.createError
13
- import com.reactnativestripesdk.utils.createResult
14
- import com.reactnativestripesdk.utils.mapFromPaymentMethod
15
- import com.stripe.android.googlepaylauncher.GooglePayEnvironment
16
- import com.stripe.android.googlepaylauncher.GooglePayLauncher
17
- import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher
18
-
19
- class GooglePayFragment(private val initPromise: Promise) : Fragment() {
20
- private var googlePayLauncher: GooglePayLauncher? = null
21
- private var googlePayMethodLauncher: GooglePayPaymentMethodLauncher? = null
22
- private var isGooglePayMethodLauncherReady: Boolean = false
23
- private var isGooglePayLauncherReady: Boolean = false
24
- private var presentPromise: Promise? = null
25
- private var createPaymentMethodPromise: Promise? = null
26
-
27
- override fun onCreateView(
28
- inflater: LayoutInflater,
29
- container: ViewGroup?,
30
- savedInstanceState: Bundle?
31
- ): View {
32
- return FrameLayout(requireActivity()).also {
33
- it.visibility = View.GONE
34
- }
35
- }
36
-
37
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
38
- super.onViewCreated(view, savedInstanceState)
39
- val testEnv = arguments?.getBoolean("testEnv")
40
- val merchantName = arguments?.getString("merchantName").orEmpty()
41
- val countryCode = arguments?.getString("countryCode").orEmpty()
42
- val isEmailRequired = arguments?.getBoolean("isEmailRequired") ?: false
43
- val existingPaymentMethodRequired = arguments?.getBoolean("existingPaymentMethodRequired") ?: false
44
-
45
- val billingAddressConfigBundle = arguments?.getBundle("billingAddressConfig") ?: Bundle()
46
- val isRequired = billingAddressConfigBundle.getBoolean("isRequired")
47
- val formatString = billingAddressConfigBundle.getString("format").orEmpty()
48
- val isPhoneNumberRequired = billingAddressConfigBundle.getBoolean("isPhoneNumberRequired")
49
-
50
- val billingAddressConfig = mapToGooglePayPaymentMethodLauncherBillingAddressConfig(formatString, isRequired, isPhoneNumberRequired)
51
-
52
- googlePayMethodLauncher = GooglePayPaymentMethodLauncher(
53
- fragment = this,
54
- config = GooglePayPaymentMethodLauncher.Config(
55
- environment = if (testEnv == true) GooglePayEnvironment.Test else GooglePayEnvironment.Production,
56
- merchantCountryCode = countryCode,
57
- merchantName = merchantName,
58
- billingAddressConfig = billingAddressConfig,
59
- isEmailRequired = isEmailRequired,
60
- existingPaymentMethodRequired = existingPaymentMethodRequired
61
- ),
62
- readyCallback = ::onGooglePayMethodLauncherReady,
63
- resultCallback = ::onGooglePayResult
64
- )
65
-
66
- val paymentMethodBillingAddressConfig = mapToGooglePayLauncherBillingAddressConfig(formatString, isRequired, isPhoneNumberRequired)
67
- googlePayLauncher = GooglePayLauncher(
68
- fragment = this,
69
- config = GooglePayLauncher.Config(
70
- environment = if (testEnv == true) GooglePayEnvironment.Test else GooglePayEnvironment.Production,
71
- merchantCountryCode = countryCode,
72
- merchantName = merchantName,
73
- billingAddressConfig = paymentMethodBillingAddressConfig,
74
- isEmailRequired = isEmailRequired,
75
- existingPaymentMethodRequired = existingPaymentMethodRequired
76
- ),
77
- readyCallback = ::onGooglePayLauncherReady,
78
- resultCallback = ::onGooglePayResult
79
- )
80
- }
81
-
82
- private fun onGooglePayMethodLauncherReady(isReady: Boolean) {
83
- isGooglePayMethodLauncherReady = true
84
- if (isGooglePayLauncherReady) {
85
- onGooglePayReady(isReady)
86
- }
87
- }
88
-
89
- private fun onGooglePayLauncherReady(isReady: Boolean) {
90
- isGooglePayLauncherReady = true
91
- if (isGooglePayMethodLauncherReady) {
92
- onGooglePayReady(isReady)
93
- }
94
- }
95
-
96
- private fun onGooglePayReady(isReady: Boolean) {
97
- if (isReady) {
98
- initPromise.resolve(WritableNativeMap())
99
- } else {
100
- initPromise.resolve(
101
- createError(
102
- GooglePayErrorType.Failed.toString(),
103
- "Google Pay is not available on this device. You can use isGooglePaySupported to preemptively check for Google Pay support."
104
- )
105
- )
106
- }
107
- }
108
-
109
- fun presentForPaymentIntent(clientSecret: String, promise: Promise) {
110
- val launcher = googlePayLauncher ?: run {
111
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), "GooglePay is not initialized."))
112
- return
113
- }
114
- runCatching {
115
- presentPromise = promise
116
- launcher.presentForPaymentIntent(clientSecret)
117
- }.onFailure {
118
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), it))
119
- }
120
- }
121
-
122
- fun presentForSetupIntent(clientSecret: String, currencyCode: String, promise: Promise) {
123
- val launcher = googlePayLauncher ?: run {
124
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), "GooglePay is not initialized."))
125
- return
126
- }
127
- runCatching {
128
- presentPromise = promise
129
- launcher.presentForSetupIntent(clientSecret, currencyCode)
130
- }.onFailure {
131
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), it))
132
- }
133
- }
134
-
135
- fun createPaymentMethod(currencyCode: String, amount: Int, promise: Promise) {
136
- val launcher = googlePayMethodLauncher ?: run {
137
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), "GooglePayPaymentMethodLauncher is not initialized."))
138
- return
139
- }
140
-
141
- runCatching {
142
- createPaymentMethodPromise = promise
143
- launcher.present(
144
- currencyCode = currencyCode,
145
- amount = amount
146
- )
147
- }.onFailure {
148
- promise.resolve(createError(GooglePayErrorType.Failed.toString(), it))
149
- }
150
- }
151
-
152
- private fun onGooglePayResult(result: GooglePayLauncher.Result) {
153
- when (result) {
154
- GooglePayLauncher.Result.Completed -> {
155
- presentPromise?.resolve(WritableNativeMap())
156
- }
157
- GooglePayLauncher.Result.Canceled -> {
158
- presentPromise?.resolve(createError(GooglePayErrorType.Canceled.toString(), "Google Pay has been canceled"))
159
- }
160
- is GooglePayLauncher.Result.Failed -> {
161
- presentPromise?.resolve(createError(GooglePayErrorType.Failed.toString(), result.error))
162
- }
163
- }
164
- presentPromise = null
165
- }
166
-
167
- private fun onGooglePayResult(result: GooglePayPaymentMethodLauncher.Result) {
168
- when (result) {
169
- is GooglePayPaymentMethodLauncher.Result.Completed -> {
170
- createPaymentMethodPromise?.resolve(createResult("paymentMethod", mapFromPaymentMethod(result.paymentMethod)))
171
- }
172
- GooglePayPaymentMethodLauncher.Result.Canceled -> {
173
- createPaymentMethodPromise?.resolve(createError(GooglePayErrorType.Canceled.toString(), "Google Pay has been canceled"))
174
- }
175
- is GooglePayPaymentMethodLauncher.Result.Failed -> {
176
- createPaymentMethodPromise?.resolve(createError(GooglePayErrorType.Failed.toString(), result.error))
177
- }
178
- }
179
- createPaymentMethodPromise = null
180
- }
181
-
182
- private fun mapToGooglePayLauncherBillingAddressConfig(formatString: String, isRequired: Boolean, isPhoneNumberRequired: Boolean): GooglePayLauncher.BillingAddressConfig {
183
- val format = when (formatString) {
184
- "FULL" -> GooglePayLauncher.BillingAddressConfig.Format.Full
185
- "MIN" -> GooglePayLauncher.BillingAddressConfig.Format.Min
186
- else -> GooglePayLauncher.BillingAddressConfig.Format.Min
187
- }
188
- return GooglePayLauncher.BillingAddressConfig(
189
- isRequired = isRequired,
190
- format = format,
191
- isPhoneNumberRequired = isPhoneNumberRequired
192
- )
193
- }
194
-
195
- private fun mapToGooglePayPaymentMethodLauncherBillingAddressConfig(formatString: String, isRequired: Boolean, isPhoneNumberRequired: Boolean): GooglePayPaymentMethodLauncher.BillingAddressConfig {
196
- val format = when (formatString) {
197
- "FULL" -> GooglePayPaymentMethodLauncher.BillingAddressConfig.Format.Full
198
- "MIN" -> GooglePayPaymentMethodLauncher.BillingAddressConfig.Format.Min
199
- else -> GooglePayPaymentMethodLauncher.BillingAddressConfig.Format.Min
200
- }
201
- return GooglePayPaymentMethodLauncher.BillingAddressConfig(
202
- isRequired = isRequired,
203
- format = format,
204
- isPhoneNumberRequired = isPhoneNumberRequired
205
- )
206
- }
207
-
208
- companion object {
209
- internal const val TAG = "google_pay_launch_fragment"
210
- }
211
- }