diff --git a/OmiseSwift.xcodeproj/project.pbxproj b/OmiseSwift.xcodeproj/project.pbxproj index 1f94b2b..6e88ed1 100644 --- a/OmiseSwift.xcodeproj/project.pbxproj +++ b/OmiseSwift.xcodeproj/project.pbxproj @@ -204,6 +204,7 @@ 8AF2219F21A40EE900AAF0F9 /* SearchOperationFixtureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF2219D21A40EE900AAF0F9 /* SearchOperationFixtureTests.swift */; }; 8AF584421E0153AC00D7D647 /* ChargeOperationsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF584411E0153AC00D7D647 /* ChargeOperationsTest.swift */; }; 98256FF31D225E3000F91436 /* TransferOperationsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98256FF11D225E3000F91436 /* TransferOperationsTest.swift */; }; + F678EA8F260C318B00EA7F7E /* RecipientOperationFixtureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F678EA8E260C318B00EA7F7E /* RecipientOperationFixtureTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -337,6 +338,7 @@ 8AF2219D21A40EE900AAF0F9 /* SearchOperationFixtureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchOperationFixtureTests.swift; sourceTree = ""; }; 8AF584411E0153AC00D7D647 /* ChargeOperationsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChargeOperationsTest.swift; sourceTree = ""; }; 98256FF11D225E3000F91436 /* TransferOperationsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferOperationsTest.swift; sourceTree = ""; }; + F678EA8E260C318B00EA7F7E /* RecipientOperationFixtureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipientOperationFixtureTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -452,6 +454,7 @@ 8A590B491EDD780A003C60E0 /* ForexOperationFixtureTests.swift */, 8AD3F2D41DEC113200F68FB4 /* LinkOperationFixtureTest.swift */, 8A5880EE1F46EEB300647405 /* ReceiptsOperationFixtureTests.swift */, + F678EA8E260C318B00EA7F7E /* RecipientOperationFixtureTests.swift */, 8A2698A11D743A2100515A0A /* RefundOperationFixtureTests.swift */, 8A4469D11ED5A40C00F07334 /* SchedulesOperationFixtureTests.swift */, 8AF2219D21A40EE900AAF0F9 /* SearchOperationFixtureTests.swift */, @@ -981,6 +984,7 @@ 8A07D2F51D73F5040030B68D /* FixtureClient.swift in Sources */, 8A98759E1F0673C90090D56F /* DocumentOperationTest.swift in Sources */, 8A1CF6B01F8BC1D7003EDB38 /* DigitsTest.swift in Sources */, + F678EA8F260C318B00EA7F7E /* RecipientOperationFixtureTests.swift in Sources */, 22112D0D1CC7910700D0DB54 /* OmiseTestCase.swift in Sources */, 8A208DDD21A81267009104C0 /* CapabilityOperationFixtureTests.swift in Sources */, ); diff --git a/OmiseSwift/API Models/Card.swift b/OmiseSwift/API Models/Card.swift index 099b288..f48084f 100644 --- a/OmiseSwift/API Models/Card.swift +++ b/OmiseSwift/API Models/Card.swift @@ -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 @@ -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? @@ -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) diff --git a/OmiseSwift/API Models/Charge.swift b/OmiseSwift/API Models/Charge.swift index b034417..20a47a2 100644 --- a/OmiseSwift/API Models/Charge.swift +++ b/OmiseSwift/API Models/Charge.swift @@ -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 } } diff --git a/OmiseSwiftTests/ChargesOperationFixtureTests.swift b/OmiseSwiftTests/ChargesOperationFixtureTests.swift index 7f5eac0..e1ff1e6 100644 --- a/OmiseSwiftTests/ChargesOperationFixtureTests.swift +++ b/OmiseSwiftTests/ChargesOperationFixtureTests.swift @@ -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)") } diff --git a/OmiseSwiftTests/Fixtures/api.omise.co/charges/chrg_test_5fzc7v0ce9ukmm02al2-get.json b/OmiseSwiftTests/Fixtures/api.omise.co/charges/chrg_test_5fzc7v0ce9ukmm02al2-get.json index 5f93020..4e3d0a9 100644 --- a/OmiseSwiftTests/Fixtures/api.omise.co/charges/chrg_test_5fzc7v0ce9ukmm02al2-get.json +++ b/OmiseSwiftTests/Fixtures/api.omise.co/charges/chrg_test_5fzc7v0ce9ukmm02al2-get.json @@ -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,