Skip to content

Commit

Permalink
Merge branch 'master' into joyceqin-update-bank-account
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceqin-stripe authored Nov 21, 2024
2 parents a10899f + cfb859a commit 4b0b0db
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class EmbeddedUITests: PaymentSheetUITestCase {
let bank6789Button = app.buttons["••••6789"]
let applePayButton = app.buttons["Apple Pay"]

// Ensure card bankacct is selected, and apple pay is not.
// Ensure card bank acct. is selected, and apple pay is not.
XCTAssertTrue(bank6789Button.waitForExistence(timeout: 3.0))
XCTAssertTrue(bank6789Button.isSelected)
XCTAssertTrue(applePayButton.waitForExistence(timeout: 3.0))
Expand All @@ -362,7 +362,7 @@ class EmbeddedUITests: PaymentSheetUITestCase {
XCTAssertTrue(applePayButton.isSelected)
XCTAssertFalse(bank6789Button.isSelected)

// Remove bankacct while it isn't selected
// Remove bank acct. while it isn't selected
app.buttons["View more"].waitForExistenceAndTap()
app.buttons["Edit"].waitForExistenceAndTap()
app.buttons["CircularButton.Remove"].firstMatch.waitForExistenceAndTap()
Expand All @@ -389,6 +389,49 @@ class EmbeddedUITests: PaymentSheetUITestCase {
payWithApplePay()
XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10))
}

func testSelection_savedPaymentMethod() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
settings.uiStyle = .embedded
settings.customerMode = .returning
settings.applePayEnabled = .on

loadPlayground(app, settings)
app.buttons["Present embedded payment element"].waitForExistenceAndTap()

