Skip to content

[EACQAPW-5763]: Реализовал передачу параметров для фискализации #503

Merged
merged 8 commits into from
Aug 3, 2023
Merged
20 changes: 10 additions & 10 deletions ASDKSample/ASDKSample/BuyProductsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ class BuyProductsViewController: UIViewController {
receiptItems.append(item)
}

paymentData.receipt = Receipt(
shopCode: nil,
email: customerEmail,
taxation: .osn,
phone: "+79876543210",
items: receiptItems,
agentData: nil,
supplierInfo: nil,
customer: nil,
customerInn: nil
paymentData.receipt = .version1_05(
ReceiptFdv1_05(
shopCode: nil,
email: customerEmail,
taxation: .osn,
phone: "+79876543210",
items: receiptItems,
agentData: nil,
supplierInfo: nil
)
)

return paymentData
Expand Down
18 changes: 9 additions & 9 deletions ASDKSample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ PODS:
- SwiftFormat/CLI (0.49.18)
- SwiftGen (6.6.2)
- SwiftLint (0.47.0)
- TinkoffASDKCore (3.1.0)
- TinkoffASDKCore/Tests (3.1.0)
- TinkoffASDKUI (3.1.0):
- TinkoffASDKCore (3.1.1)
- TinkoffASDKCore/Tests (3.1.1)
- TinkoffASDKUI (3.1.1):
- TinkoffASDKCore
- TinkoffASDKUI/Tests (3.1.0):
- TinkoffASDKUI/Tests (3.1.1):
- TinkoffASDKCore
- TinkoffASDKYandexPay (3.1.0):
- TinkoffASDKYandexPay (3.1.1):
- TinkoffASDKCore
- TinkoffASDKUI
- YandexPaySDK/Dynamic (= 1.3.6)
- TinkoffASDKYandexPay/Tests (3.1.0):
- TinkoffASDKYandexPay/Tests (3.1.1):
- TinkoffASDKCore
- TinkoffASDKUI
- YandexPaySDK/Dynamic (= 1.3.6)
Expand Down Expand Up @@ -63,9 +63,9 @@ SPEC CHECKSUMS:
SwiftFormat: 2402d29b26746f169cce5454d5af88314cbb2e35
SwiftGen: 1366a7f71aeef49954ca5a63ba4bef6b0f24138c
SwiftLint: d41cc46a2ae58ac6d9f26954bc89f1d72e71fdef
TinkoffASDKCore: 3283eaa2fa450f1b199398b1aa7b381844d7eb16
TinkoffASDKUI: 36997b50d97676892a3adde811fe6d908e1d591a
TinkoffASDKYandexPay: eb97c35476780f351f502779c8331f19f76a5a54
TinkoffASDKCore: ca48fcef4a11f09d07f200c0046446e563fda205
TinkoffASDKUI: f2742afa9c4c5434aa11753b15b49e40b040873d
TinkoffASDKYandexPay: 3ed572f091842b8eceec981524dadc1ae21b478a
YandexLoginSDK: ad9a07aca36a7748353af17c9cbbf2b83be9ba26
YandexMobileMetrica: f5368ee93f286c793d73b58da00929babfc897c1
YandexPaySDK: 94cfd7f426b8fcdee6eda91e53d281da17489e28
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// FfdVersion.swift
// TinkoffASDKCore
//
// Created by Никита Васильев on 02.08.2023.
//
// swiftlint:disable identifier_name

import Foundation

public enum FfdVersion: String, Codable {
case version1_05 = "1.05"
case version1_2 = "1.2"
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,106 +4,22 @@
//
// Created by r.akhmadeev on 07.10.2022.
//
// swiftlint:disable identifier_name

import Foundation

/// Информация о чеке
public struct Receipt: Codable {
private enum CodingKeys: String, CodingKey {
case shopCode = "ShopCode"
case email = "Email"
case taxation = "Taxation"
case phone = "Phone"
case items = "Items"
case agentData = "AgentData"
case supplierInfo = "SupplierInfo"
case customer = "Customer"
case customerInn = "CustomerInn"
}

/// Код магазина
public var shopCode: String?
/// Электронный адрес для отправки чека покупателю
/// Параметр `email` или `phone` должен быть заполнен.
public var email: String?
/// Телефон покупателя
/// Параметр `email` или `phone` должен быть заполнен.
public var phone: String?
/// Система налогообложения
public var taxation: Taxation?
/// Массив, содержащий в себе информацию о товарах
public var items: [Item]?
/// Данные агента
public var agentData: AgentData?
/// Данные поставщика платежного агента
public var supplierInfo: SupplierInfo?
/// Идентификатор покупателя
public var customer: String?
/// Инн покупателя. Если ИНН иностранного гражданина, необходимо указать 00000000000
public var customerInn: String?

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
shopCode = try? container.decode(String.self, forKey: .shopCode)
email = try? container.decode(String.self, forKey: .email)
if let value = try? container.decode(String.self, forKey: .taxation) {
taxation = Taxation(rawValue: value)
}
phone = try? container.decode(String.self, forKey: .phone)
items = try? container.decode([Item].self, forKey: .items)
agentData = try? container.decode(AgentData.self, forKey: .agentData)
supplierInfo = try? container.decode(SupplierInfo.self, forKey: .supplierInfo)
customer = try? container.decode(String.self, forKey: .customer)
customerInn = try? container.decode(String.self, forKey: .customerInn)
}

public init(
shopCode: String?,
email: String?,
taxation: Taxation?,
phone: String?,
items: [Item]?,
agentData: AgentData?,
supplierInfo: SupplierInfo?,
customer: String?,
customerInn: String?
) {
self.shopCode = shopCode
self.email = email
self.taxation = taxation
self.phone = phone
self.items = items
self.agentData = agentData
self.supplierInfo = supplierInfo
self.customer = customer
self.customerInn = customerInn
}
public enum Receipt: Equatable, Encodable {
case version1_05(ReceiptFdv1_05)
case version1_2(ReceiptFdv1_2)

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if shopCode != nil { try? container.encode(shopCode, forKey: .shopCode) }
if taxation != nil { try? container.encode(taxation?.rawValue, forKey: .taxation) }
if email != nil { try? container.encode(email, forKey: .email) }
if phone != nil { try? container.encode(phone, forKey: .phone) }
if items != nil { try? container.encode(items, forKey: .items) }
if agentData != nil { try? container.encode(agentData, forKey: .agentData) }
if supplierInfo != nil { try? container.encode(supplierInfo, forKey: .supplierInfo) }
if customer != nil { try? container.encode(customer, forKey: .customer) }
if customerInn != nil { try? container.encode(customerInn, forKey: .customerInn) }
}
}
var container = encoder.singleValueContainer()

extension Receipt: Equatable {
public static func == (lhs: Receipt, rhs: Receipt) -> Bool {
return
lhs.shopCode == rhs.shopCode &&
lhs.email == rhs.email &&
lhs.phone == rhs.phone &&
lhs.taxation == rhs.taxation &&
lhs.items == rhs.items &&
lhs.agentData == rhs.agentData &&
lhs.supplierInfo == rhs.supplierInfo &&
lhs.customer == rhs.customer &&
lhs.customerInn == rhs.customerInn
switch self {
case let .version1_05(info):
try container.encode(info)
case let .version1_2(info):
try container.encode(info)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// ReceiptFdv1_05.swift
// TinkoffASDKCore
//
// Created by Никита Васильев on 02.08.2023.
//
// swiftlint:disable type_name

import Foundation

public struct ReceiptFdv1_05: Encodable {
private enum CodingKeys: String, CodingKey {
case shopCode = "ShopCode"
case items = "Items"
case ffdVersion = "FfdVersion"
case email = "Email"
case phone = "Phone"
case taxation = "Taxation"
case agentData = "AgentData"
case supplierInfo = "SupplierInfo"
}

/// Код магазина
public var shopCode: String?
/// Электронный адрес для отправки чека покупателю
/// Параметр `email` или `phone` должен быть заполнен.
public var email: String?
/// Телефон покупателя
/// Параметр `email` или `phone` должен быть заполнен.
public var phone: String?
/// Система налогообложения
public var taxation: Taxation
/// Массив, содержащий в себе информацию о товарах
public var items: [Item]
/// Данные агента
public var agentData: AgentData?
/// Данные поставщика платежного агента
public var supplierInfo: SupplierInfo?
/// Версия ФФД.
public let ffdVersion: FfdVersion = .version1_05

public init(
shopCode: String?,
email: String?,
taxation: Taxation,
phone: String?,
items: [Item],
agentData: AgentData?,
supplierInfo: SupplierInfo?
) {
self.shopCode = shopCode
self.email = email
self.taxation = taxation
self.phone = phone
self.items = items
self.agentData = agentData
self.supplierInfo = supplierInfo
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if shopCode != nil { try? container.encode(shopCode, forKey: .shopCode) }
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved
if email != nil { try? container.encode(email, forKey: .email) }
if phone != nil { try? container.encode(phone, forKey: .phone) }
if agentData != nil { try? container.encode(agentData, forKey: .agentData) }
if supplierInfo != nil { try? container.encode(supplierInfo, forKey: .supplierInfo) }
try? container.encode(ffdVersion, forKey: .ffdVersion)
try? container.encode(taxation.rawValue, forKey: .taxation)
try? container.encode(items, forKey: .items)
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved
}
}

extension ReceiptFdv1_05: Equatable {
public static func == (lhs: ReceiptFdv1_05, rhs: ReceiptFdv1_05) -> Bool {
lhs.shopCode == rhs.shopCode &&
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved
lhs.email == rhs.email &&
lhs.phone == rhs.phone &&
lhs.taxation == rhs.taxation &&
lhs.items == rhs.items &&
lhs.ffdVersion == rhs.ffdVersion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// ReceiptFdv1_2.swift
// TinkoffASDKCore
//
// Created by Никита Васильев on 02.08.2023.
//
// swiftlint:disable type_name

import Foundation

public struct ReceiptFdv1_2: Encodable {
private enum CodingKeys: String, CodingKey {
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved
case shopCode = "ShopCode"
case items = "Items"
case ffdVersion = "FfdVersion"
case email = "Email"
case phone = "Phone"
case taxation = "Taxation"
case agentData = "AgentData"
case supplierInfo = "SupplierInfo"
case customer = "Customer"
case customerInn = "CustomerInn"
}

public let base: ReceiptFdv1_05
public var customer: String?
/// Инн покупателя. Если ИНН иностранного гражданина, необходимо указать 00000000000
public var customerInn: String?
/// Версия ФФД.
public let ffdVersion: FfdVersion = .version1_2
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved

public init(base: ReceiptFdv1_05, customer: String?, customerInn: String?) {
self.base = base
self.customer = customer
self.customerInn = customerInn
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if base.shopCode != nil { try? container.encode(base.shopCode, forKey: .shopCode) }
if base.email != nil { try? container.encode(base.email, forKey: .email) }
if base.phone != nil { try? container.encode(base.phone, forKey: .phone) }
if base.agentData != nil { try? container.encode(base.agentData, forKey: .agentData) }
if base.supplierInfo != nil { try? container.encode(base.supplierInfo, forKey: .supplierInfo) }
if customer != nil { try? container.encode(customer, forKey: .customer) }
if customerInn != nil { try? container.encode(customerInn, forKey: .customerInn) }
try? container.encode(ffdVersion, forKey: .ffdVersion)
try? container.encode(base.taxation.rawValue, forKey: .taxation)
try? container.encode(base.items, forKey: .items)
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved
}
}

extension ReceiptFdv1_2: Equatable {
public static func == (lhs: ReceiptFdv1_2, rhs: ReceiptFdv1_2) -> Bool {
lhs.base == rhs.base &&
ivanglushko marked this conversation as resolved.
Show resolved Hide resolved
lhs.customer == rhs.customer &&
lhs.customerInn == rhs.customerInn &&
lhs.ffdVersion == rhs.ffdVersion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ extension PaymentFlow {

let receiptItems: [Item] = []

paymentData.receipt = Receipt(
shopCode: nil,
email: "email@email.com",
taxation: .osn,
phone: "+79876543210",
items: receiptItems,
agentData: nil,
supplierInfo: nil,
customer: nil,
customerInn: nil
paymentData.receipt = .version1_05(
ReceiptFdv1_05(
shopCode: nil,
email: "email@email.com",
taxation: .osn,
phone: "+79876543210",
items: receiptItems,
agentData: nil,
supplierInfo: nil
)
)

let paymentOptions = PaymentOptions.create(from: paymentData)
Expand Down
Loading