@spreeloop/orange_money 1.0.7 → 1.0.9
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/package.json +4 -1
- package/.eslintrc.js +0 -47
- package/.prettierrc +0 -6
- package/babel.config.js +0 -3
- package/index.spec.ts +0 -9
- package/index.ts +0 -1
- package/jest.before-test.ts +0 -3
- package/jest.config.ts +0 -54
- package/src/disbursements/implementations/disbursement_service.ts +0 -133
- package/src/disbursements/implementations/src/live.ts +0 -79
- package/src/disbursements/implementations/src/sandbox.ts +0 -124
- package/src/disbursements/operations/create_access_token.spec.ts +0 -87
- package/src/disbursements/operations/create_access_token.ts +0 -83
- package/src/disbursements/operations/get_transfer_status.spec.ts +0 -132
- package/src/disbursements/operations/get_transfer_status.ts +0 -265
- package/src/disbursements/operations/transfer.spec.ts +0 -158
- package/src/disbursements/operations/transfer.ts +0 -125
- package/src/disbursements/routes/routes.ts +0 -54
- package/src/disbursements/utils/constants.ts +0 -4
- package/src/disbursements/utils/regex.spec.ts +0 -39
- package/src/disbursements/utils/regex.ts +0 -10
- package/src/disbursements/utils/status.ts +0 -62
- package/src/disbursements/utils/utils.spec.ts +0 -42
- package/src/disbursements/utils/utils.ts +0 -24
- package/src/index.ts +0 -12
- package/src/payments/implementations/fake.ts +0 -133
- package/src/payments/implementations/live.ts +0 -87
- package/src/payments/operations/get_access_token.spec.ts +0 -60
- package/src/payments/operations/get_access_token.ts +0 -77
- package/src/payments/operations/get_pay_token.spec.ts +0 -65
- package/src/payments/operations/get_pay_token.ts +0 -66
- package/src/payments/operations/get_payment_status.spec.ts +0 -82
- package/src/payments/operations/get_payment_status.ts +0 -78
- package/src/payments/operations/initialize_om_payment.spec.ts +0 -234
- package/src/payments/operations/initialize_om_payment.ts +0 -191
- package/src/payments/payments.ts +0 -86
- package/src/payments/routes/routes.ts +0 -61
- package/src/payments/utils/constants.ts +0 -120
- package/src/payments/utils/joi_schema.ts +0 -117
- package/src/payments/utils/request_model.ts +0 -103
- package/src/payments/utils/utils.ts +0 -31
- package/src/utils/https.spec.ts +0 -101
- package/src/utils/https.ts +0 -266
- package/src/utils/logging_interface.ts +0 -25
- package/src/utils/operation_response.ts +0 -17
- package/src/utils/utils.ts +0 -5
- package/tsconfig.build.json +0 -4
- package/tsconfig.dev.json +0 -4
- package/tsconfig.json +0 -27
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { Logger } from '../../../../logging/src/logging';
|
|
3
|
-
import * as requests from '../../utils/https';
|
|
4
|
-
import { DisbursementXTargetEnvironmentType } from '../utils/constants';
|
|
5
|
-
import { DisbursementApiRawStatus, DisbursementStatus } from '../utils/status';
|
|
6
|
-
import { DisbursementStep, getTransferStatus } from './get_transfer_status';
|
|
7
|
-
|
|
8
|
-
describe('getTransferStatus', () => {
|
|
9
|
-
it('should fail on invalid parameter provided', async () => {
|
|
10
|
-
const { error, data, raw } = await getTransferStatus({
|
|
11
|
-
configs: {
|
|
12
|
-
channelUserMsisdn: '',
|
|
13
|
-
clientId: '',
|
|
14
|
-
clientSecret: '',
|
|
15
|
-
customerKey: '',
|
|
16
|
-
customerSecret: '',
|
|
17
|
-
pin: '',
|
|
18
|
-
environment: DisbursementXTargetEnvironmentType.sandbox,
|
|
19
|
-
logger: new Logger(),
|
|
20
|
-
},
|
|
21
|
-
params: {
|
|
22
|
-
token: 55 as unknown as string,
|
|
23
|
-
messageId: 'messageId',
|
|
24
|
-
},
|
|
25
|
-
endPoint: 'https://example.com',
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(data).not.toBeDefined();
|
|
29
|
-
expect(raw).not.toBeDefined();
|
|
30
|
-
expect(error).toBeDefined();
|
|
31
|
-
});
|
|
32
|
-
it('should fail on request failure', async () => {
|
|
33
|
-
const requestSpy = jest
|
|
34
|
-
.spyOn(requests, 'getRequest')
|
|
35
|
-
.mockImplementation()
|
|
36
|
-
.mockResolvedValue({
|
|
37
|
-
error: {},
|
|
38
|
-
});
|
|
39
|
-
const { error, data, raw } = await getTransferStatus({
|
|
40
|
-
configs: {
|
|
41
|
-
channelUserMsisdn: '237699947943',
|
|
42
|
-
clientId: 'clientId',
|
|
43
|
-
clientSecret: 'clientSecret',
|
|
44
|
-
customerKey: 'customerKey',
|
|
45
|
-
customerSecret: 'customerSecret',
|
|
46
|
-
pin: 'pin',
|
|
47
|
-
environment: DisbursementXTargetEnvironmentType.sandbox,
|
|
48
|
-
logger: new Logger(),
|
|
49
|
-
},
|
|
50
|
-
params: {
|
|
51
|
-
token: 'token',
|
|
52
|
-
messageId: 'messageId',
|
|
53
|
-
},
|
|
54
|
-
endPoint: 'https://example.com',
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
expect(data).not.toBeDefined();
|
|
58
|
-
expect(raw).not.toBeDefined();
|
|
59
|
-
expect(requestSpy).toHaveBeenCalledTimes(1);
|
|
60
|
-
expect(error).toBeDefined();
|
|
61
|
-
});
|
|
62
|
-
it('should succeed on request succeed', async () => {
|
|
63
|
-
const succeedEg = {
|
|
64
|
-
result: {
|
|
65
|
-
message: 'message',
|
|
66
|
-
data: {
|
|
67
|
-
createtime: 'createtime',
|
|
68
|
-
subscriberMsisdn: 'subscriberMsisdn',
|
|
69
|
-
amount: 500,
|
|
70
|
-
payToken: 'payToken',
|
|
71
|
-
txnid: 'txnid',
|
|
72
|
-
txnmode: 'txnmode',
|
|
73
|
-
txnstatus: 'txnstatus',
|
|
74
|
-
orderId: 'orderId',
|
|
75
|
-
status: DisbursementApiRawStatus.succeeded,
|
|
76
|
-
channelUserMsisdn: 'channelUserMsisdn',
|
|
77
|
-
description: 'description',
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
parameters: {
|
|
81
|
-
amount: 500,
|
|
82
|
-
xauth: 'xauth',
|
|
83
|
-
channel_user_msisdn: 'channel_user_msisdn',
|
|
84
|
-
customer_key: 'customer_key',
|
|
85
|
-
customer_secret: 'customer_secret',
|
|
86
|
-
final_customer_name: 'final_customer_name',
|
|
87
|
-
final_customer_phone: 'final_customer_phone',
|
|
88
|
-
},
|
|
89
|
-
CreateAt: 'CreateAt',
|
|
90
|
-
MessageId: 'MessageId',
|
|
91
|
-
RefundStep: DisbursementStep.TransferSent,
|
|
92
|
-
};
|
|
93
|
-
const requestSpy = jest
|
|
94
|
-
.spyOn(requests, 'getRequest')
|
|
95
|
-
.mockImplementation()
|
|
96
|
-
.mockResolvedValue({
|
|
97
|
-
response: { data: Object(succeedEg) } as AxiosResponse<
|
|
98
|
-
unknown,
|
|
99
|
-
unknown
|
|
100
|
-
>,
|
|
101
|
-
});
|
|
102
|
-
const { error, data, raw } = await getTransferStatus({
|
|
103
|
-
configs: {
|
|
104
|
-
channelUserMsisdn: '237699947943',
|
|
105
|
-
clientId: 'clientId',
|
|
106
|
-
clientSecret: 'clientSecret',
|
|
107
|
-
customerKey: 'customerKey',
|
|
108
|
-
customerSecret: 'customerSecret',
|
|
109
|
-
pin: 'pin',
|
|
110
|
-
environment: DisbursementXTargetEnvironmentType.sandbox,
|
|
111
|
-
logger: new Logger(),
|
|
112
|
-
},
|
|
113
|
-
params: {
|
|
114
|
-
token: 'token',
|
|
115
|
-
messageId: 'messageId',
|
|
116
|
-
},
|
|
117
|
-
endPoint: 'https://example.com',
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
expect(error).not.toBeDefined();
|
|
121
|
-
expect(requestSpy).toHaveBeenCalledTimes(1);
|
|
122
|
-
expect(raw).toEqual(succeedEg);
|
|
123
|
-
expect(
|
|
124
|
-
(raw as { parameters?: { customer_secret?: unknown } })?.parameters
|
|
125
|
-
?.customer_secret
|
|
126
|
-
).toBeNull();
|
|
127
|
-
expect(data).toStrictEqual({
|
|
128
|
-
status: DisbursementStatus.succeeded,
|
|
129
|
-
refundStep: DisbursementStep.TransferSent,
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import { getRequest } from '../../utils/https';
|
|
3
|
-
import { OperationResponse } from '../../utils/operation_response';
|
|
4
|
-
import {
|
|
5
|
-
DisbursementServiceConfig,
|
|
6
|
-
DisbursementServiceConfigSchema,
|
|
7
|
-
} from '../implementations/disbursement_service';
|
|
8
|
-
import { DisbursementApiRawStatus, DisbursementStatus } from '../utils/status';
|
|
9
|
-
import { getStatusFromProviderRawStatus } from '../utils/utils';
|
|
10
|
-
export interface GetTransferStatusRequest {
|
|
11
|
-
token: string;
|
|
12
|
-
messageId: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const GetTransferStatusRequestSchema = Joi.object<GetTransferStatusRequest>({
|
|
16
|
-
token: Joi.string().required(),
|
|
17
|
-
messageId: Joi.string().required(),
|
|
18
|
-
}).required();
|
|
19
|
-
|
|
20
|
-
type GetTransferStatusResponseRawData =
|
|
21
|
-
| {
|
|
22
|
-
result: {
|
|
23
|
-
message: string;
|
|
24
|
-
data: {
|
|
25
|
-
createtime: string;
|
|
26
|
-
subscriberMsisdn: string;
|
|
27
|
-
amount: number;
|
|
28
|
-
payToken: string;
|
|
29
|
-
txnid: string;
|
|
30
|
-
txnmode: string;
|
|
31
|
-
txnstatus: string;
|
|
32
|
-
orderId: string;
|
|
33
|
-
status: DisbursementApiRawStatus;
|
|
34
|
-
channelUserMsisdn: string;
|
|
35
|
-
description: string;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
parameters?: {
|
|
39
|
-
amount: string;
|
|
40
|
-
xauth: string;
|
|
41
|
-
channel_user_msisdn: string;
|
|
42
|
-
customer_key: string;
|
|
43
|
-
customer_secret: string | null;
|
|
44
|
-
final_customer_name: string;
|
|
45
|
-
final_customer_phone: string;
|
|
46
|
-
};
|
|
47
|
-
CreateAt: string;
|
|
48
|
-
MessageId: string;
|
|
49
|
-
RefundStep: DisbursementStep;
|
|
50
|
-
}
|
|
51
|
-
| {
|
|
52
|
-
parameters?: {
|
|
53
|
-
amount: string;
|
|
54
|
-
xauth: string;
|
|
55
|
-
channel_user_msisdn: string;
|
|
56
|
-
customer_key: string;
|
|
57
|
-
customer_secret: string | null;
|
|
58
|
-
final_customer_name: string;
|
|
59
|
-
final_customer_phone: string;
|
|
60
|
-
};
|
|
61
|
-
message: string;
|
|
62
|
-
RefundStep: DisbursementStep;
|
|
63
|
-
}
|
|
64
|
-
| {
|
|
65
|
-
ErrorCode: number;
|
|
66
|
-
body: string;
|
|
67
|
-
ErrorMessage: string;
|
|
68
|
-
parameters?: {
|
|
69
|
-
amount: string;
|
|
70
|
-
xauth: string;
|
|
71
|
-
channel_user_msisdn: string;
|
|
72
|
-
customer_key: string;
|
|
73
|
-
customer_secret: string | null;
|
|
74
|
-
final_customer_name: string;
|
|
75
|
-
final_customer_phone: string;
|
|
76
|
-
};
|
|
77
|
-
CreateAt: string;
|
|
78
|
-
MessageId: string;
|
|
79
|
-
RefundStep: DisbursementStep;
|
|
80
|
-
}
|
|
81
|
-
| {
|
|
82
|
-
result: {
|
|
83
|
-
createtime: string;
|
|
84
|
-
toChannelMsisdn: string;
|
|
85
|
-
amount: 498925;
|
|
86
|
-
payToken: string;
|
|
87
|
-
txnid: string;
|
|
88
|
-
txnmode: string;
|
|
89
|
-
txnmessage: string;
|
|
90
|
-
txnstatus: string;
|
|
91
|
-
orderId: string;
|
|
92
|
-
status: DisbursementApiRawStatus;
|
|
93
|
-
fromChannelMsisdn: string;
|
|
94
|
-
description: string;
|
|
95
|
-
};
|
|
96
|
-
parameters: {
|
|
97
|
-
amount: string;
|
|
98
|
-
xauth: string;
|
|
99
|
-
channel_user_msisdn: string;
|
|
100
|
-
customer_key: string;
|
|
101
|
-
customer_secret: string | null;
|
|
102
|
-
final_customer_name: string;
|
|
103
|
-
final_customer_phone: string;
|
|
104
|
-
};
|
|
105
|
-
CreateAt: string;
|
|
106
|
-
RefundStep: DisbursementStep;
|
|
107
|
-
}
|
|
108
|
-
| string;
|
|
109
|
-
|
|
110
|
-
export enum DisbursementStep {
|
|
111
|
-
TransferSent = '2',
|
|
112
|
-
InitializingTransfer = '1',
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface responseData {
|
|
116
|
-
status?: DisbursementStatus;
|
|
117
|
-
refundStep?: DisbursementStep;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export type GetTransferStatusResponse = OperationResponse<
|
|
121
|
-
responseData,
|
|
122
|
-
GetTransferStatusResponseRawData
|
|
123
|
-
>;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Retrieves the transfer status of a transaction.
|
|
127
|
-
*
|
|
128
|
-
* @param {DisbursementServiceConfig} configs - The disbursement service config.
|
|
129
|
-
* @param {GetTransferStatusRequest} params - The parameters for retrieving the transfer status.
|
|
130
|
-
* @return {GetTransferStatusResponse} - The method response containing the transfer status.
|
|
131
|
-
*/
|
|
132
|
-
export async function getTransferStatus({
|
|
133
|
-
configs,
|
|
134
|
-
params,
|
|
135
|
-
endPoint,
|
|
136
|
-
}: {
|
|
137
|
-
configs: DisbursementServiceConfig;
|
|
138
|
-
params: GetTransferStatusRequest;
|
|
139
|
-
endPoint: string;
|
|
140
|
-
}): GetTransferStatusResponse {
|
|
141
|
-
const logger = configs.logger;
|
|
142
|
-
logger.info(
|
|
143
|
-
`getTransferStatus is running with params : ${JSON.stringify(params)}`
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const { error: configsValidationError, value: configsValues } =
|
|
147
|
-
DisbursementServiceConfigSchema.validate(configs);
|
|
148
|
-
|
|
149
|
-
if (configsValidationError) {
|
|
150
|
-
logger.error(
|
|
151
|
-
`Invalid DisbursementServiceConfig request parameters. params : ${JSON.stringify(
|
|
152
|
-
configsValidationError.details
|
|
153
|
-
)}`
|
|
154
|
-
);
|
|
155
|
-
return { error: configsValidationError.details };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const { error: paramsValidationError, value: paramsValue } =
|
|
159
|
-
GetTransferStatusRequestSchema.validate(params);
|
|
160
|
-
|
|
161
|
-
if (paramsValidationError) {
|
|
162
|
-
logger.error(
|
|
163
|
-
`Invalid getTransferStatus request parameters. params : ${JSON.stringify(
|
|
164
|
-
paramsValidationError
|
|
165
|
-
)}`
|
|
166
|
-
);
|
|
167
|
-
return { error: paramsValidationError };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const headers = {
|
|
171
|
-
Authorization: `Bearer ${paramsValue.token}`,
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const body = {
|
|
175
|
-
customerkey: configsValues.customerKey,
|
|
176
|
-
customersecret: configsValues.customerSecret,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const response = await getRequest<GetTransferStatusResponseRawData>({
|
|
180
|
-
logger: configsValues.logger,
|
|
181
|
-
route: endPoint,
|
|
182
|
-
headers: headers,
|
|
183
|
-
data: body,
|
|
184
|
-
rejectUnauthorized: false,
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
if (!response.response) {
|
|
188
|
-
return { error: response.error };
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const data = response.response.data;
|
|
192
|
-
|
|
193
|
-
if (typeof data === 'string') {
|
|
194
|
-
// Handle string response.
|
|
195
|
-
return { error: data };
|
|
196
|
-
} else if ('result' in data) {
|
|
197
|
-
// Remove the customer secret from the raw data, because
|
|
198
|
-
// it is a very sensitive secret.
|
|
199
|
-
if (data.parameters) {
|
|
200
|
-
data.parameters.customer_secret = null;
|
|
201
|
-
}
|
|
202
|
-
const rawStatus: DisbursementApiRawStatus =
|
|
203
|
-
'status' in data.result ? data.result.status : data.result.data.status;
|
|
204
|
-
const status = getStatusFromProviderRawStatus(rawStatus);
|
|
205
|
-
|
|
206
|
-
if (data.RefundStep === DisbursementStep.InitializingTransfer) {
|
|
207
|
-
return {
|
|
208
|
-
data: {
|
|
209
|
-
status:
|
|
210
|
-
status === DisbursementStatus.succeeded
|
|
211
|
-
? DisbursementStatus.pending
|
|
212
|
-
: status,
|
|
213
|
-
refundStep: data.RefundStep,
|
|
214
|
-
},
|
|
215
|
-
raw: data,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
data: {
|
|
221
|
-
status: status,
|
|
222
|
-
refundStep: data.RefundStep,
|
|
223
|
-
},
|
|
224
|
-
raw: data,
|
|
225
|
-
};
|
|
226
|
-
} else if ('ErrorCode' in data) {
|
|
227
|
-
if (data.parameters) {
|
|
228
|
-
data.parameters.customer_secret = null;
|
|
229
|
-
}
|
|
230
|
-
if (data.ErrorCode === 5019) {
|
|
231
|
-
return {
|
|
232
|
-
data: {
|
|
233
|
-
status: DisbursementStatus.failed,
|
|
234
|
-
refundStep: data.RefundStep,
|
|
235
|
-
},
|
|
236
|
-
raw: data,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
configsValues.logger.error(
|
|
240
|
-
`Unexpected ErrorCode : ${JSON.stringify(data)}`
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
data: {
|
|
245
|
-
status: DisbursementStatus.pending,
|
|
246
|
-
refundStep: data.RefundStep,
|
|
247
|
-
},
|
|
248
|
-
raw: data,
|
|
249
|
-
};
|
|
250
|
-
} else if (data.RefundStep === DisbursementStep.InitializingTransfer) {
|
|
251
|
-
if (data.parameters) {
|
|
252
|
-
data.parameters.customer_secret = null;
|
|
253
|
-
}
|
|
254
|
-
return {
|
|
255
|
-
data: {
|
|
256
|
-
status: DisbursementStatus.pending,
|
|
257
|
-
refundStep: data.RefundStep,
|
|
258
|
-
},
|
|
259
|
-
raw: data,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// By default, assume we failed to retrieve the disbursement status.
|
|
264
|
-
return { error: data };
|
|
265
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { Logger } from '../../../../logging/src/logging';
|
|
3
|
-
import * as requests from '../../utils/https';
|
|
4
|
-
import { DisbursementXTargetEnvironmentType } from '../utils/constants';
|
|
5
|
-
import { transfer } from './transfer';
|
|
6
|
-
|
|
7
|
-
describe('transfer', () => {
|
|
8
|
-
it('should fail on invalid parameter provided', async () => {
|
|
9
|
-
const { error, data, raw } = await transfer({
|
|
10
|
-
configs: {
|
|
11
|
-
channelUserMsisdn: '',
|
|
12
|
-
clientId: '',
|
|
13
|
-
clientSecret: '',
|
|
14
|
-
customerKey: '',
|
|
15
|
-
customerSecret: '',
|
|
16
|
-
pin: '',
|
|
17
|
-
environment: DisbursementXTargetEnvironmentType.sandbox,
|
|
18
|
-
logger: new Logger(),
|
|
19
|
-
},
|
|
20
|
-
params: {
|
|
21
|
-
webhook: '',
|
|
22
|
-
amount: 0,
|
|
23
|
-
customerPhone: '',
|
|
24
|
-
customerName: '',
|
|
25
|
-
token: '',
|
|
26
|
-
},
|
|
27
|
-
endPoint: '',
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
expect(data).not.toBeDefined();
|
|
31
|
-
expect(raw).not.toBeDefined();
|
|
32
|
-
expect(error).toBeDefined();
|
|
33
|
-
});
|
|
34
|
-
it('should fail on invalid phone number provided provided', async () => {
|
|
35
|
-
const { error, data, raw } = await transfer({
|
|
36
|
-
configs: {
|
|
37
|
-
channelUserMsisdn: '237699947943',
|
|
38
|
-
clientId: 'clientId',
|
|
39
|
-
clientSecret: 'clientSecret',
|
|
40
|
-
customerKey: 'customerKey',
|
|
41
|
-
customerSecret: 'customerSecret',
|
|
42
|
-
pin: 'pin',
|
|
43
|
-
environment: DisbursementXTargetEnvironmentType.sandbox,
|
|
44
|
-
logger: new Logger(),
|
|
45
|
-
},
|
|
46
|
-
params: {
|
|
47
|
-
webhook: 'https://example.com',
|
|
48
|
-
amount: 100,
|
|
49
|
-
customerPhone: '69532652',
|
|
50
|
-
customerName: 'itachi uchiwa',
|
|
51
|
-
token: 'token',
|
|
52
|
-
},
|
|
53
|
-
endPoint: 'https://example.com',
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
expect(data).not.toBeDefined();
|
|
57
|
-
expect(raw).not.toBeDefined();
|
|
58
|
-
expect(error).toBeDefined();
|
|
59
|
-
});
|
|
60
|
-
it('should fail on request failure', async () => {
|
|
61
|
-
const postSpy = jest
|
|
62
|
-
.spyOn(requests, 'postRequest')
|
|
63
|
-
.mockImplementation()
|
|
64
|
-
.mockResolvedValue({
|
|
65
|
-
error: {},
|
|
66
|
-
});
|
|
67
|
-
const { error, data, raw } = await transfer({
|
|
68
|
-
configs: {
|
|
69
|
-
channelUserMsisdn: '237699947943',
|
|
70
|
-
clientId: 'clientId',
|
|
71
|
-
clientSecret: 'clientSecret',
|
|
72
|
-
customerKey: 'customerKey',
|
|
73
|
-
customerSecret: 'customerSecret',
|
|
74
|
-
pin: 'pin',
|
|
75
|
-
environment: DisbursementXTargetEnvironmentType.sandbox,
|
|
76
|
-
logger: new Logger(),
|
|
77
|
-
},
|
|
78
|
-
params: {
|
|
79
|
-
webhook: 'https://example.com',
|
|
80
|
-
amount: 100,
|
|
81
|
-
customerPhone: '695326522',
|
|
82
|
-
customerName: 'itachi uchiwa',
|
|
83
|
-
token: 'token',
|
|
84
|
-
},
|
|
85
|
-
endPoint: 'https://example.com',
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
expect(data).not.toBeDefined();
|
|
89
|
-
expect(raw).not.toBeDefined();
|
|
90
|
-
expect(postSpy).toHaveBeenCalledTimes(1);
|
|
91
|
-
expect(error).toBeDefined();
|
|
92
|
-
});
|
|
93
|
-
it('should succeed on request succeed', async () => {
|
|
94
|
-
const postSpy = jest
|
|
95
|
-
.spyOn(requests, 'postRequest')
|
|
96
|
-
.mockImplementation()
|
|
97
|
-
.mockResolvedValue({
|
|
98
|
-
response: <AxiosResponse>{
|
|
99
|
-
data: {
|
|
100
|
-
MD5OfMessageBody: 'MD5OfMessageBody',
|
|
101
|
-
MD5OfMessageAttributes: 'MD5OfMessageAttributes',
|
|
102
|
-
MessageId: 'MessageId',
|
|
103
|
-
ResponseMetadata: {
|
|
104
|
-
RequestId: 'RequestId',
|
|
105
|
-
HTTPStatusCode: 200,
|
|
106
|
-
HTTPHeaders: {
|
|
107
|
-
'x-amzn-requestid': 'x-amzn-requestid',
|
|
108
|
-
'x-amzn-trace-id': 'x-amzn-trace-id',
|
|
109
|
-
'content-type': 'content-type',
|
|
110
|
-
'content-length': 'content-length',
|
|
111
|
-
},
|
|
112
|
-
RetryAttempts: 2,
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
const { error, data, raw } = await transfer({
|
|
118
|
-
configs: {
|
|
119
|
-
channelUserMsisdn: '237699947943',
|
|
120
|
-
clientId: 'clientId',
|
|
121
|
-
clientSecret: 'clientSecret',
|
|
122
|
-
customerKey: 'customerKey',
|
|
123
|
-
customerSecret: 'customerSecret',
|
|
124
|
-
pin: 'pin',
|
|
125
|
-
environment: DisbursementXTargetEnvironmentType.sandbox,
|
|
126
|
-
logger: new Logger(),
|
|
127
|
-
},
|
|
128
|
-
params: {
|
|
129
|
-
webhook: 'https://example.com',
|
|
130
|
-
amount: 100,
|
|
131
|
-
customerPhone: '695326522',
|
|
132
|
-
customerName: 'itachi uchiwa',
|
|
133
|
-
token: 'token',
|
|
134
|
-
},
|
|
135
|
-
endPoint: 'https://example.com',
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
expect(error).not.toBeDefined();
|
|
139
|
-
expect(postSpy).toHaveBeenCalledTimes(1);
|
|
140
|
-
expect(raw).toEqual({
|
|
141
|
-
MD5OfMessageBody: 'MD5OfMessageBody',
|
|
142
|
-
MD5OfMessageAttributes: 'MD5OfMessageAttributes',
|
|
143
|
-
MessageId: 'MessageId',
|
|
144
|
-
ResponseMetadata: {
|
|
145
|
-
RequestId: 'RequestId',
|
|
146
|
-
HTTPStatusCode: 200,
|
|
147
|
-
HTTPHeaders: {
|
|
148
|
-
'x-amzn-requestid': 'x-amzn-requestid',
|
|
149
|
-
'x-amzn-trace-id': 'x-amzn-trace-id',
|
|
150
|
-
'content-type': 'content-type',
|
|
151
|
-
'content-length': 'content-length',
|
|
152
|
-
},
|
|
153
|
-
RetryAttempts: 2,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
expect(data).toBe('MessageId');
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import { RequestResponse, postRequest } from '../../utils/https';
|
|
3
|
-
import { OperationResponse } from '../../utils/operation_response';
|
|
4
|
-
import {
|
|
5
|
-
DisbursementServiceConfig,
|
|
6
|
-
DisbursementServiceConfigSchema,
|
|
7
|
-
} from '../implementations/disbursement_service';
|
|
8
|
-
import { orangeMoneyPhoneNumberWithoutCountryCodeRegex } from '../utils/regex';
|
|
9
|
-
|
|
10
|
-
export enum TransferMethod {
|
|
11
|
-
OrangeMoney = 'OrangeMoney',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface TransferRequest {
|
|
15
|
-
webhook: string;
|
|
16
|
-
amount: number;
|
|
17
|
-
customerPhone: string;
|
|
18
|
-
customerName: string;
|
|
19
|
-
token: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const TransferRequestSchema = Joi.object<TransferRequest>({
|
|
23
|
-
webhook: Joi.string().uri().required(),
|
|
24
|
-
amount: Joi.number().integer().min(1).required(),
|
|
25
|
-
customerPhone: Joi.string()
|
|
26
|
-
.pattern(orangeMoneyPhoneNumberWithoutCountryCodeRegex)
|
|
27
|
-
.required(),
|
|
28
|
-
customerName: Joi.string().required(),
|
|
29
|
-
token: Joi.string().required(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export type TransferResponseRawData = {
|
|
33
|
-
MD5OfMessageBody: string;
|
|
34
|
-
MD5OfMessageAttributes: string;
|
|
35
|
-
MessageId: string;
|
|
36
|
-
ResponseMetadata: {
|
|
37
|
-
RequestId: string;
|
|
38
|
-
HTTPStatusCode: number;
|
|
39
|
-
HTTPHeaders: {
|
|
40
|
-
'x-amzn-requestid': string;
|
|
41
|
-
'x-amzn-trace-id': string;
|
|
42
|
-
date: string;
|
|
43
|
-
'content-type': string;
|
|
44
|
-
'content-length': string;
|
|
45
|
-
};
|
|
46
|
-
RetryAttempts: number;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type TransferResponse = OperationResponse<
|
|
51
|
-
string,
|
|
52
|
-
TransferResponseRawData
|
|
53
|
-
>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Transfers the specified amount of currency to the specified party.
|
|
57
|
-
*
|
|
58
|
-
* @param {DisbursementServiceConfig} configs - The disbursement service config.
|
|
59
|
-
* @param {TransferRequest} params - The transfer parameters.
|
|
60
|
-
* @return {MethodResponse<string, TransferRawData>} - The method response.
|
|
61
|
-
*/
|
|
62
|
-
export async function transfer({
|
|
63
|
-
configs,
|
|
64
|
-
params,
|
|
65
|
-
endPoint,
|
|
66
|
-
}: {
|
|
67
|
-
configs: DisbursementServiceConfig;
|
|
68
|
-
params: TransferRequest;
|
|
69
|
-
endPoint: string;
|
|
70
|
-
}): TransferResponse {
|
|
71
|
-
const logger = configs.logger;
|
|
72
|
-
logger.info(`transfer is running with params : ${JSON.stringify(params)}`);
|
|
73
|
-
|
|
74
|
-
const { error: configsValidationError, value: configValues } =
|
|
75
|
-
DisbursementServiceConfigSchema.validate(configs);
|
|
76
|
-
|
|
77
|
-
if (configsValidationError) {
|
|
78
|
-
logger.error(
|
|
79
|
-
`Invalid DisbursementServiceConfig request parameters. params : ${JSON.stringify(
|
|
80
|
-
configsValidationError.details
|
|
81
|
-
)}`
|
|
82
|
-
);
|
|
83
|
-
return { error: configsValidationError.details };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const { error: paramsValidationError, value: paramsValues } =
|
|
87
|
-
TransferRequestSchema.validate(params);
|
|
88
|
-
if (paramsValidationError) {
|
|
89
|
-
return {
|
|
90
|
-
error: `Invalid transfer request parameters. params : ${JSON.stringify(
|
|
91
|
-
params
|
|
92
|
-
)}`,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
const header = {
|
|
96
|
-
Authorization: `Bearer ${paramsValues.token}`,
|
|
97
|
-
};
|
|
98
|
-
const body = {
|
|
99
|
-
customerkey: configValues.customerKey,
|
|
100
|
-
customersecret: configValues.customerSecret,
|
|
101
|
-
channelUserMsisdn: configValues.channelUserMsisdn,
|
|
102
|
-
pin: configValues.pin,
|
|
103
|
-
webhook: paramsValues.webhook,
|
|
104
|
-
amount: `${paramsValues.amount}`,
|
|
105
|
-
final_customer_phone: paramsValues.customerPhone,
|
|
106
|
-
final_customer_name: paramsValues.customerName,
|
|
107
|
-
refund_method: TransferMethod.OrangeMoney,
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const response: RequestResponse<TransferResponseRawData> = await postRequest({
|
|
111
|
-
logger: logger,
|
|
112
|
-
route: endPoint,
|
|
113
|
-
data: body,
|
|
114
|
-
headers: header,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
if (!response.response) {
|
|
118
|
-
return { error: response.error };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
data: response.response.data.MessageId,
|
|
123
|
-
raw: response.response.data,
|
|
124
|
-
};
|
|
125
|
-
}
|