// // Payment.swift // // // Created by AntonovIA on 12.10.2020. // import Foundation // MARK: - Payment methods internal enum PaymentMethods: String { case shpa = "ac-shpa" } // MARK: - Request Message public struct Payment: Encodable { // Required: /// Payment amount in rub /// min: 1.00 public let amount: Decimal /// Your market order ID /// maxlength: 20 public let orderId: String // Payment method internal let paymentMethod: PaymentMethods = .shpa // Optional: /// Human readable `orderId` /// Defaults to `orderId` var showOrderId: String? /// Detailed text describing this order payment. var details: String? /// Data about paying customer var customer: CustomerData? // var recurrentable: Bool = false public init(amount: Decimal, orderId: String, showOrderId: String? = nil, details: String? = nil, customer: CustomerData? = nil, recurrentable: Bool = false) { self.amount = amount self.orderId = orderId self.showOrderId = (showOrderId == nil) ? orderId : showOrderId self.details = details self.customer = customer self.recurrentable = recurrentable } // MARK: - Encoder private enum CodingKeys: String, CodingKey { case amount, orderId, showOrderId, details, recurrentable, customer } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(amount, forKey: .amount) try container.encode(orderId, forKey: .orderId) try container.encode(showOrderId, forKey: .showOrderId) try container.encode(details, forKey: .details) try container.encode(recurrentable, forKey: .recurrentable) // Customer try customer?.encode(to: encoder) } #if DEBUG public static let example = Payment( amount: 150.00, orderId: String.random(length: 6), details: "Wonderful warm socks", customer: CustomerData( account: "ID-12345", comment: "By tomorrow please", email: "foo@bar.com", phone: "+7 900 000 00 00" ) ) #endif }