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

COIOS-806: Support all Boleto Bancario tx-variants #1903

Merged
merged 14 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
10 changes: 8 additions & 2 deletions Adyen/Core/Payment Methods/Abstract/AnyPaymentMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ internal enum AnyPaymentMethod: Codable {
case econtextStores(EContextPaymentMethod)
case econtextATM(EContextPaymentMethod)
case econtextOnline(EContextPaymentMethod)
case boleto(BoletoPaymentMethod)
case boletoBancario(BoletoPaymentMethod)
case boletoBancarioSantander(BoletoPaymentMethod)
case boletoBancarioItau(BoletoPaymentMethod)
case primeiroPayBoleto(BoletoPaymentMethod)
case affirm(AffirmPaymentMethod)
case atome(AtomePaymentMethod)
case onlineBanking(OnlineBankingPaymentMethod)
Expand Down Expand Up @@ -72,7 +75,10 @@ internal enum AnyPaymentMethod: Codable {
case let .econtextStores(paymentMethod): return paymentMethod
case let .econtextATM(paymentMethod): return paymentMethod
case let .econtextOnline(paymentMethod): return paymentMethod
case let .boleto(paymentMethod): return paymentMethod
case let .boletoBancario(paymentMethod): return paymentMethod
case let .boletoBancarioSantander(paymentMethod): return paymentMethod
case let .boletoBancarioItau(paymentMethod): return paymentMethod
case let .primeiroPayBoleto(paymentMethod): return paymentMethod
case let .affirm(paymentMethod): return paymentMethod
case let .atome(paymentMethod): return paymentMethod
case let .onlineBanking(paymentMethod): return paymentMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ internal enum AnyPaymentMethodDecoder {
.econtextStores: EContextStoresPaymentMethodDecoder(),
.econtextATM: EContextATMPaymentMethodDecoder(),
.econtextOnline: EContextOnlinePaymentMethodDecoder(),
.boleto: BoletoPaymentMethodDecoder(),
.boletoBancario: BoletoPaymentMethodDecoder(),
.boletoBancarioSantander: BoletoPaymentMethodDecoder(),
.boletoBancarioItau: BoletoPaymentMethodDecoder(),
.primeiroPayBoleto: BoletoPaymentMethodDecoder(),
.affirm: AffirmPaymentMethodDecoder(),
.atome: AtomePaymentMethodDecoder(),
.onlineBankingCZ: OnlineBankingPaymentMethodDecoder(),
Expand Down Expand Up @@ -413,11 +416,11 @@ private struct EContextOnlinePaymentMethodDecoder: PaymentMethodDecoder {

private struct BoletoPaymentMethodDecoder: PaymentMethodDecoder {
func decode(from decoder: Decoder, isStored: Bool) throws -> AnyPaymentMethod {
try .boleto(BoletoPaymentMethod(from: decoder))
try .boletoBancarioSantander(BoletoPaymentMethod(from: decoder))
}

func anyPaymentMethod(from paymentMethod: any PaymentMethod) -> AnyPaymentMethod? {
(paymentMethod as? BoletoPaymentMethod).map { .boleto($0) }
(paymentMethod as? BoletoPaymentMethod).map { .boletoBancarioSantander($0) }
}
}

Expand Down
20 changes: 16 additions & 4 deletions Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
case econtextStores
case econtextATM
case econtextOnline
case boleto
case boletoBancario
nauaros marked this conversation as resolved.
Show resolved Hide resolved
case boletoBancarioSantander
case boletoBancarioItau
case primeiroPayBoleto
case affirm
case oxxo
case bacsDirectDebit
Expand Down Expand Up @@ -110,7 +113,10 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
case "econtext_stores": self = .econtextStores
case "econtext_atm": self = .econtextATM
case "econtext_online": self = .econtextOnline
case "boletobancario_santander": self = .boleto
case "boletobancario": self = .boletoBancario
case "boletobancario_itau": self = .boletoBancarioItau
case "boletobancario_santander": self = .boletoBancarioSantander
case "primeiropay_boleto": self = .primeiroPayBoleto
case "affirm": self = .affirm
case "oxxo": self = .oxxo
case "directdebit_GB": self = .bacsDirectDebit
Expand Down Expand Up @@ -172,7 +178,10 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
case .econtextStores: return "econtext_stores"
case .econtextATM: return "econtext_atm"
case .econtextOnline: return "econtext_online"
case .boleto: return "boletobancario_santander"
case .boletoBancario: return "boletobancario"
case .boletoBancarioSantander: return "boletobancario_santander"
case .boletoBancarioItau: return "boletobancario_itau"
case .primeiroPayBoleto: return "primeiropay_boleto"
case .affirm: return "affirm"
case .oxxo: return "oxxo"
case .bacsDirectDebit: return "directdebit_GB"
Expand Down Expand Up @@ -241,7 +250,10 @@ extension PaymentMethodType {
case .econtextStores: return "econtext stores"
case .econtextATM: return "econtext ATM"
case .econtextOnline: return "econtext online"
case .boleto: return "boleto"
case .boletoBancario: return "boleto bancario"
case .boletoBancarioSantander: return "boleto bancario santander"
case .boletoBancarioItau: return "boleto bancario itau"
case .primeiroPayBoleto: return "primeiro pay boleto"
case .affirm: return "affirm"
case .oxxo: return "OXXO"
case .bacsDirectDebit: return "BACS direct debit"
Expand Down
34 changes: 32 additions & 2 deletions AdyenActions/Actions/VoucherAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ public enum VoucherPaymentMethod: String, Codable, CaseIterable {

/// Boleto Bancairo Santander
case boletoBancairoSantander = "boletobancario_santander"


/// Boleto Bancario
case boletoBancario = "boletobancario"

/// Boleto Bancario Itau
case boletoBancarioItau = "boletobancario_itau"

/// Primeiro Pay Boleto
case primeiroPayBoleto = "primeiropay_boleto"

/// OXXO
case oxxo

Expand All @@ -49,7 +58,16 @@ public enum VoucherAction: Decodable {

/// Indicates a Boleto Bancairo Santander Voucher type.
case boletoBancairoSantander(BoletoVoucherAction)


/// Indicates a Boleto Bancario Voucher type.
case boletoBancario(BoletoVoucherAction)

/// Indicates a Boleto Bancario Itau Voucher type.
case boletoBancarioItau(BoletoVoucherAction)

/// Indicates a Primeiro Pay Boleto Voucher type.
case primeiroPayBoleto(BoletoVoucherAction)

/// Indicates an OXXO voucher type
case oxxo(OXXOVoucherAction)

Expand All @@ -71,6 +89,12 @@ public enum VoucherAction: Decodable {
self = try .econtextATM(EContextATMVoucherAction(from: decoder))
case .boletoBancairoSantander:
self = try .boletoBancairoSantander(BoletoVoucherAction(from: decoder))
case .boletoBancario:
self = try .boletoBancario(BoletoVoucherAction(from: decoder))
case .boletoBancarioItau:
self = try .boletoBancarioItau(BoletoVoucherAction(from: decoder))
case .primeiroPayBoleto:
self = try .primeiroPayBoleto(BoletoVoucherAction(from: decoder))
case .oxxo:
self = try .oxxo(OXXOVoucherAction(from: decoder))
case .multibanco:
Expand All @@ -87,6 +111,12 @@ public enum VoucherAction: Decodable {
switch self {
case let .boletoBancairoSantander(action):
return action
case let .boletoBancario(action):
return action
case let .boletoBancarioItau(action):
return action
case let .primeiroPayBoleto(action):
return action
case let .dokuAlfamart(action):
return action
case let .dokuIndomaret(action):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ internal final class VoucherShareableViewProvider: AnyVoucherShareableViewProvid
view = createGenericView(with: action, fields: createOXXOVoucherFields(for: action))
case let .boletoBancairoSantander(action):
view = createBoletoView(with: action)
case let .boletoBancario(action):
view = createBoletoView(with: action)
case let .boletoBancarioItau(action):
view = createBoletoView(with: action)
case let .primeiroPayBoleto(action):
view = createBoletoView(with: action)
case let .multibanco(action):
view = createGenericView(with: action, fields: createMultibancoVoucherFields(for: action))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import XCTest

class BoletoComponentTests: XCTestCase {

private var method = BoletoPaymentMethod(type: .boleto, name: "Boleto Bancario")

private var method = BoletoPaymentMethod(type: .boletoBancarioSantander, name: "Boleto Bancario")
func testFullPrefilledInfo() throws {
// Given

Expand Down
17 changes: 10 additions & 7 deletions Tests/IntegrationTests/DropIn Tests/ComponentManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class ComponentManagerTests: XCTestCase {
econtextOnline,
oxxo,
multibanco,
boleto,
boletoBancario,
boletoBancarioSantander,
primeiroPayBoleto,
boletoBancarioItau,
affirm,
atome,
achDirectDebit,
Expand All @@ -69,7 +72,7 @@ class ComponentManagerTests: XCTestCase {
]
]

let numberOfExpectedRegularComponents = 24
let numberOfExpectedRegularComponents = 27

var presentationDelegate: PresentationDelegateMock!
var context: AdyenContext!
Expand Down Expand Up @@ -105,8 +108,8 @@ class ComponentManagerTests: XCTestCase {
XCTAssertEqual(sut.storedComponents.filter { $0.context.apiContext.clientKey == Dummy.apiContext.clientKey }.count, 6)
XCTAssertEqual(sut.regularComponents.filter { $0.context.apiContext.clientKey == Dummy.apiContext.clientKey }.count, numberOfExpectedRegularComponents)

XCTAssertEqual(sut.regularComponents.filter { $0 is LoadingComponent }.count, 19)
XCTAssertEqual(sut.regularComponents.filter { $0 is PresentableComponent }.count, 19)
XCTAssertEqual(sut.regularComponents.filter { $0 is LoadingComponent }.count, 22)
XCTAssertEqual(sut.regularComponents.filter { $0 is PresentableComponent }.count, 22)
XCTAssertEqual(sut.regularComponents.filter { $0 is FinalizableComponent }.count, 0)
}

Expand All @@ -123,8 +126,8 @@ class ComponentManagerTests: XCTestCase {
XCTAssertEqual(sut.storedComponents.count, 6)
XCTAssertEqual(sut.regularComponents.count, numberOfExpectedRegularComponents + 1)

XCTAssertEqual(sut.regularComponents.filter { $0 is LoadingComponent }.count, 19)
XCTAssertEqual(sut.regularComponents.filter { $0 is PresentableComponent }.count, 20)
XCTAssertEqual(sut.regularComponents.filter { $0 is LoadingComponent }.count, 22)
XCTAssertEqual(sut.regularComponents.filter { $0 is PresentableComponent }.count, 23)
XCTAssertEqual(sut.regularComponents.filter { $0 is FinalizableComponent }.count, 1)
}

Expand Down Expand Up @@ -452,7 +455,7 @@ class ComponentManagerTests: XCTestCase {
)

// When
let paymentComponent = try XCTUnwrap(sut.regularComponents.first { $0.paymentMethod.type == .boleto })
let paymentComponent = try XCTUnwrap(sut.regularComponents.first { $0.paymentMethod.type == .boletoBancarioSantander })

// Then
let boletoComponent = try XCTUnwrap(paymentComponent as? BoletoComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class BoletoComponentUITests: XCTestCase {
}

private var paymentMethod: BoletoPaymentMethod {
.init(type: .boleto, name: "Boleto Bancario")
.init(type: .boletoBancarioSantander, name: "Boleto Bancario")
}

func testUIConfiguration() {
Expand Down
90 changes: 66 additions & 24 deletions Tests/UnitTests/Core/PaymentMethodTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class PaymentMethodTests: XCTestCase {
givexGiftCard,
mealVoucherSodexo,
bizum,
boleto,
boletoBancario,
boletoBancarioSantander,
primeiroPayBoleto,
boletoBancarioItau,
affirm,
atome,
upi,
Expand Down Expand Up @@ -175,8 +178,8 @@ class PaymentMethodTests: XCTestCase {

// Regular payment methods

XCTAssertEqual(paymentMethods.regular.count, 32)
XCTAssertEqual(paymentMethods.regular.count, 35)

let creditCardPaymentMethod = try XCTUnwrap(paymentMethods.regular[0] as? CardPaymentMethod)
XCTAssertEqual(creditCardPaymentMethod.fundingSource, .credit)

Expand Down Expand Up @@ -295,29 +298,41 @@ class PaymentMethodTests: XCTestCase {

XCTAssertTrue(paymentMethods.regular[26] is BoletoPaymentMethod)
XCTAssertEqual(paymentMethods.regular[26].name, "Boleto Bancario")
XCTAssertEqual(paymentMethods.regular[26].type.rawValue, "boletobancario_santander")

XCTAssertTrue(paymentMethods.regular[27] is AffirmPaymentMethod)
XCTAssertEqual(paymentMethods.regular[27].name, "Affirm")
XCTAssertEqual(paymentMethods.regular[27].type.rawValue, "affirm")

XCTAssertTrue(paymentMethods.regular[28] is AtomePaymentMethod)
XCTAssertEqual(paymentMethods.regular[28].name, "Atome")
XCTAssertEqual(paymentMethods.regular[28].type.rawValue, "atome")

XCTAssertTrue(paymentMethods.regular[29] is UPIPaymentMethod)
XCTAssertEqual(paymentMethods.regular[29].name, "UPI")
XCTAssertEqual(paymentMethods.regular[29].type.rawValue, "upi")

let cashAppPay = try XCTUnwrap(paymentMethods.regular[30] as? CashAppPayPaymentMethod)
XCTAssertEqual(paymentMethods.regular[26].type.rawValue, "boletobancario")

XCTAssertTrue(paymentMethods.regular[27] is BoletoPaymentMethod)
XCTAssertEqual(paymentMethods.regular[27].name, "Boleto Bancario")
XCTAssertEqual(paymentMethods.regular[27].type.rawValue, "boletobancario_santander")

XCTAssertTrue(paymentMethods.regular[28] is BoletoPaymentMethod)
XCTAssertEqual(paymentMethods.regular[28].name, "Boleto Bancario")
XCTAssertEqual(paymentMethods.regular[28].type.rawValue, "primeiropay_boleto")

XCTAssertTrue(paymentMethods.regular[29] is BoletoPaymentMethod)
XCTAssertEqual(paymentMethods.regular[29].name, "Boleto Bancario")
XCTAssertEqual(paymentMethods.regular[29].type.rawValue, "boletobancario_itau")

XCTAssertTrue(paymentMethods.regular[30] is AffirmPaymentMethod)
XCTAssertEqual(paymentMethods.regular[30].name, "Affirm")
XCTAssertEqual(paymentMethods.regular[30].type.rawValue, "affirm")

XCTAssertTrue(paymentMethods.regular[31] is AtomePaymentMethod)
XCTAssertEqual(paymentMethods.regular[31].name, "Atome")
XCTAssertEqual(paymentMethods.regular[31].type.rawValue, "atome")

XCTAssertTrue(paymentMethods.regular[32] is UPIPaymentMethod)
XCTAssertEqual(paymentMethods.regular[32].name, "UPI")
XCTAssertEqual(paymentMethods.regular[32].type.rawValue, "upi")

let cashAppPay = try XCTUnwrap(paymentMethods.regular[33] as? CashAppPayPaymentMethod)
XCTAssertEqual(cashAppPay.name, "Cash App Pay")
XCTAssertEqual(cashAppPay.type.rawValue, "cashapp")
XCTAssertEqual(cashAppPay.clientId, "testClient")
XCTAssertEqual(cashAppPay.scopeId, "testScope")

XCTAssertTrue(paymentMethods.regular[31] is InstantPaymentMethod)
XCTAssertEqual(paymentMethods.regular[31].type.rawValue, "ideal")
XCTAssertEqual(paymentMethods.regular[31].name, "iDeal")
XCTAssertTrue(paymentMethods.regular[34] is InstantPaymentMethod)
XCTAssertEqual(paymentMethods.regular[34].type.rawValue, "ideal")
XCTAssertEqual(paymentMethods.regular[34].name, "iDeal")
}

// MARK: - Display Information Override
Expand Down Expand Up @@ -1058,16 +1073,43 @@ class PaymentMethodTests: XCTestCase {
}

// MARK: - Boleto

func testDecodingBoletoPaymentMethod() throws {
let paymentMethod = try AdyenCoder.decode(boleto) as BoletoPaymentMethod

func testDecodingBoletoBancarioPaymentMethod() throws {
let paymentMethod = try AdyenCoder.decode(boletoBancario) as BoletoPaymentMethod
XCTAssertEqual(paymentMethod.type.rawValue, "boletobancario")
XCTAssertEqual(paymentMethod.name, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).title, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).logoName, "boletobancario")
testCoding(paymentMethod)
}

func testDecodingBoletoBancarioSantanderPaymentMethod() throws {
let paymentMethod = try AdyenCoder.decode(boletoBancarioSantander) as BoletoPaymentMethod
XCTAssertEqual(paymentMethod.type.rawValue, "boletobancario_santander")
XCTAssertEqual(paymentMethod.name, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).title, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).logoName, "boletobancario_santander")
testCoding(paymentMethod)
}

func testDecodingBoletoBancarioItauPaymentMethod() throws {
let paymentMethod = try AdyenCoder.decode(boletoBancarioItau) as BoletoPaymentMethod
XCTAssertEqual(paymentMethod.type.rawValue, "boletobancario_itau")
XCTAssertEqual(paymentMethod.name, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).title, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).logoName, "boletobancario_itau")
testCoding(paymentMethod)
}

func testDecodingPrimeiroPayBoletoPaymentMethod() throws {
let paymentMethod = try AdyenCoder.decode(primeiroPayBoleto) as BoletoPaymentMethod
XCTAssertEqual(paymentMethod.type.rawValue, "primeiropay_boleto")
XCTAssertEqual(paymentMethod.name, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).title, "Boleto Bancario")
XCTAssertEqual(paymentMethod.displayInformation(using: nil).logoName, "primeiropay_boleto")
testCoding(paymentMethod)
}

// MARK: - BACS Direct Debit

func testDecodingBACSDirectDebitPaymentMethod() throws {
Expand Down
Loading
Loading