@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,66 +0,0 @@
|
|
|
1
|
-
import { postRequest } from '../../utils/https';
|
|
2
|
-
import { ApiErrorType, ApiKey, ConstantRequestField } from '../utils/constants';
|
|
3
|
-
import {
|
|
4
|
-
OrangeMoneyPaymentParams,
|
|
5
|
-
PayTokenRequestResponse,
|
|
6
|
-
} from '../utils/joi_schema';
|
|
7
|
-
import { GetPayTokenResponse } from '../utils/request_model';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Gets a pay token using the provided payment configuration.
|
|
11
|
-
*
|
|
12
|
-
* @param {OrangeMoneyPaymentParams} paymentConfig - The payment configuration.
|
|
13
|
-
* @param {OrangeMoneyPaymentParams} accessToken - The payment configuration.
|
|
14
|
-
* @param {string} endPoint - The payToken endpoint.
|
|
15
|
-
* @return {Promise<GetPayTokenResponse>} The generated pay token response.
|
|
16
|
-
*/
|
|
17
|
-
export const getPayToken = async (
|
|
18
|
-
paymentConfig: OrangeMoneyPaymentParams,
|
|
19
|
-
accessToken: string,
|
|
20
|
-
endPoint: string
|
|
21
|
-
): Promise<GetPayTokenResponse> => {
|
|
22
|
-
const logger = paymentConfig.logger;
|
|
23
|
-
|
|
24
|
-
logger.info(
|
|
25
|
-
`Request to generate the pay-token token using the provided payment configuration: ${JSON.stringify(
|
|
26
|
-
paymentConfig
|
|
27
|
-
)}`
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const headers = {
|
|
31
|
-
[ApiKey.keyAuthorization]: `Bearer ${accessToken}`,
|
|
32
|
-
[ApiKey.keyContentType]: ConstantRequestField.typeJson,
|
|
33
|
-
[ApiKey.keyXAuthToken]: paymentConfig.xAuthToken,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const result = await postRequest<PayTokenRequestResponse>({
|
|
37
|
-
headers: headers,
|
|
38
|
-
logger: logger,
|
|
39
|
-
route: endPoint,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const payToken = result.response?.data?.data?.payToken;
|
|
43
|
-
|
|
44
|
-
if (result.error || !payToken) {
|
|
45
|
-
logger.warn(
|
|
46
|
-
`Request failed to generate the pay-token. Error retrieved: ${JSON.stringify(
|
|
47
|
-
result.error
|
|
48
|
-
)}`
|
|
49
|
-
);
|
|
50
|
-
return {
|
|
51
|
-
raw: result.error,
|
|
52
|
-
error: ApiErrorType.failedToGeneratePayToken,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
logger.info(
|
|
57
|
-
`Pay-token generated successfully with data: ${JSON.stringify(
|
|
58
|
-
result.response?.data
|
|
59
|
-
)}`
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
raw: result.response?.data,
|
|
64
|
-
data: payToken,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import * as requests from '../../utils/https';
|
|
2
|
-
import { OrangeMoneyPaymentStatus } from '../utils/constants';
|
|
3
|
-
|
|
4
|
-
import { TargetEnvironment } from '../../utils/utils';
|
|
5
|
-
import { GetOrangeMoneyPaymentRequest } from '../utils/request_model';
|
|
6
|
-
import { getPaymentStatus } from './get_payment_status';
|
|
7
|
-
|
|
8
|
-
const logger = console;
|
|
9
|
-
describe('Test the status verification', () => {
|
|
10
|
-
const mobilePaymentParamForCheckStatus: GetOrangeMoneyPaymentRequest = {
|
|
11
|
-
accessToken: '1e23bee1-37dc-3015-a7d6-cb70e566bd64',
|
|
12
|
-
payToken: 'MP220807558VEF7A9C4F09AED',
|
|
13
|
-
};
|
|
14
|
-
it('Return the payment status', async () => {
|
|
15
|
-
jest.spyOn(requests, 'getRequest').mockResolvedValue({
|
|
16
|
-
response: {
|
|
17
|
-
status: 200,
|
|
18
|
-
data: {
|
|
19
|
-
message: 'Transaction retrieved successfully',
|
|
20
|
-
data: {
|
|
21
|
-
id: 74581010,
|
|
22
|
-
createtime: '1682001669',
|
|
23
|
-
subscriberMsisdn: '655637944',
|
|
24
|
-
amount: 1100,
|
|
25
|
-
payToken: 'MP23042031A1724A914DF0382D01',
|
|
26
|
-
txnid: 'MP230420.1541.C39196',
|
|
27
|
-
txnmode: 'zSapffVPWccheVZQRtvG',
|
|
28
|
-
inittxnmessage:
|
|
29
|
-
'Paiement e la clientele done.The devrez confirmer le paiement en saisissant son code PIN et vous recevrez alors un SMS. Merci dutiliser des services Orange Money.',
|
|
30
|
-
inittxnstatus: '200',
|
|
31
|
-
confirmtxnstatus: '200',
|
|
32
|
-
confirmtxnmessage:
|
|
33
|
-
'Paiement de SPREELOOP reussi par 655637944 PEKE. ID transaction:MP230420.1541.C39196, Montant:1100 FCFA. Solde: 55.81 FCFA.',
|
|
34
|
-
status: 'SUCCESSFULL',
|
|
35
|
-
notifUrl:
|
|
36
|
-
'https://europe-west1-place-prod.cloudfunctions.net/api-1/payment/orange_money/live/zSapffVPWccheVZQRtvG',
|
|
37
|
-
description: 'Commande',
|
|
38
|
-
channelUserMsisdn: '696431937',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
const result = await getPaymentStatus({
|
|
44
|
-
mobileStatusVerificationParams: mobilePaymentParamForCheckStatus,
|
|
45
|
-
paymentServiceConfig: {
|
|
46
|
-
targetEnvironment: TargetEnvironment.fake,
|
|
47
|
-
xAuthToken: 'ABCDEGHIJKLMNOPQRSTUVW',
|
|
48
|
-
apiUserName: 'secret',
|
|
49
|
-
apiPassword: 'secret',
|
|
50
|
-
logger: logger,
|
|
51
|
-
},
|
|
52
|
-
endPoint: 'https://api.paytoken.co',
|
|
53
|
-
});
|
|
54
|
-
expect(result.data?.status).toBe(
|
|
55
|
-
OrangeMoneyPaymentStatus.SUCCESSFULL_MOBILE_PAYMENT
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
it('Return the error response', async () => {
|
|
59
|
-
jest.spyOn(requests, 'getRequest').mockResolvedValue({
|
|
60
|
-
error: {
|
|
61
|
-
responseError: {
|
|
62
|
-
data: [Object],
|
|
63
|
-
status: 401,
|
|
64
|
-
statusText: 'Unauthorized',
|
|
65
|
-
headers: null,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
const result = await getPaymentStatus({
|
|
70
|
-
mobileStatusVerificationParams: mobilePaymentParamForCheckStatus,
|
|
71
|
-
paymentServiceConfig: {
|
|
72
|
-
targetEnvironment: TargetEnvironment.fake,
|
|
73
|
-
xAuthToken: 'ABCDEGHIJKLMNOPQRSTUVW',
|
|
74
|
-
apiUserName: 'secret',
|
|
75
|
-
apiPassword: 'secret',
|
|
76
|
-
logger: logger,
|
|
77
|
-
},
|
|
78
|
-
endPoint: 'https://api.paytoken.co',
|
|
79
|
-
});
|
|
80
|
-
expect(result.error).toBeDefined();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { getRequest, isSuccessfulCodeResponse } from '../../utils/https';
|
|
2
|
-
import { ApiErrorType, ApiKey, ConstantRequestField } from '../utils/constants';
|
|
3
|
-
import {
|
|
4
|
-
GenericRequestResponseData,
|
|
5
|
-
OrangeMoneyPaymentParams,
|
|
6
|
-
} from '../utils/joi_schema';
|
|
7
|
-
import {
|
|
8
|
-
GetOrangeMoneyPaymentRequest,
|
|
9
|
-
GetOrangeMoneyPaymentResponse,
|
|
10
|
-
} from '../utils/request_model';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Gets the mobile payment status.
|
|
14
|
-
*
|
|
15
|
-
* @param {Object} options - The options object.
|
|
16
|
-
* @param {GetOrangeMoneyPaymentRequest} options.mobileStatusVerificationParams - The parameters for mobile status verification.
|
|
17
|
-
* @param {string} endPoint - The init payment end point.
|
|
18
|
-
* @param {OrangeMoneyPaymentParams} paymentServiceConfig - The mobile payment config parameters.
|
|
19
|
-
* - {TargetEnvironment} PaymentServiceConfig.targetEnvironment - The target environment.
|
|
20
|
-
* - {string} PaymentServiceConfig.apiUserName - The api user name.
|
|
21
|
-
* - {string} PaymentServiceConfig.xAuthToken - The x-auth-token.
|
|
22
|
-
* - {string} PaymentServiceConfig.apiPassword - The api password.
|
|
23
|
-
* - {string} [PaymentServiceConfig.orangeMoneyVersion] - The orange money version.
|
|
24
|
-
* - {LoggerInterface} PaymentServiceConfig.logger - The logger interface.
|
|
25
|
-
* @return {Promise<GetOrangeMoneyPaymentResponse>} The promise that resolves to the mobile payment check status response.
|
|
26
|
-
*/
|
|
27
|
-
export async function getPaymentStatus({
|
|
28
|
-
mobileStatusVerificationParams,
|
|
29
|
-
paymentServiceConfig,
|
|
30
|
-
endPoint,
|
|
31
|
-
}: {
|
|
32
|
-
mobileStatusVerificationParams: GetOrangeMoneyPaymentRequest;
|
|
33
|
-
paymentServiceConfig: OrangeMoneyPaymentParams;
|
|
34
|
-
endPoint: string;
|
|
35
|
-
}): Promise<GetOrangeMoneyPaymentResponse> {
|
|
36
|
-
const logger = paymentServiceConfig.logger;
|
|
37
|
-
|
|
38
|
-
const headers = {
|
|
39
|
-
[ApiKey.keyAuthorization]: `Bearer ${mobileStatusVerificationParams.accessToken}`,
|
|
40
|
-
[ApiKey.keyContentType]: ConstantRequestField.typeJson,
|
|
41
|
-
[ApiKey.keyXAuthToken]: paymentServiceConfig.xAuthToken,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
logger.info(
|
|
45
|
-
`[ORANGE MONEY] Checks the ORANGE MONEY Payment status with route: ${endPoint}`
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const response = await getRequest<GenericRequestResponseData>({
|
|
49
|
-
headers: headers,
|
|
50
|
-
route: endPoint,
|
|
51
|
-
logger: logger,
|
|
52
|
-
});
|
|
53
|
-
const responseData = response?.response;
|
|
54
|
-
|
|
55
|
-
if (responseData && isSuccessfulCodeResponse(responseData.status)) {
|
|
56
|
-
logger.log(
|
|
57
|
-
`[ORANGE MONEY] Status verification successful with result ${JSON.stringify(
|
|
58
|
-
responseData.data
|
|
59
|
-
)}`
|
|
60
|
-
);
|
|
61
|
-
return {
|
|
62
|
-
data: {
|
|
63
|
-
status: responseData.data.data.status,
|
|
64
|
-
},
|
|
65
|
-
raw: responseData.data,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
logger.warn(
|
|
70
|
-
`[ORANGE MONEY] Status verification failed with error data: ${JSON.stringify(
|
|
71
|
-
response.error
|
|
72
|
-
)}`
|
|
73
|
-
);
|
|
74
|
-
return {
|
|
75
|
-
raw: response.error,
|
|
76
|
-
error: ApiErrorType.failedToCheckPaymentStatus,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import * as requests from '../../utils/https';
|
|
2
|
-
import { ApiErrorType } from '../utils/constants';
|
|
3
|
-
|
|
4
|
-
import { TargetEnvironment } from '../../utils/utils';
|
|
5
|
-
import { InitializeOrangeMoneyRequest } from '../utils/request_model';
|
|
6
|
-
import { initializeOmPayment } from './initialize_om_payment';
|
|
7
|
-
|
|
8
|
-
const logger = console;
|
|
9
|
-
|
|
10
|
-
describe('Test the initialization of payment', () => {
|
|
11
|
-
const mobileInitiateParams: InitializeOrangeMoneyRequest = {
|
|
12
|
-
amount: 100,
|
|
13
|
-
notifUrl: 'https://localhost',
|
|
14
|
-
transactionId: '1',
|
|
15
|
-
pinCode: '123',
|
|
16
|
-
channelUserNumber: '698526541',
|
|
17
|
-
subscriberNumber: '698526541',
|
|
18
|
-
accessToken: '1e23bee1-37dc-3015-a7d6-cb70e566bd64',
|
|
19
|
-
payToken: 'MP220807558VEF7A9C4F09AED',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
it('Initialization failed cause of invalid channel number', async () => {
|
|
23
|
-
jest.spyOn(requests, 'postRequest').mockImplementationOnce(() =>
|
|
24
|
-
Promise.resolve({
|
|
25
|
-
response: {
|
|
26
|
-
status: 417,
|
|
27
|
-
data: {
|
|
28
|
-
message: '60019 :: Le solde du compte du payeur est insuffisant',
|
|
29
|
-
data: {
|
|
30
|
-
id: 75742131,
|
|
31
|
-
createtime: '1682612128',
|
|
32
|
-
subscriberMsisdn: '696689073',
|
|
33
|
-
amount: 90,
|
|
34
|
-
payToken: 'MP2304270429730CE5AC78D276A6',
|
|
35
|
-
txnid: null,
|
|
36
|
-
txnmode: '84d1uhuhiuhiliubi',
|
|
37
|
-
inittxnmessage: 'Le solde du compte du payeur est insuffisant',
|
|
38
|
-
inittxnstatus: '60019',
|
|
39
|
-
confirmtxnstatus: null,
|
|
40
|
-
confirmtxnmessage: null,
|
|
41
|
-
status: 'FAILED',
|
|
42
|
-
notifUrl: '',
|
|
43
|
-
description: '',
|
|
44
|
-
channelUserMsisdn: '696431937',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
const result = await initializeOmPayment({
|
|
51
|
-
mobileInitParams: {
|
|
52
|
-
transactionId: mobileInitiateParams.transactionId,
|
|
53
|
-
amount: mobileInitiateParams.amount,
|
|
54
|
-
subscriberNumber: mobileInitiateParams.subscriberNumber,
|
|
55
|
-
notifUrl: mobileInitiateParams.notifUrl,
|
|
56
|
-
description: mobileInitiateParams.description,
|
|
57
|
-
pinCode: mobileInitiateParams.pinCode,
|
|
58
|
-
channelUserNumber: '688526541',
|
|
59
|
-
payToken: mobileInitiateParams.payToken,
|
|
60
|
-
accessToken: mobileInitiateParams.accessToken,
|
|
61
|
-
},
|
|
62
|
-
paymentConfig: {
|
|
63
|
-
orangeMoneyVersion: '1.2.0',
|
|
64
|
-
apiPassword: 'secret',
|
|
65
|
-
apiUserName: 'secret',
|
|
66
|
-
xAuthToken: 'ABCDEGHIJKLMNOPQRSTUVW',
|
|
67
|
-
targetEnvironment: TargetEnvironment.fake,
|
|
68
|
-
logger: logger,
|
|
69
|
-
},
|
|
70
|
-
endPoint: 'https://api.paytoken.co',
|
|
71
|
-
});
|
|
72
|
-
expect(result.error).toEqual(ApiErrorType.failedToInitiateThePayment);
|
|
73
|
-
});
|
|
74
|
-
it('Initialization failed cause of insufficient balance', async () => {
|
|
75
|
-
jest.spyOn(requests, 'postRequest').mockImplementationOnce(() =>
|
|
76
|
-
Promise.resolve({
|
|
77
|
-
response: {
|
|
78
|
-
status: 417,
|
|
79
|
-
data: {
|
|
80
|
-
message: '60019 :: Le solde du compte du payeur est insuffisant',
|
|
81
|
-
data: {
|
|
82
|
-
id: 75742131,
|
|
83
|
-
createtime: '1682612128',
|
|
84
|
-
subscriberMsisdn: '696689073',
|
|
85
|
-
amount: 90,
|
|
86
|
-
payToken: 'MP2304270429730CE5AC78D276A6',
|
|
87
|
-
txnid: null,
|
|
88
|
-
txnmode: '84d1uhuhiuhiliubi',
|
|
89
|
-
inittxnmessage: 'Le solde du compte du payeur est insuffisant',
|
|
90
|
-
inittxnstatus: '60019',
|
|
91
|
-
confirmtxnstatus: null,
|
|
92
|
-
confirmtxnmessage: null,
|
|
93
|
-
status: 'FAILED',
|
|
94
|
-
notifUrl: '',
|
|
95
|
-
description: '',
|
|
96
|
-
channelUserMsisdn: '696431937',
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
);
|
|
102
|
-
const result = await initializeOmPayment({
|
|
103
|
-
mobileInitParams: {
|
|
104
|
-
transactionId: mobileInitiateParams.transactionId,
|
|
105
|
-
amount: mobileInitiateParams.amount,
|
|
106
|
-
subscriberNumber: mobileInitiateParams.subscriberNumber,
|
|
107
|
-
notifUrl: mobileInitiateParams.notifUrl,
|
|
108
|
-
description: mobileInitiateParams.description,
|
|
109
|
-
pinCode: mobileInitiateParams.pinCode,
|
|
110
|
-
channelUserNumber: mobileInitiateParams.channelUserNumber,
|
|
111
|
-
payToken: mobileInitiateParams.payToken,
|
|
112
|
-
accessToken: mobileInitiateParams.accessToken,
|
|
113
|
-
},
|
|
114
|
-
paymentConfig: {
|
|
115
|
-
orangeMoneyVersion: '1.2.0',
|
|
116
|
-
apiPassword: 'secret',
|
|
117
|
-
apiUserName: 'secret',
|
|
118
|
-
xAuthToken: 'ABCDEGHIJKLMNOPQRSTUVW',
|
|
119
|
-
targetEnvironment: TargetEnvironment.fake,
|
|
120
|
-
logger: logger,
|
|
121
|
-
},
|
|
122
|
-
endPoint: 'https://api.paytoken.co',
|
|
123
|
-
});
|
|
124
|
-
expect(result.error).toEqual(ApiErrorType.insufficientFunds);
|
|
125
|
-
});
|
|
126
|
-
it('Initialization failed cause of account blocked ', async () => {
|
|
127
|
-
jest.spyOn(requests, 'postRequest').mockImplementationOnce(() =>
|
|
128
|
-
Promise.resolve({
|
|
129
|
-
response: {
|
|
130
|
-
status: 417,
|
|
131
|
-
data: {
|
|
132
|
-
message: '60019 :: Utilisateur bloque',
|
|
133
|
-
data: {
|
|
134
|
-
id: 75742131,
|
|
135
|
-
createtime: '1682612128',
|
|
136
|
-
subscriberMsisdn: '237696689073',
|
|
137
|
-
amount: 90,
|
|
138
|
-
payToken: 'MP2304270429730CE5AC78D276A6',
|
|
139
|
-
txnid: null,
|
|
140
|
-
txnmode: '84d1uhuhiuhiliubi',
|
|
141
|
-
inittxnmessage: 'Utilisateur bloque',
|
|
142
|
-
inittxnstatus: '60019',
|
|
143
|
-
confirmtxnstatus: null,
|
|
144
|
-
confirmtxnmessage: null,
|
|
145
|
-
status: 'FAILED',
|
|
146
|
-
notifUrl: '',
|
|
147
|
-
description: '',
|
|
148
|
-
channelUserMsisdn: '696431937',
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
const result = await initializeOmPayment({
|
|
155
|
-
mobileInitParams: {
|
|
156
|
-
transactionId: mobileInitiateParams.transactionId,
|
|
157
|
-
amount: mobileInitiateParams.amount,
|
|
158
|
-
subscriberNumber: mobileInitiateParams.subscriberNumber,
|
|
159
|
-
notifUrl: mobileInitiateParams.notifUrl,
|
|
160
|
-
description: mobileInitiateParams.description,
|
|
161
|
-
pinCode: mobileInitiateParams.pinCode,
|
|
162
|
-
channelUserNumber: mobileInitiateParams.channelUserNumber,
|
|
163
|
-
payToken: mobileInitiateParams.payToken,
|
|
164
|
-
accessToken: mobileInitiateParams.accessToken,
|
|
165
|
-
},
|
|
166
|
-
paymentConfig: {
|
|
167
|
-
orangeMoneyVersion: '1.2.0',
|
|
168
|
-
apiPassword: 'secret',
|
|
169
|
-
apiUserName: 'secret',
|
|
170
|
-
xAuthToken: 'ABCDEGHIJKLMNOPQRSTUVW',
|
|
171
|
-
targetEnvironment: TargetEnvironment.fake,
|
|
172
|
-
logger: logger,
|
|
173
|
-
},
|
|
174
|
-
endPoint: 'https://api.paytoken.co',
|
|
175
|
-
});
|
|
176
|
-
expect(result.error).toEqual(ApiErrorType.accountLocked);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('Initialization Successful', async () => {
|
|
180
|
-
jest.spyOn(requests, 'postRequest').mockImplementationOnce(() =>
|
|
181
|
-
Promise.resolve({
|
|
182
|
-
response: {
|
|
183
|
-
status: 200,
|
|
184
|
-
data: {
|
|
185
|
-
message: 'Payment request successfully initiated',
|
|
186
|
-
data: {
|
|
187
|
-
id: 75742131,
|
|
188
|
-
createtime: '1682612128',
|
|
189
|
-
subscriberMsisdn: '237696689073',
|
|
190
|
-
amount: 90,
|
|
191
|
-
payToken: 'MP2304270429730CE5AC78D276A6',
|
|
192
|
-
txnid: null,
|
|
193
|
-
txnmode: '84d1uhuhiuhiliubi',
|
|
194
|
-
inittxnmessage:
|
|
195
|
-
'Vous avez saisi un montant superieur au montant maximum autorise',
|
|
196
|
-
inittxnstatus: '60019',
|
|
197
|
-
confirmtxnstatus: null,
|
|
198
|
-
confirmtxnmessage: null,
|
|
199
|
-
status: 'PENDING',
|
|
200
|
-
notifUrl: '',
|
|
201
|
-
description: '',
|
|
202
|
-
channelUserMsisdn: '696431937',
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
})
|
|
207
|
-
);
|
|
208
|
-
const result = await initializeOmPayment({
|
|
209
|
-
mobileInitParams: {
|
|
210
|
-
transactionId: mobileInitiateParams.transactionId,
|
|
211
|
-
amount: mobileInitiateParams.amount,
|
|
212
|
-
subscriberNumber: mobileInitiateParams.subscriberNumber,
|
|
213
|
-
notifUrl: mobileInitiateParams.notifUrl,
|
|
214
|
-
description: mobileInitiateParams.description,
|
|
215
|
-
pinCode: mobileInitiateParams.pinCode,
|
|
216
|
-
channelUserNumber: mobileInitiateParams.channelUserNumber,
|
|
217
|
-
payToken: mobileInitiateParams.payToken,
|
|
218
|
-
accessToken: mobileInitiateParams.accessToken,
|
|
219
|
-
},
|
|
220
|
-
paymentConfig: {
|
|
221
|
-
orangeMoneyVersion: '1.2.0',
|
|
222
|
-
apiPassword: 'secret',
|
|
223
|
-
apiUserName: 'secret',
|
|
224
|
-
xAuthToken: 'ABCDEGHIJKLMNOPQRSTUVW',
|
|
225
|
-
targetEnvironment: TargetEnvironment.fake,
|
|
226
|
-
logger: logger,
|
|
227
|
-
},
|
|
228
|
-
endPoint: 'https://api.paytoken.co',
|
|
229
|
-
});
|
|
230
|
-
expect(result.data).toStrictEqual({
|
|
231
|
-
payToken: 'MP220807558VEF7A9C4F09AED',
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RequestResponse,
|
|
3
|
-
RequestStatusCode,
|
|
4
|
-
isSuccessfulCodeResponse,
|
|
5
|
-
postRequest,
|
|
6
|
-
} from '../../utils/https';
|
|
7
|
-
import { Routes } from '../routes/routes';
|
|
8
|
-
import {
|
|
9
|
-
ApiErrorType,
|
|
10
|
-
ApiKey,
|
|
11
|
-
ConstantRequestField,
|
|
12
|
-
OrangeMoneyErrorMessage,
|
|
13
|
-
} from '../utils/constants';
|
|
14
|
-
import {
|
|
15
|
-
GenericRequestResponseData,
|
|
16
|
-
InitPaymentBodySchema,
|
|
17
|
-
OrangeMoneyPaymentParams,
|
|
18
|
-
initPaymentBodySchema,
|
|
19
|
-
} from '../utils/joi_schema';
|
|
20
|
-
import {
|
|
21
|
-
InitializeOrangeMoneyRequest,
|
|
22
|
-
InitializeOrangeMoneyResponse,
|
|
23
|
-
} from '../utils/request_model';
|
|
24
|
-
import { validateData } from '../utils/utils';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Initiates the payment.
|
|
28
|
-
*
|
|
29
|
-
* @param {InitializeOmPaymentRequest} mobileInitParams - The mobile initialization parameters.
|
|
30
|
-
* @param {string} endPoint - The init payment end point.
|
|
31
|
-
* @param {OrangeMoneyPaymentParams} paymentConfig - The mobile payment config parameters.
|
|
32
|
-
* - {TargetEnvironment} paymentConfig.targetEnvironment - The target environment.
|
|
33
|
-
* - {string} paymentConfig.apiUserName - The api user name.
|
|
34
|
-
* - {string} paymentConfig.xAuthToken - The x-auth-token.
|
|
35
|
-
* - {string} paymentConfig.apiPassword - The api password.
|
|
36
|
-
* - {string} [paymentConfig.orangeMoneyVersion] - The orange money version.
|
|
37
|
-
* - {LoggerInterface} paymentConfig.logger - The logger interface.
|
|
38
|
-
* @return {Promise<InitializeOrangeMoneyResponse>} The promise that resolves to the mobile payment initialization response.
|
|
39
|
-
*/
|
|
40
|
-
export async function initializeOmPayment({
|
|
41
|
-
mobileInitParams,
|
|
42
|
-
paymentConfig,
|
|
43
|
-
endPoint,
|
|
44
|
-
}: {
|
|
45
|
-
mobileInitParams: InitializeOrangeMoneyRequest;
|
|
46
|
-
paymentConfig: OrangeMoneyPaymentParams;
|
|
47
|
-
endPoint: string;
|
|
48
|
-
}): Promise<InitializeOrangeMoneyResponse> {
|
|
49
|
-
const logger = paymentConfig.logger;
|
|
50
|
-
|
|
51
|
-
const paymentParams = {
|
|
52
|
-
mobileInitParams: mobileInitParams,
|
|
53
|
-
paymentConfig: paymentConfig,
|
|
54
|
-
endPoint: endPoint,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const response = await initializeOmPaymentInternal(paymentParams);
|
|
58
|
-
|
|
59
|
-
if (response.schemaErrorMessage) {
|
|
60
|
-
logger.warn(
|
|
61
|
-
`[ORANGE MONEY] Initialization failed with error data: ${JSON.stringify(
|
|
62
|
-
response.schemaErrorMessage
|
|
63
|
-
)}`
|
|
64
|
-
);
|
|
65
|
-
return {
|
|
66
|
-
raw: response.schemaErrorMessage,
|
|
67
|
-
error: ApiErrorType.failedToInitiateThePayment,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const requestResponse = response.requestResult?.response;
|
|
72
|
-
|
|
73
|
-
if (requestResponse && isSuccessfulCodeResponse(requestResponse.status)) {
|
|
74
|
-
logger.info(
|
|
75
|
-
`[ORANGE MONEY] Initialization successful with result ${JSON.stringify(
|
|
76
|
-
requestResponse.data
|
|
77
|
-
)}`
|
|
78
|
-
);
|
|
79
|
-
return {
|
|
80
|
-
data: {
|
|
81
|
-
payToken: mobileInitParams.payToken,
|
|
82
|
-
},
|
|
83
|
-
raw: requestResponse.data,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (
|
|
87
|
-
requestResponse &&
|
|
88
|
-
requestResponse.status === RequestStatusCode.expectationFailed
|
|
89
|
-
) {
|
|
90
|
-
const errorData = requestResponse.data.data;
|
|
91
|
-
|
|
92
|
-
logger.warn(
|
|
93
|
-
`[ORANGE MONEY] Initialization failed failed. Raison: ${errorData.inittxnmessage}`
|
|
94
|
-
);
|
|
95
|
-
return {
|
|
96
|
-
raw: requestResponse.data,
|
|
97
|
-
error: getApiErrorMessage(errorData.inittxnmessage),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
logger.warn(
|
|
102
|
-
`[ORANGE MONEY] Initialization failed with error data: ${JSON.stringify(
|
|
103
|
-
response.requestResult?.error
|
|
104
|
-
)}`
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
error: ApiErrorType.failedToInitiateThePayment,
|
|
109
|
-
raw: response.requestResult?.error,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Makes a payment request using the provided parameters.
|
|
115
|
-
*
|
|
116
|
-
* @param {Object} params - An object containing the following parameters:
|
|
117
|
-
* - {MobileInitPaymentParams} mobileInitParams: The mobile initialization parameters.
|
|
118
|
-
* - {PaymentConfig} paymentConfig - The mobile payment config parameters.
|
|
119
|
-
* - {string} endPoint: The init payment end point.
|
|
120
|
-
* @return {Promise} A promise that resolves to the payment request response.
|
|
121
|
-
*/
|
|
122
|
-
const initializeOmPaymentInternal = async (params: {
|
|
123
|
-
mobileInitParams: InitializeOrangeMoneyRequest;
|
|
124
|
-
paymentConfig: OrangeMoneyPaymentParams;
|
|
125
|
-
endPoint: string;
|
|
126
|
-
}): Promise<{
|
|
127
|
-
requestResult?: RequestResponse<GenericRequestResponseData>;
|
|
128
|
-
schemaErrorMessage?: string;
|
|
129
|
-
}> => {
|
|
130
|
-
const routes = new Routes(params.paymentConfig.orangeMoneyVersion);
|
|
131
|
-
const headers = {
|
|
132
|
-
[ApiKey.keyAuthorization]: `Bearer ${params.mobileInitParams.accessToken}`,
|
|
133
|
-
[ApiKey.keyContentType]: ConstantRequestField.typeJson,
|
|
134
|
-
[ApiKey.keyXAuthToken]: params.paymentConfig.xAuthToken,
|
|
135
|
-
};
|
|
136
|
-
const body = {
|
|
137
|
-
[ApiKey.keySubscriberMsisdn]: params.mobileInitParams.subscriberNumber,
|
|
138
|
-
[ApiKey.keyChannelUserMsisdn]: params.mobileInitParams.channelUserNumber,
|
|
139
|
-
[ApiKey.keyAmount]: params.mobileInitParams.amount.toString(),
|
|
140
|
-
[ApiKey.keyDescription]: params.mobileInitParams.description,
|
|
141
|
-
[ApiKey.keyMobileOrderId]: params.mobileInitParams.transactionId,
|
|
142
|
-
[ApiKey.keyPin]: params.mobileInitParams.pinCode,
|
|
143
|
-
[ApiKey.keyMobilePayToken]: params.mobileInitParams.payToken,
|
|
144
|
-
[ApiKey.keyMobileNotifUrl]: params.mobileInitParams.notifUrl,
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const dataValidation = validateData<InitPaymentBodySchema>(
|
|
148
|
-
body,
|
|
149
|
-
initPaymentBodySchema
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
if (!dataValidation.isValidData) {
|
|
153
|
-
return { schemaErrorMessage: dataValidation.message };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
params.paymentConfig.logger.info(
|
|
157
|
-
`Initiate the ORANGE MONEY Payment with data: ${JSON.stringify(
|
|
158
|
-
body
|
|
159
|
-
)}\nroute: ${routes.mobileInitPayment()}`
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const response = await postRequest<GenericRequestResponseData>({
|
|
163
|
-
logger: params.paymentConfig.logger,
|
|
164
|
-
headers: headers,
|
|
165
|
-
data: body,
|
|
166
|
-
route: routes.mobileInitPayment(),
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
return { requestResult: response };
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Maps an API error message to the corresponding API error type.
|
|
174
|
-
*
|
|
175
|
-
* @param {string} message - the error message to map
|
|
176
|
-
* @return {ApiErrorType} the corresponding API error type
|
|
177
|
-
*/
|
|
178
|
-
const getApiErrorMessage = (message: string): ApiErrorType => {
|
|
179
|
-
switch (message) {
|
|
180
|
-
case OrangeMoneyErrorMessage.beneficiaryNotFound:
|
|
181
|
-
return ApiErrorType.invalidOrangeMoneyNumber;
|
|
182
|
-
case OrangeMoneyErrorMessage.insufficientFunds:
|
|
183
|
-
return ApiErrorType.insufficientFunds;
|
|
184
|
-
case OrangeMoneyErrorMessage.accountLocked:
|
|
185
|
-
return ApiErrorType.accountLocked;
|
|
186
|
-
case OrangeMoneyErrorMessage.invalidPaymentAmount:
|
|
187
|
-
return ApiErrorType.invalidPaymentAmount;
|
|
188
|
-
default:
|
|
189
|
-
return ApiErrorType.failedToInitiateThePayment;
|
|
190
|
-
}
|
|
191
|
-
};
|