// Select Cash App Pay
app.buttons["Cash App Pay"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Cash App Pay"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)

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

// Verify we have dismissed the saved payment method view and have the correct card selected
XCTAssertFalse(app.staticTexts["Select payment method"].waitForExistence(timeout: 2))
XCTAssertTrue(app.staticTexts["•••• 4242"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)

// Select Cash App Pay again
app.buttons["Cash App Pay"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Cash App Pay"].waitForExistence(timeout: 10))
XCTAssertTrue(app.buttons["Checkout"].isEnabled)

// Delete one payment method so we only have one left, we should not auto select the last remaining saved PM
XCTAssertTrue(app.buttons["View more"].waitForExistenceAndTap())
XCTAssertTrue(app.buttons["Edit"].waitForExistenceAndTap())
XCTAssertTrue(app.buttons["CircularButton.Remove"].firstMatch.waitForExistenceAndTap())
dismissAlertView(alertBody: "Visa •••• 4242", alertTitle: "Remove card?", buttonToTap: "Remove")
XCTAssertTrue(app.buttons["Done"].waitForExistenceAndTap())

// Verify we show the bank account in the saved PM row
XCTAssertTrue(app.buttons["Edit"].waitForExistence(timeout: 10))
XCTAssertFalse(app.buttons["••••6789"].isSelected)
XCTAssertTrue(app.buttons["Cash App Pay"].isSelected)
XCTAssertTrue(app.staticTexts["Cash App Pay"].waitForExistence(timeout: 10))
}

func testSelection() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ final class LinkLoginDataSourceImplementation: LinkLoginDataSource {
country: country,
amount: elementsSessionContext?.amount,
currency: elementsSessionContext?.currency,
intentId: elementsSessionContext?.intentId
// TODO(tillh): Only pass `intentId` when the session is eligible for incentives.
intentId: nil
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
2E4C37C73AD202C8A3DD2E4E /* LoadingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FF291A25EA43D4D100983B /* LoadingViewController.swift */; };
2EC9C94DD8D62E4F4EFC8AB8 /* IntentStatusPollerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 990304EF35A0EE37DCE20D5B /* IntentStatusPollerTest.swift */; };
311AC53D6C76953E9B70148A /* ConsumerSession+PublishableKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D61B52BFA201D25E8F6428 /* ConsumerSession+PublishableKey.swift */; };
31316BD72CEC00FC0000016F /* PaymentSheet+APIMockTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31316BD62CEC00EF0000016F /* PaymentSheet+APIMockTest.swift */; };
313D00C82CD9972F00A8E6B0 /* PayWithNativeLinkController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 313D00C72CD9972F00A8E6B0 /* PayWithNativeLinkController.swift */; };
313F5F832B0BE5FD00BD98A9 /* Docs.docc in Sources */ = {isa = PBXBuildFile; fileRef = 313F5F822B0BE5FD00BD98A9 /* Docs.docc */; };
3147CEBB2CC07E960067B5E4 /* LinkUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3147CEBA2CC07E960067B5E4 /* LinkUtils.swift */; };
Expand Down Expand Up @@ -464,6 +465,7 @@
2DF75FD35820E7556EC34D15 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Localizable.strings; sourceTree = "<group>"; };
2E2B99961C09E31383C9FCE9 /* mt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = mt; path = mt.lproj/Localizable.strings; sourceTree = "<group>"; };
2E42F31D392C0AED757D6239 /* StripePaymentSheet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StripePaymentSheet.framework; sourceTree = BUILT_PRODUCTS_DIR; };
31316BD62CEC00EF0000016F /* PaymentSheet+APIMockTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PaymentSheet+APIMockTest.swift"; sourceTree = "<group>"; };
313D00C72CD9972F00A8E6B0 /* PayWithNativeLinkController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayWithNativeLinkController.swift; sourceTree = "<group>"; };
313F5F822B0BE5FD00BD98A9 /* Docs.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Docs.docc; sourceTree = "<group>"; };
3147CEBA2CC07E960067B5E4 /* LinkUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkUtils.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1650,6 +1652,7 @@
5BA7BFC43DB3EFD38A460EB9 /* PaymentMethodMessagingViewSnapshotTests.swift */,
619AF0842BF56C5E00D1C981 /* PaymentMethodRowButtonSnapshotTests.swift */,
8A0B7F6E25D93C0C0ACE3B3D /* PaymentSheet+APITest.swift */,
31316BD62CEC00EF0000016F /* PaymentSheet+APIMockTest.swift */,
82C21D5722BDEB8BAA71F69F /* PaymentSheet+DashboardConfirmParamsTest.swift */,
AA8F7F2824DFC78268ED6459 /* PaymentSheet+DeferredAPITest.swift */,
135B7354260E0E7CADCF3426 /* PaymentSheetAddressTests.swift */,
Expand Down Expand Up @@ -1960,6 +1963,7 @@
B65FE7092BED33EA009A73FC /* VerticalPaymentMethodListViewControllerSnapshotTest.swift in Sources */,
37F750E1C99D6257E845A66E /* BacsDDMandateViewSnapshotTests.swift in Sources */,
694A3B36AC19FC1F87EF0CB1 /* CustomerSheetPaymentMethodAvailabilityTests.swift in Sources */,
31316BD72CEC00FC0000016F /* PaymentSheet+APIMockTest.swift in Sources */,
9F750611C4E8EAABE9F0B460 /* CustomerSheetTests.swift in Sources */,
4FF15C6F7AF22F55B2F2BEA8 /* CustomerSheetSnapshotTests.swift in Sources */,
31699A832BE183D40048677F /* DownloadManagerTest.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ extension EmbeddedPaymentElement: VerticalSavedPaymentMethodsViewControllerDeleg
savedPaymentMethods: latestPaymentMethods
)

// If there are still saved payment methods & the saved payment method was previously selected to presenting
// the list of saved payment methods, then the embedded view should continue to show it is selected, otherwise unselected.
let isSelected: Bool = latestPaymentMethods.count > 0 && embeddedPaymentMethodsView.selection?.isSaved ?? false
// Select the *saved payment method if we selected a payment method
// or
// there are still saved payment methods & the saved payment method was previously selected to presenting
let isSelected = (latestPaymentMethods.count > 1 && selectedPaymentMethod != nil) ||
(embeddedPaymentMethodsView.selection?.isSaved ?? false && latestPaymentMethods.count > 0)
embeddedPaymentMethodsView.updateSavedPaymentMethodRow(savedPaymentMethods.first,
isSelected: isSelected,
accessoryType: accessoryType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,21 @@ extension PaymentSheet {
case .withPaymentMethod(let paymentMethod):
confirmWithPaymentMethod(paymentMethod, nil, false)
case .withPaymentDetails(let linkAccount, let paymentDetails):
// shouldSave is false, as we don't show a save checkbox in the Link VC
confirmWithPaymentDetails(linkAccount, paymentDetails, paymentDetails.cvc, false)
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
switch result {
case .success(let paymentDetailsShareResponse):
confirmWithPaymentMethod(paymentDetailsShareResponse.paymentMethod, linkAccount, shouldSave)
case .failure(let error):
STPAnalyticsClient.sharedClient.logLinkSharePaymentDetailsFailure(error: error)
paymentHandlerCompletion(.failed, error as NSError)
}
}
} else {
confirmWithPaymentDetails(linkAccount, paymentDetails, paymentDetails.cvc, shouldSave)
}
case .withPaymentMethodParams(let linkAccount, let paymentMethodParams):
// shouldSave is false, as we don't show a save checkbox in the Link VC
createPaymentDetailsAndConfirm(linkAccount, paymentMethodParams, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ extension STPElementsSession {
]
return STPElementsSession.decodedObject(fromAPIResponse: apiResponse)!
}

static var linkPassthroughElementsSession: STPElementsSession {
let apiResponse: [String: Any] = ["payment_method_preference": ["ordered_payment_method_types": ["123"],
"country_code": "US", ] as [String: Any],
"session_id": "123",
"apple_pay_preference": "enabled",
"link_settings": ["link_funding_sources": ["card"],
"link_passthrough_mode_enabled": true]
]
return STPElementsSession.decodedObject(fromAPIResponse: apiResponse)!
}
}

// Just for the purposes of this test. No need to add the (tiny) overhead of Equatable to the published binary
Expand Down
Loading

0 comments on commit 4b0b0db

Please sign in to comment.