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
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.49.+
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class PaymentSheetFragment(
}
}

@OptIn(ExperimentalCustomerSessionApi::class)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val merchantDisplayName = arguments?.getString("merchantDisplayName").orEmpty()
Expand All @@ -65,6 +66,7 @@ class PaymentSheetFragment(
val primaryButtonLabel = arguments?.getString("primaryButtonLabel")
val customerId = arguments?.getString("customerId").orEmpty()
val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret").orEmpty()
val customerSessionClientSecret = arguments?.getString("customerSessionClientSecret").orEmpty()
val googlePayConfig = buildGooglePayConfig(arguments?.getBundle("googlePay"))
val allowsDelayedPaymentMethods = arguments?.getBoolean("allowsDelayedPaymentMethods")
val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
Expand Down Expand Up @@ -191,7 +193,11 @@ class PaymentSheetFragment(
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods ?: false)
.defaultBillingDetails(defaultBillingDetails)
.customer(
if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) PaymentSheet.CustomerConfiguration(
if (customerId.isNotEmpty() && customerSessionClientSecret.isNotEmpty()) PaymentSheet.CustomerConfiguration.createWithCustomerSession(
id = customerId,
clientSecret = customerSessionClientSecret
)
else if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) PaymentSheet.CustomerConfiguration(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to add error handling if they provide both customerSessionClientSecret and customerEphemeralKeySecret?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍

id = customerId,
ephemeralKeySecret = customerEphemeralKeySecret
) else null
Expand Down
5 changes: 4 additions & 1 deletion ios/StripeSdk+PaymentSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
@_spi(ExperimentalAllowsRemovalOfLastSavedPaymentMethodAPI) @_spi(STP) import StripePaymentSheet
@_spi(ExperimentalAllowsRemovalOfLastSavedPaymentMethodAPI) @_spi(CustomerSessionBetaAccess) @_spi(STP) import StripePaymentSheet

extension StripeSdk {
internal func buildPaymentSheetConfiguration(
Expand Down Expand Up @@ -97,6 +97,9 @@ extension StripeSdk {
}
configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
}
else if let customerClientSecret = params["customerSessionClientSecret"] as? String {
configuration.customer = .init(id: customerId, customerSessionClientSecret: customerClientSecret)
}
}

if let preferredNetworksAsInts = params["preferredNetworks"] as? Array<Int> {
Expand Down
Loading