Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDKI-130: Update amount parameters in Base SDK and UI Components to use integers for subunits #83

Merged
merged 2 commits into from
Aug 22, 2024
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
82 changes: 41 additions & 41 deletions SeamlessPay/API/Client/APIClient+Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<PaymentMethod, SeamlessPayError> {
await withCheckedContinuation { continuation in
tokenize(
Expand All @@ -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<Customer, SeamlessPayError> {
await withCheckedContinuation { continuation in
createCustomer(
Expand All @@ -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<Customer, SeamlessPayError> {
await withCheckedContinuation { continuation in
updateCustomer(
Expand Down Expand Up @@ -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<Charge, SeamlessPayError> {
await withCheckedContinuation { continuation in
createCharge(
Expand Down Expand Up @@ -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<Refund, SeamlessPayError> {
await withCheckedContinuation { continuation in
createRefund(
Expand Down
148 changes: 73 additions & 75 deletions SeamlessPay/API/Client/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<PaymentMethod, SeamlessPayError>) -> Void)?
) {
var parameters: [String: Any?] = [
Expand Down Expand Up @@ -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<Customer, SeamlessPayError>) -> Void)?
) {
customer(
Expand All @@ -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<Customer, SeamlessPayError>) -> Void)?
) {
customer(
Expand Down Expand Up @@ -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<Charge, SeamlessPayError>) -> Void)?
) {
charge(
Expand Down Expand Up @@ -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<Refund, SeamlessPayError>) -> Void)?
) {
let parameters: [String: Any?] = [
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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<Customer, SeamlessPayError>) -> Void)?
) {
Expand Down Expand Up @@ -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<Charge, SeamlessPayError>) -> Void)?
) {
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand All @@ -503,7 +502,6 @@ private extension APIClient {
"Accept": "application/json",
"Authorization": authHeaderValue,
"User-Agent": "seamlesspay_ios",
"Content-Length": contentLength,
"SeamlessPay-Account": proxyAccountId,
]
.compactMapValues { $0 }
Expand Down
6 changes: 3 additions & 3 deletions SeamlessPay/API/Models/Response/Charge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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”.
*/
public let tip: String?
/**
* Surcharge fee amount. String with 2 decimal places e.g “25.00”.
*/
public let surchargeFeeAmount: String?
public let surchargeFeeAmount: Int?
/**
* Order dictionary
*/
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion SeamlessPay/API/Models/Response/Refund.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Loading