Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse 'customerSheetClientSecret' for Android and iOS #1744

Merged
merged 8 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

**Features**

- Adds support for CustomerSession in private beta [1744](https://github.com/stripe/stripe-react-native/pull/1744)

**Fixes**

* Updated `stripe-ios` to 23.30.\*
* Updated `stripe-android` to 20.52.\*

## 0.38.6 - 2024-09-04

**Fixes**
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
StripeSdk_kotlinVersion=1.8.0
# Keep StripeSdk_stripeVersion in sync with https://github.com/stripe/stripe-identity-react-native/blob/main/android/gradle.properties
StripeSdk_stripeVersion=20.48.+
StripeSdk_stripeVersion=20.52.+
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class PaymentSheetFragment(
return
}
val primaryButtonLabel = arguments?.getString("primaryButtonLabel")
val customerId = arguments?.getString("customerId").orEmpty()
val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret").orEmpty()
val googlePayConfig = buildGooglePayConfig(arguments?.getBundle("googlePay"))
val allowsDelayedPaymentMethods = arguments?.getBoolean("allowsDelayedPaymentMethods")
val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
Expand All @@ -86,6 +84,13 @@ class PaymentSheetFragment(
return
}

val customerConfiguration = try {
buildCustomerConfiguration(arguments)
} catch (error: PaymentSheetException) {
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
return
}

val shippingDetails = arguments?.getBundle("defaultShippingDetails")?.let {
AddressSheetView.buildAddressDetails(it)
}
Expand Down Expand Up @@ -190,12 +195,7 @@ class PaymentSheetFragment(
val configurationBuilder = PaymentSheet.Configuration.Builder(merchantDisplayName)
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods ?: false)
.defaultBillingDetails(defaultBillingDetails)
.customer(
if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) PaymentSheet.CustomerConfiguration(
id = customerId,
ephemeralKeySecret = customerEphemeralKeySecret
) else null
)
.customer(customerConfiguration)
.googlePay(googlePayConfig)
.appearance(appearance)
.shippingDetails(shippingDetails)
Expand Down Expand Up @@ -428,6 +428,28 @@ class PaymentSheetFragment(
)
}
}

@OptIn(ExperimentalCustomerSessionApi::class)
@Throws(PaymentSheetException::class)
private fun buildCustomerConfiguration(bundle: Bundle?): PaymentSheet.CustomerConfiguration? {
val customerId = bundle?.getString("customerId").orEmpty()
val customerEphemeralKeySecret = bundle?.getString("customerEphemeralKeySecret").orEmpty()
val customerSessionClientSecret = bundle?.getString("customerSessionClientSecret").orEmpty()
return if (customerSessionClientSecret.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) {
throw PaymentSheetException("`customerEphemeralKeySecret` and `customerSessionClientSecret` cannot both be set")
} else if (customerId.isNotEmpty() && customerSessionClientSecret.isNotEmpty()) {
PaymentSheet.CustomerConfiguration.createWithCustomerSession(
id = customerId,
clientSecret = customerSessionClientSecret
)
}
else if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) {
PaymentSheet.CustomerConfiguration(
id = customerId,
ephemeralKeySecret = customerEphemeralKeySecret
)
} else null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.stripe.android.customersheet.CustomerAdapter
import com.stripe.android.customersheet.CustomerEphemeralKey
import com.stripe.android.customersheet.CustomerSheet
import com.stripe.android.customersheet.CustomerSheetResult
import com.stripe.android.customersheet.ExperimentalCustomerSheetApi
import com.stripe.android.customersheet.PaymentOptionSelection
import com.stripe.android.model.PaymentMethod
import com.stripe.android.paymentsheet.*
Expand All @@ -29,7 +28,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch


