-
Notifications
You must be signed in to change notification settings - Fork 1
/
MenuItemModel.swift
110 lines (94 loc) · 3.13 KB
/
MenuItemModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// MenuItemModel.swift
//
// Created by N.A Shashank on 23/10/18.
//
import UIKit
import MobileCoreServices
enum PaymentType:String,Codable {
case fetchSubscription
case fetchPaymentMethods
case makePayment
case externalPaymentEntity
func isNativePayment() -> Bool {
return "\(self)".lowercased().contains("fetch") || "\(self)".lowercased().contains("make")
}
}
final class MenuItemModel:NSObject,NSItemProviderWriting,NSItemProviderReading,Codable {
let title:String
let userInfo:UserInfo
let paymentType:PaymentType
init(title:String,userInfo:UserInfo,paymentType:PaymentType = PaymentType.makePayment) {
self.title = title
self.userInfo = userInfo
self.paymentType = paymentType
}
static var writableTypeIdentifiersForItemProvider: [String]{
return [(kUTTypeData as String)]
}
static var readableTypeIdentifiersForItemProvider: [String]{
return [(kUTTypeData as String)]
}
func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping (Data?, Error?) -> Void) -> Progress? {
let progress = Progress(totalUnitCount: 100)
do {
let data = try JSONEncoder().encode(self)
progress.completedUnitCount = 100
completionHandler(data,nil)
}
catch {
completionHandler(nil,error)
}
return progress
}
static func object(withItemProviderData data: Data, typeIdentifier: String) throws -> MenuItemModel {
do {
let subject = try JSONDecoder().decode(MenuItemModel.self, from: data)
return subject
}
catch{
fatalError("\(error.localizedDescription)")
}
}
}
class UserInfo:Codable {
var strAmount:String?
var strCurrency:String?
var strEmail:String?
var strContact:String?
var strMethod:String?
var strCardName:String?
var strCardNumber:String?
var strCardExpiryMonth:String?
var strCardExpiryYear:String?
var strCardCVV:String?
var strEMIDuration:String?
var shouldDisplayLogo:Bool?
var strWallet:String?
var strBank:String?
var subscriptionID:String?
var accountID:String?
var upi:String?
enum CodingKeys:String,CodingKey {
case strAmount = "amount"
case strCurrency = "currency"
case strEmail = "email"
case strContact = "contact"
case strMethod = "method"
case strCardName = "card[name]"
case strCardNumber = "card[number]"
case strCardExpiryMonth = "card[expiry_month]"
case strCardExpiryYear = "card[expiry_year]"
case strCardCVV = "card[cvv]"
case strEMIDuration = "emi_duration"
case shouldDisplayLogo = "display_logo"
case strWallet = "wallet"
case strBank = "bank"
case subscriptionID = "subscription_id"
case accountID = "account_id"
case upi = "vpa"
}
func initializeWith<T>(keyPath:ReferenceWritableKeyPath<UserInfo,T>,value:T) {
self[keyPath:keyPath] = value
}
}