@spreeloop/orange_money 1.0.7 → 1.0.8

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.
Files changed (214) hide show
  1. package/dist/logging/src/log_level.d.ts +24 -0
  2. package/dist/logging/src/log_level.d.ts.map +1 -0
  3. package/dist/logging/src/log_level.js +34 -0
  4. package/dist/logging/src/log_level.js.map +1 -0
  5. package/dist/logging/src/logging.d.ts +50 -0
  6. package/dist/logging/src/logging.d.ts.map +1 -0
  7. package/dist/logging/src/logging.js +87 -0
  8. package/dist/logging/src/logging.js.map +1 -0
  9. package/dist/logging/src/printer.d.ts +10 -0
  10. package/dist/logging/src/printer.d.ts.map +1 -0
  11. package/dist/logging/src/printer.js +3 -0
  12. package/dist/logging/src/printer.js.map +1 -0
  13. package/dist/orange_money/index.d.ts +2 -0
  14. package/dist/orange_money/index.d.ts.map +1 -0
  15. package/dist/orange_money/index.js +18 -0
  16. package/dist/orange_money/index.js.map +1 -0
  17. package/dist/orange_money/src/disbursements/implementations/disbursement_service.d.ts +62 -0
  18. package/dist/orange_money/src/disbursements/implementations/disbursement_service.d.ts.map +1 -0
  19. package/dist/orange_money/src/disbursements/implementations/disbursement_service.js +84 -0
  20. package/dist/orange_money/src/disbursements/implementations/disbursement_service.js.map +1 -0
  21. package/dist/orange_money/src/disbursements/implementations/src/live.d.ts +40 -0
  22. package/dist/orange_money/src/disbursements/implementations/src/live.d.ts.map +1 -0
  23. package/dist/orange_money/src/disbursements/implementations/src/live.js +61 -0
  24. package/dist/orange_money/src/disbursements/implementations/src/live.js.map +1 -0
  25. package/dist/orange_money/src/disbursements/implementations/src/sandbox.d.ts +40 -0
  26. package/dist/orange_money/src/disbursements/implementations/src/sandbox.d.ts.map +1 -0
  27. package/dist/orange_money/src/disbursements/implementations/src/sandbox.js +110 -0
  28. package/dist/orange_money/src/disbursements/implementations/src/sandbox.js.map +1 -0
  29. package/dist/orange_money/src/disbursements/operations/create_access_token.d.ts +28 -0
  30. package/dist/orange_money/src/disbursements/operations/create_access_token.d.ts.map +1 -0
  31. package/dist/orange_money/src/disbursements/operations/create_access_token.js +45 -0
  32. package/dist/orange_money/src/disbursements/operations/create_access_token.js.map +1 -0
  33. package/dist/orange_money/src/disbursements/operations/create_access_token.spec.d.ts +2 -0
  34. package/dist/orange_money/src/disbursements/operations/create_access_token.spec.d.ts.map +1 -0
  35. package/dist/orange_money/src/disbursements/operations/create_access_token.spec.js +106 -0
  36. package/dist/orange_money/src/disbursements/operations/create_access_token.spec.js.map +1 -0
  37. package/dist/orange_money/src/disbursements/operations/get_transfer_status.d.ts +114 -0
  38. package/dist/orange_money/src/disbursements/operations/get_transfer_status.d.ts.map +1 -0
  39. package/dist/orange_money/src/disbursements/operations/get_transfer_status.js +128 -0
  40. package/dist/orange_money/src/disbursements/operations/get_transfer_status.js.map +1 -0
  41. package/dist/orange_money/src/disbursements/operations/get_transfer_status.spec.d.ts +2 -0
  42. package/dist/orange_money/src/disbursements/operations/get_transfer_status.spec.d.ts.map +1 -0
  43. package/dist/orange_money/src/disbursements/operations/get_transfer_status.spec.js +148 -0
  44. package/dist/orange_money/src/disbursements/operations/get_transfer_status.spec.js.map +1 -0
  45. package/dist/orange_money/src/disbursements/operations/transfer.d.ts +44 -0
  46. package/dist/orange_money/src/disbursements/operations/transfer.d.ts.map +1 -0
  47. package/dist/orange_money/src/disbursements/operations/transfer.js +74 -0
  48. package/dist/orange_money/src/disbursements/operations/transfer.js.map +1 -0
  49. package/dist/orange_money/src/disbursements/operations/transfer.spec.d.ts +2 -0
  50. package/dist/orange_money/src/disbursements/operations/transfer.spec.d.ts.map +1 -0
  51. package/dist/orange_money/src/disbursements/operations/transfer.spec.js +178 -0
  52. package/dist/orange_money/src/disbursements/operations/transfer.spec.js.map +1 -0
  53. package/dist/orange_money/src/disbursements/routes/routes.d.ts +38 -0
  54. package/dist/orange_money/src/disbursements/routes/routes.d.ts.map +1 -0
  55. package/dist/orange_money/src/disbursements/routes/routes.js +53 -0
  56. package/dist/orange_money/src/disbursements/routes/routes.js.map +1 -0
  57. package/dist/orange_money/src/disbursements/utils/constants.d.ts +5 -0
  58. package/dist/orange_money/src/disbursements/utils/constants.d.ts.map +1 -0
  59. package/dist/orange_money/src/disbursements/utils/constants.js +9 -0
  60. package/dist/orange_money/src/disbursements/utils/constants.js.map +1 -0
  61. package/{src/disbursements/utils/regex.ts → dist/orange_money/src/disbursements/utils/regex.d.ts} +3 -4
  62. package/dist/orange_money/src/disbursements/utils/regex.d.ts.map +1 -0
  63. package/dist/orange_money/src/disbursements/utils/regex.js +12 -0
  64. package/dist/orange_money/src/disbursements/utils/regex.js.map +1 -0
  65. package/dist/orange_money/src/disbursements/utils/regex.spec.d.ts +2 -0
  66. package/dist/orange_money/src/disbursements/utils/regex.spec.d.ts.map +1 -0
  67. package/dist/orange_money/src/disbursements/utils/regex.spec.js +32 -0
  68. package/dist/orange_money/src/disbursements/utils/regex.spec.js.map +1 -0
  69. package/dist/orange_money/src/disbursements/utils/status.d.ts +53 -0
  70. package/dist/orange_money/src/disbursements/utils/status.d.ts.map +1 -0
  71. package/dist/orange_money/src/disbursements/utils/status.js +58 -0
  72. package/dist/orange_money/src/disbursements/utils/status.js.map +1 -0
  73. package/dist/orange_money/src/disbursements/utils/utils.d.ts +9 -0
  74. package/dist/orange_money/src/disbursements/utils/utils.d.ts.map +1 -0
  75. package/dist/orange_money/src/disbursements/utils/utils.js +26 -0
  76. package/dist/orange_money/src/disbursements/utils/utils.js.map +1 -0
  77. package/dist/orange_money/src/disbursements/utils/utils.spec.d.ts +2 -0
  78. package/dist/orange_money/src/disbursements/utils/utils.spec.d.ts.map +1 -0
  79. package/dist/orange_money/src/disbursements/utils/utils.spec.js +43 -0
  80. package/dist/orange_money/src/disbursements/utils/utils.spec.js.map +1 -0
  81. package/{src/index.ts → dist/orange_money/src/index.d.ts} +3 -8
  82. package/dist/orange_money/src/index.d.ts.map +1 -0
  83. package/dist/orange_money/src/index.js +15 -0
  84. package/dist/orange_money/src/index.js.map +1 -0
  85. package/dist/orange_money/src/payments/implementations/fake.d.ts +33 -0
  86. package/dist/orange_money/src/payments/implementations/fake.d.ts.map +1 -0
  87. package/dist/orange_money/src/payments/implementations/fake.js +110 -0
  88. package/dist/orange_money/src/payments/implementations/fake.js.map +1 -0
  89. package/dist/orange_money/src/payments/implementations/live.d.ts +45 -0
  90. package/dist/orange_money/src/payments/implementations/live.d.ts.map +1 -0
  91. package/dist/orange_money/src/payments/implementations/live.js +69 -0
  92. package/dist/orange_money/src/payments/implementations/live.js.map +1 -0
  93. package/dist/orange_money/src/payments/operations/get_access_token.d.ts +11 -0
  94. package/dist/orange_money/src/payments/operations/get_access_token.d.ts.map +1 -0
  95. package/dist/orange_money/src/payments/operations/get_access_token.js +47 -0
  96. package/dist/orange_money/src/payments/operations/get_access_token.js.map +1 -0
  97. package/dist/orange_money/src/payments/operations/get_access_token.spec.d.ts +2 -0
  98. package/dist/orange_money/src/payments/operations/get_access_token.spec.d.ts.map +1 -0
  99. package/dist/orange_money/src/payments/operations/get_access_token.spec.js +74 -0
  100. package/dist/orange_money/src/payments/operations/get_access_token.spec.js.map +1 -0
  101. package/dist/orange_money/src/payments/operations/get_pay_token.d.ts +12 -0
  102. package/dist/orange_money/src/payments/operations/get_pay_token.d.ts.map +1 -0
  103. package/dist/orange_money/src/payments/operations/get_pay_token.js +43 -0
  104. package/dist/orange_money/src/payments/operations/get_pay_token.js.map +1 -0
  105. package/dist/orange_money/src/payments/operations/get_pay_token.spec.d.ts +2 -0
  106. package/dist/orange_money/src/payments/operations/get_pay_token.spec.d.ts.map +1 -0
  107. package/dist/orange_money/src/payments/operations/get_pay_token.spec.js +74 -0
  108. package/dist/orange_money/src/payments/operations/get_pay_token.spec.js.map +1 -0
  109. package/dist/orange_money/src/payments/operations/get_payment_status.d.ts +23 -0
  110. package/dist/orange_money/src/payments/operations/get_payment_status.d.ts.map +1 -0
  111. package/dist/orange_money/src/payments/operations/get_payment_status.js +51 -0
  112. package/dist/orange_money/src/payments/operations/get_payment_status.js.map +1 -0
  113. package/dist/orange_money/src/payments/operations/get_payment_status.spec.d.ts +2 -0
  114. package/dist/orange_money/src/payments/operations/get_payment_status.spec.d.ts.map +1 -0
  115. package/dist/orange_money/src/payments/operations/get_payment_status.spec.js +101 -0
  116. package/dist/orange_money/src/payments/operations/get_payment_status.spec.js.map +1 -0
  117. package/dist/orange_money/src/payments/operations/initialize_om_payment.d.ts +22 -0
  118. package/dist/orange_money/src/payments/operations/initialize_om_payment.d.ts.map +1 -0
  119. package/dist/orange_money/src/payments/operations/initialize_om_payment.js +124 -0
  120. package/dist/orange_money/src/payments/operations/initialize_om_payment.js.map +1 -0
  121. package/dist/orange_money/src/payments/operations/initialize_om_payment.spec.d.ts +2 -0
  122. package/dist/orange_money/src/payments/operations/initialize_om_payment.spec.d.ts.map +1 -0
  123. package/dist/orange_money/src/payments/operations/initialize_om_payment.spec.js +245 -0
  124. package/dist/orange_money/src/payments/operations/initialize_om_payment.spec.js.map +1 -0
  125. package/dist/orange_money/src/payments/payments.d.ts +57 -0
  126. package/dist/orange_money/src/payments/payments.d.ts.map +1 -0
  127. package/dist/orange_money/src/payments/payments.js +36 -0
  128. package/dist/orange_money/src/payments/payments.js.map +1 -0
  129. package/dist/orange_money/src/payments/routes/routes.d.ts +48 -0
  130. package/dist/orange_money/src/payments/routes/routes.d.ts.map +1 -0
  131. package/dist/orange_money/src/payments/routes/routes.js +61 -0
  132. package/dist/orange_money/src/payments/routes/routes.js.map +1 -0
  133. package/dist/orange_money/src/payments/utils/constants.d.ts +96 -0
  134. package/dist/orange_money/src/payments/utils/constants.d.ts.map +1 -0
  135. package/dist/orange_money/src/payments/utils/constants.js +112 -0
  136. package/dist/orange_money/src/payments/utils/constants.js.map +1 -0
  137. package/dist/orange_money/src/payments/utils/joi_schema.d.ts +70 -0
  138. package/dist/orange_money/src/payments/utils/joi_schema.d.ts.map +1 -0
  139. package/dist/orange_money/src/payments/utils/joi_schema.js +44 -0
  140. package/dist/orange_money/src/payments/utils/joi_schema.js.map +1 -0
  141. package/dist/orange_money/src/payments/utils/request_model.d.ts +75 -0
  142. package/dist/orange_money/src/payments/utils/request_model.d.ts.map +1 -0
  143. package/dist/orange_money/src/payments/utils/request_model.js +3 -0
  144. package/dist/orange_money/src/payments/utils/request_model.js.map +1 -0
  145. package/dist/orange_money/src/payments/utils/utils.d.ts +15 -0
  146. package/dist/orange_money/src/payments/utils/utils.d.ts.map +1 -0
  147. package/dist/orange_money/src/payments/utils/utils.js +27 -0
  148. package/dist/orange_money/src/payments/utils/utils.js.map +1 -0
  149. package/dist/orange_money/src/utils/https.d.ts +77 -0
  150. package/dist/orange_money/src/utils/https.d.ts.map +1 -0
  151. package/dist/orange_money/src/utils/https.js +240 -0
  152. package/dist/orange_money/src/utils/https.js.map +1 -0
  153. package/dist/orange_money/src/utils/https.spec.d.ts +2 -0
  154. package/dist/orange_money/src/utils/https.spec.d.ts.map +1 -0
  155. package/dist/orange_money/src/utils/https.spec.js +77 -0
  156. package/dist/orange_money/src/utils/https.spec.js.map +1 -0
  157. package/dist/orange_money/src/utils/logging_interface.d.ts +23 -0
  158. package/dist/orange_money/src/utils/logging_interface.d.ts.map +1 -0
  159. package/dist/orange_money/src/utils/logging_interface.js +3 -0
  160. package/dist/orange_money/src/utils/logging_interface.js.map +1 -0
  161. package/{src/utils/operation_response.ts → dist/orange_money/src/utils/operation_response.d.ts} +9 -10
  162. package/dist/orange_money/src/utils/operation_response.d.ts.map +1 -0
  163. package/dist/orange_money/src/utils/operation_response.js +3 -0
  164. package/dist/orange_money/src/utils/operation_response.js.map +1 -0
  165. package/dist/orange_money/src/utils/utils.d.ts +6 -0
  166. package/dist/orange_money/src/utils/utils.d.ts.map +1 -0
  167. package/dist/orange_money/src/utils/utils.js +10 -0
  168. package/dist/orange_money/src/utils/utils.js.map +1 -0
  169. package/package.json +6 -2
  170. package/.eslintrc.js +0 -47
  171. package/.prettierrc +0 -6
  172. package/babel.config.js +0 -3
  173. package/index.spec.ts +0 -9
  174. package/index.ts +0 -1
  175. package/jest.before-test.ts +0 -3
  176. package/jest.config.ts +0 -54
  177. package/src/disbursements/implementations/disbursement_service.ts +0 -133
  178. package/src/disbursements/implementations/src/live.ts +0 -79
  179. package/src/disbursements/implementations/src/sandbox.ts +0 -124
  180. package/src/disbursements/operations/create_access_token.spec.ts +0 -87
  181. package/src/disbursements/operations/create_access_token.ts +0 -83
  182. package/src/disbursements/operations/get_transfer_status.spec.ts +0 -132
  183. package/src/disbursements/operations/get_transfer_status.ts +0 -265
  184. package/src/disbursements/operations/transfer.spec.ts +0 -158
  185. package/src/disbursements/operations/transfer.ts +0 -125
  186. package/src/disbursements/routes/routes.ts +0 -54
  187. package/src/disbursements/utils/constants.ts +0 -4
  188. package/src/disbursements/utils/regex.spec.ts +0 -39
  189. package/src/disbursements/utils/status.ts +0 -62
  190. package/src/disbursements/utils/utils.spec.ts +0 -42
  191. package/src/disbursements/utils/utils.ts +0 -24
  192. package/src/payments/implementations/fake.ts +0 -133
  193. package/src/payments/implementations/live.ts +0 -87
  194. package/src/payments/operations/get_access_token.spec.ts +0 -60
  195. package/src/payments/operations/get_access_token.ts +0 -77
  196. package/src/payments/operations/get_pay_token.spec.ts +0 -65
  197. package/src/payments/operations/get_pay_token.ts +0 -66
  198. package/src/payments/operations/get_payment_status.spec.ts +0 -82
  199. package/src/payments/operations/get_payment_status.ts +0 -78
  200. package/src/payments/operations/initialize_om_payment.spec.ts +0 -234
  201. package/src/payments/operations/initialize_om_payment.ts +0 -191
  202. package/src/payments/payments.ts +0 -86
  203. package/src/payments/routes/routes.ts +0 -61
  204. package/src/payments/utils/constants.ts +0 -120
  205. package/src/payments/utils/joi_schema.ts +0 -117
  206. package/src/payments/utils/request_model.ts +0 -103
  207. package/src/payments/utils/utils.ts +0 -31
  208. package/src/utils/https.spec.ts +0 -101
  209. package/src/utils/https.ts +0 -266
  210. package/src/utils/logging_interface.ts +0 -25
  211. package/src/utils/utils.ts +0 -5
  212. package/tsconfig.build.json +0 -4
  213. package/tsconfig.dev.json +0 -4
  214. package/tsconfig.json +0 -27
