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

Added DefaultSPM flag and conditionally rendered card details label and default checkbox #4266

Closed
wants to merge 13 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct CustomerSheetTestPlayground: View {
SettingView(setting: $playgroundController.settings.autoreload)
TextField("headerTextForSelectionScreen", text: headerTextForSelectionScreenBinding)
SettingView(setting: $playgroundController.settings.allowsRemovalOfLastSavedPaymentMethod)
SettingView(setting: $playgroundController.settings.defaultSPMNavigation)
HStack {
Text("Macros").font(.headline)
Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

import Combine
@_spi(STP) @_spi(CustomerSessionBetaAccess) @_spi(CardBrandFilteringBeta) import StripePaymentSheet
@_spi(STP) @_spi(CustomerSessionBetaAccess) @_spi(CardBrandFilteringBeta) @_spi(DefaultSPMNavigation) import StripePaymentSheet
import SwiftUI

class CustomerSheetTestPlaygroundController: ObservableObject {
Expand Down Expand Up @@ -147,6 +147,7 @@ class CustomerSheetTestPlaygroundController: ObservableObject {
case .allowVisa:
configuration.cardBrandAcceptance = .allowed(brands: [.visa])
}
configuration.defaultSPMNavigation = settings.defaultSPMNavigation == .on
return configuration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public struct CustomerSheetTestPlaygroundSettings: Codable, Equatable {
case allowVisa
}

enum DefaultSPMNavigationEnabled: String, PickerEnum {
static let enumName: String = "defaultSPMNavigation"
case on
case off
}

var customerMode: CustomerMode
var customerId: String?
var customerKeyType: CustomerKeyType
Expand All @@ -162,6 +168,7 @@ public struct CustomerSheetTestPlaygroundSettings: Codable, Equatable {
var paymentMethodRemove: PaymentMethodRemove
var paymentMethodAllowRedisplayFilters: PaymentMethodAllowRedisplayFilters
var cardBrandAcceptance: CardBrandAcceptance
var defaultSPMNavigation: DefaultSPMNavigationEnabled

static func defaultValues() -> CustomerSheetTestPlaygroundSettings {
return CustomerSheetTestPlaygroundSettings(customerMode: .new,
Expand All @@ -182,7 +189,8 @@ public struct CustomerSheetTestPlaygroundSettings: Codable, Equatable {
allowsRemovalOfLastSavedPaymentMethod: .on,
paymentMethodRemove: .enabled,
paymentMethodAllowRedisplayFilters: .always,
cardBrandAcceptance: .all)
cardBrandAcceptance: .all,
defaultSPMNavigation: .off)
}

var base64Data: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct PaymentSheetTestPlayground: View {
SettingView(setting: $playgroundController.settings.autoreload)
SettingView(setting: $playgroundController.settings.shakeAmbiguousViews)
SettingView(setting: $playgroundController.settings.instantDebitsInDeferredIntents)
SettingView(setting: $playgroundController.settings.defaultSPM)
}

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ struct PaymentSheetTestPlaygroundSettings: Codable, Equatable {
case allowVisa
}

enum DefaultSPM: String, PickerEnum {
static let enumName: String = "defaultSPM"
case allowDefaultSPM
case navigationOnly
case off
}

var uiStyle: UIStyle
var layout: Layout
var mode: Mode
Expand Down Expand Up @@ -483,6 +490,7 @@ struct PaymentSheetTestPlaygroundSettings: Codable, Equatable {
var formSheetAction: FormSheetAction
var embeddedViewDisplaysMandateText: DisplaysMandateTextEnabled
var cardBrandAcceptance: CardBrandAcceptance
var defaultSPM: DefaultSPM

static func defaultValues() -> PaymentSheetTestPlaygroundSettings {
return PaymentSheetTestPlaygroundSettings(
Expand Down Expand Up @@ -527,7 +535,9 @@ struct PaymentSheetTestPlaygroundSettings: Codable, Equatable {
collectAddress: .automatic,
formSheetAction: .confirm,
embeddedViewDisplaysMandateText: .on,
cardBrandAcceptance: .all)
cardBrandAcceptance: .all,
defaultSPM: .off
)
}

static let nsUserDefaultsKey = "PaymentSheetTestPlaygroundSettings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Contacts
import PassKit
@_spi(STP) import StripeCore
@_spi(STP) import StripePayments
@_spi(CustomerSessionBetaAccess) @_spi(STP) @_spi(PaymentSheetSkipConfirmation) @_spi(ExperimentalAllowsRemovalOfLastSavedPaymentMethodAPI) @_spi(EmbeddedPaymentElementPrivateBeta) @_spi(CardBrandFilteringBeta) import StripePaymentSheet
@_spi(CustomerSessionBetaAccess) @_spi(STP) @_spi(PaymentSheetSkipConfirmation) @_spi(ExperimentalAllowsRemovalOfLastSavedPaymentMethodAPI) @_spi(EmbeddedPaymentElementPrivateBeta) @_spi(CardBrandFilteringBeta) @_spi(DefaultSPM) import StripePaymentSheet
import SwiftUI
import UIKit

Expand Down Expand Up @@ -184,6 +184,16 @@ class PlaygroundController: ObservableObject {
case .allowVisa:
configuration.cardBrandAcceptance = .allowed(brands: [.visa])
}

switch settings.defaultSPM {
case .allowDefaultSPM:
configuration.defaultSPM = .allowsDefaultSPM
case .navigationOnly:
configuration.defaultSPM = .navigationOnly
case .off:
configuration.defaultSPM = .off
}

return configuration
}

Expand Down Expand Up @@ -272,6 +282,14 @@ class PlaygroundController: ObservableObject {
configuration.cardBrandAcceptance = .allowed(brands: [.visa])
}

switch settings.defaultSPM {
case .allowDefaultSPM:
configuration.defaultSPM = .allowsDefaultSPM
case .navigationOnly:
configuration.defaultSPM = .navigationOnly
case .off:
configuration.defaultSPM = .off
}
return configuration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ class CustomerSheetUITest: XCTestCase {
XCTAssertTrue(app.pickerWheels.firstMatch.waitForExistence(timeout: timeout))
app.pickerWheels.firstMatch.swipeUp()
app.toolbars.buttons["Done"].tap()
app.buttons["Update"].waitForExistenceAndTap(timeout: timeout)
app.buttons["Save"].waitForExistenceAndTap(timeout: timeout)

// We should have updated to Visa
XCTAssertTrue(app.images["carousel_card_visa"].waitForExistence(timeout: timeout))

// Remove this card
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: timeout))
XCTAssertTrue(app.buttons["Remove card"].waitForExistenceAndTap(timeout: timeout))
XCTAssertTrue(app.buttons["Remove"].waitForExistenceAndTap(timeout: timeout))
let confirmRemoval = app.alerts.buttons["Remove"]
XCTAssertTrue(confirmRemoval.waitForExistence(timeout: timeout))
confirmRemoval.tap()
Expand Down Expand Up @@ -536,10 +536,10 @@ class CustomerSheetUITest: XCTestCase {

// Should be able to edit CBC enabled PM even though it's the only one
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: timeout))
XCTAssertTrue(app.buttons["Update"].waitForExistence(timeout: timeout))
XCTAssertTrue(app.buttons["Save"].waitForExistence(timeout: timeout))

// ...but should not be able to remove it.
XCTAssertFalse(app.buttons["Remove card"].exists)
XCTAssertFalse(app.buttons["Remove"].exists)
}
// MARK: - PaymentMethodRemove w/ CBC
func testCSPaymentMethodRemoveTwoCards() throws {
Expand Down Expand Up @@ -578,7 +578,7 @@ class CustomerSheetUITest: XCTestCase {
// Assert there are no remove buttons on each tile and the update screen
XCTAssertNil(scroll(collectionView: app.collectionViews.firstMatch, toFindButtonWithId: "CircularButton.Remove"))
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: timeout))
XCTAssertFalse(app.buttons["Remove card"].exists)
XCTAssertFalse(app.buttons["Remove"].exists)

// Dismiss Sheet
app.buttons["Back"].waitForExistenceAndTap(timeout: timeout)
Expand Down Expand Up @@ -613,7 +613,7 @@ class CustomerSheetUITest: XCTestCase {
// Assert there are no remove buttons on each tile and the update screen
XCTAssertNil(scroll(collectionView: app.collectionViews.firstMatch, toFindButtonWithId: "CircularButton.Remove"))
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: timeout))
XCTAssertFalse(app.buttons["Remove card"].exists)
XCTAssertFalse(app.buttons["Remove"].exists)

