diff --git a/AdyenCashAppPay/CashAppPayComponent.swift b/AdyenCashAppPay/CashAppPayComponent.swift index 246e1e5b3c..c4bfdd59a0 100644 --- a/AdyenCashAppPay/CashAppPayComponent.swift +++ b/AdyenCashAppPay/CashAppPayComponent.swift @@ -51,8 +51,8 @@ public final class CashAppPayComponent: PaymentComponent, private let cashAppPayPaymentMethod: CashAppPayPaymentMethod - private var storePayment: Bool? { - configuration.showsStorePaymentMethodField ? storeDetailsItem.value : nil + private var storePayment: Bool { + configuration.showsStorePaymentMethodField ? storeDetailsItem.value : configuration.storePaymentMethod } private lazy var cashAppPay: CashAppPay = { @@ -146,25 +146,7 @@ public final class CashAppPayComponent: PaymentComponent, referenceID: configuration.referenceId, metadata: nil)) } - - private func createPaymentActions() -> [PaymentAction] { - var actions = [PaymentAction]() - if let amount = payment?.amount, amount.value > 0 { - let moneyAmount = Money(amount: UInt(amount.value), currency: .USD) - let oneTimeAction = PaymentAction.oneTimePayment(scopeID: cashAppPayPaymentMethod.scopeId, - money: moneyAmount) - actions.append(oneTimeAction) - } - if storePayment == true { - let onFileAction = PaymentAction.onFilePayment(scopeID: cashAppPayPaymentMethod.scopeId, - accountReferenceID: nil) - actions.append(onFileAction) - } - - return actions - } - private func cashAppPayDetails(from grants: [CustomerRequest.Grant], customerProfile: CustomerRequest.CustomerProfile?) throws -> CashAppPayDetails { guard grants.isEmpty == false else { @@ -181,7 +163,25 @@ public final class CashAppPayComponent: PaymentComponent, customerId: customerId, cashtag: cashtag) } + + internal func createPaymentActions() -> [PaymentAction] { + var actions = [PaymentAction]() + if let amount = payment?.amount, amount.value > 0 { + let moneyAmount = Money(amount: UInt(amount.value), currency: .USD) + let oneTimeAction = PaymentAction.oneTimePayment(scopeID: cashAppPayPaymentMethod.scopeId, + money: moneyAmount) + actions.append(oneTimeAction) + } + if storePayment { + let onFileAction = PaymentAction.onFilePayment(scopeID: cashAppPayPaymentMethod.scopeId, + accountReferenceID: nil) + actions.append(onFileAction) + } + + return actions + } + internal func submitApprovedRequest(with grants: [CustomerRequest.Grant], profile: CustomerRequest.CustomerProfile?) { do { let details = try cashAppPayDetails(from: grants, customerProfile: profile) diff --git a/AdyenDropIn/Utilities/ComponentManager+PaymentComponentBuilder.swift b/AdyenDropIn/Utilities/ComponentManager+PaymentComponentBuilder.swift index 5aae6b6468..2c63abd829 100644 --- a/AdyenDropIn/Utilities/ComponentManager+PaymentComponentBuilder.swift +++ b/AdyenDropIn/Utilities/ComponentManager+PaymentComponentBuilder.swift @@ -200,6 +200,7 @@ extension ComponentManager: PaymentComponentBuilder { var cashAppPayConfiguration = CashAppPayConfiguration(redirectURL: cashAppPayDropInConfig.redirectURL, referenceId: cashAppPayDropInConfig.referenceId) cashAppPayConfiguration.showsStorePaymentMethodField = cashAppPayDropInConfig.showsStorePaymentMethodField + cashAppPayConfiguration.storePaymentMethod = cashAppPayDropInConfig.storePaymentMethod cashAppPayConfiguration.localizationParameters = configuration.localizationParameters cashAppPayConfiguration.style = configuration.style.formComponent diff --git a/Demo/Configuration.swift b/Demo/Configuration.swift index 3d08af8dff..28eba1423e 100644 --- a/Demo/Configuration.swift +++ b/Demo/Configuration.swift @@ -255,7 +255,7 @@ internal struct DemoAppSettings: Codable { dropInConfig.paymentMethodsList.allowDisablingStoredPaymentMethods = dropInSettings.allowDisablingStoredPaymentMethods if dropInSettings.cashAppPayEnabled { - dropInConfig.cashAppPay = .init(redirectURL: ConfigurationConstants.returnUrl) + dropInConfig.cashAppPay = .init(redirectURL: ConfigurationConstants.returnUrl, showsStorePaymentMethodField: false, storePaymentMethod: true) } dropInConfig.actionComponent.twint = .init(callbackAppScheme: ConfigurationConstants.returnUrl.scheme!) diff --git a/Tests/IntegrationTests/Components Tests/Cash App Pay/CashAppPayComponentTests.swift b/Tests/IntegrationTests/Components Tests/Cash App Pay/CashAppPayComponentTests.swift index 03156ecbc5..8f89a2f1c7 100644 --- a/Tests/IntegrationTests/Components Tests/Cash App Pay/CashAppPayComponentTests.swift +++ b/Tests/IntegrationTests/Components Tests/Cash App Pay/CashAppPayComponentTests.swift @@ -241,5 +241,49 @@ import XCTest waitForExpectations(timeout: 10, handler: nil) } + + func test_StorePayment_NotIncluded_FromConfiguration() { + let config = CashAppPayConfiguration( + redirectURL: URL(string: "test")!, + showsStorePaymentMethodField: false + ) + let sut = CashAppPayComponent(paymentMethod: paymentMethod, context: context, configuration: config) + + // no recurring, only regular + let actions = sut.createPaymentActions() + XCTAssertEqual(actions.count, 1) + let oneTimeAction = actions[0] + XCTAssertEqual(oneTimeAction.type, .ONE_TIME_PAYMENT) + } + + func test_StorePayment_Included_FromConfiguration() { + let config = CashAppPayConfiguration( + redirectURL: URL(string: "test")!, + showsStorePaymentMethodField: false, + storePaymentMethod: true + ) + let sut = CashAppPayComponent(paymentMethod: paymentMethod, context: context, configuration: config) + + // stored and regular + let actions = sut.createPaymentActions() + XCTAssertEqual(actions.count, 2) + let onFileAction = actions[1] + XCTAssertEqual(onFileAction.type, .ON_FILE_PAYMENT) + } + + func test_StorePayment_FlagIgnored_DueToConfiguration() { + let config = CashAppPayConfiguration( + redirectURL: URL(string: "test")!, + showsStorePaymentMethodField: true, + storePaymentMethod: true + ) + let sut = CashAppPayComponent(paymentMethod: paymentMethod, context: context, configuration: config) + + // no recurring, only regular + let actions = sut.createPaymentActions() + XCTAssertEqual(actions.count, 1) + let oneTimeAction = actions[0] + XCTAssertEqual(oneTimeAction.type, .ONE_TIME_PAYMENT) + } } #endif