-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show mandate in flowcontroller edge case, tests
- Loading branch information
1 parent
6caf27a
commit ce2aed4
Showing
20 changed files
with
493 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -875,6 +875,75 @@ class PaymentSheetStandardLPMUITests: PaymentSheetUITestCase { | |
|
||
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 15.0)) | ||
} | ||
|
||
func testSavedSEPADebitPaymentMethod_FlowController_ShowsMandate() { | ||
var settings = PaymentSheetTestPlaygroundSettings.defaultValues() | ||
settings.uiStyle = .flowController | ||
settings.customerMode = .new | ||
settings.applePayEnabled = .off // disable Apple Pay | ||
settings.mode = .setup | ||
settings.allowsDelayedPMs = .on | ||
loadPlayground(app, settings) | ||
|
||
let paymentMethodButton = app.buttons["Payment method"] | ||
XCTAssertTrue(paymentMethodButton.waitForExistence(timeout: 60.0)) | ||
paymentMethodButton.tap() | ||
|
||
// Save SEPA | ||
app.buttons["+ Add"].waitForExistenceAndTap() | ||
guard let sepa = scroll(collectionView: app.collectionViews.firstMatch, toFindCellWithId: "SEPA Debit") else { XCTFail("Couldn't find SEPA"); return; } | ||
sepa.tap() | ||
|
||
app.textFields["Full name"].tap() | ||
app.typeText("John Doe" + XCUIKeyboardKey.return.rawValue) | ||
app.typeText("[email protected]" + XCUIKeyboardKey.return.rawValue) | ||
app.typeText("AT611904300234573201" + XCUIKeyboardKey.return.rawValue) | ||
app.textFields["Address line 1"].tap() | ||
app.typeText("510 Townsend St" + XCUIKeyboardKey.return.rawValue) | ||
app.typeText("Floor 3" + XCUIKeyboardKey.return.rawValue) | ||
app.typeText("San Francisco" + XCUIKeyboardKey.return.rawValue) | ||
app.textFields["ZIP"].tap() | ||
app.typeText("94102" + XCUIKeyboardKey.return.rawValue) | ||
app.buttons["Continue"].tap() | ||
app.buttons["Confirm"].tap() | ||
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0)) | ||
|
||
// Reload w/ same customer | ||
reload(app, settings: settings) | ||
// Unfortunately, the next time you check out, Link is still selected by default. | ||
// Select the saved SEPA PM to make it the default and make sure we can still check out successfully. | ||
paymentMethodButton.tap() | ||
app.buttons["••••3201"].waitForExistenceAndTap() | ||
XCTAssertTrue(app.otherElements.matching(identifier: "mandatetextview").element.exists) | ||
app.buttons["Continue"].tap() | ||
app.buttons["Confirm"].tap() | ||
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0)) | ||
|
||
// Reload w/ same customer | ||
reload(app, settings: settings) | ||
// This time, expect SEPA to be pre-selected as the default | ||
XCTAssertEqual(paymentMethodButton.label, "••••3201") | ||
// Tapping confirm without presenting flowcontroller should show the mandate | ||
app.buttons["Confirm"].tap() | ||
XCTAssertTrue(app.otherElements.matching(identifier: "mandatetextview").element.waitForExistence(timeout: 1)) | ||
// Tapping out should cancel the payment | ||
app.tap() | ||
XCTAssertTrue(app.staticTexts["Payment canceled."].waitForExistence(timeout: 10.0)) | ||
// Tapping confirm again and hitting continue should confirm the payment | ||
app.buttons["Confirm"].tap() | ||
app.buttons["Continue"].tap() | ||
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0)) | ||
|
||
// Reload w/ same customer | ||
reload(app, settings: settings) | ||
// If you present the flowcontroller and see the mandate... | ||
app.buttons["••••3201"].waitForExistenceAndTap() | ||
XCTAssertTrue(app.otherElements.matching(identifier: "mandatetextview").element.exists) | ||
// ...you shouldn't see the mandate again when you confirm | ||
app.buttons["Continue"].tap() | ||
app.buttons["Confirm"].tap() | ||
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0)) | ||
} | ||
} | ||
|
||
class PaymentSheetDeferredUITests: PaymentSheetUITestCase { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...et/StripePaymentSheet/Source/PaymentSheet/ViewControllers/SepaMandateViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// SepaMandateViewController.swift | ||
// StripePaymentSheet | ||
// | ||
// Created by Yuki Tokuhiro on 9/6/23. | ||
// | ||
|
||
@_spi(STP) import StripeCore | ||
import UIKit | ||
// @_spi(STP) import StripePayments | ||
@_spi(STP) import StripeUICore | ||
|
||
class SepaMandateViewController: UIViewController, BottomSheetContentViewController { | ||
let requiresFullScreen: Bool = false | ||
|
||
lazy var navigationBar: SheetNavigationBar = { | ||
let navBar = SheetNavigationBar(isTestMode: false, appearance: configuration.appearance) | ||
navBar.setStyle(.none) | ||
navBar.delegate = self | ||
return navBar | ||
}() | ||
private lazy var sepaMandateElement: SimpleMandateElement = { | ||
let mandateText = String(format: String.Localized.sepa_mandate_text, configuration.merchantDisplayName) | ||
return SimpleMandateElement(mandateText: mandateText, theme: configuration.appearance.asElementsTheme) | ||
}() | ||
|
||
private lazy var confirmButton: ConfirmButton = { | ||
let button = ConfirmButton( | ||
callToAction: .customWithLock(title: String.Localized.continue), | ||
appearance: configuration.appearance, | ||
didTap: { [weak self] in | ||
self?.completion(true) | ||
} | ||
) | ||
return button | ||
}() | ||
|
||
let configuration: PaymentSheet.Configuration | ||
let completion: (Bool) -> Void | ||
|
||
/// - Parameter completion: Called with `true` after the customer accepts the mandate by tapping the "continue" button, or called with `false` after the customer dismisses the view (either by tapping out or swiping down). Does not dismiss the view controller. | ||
required init(configuration: PaymentSheet.Configuration, completion: @escaping (Bool) -> Void) { | ||
self.configuration = configuration | ||
self.completion = completion | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = configuration.appearance.colors.background | ||
let stackView = UIStackView(arrangedSubviews: [sepaMandateElement.view, confirmButton]) | ||
stackView.axis = .vertical | ||
stackView.spacing = PaymentSheetUI.defaultPadding | ||
|
||
view.addAndPinSubviewToSafeArea(stackView, insets: PaymentSheetUI.defaultSheetMargins/*.insets( | ||
top: PaymentSheetUI.defaultSheetMargins.top, | ||
leading: PaymentSheetUI.defaultSheetMargins.leading, | ||
bottom: PaymentSheetUI.defaultSheetMargins.bottom, | ||
trailing: PaymentSheetUI.defaultSheetMargins.trailing | ||
)*/) | ||
} | ||
|
||
func didTapOrSwipeToDismiss() { | ||
self.completion(false) | ||
} | ||
} | ||
|
||
extension SepaMandateViewController: SheetNavigationBarDelegate { | ||
func sheetNavigationBarDidClose(_ sheetNavigationBar: SheetNavigationBar) { | ||
self.completion(false) | ||
} | ||
|
||
func sheetNavigationBarDidBack(_ sheetNavigationBar: SheetNavigationBar) { | ||
self.completion(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.