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

Set correct allow_redisplay value for spms with link #4501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2204,15 +2204,25 @@ class PaymentSheetLinkUITests: PaymentSheetUITestCase {
}

// Tests the #5 flow in PaymentSheet where the merchant enables saved payment methods, buyer has SPMs and first time Link user
func testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser() {
func testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser_legacy() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.layout = .horizontal
settings.customerMode = .new
settings.apmsEnabled = .on
settings.linkPassthroughMode = .pm
// TODO: Properly pass the allow_redisplay value to 'consumers/payment_details' endpoint
settings.customerKeyType = .legacy

_testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser(settings: settings)
}
func testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser_customerSession() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.layout = .horizontal
settings.customerMode = .new
settings.apmsEnabled = .on
settings.linkPassthroughMode = .pm
settings.customerKeyType = .customerSession
_testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser(settings: settings)
}
func _testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser(settings: PaymentSheetTestPlaygroundSettings) {
loadPlayground(app, settings)
app.buttons["Present PaymentSheet"].waitForExistenceAndTap()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
}
}

func sharePaymentDetails(id: String, cvc: String?, completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void) {
func sharePaymentDetails(id: String, cvc: String?, allowRedisplay: STPPaymentMethodAllowRedisplay?, completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void) {
retryingOnAuthError(completion: completion) { [apiClient, publishableKey] completionRetryingOnAuthErrors in
guard let session = self.currentSession else {
stpAssertionFailure()
Expand All @@ -379,6 +379,7 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
with: apiClient,
id: id,
cvc: cvc,
allowRedisplay: allowRedisplay,
consumerAccountPublishableKey: publishableKey,
completion: completionRetryingOnAuthErrors
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,15 @@ extension ConsumerSession {
with apiClient: STPAPIClient = STPAPIClient.shared,
id: String,
cvc: String?,
allowRedisplay: STPPaymentMethodAllowRedisplay?,
consumerAccountPublishableKey: String?,
completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void
) {
apiClient.sharePaymentDetails(
for: clientSecret,
id: id,
consumerAccountPublishableKey: consumerAccountPublishableKey,
allowRedisplay: allowRedisplay,
cvc: cvc,
completion: completion)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ extension STPAPIClient {
for consumerSessionClientSecret: String,
id: String,
consumerAccountPublishableKey: String?,
allowRedisplay: STPPaymentMethodAllowRedisplay?,
cvc: String?,
completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void
) {
Expand All @@ -301,6 +302,9 @@ extension STPAPIClient {
if let cvc = cvc {
parameters["payment_method_options"] = ["card": ["cvc": cvc]]
}
if let allowRedisplay {
parameters["allow_redisplay"] = allowRedisplay.stringValue
}

APIRequest<PaymentDetailsShareResponse>.post(
with: self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ extension PaymentSheet {
case .success(let paymentDetails):
if elementsSession.linkPassthroughModeEnabled {
// If passthrough mode, share payment details
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentMethodParams.card?.cvc) { result in
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentMethodParams.card?.cvc, allowRedisplay: paymentMethodParams.allowRedisplay) { result in
switch result {
case .success(let paymentDetailsShareResponse):
confirmWithPaymentMethod(paymentDetailsShareResponse.paymentMethod, linkAccount, shouldSave)
Expand Down Expand Up @@ -492,6 +492,11 @@ extension PaymentSheet {
switch result {
case .success:
STPAnalyticsClient.sharedClient.logLinkSignupComplete()
// Set allow_redisplay on params
intentConfirmParams.setAllowRedisplay(
mobilePaymentElementFeatures: elementsSession.customerSessionMobilePaymentElementFeatures,
isSettingUp: intent.isSettingUp
)
createPaymentDetailsAndConfirm(linkAccount, intentConfirmParams.paymentMethodParams, intentConfirmParams.saveForFutureUseCheckboxState == .selected)
case .failure(let error as NSError):
STPAnalyticsClient.sharedClient.logLinkSignupFailure(error: error)
Expand All @@ -505,7 +510,8 @@ extension PaymentSheet {
let shouldSave = false // always false, as we don't show a save-to-merchant checkbox in Link VC

if elementsSession.linkPassthroughModeEnabled {
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentDetails.cvc) { result in
// allowRedisplay is nil since we are not saving a payment method.
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentDetails.cvc, allowRedisplay: nil) { result in
Copy link
Collaborator Author

@wooj-stripe wooj-stripe Jan 24, 2025

Choose a reason for hiding this comment

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

@davidme-stripe - a bit unclear here on capturing allowRedisplay. Is it possible to have a checkbox when given .withPaymentDetails?

switch result {
case .success(let paymentDetailsShareResponse):
confirmWithPaymentMethod(paymentDetailsShareResponse.paymentMethod, linkAccount, shouldSave)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
/// Use always to indicate that this payment method can always be shown to a customer in a checkout flow.
case always

var stringValue: String? {
@_spi(STP) public var stringValue: String? {
switch self {
case .unspecified:
return "unspecified"
Expand Down
Loading