From 422a03af9474f6ceb98c9f51b9f61a1b089469df Mon Sep 17 00:00:00 2001 From: vladimir Date: Wed, 20 Nov 2024 15:28:37 +0100 Subject: [PATCH] fix: correct type for meal_voucher --- .../Abstract/PaymentMethodType.swift | 3 ++ .../MealVoucherDetails.swift | 8 +++- .../Gift Card/GiftCardComponentTests.swift | 41 ++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift b/Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift index ff67a87f4c..9cbe11392b 100644 --- a/Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift +++ b/Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift @@ -49,6 +49,7 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable { case mealVoucherNatixis case mealVoucherGroupeUp case mealVoucherSodexo + case mealVoucher case upi case cashAppPay case twint @@ -184,6 +185,7 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable { case .mealVoucherGroupeUp: return "mealVoucher_FR_groupeup" case .mealVoucherNatixis: return "mealVoucher_FR_natixis" case .mealVoucherSodexo: return "mealVoucher_FR_sodexo" + case .mealVoucher: return "mealVoucher_FR" case .upi: return "upi" case .upiQr: return "upi_qr" case .upiIntent: return "upi_intent" @@ -253,6 +255,7 @@ extension PaymentMethodType { case .mealVoucherGroupeUp: return "meal voucher groupe-up" case .mealVoucherNatixis: return "meal voucher natixis" case .mealVoucherSodexo: return "meal voucher sodexo" + case .mealVoucher: return "meal voucher" case .upi: return "UPI" case .upiQr: return "UPI QR" case .upiIntent: return "UPI Intent" diff --git a/AdyenCard/Components/GiftCardComponent/MealVoucherDetails.swift b/AdyenCard/Components/GiftCardComponent/MealVoucherDetails.swift index 1d70834488..2216b9cb25 100644 --- a/AdyenCard/Components/GiftCardComponent/MealVoucherDetails.swift +++ b/AdyenCard/Components/GiftCardComponent/MealVoucherDetails.swift @@ -16,6 +16,9 @@ public struct MealVoucherDetails: PartialPaymentMethodDetails { @_spi(AdyenInternal) public var checkoutAttemptId: String? + /// The brand of a payment method . + public let brand: PaymentMethodType + /// The payment method type. public let type: PaymentMethodType @@ -39,8 +42,9 @@ public struct MealVoucherDetails: PartialPaymentMethodDetails { public init(paymentMethod: MealVoucherPaymentMethod, encryptedCard: EncryptedCard) throws { guard let number = encryptedCard.number, let securityCode = encryptedCard.securityCode else { throw GiftCardComponent.Error.cardEncryptionFailed } - - self.type = paymentMethod.type + + self.type = .mealVoucher + self.brand = paymentMethod.type self.encryptedCardNumber = number self.encryptedSecurityCode = securityCode self.encryptedExpiryYear = encryptedCard.expiryYear diff --git a/Tests/IntegrationTests/Components Tests/Gift Card/GiftCardComponentTests.swift b/Tests/IntegrationTests/Components Tests/Gift Card/GiftCardComponentTests.swift index 6725436884..7c5630f32c 100644 --- a/Tests/IntegrationTests/Components Tests/Gift Card/GiftCardComponentTests.swift +++ b/Tests/IntegrationTests/Components Tests/Gift Card/GiftCardComponentTests.swift @@ -41,8 +41,8 @@ class GiftCardComponentTests: XCTestCase { var securityCodeItemView: FormTextInputItemView? { sut.viewController.view.findView(with: "AdyenCard.GiftCardComponent.securityCodeItem") } - - var expiryDateItemView: FormItemView? { + + var expiryDateItemView: FormTextItemView? { sut.viewController.view.findView(with: "AdyenCard.GiftCardComponent.expiryDateItem") } @@ -123,6 +123,43 @@ class GiftCardComponentTests: XCTestCase { XCTAssertEqual(securityCodeItemTitleLabel?.text, "Security code", "cvc title changes based on payment method") } + func testMealVoucherDetails() { + + // Given + let paymentMethod = MealVoucherPaymentMethod(type: .mealVoucherSodexo, name: "Sodexo") + sut = GiftCardComponent( + partialPaymentMethodType: .mealVoucher(paymentMethod), + context: context, + amount: amountToPay, + publicKeyProvider: publicKeyProvider + ) + + // When + setupRootViewController(sut.viewController) + wait(for: .milliseconds(300)) + populate(textItemView: numberItemView!, with: "1234 1234 1234 1234") + populate(textItemView: securityCodeItemView!, with: "123") + populate(textItemView: expiryDateItemView!, with: "1233") + partialPaymentDelegate = PartialPaymentDelegateMock() + sut.partialPaymentDelegate = partialPaymentDelegate + let expectation = expectation(description: "Expect delegateMock.onDidSubmit to be called.") + + // Then + partialPaymentDelegate.onCheckBalance = { data, component in + XCTAssertTrue(data.paymentMethod is MealVoucherDetails) + let paymentMethod = data.paymentMethod as! MealVoucherDetails + XCTAssertEqual(paymentMethod.type, .mealVoucher) + XCTAssertEqual(paymentMethod.brand, .mealVoucherSodexo) + XCTAssertGreaterThan(paymentMethod.encryptedCardNumber.count, 0) + XCTAssertGreaterThan(paymentMethod.encryptedExpiryYear!.count, 0) + XCTAssertGreaterThan(paymentMethod.encryptedExpiryMonth!.count, 0) + XCTAssertGreaterThan(paymentMethod.encryptedSecurityCode.count, 0) + expectation.fulfill() + } + sut.didSelectSubmitButton() + waitForExpectations(timeout: 10, handler: nil) + } + func testCheckBalanceFailure() throws { let publicKeyProviderExpectation = expectation(description: "Expect publicKeyProvider to be called.")