@@ -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
- };
@@ -1,86 +0,0 @@
1
- import { TargetEnvironment } from '../utils/utils';
2
- import { OrangeMoneyPaymentFake } from './implementations/fake';
3
- import { OrangeMoneyPaymentLive } from './implementations/live';
4
- import { OrangeMoneyPaymentParams } from './utils/joi_schema';
5
- import {
6
- GetAccessTokenResponse,
7
- GetOrangeMoneyPaymentRequest,
8
- GetOrangeMoneyPaymentResponse,
9
- GetPayTokenResponse,
10
- InitializeOrangeMoneyRequest,
11
- InitializeOrangeMoneyResponse,
12
- } from './utils/request_model';
13
-
14
- export interface OrangeMoneyPaymentInterface {
15
- /**
16
- * Gets the pay token token.
17
- * @param {String} accessToken The access token for authorize the request.
18
- * @returns {Promise<GetPayTokenResponse>} The promise that resolves to the pay token response.
19
- */
20
- getPayToken(accessToken: string): Promise<GetPayTokenResponse>;
21
-
22
- /**
23
- * Gets the access token token.
24
- */
25
- getAccessToken(): Promise<GetAccessTokenResponse>;
26
-
27
- /**
28
- * Initializes the orange money payment.
29
- *
30
- * @param {String} mobileInitParams.description the payment description.
31
- * @param {String} mobileInitParams.subscriberNumber The phone number of the user making the payment.
32
- * @param {String} mobileInitParams.channelUserNumber The phone number of the user receiving the payment.
33
- * @param {String} mobileInitParams.transactionId Unique identifier of the customer transaction.
34
- * @param {String} mobileInitParams.amount The amount of the transaction.
35
- * @param {String} mobileInitParams.pinCode The Pin code of the ChannelUser.
36
- * @param {String} mobileInitParams.notifUrl An http endpoint able to receive a post request.
37
- * @param {String} mobileInitParams.payToken A payToken value useful to make payment
38
- * and track the status of payment.
39
- * @param {String} mobileInitParams.accessToken The access token for authorize the request.
40
- * @returns {Promise<InitializeOrangeMoneyResponse>} The promise that resolves to the mobile payment initialization response.
41
- **/
42
- initializeOrangeMoneyPayment(
43
- params: InitializeOrangeMoneyRequest
44
- ): Promise<InitializeOrangeMoneyResponse>;
45
-
46
- /**
47
- * Gets The orange money payment status.
48
- * @param {String} checkStatusParams.payToken unique identifier used to obtain payment status.
49
- * @param {String} checkStatusParams.accessToken The access token for authorize the request.
50
- * @returns {Promise<GetOrangeMoneyPaymentResponse>} The promise that resolves to the mobile payment status response.
51
- */
52
- getOrangeMoneyPaymentStatus(
53
- params: GetOrangeMoneyPaymentRequest
54
- ): Promise<GetOrangeMoneyPaymentResponse>;
55
- }
56
-
57
- /**
58
- * Creates a orange money payment.
59
- */
60
- export class OrangeMoneyPayment {
61
- /**
62
- * Create a new payment using the provided configuration.
63
- *
64
- * @param {OrangeMoneyPaymentParams} config - The payment configuration.
65
- * - {TargetEnvironment} config.targetEnvironment the target environment.
66
- * - {string} config.apiUserName channelUser api username.
67
- * - {string} config.apiPassword channelUser api password.
68
- * - {string} config.xAuthToken the x-auth-token.
69
- * - {string} [mobileInitParams.omVersion] the mobile orange money version apply for payment request.The default orange money version
70
- * is 1.0.2: for more information: https://apiw.orange.cm/omcoreapis/1.0.2/mp/pay.
71
- * - {String} config.targetEnvironment the target environment.
72
- * @return {OrangeMoneyPaymentInterface} The created payment.
73
- */
74
- static createPayment(
75
- config: OrangeMoneyPaymentParams
76
- ): OrangeMoneyPaymentInterface {
77
- switch (config.targetEnvironment) {
78
- case TargetEnvironment.prod:
79
- return new OrangeMoneyPaymentLive(config);
80
- case TargetEnvironment.fake:
81
- return new OrangeMoneyPaymentFake();
82
- default:
83
- return new OrangeMoneyPaymentLive(config);
84
- }
85
- }
86
- }
@@ -1,61 +0,0 @@
1
- const apiHost = 'https://api-s1.orange.cm';
2
-
3
- /**
4
- * Orange Money API routes builder.
5
- * @class
6
- */
7
- export class Routes {
8
- /**
9
- * Creates a new instance of the class route.
10
- *
11
- * @param {string} version - The version of the instance. Optional.
12
- */
13
- constructor(private readonly version?: string) {
14
- this.version = version ?? '1.0.2';
15
- }
16
-
17
- /**
18
- * Returns the base route for the API.
19
- *
20
- * @return {string} The base route for the API.
21
- */
22
- baseRoute = (): string => `${apiHost}/omcoreapis/${this.version}`;
23
-
24
- /**
25
- * Initializes the live payment.
26
- *
27
- * @return {string} The endpoint URL for the live payment.
28
- */
29
- mobileInitPayment(): string {
30
- return `${this.baseRoute()}/mp/pay`;
31
- }
32
-
33
- /**
34
- * Generates the payment status URL based on the provided parameters.
35
- *
36
- * @param {object} params - The parameters for generating the payment status URL.
37
- * - {string} params.payToken - The pay token.
38
- * @return {string} The generated payment status URL.
39
- */
40
- mobilePaymentStatus(params: { payToken: string }): string {
41
- return `${this.baseRoute()}/mp/paymentstatus/${params.payToken}`;
42
- }
43
-
44
- /**
45
- * Generates the URL for the Mobile Pay token.
46
- *
47
- * @return {string} The URL for the Mobile Pay token.
48
- */
49
- mobilePayToken(): string {
50
- return `${this.baseRoute()}/mp/init`;
51
- }
52
-
53
- /**
54
- * Generates the mobile access token endpoint.
55
- *
56
- * @return {string} The generated mobile access token endpoint.
57
- */
58
- mobileAccessToken(): string {
59
- return `${apiHost}/token`;
60
- }
61
- }