@stripe/stripe-react-native 0.16.0 → 0.18.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.
- package/.husky/pre-commit +4 -0
- package/CHANGELOG.md +40 -0
- package/README.md +1 -1
- package/android/build.gradle +1 -1
- package/android/gradle.properties +2 -2
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +8 -1
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +278 -0
- package/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt +4 -0
- package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +6 -2
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +9 -11
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +2 -2
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +3 -1
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +59 -22
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +4 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +11 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +5 -4
- package/ios/Errors.swift +12 -1
- package/ios/FinancialConnections.swift +258 -0
- package/ios/Mappers.swift +12 -9
- package/ios/StripeSdk.m +10 -1
- package/ios/StripeSdk.swift +51 -8
- package/lib/commonjs/NativeStripeSdk.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/StripeProvider.js +1 -1
- package/lib/commonjs/components/StripeProvider.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/hooks/useApplePay.js +1 -1
- package/lib/commonjs/hooks/useApplePay.js.map +1 -1
- package/lib/commonjs/hooks/useConfirmPayment.js +1 -1
- package/lib/commonjs/hooks/useConfirmPayment.js.map +1 -1
- package/lib/commonjs/hooks/useConfirmSetupIntent.js +1 -1
- package/lib/commonjs/hooks/useConfirmSetupIntent.js.map +1 -1
- package/lib/commonjs/hooks/useFinancialConnectionsSheet.js +2 -0
- package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -0
- package/lib/commonjs/hooks/useGooglePay.js +1 -1
- package/lib/commonjs/hooks/useGooglePay.js.map +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.js +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.js.map +1 -1
- package/lib/commonjs/hooks/useStripe.js +1 -1
- package/lib/commonjs/hooks/useStripe.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/plugin/withStripe.js +1 -1
- package/lib/commonjs/plugin/withStripe.js.map +1 -1
- package/lib/commonjs/types/FinancialConnections.js +2 -0
- package/lib/commonjs/types/FinancialConnections.js.map +1 -0
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/commonjs/types/SetupIntent.js.map +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/NativeStripeSdk.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/StripeProvider.js +1 -1
- package/lib/module/components/StripeProvider.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/hooks/useApplePay.js +1 -1
- package/lib/module/hooks/useApplePay.js.map +1 -1
- package/lib/module/hooks/useConfirmPayment.js +1 -1
- package/lib/module/hooks/useConfirmPayment.js.map +1 -1
- package/lib/module/hooks/useConfirmSetupIntent.js +1 -1
- package/lib/module/hooks/useConfirmSetupIntent.js.map +1 -1
- package/lib/module/hooks/useFinancialConnectionsSheet.js +2 -0
- package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -0
- package/lib/module/hooks/useGooglePay.js +1 -1
- package/lib/module/hooks/useGooglePay.js.map +1 -1
- package/lib/module/hooks/usePaymentSheet.js +1 -1
- package/lib/module/hooks/usePaymentSheet.js.map +1 -1
- package/lib/module/hooks/useStripe.js +1 -1
- package/lib/module/hooks/useStripe.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/plugin/withStripe.js +1 -1
- package/lib/module/plugin/withStripe.js.map +1 -1
- package/lib/module/types/FinancialConnections.js +2 -0
- package/lib/module/types/FinancialConnections.js.map +1 -0
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/module/types/SetupIntent.js.map +1 -1
- package/lib/module/types/index.js +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/src/NativeStripeSdk.d.ts +4 -2
- package/lib/typescript/src/functions.d.ts +24 -2
- package/lib/typescript/src/hooks/useConfirmPayment.d.ts +2 -2
- package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +11 -0
- package/lib/typescript/src/hooks/useStripe.d.ts +4 -2
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/types/FinancialConnections.d.ts +100 -0
- package/lib/typescript/src/types/PaymentIntent.d.ts +1 -0
- package/lib/typescript/src/types/SetupIntent.d.ts +1 -0
- package/lib/typescript/src/types/Token.d.ts +18 -7
- package/lib/typescript/src/types/index.d.ts +2 -1
- package/package.json +10 -12
- package/src/NativeStripeSdk.tsx +10 -2
- package/src/functions.ts +67 -1
- package/src/hooks/useConfirmPayment.tsx +3 -3
- package/src/hooks/useFinancialConnectionsSheet.tsx +34 -0
- package/src/hooks/useStripe.tsx +24 -2
- package/src/index.tsx +1 -0
- package/src/types/FinancialConnections.ts +126 -0
- package/src/types/PaymentIntent.ts +1 -0
- package/src/types/SetupIntent.ts +1 -0
- package/src/types/Token.ts +24 -7
- package/src/types/index.ts +2 -0
- package/stripe-react-native.podspec +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.18.1 - 2022-08-19
|
|
6
|
+
|
|
7
|
+
### Breaking changes
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
## Fixes
|
|
12
|
+
|
|
13
|
+
- Fixed an issue where some promises on Android would never resolve when using React Native 0.65.x or under. [#1089](https://github.com/stripe/stripe-react-native/pull/1089).
|
|
14
|
+
|
|
15
|
+
## 0.18.0 - 2022-08-17
|
|
16
|
+
|
|
17
|
+
### Breaking changes
|
|
18
|
+
|
|
19
|
+
- Your `compileSdkVersion` (in `android/build.gradle`) now must be at least `32`. Changing your `compileSdkVersion` does not change runtime behavior.
|
|
20
|
+
|
|
21
|
+
### New features
|
|
22
|
+
|
|
23
|
+
- `confirmPayment` can now be called with _just_ a client secret (e.g. `await confirmPayment("payment-intent-id")`), in other words the payment method can be excluded. If the payment method is excluded, it is assumed by the SDK that you have attached the payment method on the server-side during payment intent creation. [#1084](https://github.com/stripe/stripe-react-native/pull/1084)
|
|
24
|
+
- Payment Sheet now supports Link on iOS. [#1086](https://github.com/stripe/stripe-react-native/pull/1086).
|
|
25
|
+
|
|
26
|
+
### Fixes
|
|
27
|
+
|
|
28
|
+
- Fixed a bug on Android where `collectBankAccountForPayment`, `collectBankAccountForSetup`, `collectBankAccountToken`, and `collectFinancialConnectionsAccounts` wouldn't work with Stripe Connect accounts. [#1086](https://github.com/stripe/stripe-react-native/pull/1086).
|
|
29
|
+
- Upgraded `stripe-ios` to 22.7.+ and `stripe-android` to 20.9.+.
|
|
30
|
+
|
|
31
|
+
## 0.17.0 - 2022-08-11
|
|
32
|
+
|
|
33
|
+
### Breaking changes
|
|
34
|
+
|
|
35
|
+
### New features
|
|
36
|
+
|
|
37
|
+
- Added the [`collectBankAccountToken`](https://stripe.com/docs/financial-connections/connect-payouts?platform=react-native) & [`collectFinancialConnectionsAccounts`](https://stripe.com/docs/financial-connections/other-data-powered-products?platform=react-native) functions.
|
|
38
|
+
|
|
39
|
+
### Fixes
|
|
40
|
+
|
|
41
|
+
- Fixed an issue where `collectBankAccountForPayment` and `collectBankAccountForSetup` would fail on Android when using React Native 0.65.x or under. [#1059](https://github.com/stripe/stripe-react-native/pull/1059)
|
|
42
|
+
- Fixed an issue where Android apps could crash with the error `IllegalStateException: Cannot remove Fragment attached to a different FragmentManager`. [#1054](https://github.com/stripe/stripe-react-native/pull/1054)
|
|
43
|
+
- Bumped Gradle from 4.2.2 to 7.1.1. [#1058](https://github.com/stripe/stripe-react-native/pull/1058)
|
|
44
|
+
|
|
5
45
|
## 0.16.0 - 2022-07-22
|
|
6
46
|
|
|
7
47
|
### Breaking changes
|
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ to your `app.json` file, where `merchantIdentifier` is the Apple merchant ID obt
|
|
|
73
73
|
#### Android
|
|
74
74
|
|
|
75
75
|
- Android 5.0 (API level 21) and above
|
|
76
|
-
- Your `compileSdkVersion` must be `
|
|
76
|
+
- Your `compileSdkVersion` must be `32`. See [this issue](https://github.com/stripe/stripe-react-native/issues/812) for potential workarounds.
|
|
77
77
|
- Android gradle plugin 4.x and above
|
|
78
78
|
|
|
79
79
|
_Components_
|
package/android/build.gradle
CHANGED
|
@@ -8,7 +8,7 @@ buildscript {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
dependencies {
|
|
11
|
-
classpath 'com.android.tools.build:gradle:
|
|
11
|
+
classpath 'com.android.tools.build:gradle:7.1.1'
|
|
12
12
|
// noinspection DifferentKotlinGradleVersion
|
|
13
13
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
14
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
StripeSdk_kotlinVersion=1.6.
|
|
2
|
-
StripeSdk_stripeVersion=20.
|
|
1
|
+
StripeSdk_kotlinVersion=1.6.21
|
|
2
|
+
StripeSdk_stripeVersion=20.9.+
|
|
@@ -209,7 +209,7 @@ class CardFieldView(context: ThemedReactContext) : FrameLayout(context) {
|
|
|
209
209
|
*/
|
|
210
210
|
fun setCountryCode(countryString: String?) {
|
|
211
211
|
if (mCardWidget.postalCodeEnabled) {
|
|
212
|
-
val countryCode = CountryCode.create(value = countryString ?: LocaleListCompat.getAdjustedDefault()[0]
|
|
212
|
+
val countryCode = CountryCode.create(value = countryString ?: LocaleListCompat.getAdjustedDefault()[0]?.country ?: "US")
|
|
213
213
|
mCardWidget.postalCodeRequired = CountryUtils.doesCountryUsePostalCode(countryCode)
|
|
214
214
|
setPostalCodeFilter(countryCode)
|
|
215
215
|
}
|
package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt
CHANGED
|
@@ -24,6 +24,7 @@ import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResu
|
|
|
24
24
|
class CollectBankAccountLauncherFragment(
|
|
25
25
|
private val context: ReactApplicationContext,
|
|
26
26
|
private val publishableKey: String,
|
|
27
|
+
private val stripeAccountId: String?,
|
|
27
28
|
private val clientSecret: String,
|
|
28
29
|
private val isPaymentIntent: Boolean,
|
|
29
30
|
private val collectParams: CollectBankAccountConfiguration.USBankAccount,
|
|
@@ -48,12 +49,14 @@ class CollectBankAccountLauncherFragment(
|
|
|
48
49
|
if (isPaymentIntent) {
|
|
49
50
|
collectBankAccountLauncher.presentWithPaymentIntent(
|
|
50
51
|
publishableKey,
|
|
52
|
+
stripeAccountId,
|
|
51
53
|
clientSecret,
|
|
52
54
|
collectParams
|
|
53
55
|
)
|
|
54
56
|
} else {
|
|
55
57
|
collectBankAccountLauncher.presentWithSetupIntent(
|
|
56
58
|
publishableKey,
|
|
59
|
+
stripeAccountId,
|
|
57
60
|
clientSecret,
|
|
58
61
|
collectParams
|
|
59
62
|
)
|
|
@@ -83,7 +86,11 @@ class CollectBankAccountLauncherFragment(
|
|
|
83
86
|
promise.resolve(createError(ErrorType.Failed.toString(), result.error))
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
|
-
(context
|
|
89
|
+
removeFragment(context)
|
|
87
90
|
}
|
|
88
91
|
}
|
|
92
|
+
|
|
93
|
+
companion object {
|
|
94
|
+
const val TAG = "collect_bank_account_launcher_fragment"
|
|
95
|
+
}
|
|
89
96
|
}
|
|
@@ -0,0 +1,278 @@
|
|
|
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.appcompat.app.AppCompatActivity
|
|
9
|
+
import androidx.fragment.app.Fragment
|
|
10
|
+
import com.facebook.react.bridge.*
|
|
11
|
+
import com.reactnativestripesdk.utils.*
|
|
12
|
+
import com.reactnativestripesdk.utils.createError
|
|
13
|
+
import com.reactnativestripesdk.utils.createMissingActivityError
|
|
14
|
+
import com.reactnativestripesdk.utils.mapFromToken
|
|
15
|
+
import com.stripe.android.financialconnections.FinancialConnectionsSheet
|
|
16
|
+
import com.stripe.android.financialconnections.FinancialConnectionsSheetForTokenResult
|
|
17
|
+
import com.stripe.android.financialconnections.FinancialConnectionsSheetResult
|
|
18
|
+
import com.stripe.android.financialconnections.model.*
|
|
19
|
+
|
|
20
|
+
class FinancialConnectionsSheetFragment : Fragment() {
|
|
21
|
+
enum class Mode {
|
|
22
|
+
ForToken, ForSession
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private lateinit var promise: Promise
|
|
26
|
+
private lateinit var context: ReactApplicationContext
|
|
27
|
+
private lateinit var configuration: FinancialConnectionsSheet.Configuration
|
|
28
|
+
private lateinit var mode: Mode
|
|
29
|
+
|
|
30
|
+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
31
|
+
savedInstanceState: Bundle?): View {
|
|
32
|
+
return FrameLayout(requireActivity()).also {
|
|
33
|
+
it.visibility = View.GONE
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
38
|
+
when (mode) {
|
|
39
|
+
Mode.ForToken -> {
|
|
40
|
+
FinancialConnectionsSheet.createForBankAccountToken(
|
|
41
|
+
this,
|
|
42
|
+
::onFinancialConnectionsSheetForTokenResult
|
|
43
|
+
).present(
|
|
44
|
+
configuration = configuration
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
Mode.ForSession -> {
|
|
48
|
+
FinancialConnectionsSheet.create(
|
|
49
|
+
this,
|
|
50
|
+
::onFinancialConnectionsSheetForDataResult
|
|
51
|
+
).present(
|
|
52
|
+
configuration = configuration
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private fun onFinancialConnectionsSheetForTokenResult(result: FinancialConnectionsSheetForTokenResult) {
|
|
59
|
+
when(result) {
|
|
60
|
+
is FinancialConnectionsSheetForTokenResult.Canceled -> {
|
|
61
|
+
promise.resolve(
|
|
62
|
+
createError(ErrorType.Canceled.toString(), "The flow has been canceled")
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
is FinancialConnectionsSheetForTokenResult.Failed -> {
|
|
66
|
+
promise.resolve(
|
|
67
|
+
createError(ErrorType.Failed.toString(), result.error)
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
is FinancialConnectionsSheetForTokenResult.Completed -> {
|
|
71
|
+
promise.resolve(createTokenResult(result))
|
|
72
|
+
(context.currentActivity as? AppCompatActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private fun onFinancialConnectionsSheetForDataResult(result: FinancialConnectionsSheetResult) {
|
|
78
|
+
when(result) {
|
|
79
|
+
is FinancialConnectionsSheetResult.Canceled -> {
|
|
80
|
+
promise.resolve(
|
|
81
|
+
createError(ErrorType.Canceled.toString(), "The flow has been canceled")
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
is FinancialConnectionsSheetResult.Failed -> {
|
|
85
|
+
promise.resolve(
|
|
86
|
+
createError(ErrorType.Failed.toString(), result.error)
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
is FinancialConnectionsSheetResult.Completed -> {
|
|
90
|
+
promise.resolve(
|
|
91
|
+
WritableNativeMap().also {
|
|
92
|
+
it.putMap("session", mapFromSession(result.financialConnectionsSession))
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
(context.currentActivity as? AppCompatActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fun presentFinancialConnectionsSheet(clientSecret: String, mode: Mode, publishableKey: String, stripeAccountId: String?, promise: Promise, context: ReactApplicationContext) {
|
|
101
|
+
this.promise = promise
|
|
102
|
+
this.context = context
|
|
103
|
+
this.mode = mode
|
|
104
|
+
this.configuration = FinancialConnectionsSheet.Configuration(
|
|
105
|
+
financialConnectionsSessionClientSecret = clientSecret,
|
|
106
|
+
publishableKey = publishableKey,
|
|
107
|
+
stripeAccountId = stripeAccountId,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
(context.currentActivity as? AppCompatActivity)?.let {
|
|
111
|
+
attemptToCleanupPreviousFragment(it)
|
|
112
|
+
commitFragmentAndStartFlow(it)
|
|
113
|
+
} ?: run {
|
|
114
|
+
promise.resolve(createMissingActivityError())
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private fun attemptToCleanupPreviousFragment(currentActivity: AppCompatActivity) {
|
|
120
|
+
currentActivity.supportFragmentManager.beginTransaction()
|
|
121
|
+
.remove(this)
|
|
122
|
+
.commitAllowingStateLoss()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private fun commitFragmentAndStartFlow(currentActivity: AppCompatActivity) {
|
|
126
|
+
try {
|
|
127
|
+
currentActivity.supportFragmentManager.beginTransaction()
|
|
128
|
+
.add(this, "financial_connections_sheet_launch_fragment")
|
|
129
|
+
.commit()
|
|
130
|
+
} catch (error: IllegalStateException) {
|
|
131
|
+
promise.resolve(createError(ErrorType.Failed.toString(), error.message))
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
companion object {
|
|
136
|
+
private fun createTokenResult(result: FinancialConnectionsSheetForTokenResult.Completed): WritableMap {
|
|
137
|
+
return WritableNativeMap().also {
|
|
138
|
+
it.putMap("session", mapFromSession(result.financialConnectionsSession))
|
|
139
|
+
it.putMap("token", mapFromToken(result.token))
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private fun mapFromSession(financialConnectionsSession: FinancialConnectionsSession): WritableMap {
|
|
144
|
+
val session = WritableNativeMap()
|
|
145
|
+
session.putString("id", financialConnectionsSession.id)
|
|
146
|
+
session.putString("clientSecret", financialConnectionsSession.clientSecret)
|
|
147
|
+
session.putBoolean("livemode", financialConnectionsSession.livemode)
|
|
148
|
+
session.putArray("accounts", mapFromAccountsList(financialConnectionsSession.accounts))
|
|
149
|
+
return session
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private fun mapFromAccountsList(accounts: FinancialConnectionsAccountList): ReadableArray {
|
|
153
|
+
val results: WritableArray = Arguments.createArray()
|
|
154
|
+
for (account in accounts.data) {
|
|
155
|
+
val map = WritableNativeMap()
|
|
156
|
+
map.putString("id", account.id)
|
|
157
|
+
map.putBoolean("livemode", account.livemode)
|
|
158
|
+
map.putString("displayName", account.displayName)
|
|
159
|
+
map.putString("status", mapFromStatus(account.status))
|
|
160
|
+
map.putString("institutionName", account.institutionName)
|
|
161
|
+
map.putString("last4", account.last4)
|
|
162
|
+
map.putDouble("created", account.created * 1000.0)
|
|
163
|
+
map.putMap("balance", mapFromAccountBalance(account.balance))
|
|
164
|
+
map.putMap("balanceRefresh", mapFromAccountBalanceRefresh(account.balanceRefresh))
|
|
165
|
+
map.putString("category", mapFromCategory(account.category))
|
|
166
|
+
map.putString("subcategory", mapFromSubcategory(account.subcategory))
|
|
167
|
+
map.putArray("permissions", (account.permissions?.map { permission -> mapFromPermission(permission) })?.toReadableArray())
|
|
168
|
+
map.putArray("supportedPaymentMethodTypes", (account.supportedPaymentMethodTypes.map { type -> mapFromSupportedPaymentMethodTypes(type) }).toReadableArray())
|
|
169
|
+
results.pushMap(map)
|
|
170
|
+
}
|
|
171
|
+
return results
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private fun mapFromAccountBalance(balance: Balance?): WritableMap? {
|
|
175
|
+
if (balance == null) {
|
|
176
|
+
return null
|
|
177
|
+
}
|
|
178
|
+
val map = WritableNativeMap()
|
|
179
|
+
map.putDouble("asOf", balance.asOf * 1000.0)
|
|
180
|
+
map.putString("type", mapFromBalanceType(balance.type))
|
|
181
|
+
map.putMap("current", balance.current as ReadableMap)
|
|
182
|
+
WritableNativeMap().also {
|
|
183
|
+
it.putMap("available", balance.cash?.available as ReadableMap)
|
|
184
|
+
map.putMap("cash", it)
|
|
185
|
+
}
|
|
186
|
+
WritableNativeMap().also {
|
|
187
|
+
it.putMap("used", balance.credit?.used as ReadableMap)
|
|
188
|
+
map.putMap("credit", it)
|
|
189
|
+
}
|
|
190
|
+
return map
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private fun mapFromAccountBalanceRefresh(balanceRefresh: BalanceRefresh?): WritableMap? {
|
|
194
|
+
if (balanceRefresh == null) {
|
|
195
|
+
return null
|
|
196
|
+
}
|
|
197
|
+
val map = WritableNativeMap()
|
|
198
|
+
map.putString("status", mapFromBalanceRefreshStatus(balanceRefresh.status))
|
|
199
|
+
map.putDouble("lastAttemptedAt", balanceRefresh.lastAttemptedAt * 1000.0)
|
|
200
|
+
return map
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private fun mapFromStatus(status: FinancialConnectionsAccount.Status): String {
|
|
204
|
+
return when (status) {
|
|
205
|
+
FinancialConnectionsAccount.Status.ACTIVE -> "active"
|
|
206
|
+
FinancialConnectionsAccount.Status.DISCONNECTED -> "disconnected"
|
|
207
|
+
FinancialConnectionsAccount.Status.INACTIVE -> "inactive"
|
|
208
|
+
FinancialConnectionsAccount.Status.UNKNOWN -> "unparsable"
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private fun mapFromCategory(category: FinancialConnectionsAccount.Category): String {
|
|
213
|
+
return when (category) {
|
|
214
|
+
FinancialConnectionsAccount.Category.CASH -> "cash"
|
|
215
|
+
FinancialConnectionsAccount.Category.CREDIT -> "credit"
|
|
216
|
+
FinancialConnectionsAccount.Category.INVESTMENT -> "investment"
|
|
217
|
+
FinancialConnectionsAccount.Category.OTHER -> "other"
|
|
218
|
+
FinancialConnectionsAccount.Category.UNKNOWN -> "unparsable"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private fun mapFromSubcategory(subcategory: FinancialConnectionsAccount.Subcategory): String {
|
|
223
|
+
return when (subcategory) {
|
|
224
|
+
FinancialConnectionsAccount.Subcategory.CHECKING -> "checking"
|
|
225
|
+
FinancialConnectionsAccount.Subcategory.CREDIT_CARD -> "creditCard"
|
|
226
|
+
FinancialConnectionsAccount.Subcategory.LINE_OF_CREDIT -> "lineOfCredit"
|
|
227
|
+
FinancialConnectionsAccount.Subcategory.MORTGAGE -> "mortgage"
|
|
228
|
+
FinancialConnectionsAccount.Subcategory.OTHER -> "other"
|
|
229
|
+
FinancialConnectionsAccount.Subcategory.SAVINGS -> "savings"
|
|
230
|
+
FinancialConnectionsAccount.Subcategory.UNKNOWN -> "unparsable"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private fun mapFromPermission(permission: FinancialConnectionsAccount.Permissions): String {
|
|
235
|
+
return when (permission) {
|
|
236
|
+
FinancialConnectionsAccount.Permissions.PAYMENT_METHOD -> "paymentMethod"
|
|
237
|
+
FinancialConnectionsAccount.Permissions.BALANCES -> "balances"
|
|
238
|
+
FinancialConnectionsAccount.Permissions.OWNERSHIP -> "ownership"
|
|
239
|
+
FinancialConnectionsAccount.Permissions.TRANSACTIONS -> "transactions"
|
|
240
|
+
FinancialConnectionsAccount.Permissions.UNKNOWN -> "unparsable"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private fun mapFromSupportedPaymentMethodTypes(type: FinancialConnectionsAccount.SupportedPaymentMethodTypes): String {
|
|
245
|
+
return when (type) {
|
|
246
|
+
FinancialConnectionsAccount.SupportedPaymentMethodTypes.US_BANK_ACCOUNT -> "usBankAccount"
|
|
247
|
+
FinancialConnectionsAccount.SupportedPaymentMethodTypes.LINK -> "link"
|
|
248
|
+
FinancialConnectionsAccount.SupportedPaymentMethodTypes.UNKNOWN -> "unparsable"
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private fun mapFromBalanceType(type: Balance.Type): String {
|
|
253
|
+
return when (type) {
|
|
254
|
+
Balance.Type.CASH -> "cash"
|
|
255
|
+
Balance.Type.CREDIT -> "credit"
|
|
256
|
+
Balance.Type.UNKNOWN -> "unparsable"
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private fun mapFromBalanceRefreshStatus(status: BalanceRefresh.BalanceRefreshStatus?): String {
|
|
261
|
+
return when (status) {
|
|
262
|
+
BalanceRefresh.BalanceRefreshStatus.SUCCEEDED -> "succeeded"
|
|
263
|
+
BalanceRefresh.BalanceRefreshStatus.FAILED -> "failed"
|
|
264
|
+
BalanceRefresh.BalanceRefreshStatus.PENDING -> "pending"
|
|
265
|
+
BalanceRefresh.BalanceRefreshStatus.UNKNOWN -> "unparsable"
|
|
266
|
+
null -> "null"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
fun List<String>.toReadableArray(): ReadableArray {
|
|
273
|
+
val results: WritableArray = Arguments.createArray()
|
|
274
|
+
for (s in this) {
|
|
275
|
+
results.pushString(s)
|
|
276
|
+
}
|
|
277
|
+
return results
|
|
278
|
+
}
|
package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt
CHANGED
|
@@ -5,10 +5,10 @@ import android.view.LayoutInflater
|
|
|
5
5
|
import android.view.View
|
|
6
6
|
import android.view.ViewGroup
|
|
7
7
|
import android.widget.FrameLayout
|
|
8
|
-
import androidx.appcompat.app.AppCompatActivity
|
|
9
8
|
import androidx.fragment.app.Fragment
|
|
10
9
|
import com.facebook.react.bridge.Promise
|
|
11
10
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
|
+
import com.reactnativestripesdk.utils.removeFragment
|
|
12
12
|
import com.stripe.android.googlepaylauncher.GooglePayEnvironment
|
|
13
13
|
import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher
|
|
14
14
|
|
|
@@ -37,9 +37,13 @@ class GooglePayPaymentMethodLauncherFragment(
|
|
|
37
37
|
),
|
|
38
38
|
readyCallback = {
|
|
39
39
|
promise.resolve(it)
|
|
40
|
-
(context
|
|
40
|
+
removeFragment(context)
|
|
41
41
|
},
|
|
42
42
|
resultCallback = {}
|
|
43
43
|
)
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
companion object {
|
|
47
|
+
const val TAG = "google_pay_support_fragment"
|
|
48
|
+
}
|
|
45
49
|
}
|
|
@@ -110,7 +110,7 @@ class PaymentLauncherFragment(
|
|
|
110
110
|
(context.currentActivity as? AppCompatActivity)?.let {
|
|
111
111
|
try {
|
|
112
112
|
it.supportFragmentManager.beginTransaction()
|
|
113
|
-
.add(fragment,
|
|
113
|
+
.add(fragment, TAG)
|
|
114
114
|
.commit()
|
|
115
115
|
} catch (error: IllegalStateException) {
|
|
116
116
|
promise.resolve(createError(ErrorType.Failed.toString(), error.message))
|
|
@@ -119,6 +119,8 @@ class PaymentLauncherFragment(
|
|
|
119
119
|
promise.resolve(createMissingActivityError())
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
+
|
|
123
|
+
const val TAG = "payment_launcher_fragment"
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
@@ -154,25 +156,21 @@ class PaymentLauncherFragment(
|
|
|
154
156
|
}
|
|
155
157
|
is PaymentResult.Canceled -> {
|
|
156
158
|
promise.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), message = null))
|
|
157
|
-
|
|
159
|
+
removeFragment(context)
|
|
158
160
|
}
|
|
159
161
|
is PaymentResult.Failed -> {
|
|
160
162
|
promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), paymentResult.throwable))
|
|
161
|
-
|
|
163
|
+
removeFragment(context)
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
|
|
167
|
-
private fun cleanup() {
|
|
168
|
-
(context.currentActivity as? AppCompatActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
|
|
169
|
-
}
|
|
170
|
-
|
|
171
169
|
private fun retrieveSetupIntent(clientSecret: String, stripeAccountId: String?) {
|
|
172
170
|
stripe.retrieveSetupIntent(clientSecret, stripeAccountId, object : ApiResultCallback<SetupIntent> {
|
|
173
171
|
override fun onError(e: Exception) {
|
|
174
172
|
promise.resolve(createError(ConfirmSetupIntentErrorType.Failed.toString(), e))
|
|
175
|
-
|
|
173
|
+
removeFragment(context)
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
override fun onSuccess(result: SetupIntent) {
|
|
@@ -204,7 +202,7 @@ class PaymentLauncherFragment(
|
|
|
204
202
|
promise.resolve(createError(ConfirmSetupIntentErrorType.Unknown.toString(), "unhandled error: ${result.status}"))
|
|
205
203
|
}
|
|
206
204
|
}
|
|
207
|
-
|
|
205
|
+
removeFragment(context)
|
|
208
206
|
}
|
|
209
207
|
})
|
|
210
208
|
}
|
|
@@ -213,7 +211,7 @@ class PaymentLauncherFragment(
|
|
|
213
211
|
stripe.retrievePaymentIntent(clientSecret, stripeAccountId, object : ApiResultCallback<PaymentIntent> {
|
|
214
212
|
override fun onError(e: Exception) {
|
|
215
213
|
promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), e))
|
|
216
|
-
|
|
214
|
+
removeFragment(context)
|
|
217
215
|
}
|
|
218
216
|
|
|
219
217
|
override fun onSuccess(result: PaymentIntent) {
|
|
@@ -245,7 +243,7 @@ class PaymentLauncherFragment(
|
|
|
245
243
|
promise.resolve(createError(ConfirmPaymentErrorType.Unknown.toString(), "unhandled error: ${result.status}"))
|
|
246
244
|
}
|
|
247
245
|
}
|
|
248
|
-
|
|
246
|
+
removeFragment(context)
|
|
249
247
|
}
|
|
250
248
|
})
|
|
251
249
|
}
|
|
@@ -203,14 +203,13 @@ class PaymentMethodCreateParamsFactory(
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
@Throws(PaymentMethodCreateParamsException::class)
|
|
206
|
-
fun createParams(clientSecret: String, paymentMethodType: PaymentMethod.Type
|
|
206
|
+
fun createParams(clientSecret: String, paymentMethodType: PaymentMethod.Type?, isPaymentIntent: Boolean): ConfirmStripeIntentParams {
|
|
207
207
|
try {
|
|
208
208
|
return when (paymentMethodType) {
|
|
209
209
|
PaymentMethod.Type.Card -> createCardStripeIntentParams(clientSecret, isPaymentIntent)
|
|
210
210
|
PaymentMethod.Type.USBankAccount -> createUSBankAccountStripeIntentParams(clientSecret, isPaymentIntent)
|
|
211
211
|
PaymentMethod.Type.PayPal -> createPayPalStripeIntentParams(clientSecret, isPaymentIntent)
|
|
212
212
|
PaymentMethod.Type.Affirm -> createAffirmStripeIntentParams(clientSecret, isPaymentIntent)
|
|
213
|
-
|
|
214
213
|
PaymentMethod.Type.Ideal,
|
|
215
214
|
PaymentMethod.Type.Alipay,
|
|
216
215
|
PaymentMethod.Type.Sofort,
|
|
@@ -241,6 +240,7 @@ class PaymentMethodCreateParamsFactory(
|
|
|
241
240
|
)
|
|
242
241
|
}
|
|
243
242
|
}
|
|
243
|
+
null -> ConfirmPaymentIntentParams.create(clientSecret)
|
|
244
244
|
else -> {
|
|
245
245
|
throw Exception("This paymentMethodType is not supported yet")
|
|
246
246
|
}
|
|
@@ -95,7 +95,7 @@ class PaymentSheetFragment(
|
|
|
95
95
|
is PaymentSheetResult.Completed -> {
|
|
96
96
|
resolvePaymentResult(WritableNativeMap())
|
|
97
97
|
// Remove the fragment now, we can be sure it won't be needed again if an intent is successful
|
|
98
|
-
(context
|
|
98
|
+
removeFragment(context)
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -196,6 +196,8 @@ class PaymentSheetFragment(
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
companion object {
|
|
199
|
+
const val TAG = "payment_sheet_launch_fragment"
|
|
200
|
+
|
|
199
201
|
internal fun buildGooglePayConfig(params: Bundle?): PaymentSheet.GooglePayConfiguration? {
|
|
200
202
|
if (params == null) {
|
|
201
203
|
return null
|