skipcash-reactnative 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/SkipcashReactnative.swift +266 -285
- package/package.json +1 -1
|
@@ -10,210 +10,13 @@ import CryptoKit
|
|
|
10
10
|
import CommonCrypto
|
|
11
11
|
import PassKit
|
|
12
12
|
import WebKit
|
|
13
|
+
import Network
|
|
14
|
+
import SystemConfiguration.CaptiveNetwork
|
|
13
15
|
|
|
14
|
-
public struct ResultObject: Codable {
|
|
15
|
-
public var isSuccess: Bool
|
|
16
|
-
var data: String
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public class ResponseData: NSObject, Codable {
|
|
20
|
-
public var transactionId: String?
|
|
21
|
-
public var paymentId: String?
|
|
22
|
-
public var resultObj: ResultObject
|
|
23
|
-
public var returnCode: Int
|
|
24
|
-
public var errorCode: Int
|
|
25
|
-
public var errorMessage: String?
|
|
26
|
-
public var error: String?
|
|
27
|
-
public var validationErrors: String?
|
|
28
|
-
public var hasError: Bool
|
|
29
|
-
public var hasValidationError: Bool
|
|
30
|
-
|
|
31
|
-
// Initializer
|
|
32
|
-
public init(transactionId: String?, paymentId: String?, resultObj: ResultObject, returnCode: Int, errorCode: Int, errorMessage: String?, error: String?, validationErrors: String?, hasError: Bool, hasValidationError: Bool) {
|
|
33
|
-
self.transactionId = transactionId
|
|
34
|
-
self.paymentId = paymentId
|
|
35
|
-
self.resultObj = resultObj
|
|
36
|
-
self.returnCode = returnCode
|
|
37
|
-
self.errorCode = errorCode
|
|
38
|
-
self.errorMessage = errorMessage
|
|
39
|
-
self.error = error
|
|
40
|
-
self.validationErrors = validationErrors
|
|
41
|
-
self.hasError = hasError
|
|
42
|
-
self.hasValidationError = hasValidationError
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
public func getResultObjIsSuccess() -> Bool {
|
|
47
|
-
return resultObj.isSuccess;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public func getPaymentId() -> String {
|
|
51
|
-
return paymentId ?? "No Payment ID";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public func getTransactionId() -> String {
|
|
55
|
-
return transactionId ?? "No Transaction ID";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public func getErrorMessage() -> String {
|
|
59
|
-
return errorMessage ?? "Nothing to show";
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@objc public protocol ApplePayReponseDelegate{
|
|
64
|
-
func applePayResponseData(transactionID: String, paymentID: String, isSuccess: Bool, token: String, returnCode: Int, errorMessage: String, completion: ((PKPaymentAuthorizationResult) -> Void)?)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public class SetupVC: UIViewController {
|
|
68
|
-
let production = "https://api.skipcash.app"
|
|
69
|
-
let sandboxUrl = "https://skipcashtest.azurewebsites.net"
|
|
70
|
-
let uat = "https://skipcash-uat-api.azurewebsites.net"
|
|
71
|
-
|
|
72
|
-
public var paymentToken: String = ""
|
|
73
|
-
public var paymentID: String = ""
|
|
74
|
-
public var transactionID: String = ""
|
|
75
|
-
public var delegate:ApplePayReponseDelegate?
|
|
76
|
-
public var completion: ((PKPaymentAuthorizationResult) -> Void)?
|
|
77
|
-
|
|
78
|
-
override public func viewDidLoad() {
|
|
79
|
-
self.callApplePay(paymentId: self.paymentID, applePaymentToken: self.paymentToken)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
func callApplePay(paymentId: String, applePaymentToken: String) {
|
|
83
|
-
|
|
84
|
-
let request = "{\"token\": {\"paymentData\":\(applePaymentToken)}}"
|
|
85
|
-
let postData = request.data(using: .utf8)
|
|
86
|
-
let url = URL(string: uat + "/api/v1/payments/apple/" + paymentId + "/pay-mc")!
|
|
87
|
-
var urlRequest = URLRequest(url: url)
|
|
88
|
-
urlRequest.httpMethod = "POST"
|
|
89
|
-
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
90
|
-
urlRequest.httpBody = postData
|
|
91
|
-
|
|
92
|
-
let task: URLSessionDataTask
|
|
93
|
-
|
|
94
|
-
task = URLSession.shared.dataTask(with: urlRequest) { data, response, error in
|
|
95
|
-
|
|
96
|
-
guard let data = data else {
|
|
97
|
-
debugPrint(data ?? "NO DATA RECEIVED")
|
|
98
|
-
let responseData = ResponseData(
|
|
99
|
-
transactionId: self.transactionID,
|
|
100
|
-
paymentId: self.paymentID,
|
|
101
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
102
|
-
returnCode: 400,
|
|
103
|
-
errorCode: 1001,
|
|
104
|
-
errorMessage: "Sample error message",
|
|
105
|
-
error: "No data received",
|
|
106
|
-
validationErrors: "Sample validation errors",
|
|
107
|
-
hasError: true,
|
|
108
|
-
hasValidationError: true
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
DispatchQueue.main.async{
|
|
112
|
-
self.dismiss(animated: true, completion: nil)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
116
|
-
self.delegate?.applePayResponseData(transactionID: self.transactionID, paymentID: self.paymentID, isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: self.completion)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if let text = String(data: data, encoding: .utf8) {
|
|
123
|
-
if let jsonData = text.data(using: .utf8) {
|
|
124
|
-
do {
|
|
125
|
-
let decoder = JSONDecoder()
|
|
126
|
-
var responseData = try decoder.decode(ResponseData.self, from: jsonData)
|
|
127
|
-
|
|
128
|
-
responseData.paymentId = paymentId
|
|
129
|
-
|
|
130
|
-
DispatchQueue.main.async{
|
|
131
|
-
self.dismiss(animated: true, completion: nil)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
135
|
-
self.delegate?.applePayResponseData(transactionID: self.transactionID, paymentID: self.paymentID, isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: self.completion)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
} catch {
|
|
139
|
-
let responseData = ResponseData(
|
|
140
|
-
transactionId: self.transactionID,
|
|
141
|
-
paymentId: self.paymentID,
|
|
142
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
143
|
-
returnCode: 400,
|
|
144
|
-
errorCode: 1001,
|
|
145
|
-
errorMessage: "Payment Failed!",
|
|
146
|
-
error: "\(error)",
|
|
147
|
-
validationErrors: "failed to decode json response for the payment",
|
|
148
|
-
hasError: true,
|
|
149
|
-
hasValidationError: true
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
DispatchQueue.main.async{
|
|
154
|
-
self.dismiss(animated: true, completion: nil)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
158
|
-
|
|
159
|
-
self.delegate?.applePayResponseData(transactionID: self.transactionID, paymentID: self.paymentID, isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: self.completion)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
let responseData = ResponseData(
|
|
167
|
-
transactionId: self.transactionID,
|
|
168
|
-
paymentId: self.paymentID,
|
|
169
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
170
|
-
returnCode: 400,
|
|
171
|
-
errorCode: 1001,
|
|
172
|
-
errorMessage: "Sample error message",
|
|
173
|
-
error: "Failed to convert JSON text to data",
|
|
174
|
-
validationErrors: "Sample validation errors",
|
|
175
|
-
hasError: true,
|
|
176
|
-
hasValidationError: true
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
DispatchQueue.main.async{
|
|
180
|
-
self.dismiss(animated: true, completion: nil)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
184
|
-
self.delegate?.applePayResponseData(transactionID: self.transactionID, paymentID: self.paymentID, isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: self.completion)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
let responseData = ResponseData(
|
|
190
|
-
transactionId: self.transactionID,
|
|
191
|
-
paymentId: self.paymentID,
|
|
192
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
193
|
-
returnCode: 400,
|
|
194
|
-
errorCode: 1001,
|
|
195
|
-
errorMessage: "Sample error message",
|
|
196
|
-
error: "Failed to decode data as UTF-8 string",
|
|
197
|
-
validationErrors: "Sample validation errors",
|
|
198
|
-
hasError: true,
|
|
199
|
-
hasValidationError: true
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
DispatchQueue.main.async{
|
|
203
|
-
self.dismiss(animated: true, completion: nil)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
207
|
-
self.delegate?.applePayResponseData(transactionID: self.transactionID, paymentID: self.paymentID, isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: self.completion)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
task.resume()
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
16
|
|
|
215
17
|
public class PaymentData: NSObject, Codable{
|
|
216
18
|
let merchantIdentifier: String
|
|
19
|
+
var token: String
|
|
217
20
|
let countryCode: String
|
|
218
21
|
let currencyCode: String
|
|
219
22
|
let createPaymentLinkEndPoint: String
|
|
@@ -240,8 +43,8 @@ public class PaymentData: NSObject, Codable{
|
|
|
240
43
|
let custom9: String
|
|
241
44
|
let custom10: String
|
|
242
45
|
|
|
243
|
-
let
|
|
244
|
-
let
|
|
46
|
+
let paymentDescription: String
|
|
47
|
+
let paymentSubject: String
|
|
245
48
|
let paymentModalTitle: String
|
|
246
49
|
|
|
247
50
|
let merchantName: String
|
|
@@ -249,6 +52,7 @@ public class PaymentData: NSObject, Codable{
|
|
|
249
52
|
init?(data: [String: Any]) {
|
|
250
53
|
guard
|
|
251
54
|
let merchantIdentifier = data["merchantIdentifier"] as? String,
|
|
55
|
+
var token = "" as? String,
|
|
252
56
|
let countryCode = data["countryCode"] as? String,
|
|
253
57
|
let currencyCode = data["currencyCode"] as? String,
|
|
254
58
|
let createPaymentLinkEndPoint = data["createPaymentLinkEndPoint"] as? String,
|
|
@@ -269,8 +73,8 @@ public class PaymentData: NSObject, Codable{
|
|
|
269
73
|
let custom5 = data["custom5"] as? String, let custom6 = data["custom6"] as? String,
|
|
270
74
|
let custom7 = data["custom7"] as? String, let custom8 = data["custom8"] as? String,
|
|
271
75
|
let custom9 = data["custom9"] as? String, let custom10 = data["custom10"] as? String,
|
|
272
|
-
let
|
|
273
|
-
let
|
|
76
|
+
let paymentDescription = data["description"] as? String,
|
|
77
|
+
let paymentSubject = data["subject"] as? String,
|
|
274
78
|
let paymentModalTitle = data["paymentModalTitle"] as? String,
|
|
275
79
|
|
|
276
80
|
let merchantName = data["merchantName"] as? String
|
|
@@ -279,6 +83,7 @@ public class PaymentData: NSObject, Codable{
|
|
|
279
83
|
}
|
|
280
84
|
|
|
281
85
|
self.merchantIdentifier = merchantIdentifier
|
|
86
|
+
self.token = token
|
|
282
87
|
self.countryCode = countryCode
|
|
283
88
|
self.currencyCode = currencyCode
|
|
284
89
|
self.createPaymentLinkEndPoint = createPaymentLinkEndPoint
|
|
@@ -304,18 +109,78 @@ public class PaymentData: NSObject, Codable{
|
|
|
304
109
|
self.custom9 = custom9
|
|
305
110
|
self.custom10 = custom10
|
|
306
111
|
|
|
307
|
-
self.
|
|
308
|
-
self.
|
|
112
|
+
self.paymentSubject = paymentSubject
|
|
113
|
+
self.paymentDescription = paymentDescription
|
|
309
114
|
self.paymentModalTitle = paymentModalTitle
|
|
310
115
|
|
|
311
116
|
self.merchantName = merchantName
|
|
312
117
|
}
|
|
118
|
+
|
|
119
|
+
func encodeToJSON() -> String? {
|
|
120
|
+
let encoder = JSONEncoder()
|
|
121
|
+
//encoder.keyEncodingStrategy = .convertToSnakeCase // Optional: Adjust key casing if needed
|
|
122
|
+
|
|
123
|
+
do {
|
|
124
|
+
let jsonData = try encoder.encode(self)
|
|
125
|
+
// Convert to a string if needed (for the body of the POST request)
|
|
126
|
+
let jsonString = String(data: jsonData, encoding: .utf8)
|
|
127
|
+
return jsonString
|
|
128
|
+
} catch {
|
|
129
|
+
print("Error encoding PaymentData to JSON: \(error)")
|
|
130
|
+
return nil
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public struct ResultObject: Codable {
|
|
136
|
+
public var isSuccess: Bool
|
|
137
|
+
var data: String
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public class ResponseData: NSObject, Codable {
|
|
141
|
+
public var transactionId: String?
|
|
142
|
+
public var resultObj: ResultObject
|
|
143
|
+
public var returnCode: Int
|
|
144
|
+
public var errorCode: Int
|
|
145
|
+
public var errorMessage: String?
|
|
146
|
+
public var error: String?
|
|
147
|
+
public var validationErrors: String?
|
|
148
|
+
public var hasError: Bool
|
|
149
|
+
public var hasValidationError: Bool
|
|
150
|
+
|
|
151
|
+
// Initializer
|
|
152
|
+
public init(transactionId: String?, resultObj: ResultObject, returnCode: Int, errorCode: Int, errorMessage: String?, error: String?, validationErrors: String?, hasError: Bool, hasValidationError: Bool) {
|
|
153
|
+
self.transactionId = transactionId
|
|
154
|
+
self.resultObj = resultObj
|
|
155
|
+
self.returnCode = returnCode
|
|
156
|
+
self.errorCode = errorCode
|
|
157
|
+
self.errorMessage = errorMessage
|
|
158
|
+
self.error = error
|
|
159
|
+
self.validationErrors = validationErrors
|
|
160
|
+
self.hasError = hasError
|
|
161
|
+
self.hasValidationError = hasValidationError
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
public func getResultObjIsSuccess() -> Bool {
|
|
166
|
+
return resultObj.isSuccess;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public func getTransactionId() -> String {
|
|
170
|
+
return transactionId ?? "No Transaction ID";
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public func getErrorMessage() -> String {
|
|
174
|
+
return errorMessage ?? "Nothing to show";
|
|
175
|
+
}
|
|
313
176
|
}
|
|
314
177
|
|
|
315
178
|
@objc(SkipcashReactnative)
|
|
316
|
-
class SkipcashReactnative: RCTEventEmitter
|
|
179
|
+
class SkipcashReactnative: RCTEventEmitter {
|
|
317
180
|
private var paymentID: String = ""
|
|
318
181
|
private var transactionID: String = ""
|
|
182
|
+
private var authorizationHeaderValue: String = ""
|
|
183
|
+
private var paymentData: PaymentData?
|
|
319
184
|
|
|
320
185
|
var webView: WKWebView!
|
|
321
186
|
var navigationController: UINavigationController?
|
|
@@ -328,10 +193,9 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
328
193
|
}
|
|
329
194
|
|
|
330
195
|
|
|
331
|
-
public func applePayResponseData(transactionID: String,
|
|
196
|
+
public func applePayResponseData(transactionID: String, isSuccess: Bool, token: String, returnCode: Int, errorMessage: String, completion: ((PKPaymentAuthorizationResult) -> Void)?) {
|
|
332
197
|
let responseData: [String: Any] = [
|
|
333
198
|
"transactionId": transactionID,
|
|
334
|
-
"paymentId": paymentID,
|
|
335
199
|
"isSuccess": isSuccess,
|
|
336
200
|
"token": token,
|
|
337
201
|
"returnCode": returnCode,
|
|
@@ -366,6 +230,135 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
366
230
|
.visa
|
|
367
231
|
]
|
|
368
232
|
|
|
233
|
+
func callApplePay(paymentData: PaymentData, applePaymentToken: String, completion: ((PKPaymentAuthorizationResult) -> Void)?) {
|
|
234
|
+
|
|
235
|
+
guard let request = paymentData.encodeToJSON() else {
|
|
236
|
+
let responseData = ResponseData(
|
|
237
|
+
transactionId: paymentData.transactionId,
|
|
238
|
+
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
239
|
+
returnCode: 400,
|
|
240
|
+
errorCode: 1001,
|
|
241
|
+
errorMessage: "Couldn't convert payment request data",
|
|
242
|
+
error: "Couldn't convert payment request data",
|
|
243
|
+
validationErrors: "Couldn't convert payment request data",
|
|
244
|
+
hasError: true,
|
|
245
|
+
hasValidationError: true
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
249
|
+
self.applePayResponseData(transactionID: responseData.getTransactionId(), isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: completion)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let postData = request.data(using: .utf8)
|
|
256
|
+
let url = URL(string: paymentData.createPaymentLinkEndPoint)!
|
|
257
|
+
var urlRequest = URLRequest(url: url)
|
|
258
|
+
urlRequest.httpMethod = "POST"
|
|
259
|
+
|
|
260
|
+
if self.authorizationHeaderValue.count > 0 {
|
|
261
|
+
urlRequest.addValue(self.authorizationHeaderValue, forHTTPHeaderField: "Authorization")
|
|
262
|
+
}
|
|
263
|
+
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
264
|
+
urlRequest.httpBody = postData
|
|
265
|
+
|
|
266
|
+
let task: URLSessionDataTask
|
|
267
|
+
|
|
268
|
+
task = URLSession.shared.dataTask(with: urlRequest) { data, response, error in
|
|
269
|
+
|
|
270
|
+
guard let data = data else {
|
|
271
|
+
let responseData = ResponseData(
|
|
272
|
+
transactionId: paymentData.transactionId,
|
|
273
|
+
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
274
|
+
returnCode: 400,
|
|
275
|
+
errorCode: 1001,
|
|
276
|
+
errorMessage: "NO DATA RECEIVED",
|
|
277
|
+
error: "No data received",
|
|
278
|
+
validationErrors: "NO DATA RECEIVED",
|
|
279
|
+
hasError: true,
|
|
280
|
+
hasValidationError: true
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
285
|
+
self.applePayResponseData(transactionID: responseData.getTransactionId(), isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: completion)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if let text = String(data: data, encoding: .utf8) {
|
|
292
|
+
if let jsonData = text.data(using: .utf8) {
|
|
293
|
+
do {
|
|
294
|
+
let decoder = JSONDecoder()
|
|
295
|
+
|
|
296
|
+
var responseData = try decoder.decode(ResponseData.self, from: jsonData)
|
|
297
|
+
|
|
298
|
+
responseData.transactionId = paymentData.transactionId
|
|
299
|
+
|
|
300
|
+
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
301
|
+
// self.delegate?.
|
|
302
|
+
self.applePayResponseData(
|
|
303
|
+
transactionID: responseData.getTransactionId(), isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: completion)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
} catch {
|
|
307
|
+
let responseData = ResponseData(
|
|
308
|
+
transactionId: paymentData.transactionId,
|
|
309
|
+
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
310
|
+
returnCode: 400,
|
|
311
|
+
errorCode: 1001,
|
|
312
|
+
errorMessage: "failed to decode json response for the payment!",
|
|
313
|
+
error: "\(error)",
|
|
314
|
+
validationErrors: "failed to decode json response for the payment",
|
|
315
|
+
hasError: true,
|
|
316
|
+
hasValidationError: true
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
320
|
+
self.applePayResponseData(transactionID: responseData.getTransactionId(), isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: completion)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
let responseData = ResponseData(
|
|
326
|
+
transactionId: paymentData.transactionId,
|
|
327
|
+
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
328
|
+
returnCode: 400,
|
|
329
|
+
errorCode: 1001,
|
|
330
|
+
errorMessage: "Failed to convert JSON text to data",
|
|
331
|
+
error: "Failed to convert JSON text to data",
|
|
332
|
+
validationErrors: "Failed to convert JSON text to data",
|
|
333
|
+
hasError: true,
|
|
334
|
+
hasValidationError: true
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
338
|
+
self.applePayResponseData(transactionID: responseData.getTransactionId(), isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: completion)
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
let responseData = ResponseData(
|
|
343
|
+
transactionId: paymentData.transactionId,
|
|
344
|
+
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
345
|
+
returnCode: 400,
|
|
346
|
+
errorCode: 1001,
|
|
347
|
+
errorMessage: "Failed to decode data as UTF-8 string",
|
|
348
|
+
error: "Failed to decode data as UTF-8 string",
|
|
349
|
+
validationErrors: "Failed to decode data as UTF-8 string",
|
|
350
|
+
hasError: true,
|
|
351
|
+
hasValidationError: true
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
355
|
+
self.applePayResponseData(transactionID: responseData.getTransactionId(), isSuccess: responseData.resultObj.isSuccess, token: responseData.resultObj.data, returnCode: responseData.returnCode, errorMessage: responseData.getErrorMessage(), completion: completion)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
task.resume()
|
|
360
|
+
}
|
|
361
|
+
|
|
369
362
|
@objc(isWalletHasCards:rejecter:)
|
|
370
363
|
func isWalletHasCards (resolve:RCTPromiseResolveBlock,rejecter:RCTPromiseRejectBlock) -> Void {
|
|
371
364
|
let result = SkipcashReactnative.applePayStatus();
|
|
@@ -401,29 +394,29 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
401
394
|
|
|
402
395
|
var convertedData: [String: Any] = [:]
|
|
403
396
|
|
|
404
|
-
convertedData["
|
|
405
|
-
convertedData["
|
|
406
|
-
convertedData["
|
|
407
|
-
convertedData["
|
|
408
|
-
convertedData["
|
|
397
|
+
convertedData["amount"] = data.amount
|
|
398
|
+
convertedData["firstName"] = data.firstName
|
|
399
|
+
convertedData["lastName"] = data.lastName
|
|
400
|
+
convertedData["phone"] = data.phone
|
|
401
|
+
convertedData["email"] = data.email
|
|
409
402
|
|
|
410
|
-
convertedData["
|
|
411
|
-
convertedData["
|
|
412
|
-
convertedData["
|
|
403
|
+
convertedData["returnUrl"] = returnURL
|
|
404
|
+
convertedData["transactionId"] = data.transactionId
|
|
405
|
+
convertedData["webhookUrl"] = data.webhookUrl
|
|
413
406
|
|
|
414
|
-
convertedData["
|
|
415
|
-
convertedData["
|
|
416
|
-
convertedData["
|
|
417
|
-
convertedData["
|
|
418
|
-
convertedData["
|
|
419
|
-
convertedData["
|
|
420
|
-
convertedData["
|
|
421
|
-
convertedData["
|
|
422
|
-
convertedData["
|
|
423
|
-
convertedData["
|
|
407
|
+
convertedData["custom1"] = data.custom1
|
|
408
|
+
convertedData["custom2"] = data.custom2
|
|
409
|
+
convertedData["custom3"] = data.custom3
|
|
410
|
+
convertedData["custom4"] = data.custom4
|
|
411
|
+
convertedData["custom5"] = data.custom5
|
|
412
|
+
convertedData["custom6"] = data.custom6
|
|
413
|
+
convertedData["custom7"] = data.custom7
|
|
414
|
+
convertedData["custom8"] = data.custom8
|
|
415
|
+
convertedData["custom9"] = data.custom9
|
|
416
|
+
convertedData["custom10"] = data.custom10
|
|
424
417
|
|
|
425
|
-
convertedData["
|
|
426
|
-
convertedData["
|
|
418
|
+
convertedData["description"] = data.paymentDescription
|
|
419
|
+
convertedData["subject"] = data.paymentSubject
|
|
427
420
|
|
|
428
421
|
|
|
429
422
|
guard let jsonData = try? JSONSerialization.data(withJSONObject: convertedData) else {
|
|
@@ -495,7 +488,6 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
495
488
|
debugPrint("Error: \(error.localizedDescription) - endpoint response")
|
|
496
489
|
let responseData: [String: Any] = [
|
|
497
490
|
"transactionId": self.transactionID,
|
|
498
|
-
"paymentId": self.paymentID,
|
|
499
491
|
"isSuccess": false,
|
|
500
492
|
"token": "",
|
|
501
493
|
"returnCode": 400,
|
|
@@ -518,37 +510,24 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
518
510
|
// Convert JSON data to a dictionary
|
|
519
511
|
if let paymentDictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
|
|
520
512
|
if let paymentData = PaymentData(data: paymentDictionary) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
513
|
+
self.startPayment(data: paymentData, authorizationHeader: paymentData.authorizationHeader) { success in
|
|
514
|
+
if success {} else {
|
|
515
|
+
let responseData: [String: Any] = [
|
|
516
|
+
"transactionId": self.transactionID,
|
|
517
|
+
"isSuccess": false,
|
|
518
|
+
"token": "",
|
|
519
|
+
"returnCode": 400,
|
|
520
|
+
"errorMessage": "Payment failed!"
|
|
521
|
+
]
|
|
522
|
+
|
|
523
|
+
self.sendEvent(withName: "applepay_response", body: responseData)
|
|
527
524
|
return
|
|
528
525
|
}
|
|
529
|
-
|
|
530
|
-
self.startPayment(data: paymentData, paymentID: paymentID) { success in
|
|
531
|
-
if success {} else {
|
|
532
|
-
let responseData: [String: Any] = [
|
|
533
|
-
"transactionId": self.transactionID,
|
|
534
|
-
"paymentId": self.paymentID,
|
|
535
|
-
"isSuccess": false,
|
|
536
|
-
"token": "",
|
|
537
|
-
"returnCode": 400,
|
|
538
|
-
"errorMessage": "Payment failed!"
|
|
539
|
-
]
|
|
540
|
-
|
|
541
|
-
self.sendEvent(withName: "applepay_response", body: responseData)
|
|
542
|
-
return
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
526
|
}
|
|
547
527
|
} else {
|
|
548
528
|
debugPrint("Unable to convert jsonData(cross-platform passed data) to paymentDictionary")
|
|
549
529
|
let responseData: [String: Any] = [
|
|
550
530
|
"transactionId": self.transactionID,
|
|
551
|
-
"paymentId": self.paymentID,
|
|
552
531
|
"isSuccess": false,
|
|
553
532
|
"token": "",
|
|
554
533
|
"returnCode": 400,
|
|
@@ -562,7 +541,6 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
562
541
|
debugPrint("Error: Unable to convert JSON string to data")
|
|
563
542
|
let responseData: [String: Any] = [
|
|
564
543
|
"transactionId": self.transactionID,
|
|
565
|
-
"paymentId": self.paymentID,
|
|
566
544
|
"isSuccess": false,
|
|
567
545
|
"token": "",
|
|
568
546
|
"returnCode": 400,
|
|
@@ -575,7 +553,6 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
575
553
|
debugPrint("Error: \(error)")
|
|
576
554
|
let responseData: [String: Any] = [
|
|
577
555
|
"transactionId": self.transactionID,
|
|
578
|
-
"paymentId": self.paymentID,
|
|
579
556
|
"isSuccess": false,
|
|
580
557
|
"token": "",
|
|
581
558
|
"returnCode": 400,
|
|
@@ -602,11 +579,14 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
602
579
|
// }
|
|
603
580
|
}
|
|
604
581
|
|
|
605
|
-
func startPayment(data: PaymentData,
|
|
582
|
+
func startPayment(data: PaymentData, authorizationHeader: String, completion: @escaping PaymentCompletionHandler) {
|
|
606
583
|
|
|
607
|
-
completionHandler
|
|
608
|
-
self.
|
|
584
|
+
completionHandler = completion
|
|
585
|
+
self.transactionID = data.transactionId
|
|
586
|
+
self.authorizationHeaderValue = authorizationHeader
|
|
587
|
+
self.paymentData = data
|
|
609
588
|
|
|
589
|
+
// self.paymentID = paymentID
|
|
610
590
|
|
|
611
591
|
var paymentSummaryItems = [PKPaymentSummaryItem]()
|
|
612
592
|
|
|
@@ -659,19 +639,18 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
659
639
|
if let paymentDictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
|
|
660
640
|
if let paymentData = PaymentData(data: paymentDictionary) {
|
|
661
641
|
self.getPaymentID(authorizationHeader: paymentData.authorizationHeader, data: paymentData, createPaymentApi: paymentData.createPaymentLinkEndPoint, returnURL: paymentData.returnUrl) { result in
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
642
|
+
if let result = result {
|
|
643
|
+
let paymentID = result["paymentID"] as? String ?? ""
|
|
644
|
+
let payUrl = result["payUrl"] as? String ?? ""
|
|
645
|
+
let transactionID = result["transactionId"] as? String ?? ""
|
|
646
|
+
|
|
647
|
+
if(paymentID.count == 0){
|
|
648
|
+
debugPrint("new payment request failed!")
|
|
649
|
+
return
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
self.showPaymentModal(url: payUrl, paymentTitle: paymentData.paymentModalTitle, returnURL: paymentData.returnUrl, paymentId: paymentID, transactionId: transactionID)
|
|
653
|
+
}
|
|
675
654
|
}
|
|
676
655
|
} else {
|
|
677
656
|
debugPrint("Unable to convert jsonData(cross-platform passed data) to paymentDictionary")
|
|
@@ -755,20 +734,22 @@ extension SkipcashReactnative: PKPaymentAuthorizationControllerDelegate {
|
|
|
755
734
|
return
|
|
756
735
|
}
|
|
757
736
|
|
|
737
|
+
paymentData?.token = token
|
|
738
|
+
self.callApplePay(paymentData: self.paymentData!, applePaymentToken: token, completion: completion)
|
|
758
739
|
//
|
|
759
|
-
let vc = SetupVC()
|
|
760
|
-
|
|
761
|
-
vc.modalPresentationStyle = .overCurrentContext
|
|
762
|
-
vc.delegate = self
|
|
763
|
-
vc.transactionID = self.transactionID
|
|
764
|
-
vc.paymentID = self.paymentID
|
|
765
|
-
vc.completion = completion
|
|
766
|
-
vc.paymentToken = token
|
|
767
|
-
|
|
768
|
-
if let topViewController = UIApplication.shared.keyWindow?.rootViewController?.topMostViewController() {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
}
|
|
740
|
+
// let vc = SetupVC()
|
|
741
|
+
|
|
742
|
+
// vc.modalPresentationStyle = .overCurrentContext
|
|
743
|
+
// vc.delegate = self
|
|
744
|
+
// vc.transactionID = self.transactionID
|
|
745
|
+
// vc.paymentID = self.paymentID
|
|
746
|
+
// vc.completion = completion
|
|
747
|
+
// vc.paymentToken = token
|
|
748
|
+
|
|
749
|
+
// if let topViewController = UIApplication.shared.keyWindow?.rootViewController?.topMostViewController() {
|
|
750
|
+
// topViewController.modalPresentationStyle = .overCurrentContext
|
|
751
|
+
// topViewController.present(vc, animated: true, completion: nil)
|
|
752
|
+
// }
|
|
772
753
|
}
|
|
773
754
|
|
|
774
755
|
public func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
|