skipcash-reactnative 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -20,9 +20,10 @@ SkipCash React Native Package; This package facilitates SkipCash integration wit
20
20
  # Example
21
21
 
22
22
  ```jsx
23
+
23
24
  import { useEffect, useState } from 'react';
24
25
 
25
- import { StyleSheet, View, NativeEventEmitter, NativeModules, Platform, Alert } from 'react-native';
26
+ import { StyleSheet, View, NativeEventEmitter, KeyboardAvoidingView, NativeModules, Platform, Alert } from 'react-native';
26
27
  import { initiateApplePay, PaymentData, PaymentResponse,
27
28
  isWalletHasCards, setupNewCard, initiatePaymentModel
28
29
  } from 'skipcash-reactnative';
@@ -43,29 +44,12 @@ export default function App() {
43
44
  /**********************************
44
45
  - THIS PACKAGE PROVIDES TWO PAYMENT OPTIONS FOR YOUR CUSTOMER -
45
46
  1. IN-APP APPLE PAY using 'initiateApplePay()' function.
46
- 2. IN-APP WEB VIEW (INCLUDES ALL PAYMENT OPTIONS THAT SKIPCASH OFFERS).
47
+ 2. IN-APP WEB VIEW (INCLUDES ALL PAYMENT OPTIONS THAT SKIPCASH OFFERS (visa, master, amex,
48
+ international cards, etc...) using 'initiatePaymentModel()' function.
47
49
  - THIS EXAMPLE APP, DEMONESTRATES HOW TO USE THE DIFFERENT OPTIONS MENTIONED ABOVE
48
50
  ***********************************/
49
51
 
50
- /*
51
- Here In case if you want to implement IN-APP Apple Pay
52
- you have to pass the name of the merchant identifier
53
- (you need to create a new one from apple developer account of your app ).
54
- please reachout to https://dev.skipcash.app/ mobile apple pay section to
55
- know how to generate your merchant identifier and setup Xcode.
56
- */
57
-
58
- paymentData.setMerchantIdentifier("");
59
- /*
60
- Add your payment endpoint; You need to create an endpoint for your merchant account.
61
- For more information on how to request a new payment, Please refer to https://dev.skipcash.app/doc/api-integration/.
62
-
63
- You will need to implement this functionality on your backend server to create an endpoint that requests a new payment and returns the details you receive from the SkipCash server to this package. Of course your endpoint will receive the customer's details from this package request, Upon receiving the details response from your server this package will use that details to process your customer's payment via Apple Pay.
64
52
 
65
- Once you have completed setting up and testing your endpoint, please provide the link to the setPaymentLinkEndPoint below.
66
- */
67
- paymentData.setPaymentLinkEndPoint("")
68
- paymentData.setAuthorizationHeader("");
69
53
  /* add authorizartion header; used to protect your endpoint from unathorized access */
70
54
 
71
55
  useEffect(() => {
@@ -92,7 +76,7 @@ export default function App() {
92
76
  }
93
77
  ));
94
78
 
95
- // For In-App Apple Pay response
79
+ // For In-App Apple Pay
96
80
  subscriptions.push(new NativeEventEmitter(NativeModules.SkipcashReactnative).addListener(
97
81
  'applepay_response',
98
82
  (paymentResponse: any) => {
@@ -101,7 +85,7 @@ export default function App() {
101
85
  let response: PaymentResponse = PaymentResponse.fromJson(paymentResponse);
102
86
 
103
87
 
104
- Alert.alert(`isSuccess: ${response.isSuccess} | transactionId: ${response.transactionId} | PaymentID: ${response.paymentId}
88
+ Alert.alert(`isSuccess: ${response.isSuccess} | transactionId: ${response.transactionId}
105
89
  | returnCode: ${response.returnCode} | errorMessage: ${response.errorMessage}`);
106
90
 
