Skip to content

Commit

Permalink
[fix] change price to Decimal + add cocoapods
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Apr 6, 2020
1 parent 5eb18e2 commit c6910b6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2020 Oleh Hudeichuk. All rights reserved.
//

import Foundation

public struct WFPChargeRequest: Codable {

public var apiVersion: Int
Expand All @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2020 Oleh Hudeichuk. All rights reserved.
//

import Foundation

public struct WFPChargeResponse: Codable {

public var reason: String
Expand All @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions Sources/WFPClient/Helpers/WFPError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
14 changes: 7 additions & 7 deletions Sources/WFPClient/WFPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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))
Expand All @@ -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))

Expand Down
32 changes: 32 additions & 0 deletions WFPClient.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]' }
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

0 comments on commit c6910b6

Please sign in to comment.