@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.
Files changed (49) hide show
  1. package/package.json +4 -1
  2. package/.eslintrc.js +0 -47
  3. package/.prettierrc +0 -6
  4. package/babel.config.js +0 -3
  5. package/index.spec.ts +0 -9
  6. package/index.ts +0 -1
  7. package/jest.before-test.ts +0 -3
  8. package/jest.config.ts +0 -54
  9. package/src/disbursements/implementations/disbursement_service.ts +0 -133
  10. package/src/disbursements/implementations/src/live.ts +0 -79
  11. package/src/disbursements/implementations/src/sandbox.ts +0 -124
  12. package/src/disbursements/operations/create_access_token.spec.ts +0 -87
  13. package/src/disbursements/operations/create_access_token.ts +0 -83
  14. package/src/disbursements/operations/get_transfer_status.spec.ts +0 -132
  15. package/src/disbursements/operations/get_transfer_status.ts +0 -265
  16. package/src/disbursements/operations/transfer.spec.ts +0 -158
  17. package/src/disbursements/operations/transfer.ts +0 -125
  18. package/src/disbursements/routes/routes.ts +0 -54
  19. package/src/disbursements/utils/constants.ts +0 -4
  20. package/src/disbursements/utils/regex.spec.ts +0 -39
  21. package/src/disbursements/utils/regex.ts +0 -10
  22. package/src/disbursements/utils/status.ts +0 -62
  23. package/src/disbursements/utils/utils.spec.ts +0 -42
  24. package/src/disbursements/utils/utils.ts +0 -24
  25. package/src/index.ts +0 -12
  26. package/src/payments/implementations/fake.ts +0 -133
  27. package/src/payments/implementations/live.ts +0 -87
  28. package/src/payments/operations/get_access_token.spec.ts +0 -60
  29. package/src/payments/operations/get_access_token.ts +0 -77
  30. package/src/payments/operations/get_pay_token.spec.ts +0 -65
  31. package/src/payments/operations/get_pay_token.ts +0 -66
  32. package/src/payments/operations/get_payment_status.spec.ts +0 -82
  33. package/src/payments/operations/get_payment_status.ts +0 -78
  34. package/src/payments/operations/initialize_om_payment.spec.ts +0 -234
  35. package/src/payments/operations/initialize_om_payment.ts +0 -191
  36. package/src/payments/payments.ts +0 -86
  37. package/src/payments/routes/routes.ts +0 -61
  38. package/src/payments/utils/constants.ts +0 -120
  39. package/src/payments/utils/joi_schema.ts +0 -117
  40. package/src/payments/utils/request_model.ts +0 -103
  41. package/src/payments/utils/utils.ts +0 -31
  42. package/src/utils/https.spec.ts +0 -101
  43. package/src/utils/https.ts +0 -266
  44. package/src/utils/logging_interface.ts +0 -25
  45. package/src/utils/operation_response.ts +0 -17
  46. package/src/utils/utils.ts +0 -5
  47. package/tsconfig.build.json +0 -4
  48. package/tsconfig.dev.json +0 -4
  49. package/tsconfig.json +0 -27
