Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Fix installment charges #111

Merged
merged 3 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions OmiseSwift/API Models/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public enum Card: OmiseIdentifiableObject, OmiseLiveModeObject {
}
}

public var fingerPrint: String {
public var fingerPrint: String? {
switch self {
case .tokenized(let card):
return card.fingerPrint
Expand Down Expand Up @@ -219,7 +219,7 @@ public struct TokenizedCard: OmiseIdentifiableObject, OmiseLiveModeObject, Omise
public let expiration: (month: Int, year: Int)?

public let name: String?
public let fingerPrint: String
public let fingerPrint: String?

public let financing: CardFinancing?

Expand Down Expand Up @@ -279,11 +279,11 @@ extension TokenizedCard {
firstDigits = try container.decodeIfPresent(Digits.self, forKey: .firstDigits)
lastDigits = try container.decode(Digits.self, forKey: .lastDigits)
brand = try container.decode(CardBrand.self, forKey: .brand)
name = try container.decode(String.self, forKey: .name)
name = try container.decodeIfPresent(String.self, forKey: .name)
bankName = try container.decodeIfPresent(String.self, forKey: .bankName)
billingAddress = try BillingAddress(from: decoder)
financing = try container.decodeIfPresent(CardFinancing.self, forKey: .financing)
fingerPrint = try container.decode(String.self, forKey: .fingerPrint)
fingerPrint = try container.decodeIfPresent(String.self, forKey: .fingerPrint)
passSecurityCodeCheck = try container.decode(Bool.self, forKey: .passSecurityCodeCheck)
let expirationMonth = try container.decodeIfPresent(Int.self, forKey: .expirationMonth)
let expirationYear = try container.decodeIfPresent(Int.self, forKey: .expirationYear)
Expand Down
6 changes: 3 additions & 3 deletions OmiseSwift/API Models/Charge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ extension Charge {
card = try container.decodeIfPresent(Card.self, forKey: .card)

switch (card, source) {
case (_, let source?):
payment = .source(source)
case (let card?, nil):
payment = .card(card)
case (nil, let source?):
payment = .source(source)
case (nil, nil), (.some, .some):
case (nil, nil):
payment = .unknown
}
}
Expand Down
10 changes: 10 additions & 0 deletions OmiseSwiftTests/ChargesOperationFixtureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,16 @@ class ChargesOperationFixtureTests: FixtureTestCase {
XCTAssertEqual(charge.source?.flow, .redirect)
XCTAssertEqual(charge.source?.paymentInformation,
EnrolledSource.EnrolledPaymentInformation.installment(.bay))

XCTAssertEqual(charge.card?.brand, .visa)
XCTAssertEqual(charge.card?.lastDigits, Digits(digitsString: "1234"))

switch charge.paymentInformation {
case .source(let source):
XCTAssertEqual(source, .installment(.bay))
default:
XCTFail("Unexpected payment info: \(charge.paymentInformation)")
}
case let .failure(error):
XCTFail("\(error)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,31 @@
"return_uri": "https://omise.co",
"failure_code": null,
"failure_message": null,
"card": null,
"card": {
"object": "card",
"id": "card_test_98dsf987dsf7987dsf",
"livemode": false,
"location": null,
"deleted": false,
"street1": null,
"street2": null,
"city": null,
"state": null,
"phone_number": null,
"postal_code": null,
"country": "",
"financing": "",
"bank": "",
"brand": "Visa",
"fingerprint": null,
"first_digits": null,
"last_digits": "1234",
"name": null,
"expiration_month": null,
"expiration_year": null,
"security_code_check": true,
"created_at": "2021-01-21T09:29:38+07:00"
},
"customer": null,
"ip": null,
"dispute": null,
Expand Down