skipcash-reactnative 0.0.5 → 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 +264 -287
- package/package.json +1 -1
|
@@ -14,210 +14,9 @@ import Network
|
|
|
14
14
|
import SystemConfiguration.CaptiveNetwork
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
public struct ResultObject: Codable {
|
|
19
|
-
public var isSuccess: Bool
|
|
20
|
-
var data: String
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public class ResponseData: NSObject, Codable {
|
|
24
|
-
public var transactionId: String?
|
|
25
|
-
public var paymentId: String?
|
|
26
|
-
public var resultObj: ResultObject
|
|
27
|
-
public var returnCode: Int
|
|
28
|
-
public var errorCode: Int
|
|
29
|
-
public var errorMessage: String?
|
|
30
|
-
public var error: String?
|
|
31
|
-
public var validationErrors: String?
|
|
32
|
-
public var hasError: Bool
|
|
33
|
-
public var hasValidationError: Bool
|
|
34
|
-
|
|
35
|
-
// Initializer
|
|
36
|
-
public init(transactionId: String?, paymentId: String?, resultObj: ResultObject, returnCode: Int, errorCode: Int, errorMessage: String?, error: String?, validationErrors: String?, hasError: Bool, hasValidationError: Bool) {
|
|
37
|
-
self.transactionId = transactionId
|
|
38
|
-
self.paymentId = paymentId
|
|
39
|
-
self.resultObj = resultObj
|
|
40
|
-
self.returnCode = returnCode
|
|
41
|
-
self.errorCode = errorCode
|
|
42
|
-
self.errorMessage = errorMessage
|
|
43
|
-
self.error = error
|
|
44
|
-
self.validationErrors = validationErrors
|
|
45
|
-
self.hasError = hasError
|
|
46
|
-
self.hasValidationError = hasValidationError
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
public func getResultObjIsSuccess() -> Bool {
|
|
51
|
-
return resultObj.isSuccess;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public func getPaymentId() -> String {
|
|
55
|
-
return paymentId ?? "No Payment ID";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public func getTransactionId() -> String {
|
|
59
|
-
return transactionId ?? "No Transaction ID";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public func getErrorMessage() -> String {
|
|
63
|
-
return errorMessage ?? "Nothing to show";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@objc public protocol ApplePayReponseDelegate{
|
|
68
|
-
func applePayResponseData(transactionID: String, paymentID: String, isSuccess: Bool, token: String, returnCode: Int, errorMessage: String, completion: ((PKPaymentAuthorizationResult) -> Void)?)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public class SetupVC: UIViewController {
|
|
72
|
-
let production = "https://api.skipcash.app"
|
|
73
|
-
let sandboxUrl = "https://skipcashtest.azurewebsites.net"
|
|
74
|
-
let uat = "https://skipcash-uat-api.azurewebsites.net"
|
|
75
|
-
|
|
76
|
-
public var paymentToken: String = ""
|
|
77
|
-
public var paymentID: String = ""
|
|
78
|
-
public var transactionID: String = ""
|
|
79
|
-
public var delegate:ApplePayReponseDelegate?
|
|
80
|
-
public var completion: ((PKPaymentAuthorizationResult) -> Void)?
|
|
81
|
-
|
|
82
|
-
override public func viewDidLoad() {
|
|
83
|
-
self.callApplePay(paymentId: self.paymentID, applePaymentToken: self.paymentToken)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
func callApplePay(paymentId: String, applePaymentToken: String) {
|
|
87
|
-
let request = "{\"token\": {\"paymentData\":\(applePaymentToken)}, \"ip\": \"178.152.136.90\"}"
|
|
88
|
-
// let request = "{\"token\": {\"paymentData\":\(applePaymentToken)}, \"ip\": ""}"
|
|
89
|
-
let postData = request.data(using: .utf8)
|
|
90
|
-
let url = URL(string: production + "/api/v1/payments/apple/" + paymentId + "/pay-mc")!
|
|
91
|
-
var urlRequest = URLRequest(url: url)
|
|
92
|
-
urlRequest.httpMethod = "POST"
|
|
93
|
-
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
94
|
-
urlRequest.httpBody = postData
|
|
95
|
-
|
|
96
|
-
let task: URLSessionDataTask
|
|
97
|
-
|
|
98
|
-
task = URLSession.shared.dataTask(with: urlRequest) { data, response, error in
|
|
99
|
-
|
|
100
|
-
guard let data = data else {
|
|
101
|
-
debugPrint(data ?? "NO DATA RECEIVED")
|
|
102
|
-
let responseData = ResponseData(
|
|
103
|
-
transactionId: self.transactionID,
|
|
104
|
-
paymentId: self.paymentID,
|
|
105
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
106
|
-
returnCode: 400,
|
|
107
|
-
errorCode: 1001,
|
|
108
|
-
errorMessage: "Sample error message",
|
|
109
|
-
error: "No data received",
|
|
110
|
-
validationErrors: "Sample validation errors",
|
|
111
|
-
hasError: true,
|
|
112
|
-
hasValidationError: true
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
DispatchQueue.main.async{
|
|
116
|
-
self.dismiss(animated: true, completion: nil)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
120
|
-
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)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if let text = String(data: data, encoding: .utf8) {
|
|
127
|
-
if let jsonData = text.data(using: .utf8) {
|
|
128
|
-
do {
|
|
129
|
-
let decoder = JSONDecoder()
|
|
130
|
-
var responseData = try decoder.decode(ResponseData.self, from: jsonData)
|
|
131
|
-
|
|
132
|
-
responseData.paymentId = paymentId
|
|
133
|
-
|
|
134
|
-
DispatchQueue.main.async{
|
|
135
|
-
self.dismiss(animated: true, completion: nil)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
139
|
-
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)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
} catch {
|
|
143
|
-
let responseData = ResponseData(
|
|
144
|
-
transactionId: self.transactionID,
|
|
145
|
-
paymentId: self.paymentID,
|
|
146
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
147
|
-
returnCode: 400,
|
|
148
|
-
errorCode: 1001,
|
|
149
|
-
errorMessage: "Payment Failed!",
|
|
150
|
-
error: "\(error)",
|
|
151
|
-
validationErrors: "failed to decode json response for the payment",
|
|
152
|
-
hasError: true,
|
|
153
|
-
hasValidationError: true
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
DispatchQueue.main.async{
|
|
158
|
-
self.dismiss(animated: true, completion: nil)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
162
|
-
|
|
163
|
-
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)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
let responseData = ResponseData(
|
|
171
|
-
transactionId: self.transactionID,
|
|
172
|
-
paymentId: self.paymentID,
|
|
173
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
174
|
-
returnCode: 400,
|
|
175
|
-
errorCode: 1001,
|
|
176
|
-
errorMessage: "Sample error message",
|
|
177
|
-
error: "Failed to convert JSON text to data",
|
|
178
|
-
validationErrors: "Sample validation errors",
|
|
179
|
-
hasError: true,
|
|
180
|
-
hasValidationError: true
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
DispatchQueue.main.async{
|
|
184
|
-
self.dismiss(animated: true, completion: nil)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
188
|
-
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)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
let responseData = ResponseData(
|
|
194
|
-
transactionId: self.transactionID,
|
|
195
|
-
paymentId: self.paymentID,
|
|
196
|
-
resultObj: ResultObject(isSuccess: false, data: "\(applePaymentToken)"),
|
|
197
|
-
returnCode: 400,
|
|
198
|
-
errorCode: 1001,
|
|
199
|
-
errorMessage: "Sample error message",
|
|
200
|
-
error: "Failed to decode data as UTF-8 string",
|
|
201
|
-
validationErrors: "Sample validation errors",
|
|
202
|
-
hasError: true,
|
|
203
|
-
hasValidationError: true
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
DispatchQueue.main.async{
|
|
207
|
-
self.dismiss(animated: true, completion: nil)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
DispatchQueue.main.asyncAfter(deadline: .now()){
|
|
211
|
-
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)
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
task.resume()
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
17
|
public class PaymentData: NSObject, Codable{
|
|
220
18
|
let merchantIdentifier: String
|
|
19
|
+
var token: String
|
|
221
20
|
let countryCode: String
|
|
222
21
|
let currencyCode: String
|
|
223
22
|
let createPaymentLinkEndPoint: String
|
|
@@ -244,8 +43,8 @@ public class PaymentData: NSObject, Codable{
|
|
|
244
43
|
let custom9: String
|
|
245
44
|
let custom10: String
|
|
246
45
|
|
|
247
|
-
let
|
|
248
|
-
let
|
|
46
|
+
let paymentDescription: String
|
|
47
|
+
let paymentSubject: String
|
|
249
48
|
let paymentModalTitle: String
|
|
250
49
|
|
|
251
50
|
let merchantName: String
|
|
@@ -253,6 +52,7 @@ public class PaymentData: NSObject, Codable{
|
|
|
253
52
|
init?(data: [String: Any]) {
|
|
254
53
|
guard
|
|
255
54
|
let merchantIdentifier = data["merchantIdentifier"] as? String,
|
|
55
|
+
var token = "" as? String,
|
|
256
56
|
let countryCode = data["countryCode"] as? String,
|
|
257
57
|
let currencyCode = data["currencyCode"] as? String,
|
|
258
58
|
let createPaymentLinkEndPoint = data["createPaymentLinkEndPoint"] as? String,
|
|
@@ -273,8 +73,8 @@ public class PaymentData: NSObject, Codable{
|
|
|
273
73
|
let custom5 = data["custom5"] as? String, let custom6 = data["custom6"] as? String,
|
|
274
74
|
let custom7 = data["custom7"] as? String, let custom8 = data["custom8"] as? String,
|
|
275
75
|
let custom9 = data["custom9"] as? String, let custom10 = data["custom10"] as? String,
|
|
276
|
-
let
|
|
277
|
-
let
|
|
76
|
+
let paymentDescription = data["description"] as? String,
|
|
77
|
+
let paymentSubject = data["subject"] as? String,
|
|
278
78
|
let paymentModalTitle = data["paymentModalTitle"] as? String,
|
|
279
79
|
|
|
280
80
|
let merchantName = data["merchantName"] as? String
|
|
@@ -283,6 +83,7 @@ public class PaymentData: NSObject, Codable{
|
|
|
283
83
|
}
|
|
284
84
|
|
|
285
85
|
self.merchantIdentifier = merchantIdentifier
|
|
86
|
+
self.token = token
|
|
286
87
|
self.countryCode = countryCode
|
|
287
88
|
self.currencyCode = currencyCode
|
|
288
89
|
self.createPaymentLinkEndPoint = createPaymentLinkEndPoint
|
|
@@ -308,18 +109,78 @@ public class PaymentData: NSObject, Codable{
|
|
|
308
109
|
self.custom9 = custom9
|
|
309
110
|
self.custom10 = custom10
|
|
310
111
|
|
|
311
|
-
self.
|
|
312
|
-
self.
|
|
112
|
+
self.paymentSubject = paymentSubject
|
|
113
|
+
self.paymentDescription = paymentDescription
|
|
313
114
|
self.paymentModalTitle = paymentModalTitle
|
|
314
115
|
|
|
315
116
|
self.merchantName = merchantName
|
|
316
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
|
+
}
|
|
317
176
|
}
|
|
318
177
|
|
|
319
178
|
@objc(SkipcashReactnative)
|
|
320
|
-
class SkipcashReactnative: RCTEventEmitter
|
|
179
|
+
class SkipcashReactnative: RCTEventEmitter {
|
|
321
180
|
private var paymentID: String = ""
|
|
322
181
|
private var transactionID: String = ""
|
|
182
|
+
private var authorizationHeaderValue: String = ""
|
|
183
|
+
private var paymentData: PaymentData?
|
|
323
184
|
|
|
324
185
|
var webView: WKWebView!
|
|
325
186
|
var navigationController: UINavigationController?
|
|
@@ -332,10 +193,9 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
332
193
|
}
|
|
333
194
|
|
|
334
195
|
|
|
335
|
-
public func applePayResponseData(transactionID: String,
|
|
196
|
+
public func applePayResponseData(transactionID: String, isSuccess: Bool, token: String, returnCode: Int, errorMessage: String, completion: ((PKPaymentAuthorizationResult) -> Void)?) {
|
|
336
197
|
let responseData: [String: Any] = [
|
|
337
198
|
"transactionId": transactionID,
|
|
338
|
-
"paymentId": paymentID,
|
|
339
199
|
"isSuccess": isSuccess,
|
|
340
200
|
"token": token,
|
|
341
201
|
"returnCode": returnCode,
|
|
@@ -370,6 +230,135 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
370
230
|
.visa
|
|
371
231
|
]
|
|
372
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
|
+
|
|
373
362
|
@objc(isWalletHasCards:rejecter:)
|
|
374
363
|
func isWalletHasCards (resolve:RCTPromiseResolveBlock,rejecter:RCTPromiseRejectBlock) -> Void {
|
|
375
364
|
let result = SkipcashReactnative.applePayStatus();
|
|
@@ -405,29 +394,29 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
405
394
|
|
|
406
395
|
var convertedData: [String: Any] = [:]
|
|
407
396
|
|
|
408
|
-
convertedData["
|
|
409
|
-
convertedData["
|
|
410
|
-
convertedData["
|
|
411
|
-
convertedData["
|
|
412
|
-
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
|
|
413
402
|
|
|
414
|
-
convertedData["
|
|
415
|
-
convertedData["
|
|
416
|
-
convertedData["
|
|
403
|
+
convertedData["returnUrl"] = returnURL
|
|
404
|
+
convertedData["transactionId"] = data.transactionId
|
|
405
|
+
convertedData["webhookUrl"] = data.webhookUrl
|
|
417
406
|
|
|
418
|
-
convertedData["
|
|
419
|
-
convertedData["
|
|
420
|
-
convertedData["
|
|
421
|
-
convertedData["
|
|
422
|
-
convertedData["
|
|
423
|
-
convertedData["
|
|
424
|
-
convertedData["
|
|
425
|
-
convertedData["
|
|
426
|
-
convertedData["
|
|
427
|
-
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
|
|
428
417
|
|
|
429
|
-
convertedData["
|
|
430
|
-
convertedData["
|
|
418
|
+
convertedData["description"] = data.paymentDescription
|
|
419
|
+
convertedData["subject"] = data.paymentSubject
|
|
431
420
|
|
|
432
421
|
|
|
433
422
|
guard let jsonData = try? JSONSerialization.data(withJSONObject: convertedData) else {
|
|
@@ -499,7 +488,6 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
499
488
|
debugPrint("Error: \(error.localizedDescription) - endpoint response")
|
|
500
489
|
let responseData: [String: Any] = [
|
|
501
490
|
"transactionId": self.transactionID,
|
|
502
|
-
"paymentId": self.paymentID,
|
|
503
491
|
"isSuccess": false,
|
|
504
492
|
"token": "",
|
|
505
493
|
"returnCode": 400,
|
|
@@ -522,37 +510,24 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
522
510
|
// Convert JSON data to a dictionary
|
|
523
511
|
if let paymentDictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
|
|
524
512
|
if let paymentData = PaymentData(data: paymentDictionary) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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)
|
|
531
524
|
return
|
|
532
525
|
}
|
|
533
|
-
|
|
534
|
-
self.startPayment(data: paymentData, paymentID: paymentID) { success in
|
|
535
|
-
if success {} else {
|
|
536
|
-
let responseData: [String: Any] = [
|
|
537
|
-
"transactionId": self.transactionID,
|
|
538
|
-
"paymentId": self.paymentID,
|
|
539
|
-
"isSuccess": false,
|
|
540
|
-
"token": "",
|
|
541
|
-
"returnCode": 400,
|
|
542
|
-
"errorMessage": "Payment failed!"
|
|
543
|
-
]
|
|
544
|
-
|
|
545
|
-
self.sendEvent(withName: "applepay_response", body: responseData)
|
|
546
|
-
return
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
526
|
}
|
|
551
527
|
} else {
|
|
552
528
|
debugPrint("Unable to convert jsonData(cross-platform passed data) to paymentDictionary")
|
|
553
529
|
let responseData: [String: Any] = [
|
|
554
530
|
"transactionId": self.transactionID,
|
|
555
|
-
"paymentId": self.paymentID,
|
|
556
531
|
"isSuccess": false,
|
|
557
532
|
"token": "",
|
|
558
533
|
"returnCode": 400,
|
|
@@ -566,7 +541,6 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
566
541
|
debugPrint("Error: Unable to convert JSON string to data")
|
|
567
542
|
let responseData: [String: Any] = [
|
|
568
543
|
"transactionId": self.transactionID,
|
|
569
|
-
"paymentId": self.paymentID,
|
|
570
544
|
"isSuccess": false,
|
|
571
545
|
"token": "",
|
|
572
546
|
"returnCode": 400,
|
|
@@ -579,7 +553,6 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
579
553
|
debugPrint("Error: \(error)")
|
|
580
554
|
let responseData: [String: Any] = [
|
|
581
555
|
"transactionId": self.transactionID,
|
|
582
|
-
"paymentId": self.paymentID,
|
|
583
556
|
"isSuccess": false,
|
|
584
557
|
"token": "",
|
|
585
558
|
"returnCode": 400,
|
|
@@ -606,11 +579,14 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
606
579
|
// }
|
|
607
580
|
}
|
|
608
581
|
|
|
609
|
-
func startPayment(data: PaymentData,
|
|
582
|
+
func startPayment(data: PaymentData, authorizationHeader: String, completion: @escaping PaymentCompletionHandler) {
|
|
610
583
|
|
|
611
|
-
completionHandler
|
|
612
|
-
self.
|
|
584
|
+
completionHandler = completion
|
|
585
|
+
self.transactionID = data.transactionId
|
|
586
|
+
self.authorizationHeaderValue = authorizationHeader
|
|
587
|
+
self.paymentData = data
|
|
613
588
|
|
|
589
|
+
// self.paymentID = paymentID
|
|
614
590
|
|
|
615
591
|
var paymentSummaryItems = [PKPaymentSummaryItem]()
|
|
616
592
|
|
|
@@ -663,19 +639,18 @@ class SkipcashReactnative: RCTEventEmitter, ApplePayReponseDelegate {
|
|
|
663
639
|
if let paymentDictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
|
|
664
640
|
if let paymentData = PaymentData(data: paymentDictionary) {
|
|
665
641
|
self.getPaymentID(authorizationHeader: paymentData.authorizationHeader, data: paymentData, createPaymentApi: paymentData.createPaymentLinkEndPoint, returnURL: paymentData.returnUrl) { result in
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
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
|
+
}
|
|
679
654
|
}
|
|
680
655
|
} else {
|
|
681
656
|
debugPrint("Unable to convert jsonData(cross-platform passed data) to paymentDictionary")
|
|
@@ -759,20 +734,22 @@ extension SkipcashReactnative: PKPaymentAuthorizationControllerDelegate {
|
|
|
759
734
|
return
|
|
760
735
|
}
|
|
761
736
|
|
|
737
|
+
paymentData?.token = token
|
|
738
|
+
self.callApplePay(paymentData: self.paymentData!, applePaymentToken: token, completion: completion)
|
|
762
739
|
//
|
|
763
|
-
let vc = SetupVC()
|
|
764
|
-
|
|
765
|
-
vc.modalPresentationStyle = .overCurrentContext
|
|
766
|
-
vc.delegate = self
|
|
767
|
-
vc.transactionID = self.transactionID
|
|
768
|
-
vc.paymentID = self.paymentID
|
|
769
|
-
vc.completion = completion
|
|
770
|
-
vc.paymentToken = token
|
|
771
|
-
|
|
772
|
-
if let topViewController = UIApplication.shared.keyWindow?.rootViewController?.topMostViewController() {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
}
|
|
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
|
+
// }
|
|
776
753
|
}
|
|
777
754
|
|
|
778
755
|
public func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
|