@OptIn(ExperimentalCustomerSheetApi::class, ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
@OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
class CustomerSheetFragment : Fragment() {
private var customerSheet: CustomerSheet? = null
internal var customerAdapter: ReactNativeCustomerAdapter? = null
Expand Down Expand Up @@ -111,11 +110,12 @@ class CustomerSheetFragment : Fragment() {

customerSheet = CustomerSheet.create(
fragment = this,
configuration = configuration.build(),
customerAdapter = customerAdapter,
callback = ::handleResult
)

customerSheet?.configure(configuration.build())

initPromise.resolve(WritableNativeMap())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.WritableMap
import com.reactnativestripesdk.StripeSdkModule
import com.stripe.android.customersheet.CustomerAdapter
import com.stripe.android.customersheet.ExperimentalCustomerSheetApi
import com.stripe.android.model.PaymentMethod
import kotlinx.coroutines.CompletableDeferred

@OptIn(ExperimentalCustomerSheetApi::class)
class ReactNativeCustomerAdapter (
private val context: ReactApplicationContext,
private val adapter: CustomerAdapter,
Expand Down
104 changes: 52 additions & 52 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -299,50 +299,50 @@ PODS:
- RNScreens (3.29.0):
- React-Core
- React-RCTImage
- Stripe (23.28.1):
- StripeApplePay (= 23.28.1)
- StripeCore (= 23.28.1)
- StripePayments (= 23.28.1)
- StripePaymentsUI (= 23.28.1)
- StripeUICore (= 23.28.1)
- stripe-react-native (0.38.4):
- Stripe (23.30.0):
- StripeApplePay (= 23.30.0)
- StripeCore (= 23.30.0)
- StripePayments (= 23.30.0)
- StripePaymentsUI (= 23.30.0)
- StripeUICore (= 23.30.0)
- stripe-react-native (0.38.6):
- React-Core
- Stripe (~> 23.28.0)
- StripeApplePay (~> 23.28.0)
- StripeFinancialConnections (~> 23.28.0)
- StripePayments (~> 23.28.0)
- StripePaymentSheet (~> 23.28.0)
- StripePaymentsUI (~> 23.28.0)
- stripe-react-native/Tests (0.38.4):
- Stripe (~> 23.30.0)
- StripeApplePay (~> 23.30.0)
- StripeFinancialConnections (~> 23.30.0)
- StripePayments (~> 23.30.0)
- StripePaymentSheet (~> 23.30.0)
- StripePaymentsUI (~> 23.30.0)
- stripe-react-native/Tests (0.38.6):
- React-Core
- Stripe (~> 23.28.0)
- StripeApplePay (~> 23.28.0)
- StripeFinancialConnections (~> 23.28.0)
- StripePayments (~> 23.28.0)
- StripePaymentSheet (~> 23.28.0)
- StripePaymentsUI (~> 23.28.0)
- StripeApplePay (23.28.1):
- StripeCore (= 23.28.1)
- StripeCore (23.28.1)
- StripeFinancialConnections (23.28.1):
- StripeCore (= 23.28.1)
- StripeUICore (= 23.28.1)
- StripePayments (23.28.1):
- StripeCore (= 23.28.1)
- StripePayments/Stripe3DS2 (= 23.28.1)
- StripePayments/Stripe3DS2 (23.28.1):
- StripeCore (= 23.28.1)
- StripePaymentSheet (23.28.1):
- StripeApplePay (= 23.28.1)
- StripeCore (= 23.28.1)
- StripePayments (= 23.28.1)
- StripePaymentsUI (= 23.28.1)
- StripePaymentsUI (23.28.1):
- StripeCore (= 23.28.1)
- StripePayments (= 23.28.1)
- StripeUICore (= 23.28.1)
- StripeUICore (23.28.1):
- StripeCore (= 23.28.1)
- Stripe (~> 23.30.0)
- StripeApplePay (~> 23.30.0)
- StripeFinancialConnections (~> 23.30.0)
- StripePayments (~> 23.30.0)
- StripePaymentSheet (~> 23.30.0)
- StripePaymentsUI (~> 23.30.0)
- StripeApplePay (23.30.0):
- StripeCore (= 23.30.0)
- StripeCore (23.30.0)
- StripeFinancialConnections (23.30.0):
- StripeCore (= 23.30.0)
- StripeUICore (= 23.30.0)
- StripePayments (23.30.0):
- StripeCore (= 23.30.0)
- StripePayments/Stripe3DS2 (= 23.30.0)
- StripePayments/Stripe3DS2 (23.30.0):
- StripeCore (= 23.30.0)
- StripePaymentSheet (23.30.0):
- StripeApplePay (= 23.30.0)
- StripeCore (= 23.30.0)
- StripePayments (= 23.30.0)
- StripePaymentsUI (= 23.30.0)
- StripePaymentsUI (23.30.0):
- StripeCore (= 23.30.0)
- StripePayments (= 23.30.0)
- StripeUICore (= 23.30.0)
- StripeUICore (23.30.0):
- StripeCore (= 23.30.0)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -511,17 +511,17 @@ SPEC CHECKSUMS:
RNCMaskedView: bc0170f389056201c82a55e242e5d90070e18e5a
RNCPicker: 0bf8ef8f7800524f32d2bb2a8bcadd53eda0ecd1
RNScreens: fa9b582d85ae5d62c91c66003b5278458fed7aaa
Stripe: 20e24971647daa5750e7764faa1e8aefe4917243
stripe-react-native: 3479d62b758ac162b4465cb0aed313b525a575f3
StripeApplePay: 5b098a0ba6136f4b587e03f5a3776461b4f20dd4
StripeCore: 880a68482cf78d4745c5213c2fd3446efc73574b
StripeFinancialConnections: 49a19ca17dbb3055a8b559a1e3adfe769784a8f8
StripePayments: 3af5b03fa1831c301a4d1621eb0e790280dccb46
StripePaymentSheet: 8321efebb6d104add8fce929286d414545913114
StripePaymentsUI: 4c35e12ebcd4bd9bd21e379f03f730bee097250d
StripeUICore: 22b314dc9f7ea8814d0f9eeba0ddb5e4b77f34f3
Stripe: 9757efc154de1d9615cbea4836d590bc4034d3a4
stripe-react-native: 99b3cc2fae5a53f0ab1d9949ff19ae2aaba73641
StripeApplePay: ca33933601302742623762157d587b79b942d073
StripeCore: 2af250a2366ff2bbf64d4243c5f9bbf2a98b2aaf
StripeFinancialConnections: 3ab1ef6182ec44e71c29e9a2100b663f9713ac20
StripePayments: 658a16bd34d20c8185aa281866227b9e1743300e
StripePaymentSheet: eac031f76d7fbb4f52df9b9c39be5be671ca4c07
StripePaymentsUI: 7d7cffb2ecfc0d6b5ac3a4488c02893a5ff6cc77
StripeUICore: bb102d453b1e1a10a37f810bc0a9aa0675fb17fd
Yoga: 8a90b50af67eaa9fe94fd03e550bfeab06096873

PODFILE CHECKSUM: 7b4a5e954edfeed0967520f79be9e773f07d8266

COCOAPODS: 1.11.3
COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"nodemon": "^2.0.19",
"path": "^0.12.7",
"react-test-renderer": "18.0.0",
"stripe": "^11.0.0",
"stripe": "^14.18.0",
"typescript": "^4.5.5"
}
}
Loading
Loading