-
Notifications
You must be signed in to change notification settings - Fork 995
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
Set 'Change >' and sublabel to selected embedded form rows #4538
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8902164
Set/unset Change > + label to selected row
yuki-stripe 3694d32
Add tests
yuki-stripe 6bf7437
Fix flatWithCheckmark
yuki-stripe fc7f49a
Support CBC
yuki-stripe a1cf117
pr feedback
yuki-stripe a19f8a4
fix test xcode 15 compile issue
yuki-stripe 77581cf
sigh more xcode 15 differences
yuki-stripe 438c550
Fix test
yuki-stripe 38a3fb2
Merge remote-tracking branch 'origin/master' into yuki/embedded-updat…
yuki-stripe 43bff63
update snapshot tests
yuki-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -60,4 +60,88 @@ class EmbeddedPaymentElementSnapshotTests: STPSnapshotTestCase, EmbeddedPaymentE | |
XCTAssertEqual(sut.view.directionalLayoutMargins, .zero) | ||
XCTAssertFalse(sut.view.hasAmbiguousLayout) | ||
} | ||
|
||
// MARK: - 'Change >' button and sublabel (eg Visa 4242) | ||
|
||
func testShowsChangeButton_flatRadio() async throws { | ||
await _testShowsChangeButton(rowStyle: .flatWithRadio) | ||
} | ||
|
||
func testShowsChangeButton_floatingButton() async throws { | ||
await _testShowsChangeButton(rowStyle: .floatingButton) | ||
|
||
} | ||
|
||
func testShowsChangeButton_flatCheckmark() async throws { | ||
await _testShowsChangeButton(rowStyle: .flatWithCheckmark) | ||
} | ||
|
||
func _testShowsChangeButton(rowStyle: PaymentSheet.Appearance.EmbeddedPaymentElement.Row.Style) async { | ||
var configuration = configuration | ||
configuration.appearance.embeddedPaymentElement.row.style = rowStyle | ||
var paymentIntentConfig = paymentIntentConfig | ||
paymentIntentConfig.paymentMethodTypes = ["card", "us_bank_account", "afterpay_clearpay"] | ||
let loadResult = PaymentSheetLoader.LoadResult( | ||
intent: .deferredIntent(intentConfig: paymentIntentConfig), | ||
elementsSession: ._testValue(paymentMethodTypes: ["card", "us_bank_account", "afterpay_clearpay"]), | ||
savedPaymentMethods: [], | ||
paymentMethodTypes: [.stripe(.card), .stripe(.USBankAccount), .stripe(.afterpayClearpay)] | ||
) | ||
await AddressSpecProvider.shared.loadAddressSpecs() | ||
await FormSpecProvider.shared.load() | ||
let sut = EmbeddedPaymentElement( | ||
configuration: configuration, | ||
loadResult: loadResult, | ||
analyticsHelper: ._testValue() | ||
) | ||
sut.view.autosizeHeight(width: 300) | ||
sut.delegate = self | ||
sut.presentingViewController = UIViewController() | ||
// There are 3 variations of adding a 'Change >' button and sublabel to a selected row | ||
// 1️⃣ | ||
// ...tapping card and filling out the form... | ||
sut.embeddedPaymentMethodsView.getRowButton(accessibilityIdentifier: "Card").handleTap() | ||
let cardForm = sut.formCache[.stripe(.card)]! | ||
cardForm.getTextFieldElement("Card number")?.setText("4242424242424242") | ||
cardForm.getTextFieldElement("MM / YY").setText("1232") | ||
cardForm.getTextFieldElement("CVC").setText("123") | ||
cardForm.getTextFieldElement("ZIP").setText("65432") | ||
sut.selectedFormViewController?.didTapPrimaryButton() | ||
|
||
// ...should show the card row w/ the 'Change >' + "Visa 4242" | ||
STPSnapshotVerifyView(sut.view, identifier: "card") | ||
|
||
// 2️⃣ | ||
// Tapping US Bank Account... | ||
sut.embeddedPaymentMethodsView.getRowButton(accessibilityIdentifier: "US bank account").handleTap() | ||
// ...and backing out... | ||
sut.embeddedFormViewControllerDidCancel(sut.selectedFormViewController!) | ||
// ...should keep the card row selected... | ||
// (this tests that setting the selection back to the previous works) | ||
STPSnapshotVerifyView(sut.view, identifier: "us_bank_account_canceled") | ||
|
||
// Filling out US Bank account... | ||
sut.embeddedPaymentMethodsView.getRowButton(accessibilityIdentifier: "US bank account").handleTap() | ||
let bankForm = sut.formCache[.stripe(.USBankAccount)] as! USBankAccountPaymentMethodElement | ||
bankForm.getTextFieldElement("Full name").setText("Name") | ||
bankForm.getTextFieldElement("Email").setText("[email protected]") | ||
bankForm.linkedBank = FinancialConnectionsLinkedBank(sessionId: "123", accountId: "123", displayName: "Success", bankName: "StripeBank", last4: "6789", instantlyVerified: true) | ||
sut.selectedFormViewController?.didTapPrimaryButton() | ||
// ...should show the row w/ 'Change >' + "6789" (the last bank 4) | ||
STPSnapshotVerifyView(sut.view, identifier: "us_bank_account_continue") | ||
|
||
// 3️⃣ | ||
// Tapping Afterpay and filling out the form... | ||
sut.embeddedPaymentMethodsView.getRowButton(accessibilityIdentifier: "Afterpay").handleTap() | ||
let afterpayForm = sut.formCache[.stripe(.afterpayClearpay)]! | ||
afterpayForm.getTextFieldElement("Full name")?.setText("Tester") | ||
afterpayForm.getTextFieldElement("Email")?.setText("[email protected]") | ||
afterpayForm.getTextFieldElement("Address line 1").setText("asdf") | ||
afterpayForm.getTextFieldElement("City").setText("asdf") | ||
afterpayForm.getTextFieldElement("ZIP").setText("12345") | ||
sut.selectedFormViewController?.didTapPrimaryButton() | ||
|
||
// ...should show the row w/ 'Change >' | ||
STPSnapshotVerifyView(sut.view, identifier: "afterpay") | ||
} | ||
} |
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
Binary file added
BIN
+37.8 KB
...Tests/testShowsChangeButton_flatCheckmarkWithCompletionHandler__afterpay@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.3 KB
...shotTests/testShowsChangeButton_flatCheckmarkWithCompletionHandler__card@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.3 KB
...hangeButton_flatCheckmarkWithCompletionHandler__us_bank_account_canceled@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.2 KB
...hangeButton_flatCheckmarkWithCompletionHandler__us_bank_account_continue@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.7 KB
...shotTests/testShowsChangeButton_flatRadioWithCompletionHandler__afterpay@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.4 KB
...SnapshotTests/testShowsChangeButton_flatRadioWithCompletionHandler__card@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.4 KB
...owsChangeButton_flatRadioWithCompletionHandler__us_bank_account_canceled@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.1 KB
...owsChangeButton_flatRadioWithCompletionHandler__us_bank_account_continue@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.6 KB
...ests/testShowsChangeButton_floatingButtonWithCompletionHandler__afterpay@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.2 KB
...hotTests/testShowsChangeButton_floatingButtonWithCompletionHandler__card@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.2 KB
...angeButton_floatingButtonWithCompletionHandler__us_bank_account_canceled@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.8 KB
...angeButton_floatingButtonWithCompletionHandler__us_bank_account_continue@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to work with co-branded cards, when I enter a co-branded (Visa/CB) card and choose CB, the copy says "Visa ...". we need to also check the preferred network (if it exists) on the card params. Can we add a test for this too?
params.paymentMethodParams.card?.networks?.preferred
There's also a weird edge case where you can fill out a form for a co-branded card and don't select a brand since it's optional, so the card brand gets decided on the backend. Not exactly sure what we show there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this! Fixed it up. Are there things we can do to make it harder to make this mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did something similar to what you did with
func brand(for card: STPPaymentMethodCardParams?) -> STPCardBrand
onSTPPaymentMethodCard
. But this is the first instance AFAIK where we have needed to read it off theSTPPaymentMethodCardParams
. Maybe we "internally" deprecate STPCardBrandUtilities.stringFrom(brand) somehow, since the card number is not the single source of truth for the card brand for a number.