Skip to content

Commit

Permalink
fix: correct type for meal_voucher
Browse files Browse the repository at this point in the history
  • Loading branch information
descorp committed Nov 21, 2024
1 parent 74d3d0c commit 422a03a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
case mealVoucherNatixis
case mealVoucherGroupeUp
case mealVoucherSodexo
case mealVoucher
case upi
case cashAppPay
case twint
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class GiftCardComponentTests: XCTestCase {
var securityCodeItemView: FormTextInputItemView? {
sut.viewController.view.findView(with: "AdyenCard.GiftCardComponent.securityCodeItem")
}

var expiryDateItemView: FormItemView<FormCardExpiryDateItem>? {
var expiryDateItemView: FormTextItemView<FormCardExpiryDateItem>? {
sut.viewController.view.findView(with: "AdyenCard.GiftCardComponent.expiryDateItem")
}

Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit 422a03a

Please sign in to comment.