107
91
  /*
@@ -118,6 +102,9 @@ export default function App() {
118
102
 
119
103
  return () => {
120
104
  // cleaning up after leaving the current app view
105
+ // make sure to block leaving the current view until the payment is
106
+ // finished or canceled by the client or you will not be able to
107
+ // record the callback event for the payment status.
121
108
  new NativeEventEmitter().removeAllListeners("responseScPaymentData");
122
109
  if(Platform.OS === 'ios'){
123
110
  new NativeEventEmitter().removeAllListeners("applepay_response");
@@ -128,6 +115,34 @@ export default function App() {
128
115
  }, []);
129
116
 
130
117
  const initiateApplePayPayment = () => {
118
+ /*
119
+ you have to pass the name of the merchant identifier
120
+ (you need to create a new one from apple developer account of your app ).
121
+ please reachout to https://dev.skipcash.app/ mobile apple pay section to
122
+ know how to generate your merchant identifier and setup Xcode.
123
+ */
124
+ paymentData.setMerchantIdentifier("");
125
+
126
+ /*
127
+ Apple Pay Payments Processing endpoint.
128
+
129
+ You need to setup an endpoint to create a new payments.
130
+ For more information on how to request a new payment, Please refer to https://dev.skipcash.app/doc/api-integration/.
131
+
132
+ You will need to implement this functionality on your backend server to create an endpoint that requests and create new payment and process it
133
+ and returns the details you receive from the SkipCash server to this package.
134
+
135
+ Your endpoint will receive the customer's details and apple pay token once the customer authorizes the transaction after calling initiateApplePay()
136
+ then your endpoint should process the payment by calling skipcash API, once done your endpoint should return the response received from SkipCash API
137
+ you can find details about how to setup your endpoint at "https://dev.skipcash.app/" under applepay section "configure payment processing endpoint".
138
+
139
+ Once you have completed setting up and testing your endpoint, please provide the link to the setPaymentLinkEndPoint below.
140
+ */
141
+ paymentData.setPaymentLinkEndPoint("");
142
+
143
+ // if your endpoint requires authorization header you can pass it below
144
+ paymentData.setAuthorizationHeader("");
145
+
131
146
  paymentData.setSummaryItem('Tax', '0.0'); // set summary item
132
147
  paymentData.setSummaryItem('Total', amount); // set summary item
133
148
 
