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

Embedded confirm tests #4249

Merged
merged 9 commits into from
Nov 14, 2024
Merged
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
267 changes: 267 additions & 0 deletions Example/PaymentSheet Example/PaymentSheetUITest/EmbeddedUITest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,268 @@ class EmbeddedUITests: PaymentSheetUITestCase {
springboard.buttons["Continue"].waitForExistenceAndTap()
// Stop here; Links's test playground is out of scope
}

func testCVCRecollection() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .returning
settings.mode = .payment
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .continue
settings.requireCVCRecollection = .on
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

// Select the saved card
app.buttons["View more"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Select payment method"].waitForExistence(timeout: 10))
app.buttons["•••• 4242"].firstMatch.waitForExistenceAndTap()

// Ensure the card is selected and start checking out
XCTAssertEqual(app.staticTexts["Payment method"].label, "•••• 4242")
app.swipeUp() // scroll to see the checkout button
XCTAssertTrue(app.buttons["Checkout"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)
app.buttons["Checkout"].tap()

// CVC field should already be selected
app.typeText("123")
app.buttons["Confirm"].waitForExistenceAndTap()

XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10))
}

func testCashAppPay() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .returning
settings.mode = .payment
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .continue
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

app.buttons["Cash App Pay"].waitForExistenceAndTap()

// Ensure Cash App Pay is selected and start checking out
XCTAssertEqual(app.staticTexts["Payment method"].label, "Cash App Pay")
app.swipeUp() // scroll to see the checkout button
XCTAssertTrue(app.buttons["Checkout"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)
app.buttons["Checkout"].tap()

webviewAuthorizePaymentButton.waitForExistenceAndTap(timeout: 10)
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10))
}

func testCashAppPayAndSetup() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .returning
settings.mode = .paymentWithSetup
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .continue
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

app.buttons["Cash App Pay"].waitForExistenceAndTap()

// Ensure Cash App Pay is selected and start checking out
XCTAssertEqual(app.staticTexts["Payment method"].label, "Cash App Pay")
app.swipeUp() // scroll to see the checkout button
XCTAssertTrue(app.buttons["Checkout"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)
app.buttons["Checkout"].tap()

webviewAuthorizePaymentButton.waitForExistenceAndTap(timeout: 10)
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10))
}

func testCashAppPaySetup() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .returning
settings.mode = .setup
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .continue
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

app.buttons["Cash App Pay"].waitForExistenceAndTap()

// Ensure Cash App Pay is selected and start checking out
XCTAssertEqual(app.staticTexts["Payment method"].label, "Cash App Pay")
app.swipeUp() // scroll to see the checkout button
XCTAssertTrue(app.buttons["Checkout"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)
app.buttons["Checkout"].tap()

webviewAuthorizeSetupButton.waitForExistenceAndTap(timeout: 10)
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10))
}

func testCashAppPayBillingAddressCollection() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .returning
settings.mode = .payment
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .continue
settings.collectName = .always
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

app.buttons["Cash App Pay"].waitForExistenceAndTap()

let fullNameField = app.textFields["Full name"]
XCTAssertTrue(fullNameField.waitForExistence(timeout: 10))
fullNameField.forceTapElement()
fullNameField.typeText("Jane Doe")

app.buttons["Continue"].tap()

// Ensure Cash App Pay is selected and start checking out
XCTAssertTrue(app.staticTexts["Payment method"].waitForExistence(timeout: 10))
XCTAssertEqual(app.staticTexts["Payment method"].label, "Cash App Pay")
app.swipeUp() // scroll to see the checkout button
XCTAssertTrue(app.buttons["Checkout"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)
app.buttons["Checkout"].tap()

webviewAuthorizePaymentButton.waitForExistenceAndTap(timeout: 10)
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10))
}

func testExternalPayPal() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .new
settings.mode = .payment
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .continue
settings.externalPaymentMethods = .paypal
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

app.buttons["PayPal"].waitForExistenceAndTap()

// Ensure PayPal is selected and start checking out
XCTAssertEqual(app.staticTexts["Payment method"].label, "PayPal")
app.swipeUp() // scroll to see the checkout button
XCTAssertTrue(app.buttons["Checkout"].isEnabled)
app.buttons["Checkout"].waitForExistenceAndTap()

XCTAssertNotNil(app.staticTexts["Confirm external_paypal?"])
app.buttons["Cancel"].waitForExistenceAndTap()

app.buttons["Checkout"].waitForExistenceAndTap()
app.buttons["Confirm"].waitForExistenceAndTap()

XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10))
}

func testSEPA() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.currency = .eur
settings.allowsDelayedPMs = .on
settings.customerMode = .new
settings.mode = .payment
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .confirm
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

app.buttons["SEPA Debit"].waitForExistenceAndTap()

app.textFields["Full name"].waitForExistenceAndTap()
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["Pay €50.99"].tap()

XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0))
}

func testUSBankAccount() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .returning
settings.mode = .payment
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .confirm
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

XCTAssertTrue(app.buttons["US bank account"].waitForExistenceAndTap())

// Fill out name and email fields
let continueButton = app.buttons["Continue"]
XCTAssertFalse(continueButton.isEnabled)
app.textFields["Full name"].tap()
app.typeText("John Doe" + XCUIKeyboardKey.return.rawValue)
app.typeText("test-\(UUID().uuidString)@example.com" + XCUIKeyboardKey.return.rawValue)
XCTAssertTrue(continueButton.isEnabled)
continueButton.tap()

// Go through connections flow
app.buttons["Agree and continue"].tap()
app.staticTexts["Test Institution"].forceTapElement()
// "Success" institution is automatically selected because its the first
app.buttons["connect_accounts_button"].waitForExistenceAndTap(timeout: 10)

XCUIApplication().toolbars.buttons["Done"].waitForExistenceAndTap()
app.buttons["Not now"].waitForExistenceAndTap()

XCTAssertTrue(app.staticTexts["Success"].waitForExistence(timeout: 10))
app.buttons.matching(identifier: "Done").allElementsBoundByIndex.last?.tap()

// Make sure bottom notice mandate is visible
XCTAssertTrue(app.textViews["By continuing, you agree to authorize payments pursuant to these terms."].waitForExistence(timeout: 5))

let saveThisAccountToggle = app.switches["Save this account for future Example, Inc. payments"]
XCTAssertFalse(saveThisAccountToggle.isSelected)
saveThisAccountToggle.tap()

// Confirm
app.buttons["Pay $50.99"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0))
}

func test3DS2CardAlwaysAuthenticate() throws {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.customerMode = .new
settings.mode = .payment
settings.integrationType = .deferred_csc
settings.uiStyle = .embedded
settings.formSheetAction = .continue
settings.currency = .eur
loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

XCTAssertTrue(app.buttons["Card"].waitForExistenceAndTap())
XCTAssertTrue(app.staticTexts["Add card"].waitForExistence(timeout: 10))

// Card number from https://docs.stripe.com/testing#regulatory-cards
try! fillCardData(app, cardNumber: "4000002760003184")
app.toolbars.buttons["Done"].waitForExistenceAndTap()
app.buttons["Continue"].waitForExistenceAndTap()
app.swipeUp() // scroll to see the checkout button
app.buttons["Checkout"].waitForExistenceAndTap()

// Finish the 3DS2 payment
let challengeCodeTextField = app.textFields["STDSTextField"]
XCTAssertTrue(challengeCodeTextField.waitForExistenceAndTap(timeout: 10))
challengeCodeTextField.typeText("424242" + XCUIKeyboardKey.return.rawValue)
app.buttons["Submit"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0))
}

func dismissAlertView(alertBody: String, alertTitle: String, buttonToTap: String) {
let alertText = app.staticTexts[alertBody]
Expand All @@ -563,3 +825,8 @@ class EmbeddedUITests: PaymentSheetUITestCase {
XCTAssertTrue(app.buttons[label1].waitForExistence(timeout: 3.0))
}
}

extension EmbeddedUITests {
var webviewAuthorizePaymentButton: XCUIElement { app.firstDescendant(withLabel: "AUTHORIZE TEST PAYMENT") }
var webviewAuthorizeSetupButton: XCUIElement { app.firstDescendant(withLabel: "AUTHORIZE TEST SETUP") }
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class EmbeddedPaymentElementTest: XCTestCase {
confirmParams.paymentMethodParams.card = STPPaymentMethodCardParams()
confirmParams.paymentMethodParams.card?.number = "4242424242424242"
confirmParams.paymentMethodParams.card?.expMonth = NSNumber(value: 12)
confirmParams.paymentMethodParams.card?.expYear = NSNumber(value: 34)
confirmParams.paymentMethodParams.card?.expYear = NSNumber(value: Calendar.current.component(.year, from: Date()) + 5)
confirmParams.paymentMethodParams.card?.cvc = "123"
confirmParams.setDefaultBillingDetailsIfNecessary(for: sut.configuration)

Expand Down
Loading