// Dismiss Sheet
app.buttons["Back"].waitForExistenceAndTap(timeout: timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class EmbeddedUITests: PaymentSheetUITestCase {
app.otherElements["Card Brand Dropdown"].waitForExistenceAndTap()
app.pickerWheels.firstMatch.swipeUp()
app.buttons["Done"].waitForExistenceAndTap()
app.buttons["Update"].waitForExistenceAndTap()
XCTAssertFalse(app.staticTexts["Update card brand"].waitForExistence(timeout: 3))
app.buttons["Save"].waitForExistenceAndTap()
XCTAssertFalse(app.staticTexts["Manage card"].waitForExistence(timeout: 3))

// Ensure card preference is switched to visa
XCTAssertTrue(card1001Button.waitForExistence(timeout: 3))
Expand Down Expand Up @@ -178,12 +178,12 @@ class EmbeddedUITests: PaymentSheetUITestCase {

// Remove last card while selected state is NOT on the card
app.buttons["Edit"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Update card brand"].waitForExistence(timeout: 3.0))
app.buttons["Remove card"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Manage card"].waitForExistence(timeout: 3.0))
app.buttons["Remove"].waitForExistenceAndTap()
dismissAlertView(alertBody: "Visa •••• 1001", alertTitle: "Remove card?", buttonToTap: "Remove")

// Apple pay should be continued to be selected
XCTAssertFalse(app.staticTexts["Update card brand"].waitForExistence(timeout: 3.0))
XCTAssertFalse(app.staticTexts["Manage card"].waitForExistence(timeout: 3.0))
XCTAssertFalse(app.images["stp_card_visa"].waitForExistence(timeout: 3))
XCTAssertFalse(app.images["stp_card_cartes_bancaires"].waitForExistence(timeout: 3))
XCTAssertTrue(applePayButton.isSelected)
Expand Down Expand Up @@ -228,8 +228,8 @@ class EmbeddedUITests: PaymentSheetUITestCase {

// Remove last card while selected state is on the card
app.buttons["Edit"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Update card brand"].waitForExistence(timeout: 3.0))
app.buttons["Remove card"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Manage card"].waitForExistence(timeout: 3.0))
app.buttons["Remove"].waitForExistenceAndTap()
dismissAlertView(alertBody: "Cartes Bancaires •••• 1001", alertTitle: "Remove card?", buttonToTap: "Remove")

// Nothing should be selected
Expand Down Expand Up @@ -264,7 +264,7 @@ class EmbeddedUITests: PaymentSheetUITestCase {
app.otherElements["Card Brand Dropdown"].waitForExistenceAndTap()
app.pickerWheels.firstMatch.swipeUp()
app.buttons["Done"].waitForExistenceAndTap()
app.buttons["Update"].waitForExistenceAndTap()
app.buttons["Save"].waitForExistenceAndTap()

// Tap done on manage payment methods screen, then select 4242 card
app.buttons["Done"].waitForExistenceAndTap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ class PaymentSheetStandardLPMUICBCTests: PaymentSheetStandardLPMUICase {
XCTAssertTrue(app.pickerWheels.firstMatch.waitForExistence(timeout: 5))
app.pickerWheels.firstMatch.swipeUp()
app.toolbars.buttons["Done"].tap()
app.buttons["Update"].waitForExistenceAndTap(timeout: 5)
app.buttons["Save"].waitForExistenceAndTap(timeout: 5)

// We should have updated to Visa
XCTAssertTrue(app.images["carousel_card_visa"].waitForExistence(timeout: 5))
Expand All @@ -996,7 +996,7 @@ class PaymentSheetStandardLPMUICBCTests: PaymentSheetStandardLPMUICase {
XCTAssertTrue(app.pickerWheels.firstMatch.waitForExistence(timeout: 5))
app.pickerWheels.firstMatch.swipeDown()
app.toolbars.buttons["Done"].tap()
app.buttons["Update"].waitForExistenceAndTap(timeout: 5)
app.buttons["Save"].waitForExistenceAndTap(timeout: 5)

// We should have updated to Cartes Bancaires
XCTAssertTrue(app.images["carousel_card_cartes_bancaires"].waitForExistence(timeout: 5))
Expand All @@ -1016,7 +1016,7 @@ class PaymentSheetStandardLPMUICBCTests: PaymentSheetStandardLPMUICase {
// Remove this card
XCTAssertTrue(app.staticTexts["Edit"].waitForExistenceAndTap(timeout: 60.0))
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: 5))
XCTAssertTrue(app.buttons["Remove card"].waitForExistenceAndTap(timeout: 5))
XCTAssertTrue(app.buttons["Remove"].waitForExistenceAndTap(timeout: 5))
let confirmRemoval = app.alerts.buttons["Remove"]
XCTAssertTrue(confirmRemoval.waitForExistence(timeout: 5))
confirmRemoval.tap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ class PaymentSheetCustomerSessionCBCUITests: PaymentSheetUITestCase {
// Detect there are no remove buttons on each tile and the update screen
XCTAssertNil(scroll(collectionView: app.collectionViews.firstMatch, toFindButtonWithId: "CircularButton.Remove")?.tap())
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: 5))
XCTAssertFalse(app.buttons["Remove card"].exists)
XCTAssertFalse(app.buttons["Remove"].exists)

app.buttons["Back"].waitForExistenceAndTap(timeout: 5)
app.buttons["Done"].waitForExistenceAndTap(timeout: 5)
Expand Down Expand Up @@ -1528,7 +1528,7 @@ class PaymentSheetCustomerSessionCBCUITests: PaymentSheetUITestCase {
// Detect there are no remove buttons on each tile and the update screen
XCTAssertNil(scroll(collectionView: app.collectionViews.firstMatch, toFindButtonWithId: "CircularButton.Remove")?.tap())
XCTAssertTrue(app.buttons["CircularButton.Edit"].waitForExistenceAndTap(timeout: 5))
XCTAssertFalse(app.buttons["Remove card"].exists)
XCTAssertFalse(app.buttons["Remove"].exists)

app.buttons["Back"].waitForExistenceAndTap(timeout: 5)
app.buttons["Done"].waitForExistenceAndTap(timeout: 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class PaymentSheetVerticalUITests: PaymentSheetUITestCase {
app.buttons["CircularButton.Edit"].firstMatch.waitForExistenceAndTap()

// Should present the update card view controller
XCTAssertTrue(app.staticTexts["Update card brand"].waitForExistence(timeout: 2.0))
XCTAssertTrue(app.staticTexts["Manage card"].waitForExistence(timeout: 2.0))

// Update card brand to Visa
XCTAssertTrue(app.textFields["Cartes Bancaires"].waitForExistenceAndTap(timeout: 5))
Expand All @@ -269,14 +269,14 @@ class PaymentSheetVerticalUITests: PaymentSheetUITestCase {
XCTAssertTrue(app.textFields["Visa"].waitForExistence(timeout: 5))

// Update the card
app.buttons["Update"].waitForExistenceAndTap(timeout: 5)
app.buttons["Save"].waitForExistenceAndTap(timeout: 5)

// We should have updated to Visa
XCTAssertTrue(app.buttons["Visa ending in 1 0 0 1"].waitForExistence(timeout: 1.0))

// Reselect edit icon and delete the card from the update view controller
app.buttons["Edit"].firstMatch.waitForExistenceAndTap()
app.buttons["Remove card"].waitForExistenceAndTap()
app.buttons["Remove"].waitForExistenceAndTap()
XCTAssertTrue(app.alerts.buttons["Remove"].waitForExistenceAndTap())

// Verify we are kicked out to the main screen after removing all saved payment methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
/* Button text on a screen asking the user to approve a payment */
"Cancel and pay another way" = "Cancel and pay another way";

/* Text on a screen that indicates card details cannot be changed. */
"Card details cannot be changed." = "Card details cannot be changed.";

/* Title for a button that allows the user to use a different email in the signup flow. */
"Change email" = "Change email";

Expand Down Expand Up @@ -173,6 +176,9 @@ re-entering the security code (CVV/CVC). */
/* Title of the logout action. */
"Log out of Link" = "Log out of Link";

/* Title shown above a view containing the customer's card that they can delete or update */
"Manage card" = "Manage card";

/* Title shown above a view containing the customer's payment method that they can delete or update */
"Manage payment method" = "Manage payment method";

Expand Down Expand Up @@ -268,7 +274,8 @@ e.g, 'Pay faster at Example, Inc. and thousands of businesses.' */
/* Label for a button that re-sends the a login code when tapped */
"Resend code" = "Resend code";

/* A button used for saving a new payment method */
/* A button used for saving a new payment method
Label on a button that when tapped, updates a card brand. */
"Save" = "Save";

/* Title shown above a form where the customer can enter payment information like credit card details, email, billing address, etc. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ extension String.Localized {
STPLocalizedString("Back", "Text for back button")
}

static var card_details_cannot_be_changed: String {
STPLocalizedString(
"Card details cannot be changed.",
"Text on a screen that indicates card details cannot be changed."
)
}

static var manage_card: String {
STPLocalizedString(
"Manage card",
"Title shown above a view containing the customer's card that they can delete or update"
)
}

static var save: String {
STPLocalizedString(
"Save",
"Label on a button that when tapped, updates a card brand."
)
}

static var update_card: String {
STPLocalizedString(
"Update card",
Expand Down
Loading
Loading