@@ -137,9 +152,10 @@ export default function App() {
137
152
  paymentData.setEmail(email); // required
138
153
  paymentData.setAmount(amount); // required
139
154
  paymentData.setTransactionId(""); // your internal order id, (Optional) - but very much recommended
140
- paymentData.setWebhookUrl(""); // very much recommended
155
+ paymentData.setWebhookUrl(""); // very much recommended
141
156
  // read about webhooks -> https://dev.skipcash.app/doc/api-integration/web-hooks/
142
- paymentData.setMerchantName(""); /*
157
+ paymentData.setMerchantName("Your official business name in appstore");
158
+ /*
143
159
  Required - (if using in-app apple-pay set your official merchant/business name for apple payment sheet)
144
160
  this is required by apple, it must match your official name in appstore
145
161
  */
@@ -152,6 +168,7 @@ export default function App() {
152
168
  const paymentDataJson = JSON.stringify(paymentData); // convert paymentData to json string
153
169
 
154
170
  if(firstName && lastName && phone && email) {
171
+ console.log(paymentDataJson);
155
172
  initiateApplePay(paymentDataJson);
156
173
  }else{
157
174
  Alert.alert("please fill firstname, lastname, phone, email & amount");
@@ -159,6 +176,26 @@ export default function App() {
159
176
  }
160
177
 
161
178
  const startPaymentModel = () => {
179
+
180
+ /*
181
+ Add your payment endpoint; You need to create an endpoint for your merchant account.
182
+ For more information on how to request a new payment, Please refer to https://dev.skipcash.app/doc/api-integration/.
183
+
184
+ You will need to implement this functionality at your backend server. Create an endpoint that requests a new payment and returns the response
185
+ received from the SkipCash API.
186
+
187
+ Your endpoint will receive the customer's details from this package request, Upon receiving the details call SkipCash API to create a new payment
188
+ as mentioned in the above documentation then your endpoint should return the response received from SkipCash API this package will use the response
189
+ to open the new payment a webview to show the online payment options to customer.
190
+
191
+ Once you have completed setting up and testing your endpoint, please provide the link to the setPaymentLinkEndPoint below.
192
+ */
193
+ paymentData.setPaymentLinkEndPoint("");
194
+
195
+ // if your endpoint requires authorization header you can pass it below
196
+ paymentData.setAuthorizationHeader("");
197
+
198
+
162
199
  paymentData.setFirstName(firstName); // required
163
200
  paymentData.setLastName(lastName); // required
164
201
  paymentData.setPhone(phone); // required
@@ -194,7 +231,7 @@ export default function App() {
194
231
  }
195
232
 
196
233
  return (
197
- <View style={styles.container}>
234
+ <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={styles.container}>
198
235
  <Title style={styles.title}>Payment Details</Title>
199
236
 
200
237
  <TextInput
@@ -302,7 +339,7 @@ export default function App() {
302
339
  >
303
340
  Setup A Card
304
341
  </Button>
305
- </View>
342
+ </KeyboardAvoidingView>
306
343
  );
307
344
  }
308
345
 
@@ -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 Description: String
248
- let Subject: String
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 Description = data["description"] as? String,
277
- let Subject = data["subject"] as? String,
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.Subject = Subject
312
- self.Description = Description
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, ApplePayReponseDelegate {
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, paymentID: String, isSuccess: Bool, token: String, returnCode: Int, errorMessage: String, completion: ((PKPaymentAuthorizationResult) -> Void)?) {
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["Amount"] = data.amount
409
- convertedData["FirstName"] = data.firstName
410
- convertedData["LastName"] = data.lastName
411
- convertedData["Phone"] = data.phone
412
- convertedData["Email"] = data.email
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["ReturnUrl"] = returnURL
415
- convertedData["TransactionId"] = data.transactionId
416
- convertedData["WebhookUrl"] = data.webhookUrl
403
+ convertedData["returnUrl"] = returnURL
404
+ convertedData["transactionId"] = data.transactionId
405
+ convertedData["webhookUrl"] = data.webhookUrl
417
406
 
418
- convertedData["Custom1"] = data.custom1
419
- convertedData["Custom2"] = data.custom2
420
- convertedData["Custom3"] = data.custom3
421
- convertedData["Custom4"] = data.custom4
422
- convertedData["Custom5"] = data.custom5
423
- convertedData["Custom6"] = data.custom6
424
- convertedData["Custom7"] = data.custom7
425
- convertedData["Custom8"] = data.custom8
426
- convertedData["Custom9"] = data.custom9
427
- convertedData["Custom10"] = data.custom10
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["Description"] = data.Description
430
- convertedData["Subject"] = data.Subject
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
- getPaymentID(authorizationHeader: paymentData.authorizationHeader, data: paymentData, createPaymentApi: paymentData.createPaymentLinkEndPoint, returnURL: paymentData.returnUrl) { result in
526
- if let result = result {
527
- let paymentID = result["paymentID"] as? String ?? ""
528
-
529
- if(paymentID.count == 0){
530
- debugPrint("new payment request failed!")
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, paymentID: String, completion: @escaping PaymentCompletionHandler) {
582
+ func startPayment(data: PaymentData, authorizationHeader: String, completion: @escaping PaymentCompletionHandler) {
610
583
 
611
- completionHandler = completion
612
- self.paymentID = paymentID
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
- if let result = result {
667
- let paymentID = result["paymentID"] as? String ?? ""
668
- let payUrl = result["payUrl"] as? String ?? ""
669
- let transactionID = result["transactionId"] as? String ?? ""
670
-
671
- if(paymentID.count == 0){
672
- debugPrint("new payment request failed!")
673
- return
674
- }
675
-
676
- self.showPaymentModal(url: payUrl, paymentTitle: paymentData.paymentModalTitle, returnURL: paymentData.returnUrl, paymentId: paymentID, transactionId: transactionID)
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
- topViewController.modalPresentationStyle = .overCurrentContext
774
- topViewController.present(vc, animated: true, completion: nil)
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skipcash-reactnative",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "integrate skipcash in react native app.",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",