@@ -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
- }
@@ -1,120 +0,0 @@
1
- export enum ApiKey {
2
- keyAuthorization = 'Authorization',
3
- keyGrantType = 'grant_type',
4
- keyContentType = 'Content-Type',
5
- keyXAuthToken = 'X-AUTH-TOKEN',
6
- keyMerchantKey = 'merchant_key',
7
- keyCurrency = 'currency',
8
- keyOrderId = 'order_id',
9
- keyReturnUrl = 'return_url',
10
- keyCancelUrl = 'cancel_url',
11
- keyWebNotifyUrl = 'notif_url',
12
- keyLang = 'lang',
13
- keyReference = 'reference',
14
- keyAmount = 'amount',
15
- keyPayToken = 'pay_token',
16
- keySubscriberMsisdn = 'subscriberMsisdn',
17
- keyChannelUserMsisdn = 'channelUserMsisdn',
18
- keyDescription = 'description',
19
- keyMobileOrderId = 'orderId',
20
- keyPin = 'pin',
21
- keyMobilePayToken = 'payToken',
22
- keyMobileNotifUrl = 'notifUrl',
23
- }
24
-
25
- /**
26
- * Contains request fields.
27
- */
28
- export class ConstantRequestField {
29
- // The content type field.
30
- public static readonly typeJson = 'application/json';
31
-
32
- // The url encode form.
33
- public static readonly TypeWwwFrom = 'application/x-www-form-urlencoded';
34
-
35
- // The basic authorization field.
36
- public static readonly basic = 'Basic ';
37
-
38
- // The authorization field.
39
- public static readonly authorization = 'AUTHORIZATION';
40
-
41
- // The bearer field.
42
- public static readonly bearer = 'Bearer ';
43
-
44
- // The grant type field.
45
- public static readonly grantType = 'grant_type';
46
-
47
- // The client credentials field.
48
- public static readonly clientCredentials = 'client_credentials';
49
-
50
- // The X-AUTH-TOKEN field.
51
- public static readonly xAuthToken = 'X-AUTH-TOKEN';
52
- }
53
-
54
- /**
55
- * The orange money payment status.
56
- */
57
- export enum OrangeMoneyPaymentStatus {
58
- /**
59
- * User has clicked on “Confirmed”, transaction
60
- * is in progress on Orange system.
61
- */
62
- PENDING_PAYMENT = 'PENDING',
63
-
64
- /**
65
- * The user canceled the payment.
66
- */
67
- CANCELLED_PAYMENT = 'CANCELLED',
68
-
69
- /**
70
- * Waiting for user entry.
71
- * Specially for web.
72
- */
73
- INITIATE_PAYMENT = 'INITIATED',
74
-
75
- /**
76
- * Payment is done for mobile.
77
- */
78
- SUCCESSFULL_MOBILE_PAYMENT = 'SUCCESSFULL',
79
-
80
- /**
81
- * Payment is done for web.
82
- */
83
- SUCCESS_WEB_PAYMENT = 'SUCCESS',
84
-
85
- /**
86
- * Payment has failed.
87
- * On web, the status can failed when user press to confirm payment too
88
- * late or when user enter a wrong validation code.
89
- * On mobile, it may fail when the user does not have a mooney orange wallet
90
- * or the account balance is insufficient.
91
- */
92
- FAILED_PAYMENT = 'FAILED',
93
-
94
- /**
95
- * User has clicked on “Confirmed” too late (after token’s validity), or the
96
- * delay token timeout has expired.
97
- * Note that the minimum token expiration time is 7 min.
98
- */
99
- EXPIRED_PAYMENT = 'EXPIRED',
100
- }
101
-
102
- export enum ApiErrorType {
103
- insufficientFunds = 'insufficientFunds',
104
- invalidOrangeMoneyNumber = 'invalidOrangeMoneyNumber',
105
- invalidData = 'invalidData',
106
- failedToInitiateThePayment = 'failedToInitiateThePayment',
107
- failedToGenerateAccessToken = 'failedToGenerateAccessToken',
108
- failedToCheckPaymentStatus = 'failedToCheckPaymentStatus',
109
- failedToGeneratePayToken = 'failedToGeneratePayToken',
110
- accountLocked = 'accountLocked',
111
- invalidPaymentAmount = 'invalidPaymentAmount',
112
- unauthorized = 'unauthorized',
113
- }
114
-
115
- export enum OrangeMoneyErrorMessage {
116
- beneficiaryNotFound = 'Beneficiaire introuvable',
117
- insufficientFunds = 'Le solde du compte du payeur est insuffisant',
118
- accountLocked = 'Utilisateur bloque',
119
- invalidPaymentAmount = 'Vous avez saisi un montant superieur au montant maximum autorise',
120
- }
@@ -1,117 +0,0 @@
1
- import Joi from 'joi';
2
- import { LoggerInterface } from '../../utils/logging_interface';
3
- import { TargetEnvironment } from '../../utils/utils';
4
- import { OrangeMoneyPaymentStatus } from './constants';
5
-
6
- /**
7
- * The provider generic response data of payment request of status verification request.
8
- */
9
- export type GenericRequestResponseData = {
10
- message: string;
11
- data: {
12
- id: number;
13
- createtime: string | null;
14
- subscriberMsisdn: string;
15
- amount: number;
16
- payToken: string;
17
- txnid: string | null;
18
- txnmode: string | null;
19
- inittxnmessage: string;
20
- inittxnstatus: string;
21
- confirmtxnstatus: string | null;
22
- confirmtxnmessage: string | null;
23
- status: OrangeMoneyPaymentStatus;
24
- notifUrl: string | null;
25
- description: string | null;
26
- channelUserMsisdn: string;
27
- };
28
- };
29
-
30
- /**
31
- * The provider generic response data of payment request of status verification request.
32
- * We only make validation off fields that are required.
33
- */
34
- export const genericRequestResponseSchema =
35
- Joi.object<GenericRequestResponseData>({
36
- message: Joi.string().required(),
37
- data: Joi.object({
38
- subscriberMsisdn: Joi.string().required(),
39
- amount: Joi.number().required(),
40
- inittxnmessage: Joi.string().allow(null).allow('').required(),
41
- status: Joi.string()
42
- .valid(
43
- OrangeMoneyPaymentStatus.FAILED_PAYMENT,
44
- OrangeMoneyPaymentStatus.PENDING_PAYMENT,
45
- OrangeMoneyPaymentStatus.CANCELLED_PAYMENT,
46
- OrangeMoneyPaymentStatus.EXPIRED_PAYMENT,
47
- OrangeMoneyPaymentStatus.SUCCESSFULL_MOBILE_PAYMENT
48
- )
49
- .required(),
50
- channelUserMsisdn: Joi.string().required(),
51
- })
52
- .required()
53
- .unknown(true),
54
- });
55
-
56
- export type InitPaymentBodySchema = {
57
- orderId: string;
58
- description: string;
59
- orangeMoneyVersion?: string;
60
- notifUrl: string;
61
- pin: string;
62
- payToken: string;
63
- amount: number;
64
- channelUserMsisdn: string;
65
- subscriberMsisdn: string;
66
- };
67
-
68
- export const initPaymentBodySchema = Joi.object<InitPaymentBodySchema>({
69
- subscriberMsisdn: Joi.string()
70
- .required()
71
- .pattern(/^(69\d{7}$|65[5-9]\d{6}$)/)
72
- .message(
73
- '[subscriberMsisdn] Invalid orange number. Format of valid number: 69******* or 65[5-9]******'
74
- ),
75
- channelUserMsisdn: Joi.string()
76
- .required()
77
- .pattern(/^(69\d{7}$|65[5-9]\d{6}$)/)
78
- .message(
79
- '[channelUserMsisdn] Invalid orange number. Format of valid number: 69******* or 65[5-9]******'
80
- ),
81
- amount: Joi.string().required(),
82
- payToken: Joi.string().required(),
83
- pin: Joi.string().max(4).required(),
84
- notifUrl: Joi.string().allow('').default(''),
85
- orangeMoneyVersion: Joi.string().optional(),
86
- description: Joi.string().allow('').max(125).default('payment'),
87
- orderId: Joi.string().max(20).required(),
88
- });
89
-
90
- export interface OrangeMoneyPaymentParams {
91
- targetEnvironment: TargetEnvironment;
92
- logger: LoggerInterface;
93
- apiUserName: string;
94
- apiPassword: string;
95
- xAuthToken: string;
96
- orangeMoneyVersion?: string;
97
- }
98
-
99
- /**
100
- * The provider access token request response from the OM server.
101
- */
102
- export type AccessTokenRequestResponse = {
103
- access_token: string;
104
- scope: string;
105
- token_type: string;
106
- expires_in: number;
107
- };
108
-
109
- /**
110
- * The provider payToken request response from the OM server.
111
- */
112
- export type PayTokenRequestResponse = {
113
- message: string;
114
- data: {
115
- payToken: string;
116
- };
117
- };
@@ -1,103 +0,0 @@
1
- import { OperationResponse } from '../../utils/operation_response';
2
- import { ApiErrorType, OrangeMoneyPaymentStatus } from './constants';
3
- import {
4
- AccessTokenRequestResponse,
5
- GenericRequestResponseData,
6
- PayTokenRequestResponse,
7
- } from './joi_schema';
8
-
9
- export type InitializeOrangeMoneyRequest = {
10
- /**
11
- * The phone number of the user making the payment.
12
- */
13
- subscriberNumber: string;
14
- /**
15
- * The phone number of the user receiving the payment.
16
- */
17
- channelUserNumber: string;
18
- /**
19
- * Unique identifier of the customer transaction.
20
- */
21
- transactionId: string;
22
- /**
23
- * The amount of the transaction.
24
- */
25
- amount: number;
26
- /**
27
- * The Pin code of the ChannelUser.
28
- */
29
- pinCode: string;
30
- /**
31
- * An http endpoint able to receive a post request with the following json body.
32
- * {
33
- * ”payToken” : ”payToken”,
34
- * ”status” : status”,
35
- * ”message” : ”message”
36
- * }
37
- */
38
- notifUrl?: string;
39
- /**
40
- * The payment description.
41
- */
42
- description?: string;
43
-
44
- /**
45
- * The payToken value useful to make payment
46
- * and track the status of payment.
47
- */
48
- payToken: string;
49
-
50
- /**
51
- * The access token for authorize the request.
52
- */
53
- accessToken: string;
54
- };
55
-
56
- export type GetOrangeMoneyPaymentRequest = {
57
- /**
58
- * The access token for authorize the request.
59
- */
60
- accessToken: string;
61
-
62
- /**
63
- * unique identifier used to obtain payment status.
64
- */
65
- payToken: string;
66
- };
67
-
68
- /**
69
- * This response is obtained when we initiate a mobile payment request,
70
- * the request would generate a payToken useful to make payment
71
- * and track the status of payment.
72
- */
73
- export type InitializeOrangeMoneyResponse = OperationResponse<
74
- {
75
- /**
76
- * The payToken value useful to make payment
77
- * and track the status of payment.
78
- */
79
- payToken: string;
80
- },
81
- GenericRequestResponseData,
82
- ApiErrorType
83
- >;
84
-
85
- export type GetOrangeMoneyPaymentResponse = OperationResponse<
86
- {
87
- status: OrangeMoneyPaymentStatus;
88
- },
89
- GenericRequestResponseData,
90
- ApiErrorType
91
- >;
92
-
93
- export type GetAccessTokenResponse = OperationResponse<
94
- string,
95
- AccessTokenRequestResponse | undefined,
96
- ApiErrorType
97
- >;
98
-
99
- export type GetPayTokenResponse = OperationResponse<
100
- string,
101
- PayTokenRequestResponse | undefined,
102
- ApiErrorType
103
- >;
@@ -1,31 +0,0 @@
1
- import Joi from 'joi';
2
-
3
- /**
4
- * Checks if the data is valid type.
5
- * @param {Record<string, unknown>} data .
6
- * @param {Joi.PartialSchemaMap<T>} schema .
7
- * @return {Record<string, unknown>}
8
- */
9
- export function validateData<T>(
10
- data: unknown,
11
- schema: Joi.ObjectSchema<T>
12
- ): { isValidData: true; data: T } | { isValidData: false; message: string } {
13
- const { error, value } = schema.unknown(true).validate(data, {
14
- abortEarly: false,
15
- convert: false,
16
- });
17
- if (error) {
18
- return {
19
- isValidData: false,
20
- message: JSON.stringify(
21
- error.details.map((e) => e.message),
22
- null,
23
- ' '
24
- ),
25
- };
26
- }
27
- return {
28
- isValidData: true,
29
- data: value,
30
- };
31
- }
@@ -1,101 +0,0 @@
1
- import {
2
- encodeTheBodyOfRequest,
3
- encodeToBase64,
4
- hash,
5
- parseAxiosError,
6
- } from './https';
7
- import { AxiosError, AxiosResponse } from 'axios';
8
-
9
- describe('hash', () => {
10
- const btoaRef = global.btoa;
11
- it('should still Hash if the btao function is not available', () => {
12
- global.btoa = undefined as unknown as typeof btoaRef;
13
- const hashResponse = hash('key', 'secret');
14
- expect(hashResponse).toBe('a2V5OnNlY3JldA==');
15
- global.btoa = btoaRef;
16
- });
17
- });
18
-
19
- describe('parseAxiosError', () => {
20
- it('should return initial obj if not instance of axios error', () => {
21
- const initialObj = { key: 'ERROR_100' };
22
- const parsedResponse = parseAxiosError(initialObj);
23
- expect(parsedResponse).toBe(initialObj);
24
- });
25
-
26
- it('should have the configuration failed message when config failed', () => {
27
- const message = 'configuration failed';
28
- const parsedResponse = parseAxiosError(
29
- new AxiosError(message) as unknown as Record<string, unknown>
30
- );
31
- expect(parsedResponse).toEqual({
32
- configFailed: message,
33
- });
34
- });
35
-
36
- it('should return request failed when axios is unable to send the request.', () => {
37
- const request = {
38
- headers: {
39
- 'Content-Type': 'application/json',
40
- },
41
- };
42
- const parsedResponse = parseAxiosError(
43
- new AxiosError('message', '400', undefined, request) as unknown as Record<
44
- string,
45
- unknown
46
- >
47
- );
48
- expect(parsedResponse).toEqual({
49
- requestFailed: { data: undefined, headers: undefined },
50
- });
51
- });
52
-
53
- it('should return response error when the request response fail to be retrieve.', () => {
54
- const request = {
55
- headers: {
56
- 'Content-Type': 'application/json',
57
- },
58
- body: '',
59
- };
60
- const response = <AxiosResponse>{
61
- data: '',
62
- status: 201,
63
- statusText: 'created',
64
- headers: {},
65
- request: request,
66
- };
67
-
68
- const parsedResponse = parseAxiosError(
69
- new AxiosError(
70
- 'message',
71
- '400',
72
- undefined,
73
- request,
74
- response
75
- ) as unknown as Record<string, unknown>
76
- );
77
- expect(parsedResponse).toEqual({
78
- responseError: {
79
- data: response.data,
80
- status: response.status,
81
- statusText: response.statusText,
82
- headers: response.headers,
83
- },
84
- requestBody: request.body,
85
- });
86
- });
87
- });
88
-
89
- describe('Test the utils function', () => {
90
- it('Generate the base 64 encoding', async () => {
91
- const value = encodeToBase64('123', '123');
92
- expect(value).toEqual('MTIzOjEyMw');
93
- });
94
- it('encode the body request', async () => {
95
- const body = {
96
- amount: '123',
97
- };
98
- const value = encodeTheBodyOfRequest(body);
99
- expect(value).toEqual('amount=123');
100
- });
101
- });