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

Cashapp recurring fix #1786

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
40 changes: 20 additions & 20 deletions AdyenCashAppPay/CashAppPayComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Demo/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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