From 589867ebb683b4e5a43c8c5a5606bac84d26f0ed Mon Sep 17 00:00:00 2001 From: seamless-pay-ios Date: Tue, 20 Aug 2024 19:06:20 +0100 Subject: [PATCH 1/2] feat: SDKI-130: Update amount type to interact with v2 API --- .../API/Client/APIClient+Concurrency.swift | 82 +++++----- SeamlessPay/API/Client/APIClient.swift | 147 +++++++++--------- SeamlessPay/API/Models/Response/Charge.swift | 6 +- SeamlessPay/API/Models/Response/Refund.swift | 2 +- SeamlessPay/UI/Models/ChargeRequest.swift | 12 +- SeamlessPay/UI/Models/PaymentResponse.swift | 4 +- SeamlessPay/UI/Models/RefundRequest.swift | 4 +- .../APIClient/APIClientConcurrencyTests.swift | 4 +- .../APIClient/APIClientTest.swift | 32 ++-- .../APIClientWithProxyAccountIdTest.swift | 8 +- .../SingleLineCardForm+RequestsTest.swift | 24 +-- 11 files changed, 162 insertions(+), 163 deletions(-) diff --git a/SeamlessPay/API/Client/APIClient+Concurrency.swift b/SeamlessPay/API/Client/APIClient+Concurrency.swift index 84ea9e6b..b3d66ae1 100644 --- a/SeamlessPay/API/Client/APIClient+Concurrency.swift +++ b/SeamlessPay/API/Client/APIClient+Concurrency.swift @@ -12,13 +12,13 @@ public extension APIClient { func tokenize( paymentType: PaymentType, accountNumber: String, - expDate: ExpirationDate? = nil, - cvv: String? = nil, - accountType: String? = nil, - routing: String? = nil, - pin: String? = nil, - billingAddress: Address? = nil, - name: String? = nil + expDate: ExpirationDate? = .none, + cvv: String? = .none, + accountType: String? = .none, + routing: String? = .none, + pin: String? = .none, + billingAddress: Address? = .none, + name: String? = .none ) async -> Result { await withCheckedContinuation { continuation in tokenize( @@ -41,13 +41,13 @@ public extension APIClient { func createCustomer( name: String, email: String, - address: Address? = nil, - companyName: String? = nil, - notes: String? = nil, - phone: String? = nil, - website: String? = nil, - paymentMethods: [PaymentMethod]? = nil, - metadata: String? = nil + address: Address? = .none, + companyName: String? = .none, + notes: String? = .none, + phone: String? = .none, + website: String? = .none, + paymentMethods: [PaymentMethod]? = .none, + metadata: String? = .none ) async -> Result { await withCheckedContinuation { continuation in createCustomer( @@ -70,13 +70,13 @@ public extension APIClient { id: String, name: String, email: String, - address: Address? = nil, - companyName: String? = nil, - notes: String? = nil, - phone: String? = nil, - website: String? = nil, - paymentMethods: [PaymentMethod]? = nil, - metadata: String? = nil + address: Address? = .none, + companyName: String? = .none, + notes: String? = .none, + phone: String? = .none, + website: String? = .none, + paymentMethods: [PaymentMethod]? = .none, + metadata: String? = .none ) async -> Result { await withCheckedContinuation { continuation in updateCustomer( @@ -110,22 +110,22 @@ public extension APIClient { // MARK: Charge func createCharge( token: String, - cvv: String? = nil, + cvv: String? = .none, capture: Bool? = false, - currency: String? = nil, - amount: String, - taxAmount: String? = nil, - taxExempt: Bool? = nil, - tip: String? = nil, - surchargeFeeAmount: String? = nil, - description: String? = nil, - order: [String: String]? = nil, - orderID: String? = nil, - poNumber: String? = nil, - metadata: String? = nil, - descriptor: String? = nil, - entryType: String? = nil, - idempotencyKey: String? = nil + currency: String? = .none, + amount: Int, + taxAmount: Int? = .none, + taxExempt: Bool? = .none, + tip: String? = .none, + surchargeFeeAmount: Int? = .none, + description: String? = .none, + order: [String: String]? = .none, + orderID: String? = .none, + poNumber: String? = .none, + metadata: String? = .none, + descriptor: String? = .none, + entryType: String? = .none, + idempotencyKey: String? = .none ) async -> Result { await withCheckedContinuation { continuation in createCharge( @@ -185,11 +185,11 @@ public extension APIClient { // MARK: Refunds func createRefund( token: String, - amount: String, - currency: String? = nil, - descriptor: String? = nil, - idempotencyKey: String? = nil, - metadata: String? = nil + amount: Int, + currency: String? = .none, + descriptor: String? = .none, + idempotencyKey: String? = .none, + metadata: String? = .none ) async -> Result { await withCheckedContinuation { continuation in createRefund( diff --git a/SeamlessPay/API/Client/APIClient.swift b/SeamlessPay/API/Client/APIClient.swift index 5947c69e..ee2e3aee 100644 --- a/SeamlessPay/API/Client/APIClient.swift +++ b/SeamlessPay/API/Client/APIClient.swift @@ -9,7 +9,7 @@ import Foundation public class APIClient { // MARK: Private Constants - private let apiVersion = "v2020" + private let apiVersion = "v2" // MARK: Private private let session: URLSession @@ -47,13 +47,13 @@ public class APIClient { public func tokenize( paymentType: PaymentType, accountNumber: String, - expDate: ExpirationDate? = nil, - cvv: String? = nil, - accountType: String? = nil, - routing: String? = nil, - pin: String? = nil, - billingAddress: Address? = nil, - name: String? = nil, + expDate: ExpirationDate? = .none, + cvv: String? = .none, + accountType: String? = .none, + routing: String? = .none, + pin: String? = .none, + billingAddress: Address? = .none, + name: String? = .none, completion: ((Result) -> Void)? ) { var parameters: [String: Any?] = [ @@ -89,13 +89,13 @@ public class APIClient { public func createCustomer( name: String, email: String, - address: Address? = nil, - companyName: String? = nil, - notes: String? = nil, - phone: String? = nil, - website: String? = nil, - paymentMethods: [PaymentMethod]? = nil, - metadata: String? = nil, + address: Address? = .none, + companyName: String? = .none, + notes: String? = .none, + phone: String? = .none, + website: String? = .none, + paymentMethods: [PaymentMethod]? = .none, + metadata: String? = .none, completion: ((Result) -> Void)? ) { customer( @@ -117,13 +117,13 @@ public class APIClient { id: String, name: String, email: String, - address: Address? = nil, - companyName: String? = nil, - notes: String? = nil, - phone: String? = nil, - website: String? = nil, - paymentMethods: [PaymentMethod]? = nil, - metadata: String? = nil, + address: Address? = .none, + companyName: String? = .none, + notes: String? = .none, + phone: String? = .none, + website: String? = .none, + paymentMethods: [PaymentMethod]? = .none, + metadata: String? = .none, completion: ((Result) -> Void)? ) { customer( @@ -151,22 +151,22 @@ public class APIClient { // MARK: Charge public func createCharge( token: String, - amount: String, - cvv: String? = nil, + amount: Int, + cvv: String? = .none, capture: Bool? = false, - currency: String? = nil, - taxAmount: String? = nil, - taxExempt: Bool? = nil, - tip: String? = nil, - surchargeFeeAmount: String? = nil, - description: String? = nil, - order: [String: String]? = nil, - orderID: String? = nil, - poNumber: String? = nil, - metadata: String? = nil, - descriptor: String? = nil, - entryType: String? = nil, - idempotencyKey: String? = nil, + currency: String? = .none, + taxAmount: Int? = .none, + taxExempt: Bool? = .none, + tip: String? = .none, + surchargeFeeAmount: Int? = .none, + description: String? = .none, + order: [String: String]? = .none, + orderID: String? = .none, + poNumber: String? = .none, + metadata: String? = .none, + descriptor: String? = .none, + entryType: String? = .none, + idempotencyKey: String? = .none, completion: ((Result) -> Void)? ) { charge( @@ -231,11 +231,11 @@ public class APIClient { // MARK: Refunds public func createRefund( token: String, - amount: String, - currency: String? = nil, - descriptor: String? = nil, - idempotencyKey: String? = nil, - metadata: String? = nil, + amount: Int, + currency: String? = .none, + descriptor: String? = .none, + idempotencyKey: String? = .none, + metadata: String? = .none, completion: ((Result) -> Void)? ) { let parameters: [String: Any?] = [ @@ -273,9 +273,8 @@ private extension APIClient { parameters: parameters ) - session.dataTask( - with: request - ) { [weak self] data, response, error in + session.dataTask(with: request) { [weak self] data, response, error in + guard let self else { return } @@ -322,15 +321,15 @@ private extension APIClient { // MARK: Helpers private extension APIClient { func customer( - name: String? = nil, - email: String? = nil, - address: Address? = nil, - companyName: String? = nil, - notes: String? = nil, - phone: String? = nil, - website: String? = nil, - paymentMethods: [PaymentMethod]? = nil, - metadata: String? = nil, + name: String? = .none, + email: String? = .none, + address: Address? = .none, + companyName: String? = .none, + notes: String? = .none, + phone: String? = .none, + website: String? = .none, + paymentMethods: [PaymentMethod]? = .none, + metadata: String? = .none, operation: APIOperation, completion: ((Result) -> Void)? ) { @@ -359,23 +358,23 @@ private extension APIClient { } func charge( - token: String? = nil, - cvv: String? = nil, - capture: Bool? = nil, - currency: String? = nil, - amount: String? = nil, - taxAmount: String? = nil, - taxExempt: Bool? = nil, - tip: String? = nil, - surchargeFeeAmount: String? = nil, - description: String? = nil, - order: [String: String]? = nil, - orderID: String? = nil, - poNumber: String? = nil, - metadata: String? = nil, - descriptor: String? = nil, - entryType: String? = nil, - idempotencyKey: String? = nil, + token: String? = .none, + cvv: String? = .none, + capture: Bool? = .none, + currency: String? = .none, + amount: Int? = .none, + taxAmount: Int? = .none, + taxExempt: Bool? = .none, + tip: String? = .none, + surchargeFeeAmount: Int? = .none, + description: String? = .none, + order: [String: String]? = .none, + orderID: String? = .none, + poNumber: String? = .none, + metadata: String? = .none, + descriptor: String? = .none, + entryType: String? = .none, + idempotencyKey: String? = .none, operation: APIOperation, completion: ((Result) -> Void)? ) { @@ -451,7 +450,7 @@ private extension APIClient { .put: postBody = try parameters.flatMap { try JSONSerialization.data(withJSONObject: $0) } default: - postBody = nil + postBody = .none } let url = try url( @@ -476,11 +475,11 @@ private extension APIClient { return request } - func url(host: String?, path: String, queryItems: [String: String]? = nil) throws -> URL { + func url(host: String?, path: String, queryItems: [String: String]? = .none) throws -> URL { var urlComponents = URLComponents() urlComponents.scheme = "https" urlComponents.host = host - urlComponents.port = nil + urlComponents.port = .none urlComponents.path = path urlComponents.queryItems = queryItems?.map { URLQueryItem(name: $0, value: $1) } guard let url = urlComponents.url else { diff --git a/SeamlessPay/API/Models/Response/Charge.swift b/SeamlessPay/API/Models/Response/Charge.swift index 6385d38c..4ff838a0 100644 --- a/SeamlessPay/API/Models/Response/Charge.swift +++ b/SeamlessPay/API/Models/Response/Charge.swift @@ -21,7 +21,7 @@ public struct Charge: APICodable { /** * Amount to add to stored value account. */ - public let amount: String? + public let amount: Int? /** * String with 2 decimal places e.g “25.00”. */ @@ -29,7 +29,7 @@ public struct Charge: APICodable { /** * Surcharge fee amount. String with 2 decimal places e.g “25.00”. */ - public let surchargeFeeAmount: String? + public let surchargeFeeAmount: Int? /** * Order dictionary */ @@ -132,7 +132,7 @@ public struct Order: Codable { public struct Item: Codable { public let itemDescription, discountAmount, lineNumber, lineTotal: String? public let taxRate, unitCost, unitOfMeasure, upc: String? - public let quantity, taxAmount: String? + public let quantity, taxAmount: Int? public let taxExempt: Bool? enum CodingKeys: String, CodingKey { diff --git a/SeamlessPay/API/Models/Response/Refund.swift b/SeamlessPay/API/Models/Response/Refund.swift index 329cd087..99053c93 100644 --- a/SeamlessPay/API/Models/Response/Refund.swift +++ b/SeamlessPay/API/Models/Response/Refund.swift @@ -12,7 +12,7 @@ import Foundation public struct Refund: APICodable { public let id: String public let accountType: AccountType? - public let amount: String? + public let amount: Int? public let authCode: String? public let batchID: String? public let createdAt: String? diff --git a/SeamlessPay/UI/Models/ChargeRequest.swift b/SeamlessPay/UI/Models/ChargeRequest.swift index 5bb0afd5..e4b34443 100644 --- a/SeamlessPay/UI/Models/ChargeRequest.swift +++ b/SeamlessPay/UI/Models/ChargeRequest.swift @@ -8,7 +8,7 @@ import Foundation public struct ChargeRequest { - public let amount: String + public let amount: Int public let capture: Bool public let currency: String? public let description: String? @@ -19,13 +19,13 @@ public struct ChargeRequest { public let order: [String: String]? public let orderID: String? public let poNumber: String? - public let surchargeFeeAmount: String? - public let taxAmount: String? + public let surchargeFeeAmount: Int? + public let taxAmount: Int? public let taxExempt: Bool? public let tip: String? public init( - amount: String, + amount: Int, capture: Bool = true, currency: String? = .none, description: String? = .none, @@ -36,8 +36,8 @@ public struct ChargeRequest { order: [String: String]? = .none, orderID: String? = .none, poNumber: String? = .none, - surchargeFeeAmount: String? = .none, - taxAmount: String? = .none, + surchargeFeeAmount: Int? = .none, + taxAmount: Int? = .none, taxExempt: Bool? = .none, tip: String? = .none ) { diff --git a/SeamlessPay/UI/Models/PaymentResponse.swift b/SeamlessPay/UI/Models/PaymentResponse.swift index 6291ceab..d15792dc 100644 --- a/SeamlessPay/UI/Models/PaymentResponse.swift +++ b/SeamlessPay/UI/Models/PaymentResponse.swift @@ -10,7 +10,7 @@ import Foundation public struct PaymentResponse: Identifiable, Equatable { public struct Details: Equatable { public let accountType: AccountType? - public let amount: String? + public let amount: Int? public let authCode: String? public let batchId: String? public let cardBrand: PaymentNetwork? @@ -20,7 +20,7 @@ public struct PaymentResponse: Identifiable, Equatable { public let status: TransactionStatus? public let statusCode: String? public let statusDescription: String? - public let surchargeFeeAmount: String? + public let surchargeFeeAmount: Int? public let tip: String? public let transactionDate: String? public let avsPostalCodeResult: AVSResult? diff --git a/SeamlessPay/UI/Models/RefundRequest.swift b/SeamlessPay/UI/Models/RefundRequest.swift index e0fef487..47068e75 100644 --- a/SeamlessPay/UI/Models/RefundRequest.swift +++ b/SeamlessPay/UI/Models/RefundRequest.swift @@ -8,14 +8,14 @@ import Foundation public struct RefundRequest { - public let amount: String + public let amount: Int public let currency: String? public let descriptor: String? public let idempotencyKey: String? public let metadata: String? public init( - amount: String, + amount: Int, currency: String? = .none, descriptor: String? = .none, idempotencyKey: String? = .none, diff --git a/Tests/SeamlessPayTests/APIClient/APIClientConcurrencyTests.swift b/Tests/SeamlessPayTests/APIClient/APIClientConcurrencyTests.swift index db6b7891..689b4c61 100644 --- a/Tests/SeamlessPayTests/APIClient/APIClientConcurrencyTests.swift +++ b/Tests/SeamlessPayTests/APIClient/APIClientConcurrencyTests.swift @@ -91,7 +91,7 @@ final class APIClientConcurrencyTest: XCTestCase { func testAsyncCreateChargeRequest() async { // when - _ = await client.createCharge(token: "test_token", amount: "100") + _ = await client.createCharge(token: "test_token", amount: 100) // then XCTAssertEqual(urlToBeTested, "https://api.seamlesspay.com/charges") @@ -104,7 +104,7 @@ final class APIClientConcurrencyTest: XCTestCase { // when _ = await client.createRefund( token: "test_token", - amount: "101" + amount: 101 ) // then diff --git a/Tests/SeamlessPayTests/APIClient/APIClientTest.swift b/Tests/SeamlessPayTests/APIClient/APIClientTest.swift index 2d679e74..519af18d 100644 --- a/Tests/SeamlessPayTests/APIClient/APIClientTest.swift +++ b/Tests/SeamlessPayTests/APIClient/APIClientTest.swift @@ -64,7 +64,7 @@ final class APIClientTest: XCTestCase { XCTAssertNotNil(headers["Content-Length"]) XCTAssertEqual(headers["Content-Type"], "application/json") XCTAssertEqual(headers["Accept"], "application/json") - XCTAssertEqual(headers["API-Version"], "v2020") + XCTAssertEqual(headers["API-Version"], "v2") XCTAssertEqual(headers["User-Agent"], "seamlesspay_ios") XCTAssertEqual(headers["Authorization"], "Bearer sk_TEST") @@ -217,7 +217,7 @@ final class APIClientTest: XCTestCase { XCTAssertNil(headers["Content-Length"]) XCTAssertEqual(headers["Content-Type"], "application/json") XCTAssertEqual(headers["Accept"], "application/json") - XCTAssertEqual(headers["API-Version"], "v2020") + XCTAssertEqual(headers["API-Version"], "v2") XCTAssertEqual(headers["User-Agent"], "seamlesspay_ios") XCTAssertEqual(headers["Authorization"], "Bearer sk_TEST") @@ -247,7 +247,7 @@ final class APIClientTest: XCTestCase { XCTAssertNil(headers["Content-Length"]) XCTAssertEqual(headers["Content-Type"], "application/json") XCTAssertEqual(headers["Accept"], "application/json") - XCTAssertEqual(headers["API-Version"], "v2020") + XCTAssertEqual(headers["API-Version"], "v2") XCTAssertEqual(headers["User-Agent"], "seamlesspay_ios") XCTAssertEqual(headers["Authorization"], "Bearer sk_TEST") @@ -277,7 +277,7 @@ final class APIClientTest: XCTestCase { XCTAssertNil(headers["Content-Length"]) XCTAssertEqual(headers["Content-Type"], "application/json") XCTAssertEqual(headers["Accept"], "application/json") - XCTAssertEqual(headers["API-Version"], "v2020") + XCTAssertEqual(headers["API-Version"], "v2") XCTAssertEqual(headers["User-Agent"], "seamlesspay_ios") XCTAssertEqual(headers["Authorization"], "Bearer sk_TEST") @@ -293,14 +293,14 @@ final class APIClientTest: XCTestCase { // when client.createCharge( token: "test_token", - amount: "100", + amount: 100, cvv: "test_cvv", capture: true, currency: "test_currency", - taxAmount: "test_taxAmount", + taxAmount: 1, taxExempt: false, tip: "test_tip", - surchargeFeeAmount: "test_surchargeFeeAmount", + surchargeFeeAmount: 12, description: "test_description", order: ["test_order_key": "test_order_value"], orderID: "test_orderID", @@ -325,7 +325,7 @@ final class APIClientTest: XCTestCase { XCTAssertNotNil(headers["Content-Length"]) XCTAssertEqual(headers["Content-Type"], "application/json") XCTAssertEqual(headers["Accept"], "application/json") - XCTAssertEqual(headers["API-Version"], "v2020") + XCTAssertEqual(headers["API-Version"], "v2") XCTAssertEqual(headers["User-Agent"], "seamlesspay_ios") XCTAssertEqual(headers["Authorization"], "Bearer sk_TEST") @@ -333,10 +333,10 @@ final class APIClientTest: XCTestCase { let capture = body["capture"] as! Bool let cvv = body["cvv"] as! String let currency = body["currency"] as! String - let taxAmount = body["taxAmount"] as! String + let taxAmount = body["taxAmount"] as! Int let taxExempt = body["taxExempt"] as! Bool let tip = body["tip"] as! String - let surchargeFeeAmount = body["surchargeFeeAmount"] as! String + let surchargeFeeAmount = body["surchargeFeeAmount"] as! Int let description = body["description"] as! String let order = body["order"] as! [String: String] @@ -353,10 +353,10 @@ final class APIClientTest: XCTestCase { XCTAssertEqual(capture, true) XCTAssertEqual(cvv, "test_cvv") XCTAssertEqual(currency, "test_currency") - XCTAssertEqual(taxAmount, "test_taxAmount") + XCTAssertEqual(taxAmount, 1) XCTAssertEqual(taxExempt, false) XCTAssertEqual(tip, "test_tip") - XCTAssertEqual(surchargeFeeAmount, "test_surchargeFeeAmount") + XCTAssertEqual(surchargeFeeAmount, 12) XCTAssertEqual(description, "test_description") XCTAssertEqual(order, ["test_order_key": "test_order_value"]) XCTAssertEqual(orderId, "test_orderID") @@ -379,7 +379,7 @@ final class APIClientTest: XCTestCase { // when client.createRefund( token: "test_token", - amount: "101" + amount: 101 ) { result in // then @@ -396,16 +396,16 @@ final class APIClientTest: XCTestCase { XCTAssertNotNil(headers["Content-Length"]) XCTAssertEqual(headers["Content-Type"], "application/json") XCTAssertEqual(headers["Accept"], "application/json") - XCTAssertEqual(headers["API-Version"], "v2020") + XCTAssertEqual(headers["API-Version"], "v2") XCTAssertEqual(headers["User-Agent"], "seamlesspay_ios") XCTAssertEqual(headers["Authorization"], "Bearer sk_TEST") let token = body["token"] as! String - let amount = body["amount"] as! String + let amount = body["amount"] as! Int // parameters XCTAssertEqual(token, "test_token") - XCTAssertEqual(amount, "101") + XCTAssertEqual(amount, 101) expectation.fulfill() } diff --git a/Tests/SeamlessPayTests/APIClient/APIClientWithProxyAccountIdTest.swift b/Tests/SeamlessPayTests/APIClient/APIClientWithProxyAccountIdTest.swift index 5d21a3f8..62be4cf3 100644 --- a/Tests/SeamlessPayTests/APIClient/APIClientWithProxyAccountIdTest.swift +++ b/Tests/SeamlessPayTests/APIClient/APIClientWithProxyAccountIdTest.swift @@ -127,14 +127,14 @@ final class APIClientWithProxyAccountIdTest: XCTestCase { // when client.createCharge( token: "test_token", - amount: "100", + amount: 100, cvv: "test_cvv", capture: true, currency: "test_currency", - taxAmount: "test_taxAmount", + taxAmount: 12, taxExempt: false, tip: "test_tip", - surchargeFeeAmount: "test_surchargeFeeAmount", + surchargeFeeAmount: 12, description: "test_description", order: ["test_order_key": "test_order_value"], orderID: "test_orderID", @@ -165,7 +165,7 @@ final class APIClientWithProxyAccountIdTest: XCTestCase { // when client.createRefund( token: "test_token", - amount: "101" + amount: 101 ) { result in // then diff --git a/Tests/SeamlessPayTests/UI/PaymentInputs/Direct/SingleLineCardForm+RequestsTest.swift b/Tests/SeamlessPayTests/UI/PaymentInputs/Direct/SingleLineCardForm+RequestsTest.swift index 75b0a6c9..7e7ec3a5 100644 --- a/Tests/SeamlessPayTests/UI/PaymentInputs/Direct/SingleLineCardForm+RequestsTest.swift +++ b/Tests/SeamlessPayTests/UI/PaymentInputs/Direct/SingleLineCardForm+RequestsTest.swift @@ -54,7 +54,7 @@ class SingleLineCardFormRequestsTest: XCTestCase { // Given let apiClientMock = APIClientMock() sut.apiClient = apiClientMock - let request = ChargeRequest(amount: "1") + let request = ChargeRequest(amount: 1) // When sut.charge(request) { result in @@ -62,14 +62,14 @@ class SingleLineCardFormRequestsTest: XCTestCase { switch result { case let .success(payload): XCTAssertEqual(payload.id, "mockedChargeID") - XCTAssertEqual(payload.details.amount, "99") + XCTAssertEqual(payload.details.amount, 99) XCTAssertEqual(payload.details.status, .captured) XCTAssertEqual(payload.details.statusCode, "mocked_statusCode") XCTAssertEqual(payload.details.statusDescription, "mocked_statusDescription") XCTAssertEqual(payload.details.authCode, "mocked_authCode") XCTAssertEqual(payload.details.batchId, "mocked_batch") XCTAssertEqual(payload.details.transactionDate, "mocked_transactionDate") - XCTAssertEqual(payload.details.surchargeFeeAmount, "mocked_surchargeFeeAmount") + XCTAssertEqual(payload.details.surchargeFeeAmount, 101) XCTAssertEqual(payload.details.cardBrand, .masterCard) XCTAssertEqual(payload.details.lastFour, "mocked_lastFour") XCTAssertEqual(payload.details.cardBrand, .masterCard) @@ -92,7 +92,7 @@ class SingleLineCardFormRequestsTest: XCTestCase { // Given let apiClientMock = APIClientMock() sut.apiClient = apiClientMock - let request = RefundRequest(amount: "1") + let request = RefundRequest(amount: 1) // When sut.refund(request) { result in @@ -100,7 +100,7 @@ class SingleLineCardFormRequestsTest: XCTestCase { switch result { case let .success(payload): XCTAssertEqual(payload.id, "refund_id") - XCTAssertEqual(payload.details.amount, "refund_amount") + XCTAssertEqual(payload.details.amount, 10001) XCTAssertEqual(payload.details.status, .authorized) XCTAssertEqual(payload.details.statusCode, "refund_statusCode") XCTAssertEqual(payload.details.statusDescription, "refund_statusDescription") @@ -168,14 +168,14 @@ private class APIClientMock: APIClient { override func createCharge( token: String, - amount: String?, + amount: Int?, cvv: String? = nil, capture: Bool? = false, currency: String? = nil, - taxAmount: String? = nil, + taxAmount: Int? = nil, taxExempt: Bool? = nil, tip: String? = nil, - surchargeFeeAmount: String? = nil, + surchargeFeeAmount: Int? = nil, description: String? = nil, order: [String: String]? = nil, orderID: String? = nil, @@ -189,9 +189,9 @@ private class APIClientMock: APIClient { let charge = Charge( id: "mockedChargeID", method: .charge, - amount: "99", + amount: 99, tip: "mocked_tip", - surchargeFeeAmount: "mocked_surchargeFeeAmount", + surchargeFeeAmount: 101, order: .init( items: [], shipFromPostalCode: "mocked_shipFromPostalCode", @@ -230,7 +230,7 @@ private class APIClientMock: APIClient { override func createRefund( token: String, - amount: String, + amount: Int, currency: String? = nil, descriptor: String? = nil, idempotencyKey: String? = nil, @@ -242,7 +242,7 @@ private class APIClientMock: APIClient { Refund( id: "refund_id", accountType: .credit, - amount: "refund_amount", + amount: 10001, authCode: "refund_aute_code", batchID: "refund_batch_id", createdAt: "refund_created_at", From 74f1144148ffb46021ce69eb5626f1f49d745feb Mon Sep 17 00:00:00 2001 From: seamless-pay-ios Date: Wed, 21 Aug 2024 13:11:52 +0100 Subject: [PATCH 2/2] feat SDKI-130: Remove content lenght header. --- SeamlessPay/API/Client/APIClient.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/SeamlessPay/API/Client/APIClient.swift b/SeamlessPay/API/Client/APIClient.swift index ee2e3aee..29d6e81e 100644 --- a/SeamlessPay/API/Client/APIClient.swift +++ b/SeamlessPay/API/Client/APIClient.swift @@ -502,7 +502,6 @@ private extension APIClient { "Accept": "application/json", "Authorization": authHeaderValue, "User-Agent": "seamlesspay_ios", - "Content-Length": contentLength, "SeamlessPay-Account": proxyAccountId, ] .compactMapValues { $0 }