From c6910b60871eac99d4b53f39d0fa10802bc4dc8b Mon Sep 17 00:00:00 2001 From: Oleh Hudeichuk Date: Mon, 6 Apr 2020 08:40:06 +0300 Subject: [PATCH] [fix] change price to Decimal + add cocoapods --- .../Models/Request/WFPCharge+Request.swift | 10 +++--- .../Models/Response/WFPCharge+Response.swift | 4 ++- Sources/WFPClient/Helpers/WFPError.swift | 6 ++-- Sources/WFPClient/WFPClient.swift | 14 ++++---- WFPClient.podspec | 32 +++++++++++++++++++ 5 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 WFPClient.podspec diff --git a/Sources/WFPClient/ApplePay/Models/Request/WFPCharge+Request.swift b/Sources/WFPClient/ApplePay/Models/Request/WFPCharge+Request.swift index cf105df..a4d1ba8 100644 --- a/Sources/WFPClient/ApplePay/Models/Request/WFPCharge+Request.swift +++ b/Sources/WFPClient/ApplePay/Models/Request/WFPCharge+Request.swift @@ -6,6 +6,8 @@ // Copyright © 2020 Oleh Hudeichuk. All rights reserved. // +import Foundation + public struct WFPChargeRequest: Codable { public var apiVersion: Int @@ -14,10 +16,10 @@ public struct WFPChargeRequest: Codable { public var merchantDomainName: String public var orderReference: String public var orderDate: Int64 - public var amount: Int + public var amount: Decimal public var currency: WFPCurrency public var productName: [String] - public var productPrice: [Int] + public var productPrice: [Decimal] public var productCount: [Int] public var clientFirstName: String public var clientLastName: String @@ -39,10 +41,10 @@ public struct WFPChargeRequest: Codable { merchantDomainName: String, orderReference: String, orderDate: Int64, - amount: Int = 0, + amount: Decimal = 0.0, currency: WFPCurrency, productName: [String] = [], - productPrice: [Int] = [], + productPrice: [Decimal] = [], productCount: [Int] = [], clientFirstName: String, clientLastName: String, diff --git a/Sources/WFPClient/ApplePay/Models/Response/WFPCharge+Response.swift b/Sources/WFPClient/ApplePay/Models/Response/WFPCharge+Response.swift index a9dbef5..694baaa 100644 --- a/Sources/WFPClient/ApplePay/Models/Response/WFPCharge+Response.swift +++ b/Sources/WFPClient/ApplePay/Models/Response/WFPCharge+Response.swift @@ -6,6 +6,8 @@ // Copyright © 2020 Oleh Hudeichuk. All rights reserved. // +import Foundation + public struct WFPChargeResponse: Codable { public var reason: String @@ -14,7 +16,7 @@ public struct WFPChargeResponse: Codable { public var authTicket: String? public var orderReference: String? public var merchantSignature: String? - public var amount: Double? + public var amount: Decimal? public var currency: WFPCurrency? public var authCode: String? public var email: String? diff --git a/Sources/WFPClient/Helpers/WFPError.swift b/Sources/WFPClient/Helpers/WFPError.swift index 282b58b..ff23a25 100644 --- a/Sources/WFPClient/Helpers/WFPError.swift +++ b/Sources/WFPClient/Helpers/WFPError.swift @@ -8,12 +8,12 @@ import Foundation public enum WFPError: Error, CustomStringConvertible { - case codableError + case codableDecodeError public var description: String { switch self { - case .codableError: - return "Can't convert to codable model" + case .codableDecodeError: + return "Can't decode server response to swift struct" } } diff --git a/Sources/WFPClient/WFPClient.swift b/Sources/WFPClient/WFPClient.swift index f5d5c8f..bde8854 100644 --- a/Sources/WFPClient/WFPClient.swift +++ b/Sources/WFPClient/WFPClient.swift @@ -26,11 +26,11 @@ open class WFPClient { self.httpClient = httpClient } - public func addProduct(name: String, price: Int, count: Int) { + public func addProduct(name: String, price: Decimal, count: Int) { request.productName.append(name) request.productPrice.append(price) request.productCount.append(count) - request.amount += price * count + request.amount += price * Decimal(count) } public func generateSignature() { @@ -58,7 +58,7 @@ open class WFPClient { if let response: WFPChargeResponse = try? JSONDecoder().decode(WFPChargeResponse.self, from: data) { handler(.success(response)) } else { - handler(.failure(WFPError.codableError)) + handler(.failure(WFPError.codableDecodeError)) } case let .failure(error): handler(.failure(error)) @@ -71,17 +71,17 @@ open class WFPClient { addSignItem(to: &string, request.merchantAccount) addSignItem(to: &string, request.merchantDomainName) addSignItem(to: &string, request.orderReference) - addSignItem(to: &string, String(request.orderDate)) - addSignItem(to: &string, String(request.amount)) + addSignItem(to: &string, "\(request.orderDate)") + addSignItem(to: &string, "\(request.amount))") addSignItem(to: &string, request.currency.rawValue) request.productName.forEach { (name) in addSignItem(to: &string, name) } request.productCount.forEach { (count) in - addSignItem(to: &string, String(count)) + addSignItem(to: &string, "\(count)") } request.productPrice.forEach { (price) in - addSignItem(to: &string, String(price)) + addSignItem(to: &string, "\(price)") } string.remove(at: string.index(before: string.endIndex)) diff --git a/WFPClient.podspec b/WFPClient.podspec new file mode 100644 index 0000000..625d621 --- /dev/null +++ b/WFPClient.podspec @@ -0,0 +1,32 @@ +# +# Be sure to run `pod lib lint ActionCableSwift.podspec' to ensure this is a +# valid spec before submitting. +# +# Any lines starting with a # are optional, but their use is encouraged +# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html +# + +Pod::Spec.new do |s| + s.name = 'WFPClient' + s.module_name = 'WFPClient' + s.version = '0.2.1' + s.summary = 'WayForPay Swift Client for Apple Pay.' + s.swift_version = '5.1' + +# This description is used to generate tags and improve search results. +# * Think: What does it do? Why did you write it? What is the focus? +# * Try to keep it short, snappy and to the point. +# * Write the description between the DESC delimiters below. +# * Finally, don't worry about the indent, CocoaPods strips it! + + s.description = 'Swift Client for payment gateway WayForPay. Implemented Apple Pay API.' + s.homepage = 'https://github.com/nerzh/WayForPay-Swift-Client' + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.author = { 'Oleh Hudeichuk' => 'emptystamp@gmail.com' } + s.source = { :git => 'https://github.com/nerzh/WayForPay-Swift-Client.git', :tag => s.version.to_s } + s.social_media_url = 'https://www.linkedin.com/in/oleh-gudeychuk-428389ab' + s.ios.deployment_target = '11.0' + s.source_files = 'Sources/**/*' + s.frameworks = 'Foundation' + s.dependency 'SwiftExtensionsPack', '~> 0.3.0' +end