@crmcom/self-service-sdk 2.1.2
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/account.js +144 -0
- package/authentication.js +475 -0
- package/communications.js +94 -0
- package/community.js +327 -0
- package/config.js +302 -0
- package/connectx.js +92 -0
- package/contacts.js +1109 -0
- package/dataUtil.js +2186 -0
- package/eventListener.js +41 -0
- package/httpBackOfficeUtil.js +396 -0
- package/httpJCCUtil.js +61 -0
- package/httpUtil.js +863 -0
- package/index.d.ts +527 -0
- package/index.js +24 -0
- package/jcccards.js +112 -0
- package/logger.js +40 -0
- package/mobilepass.js +64 -0
- package/orders.js +732 -0
- package/organisations.js +141 -0
- package/package.json +63 -0
- package/payment.js +338 -0
- package/paymentgateway.js +26 -0
- package/payouts.js +33 -0
- package/resultUtil.js +86 -0
- package/rewards.js +409 -0
- package/servicerequest.js +235 -0
- package/subscriptions.js +406 -0
- package/wallet.js +478 -0
package/organisations.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { httpUtil } from './httpUtil'
|
|
2
|
+
import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
|
|
3
|
+
import { logger } from './logger';
|
|
4
|
+
|
|
5
|
+
export const organisations = {
|
|
6
|
+
searchOrganisations,
|
|
7
|
+
getLocations,
|
|
8
|
+
getOrganisation
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function searchOrganisations({
|
|
12
|
+
business_activities,
|
|
13
|
+
contact_registry,
|
|
14
|
+
countries,
|
|
15
|
+
custom_fields,
|
|
16
|
+
distance,
|
|
17
|
+
include_custom_fields,
|
|
18
|
+
include_order_catalogs,
|
|
19
|
+
include_total,
|
|
20
|
+
include_wifi_sites,
|
|
21
|
+
industries,
|
|
22
|
+
industry_sectors,
|
|
23
|
+
lat,
|
|
24
|
+
lon,
|
|
25
|
+
name,
|
|
26
|
+
tags,
|
|
27
|
+
tap_code,
|
|
28
|
+
town_cities,
|
|
29
|
+
type,
|
|
30
|
+
page = 1,
|
|
31
|
+
size = 20,
|
|
32
|
+
sort='name',
|
|
33
|
+
order='ASC',
|
|
34
|
+
} = {}, orgId) {
|
|
35
|
+
try {
|
|
36
|
+
let queryParams = {
|
|
37
|
+
business_activities,
|
|
38
|
+
contact_registry,
|
|
39
|
+
countries,
|
|
40
|
+
custom_fields,
|
|
41
|
+
distance,
|
|
42
|
+
include_custom_fields,
|
|
43
|
+
include_order_catalogs,
|
|
44
|
+
include_total,
|
|
45
|
+
include_wifi_sites,
|
|
46
|
+
industries,
|
|
47
|
+
industry_sectors,
|
|
48
|
+
lat,
|
|
49
|
+
lon,
|
|
50
|
+
name,
|
|
51
|
+
tags,
|
|
52
|
+
tap_code,
|
|
53
|
+
town_cities,
|
|
54
|
+
type,
|
|
55
|
+
page,
|
|
56
|
+
size,
|
|
57
|
+
sort,
|
|
58
|
+
order
|
|
59
|
+
};
|
|
60
|
+
let id = orgId ? orgId : httpUtil.getSession().current_organisation_id;
|
|
61
|
+
let response = await httpUtil.get({
|
|
62
|
+
resourcePath: '/v2/organisations/' + id + '/network',
|
|
63
|
+
queryParams: queryParams,
|
|
64
|
+
withAccessToken: true
|
|
65
|
+
});
|
|
66
|
+
return createCommonResult(response);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
logger.error('Exception searchOrganisations:', e);
|
|
69
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function getLocations({
|
|
74
|
+
lat,
|
|
75
|
+
lon,
|
|
76
|
+
business_activities,
|
|
77
|
+
include_creatives,
|
|
78
|
+
include_opening_hours,
|
|
79
|
+
industries,
|
|
80
|
+
industry_sectors,
|
|
81
|
+
is_open,
|
|
82
|
+
name,
|
|
83
|
+
supply_method,
|
|
84
|
+
tags,
|
|
85
|
+
town_cities,
|
|
86
|
+
within,
|
|
87
|
+
page = 1,
|
|
88
|
+
size = 20,
|
|
89
|
+
sort='name',
|
|
90
|
+
order='ASC',
|
|
91
|
+
include_custom_fields = true,
|
|
92
|
+
custom_fields,
|
|
93
|
+
organisation_id
|
|
94
|
+
} = {}) {
|
|
95
|
+
try {
|
|
96
|
+
let queryParams = {
|
|
97
|
+
lat,
|
|
98
|
+
lon,
|
|
99
|
+
business_activities,
|
|
100
|
+
include_creatives,
|
|
101
|
+
include_opening_hours,
|
|
102
|
+
industries,
|
|
103
|
+
industry_sectors,
|
|
104
|
+
is_open,
|
|
105
|
+
name,
|
|
106
|
+
supply_method,
|
|
107
|
+
tags,
|
|
108
|
+
town_cities,
|
|
109
|
+
within,
|
|
110
|
+
page,
|
|
111
|
+
size,
|
|
112
|
+
sort,
|
|
113
|
+
order,
|
|
114
|
+
include_custom_fields,
|
|
115
|
+
custom_fields,
|
|
116
|
+
organisation_id
|
|
117
|
+
};
|
|
118
|
+
let response = await httpUtil.get({
|
|
119
|
+
resourcePath: '/v2/locations',
|
|
120
|
+
queryParams: queryParams,
|
|
121
|
+
withAccessToken: true
|
|
122
|
+
});
|
|
123
|
+
return createCommonResult(response);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
logger.error('Exception getLocations:', e);
|
|
126
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function getOrganisation(id) {
|
|
131
|
+
try {
|
|
132
|
+
let response = await httpUtil.get({
|
|
133
|
+
resourcePath: '/v2/organisations/' + id,
|
|
134
|
+
withAccessToken: true
|
|
135
|
+
});
|
|
136
|
+
return createCommonResult(response);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
logger.error('Exception getOrganisation:', e);
|
|
139
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
140
|
+
}
|
|
141
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@crmcom/self-service-sdk",
|
|
3
|
+
"version": "2.1.2",
|
|
4
|
+
"description": "Official CRM.COM Self-Service JavaScript SDK for consumer-facing API integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./httpUtil": "./httpUtil.js",
|
|
11
|
+
"./httpBackOfficeUtil": "./httpBackOfficeUtil.js",
|
|
12
|
+
"./authentication": "./authentication.js",
|
|
13
|
+
"./contacts": "./contacts.js",
|
|
14
|
+
"./orders": "./orders.js",
|
|
15
|
+
"./wallet": "./wallet.js",
|
|
16
|
+
"./payment": "./payment.js",
|
|
17
|
+
"./subscriptions": "./subscriptions.js",
|
|
18
|
+
"./rewards": "./rewards.js",
|
|
19
|
+
"./account": "./account.js",
|
|
20
|
+
"./communications": "./communications.js",
|
|
21
|
+
"./community": "./community.js",
|
|
22
|
+
"./config": "./config.js",
|
|
23
|
+
"./connectx": "./connectx.js",
|
|
24
|
+
"./organisations": "./organisations.js",
|
|
25
|
+
"./servicerequest": "./servicerequest.js",
|
|
26
|
+
"./jcccards": "./jcccards.js",
|
|
27
|
+
"./mobilepass": "./mobilepass.js",
|
|
28
|
+
"./paymentgateway": "./paymentgateway.js",
|
|
29
|
+
"./payouts": "./payouts.js",
|
|
30
|
+
"./dataUtil": "./dataUtil.js",
|
|
31
|
+
"./resultUtil": "./resultUtil.js",
|
|
32
|
+
"./eventListener": "./eventListener.js",
|
|
33
|
+
"./logger": "./logger.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"*.js",
|
|
37
|
+
"*.d.ts",
|
|
38
|
+
"!add_imports.ps1"
|
|
39
|
+
],
|
|
40
|
+
"keywords": [
|
|
41
|
+
"crm",
|
|
42
|
+
"crm.com",
|
|
43
|
+
"sdk",
|
|
44
|
+
"api",
|
|
45
|
+
"loyalty",
|
|
46
|
+
"rewards",
|
|
47
|
+
"wallet",
|
|
48
|
+
"payments",
|
|
49
|
+
"orders",
|
|
50
|
+
"subscriptions"
|
|
51
|
+
],
|
|
52
|
+
"author": "CRM.COM",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"jwt-decode": ">=3.0.0",
|
|
56
|
+
"js-sha256": ">=0.9.0",
|
|
57
|
+
"xml2js": ">=0.4.0"
|
|
58
|
+
},
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://bitbucket.org/nicostella/shared_libs_v2.git"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/payment.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { httpUtil } from './httpUtil'
|
|
2
|
+
import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
|
|
3
|
+
import { wallet } from './wallet';
|
|
4
|
+
import { logger } from './logger';
|
|
5
|
+
|
|
6
|
+
export const payment = {
|
|
7
|
+
getListPaymentMethods,
|
|
8
|
+
addPaymentMethod,
|
|
9
|
+
removePaymentMethod,
|
|
10
|
+
createPaymentForm,
|
|
11
|
+
createFormToAddCard,
|
|
12
|
+
setPrimaryCard,
|
|
13
|
+
addPaymentMethodV2,
|
|
14
|
+
getFormAddCard,
|
|
15
|
+
getPaymentForm,
|
|
16
|
+
createTopup,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function getListPaymentMethods({
|
|
20
|
+
include_total,
|
|
21
|
+
page = 1,
|
|
22
|
+
size = 10,
|
|
23
|
+
sort,
|
|
24
|
+
order,
|
|
25
|
+
support_payouts,
|
|
26
|
+
financial_types,
|
|
27
|
+
is_rewards,
|
|
28
|
+
} = {}) {
|
|
29
|
+
try {
|
|
30
|
+
let id = httpUtil.getSession().sub;
|
|
31
|
+
//console.log('API: ', contact)
|
|
32
|
+
let response = await httpUtil.get({
|
|
33
|
+
resourcePath: "/v2/contacts/" + id + "/payment_methods",
|
|
34
|
+
queryParams: {
|
|
35
|
+
include_total,
|
|
36
|
+
page,
|
|
37
|
+
size,
|
|
38
|
+
sort,
|
|
39
|
+
order,
|
|
40
|
+
support_payouts,
|
|
41
|
+
financial_types,
|
|
42
|
+
is_rewards,
|
|
43
|
+
},
|
|
44
|
+
withAccessToken: true,
|
|
45
|
+
});
|
|
46
|
+
return createCommonResult(response);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
logger.error("Exception getContactPurchases:", e);
|
|
49
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function addPaymentMethod({
|
|
54
|
+
name,
|
|
55
|
+
contact_id,
|
|
56
|
+
is_primary,
|
|
57
|
+
is_backup,
|
|
58
|
+
payment_method_type,
|
|
59
|
+
notes,
|
|
60
|
+
email,
|
|
61
|
+
phone,
|
|
62
|
+
country_code,
|
|
63
|
+
card_info,
|
|
64
|
+
gateway_name,
|
|
65
|
+
gateway_token,
|
|
66
|
+
integration_id
|
|
67
|
+
}, { }) {
|
|
68
|
+
try {
|
|
69
|
+
let id = httpUtil.getSession().sub;
|
|
70
|
+
let wallet = null;
|
|
71
|
+
let card = null;
|
|
72
|
+
if (payment_method_type == 'WALLET') {
|
|
73
|
+
wallet = {
|
|
74
|
+
gateway_token: [{
|
|
75
|
+
gateway: gateway_name ? gateway_name : null,
|
|
76
|
+
integration_id: integration_id,
|
|
77
|
+
token: gateway_token
|
|
78
|
+
}]
|
|
79
|
+
}
|
|
80
|
+
if (email) {
|
|
81
|
+
wallet.email = email;
|
|
82
|
+
}
|
|
83
|
+
if (phone) {
|
|
84
|
+
wallet.phone_details = {
|
|
85
|
+
number: phone,
|
|
86
|
+
country_code: country_code
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (payment_method_type == 'CARD') {
|
|
91
|
+
card = {
|
|
92
|
+
...card_info,
|
|
93
|
+
gateway_token: [{
|
|
94
|
+
integration_id: integration_id,
|
|
95
|
+
token: gateway_token,
|
|
96
|
+
gateway: gateway_name,
|
|
97
|
+
}]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
let response = await httpUtil.post({
|
|
101
|
+
resourcePath: "/v2/contacts/" + id + "/payment_methods",
|
|
102
|
+
body: {
|
|
103
|
+
name,
|
|
104
|
+
contact_id,
|
|
105
|
+
payment_method_type,
|
|
106
|
+
is_primary,
|
|
107
|
+
is_backup,
|
|
108
|
+
notes,
|
|
109
|
+
wallet,
|
|
110
|
+
card
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return createCommonResult(response);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
logger.error("Exception addPaymentMethod:", e);
|
|
116
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function addPaymentMethodV2({
|
|
121
|
+
name,
|
|
122
|
+
is_primary,
|
|
123
|
+
payment_method_type,
|
|
124
|
+
account_debit,
|
|
125
|
+
wallet,
|
|
126
|
+
card,
|
|
127
|
+
contact_id,
|
|
128
|
+
}) {
|
|
129
|
+
try {
|
|
130
|
+
let id = httpUtil.getSession().sub;
|
|
131
|
+
if (!contact_id) contact_id = id;
|
|
132
|
+
let response = await httpUtil.post({
|
|
133
|
+
resourcePath: "/v2/contacts/" + id + "/payment_methods",
|
|
134
|
+
body: {
|
|
135
|
+
name,
|
|
136
|
+
is_primary,
|
|
137
|
+
payment_method_type,
|
|
138
|
+
account_debit,
|
|
139
|
+
wallet,
|
|
140
|
+
card,
|
|
141
|
+
contact_id,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return createCommonResult(response);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
logger.error("Exception addPaymentMethodV2:", e);
|
|
147
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function removePaymentMethod(paymentMethodId) {
|
|
152
|
+
try {
|
|
153
|
+
let id = httpUtil.getSession().sub;
|
|
154
|
+
let response = await httpUtil.sendDelete({
|
|
155
|
+
resourcePath: '/v2/contacts/' + id + '/payment_methods/' + paymentMethodId,
|
|
156
|
+
});
|
|
157
|
+
return createCommonResult(response);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
logger.error('Exception removePaymentMethod:', e);
|
|
160
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function createPaymentForm({
|
|
165
|
+
topup_amount,
|
|
166
|
+
payment_method_id,
|
|
167
|
+
redirect_url,
|
|
168
|
+
estimation_id,
|
|
169
|
+
}) {
|
|
170
|
+
try {
|
|
171
|
+
let response = await httpUtil.get({
|
|
172
|
+
resourcePath: '/v2/jcc/payment_form',
|
|
173
|
+
withAccessToken: true,
|
|
174
|
+
queryParams: {
|
|
175
|
+
topup_amount,
|
|
176
|
+
payment_method_id,
|
|
177
|
+
redirect_url,
|
|
178
|
+
estimation_id
|
|
179
|
+
},
|
|
180
|
+
returnText: true
|
|
181
|
+
});
|
|
182
|
+
return createCommonResult(response);
|
|
183
|
+
} catch (e) {
|
|
184
|
+
logger.error('Exception createPaymentFormTopup:', e);
|
|
185
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function createFormToAddCard(redirect_url) {
|
|
190
|
+
let plus_path = "";
|
|
191
|
+
if (redirect_url) {
|
|
192
|
+
plus_path = "&redirect_url=" + redirect_url
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
let response = await httpUtil.get({
|
|
196
|
+
resourcePath: "/v1/jcc/form?action=CREATE" + plus_path,
|
|
197
|
+
withAccessToken: true,
|
|
198
|
+
returnText: true,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
return createCommonResult(response);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
logger.error("Exception createFormToAddCard:", e);
|
|
204
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function setPrimaryCard(payment_method_id) {
|
|
209
|
+
try {
|
|
210
|
+
let id = httpUtil.getSession().sub;
|
|
211
|
+
let response = await httpUtil.put({
|
|
212
|
+
// resourcePath: "/v2/contacts/" + id + "/payment_methods/" + payment_method_id,
|
|
213
|
+
resourcePath: "/v1/contacts/" + id + "/payment_methods/" + payment_method_id,
|
|
214
|
+
body: {
|
|
215
|
+
is_primary: true
|
|
216
|
+
},
|
|
217
|
+
withAccessToken: true,
|
|
218
|
+
});
|
|
219
|
+
return createCommonResult(response);
|
|
220
|
+
} catch (e) {
|
|
221
|
+
logger.error("Exception setPrimaryCard:", e);
|
|
222
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function getFormAddCard({
|
|
227
|
+
integration_id,
|
|
228
|
+
device_type,
|
|
229
|
+
redirect_url,
|
|
230
|
+
currency_code,
|
|
231
|
+
back_url,
|
|
232
|
+
back_url_name
|
|
233
|
+
}) {
|
|
234
|
+
try {
|
|
235
|
+
let response = await httpUtil.get({
|
|
236
|
+
resourcePath: '/v2/hosted_pages/payment_methods',
|
|
237
|
+
withAccessToken: true,
|
|
238
|
+
queryParams: {
|
|
239
|
+
integration_id,
|
|
240
|
+
device_type,
|
|
241
|
+
redirect_url,
|
|
242
|
+
currency_code,
|
|
243
|
+
back_url,
|
|
244
|
+
back_url_name
|
|
245
|
+
},
|
|
246
|
+
returnText: true
|
|
247
|
+
});
|
|
248
|
+
return createCommonResult(response);
|
|
249
|
+
} catch (e) {
|
|
250
|
+
logger.error('Exception getFormAddCard:', e);
|
|
251
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function getPaymentForm({
|
|
256
|
+
integration_id,
|
|
257
|
+
device_type,
|
|
258
|
+
redirect_url,
|
|
259
|
+
currency_code,
|
|
260
|
+
amount,
|
|
261
|
+
estimation_id,
|
|
262
|
+
payment_method_id,
|
|
263
|
+
type,
|
|
264
|
+
header_accept,
|
|
265
|
+
header_accept_language,
|
|
266
|
+
browser_color_depth,
|
|
267
|
+
browser_screen_height,
|
|
268
|
+
browser_screen_width,
|
|
269
|
+
browser_java_enabled,
|
|
270
|
+
time_zone_offset,
|
|
271
|
+
user_agent,
|
|
272
|
+
back_url,
|
|
273
|
+
back_url_name
|
|
274
|
+
}) {
|
|
275
|
+
try {
|
|
276
|
+
let response = await httpUtil.get({
|
|
277
|
+
resourcePath: '/v2/hosted_pages/payments',
|
|
278
|
+
withAccessToken: true,
|
|
279
|
+
queryParams: {
|
|
280
|
+
integration_id,
|
|
281
|
+
device_type,
|
|
282
|
+
redirect_url,
|
|
283
|
+
currency_code,
|
|
284
|
+
amount,
|
|
285
|
+
estimation_id,
|
|
286
|
+
payment_method_id,
|
|
287
|
+
type,
|
|
288
|
+
header_accept,
|
|
289
|
+
header_accept_language,
|
|
290
|
+
browser_color_depth,
|
|
291
|
+
browser_screen_height,
|
|
292
|
+
browser_screen_width,
|
|
293
|
+
browser_java_enabled,
|
|
294
|
+
time_zone_offset,
|
|
295
|
+
user_agent,
|
|
296
|
+
back_url,
|
|
297
|
+
back_url_name
|
|
298
|
+
},
|
|
299
|
+
returnText: true
|
|
300
|
+
});
|
|
301
|
+
return createCommonResult(response);
|
|
302
|
+
} catch (e) {
|
|
303
|
+
logger.error('Exception getPaymentForm:', e);
|
|
304
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function createTopup({
|
|
309
|
+
amount,
|
|
310
|
+
wallet_id,
|
|
311
|
+
code,
|
|
312
|
+
payment_method,
|
|
313
|
+
client_secret,
|
|
314
|
+
commerce_pool_id,
|
|
315
|
+
}) {
|
|
316
|
+
try {
|
|
317
|
+
if(!wallet_id) {
|
|
318
|
+
wallet_id = await wallet.getWalletId();
|
|
319
|
+
}
|
|
320
|
+
let response = await httpUtil.post({
|
|
321
|
+
resourcePath: '/v2/topups',
|
|
322
|
+
withAccessToken: true,
|
|
323
|
+
body: {
|
|
324
|
+
amount: amount,
|
|
325
|
+
wallet_id,
|
|
326
|
+
code,
|
|
327
|
+
payment_method,
|
|
328
|
+
client_secret,
|
|
329
|
+
commerce_pool_id,
|
|
330
|
+
},
|
|
331
|
+
returnText: true
|
|
332
|
+
});
|
|
333
|
+
return createCommonResult(response);
|
|
334
|
+
} catch (e) {
|
|
335
|
+
logger.error('Exception createTopup:', e);
|
|
336
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { httpUtil } from './httpUtil'
|
|
2
|
+
import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
|
|
3
|
+
import { logger } from './logger';
|
|
4
|
+
|
|
5
|
+
export const paymentgateway = {
|
|
6
|
+
getClientToken,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function getClientToken({
|
|
10
|
+
integration_id
|
|
11
|
+
} = {}) {
|
|
12
|
+
try {
|
|
13
|
+
let id = httpUtil.getSession().sub;
|
|
14
|
+
let response = await httpUtil.get({
|
|
15
|
+
resourcePath: "/v2/contacts/" + id + "/client_token",
|
|
16
|
+
queryParams: {
|
|
17
|
+
integration_id,
|
|
18
|
+
},
|
|
19
|
+
withAccessToken: true,
|
|
20
|
+
});
|
|
21
|
+
return createCommonResult(response);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
logger.error("Exception getClientToken:", e);
|
|
24
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
25
|
+
}
|
|
26
|
+
}
|
package/payouts.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { httpUtil } from './httpUtil'
|
|
2
|
+
import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
|
|
3
|
+
import { wallet } from './wallet'
|
|
4
|
+
import { logger } from './logger';
|
|
5
|
+
|
|
6
|
+
export const payouts = {
|
|
7
|
+
createPayout,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function createPayout({
|
|
11
|
+
wallet_id,
|
|
12
|
+
amount,
|
|
13
|
+
payment_method,
|
|
14
|
+
}) {
|
|
15
|
+
try {
|
|
16
|
+
if (!wallet_id) {
|
|
17
|
+
wallet_id = await wallet.getWalletId();
|
|
18
|
+
}
|
|
19
|
+
let response = await httpUtil.post({
|
|
20
|
+
resourcePath: "/v2/payouts",
|
|
21
|
+
body: {
|
|
22
|
+
wallet_id,
|
|
23
|
+
amount,
|
|
24
|
+
payment_method,
|
|
25
|
+
},
|
|
26
|
+
withAccessToken: true,
|
|
27
|
+
});
|
|
28
|
+
return createCommonResult(response);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
logger.error("Exception createPayout:", e);
|
|
31
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
32
|
+
}
|
|
33
|
+
}
|
package/resultUtil.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { logger } from './logger';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const ErrorCodes = {
|
|
5
|
+
OK: 'OK',
|
|
6
|
+
UNKNOWN: 'UNKNOWN',
|
|
7
|
+
UNCLASSIFIED_ERROR: 'UNCLASSIFIED_ERROR',
|
|
8
|
+
REGISTRATION_FAIL_CONTACT_EXISTS: 'REGISTRATION_FAIL_CONTACT_EXISTS',
|
|
9
|
+
INVALID_LOGIN: 'INVALID_LOGIN',
|
|
10
|
+
ACCOUNT_NOT_FOUND: 'ACCOUNT_NOT_FOUND',
|
|
11
|
+
ADD_ADDRESS_ALREADY_TYPE: 'ADD_ADDRESS_ALREADY_TYPE',
|
|
12
|
+
FORGOT_EMAIL_NOT_FOUND_EXCEPTION: 'FORGOT_EMAIL_NOT_FOUND_EXCEPTION',
|
|
13
|
+
PHONE_NUMBER_ALREADY_EXIST: 'PHONE_NUMBER_ALREADY_EXIST',
|
|
14
|
+
CAN_NOT_FULFILL_ORDER_EXCEPTION: 'CAN_NOT_FULFILL_ORDER_EXCEPTION',
|
|
15
|
+
MINIMUM_ORDER_AMOUNT_NOT_REACHED: 'MINIMUM_ORDER_AMOUNT_NOT_REACHED',
|
|
16
|
+
SIGN_UP_ORGANISATION_ALREADY: 'SIGN_UP_ORGANISATION_ALREADY',
|
|
17
|
+
CONTACTUNIQUELYIDENTIFYEXCEPTION: 'CONTACTUNIQUELYIDENTIFYEXCEPTION',
|
|
18
|
+
NOTFOUNDEXCEPTION: 'NOTFOUNDEXCEPTION',
|
|
19
|
+
EMAIL_NOT_VERIFIED: 'EMAIL_NOT_VERIFIED',
|
|
20
|
+
CARD_ALREADY_EXIT: 'CARD_ALREADY_EXIT',
|
|
21
|
+
CARD_NOT_FOUND: 'CARD_NOT_FOUND',
|
|
22
|
+
INVALID_PASSWORD_EXCEPTION: 'INVALID_PASSWORD_EXCEPTION',
|
|
23
|
+
PASSWORD_LENGTH_EXCEPTION: 'PASSWORD_LENGTH_EXCEPTION',
|
|
24
|
+
PAYMENT_GATEWAY_EXCEPTION: 'PAYMENT_GATEWAY_EXCEPTION',
|
|
25
|
+
CUSTOMER_EMAIL_ALREADY_EXIST: 'CUSTOMER_EMAIL_ALREADY_EXIST',
|
|
26
|
+
TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS",
|
|
27
|
+
TOO_MANY_RECIPIENTS_EXCEPTION: "TOO_MANY_RECIPIENTS_EXCEPTION",
|
|
28
|
+
SPEND_AMOUNT_NOT_FULLY_COVERED_EXCEPTION: 'SPEND_AMOUNT_NOT_FULLY_COVERED_EXCEPTION',
|
|
29
|
+
REDEEM_PASS_INVALID: "REDEEM_PASS_INVALID",
|
|
30
|
+
REDEEM_PASS_NOT_ACTIVE: "REDEEM_PASS_NOT_ACTIVE",
|
|
31
|
+
REDEEM_PASS_PIN_MANDATORY: "REDEEM_PASS_PIN_MANDATORY",
|
|
32
|
+
REDEEM_PASS_USED: "REDEEM_PASS_USED",
|
|
33
|
+
SERVICE_ALREADY_EXIST: "SERVICE_ALREADY_EXIST",
|
|
34
|
+
CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION: 'CANNOTEXECUTEACTIONCREDITLIMITEXCEPTION',
|
|
35
|
+
CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION: 'CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION',
|
|
36
|
+
CANNOTUNREGISTERCONTACTEXCEPTION: 'CANNOTUNREGISTERCONTACTEXCEPTION',
|
|
37
|
+
CANNOTEXECUTESUBSCRIPTIONACTIONEXCEPTION: 'CANNOTEXECUTESUBSCRIPTIONACTIONEXCEPTION',
|
|
38
|
+
INVALIDVALUEEXCEPTION: "INVALIDVALUEEXCEPTION",
|
|
39
|
+
MULTIPLECONTACTSSAMEPHONEEXCEPTION: "MULTIPLECONTACTSSAMEPHONEEXCEPTION",
|
|
40
|
+
COMMUNITYPARENTCHILDEXCEPTION: "COMMUNITYPARENTCHILDEXCEPTION",
|
|
41
|
+
CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION: "CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION",
|
|
42
|
+
INVALIDENTITYLIFECYCLESTATEEXCEPTION: "INVALIDENTITYLIFECYCLESTATEEXCEPTION"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createResult(errorCode, data) {
|
|
46
|
+
return {
|
|
47
|
+
code: errorCode,
|
|
48
|
+
data: data
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createCommonResult(response, requestType) {
|
|
53
|
+
logger.debug("createCommonResult response:", response);
|
|
54
|
+
if (response.code == 'OK' || response.code == '204')
|
|
55
|
+
return createResult(ErrorCodes.OK, response.data);
|
|
56
|
+
else if (response.code == '429') {
|
|
57
|
+
return createResult(ErrorCodes.TOO_MANY_REQUESTS, response.error);
|
|
58
|
+
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.SPENDAMOUNTNOTFULLYCOVEREDEXCEPTION") {
|
|
59
|
+
return createResult(ErrorCodes.SPEND_AMOUNT_NOT_FULLY_COVERED_EXCEPTION, response.error);
|
|
60
|
+
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CANNOTUNREGISTERCONTACTEXCEPTION") {
|
|
61
|
+
return createResult(ErrorCodes.CANNOTUNREGISTERCONTACTEXCEPTION, response.error)
|
|
62
|
+
} else if (response.error && response.error.error == "CRM.EXCEPTIONS.INVALIDVALUEEXCEPTION") {
|
|
63
|
+
return createResult(ErrorCodes.INVALIDVALUEEXCEPTION, response.error)
|
|
64
|
+
} else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CONTACTUNIQUELYIDENTIFYEXCEPTION") {
|
|
65
|
+
return createResult(ErrorCodes.CONTACTUNIQUELYIDENTIFYEXCEPTION, response.error)
|
|
66
|
+
} else if (response.error && response.error.error == "CRM.EXCEPTIONS.ALREADYEXISTSEXCEPTION") {
|
|
67
|
+
return createResult(ErrorCodes.CUSTOMER_EMAIL_ALREADY_EXIST, response.error)
|
|
68
|
+
} else if (response.error && response.error.error == "CRM.EXCEPTIONS.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION") {
|
|
69
|
+
return createResult(ErrorCodes.CANNOTSPENDAMOUNTWALLETBALANCENOTENOUGHEXCEPTION, response.error)
|
|
70
|
+
}else if (response.error && response.error.error == "CRM.EXCEPTIONS.NOTFOUNDEXCEPTION") {
|
|
71
|
+
return createResult(ErrorCodes.NOTFOUNDEXCEPTION, response.error)
|
|
72
|
+
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.MULTIPLECONTACTSSAMEPHONEEXCEPTION") {
|
|
73
|
+
return createResult(ErrorCodes.MULTIPLECONTACTSSAMEPHONEEXCEPTION, response.error)
|
|
74
|
+
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.COMMUNITYPARENTCHILDEXCEPTION") {
|
|
75
|
+
return createResult(ErrorCodes.COMMUNITYPARENTCHILDEXCEPTION, response.error)
|
|
76
|
+
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION") {
|
|
77
|
+
return createResult(ErrorCodes.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION, response.error)
|
|
78
|
+
}else if (response.error && response.error.error == "COM.CRM.EXCEPTIONS.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION") {
|
|
79
|
+
return createResult(ErrorCodes.CIMALREADYEXISTSFORANOTHERCONTACTEXCEPTION, response.error)
|
|
80
|
+
}else if (response.error && response.error.error == "CRM.EXCEPTIONS.INVALIDENTITYLIFECYCLESTATEEXCEPTION") {
|
|
81
|
+
return createResult(ErrorCodes.INVALIDENTITYLIFECYCLESTATEEXCEPTION, response.error)
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
85
|
+
}
|
|
86
|
+
}
|