Skip to content
Closed
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
30 changes: 10 additions & 20 deletions Stripe/StripeiOSTests/ConfirmButtonSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import UIKit
// @iOS26
class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
func testConfirmButton() {
var appearance = PaymentSheet.Appearance.default.applyingLiquidGlassIfPossible()
let confirmButton = ConfirmButton(style: .stripe, callToAction: .setup, appearance: appearance, didTap: {})
let appearance = PaymentSheet.Appearance.default.applyingLiquidGlassIfPossible()
let confirmButton = ConfirmButton(callToAction: .setup, appearance: appearance, didTap: {})

verify(confirmButton)
}
Expand All @@ -32,7 +32,6 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
appearance.primaryButton = button

let confirmButton = ConfirmButton(
style: .stripe,
callToAction: .setup,
appearance: appearance,
didTap: {}
Expand All @@ -45,7 +44,6 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
var appearance = PaymentSheet.Appearance.default.applyingLiquidGlassIfPossible()
appearance.font.base = try XCTUnwrap(UIFont(name: "AmericanTypewriter", size: 12.0))
let confirmButton = ConfirmButton(
style: .stripe,
callToAction: .custom(title: "Custom Title"),
appearance: appearance,
didTap: {}
Expand All @@ -60,7 +58,6 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
appearance.font.sizeScaleFactor = 0.85

let confirmButton = ConfirmButton(
style: .stripe,
callToAction: .custom(title: "Custom Title"),
appearance: appearance,
didTap: {}
Expand All @@ -72,8 +69,7 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
// Tests that `primaryButton` disabled color is correct for the default theme
func testConfirmButtonDefaultDisabledColor() {
let confirmButton = ConfirmButton(
state: .disabled,
style: .stripe,
status: .disabled,
callToAction: .setup,
appearance: .default.applyingLiquidGlassIfPossible(),
didTap: {}
Expand All @@ -91,8 +87,7 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
appearance.colors.primary = .yellow

let confirmButton = ConfirmButton(
state: .disabled,
style: .stripe,
status: .disabled,
callToAction: .setup,
appearance: appearance,
didTap: {}
Expand All @@ -110,8 +105,7 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
appearance.primaryButton = button

let confirmButton = ConfirmButton(
state: .disabled,
style: .stripe,
status: .disabled,
callToAction: .setup,
appearance: appearance,
didTap: {}
Expand All @@ -131,8 +125,7 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
appearance.colors.primary = .yellow

let confirmButton = ConfirmButton(
state: .disabled,
style: .stripe,
status: .disabled,
callToAction: .setup,
appearance: appearance,
didTap: {}
Expand All @@ -150,8 +143,7 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
appearance.primaryButton = button

let confirmButton = ConfirmButton(
state: .disabled,
style: .stripe,
status: .disabled,
callToAction: .setup,
appearance: appearance,
didTap: {}
Expand All @@ -162,10 +154,9 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {

// Tests that `primaryButton` success color is correct for the default theme
func testConfirmButtonDefaultSuccessColor() {
var appearance = PaymentSheet.Appearance.default.applyingLiquidGlassIfPossible()
let appearance = PaymentSheet.Appearance.default.applyingLiquidGlassIfPossible()
let confirmButton = ConfirmButton(
state: .succeeded,
style: .stripe,
status: .succeeded,
callToAction: .setup,
appearance: appearance,
didTap: {}
Expand All @@ -183,8 +174,7 @@ class ConfirmButtonSnapshotTests: STPSnapshotTestCase {
appearance.primaryButton = button

let confirmButton = ConfirmButton(
state: .succeeded,
style: .stripe,
status: .succeeded,
callToAction: .setup,
appearance: appearance,
didTap: {}
Expand Down
8 changes: 3 additions & 5 deletions Stripe/StripeiOSTests/ConfirmButtonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ConfirmButtonTests: XCTestCase {
]

for (backgroundColor, expectedForeground) in testCases {
let button = ConfirmButton.BuyButton()
let button = ConfirmButton(callToAction: .pay(amount: 900, currency: "usd"), didTap: {})
button.tintColor = backgroundColor
button.update(
status: .enabled,
Expand All @@ -59,14 +59,13 @@ class ConfirmButtonTests: XCTestCase {

func testUpdateShouldCallTheCompletionBlock() {
let sut = ConfirmButton(
style: .stripe,
callToAction: .pay(amount: 1000, currency: "usd"),
didTap: {}
)

let expectation = XCTestExpectation(description: "Should call the completion block")

sut.update(state: .disabled, animated: false) {
sut.update(status: .disabled, animated: false) {
expectation.fulfill()
}

Expand All @@ -75,14 +74,13 @@ class ConfirmButtonTests: XCTestCase {

func testUpdateShouldCallTheCompletionBlockWhenAnimated() {
let sut = ConfirmButton(
style: .stripe,
callToAction: .pay(amount: 1000, currency: "usd"),
didTap: {}
)

let expectation = XCTestExpectation(description: "Should call the completion block")

sut.update(state: .disabled, animated: true) {
sut.update(status: .disabled, animated: true) {
expectation.fulfill()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@
9E77F1E9F801AE970F1A5BE1 /* CustomerSheetConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7768E4377A7D7495A02655D /* CustomerSheetConfiguration.swift */; };
9F750611C4E8EAABE9F0B460 /* CustomerSheetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED7ABCE56539213DCE501C54 /* CustomerSheetTests.swift */; };
A0317DBB2DC2CD88003EF979 /* RowButtonFlatWithDisclosure.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0317DBA2DC2CD7D003EF979 /* RowButtonFlatWithDisclosure.swift */; };
A070C79A2E9563EF00C88F44 /* ConfirmButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A070C7992E9563EC00C88F44 /* ConfirmButton.swift */; };
A070C79C2E95737000C88F44 /* CheckProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A070C79B2E95736C00C88F44 /* CheckProgressView.swift */; };
A1AC7034E778F81B8758A653 /* OHHTTPStubsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 20076FBD56C42E259EF62F2B /* OHHTTPStubsSwift */; };
A36949C52CE7D72300739E5D /* UpdatePaymentMethodViewController+Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36949C42CE7D72300739E5D /* UpdatePaymentMethodViewController+Configuration.swift */; };
A3B2F2B22CEE689C00C0E88C /* TextFieldElement+USBankAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3B2F2B12CEE689C00C0E88C /* TextFieldElement+USBankAccount.swift */; };
Expand Down Expand Up @@ -450,7 +452,6 @@
F42DEC1850964E75ACAC29AB /* CustomerSheet+API.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCB8C12DBBD4CC909EF3A4F /* CustomerSheet+API.swift */; };
F4EA474D60D0889E7D48E1CF /* BankAccountInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3595F1786387A6B562FA472F /* BankAccountInfoView.swift */; };
F70BCDEECB5863244085F12F /* BoolReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB812081AFBCE283C1EB6130 /* BoolReference.swift */; };
F79DBDF42E5C0ED6B6DDC246 /* ConfirmButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFD640EBCE4B4224773DDF45 /* ConfirmButton.swift */; };
F7BCE78B8F782979FD5EE323 /* SepaMandateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB56BACEB0ADD42882632CB /* SepaMandateViewController.swift */; };
F8411A9B28F2E2D927ABAE7C /* CustomerAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A1D1B8BFBA136BAE1D74194 /* CustomerAdapter.swift */; };
F90B7028426261188B66C834 /* Error+PaymentSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EA56C3880C50858583CE468 /* Error+PaymentSheet.swift */; };
Expand Down Expand Up @@ -864,6 +865,8 @@
9A0D887C5AC6EFFAFE1AFD77 /* PaymentMethodType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentMethodType.swift; sourceTree = "<group>"; };
9E3905FE9F40E82EAEF49CD2 /* ro-RO */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ro-RO"; path = "ro-RO.lproj/Localizable.strings"; sourceTree = "<group>"; };
A0317DBA2DC2CD7D003EF979 /* RowButtonFlatWithDisclosure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RowButtonFlatWithDisclosure.swift; sourceTree = "<group>"; };
A070C7992E9563EC00C88F44 /* ConfirmButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmButton.swift; sourceTree = "<group>"; };
A070C79B2E95736C00C88F44 /* CheckProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckProgressView.swift; sourceTree = "<group>"; };
A09CCD0ED44336B23450A995 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
A1928BE9DFF116368B1A19DC /* LinkCookieKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkCookieKey.swift; sourceTree = "<group>"; };
A36949C42CE7D72300739E5D /* UpdatePaymentMethodViewController+Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UpdatePaymentMethodViewController+Configuration.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1003,7 +1006,6 @@
ED7ABCE56539213DCE501C54 /* CustomerSheetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerSheetTests.swift; sourceTree = "<group>"; };
EDDECF0A74497EE887DFCB46 /* AutoCompleteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoCompleteViewController.swift; sourceTree = "<group>"; };
EF60B1F629F82621D9911C07 /* AddressViewControllerSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressViewControllerSnapshotTests.swift; sourceTree = "<group>"; };
EFD640EBCE4B4224773DDF45 /* ConfirmButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmButton.swift; sourceTree = "<group>"; };
EFDE97D76542848E7821BA43 /* FormElement+Link.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FormElement+Link.swift"; sourceTree = "<group>"; };
F1E614E8481658A027599A92 /* STPAPIClient+Link.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "STPAPIClient+Link.swift"; sourceTree = "<group>"; };
F20379AE078D68A0AC83A6C5 /* PaymentSheetFormFactory+OXXO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PaymentSheetFormFactory+OXXO.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1701,6 +1703,8 @@
9F9FEA0AE875EE2B104F0599 /* Views */ = {
isa = PBXGroup;
children = (
A070C79B2E95736C00C88F44 /* CheckProgressView.swift */,
A070C7992E9563EC00C88F44 /* ConfirmButton.swift */,
62CE362B80042827F47ABC3F /* AffirmCopyLabel.swift */,
B2021DBBBC100334FFD0647F /* AfterpayPriceBreakdownView.swift */,
CD0150C1C20FD33EA024096A /* Appearance+FontScaling.swift */,
Expand All @@ -1709,7 +1713,6 @@
24AB1D50F770A8A035EF31DF /* CardScanButton.swift */,
D34B92439E9DC6E36D498312 /* CardScanningView.swift */,
A68FBE0A16FE56AAAAF4ABBF /* CircularButton.swift */,
EFD640EBCE4B4224773DDF45 /* ConfirmButton.swift */,
95BDADF560DB0B1ED175EF50 /* ManualEntryButton.swift */,
B626EE922BF2872200B05B05 /* PaymentMethodTypeImageView.swift */,
383EA30FC9C862DF2217F96D /* PaymentSheetUIKitAdditions.swift */,
Expand Down Expand Up @@ -2664,6 +2667,7 @@
49E3D7612E70B9F8006CE394 /* LinkGlobalHoldbackAA.swift in Sources */,
61A3F0162E81A07D00667D88 /* PaymentSheet+ConfirmationTokens.swift in Sources */,
6107F5462D4C389800905BD8 /* EmbeddedViewRepresentable.swift in Sources */,
A070C79A2E9563EF00C88F44 /* ConfirmButton.swift in Sources */,
820C3EDE61ADBFE4DA1E9A98 /* PaymentSheet+API.swift in Sources */,
294AE0A8838786ACABE6BCF2 /* PaymentSheet+DeferredAPI.swift in Sources */,
1B03C54F5F988C552487C564 /* PaymentSheet+PaymentMethodAvailability.swift in Sources */,
Expand Down Expand Up @@ -2692,6 +2696,7 @@
B61E2C202C5C44FE0045B5CF /* PaymentSheetAnalyticsHelper.swift in Sources */,
CB6F8F892E0455D9003551D5 /* LinkController.swift in Sources */,
C5E3750BBCA700CF364F7578 /* PaymentSheetFormFactory+OXXO.swift in Sources */,
A070C79C2E95737000C88F44 /* CheckProgressView.swift in Sources */,
49909A352D8B48D40031EC33 /* FCLiteError.swift in Sources */,
4930D8D52DB92CDC0091FBFE /* LinkPaymentMethodPicker-Email.swift in Sources */,
49679F6D2E3963460077112E /* LinkPaymentMethodPreview.swift in Sources */,
Expand Down Expand Up @@ -2764,7 +2769,6 @@
B63938722E78A67F0016C3F4 /* PaymentSheetAppearance+Helpers.swift in Sources */,
3147CEBB2CC07E960067B5E4 /* LinkUtils.swift in Sources */,
B662953E2C63F6C2007B6B14 /* PaymentDetailsShareResponse.swift in Sources */,
F79DBDF42E5C0ED6B6DDC246 /* ConfirmButton.swift in Sources */,
5C0D1B932954D0EF3F3A679F /* ManualEntryButton.swift in Sources */,
49909A202D8AFAC80031EC33 /* FCLiteSession.swift in Sources */,
A3B2F2B82CF1343F00C0E88C /* SavedPaymentMethodFormFactory+USBankAccount.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ extension PayWithLinkViewController {
#if !os(visionOS)
feedbackGenerator.prepare()
#endif
confirmButton.update(state: .processing)
confirmButton.update(status: .processing)
coordinator?.allowSheetDismissal(false)

linkAccount.createPaymentDetails(
Expand Down Expand Up @@ -270,7 +270,7 @@ extension PayWithLinkViewController {
#if !os(visionOS)
self?.feedbackGenerator.notificationOccurred(.success)
#endif
self?.confirmButton.update(state: state, animated: true) {
self?.confirmButton.update(status: state, animated: true) {
self?.coordinator?.allowSheetDismissal(true)
if state == .succeeded {
self?.coordinator?.finish(withResult: result, deferredIntentConfirmationType: deferredIntentConfirmationType)
Expand All @@ -281,15 +281,15 @@ extension PayWithLinkViewController {
#if !os(visionOS)
self.feedbackGenerator.notificationOccurred(.error)
#endif
self.confirmButton.update(state: .enabled, animated: true)
self.confirmButton.update(status: .enabled, animated: true)
self.updateErrorLabel(for: error)
self.coordinator?.allowSheetDismissal(true)
}
}
}

func didSelectAddBankAccount() {
confirmButton.update(state: .processing)
confirmButton.update(status: .processing)

coordinator?.startInstantDebits { [weak self] result in
guard let self = self else { return }
Expand All @@ -300,10 +300,10 @@ extension PayWithLinkViewController {
case .failure(let error):
switch error {
case InstantDebitsOnlyAuthenticationSessionManager.Error.canceled:
self.confirmButton.update(state: .enabled)
self.confirmButton.update(status: .enabled)
default:
self.updateErrorLabel(for: error)
self.confirmButton.update(state: .enabled)
self.confirmButton.update(status: .enabled)
}
}
}
Expand Down Expand Up @@ -335,10 +335,10 @@ extension PayWithLinkViewController.NewPaymentViewController: AddPaymentMethodVi

func didUpdate(_ viewController: AddPaymentMethodViewController) {
if viewController.selectedPaymentMethodType == .instantDebits {
confirmButton.update(state: .enabled, style: .stripe, callToAction: .add(paymentMethodType: .instantDebits))
confirmButton.update(status: .enabled, callToAction: .add(paymentMethodType: .instantDebits))
} else {
confirmButton.update(
state: viewController.paymentOption != nil ? .enabled : .disabled,
status: viewController.paymentOption != nil ? .enabled : .disabled,
callToAction: context.callToAction
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extension PayWithLinkViewController {
thisIsYourDefaultView.isHidden = true
}

updateButton.update(state: paymentMethodEditElement.validationState.isValid ? .enabled : .disabled)
updateButton.update(status: paymentMethodEditElement.validationState.isValid ? .enabled : .disabled)

}

Expand All @@ -148,7 +148,7 @@ extension PayWithLinkViewController {

paymentMethodEditElement.view.endEditing(true)
paymentMethodEditElement.view.isUserInteractionEnabled = false
updateButton.update(state: .processing)
updateButton.update(status: .processing)

// When updating a payment method that is not the default and you send isDefault=false to the server you get
// "Can't unset payment details when it's not the default", so send nil instead of false
Expand Down Expand Up @@ -178,7 +178,7 @@ extension PayWithLinkViewController {
confirmationExtras = .init(billingPhoneNumber: self.isBillingDetailsUpdateFlow ? params.billingDetails.phone : nil)
}

self.updateButton.update(state: .succeeded, style: nil, callToAction: nil, animated: true) {
self.updateButton.update(status: .succeeded, callToAction: nil, animated: true) {
self.coordinator?.allowSheetDismissal(true)
self.delegate?.didUpdate(
paymentMethod: updatedPaymentDetails,
Expand All @@ -189,7 +189,7 @@ extension PayWithLinkViewController {
case .failure(let error):
self.updateErrorLabel(for: error)
self.paymentMethodEditElement.view.isUserInteractionEnabled = true
self.updateButton.update(state: .enabled)
self.updateButton.update(status: .enabled)
coordinator?.allowSheetDismissal(true)
}
}
Expand Down Expand Up @@ -222,11 +222,11 @@ extension PayWithLinkViewController.UpdatePaymentViewController: ElementDelegate

func didUpdate(element: Element) {
updateErrorLabel(for: nil)
updateButton.update(state: paymentMethodEditElement.validationState.isValid ? .enabled : .disabled)
updateButton.update(status: paymentMethodEditElement.validationState.isValid ? .enabled : .disabled)
}

func continueToNextField(element: Element) {
updateButton.update(state: paymentMethodEditElement.validationState.isValid ? .enabled : .disabled)
updateButton.update(status: paymentMethodEditElement.validationState.isValid ? .enabled : .disabled)
}

}
Loading
Loading