@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,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
- }
@@ -1,54 +0,0 @@
1
- import { DisbursementXTargetEnvironmentType } from '../utils/constants';
2
-
3
- const apiHost = 'https://omapi.ynote.africa';
4
- const apiTokenHost = 'https://omapi-token.ynote.africa/oauth2/token';
5
-
6
- /**
7
- * Orange Money API routes builder.
8
- * @class
9
- */
10
- export class Routes {
11
- /**
12
- * Constructs a new {CommonRoutes}.
13
- * @constructor
14
- * @param {RoutesParams} config - The required global route configuration.
15
- */
16
-
17
- /**
18
- * Returns the base route for the API.
19
- * e.g: https://docs.google.com/document/d/1h-gMj7PSGAALxRSofOvLa2g5vF3IpDkUufNrU1hX6Yk/edit?pli=1
20
- * @return {string} The base route.
21
- */
22
- private baseRoute(): string {
23
- return `${apiHost}/${DisbursementXTargetEnvironmentType.prod}`;
24
- }
25
-
26
- /**
27
- * This route is used to create an access token which can then be used to authorize and authenticate towards the other end-points of the API.
28
- * e.g : https://docs.google.com/document/d/1h-gMj7PSGAALxRSofOvLa2g5vF3IpDkUufNrU1hX6Yk/edit?pli=1 page 2
29
- * @return {string}
30
- */
31
- createAccessToken(): string {
32
- return apiTokenHost;
33
- }
34
-
35
- /**
36
- * This route is used to transfer an amount from the owner’s account to a payee account (customer).
37
- * e.g : https://docs.google.com/document/d/1h-gMj7PSGAALxRSofOvLa2g5vF3IpDkUufNrU1hX6Yk/edit?pli=1 page 4
38
- * @return {string} - The transfer route.
39
- */
40
- transfer(): string {
41
- return `${this.baseRoute()}/refund`;
42
- }
43
-
44
- /**
45
- * This route is used to get the status of a transfer.
46
- *
47
- * @param {string} Id - The reference of the transfer.
48
- * e.g : https://docs.google.com/document/d/1h-gMj7PSGAALxRSofOvLa2g5vF3IpDkUufNrU1hX6Yk/edit?pli=1 page 9
49
- * @return {string} - The transfer status route.
50
- */
51
- transferStatus(Id: string): string {
52
- return `${this.baseRoute()}/refund/status/${Id}`;
53
- }
54
- }
@@ -1,4 +0,0 @@
1
- export enum DisbursementXTargetEnvironmentType {
2
- sandbox = 'dev',
3
- prod = 'prod',
4
- }
@@ -1,39 +0,0 @@
1
- import {
2
- merchantPhoneNumberRegex,
3
- orangeMoneyPhoneNumberWithoutCountryCodeRegex,
4
- } from './regex';
5
-
6
- describe('Test regex merchant phone number', () => {
7
- test('Merchant phone number regex matches valid numbers', () => {
8
- const validNumbers = ['699947943', '237699947943'];
9
- validNumbers.forEach((number) => {
10
- expect(merchantPhoneNumberRegex.test(number)).toBe(true);
11
- });
12
- });
13
-
14
- test('Merchant phone number regex does not match invalid numbers', () => {
15
- const invalidNumbers = ['12345', '23712345', 'abc'];
16
- invalidNumbers.forEach((number) => {
17
- expect(merchantPhoneNumberRegex.test(number)).toBe(false);
18
- });
19
- });
20
- });
21
- describe('Test regex orange money phone number without country code', () => {
22
- test('Oman phone number without country code regex matches valid numbers', () => {
23
- const validNumbers = ['696512345', '696898765'];
24
- validNumbers.forEach((number) => {
25
- expect(orangeMoneyPhoneNumberWithoutCountryCodeRegex.test(number)).toBe(
26
- true
27
- );
28
- });
29
- });
30
-
31
- test('Orange money phone number without country code regex does not match invalid numbers', () => {
32
- const invalidNumbers = ['12345', '96812345', 'abc'];
33
- invalidNumbers.forEach((number) => {
34
- expect(orangeMoneyPhoneNumberWithoutCountryCodeRegex.test(number)).toBe(
35
- false
36
- );
37
- });
38
- });
39
- });
@@ -1,62 +0,0 @@
1
- /**
2
- * The simplified version of transaction status.
3
- */
4
- export enum DisbursementStatus {
5
- /**
6
- * The transaction failed.
7
- */
8
- failed = 'FAILED',
9
-
10
- /**
11
- * The transaction is pending.
12
- */
13
- pending = 'PENDING',
14
-
15
- /**
16
- * The transaction succeeded.
17
- */
18
- succeeded = 'SUCCEEDED',
19
-
20
- /**
21
- * The status received from the endpoint was not recognized.
22
- */
23
- unknown = 'UNKNOWN',
24
- }
25
-
26
- export enum DisbursementApiRawStatus {
27
- /**
28
- * Transaction is in progress on Orange system.
29
- */
30
- pending = 'PENDING',
31
-
32
- /**
33
- * The user canceled the disbursement.
34
- */
35
- canceled = 'CANCELLED',
36
-
37
- /**
38
- * Waiting for user entry.
39
- */
40
- initialized = 'INITIATED',
41
-
42
- /**
43
- * Disbursement is done for mobile.
44
- */
45
- succeeded = 'SUCCESSFULL',
46
-
47
- /**
48
- * Disbursement is done for web.
49
- */
50
- succeeded2 = 'SUCCESS',
51
-
52
- /**
53
- * Disbursement failed.
54
- */
55
- failed = 'FAILED',
56
-
57
- /**
58
- * The token timed out.
59
- * Note that the minimum token expiration time is 7 min.
60
- */
61
- expired = 'EXPIRED',
62
- }