react-native-cashfree-pg-sdk 0.1.7-dev.0 → 0.1.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
@@ -1,6 +1,7 @@
1
1
  # react-native-cashfree-pg-api
2
+ The Cashfree React Native SDK allows you to integrate Cashfree Payment Gateway into your application and start collecting payments from your customers. The React Native SDK has been designed to minimise the complexity of handling and integrating payments in your React Native project.
2
3
 
3
- ..
4
+ Click [here](https://docs.cashfree.com/docs/react-native-integration) for more Documentation.
4
5
 
5
6
  ## Installation
6
7
 
@@ -8,6 +9,20 @@
8
9
  npm install react-native-cashfree-pg-sdk
9
10
  ```
10
11
 
12
+ ### iOS
13
+ Add the following code to application's info.plist file.
14
+ ```xml
15
+ <key>LSApplicationCategoryType</key>
16
+ <string></string>
17
+ <key>LSApplicationQueriesSchemes</key>
18
+ <array>
19
+ <string>phonepe</string>
20
+ <string>tez</string>
21
+ <string>paytm</string>
22
+ <string>bhim</string>
23
+ </array>
24
+ ```
25
+
11
26
  ## Usage
12
27
 
13
28
  ```js
@@ -15,7 +30,7 @@ import {
15
30
  CFCallback,
16
31
  CFErrorResponse,
17
32
  CFPaymentGatewayService,
18
- } from 'react-native-cashfree-pg-api';
33
+ } from 'react-native-cashfree-pg-sdk';
19
34
  import {
20
35
  CFDropCheckoutPayment,
21
36
  CFEnvironment,
@@ -27,8 +42,8 @@ import {
27
42
 
28
43
  try {
29
44
  const session = new CFSession(
30
- 'EKnOtw8HtEo26tlmUg6P',
31
- 'order_1246922AeJyW66DV9SAC7LJL5UJGfmZuW',
45
+ 'order_token',
46
+ 'order_id',
32
47
  CFEnvironment.SANDBOX
33
48
  );
34
49
  const theme = new CFThemeBuilder()
@@ -69,7 +69,7 @@ dependencies {
69
69
  implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
70
70
  implementation 'androidx.gridlayout:gridlayout:1.0.0'
71
71
 
72
- implementation 'com.cashfree.pg:api:1.0.9'
72
+ implementation 'com.cashfree.pg:api:1.0.10'
73
73
 
74
74
  implementation "com.facebook.react:react-native:+" // From node_modules
75
75
  }
@@ -22,7 +22,7 @@ public class DropPaymentParser {
22
22
  .setCFUIPaymentModes(cfPaymentComponent)
23
23
  .setCFNativeCheckoutUITheme(cfTheme)
24
24
  .build();
25
- String version = cfPaymentJson.getJSONObject("version");
25
+ String version = cfPaymentJson.getString("version");
26
26
  cfDropCheckoutPayment.setPlatform("android-rn-" + version);
27
27
  return cfDropCheckoutPayment;
28
28
  }
@@ -4,21 +4,25 @@ import CashfreePG
4
4
 
5
5
  @objc(CashfreePgApi)
6
6
  class CashfreePgApi: NSObject {
7
-
7
+
8
8
  @objc func doPayment(_ paymentObject: NSString) -> Void {
9
9
  do {
10
10
  let dropObject = try! parseDropPayment(paymentObject: "\(paymentObject)")
11
+ if (dropObject != nil) {
12
+ let vc = RCTPresentedViewController()
13
+ try CFPaymentGatewayService.getInstance().doPayment(dropObject!, viewController: vc!)
14
+ }
11
15
  }
12
16
  catch {
13
17
  print (error)
14
18
  }
15
19
  }
16
-
20
+
17
21
  @objc func setCallback() -> Void {
18
22
  CFPaymentGatewayService.getInstance().setCallback(self)
19
23
  }
20
-
21
- private func parseDropPayment(paymentObject: String) throws {
24
+
25
+ private func parseDropPayment(paymentObject: String) throws -> CFDropCheckoutPayment? {
22
26
  // print(paymentObject)
23
27
  let data = paymentObject.data(using: .utf8)!
24
28
  if let output = try! JSONSerialization.jsonObject(with: data, options: .allowFragments) as? Dictionary<String, Any> {
@@ -26,26 +30,24 @@ class CashfreePgApi: NSObject {
26
30
  let session = getSession(paymentObject: output)
27
31
  let component = getComponents(paymentObject: output)
28
32
  let theme = getTheme(paymentObject: output)
29
-
33
+
30
34
  let nativePayment = try CFDropCheckoutPayment.CFDropCheckoutPaymentBuilder()
31
35
  .setSession(session!)
32
36
  .setTheme(theme!)
33
37
  .setComponent(component!)
34
38
  .build()
35
-
36
- print(nativePayment)
37
- let vc = RCTPresentedViewController()
38
-
39
- // Invoke SDK
40
- try CFPaymentGatewayService.getInstance().doPayment(nativePayment, viewController: vc!)
39
+ nativePayment.setPlatform( "ios-rn-" + (((output["version"]) as? String) ?? ""))
40
+ return nativePayment
41
+
41
42
  } catch let e {
42
43
  let error = e as! CashfreeError
43
44
  print(error.localizedDescription)
44
45
  // Handle errors here
45
46
  }
46
47
  }
48
+ return nil
47
49
  }
48
-
50
+
49
51
  private func getSession(paymentObject: Dictionary<String,Any>) -> CFSession? {
50
52
  if let sessionDict = paymentObject["session"] as? Dictionary<String, String> {
51
53
  do {
@@ -67,7 +69,7 @@ class CashfreePgApi: NSObject {
67
69
  }
68
70
  return nil
69
71
  }
70
-
72
+
71
73
  private func getComponents(paymentObject: Dictionary<String,Any>) -> CFPaymentComponent? {
72
74
  if let components = paymentObject["components"] as? Array<String> {
73
75
  do {
@@ -90,7 +92,7 @@ class CashfreePgApi: NSObject {
90
92
  }
91
93
  return nil
92
94
  }
93
-
95
+
94
96
  private func getItemName(item: String) -> String? {
95
97
  switch item {
96
98
  case "CARD" :
@@ -109,7 +111,7 @@ class CashfreePgApi: NSObject {
109
111
  return nil
110
112
  }
111
113
  }
112
-
114
+
113
115
  private func getTheme(paymentObject: Dictionary<String,Any>) -> CFTheme? {
114
116
  if let theme = paymentObject["theme"] as? Dictionary<String, String> {
115
117
  do {
@@ -131,7 +133,7 @@ class CashfreePgApi: NSObject {
131
133
  }
132
134
  return nil
133
135
  }
134
-
136
+
135
137
  func stringify(json: Any) -> String {
136
138
  var options: JSONSerialization.WritingOptions = []
137
139
  do {
@@ -157,7 +159,7 @@ extension CashfreePgApi: CFResponseDelegate {
157
159
  var body:[String: String] = ["error": stringify(json: data), "orderID": order_id]
158
160
  CashfreeEmitter.sharedInstance.dispatch(name: "cfFailure", body: stringify(json: body))
159
161
  }
160
-
162
+
161
163
  func verifyPayment(order_id: String) {
162
164
  print(order_id)
163
165
  CashfreeEmitter.sharedInstance.dispatch(name: "cfSuccess", body: order_id)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-cashfree-pg-sdk",
3
- "version": "0.1.7-dev.0",
4
- "description": "..",
3
+ "version": "0.1.7",
4
+ "description": "Cashfree PG Plugin for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
7
7
  "types": "lib/typescript/index.d.ts",
@@ -36,13 +36,13 @@
36
36
  "ios",
37
37
  "android"
38
38
  ],
39
- "repository": "https://www.cashfree.com/",
39
+ "repository": "https://github.com/cashfree/react-native-cashfree-pg-sdk",
40
40
  "author": "cashfree-payments <developers@cashfree.com> (https://www.cashfree.com/)",
41
41
  "license": "MIT",
42
42
  "bugs": {
43
- "url": "https://www.cashfree.com//issues"
43
+ "url": "https://github.com/cashfree/react-native-cashfree-pg-sdk/issues"
44
44
  },
45
- "homepage": "https://www.cashfree.com/#readme",
45
+ "homepage": "https://docs.cashfree.com/docs/react-native-integration",
46
46
  "publishConfig": {
47
47
  "registry": "https://registry.npmjs.org/"
48
48
  },