Skip to content

Commit 15c5acd

Browse files
authored
Set correct allow_redisplay value for spms with link (#4501)
## Summary Set allow_redisplay value when signing up for link and saving a new payment method ## Motivation allow_redisplay was not being set. ## Testing Updated existing test ## Changelog <!-- Is this a notable change that affects users? If so, add a line to `CHANGELOG.md` and prefix the line with one of the following: - [Added] for new features. - [Changed] for changes in existing functionality. - [Deprecated] for soon-to-be removed features. - [Removed] for now removed features. - [Fixed] for any bug fixes. - [Security] in case of vulnerabilities. -->
1 parent 8c6dd20 commit 15c5acd

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetUITest.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -2204,15 +2204,25 @@ class PaymentSheetLinkUITests: PaymentSheetUITestCase {
22042204
}
22052205

22062206
// Tests the #5 flow in PaymentSheet where the merchant enables saved payment methods, buyer has SPMs and first time Link user
2207-
func testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser() {
2207+
func testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser_legacy() {
22082208
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
22092209
settings.layout = .horizontal
22102210
settings.customerMode = .new
22112211
settings.apmsEnabled = .on
22122212
settings.linkPassthroughMode = .pm
2213-
// TODO: Properly pass the allow_redisplay value to 'consumers/payment_details' endpoint
22142213
settings.customerKeyType = .legacy
2215-
2214+
_testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser(settings: settings)
2215+
}
2216+
func testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser_customerSession() {
2217+
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
2218+
settings.layout = .horizontal
2219+
settings.customerMode = .new
2220+
settings.apmsEnabled = .on
2221+
settings.linkPassthroughMode = .pm
2222+
settings.customerKeyType = .customerSession
2223+
_testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser(settings: settings)
2224+
}
2225+
func _testLinkPaymentSheet_enabledSPM_hasSPMs_firstTimeLinkUser(settings: PaymentSheetTestPlaygroundSettings) {
22162226
loadPlayground(app, settings)
22172227
app.buttons["Present PaymentSheet"].waitForExistenceAndTap()
22182228

StripePaymentSheet/StripePaymentSheet/Source/Helpers/PaymentSheetLinkAccount.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
364364
}
365365
}
366366

367-
func sharePaymentDetails(id: String, cvc: String?, completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void) {
367+
func sharePaymentDetails(id: String, cvc: String?, allowRedisplay: STPPaymentMethodAllowRedisplay?, completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void) {
368368
retryingOnAuthError(completion: completion) { [apiClient, publishableKey] completionRetryingOnAuthErrors in
369369
guard let session = self.currentSession else {
370370
stpAssertionFailure()
@@ -379,6 +379,7 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
379379
with: apiClient,
380380
id: id,
381381
cvc: cvc,
382+
allowRedisplay: allowRedisplay,
382383
consumerAccountPublishableKey: publishableKey,
383384
completion: completionRetryingOnAuthErrors
384385
)

StripePaymentSheet/StripePaymentSheet/Source/Internal/API Bindings/Link/ConsumerSession.swift

+2
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,15 @@ extension ConsumerSession {
238238
with apiClient: STPAPIClient = STPAPIClient.shared,
239239
id: String,
240240
cvc: String?,
241+
allowRedisplay: STPPaymentMethodAllowRedisplay?,
241242
consumerAccountPublishableKey: String?,
242243
completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void
243244
) {
244245
apiClient.sharePaymentDetails(
245246
for: clientSecret,
246247
id: id,
247248
consumerAccountPublishableKey: consumerAccountPublishableKey,
249+
allowRedisplay: allowRedisplay,
248250
cvc: cvc,
249251
completion: completion)
250252
}

StripePaymentSheet/StripePaymentSheet/Source/Internal/API Bindings/Link/STPAPIClient+Link.swift

+4
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ extension STPAPIClient {
286286
for consumerSessionClientSecret: String,
287287
id: String,
288288
consumerAccountPublishableKey: String?,
289+
allowRedisplay: STPPaymentMethodAllowRedisplay?,
289290
cvc: String?,
290291
completion: @escaping (Result<PaymentDetailsShareResponse, Error>) -> Void
291292
) {
@@ -301,6 +302,9 @@ extension STPAPIClient {
301302
if let cvc = cvc {
302303
parameters["payment_method_options"] = ["card": ["cvc": cvc]]
303304
}
305+
if let allowRedisplay {
306+
parameters["allow_redisplay"] = allowRedisplay.stringValue
307+
}
304308

305309
APIRequest<PaymentDetailsShareResponse>.post(
306310
with: self,

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheet+API.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ extension PaymentSheet {
456456
case .success(let paymentDetails):
457457
if elementsSession.linkPassthroughModeEnabled {
458458
// If passthrough mode, share payment details
459-
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentMethodParams.card?.cvc) { result in
459+
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentMethodParams.card?.cvc, allowRedisplay: paymentMethodParams.allowRedisplay) { result in
460460
switch result {
461461
case .success(let paymentDetailsShareResponse):
462462
confirmWithPaymentMethod(paymentDetailsShareResponse.paymentMethod, linkAccount, shouldSave)
@@ -495,6 +495,11 @@ extension PaymentSheet {
495495
switch result {
496496
case .success:
497497
STPAnalyticsClient.sharedClient.logLinkSignupComplete()
498+
// Set allow_redisplay on params
499+
intentConfirmParams.setAllowRedisplay(
500+
mobilePaymentElementFeatures: elementsSession.customerSessionMobilePaymentElementFeatures,
501+
isSettingUp: intent.isSettingUp
502+
)
498503
createPaymentDetailsAndConfirm(linkAccount, intentConfirmParams.paymentMethodParams, intentConfirmParams.saveForFutureUseCheckboxState == .selected)
499504
case .failure(let error as NSError):
500505
STPAnalyticsClient.sharedClient.logLinkSignupFailure(error: error)
@@ -508,7 +513,8 @@ extension PaymentSheet {
508513
let shouldSave = false // always false, as we don't show a save-to-merchant checkbox in Link VC
509514

510515
if elementsSession.linkPassthroughModeEnabled {
511-
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentDetails.cvc) { result in
516+
// allowRedisplay is nil since we are not saving a payment method.
517+
linkAccount.sharePaymentDetails(id: paymentDetails.stripeID, cvc: paymentDetails.cvc, allowRedisplay: nil) { result in
512518
switch result {
513519
case .success(let paymentDetailsShareResponse):
514520
confirmWithPaymentMethod(paymentDetailsShareResponse.paymentMethod, linkAccount, shouldSave)

StripePayments/StripePayments/Source/API Bindings/Models/PaymentMethods/STPPaymentMethodAllowRedisplay.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616
/// Use always to indicate that this payment method can always be shown to a customer in a checkout flow.
1717
case always
1818

19-
var stringValue: String? {
19+
@_spi(STP) public var stringValue: String? {
2020
switch self {
2121
case .unspecified:
2222
return "unspecified"

0 commit comments

Comments
 (0)