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 all 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
4 changes: 4 additions & 0 deletions OmiseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -337,6 +338,7 @@
8AF2219D21A40EE900AAF0F9 /* SearchOperationFixtureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchOperationFixtureTests.swift; sourceTree = "<group>"; };
8AF584411E0153AC00D7D647 /* ChargeOperationsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChargeOperationsTest.swift; sourceTree = "<group>"; };
98256FF11D225E3000F91436 /* TransferOperationsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferOperationsTest.swift; sourceTree = "<group>"; };
F678EA8E260C318B00EA7F7E /* RecipientOperationFixtureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipientOperationFixtureTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
);
Expand Down
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