Skip to content

Commit

Permalink
[EACQAPW-5763]: Реализовал передачу параметров для фискализации (#503)
Browse files Browse the repository at this point in the history
* EACQAPW-5765. Implement passing `ffdVersion` into `v2/Init` request

* EACQAPW-5765. Delete useless init

* EACQAPW-5765. Update `Receipt` model

* EACQAPW-5765. Update properties

* EACQAPW-5763. Delete useless comment

* EACQAPW-5763. Update `CHANGELOG.md`

* EACQAPW-5763. Fixes after code review

* EACQAPW-5763. Fixes after code review
  • Loading branch information
nik3212 authored Aug 3, 2023
1 parent 86bc068 commit 0726458
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 125 deletions.
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
* [EACQAPW-5258] RunLoop run caused bugy getState handles
* [EACQAPW-5288] TPay Controller handle DEADLINE_EXPIRED
* [EACQAPW-5297] Fix broken pdfs

* [EACQAPW-5763] Add ffdVersion param

## [3.0.0] - 2023-05-12Z

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// FfdVersion.swift
// TinkoffASDKCore
//
// Created by Никита Васильев on 02.08.2023.
//
// swiftlint:disable identifier_name

import Foundation

public enum FfdVersion: String, Codable {
/// По умолчанию версия ФФД - 1.05
case version1_05 = "1.05"
case version1_2 = "1.2"
}
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,71 @@
//
// ReceiptFdv1_05.swift
// TinkoffASDKCore
//
// Created by Никита Васильев on 02.08.2023.
//
// swiftlint:disable type_name

import Foundation

public struct ReceiptFdv1_05: Encodable, Equatable {
/// Код магазина
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

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 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)
try container.encodeIfPresent(shopCode, forKey: .shopCode)
try container.encodeIfPresent(email, forKey: .email)
try container.encodeIfPresent(phone, forKey: .phone)
try container.encodeIfPresent(agentData, forKey: .agentData)
try container.encodeIfPresent(supplierInfo, forKey: .supplierInfo)
try container.encode(ffdVersion, forKey: .ffdVersion)
try container.encode(taxation.rawValue, forKey: .taxation)
try container.encode(items, forKey: .items)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// ReceiptFdv1_2.swift
// TinkoffASDKCore
//
// Created by Никита Васильев on 02.08.2023.
//
// swiftlint:disable type_name

import Foundation

public struct ReceiptFdv1_2: Encodable, Equatable {

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

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"
case customer = "Customer"
case customerInn = "CustomerInn"
}

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)
try container.encodeIfPresent(base.shopCode, forKey: .shopCode)
try container.encodeIfPresent(base.email, forKey: .email)
try container.encodeIfPresent(base.phone, forKey: .phone)
try container.encodeIfPresent(base.agentData, forKey: .agentData)
try container.encodeIfPresent(base.supplierInfo, forKey: .supplierInfo)
try container.encodeIfPresent(customer, forKey: .customer)
try container.encodeIfPresent(customerInn, forKey: .customerInn)
try container.encode(ffdVersion, forKey: .ffdVersion)
try container.encode(base.taxation.rawValue, forKey: .taxation)
try container.encode(base.items, forKey: .items)
}
}
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

0 comments on commit 0726458

Please sign in to comment.