react-native-cashfree-pg-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +27 -0
- package/android/.gradle/6.8/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/6.8/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.8/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.8/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/6.8/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.8/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/6.8/gc.properties +0 -0
- package/android/.gradle/6.8/javaCompile/classAnalysis.bin +0 -0
- package/android/.gradle/6.8/javaCompile/jarAnalysis.bin +0 -0
- package/android/.gradle/6.8/javaCompile/javaCompile.lock +0 -0
- package/android/.gradle/6.8/javaCompile/taskHistory.bin +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +19 -0
- package/android/.idea/jarRepositories.xml +45 -0
- package/android/.idea/libraries/Gradle__androidx_activity_activity_1_2_3_aar.xml +17 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_2_0.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_experimental_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_3_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_resources_1_3_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_1_0.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_1_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_cardview_cardview_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_collection_collection_1_1_0.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_constraintlayout_constraintlayout_2_1_3_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_1_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_core_core_1_5_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +17 -0
- package/android/.idea/libraries/Gradle__androidx_dynamicanimation_dynamicanimation_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_3_4_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_gridlayout_gridlayout_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_3_1.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_3_1_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_3_1_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_3_1_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_savedstate_2_3_1_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_print_print_1_0_0_aar.xml +17 -0
- package/android/.idea/libraries/Gradle__androidx_recyclerview_recyclerview_1_1_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_savedstate_savedstate_1_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml +17 -0
- package/android/.idea/libraries/Gradle__androidx_transition_transition_1_2_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_1_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_1_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_1_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_viewpager2_viewpager2_1_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__com_cashfree_pg_analytics_1_0_6_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_cashfree_pg_api_1_0_9_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_cashfree_pg_base_1_0_1_aar.xml +12 -0
- package/android/.idea/libraries/Gradle__com_cashfree_pg_core_1_0_9_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_cashfree_pg_image_caching_1_0_1_aar.xml +12 -0
- package/android/.idea/libraries/Gradle__com_cashfree_pg_network_1_0_0_aar.xml +12 -0
- package/android/.idea/libraries/Gradle__com_cashfree_pg_ui_1_0_9_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_facebook_fbjni_fbjni_java_only_0_0_3.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_2_0_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_2_0_0_aar.xml +19 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_2_0_0_aar.xml +19 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_2_0_0_aar.xml +19 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_2_0_0_aar.xml +19 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_2_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagefilters_2_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagetranscoder_2_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__com_facebook_infer_annotation_infer_annotation_0_11_2.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_63_4_aar.xml +18 -0
- package/android/.idea/libraries/Gradle__com_facebook_soloader_annotation_0_9_0.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_soloader_nativeloader_0_9_0.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_9_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__com_facebook_yoga_proguard_annotations_1_14_1.xml +13 -0
- package/android/.idea/libraries/Gradle__com_google_android_material_material_1_4_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2.xml +13 -0
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_3_12_12.xml +13 -0
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_urlconnection_3_12_12.xml +13 -0
- package/android/.idea/libraries/Gradle__com_squareup_okio_okio_1_15_0.xml +13 -0
- package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +13 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/modules/android.iml +114 -0
- package/android/.idea/modules.xml +8 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +75 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/local.properties +8 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactnativecashfreepgapi/CashfreePgApiModule.java +80 -0
- package/android/src/main/java/com/reactnativecashfreepgapi/CashfreePgApiPackage.java +28 -0
- package/android/src/main/java/com/reactnativecashfreepgapi/DropPaymentParser.java +54 -0
- package/ios/CashfreeEmitter.swift +36 -0
- package/ios/CashfreeEventEmitter.m +16 -0
- package/ios/CashfreeEventEmitter.swift +24 -0
- package/ios/CashfreePgApi-Bridging-Header.h +5 -0
- package/ios/CashfreePgApi.m +10 -0
- package/ios/CashfreePgApi.swift +165 -0
- package/ios/CashfreePgApi.xcodeproj/project.pbxproj +293 -0
- package/ios/CashfreePgApi.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/lib/commonjs/index.js +116 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +105 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/index.d.ts +27 -0
- package/package.json +150 -0
- package/react-native-cashfree-pg-api.podspec +20 -0
- package/src/index.js +86 -0
- package/src/index.tsx +128 -0
package/package.json
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-cashfree-pg-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "..",
|
|
5
|
+
"main": "lib/commonjs/index",
|
|
6
|
+
"module": "lib/module/index",
|
|
7
|
+
"types": "lib/typescript/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"lib",
|
|
13
|
+
"android",
|
|
14
|
+
"ios",
|
|
15
|
+
"cpp",
|
|
16
|
+
"react-native-cashfree-pg-api.podspec",
|
|
17
|
+
"!lib/typescript/example",
|
|
18
|
+
"!android/build",
|
|
19
|
+
"!ios/build",
|
|
20
|
+
"!**/__tests__",
|
|
21
|
+
"!**/__fixtures__",
|
|
22
|
+
"!**/__mocks__"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"typescript": "tsc --noEmit",
|
|
27
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
28
|
+
"prepare": "bob build",
|
|
29
|
+
"release": "release-it",
|
|
30
|
+
"example": "yarn --cwd example",
|
|
31
|
+
"pods": "cd example && pod-install --quiet",
|
|
32
|
+
"bootstrap": "yarn example && yarn && yarn pods"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"react-native",
|
|
36
|
+
"ios",
|
|
37
|
+
"android"
|
|
38
|
+
],
|
|
39
|
+
"repository": "https://www.cashfree.com/",
|
|
40
|
+
"author": "cashfree-payments <developers@cashfree.com> (https://www.cashfree.com/)",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://www.cashfree.com//issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://www.cashfree.com/#readme",
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"registry": "https://registry.npmjs.org/"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@commitlint/config-conventional": "^11.0.0",
|
|
51
|
+
"@react-native-community/eslint-config": "^2.0.0",
|
|
52
|
+
"@release-it/conventional-changelog": "^2.0.0",
|
|
53
|
+
"@types/jest": "^26.0.0",
|
|
54
|
+
"@types/react": "^16.9.19",
|
|
55
|
+
"@types/react-native": "0.62.13",
|
|
56
|
+
"commitlint": "^11.0.0",
|
|
57
|
+
"eslint": "^7.2.0",
|
|
58
|
+
"eslint-config-prettier": "^7.0.0",
|
|
59
|
+
"eslint-plugin-prettier": "^3.1.3",
|
|
60
|
+
"husky": "^6.0.0",
|
|
61
|
+
"jest": "^26.0.1",
|
|
62
|
+
"pod-install": "^0.1.0",
|
|
63
|
+
"prettier": "^2.0.5",
|
|
64
|
+
"react": "16.13.1",
|
|
65
|
+
"react-native": "0.63.4",
|
|
66
|
+
"react-native-builder-bob": "^0.18.0",
|
|
67
|
+
"release-it": "^14.2.2",
|
|
68
|
+
"typescript": "^4.1.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"react": "*",
|
|
72
|
+
"react-native": "*"
|
|
73
|
+
},
|
|
74
|
+
"jest": {
|
|
75
|
+
"preset": "react-native",
|
|
76
|
+
"modulePathIgnorePatterns": [
|
|
77
|
+
"<rootDir>/example/node_modules",
|
|
78
|
+
"<rootDir>/lib/"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
"commitlint": {
|
|
82
|
+
"extends": [
|
|
83
|
+
"@commitlint/config-conventional"
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
"release-it": {
|
|
87
|
+
"git": {
|
|
88
|
+
"commitMessage": "chore: release ${version}",
|
|
89
|
+
"tagName": "v${version}"
|
|
90
|
+
},
|
|
91
|
+
"npm": {
|
|
92
|
+
"publish": true
|
|
93
|
+
},
|
|
94
|
+
"github": {
|
|
95
|
+
"release": true
|
|
96
|
+
},
|
|
97
|
+
"plugins": {
|
|
98
|
+
"@release-it/conventional-changelog": {
|
|
99
|
+
"preset": "angular"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"eslintConfig": {
|
|
104
|
+
"root": true,
|
|
105
|
+
"extends": [
|
|
106
|
+
"@react-native-community",
|
|
107
|
+
"prettier"
|
|
108
|
+
],
|
|
109
|
+
"rules": {
|
|
110
|
+
"prettier/prettier": [
|
|
111
|
+
"error",
|
|
112
|
+
{
|
|
113
|
+
"quoteProps": "consistent",
|
|
114
|
+
"singleQuote": true,
|
|
115
|
+
"tabWidth": 2,
|
|
116
|
+
"trailingComma": "es5",
|
|
117
|
+
"useTabs": false
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"eslintIgnore": [
|
|
123
|
+
"node_modules/",
|
|
124
|
+
"lib/"
|
|
125
|
+
],
|
|
126
|
+
"prettier": {
|
|
127
|
+
"quoteProps": "consistent",
|
|
128
|
+
"singleQuote": true,
|
|
129
|
+
"tabWidth": 2,
|
|
130
|
+
"trailingComma": "es5",
|
|
131
|
+
"useTabs": false
|
|
132
|
+
},
|
|
133
|
+
"react-native-builder-bob": {
|
|
134
|
+
"source": "src",
|
|
135
|
+
"output": "lib",
|
|
136
|
+
"targets": [
|
|
137
|
+
"commonjs",
|
|
138
|
+
"module",
|
|
139
|
+
[
|
|
140
|
+
"typescript",
|
|
141
|
+
{
|
|
142
|
+
"project": "tsconfig.build.json"
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
"dependencies": {
|
|
148
|
+
"cashfree-pg-api-contract": "0.0.1"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "react-native-cashfree-pg-api"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => "10.0" }
|
|
14
|
+
s.source = { :git => "https://www.cashfree.com/.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
|
+
|
|
18
|
+
s.dependency "React-Core"
|
|
19
|
+
s.dependency "CashfreePG", "~> 1.1"
|
|
20
|
+
end
|
package/src/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { NativeAppEventEmitter, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
|
|
2
|
+
const LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
|
|
3
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
4
|
+
'- You rebuilt the app after installing the package\n' +
|
|
5
|
+
'- You are not using Expo managed workflow\n';
|
|
6
|
+
const CashfreePgApi = NativeModules.CashfreePgApi
|
|
7
|
+
? NativeModules.CashfreePgApi
|
|
8
|
+
: new Proxy({}, {
|
|
9
|
+
get() {
|
|
10
|
+
throw new Error(LINKING_ERROR);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
// noinspection JSVoidFunctionReturnValueUsed,TypeScriptValidateJSTypes
|
|
14
|
+
class CFPaymentGateway {
|
|
15
|
+
emitter;
|
|
16
|
+
successSubscription = null;
|
|
17
|
+
failureSubscription = null;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.emitter =
|
|
20
|
+
Platform.OS === 'ios'
|
|
21
|
+
? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)
|
|
22
|
+
: NativeAppEventEmitter;
|
|
23
|
+
}
|
|
24
|
+
doPayment(checkoutPayment) {
|
|
25
|
+
return CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));
|
|
26
|
+
}
|
|
27
|
+
setCallback(cfCallback) {
|
|
28
|
+
// this.cfCallback = cfCallback;
|
|
29
|
+
let successFunction = (orderID) => {
|
|
30
|
+
console.log('response is : ' + JSON.stringify(orderID));
|
|
31
|
+
cfCallback.onVerify(orderID);
|
|
32
|
+
};
|
|
33
|
+
let failureFunction = (error) => {
|
|
34
|
+
console.log('reason: ' + JSON.stringify(error));
|
|
35
|
+
const response = new CFErrorResponse();
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const message = JSON.parse(error);
|
|
38
|
+
response.fromJSON(message.error);
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
cfCallback.onError(response, message.orderID);
|
|
41
|
+
};
|
|
42
|
+
this.successSubscription = this.emitter.addListener('cfSuccess', successFunction);
|
|
43
|
+
this.failureSubscription = this.emitter.addListener('cfFailure', failureFunction);
|
|
44
|
+
CashfreePgApi.setCallback();
|
|
45
|
+
}
|
|
46
|
+
removeCallback() {
|
|
47
|
+
if (this.successSubscription !== undefined &&
|
|
48
|
+
this.successSubscription !== null) {
|
|
49
|
+
this.emitter.removeSubscription(this.successSubscription);
|
|
50
|
+
this.successSubscription = null;
|
|
51
|
+
}
|
|
52
|
+
if (this.failureSubscription !== undefined &&
|
|
53
|
+
this.failureSubscription !== null) {
|
|
54
|
+
this.emitter.removeSubscription(this.failureSubscription);
|
|
55
|
+
this.failureSubscription = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class CFErrorResponse {
|
|
60
|
+
status = 'FAILED';
|
|
61
|
+
message = 'payment has failed';
|
|
62
|
+
code = 'payment_failed';
|
|
63
|
+
type = 'request_failed';
|
|
64
|
+
fromJSON(errorString) {
|
|
65
|
+
console.log('errorString :' + errorString);
|
|
66
|
+
const object = JSON.parse(errorString);
|
|
67
|
+
console.log('errorStringObject :' + object);
|
|
68
|
+
this.status = object.status;
|
|
69
|
+
this.message = object.message;
|
|
70
|
+
this.code = object.code;
|
|
71
|
+
this.type = object.type;
|
|
72
|
+
}
|
|
73
|
+
getStatus() {
|
|
74
|
+
return this.status;
|
|
75
|
+
}
|
|
76
|
+
getMessage() {
|
|
77
|
+
return this.message;
|
|
78
|
+
}
|
|
79
|
+
getCode() {
|
|
80
|
+
return this.code;
|
|
81
|
+
}
|
|
82
|
+
getType() {
|
|
83
|
+
return this.type;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export var CFPaymentGatewayService = new CFPaymentGateway();
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EmitterSubscription,
|
|
3
|
+
EventEmitter,
|
|
4
|
+
NativeAppEventEmitter,
|
|
5
|
+
NativeEventEmitter,
|
|
6
|
+
NativeModules,
|
|
7
|
+
Platform,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import type { CheckoutPayment } from 'cashfree-pg-api-contract';
|
|
10
|
+
|
|
11
|
+
const LINKING_ERROR =
|
|
12
|
+
`The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
|
|
13
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
14
|
+
'- You rebuilt the app after installing the package\n' +
|
|
15
|
+
'- You are not using Expo managed workflow\n';
|
|
16
|
+
|
|
17
|
+
const CashfreePgApi = NativeModules.CashfreePgApi
|
|
18
|
+
? NativeModules.CashfreePgApi
|
|
19
|
+
: new Proxy(
|
|
20
|
+
{},
|
|
21
|
+
{
|
|
22
|
+
get() {
|
|
23
|
+
throw new Error(LINKING_ERROR);
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// noinspection JSVoidFunctionReturnValueUsed,TypeScriptValidateJSTypes
|
|
29
|
+
class CFPaymentGateway {
|
|
30
|
+
private emitter: EventEmitter;
|
|
31
|
+
private successSubscription: EmitterSubscription | null = null;
|
|
32
|
+
private failureSubscription: EmitterSubscription | null = null;
|
|
33
|
+
|
|
34
|
+
constructor() {
|
|
35
|
+
this.emitter =
|
|
36
|
+
Platform.OS === 'ios'
|
|
37
|
+
? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)
|
|
38
|
+
: NativeAppEventEmitter;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
doPayment(checkoutPayment: CheckoutPayment) {
|
|
42
|
+
return CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setCallback(cfCallback: CFCallback) {
|
|
46
|
+
// this.cfCallback = cfCallback;
|
|
47
|
+
let successFunction = (orderID: string) => {
|
|
48
|
+
console.log('response is : ' + JSON.stringify(orderID));
|
|
49
|
+
cfCallback.onVerify(orderID);
|
|
50
|
+
};
|
|
51
|
+
let failureFunction = (error: string) => {
|
|
52
|
+
console.log('reason: ' + JSON.stringify(error));
|
|
53
|
+
const response = new CFErrorResponse();
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
const message = JSON.parse(error);
|
|
56
|
+
response.fromJSON(message.error);
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
cfCallback.onError(response, message.orderID);
|
|
59
|
+
};
|
|
60
|
+
this.successSubscription = this.emitter.addListener(
|
|
61
|
+
'cfSuccess',
|
|
62
|
+
successFunction
|
|
63
|
+
);
|
|
64
|
+
this.failureSubscription = this.emitter.addListener(
|
|
65
|
+
'cfFailure',
|
|
66
|
+
failureFunction
|
|
67
|
+
);
|
|
68
|
+
CashfreePgApi.setCallback();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
removeCallback() {
|
|
72
|
+
if (
|
|
73
|
+
this.successSubscription !== undefined &&
|
|
74
|
+
this.successSubscription !== null
|
|
75
|
+
) {
|
|
76
|
+
this.emitter.removeSubscription(this.successSubscription);
|
|
77
|
+
this.successSubscription = null;
|
|
78
|
+
}
|
|
79
|
+
if (
|
|
80
|
+
this.failureSubscription !== undefined &&
|
|
81
|
+
this.failureSubscription !== null
|
|
82
|
+
) {
|
|
83
|
+
this.emitter.removeSubscription(this.failureSubscription);
|
|
84
|
+
this.failureSubscription = null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface CFCallback {
|
|
90
|
+
onVerify(orderID: string): void;
|
|
91
|
+
|
|
92
|
+
onError(error: CFErrorResponse, orderID: string): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class CFErrorResponse {
|
|
96
|
+
private status: string = 'FAILED';
|
|
97
|
+
private message: string = 'payment has failed';
|
|
98
|
+
private code: string = 'payment_failed';
|
|
99
|
+
private type: string = 'request_failed';
|
|
100
|
+
|
|
101
|
+
fromJSON(errorString: string) {
|
|
102
|
+
console.log('errorString :' + errorString);
|
|
103
|
+
const object = JSON.parse(errorString);
|
|
104
|
+
console.log('errorStringObject :' + object);
|
|
105
|
+
this.status = object.status;
|
|
106
|
+
this.message = object.message;
|
|
107
|
+
this.code = object.code;
|
|
108
|
+
this.type = object.type;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getStatus(): string {
|
|
112
|
+
return this.status;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getMessage(): string {
|
|
116
|
+
return this.message;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getCode(): string {
|
|
120
|
+
return this.code;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getType(): string {
|
|
124
|
+
return this.type;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export var CFPaymentGatewayService = new CFPaymentGateway();
|