Skip to content

Commit

Permalink
Parse 'customerSheetClientSecret for Android and iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
tjclawson-stripe committed Oct 2, 2024
1 parent 888c6cb commit 5f2131a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.reactnativestripesdk

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Application
import android.content.Context
Expand Down Expand Up @@ -55,6 +56,8 @@ class PaymentSheetFragment(
}
}

@SuppressLint("RestrictedApi")
@OptIn(ExperimentalCustomerSessionApi::class)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val merchantDisplayName = arguments?.getString("merchantDisplayName").orEmpty()
Expand All @@ -65,6 +68,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 +195,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(
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

0 comments on commit 5f2131a

Please sign in to comment.