moosyl 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/src/helpers/exceptions.d.ts +20 -0
- package/dist/src/helpers/exceptions.d.ts.map +1 -0
- package/dist/src/helpers/exceptions.js +22 -0
- package/dist/src/helpers/exceptions.js.map +1 -0
- package/dist/src/helpers/fetcher.d.ts +46 -0
- package/dist/src/helpers/fetcher.d.ts.map +1 -0
- package/dist/src/helpers/fetcher.js +128 -0
- package/dist/src/helpers/fetcher.js.map +1 -0
- package/dist/src/models/payment-method-model.d.ts +61 -0
- package/dist/src/models/payment-method-model.d.ts.map +1 -0
- package/dist/src/models/payment-method-model.js +112 -0
- package/dist/src/models/payment-method-model.js.map +1 -0
- package/dist/src/models/payment-request-model.d.ts +15 -0
- package/dist/src/models/payment-request-model.d.ts.map +1 -0
- package/dist/src/models/payment-request-model.js +22 -0
- package/dist/src/models/payment-request-model.js.map +1 -0
- package/dist/src/services/get-payment-methods-service.d.ts +10 -0
- package/dist/src/services/get-payment-methods-service.d.ts.map +1 -0
- package/dist/src/services/get-payment-methods-service.js +18 -0
- package/dist/src/services/get-payment-methods-service.js.map +1 -0
- package/dist/src/services/get-payment-request-service.d.ts +10 -0
- package/dist/src/services/get-payment-request-service.d.ts.map +1 -0
- package/dist/src/services/get-payment-request-service.js +18 -0
- package/dist/src/services/get-payment-request-service.js.map +1 -0
- package/dist/src/services/pay-service.d.ts +16 -0
- package/dist/src/services/pay-service.d.ts.map +1 -0
- package/dist/src/services/pay-service.js +61 -0
- package/dist/src/services/pay-service.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Moosyl JavaScript SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/moosyl)
|
|
4
|
+
|
|
5
|
+
The **Moosyl JavaScript SDK** helps you integrate payment solutions with Mauritania's popular banking apps—such as **Bankily**, **Sedad**, and **Masrivi**—in Node.js or the browser. Use it to fetch available payment methods and payment request details from the Moosyl API.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Payment methods**: Fetch available payment methods (including testing mode).
|
|
12
|
+
- **Payment request**: Get payment request details by transaction ID.
|
|
13
|
+
- **Lightweight**: No UI; use your own front end or backend flows.
|
|
14
|
+
- **ESM**: Native ES modules (`import`).
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
Install the package:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install moosyl
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Import the package
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import {
|
|
32
|
+
GetPaymentMethodsService,
|
|
33
|
+
GetPaymentRequestService,
|
|
34
|
+
PaymentRequestModel,
|
|
35
|
+
PaymentMethodTitles,
|
|
36
|
+
} from "moosyl";
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Fetch payment methods
|
|
44
|
+
|
|
45
|
+
Get the list of payment methods (e.g. to show options to the user):
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import { GetPaymentMethodsService } from "moosyl";
|
|
49
|
+
|
|
50
|
+
const service = new GetPaymentMethodsService("YOUR_PUBLISHABLE_API_KEY");
|
|
51
|
+
const methods = await service.get(true); // true = testing mode
|
|
52
|
+
|
|
53
|
+
methods.forEach((m) => {
|
|
54
|
+
const title = PaymentMethodTitles[m.method] ?? m.method;
|
|
55
|
+
console.log(title, m.type, m.id);
|
|
56
|
+
// Bankily/Sedad/etc. may expose m.bPayNumber or m.merchantCode
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Fetch payment request details
|
|
61
|
+
|
|
62
|
+
Get details for a given transaction (after creating a payment request from your backend):
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
import { GetPaymentRequestService } from "moosyl";
|
|
66
|
+
|
|
67
|
+
const service = new GetPaymentRequestService("YOUR_PUBLISHABLE_API_KEY");
|
|
68
|
+
const request = await service.get("TRANSACTION_ID");
|
|
69
|
+
|
|
70
|
+
console.log(request.id, request.amount, request.phoneNumber);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Create a payment request (backend)
|
|
74
|
+
|
|
75
|
+
Payment requests are created on your backend with your **secret API key**. The SDK does not create them; it only fetches payment methods and payment request details. Example with cURL:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
curl -X POST https://api.moosyl.com/payment-request \
|
|
79
|
+
-H "Authorization: YOUR_SECRET_API_KEY" \
|
|
80
|
+
-H "Content-Type: application/json" \
|
|
81
|
+
-d '{
|
|
82
|
+
"phoneNumber": "+22212345678",
|
|
83
|
+
"transactionId": "your-unique-transaction-id",
|
|
84
|
+
"amount": 5000
|
|
85
|
+
}'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Once created, use the returned **transactionId** with `GetPaymentRequestService` and your payment flow.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## API overview
|
|
93
|
+
|
|
94
|
+
| Export | Description |
|
|
95
|
+
| ---------------------------------------------------------- | ------------------------------------------------------ |
|
|
96
|
+
| `GetPaymentMethodsService` | Fetches available payment methods. |
|
|
97
|
+
| `GetPaymentRequestService` | Fetches payment request by transaction ID. |
|
|
98
|
+
| `PaymentRequestModel` | Model for payment request (id, amount, phoneNumber). |
|
|
99
|
+
| `PaymentMethod`, `BankilyConfigModel`, `ManualConfigModel` | Payment method models. |
|
|
100
|
+
| `PaymentMethodTitles` | Display names for payment method types. |
|
|
101
|
+
| `PaymentType`, `PaymentMethodTypes` | Enums/constants for method and type. |
|
|
102
|
+
| `Fetcher`, `Endpoints` | Low-level HTTP client and API URLs (for advanced use). |
|
|
103
|
+
| `AppException` | Error type thrown on failed API calls. |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Configuration
|
|
108
|
+
|
|
109
|
+
- **API key**: Use your **publishable** API key for `GetPaymentMethodsService` and `GetPaymentRequestService`. Get keys at [moosyl.com](https://moosyl.com).
|
|
110
|
+
- **Testing mode**: Pass `true` to `GetPaymentMethodsService#get(isTestingMode)` for test configuration.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Documentation
|
|
115
|
+
|
|
116
|
+
For more guides and API details, see [docs.moosyl.com](https://docs.moosyl.com).
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Contributing
|
|
121
|
+
|
|
122
|
+
1. Fork this repository.
|
|
123
|
+
2. Create a feature branch (`git checkout -b feature-name`).
|
|
124
|
+
3. Commit your changes (`git commit -m 'Add feature'`).
|
|
125
|
+
4. Push to your branch (`git push origin feature-name`).
|
|
126
|
+
5. Open a pull request.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Support
|
|
131
|
+
|
|
132
|
+
- [moosyl.com](https://moosyl.com)
|
|
133
|
+
- support@moosyl.com
|
|
134
|
+
- [GitHub Issues](https://github.com/SoftwareSavants/moosyl_js/issues)
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
This project is licensed under the ISC License. See the [LICENSE](LICENSE) file for details.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
**Integrate Moosyl into your Node or web app.**
|
|
145
|
+
Get started at [moosyl.com](https://moosyl.com).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moosyl JS – integrating payment solutions with Mauritania's popular banking apps.
|
|
3
|
+
*/
|
|
4
|
+
export { Fetcher, FetcherResponse, Endpoints } from './src/helpers/fetcher.js';
|
|
5
|
+
export { AppException, AppExceptionCode } from './src/helpers/exceptions.js';
|
|
6
|
+
export { PaymentType, PaymentMethodTypes, PaymentMethodTitles, paymentTypeFromString, paymentMethodTypesFromString, PaymentMethod, BankilyConfigModel, ManualConfigModel, } from './src/models/payment-method-model.js';
|
|
7
|
+
export type { PaymentTypeValue, PaymentMethodTypesValue } from './src/models/payment-method-model.js';
|
|
8
|
+
export { PaymentRequestModel } from './src/models/payment-request-model.js';
|
|
9
|
+
export { GetPaymentMethodsService } from './src/services/get-payment-methods-service.js';
|
|
10
|
+
export { GetPaymentRequestService } from './src/services/get-payment-request-service.js';
|
|
11
|
+
export { PayService } from './src/services/pay-service.js';
|
|
12
|
+
export type { ManualPayImageInput } from './src/services/pay-service.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sCAAsC,CAAC;AAC9C,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAEtG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,YAAY,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moosyl JS – integrating payment solutions with Mauritania's popular banking apps.
|
|
3
|
+
*/
|
|
4
|
+
export { Fetcher, FetcherResponse, Endpoints } from './src/helpers/fetcher.js';
|
|
5
|
+
export { AppException, AppExceptionCode } from './src/helpers/exceptions.js';
|
|
6
|
+
export { PaymentType, PaymentMethodTypes, PaymentMethodTitles, paymentTypeFromString, paymentMethodTypesFromString, PaymentMethod, BankilyConfigModel, ManualConfigModel, } from './src/models/payment-method-model.js';
|
|
7
|
+
export { PaymentRequestModel } from './src/models/payment-request-model.js';
|
|
8
|
+
export { GetPaymentMethodsService } from './src/services/get-payment-methods-service.js';
|
|
9
|
+
export { GetPaymentRequestService } from './src/services/get-payment-request-service.js';
|
|
10
|
+
export { PayService } from './src/services/pay-service.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception codes returned by the API or used internally.
|
|
3
|
+
*/
|
|
4
|
+
export declare const AppExceptionCode: {
|
|
5
|
+
readonly unknown: "unknown";
|
|
6
|
+
};
|
|
7
|
+
export type AppExceptionCodeType = (typeof AppExceptionCode)[keyof typeof AppExceptionCode];
|
|
8
|
+
/**
|
|
9
|
+
* Application exception with code and message.
|
|
10
|
+
* Thrown when API requests fail.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AppException extends Error {
|
|
13
|
+
code: string;
|
|
14
|
+
message: string;
|
|
15
|
+
constructor(options: {
|
|
16
|
+
code?: string;
|
|
17
|
+
message?: string;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../../src/helpers/exceptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,gBAAgB;;CAEnB,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE5F;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAC;IACJ,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;CAOzD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception codes returned by the API or used internally.
|
|
3
|
+
*/
|
|
4
|
+
export const AppExceptionCode = {
|
|
5
|
+
unknown: 'unknown',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Application exception with code and message.
|
|
9
|
+
* Thrown when API requests fail.
|
|
10
|
+
*/
|
|
11
|
+
export class AppException extends Error {
|
|
12
|
+
code;
|
|
13
|
+
message;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
const message = options.message ?? 'An error occurred';
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'AppException';
|
|
18
|
+
this.code = options.code ?? AppExceptionCode.unknown;
|
|
19
|
+
this.message = message;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../../src/helpers/exceptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,SAAS;CACV,CAAC;AAIX;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,IAAI,CAAS;IACJ,OAAO,CAAS;IAEzB,YAAY,OAA4C;QACtD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,mBAAmB,CAAC;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAC,OAAO,CAAC;QACrD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AppException } from './exceptions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Static API base URL and endpoint builders.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Endpoints: {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
paymentMethods(isTestingMode: boolean): string;
|
|
8
|
+
readonly pay: string;
|
|
9
|
+
readonly manualPayment: string;
|
|
10
|
+
paymentRequest(id: string): string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* HTTP client for Moosyl API. Sends GET/POST with auth header.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Fetcher {
|
|
16
|
+
publishableApiKey: string;
|
|
17
|
+
constructor(publishableApiKey: string);
|
|
18
|
+
get headers(): Record<string, string>;
|
|
19
|
+
static fromResponse(response: Response, bytes?: boolean): Promise<FetcherResponse>;
|
|
20
|
+
get(url: string, options?: {
|
|
21
|
+
bytes?: boolean;
|
|
22
|
+
}): Promise<FetcherResponse>;
|
|
23
|
+
post(url: string, body?: Record<string, unknown>): Promise<FetcherResponse>;
|
|
24
|
+
multipartPost(url: string, body: Record<string, string>, files?: {
|
|
25
|
+
name: string;
|
|
26
|
+
data: Buffer | Blob;
|
|
27
|
+
filename?: string;
|
|
28
|
+
}[]): Promise<FetcherResponse>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Wrapper for API response (url, status, data).
|
|
32
|
+
*/
|
|
33
|
+
export declare class FetcherResponse {
|
|
34
|
+
readonly url: string;
|
|
35
|
+
readonly status: number;
|
|
36
|
+
readonly data: unknown;
|
|
37
|
+
constructor(options: {
|
|
38
|
+
url: string;
|
|
39
|
+
status: number;
|
|
40
|
+
data: unknown;
|
|
41
|
+
});
|
|
42
|
+
get success(): boolean;
|
|
43
|
+
stripHtmlIfNeeded(text: string): string;
|
|
44
|
+
toException(): AppException;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/helpers/fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,SAAS;;kCAGU,OAAO,GAAG,MAAM;kBAInC,MAAM;4BAII,MAAM;uBAIR,MAAM,GAAG,MAAM;CAGnC,CAAC;AAUF;;GAEG;AACH,qBAAa,OAAO;IA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+
* Static API base URL and endpoint builders.
|
|
4
|
+
*/
|
|
5
|
+
export const Endpoints = {
|
|
6
|
+
baseUrl: 'https://moosyl.moosyl.workers.dev',
|
|
7
|
+
paymentMethods(isTestingMode) {
|
|
8
|
+
return `${this.baseUrl}/configuration?isTestingMode=${isTestingMode}`;
|
|
9
|
+
},
|
|
10
|
+
get pay() {
|
|
11
|
+
return `${this.baseUrl}/payment`;
|
|
12
|
+
},
|
|
13
|
+
get manualPayment() {
|
|
14
|
+
return `${this.baseUrl}/payment/manual`;
|
|
15
|
+
},
|
|
16
|
+
paymentRequest(id) {
|
|
17
|
+
return `${this.baseUrl}/payment-request/by-transaction/${id}`;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
function parseResponseBody(body) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(body);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return body;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* HTTP client for Moosyl API. Sends GET/POST with auth header.
|
|
30
|
+
*/
|
|
31
|
+
export class Fetcher {
|
|
32
|
+
publishableApiKey;
|
|
33
|
+
constructor(publishableApiKey) {
|
|
34
|
+
this.publishableApiKey = publishableApiKey;
|
|
35
|
+
}
|
|
36
|
+
get headers() {
|
|
37
|
+
return {
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
Authorization: this.publishableApiKey,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
static async fromResponse(response, bytes = false) {
|
|
43
|
+
const url = response.url ?? '';
|
|
44
|
+
const status = response.status;
|
|
45
|
+
const body = await response.text();
|
|
46
|
+
const data = bytes ? body : parseResponseBody(body);
|
|
47
|
+
return new FetcherResponse({ url, status, data });
|
|
48
|
+
}
|
|
49
|
+
async get(url, options = {}) {
|
|
50
|
+
const { bytes = false } = options;
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
method: 'GET',
|
|
53
|
+
headers: this.headers,
|
|
54
|
+
signal: AbortSignal.timeout(60_000),
|
|
55
|
+
});
|
|
56
|
+
const res = await Fetcher.fromResponse(response, bytes);
|
|
57
|
+
if (!res.success)
|
|
58
|
+
throw res.toException();
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
async post(url, body) {
|
|
62
|
+
const response = await fetch(url, {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: this.headers,
|
|
65
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
66
|
+
signal: AbortSignal.timeout(60_000),
|
|
67
|
+
});
|
|
68
|
+
const res = await Fetcher.fromResponse(response);
|
|
69
|
+
if (!res.success)
|
|
70
|
+
throw res.toException();
|
|
71
|
+
return res;
|
|
72
|
+
}
|
|
73
|
+
async multipartPost(url, body, files = []) {
|
|
74
|
+
const form = new FormData();
|
|
75
|
+
for (const [key, value] of Object.entries(body)) {
|
|
76
|
+
form.append(key, value);
|
|
77
|
+
}
|
|
78
|
+
for (const file of files) {
|
|
79
|
+
const blob = file.data instanceof Blob ? file.data : new Blob([new Uint8Array(file.data)]);
|
|
80
|
+
form.append('attachments', blob, file.filename ?? file.name);
|
|
81
|
+
}
|
|
82
|
+
const headers = { Authorization: this.publishableApiKey };
|
|
83
|
+
const response = await fetch(url, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers,
|
|
86
|
+
body: form,
|
|
87
|
+
signal: AbortSignal.timeout(60_000),
|
|
88
|
+
});
|
|
89
|
+
const res = await Fetcher.fromResponse(response);
|
|
90
|
+
if (!res.success)
|
|
91
|
+
throw res.toException();
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wrapper for API response (url, status, data).
|
|
97
|
+
*/
|
|
98
|
+
export class FetcherResponse {
|
|
99
|
+
url;
|
|
100
|
+
status;
|
|
101
|
+
data;
|
|
102
|
+
constructor(options) {
|
|
103
|
+
this.url = options.url;
|
|
104
|
+
this.status = options.status;
|
|
105
|
+
this.data = options.data;
|
|
106
|
+
}
|
|
107
|
+
get success() {
|
|
108
|
+
return this.status >= 200 && this.status <= 299;
|
|
109
|
+
}
|
|
110
|
+
stripHtmlIfNeeded(text) {
|
|
111
|
+
return String(text).replace(/<[^>]*>|&[^;]+;/g, ' ');
|
|
112
|
+
}
|
|
113
|
+
toException() {
|
|
114
|
+
const data = this.data;
|
|
115
|
+
const code = typeof data === 'string'
|
|
116
|
+
? data
|
|
117
|
+
: (data && typeof data === 'object' && 'code' in data
|
|
118
|
+
? data.code
|
|
119
|
+
: AppExceptionCode.unknown);
|
|
120
|
+
const message = typeof data === 'string'
|
|
121
|
+
? data
|
|
122
|
+
: (data && typeof data === 'object' && 'message' in data
|
|
123
|
+
? data.message
|
|
124
|
+
: 'An error occurred');
|
|
125
|
+
return new AppException({ code, message: String(message) });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=fetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../../../src/helpers/fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEjE;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,mCAAmC;IAE5C,cAAc,CAAC,aAAsB;QACnC,OAAO,GAAG,IAAI,CAAC,OAAO,gCAAgC,aAAa,EAAE,CAAC;IACxE,CAAC;IAED,IAAI,GAAG;QACL,OAAO,GAAG,IAAI,CAAC,OAAO,UAAU,CAAC;IACnC,CAAC;IAED,IAAI,aAAa;QACf,OAAO,GAAG,IAAI,CAAC,OAAO,iBAAiB,CAAC;IAC1C,CAAC;IAED,cAAc,CAAC,EAAU;QACvB,OAAO,GAAG,IAAI,CAAC,OAAO,mCAAmC,EAAE,EAAE,CAAC;IAChE,CAAC;CACF,CAAC;AAEF,SAAS,iBAAiB,CAAC,IAAY;IACrC,IAAI,CA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I;gBACjD,CAAC,CAAE,IAAyB,CAAC,IAAI;gBACjC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,OAAO,GACX,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,SAAS,IAAI,IAAI;gBACpD,CAAC,CAAE,IAA4B,CAAC,OAAO;gBACvC,CAAC,CAAC,mBAAmB,CAAC,CAAC;QAC/B,OAAO,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type PaymentTypeValue = 'manual' | 'auto';
|
|
2
|
+
export declare const PaymentType: {
|
|
3
|
+
readonly manual: "manual";
|
|
4
|
+
readonly auto: "auto";
|
|
5
|
+
};
|
|
6
|
+
export declare function paymentTypeFromString(type: string): PaymentTypeValue;
|
|
7
|
+
export type PaymentMethodTypesValue = 'masrivi' | 'bankily' | 'sedad' | 'bim_bank' | 'amanty' | 'bci_pay';
|
|
8
|
+
export declare const PaymentMethodTypes: {
|
|
9
|
+
readonly masrivi: "masrivi";
|
|
10
|
+
readonly bankily: "bankily";
|
|
11
|
+
readonly sedad: "sedad";
|
|
12
|
+
readonly bimBank: "bim_bank";
|
|
13
|
+
readonly amanty: "amanty";
|
|
14
|
+
readonly bCIpay: "bci_pay";
|
|
15
|
+
};
|
|
16
|
+
/** Human-readable titles for payment methods (no i18n in core). */
|
|
17
|
+
export declare const PaymentMethodTitles: Record<string, string>;
|
|
18
|
+
export declare function paymentMethodTypesFromString(method: string): PaymentMethodTypesValue;
|
|
19
|
+
/**
|
|
20
|
+
* Base payment method (id, method type, payment type).
|
|
21
|
+
*/
|
|
22
|
+
export declare class PaymentMethod {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly method: PaymentMethodTypesValue;
|
|
25
|
+
readonly type: PaymentTypeValue;
|
|
26
|
+
constructor(options: {
|
|
27
|
+
id: string;
|
|
28
|
+
method: PaymentMethodTypesValue;
|
|
29
|
+
type: PaymentTypeValue;
|
|
30
|
+
});
|
|
31
|
+
static fromMap(map: Record<string, unknown>): PaymentMethod;
|
|
32
|
+
static fromPaymentMethod(map: Record<string, unknown>): PaymentMethod;
|
|
33
|
+
static fromPaymentType(map: Record<string, unknown>): PaymentMethod;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Bankily payment method config (adds bPayNumber).
|
|
37
|
+
*/
|
|
38
|
+
export declare class BankilyConfigModel extends PaymentMethod {
|
|
39
|
+
readonly bPayNumber: string;
|
|
40
|
+
constructor(options: {
|
|
41
|
+
id: string;
|
|
42
|
+
method: PaymentMethodTypesValue;
|
|
43
|
+
type: PaymentTypeValue;
|
|
44
|
+
bPayNumber: string;
|
|
45
|
+
});
|
|
46
|
+
static fromMap(map: Record<string, unknown>): BankilyConfigModel;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Manual payment method config (adds merchantCode).
|
|
50
|
+
*/
|
|
51
|
+
export declare class ManualConfigModel extends PaymentMethod {
|
|
52
|
+
readonly merchantCode: string;
|
|
53
|
+
constructor(options: {
|
|
54
|
+
id: string;
|
|
55
|
+
method: PaymentMethodTypesValue;
|
|
56
|
+
type: PaymentTypeValue;
|
|
57
|
+
merchantCode: string;
|
|
58
|
+
});
|
|
59
|
+
static fromMap(map: Record<string, unknown>): ManualConfigModel;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=payment-method-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-method-model.d.ts","sourceRoot":"","sources":["../../../src/models/payment-method-model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEjD,eAAO,MAAM,WAAW;;;CAGd,CA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AAM,EAAE,OAAO,CAAC,GAAG,kBAAkB;CAU1E;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAElB,OAAO,EAAE;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,uBAAuB,CAAC;QAChC,IAAI,EAAE,gBAAgB,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;KACtB;WAKe,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,iBAAiB;CAUzE"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export const PaymentType = {
|
|
2
|
+
manual: 'manual',
|
|
3
|
+
auto: 'auto',
|
|
4
|
+
};
|
|
5
|
+
export function paymentTypeFromString(type) {
|
|
6
|
+
if (type === PaymentType.manual || type === PaymentType.auto)
|
|
7
|
+
return type;
|
|
8
|
+
throw new Error('This payment method is not supported');
|
|
9
|
+
}
|
|
10
|
+
export const PaymentMethodTypes = {
|
|
11
|
+
masrivi: 'masrivi',
|
|
12
|
+
bankily: 'bankily',
|
|
13
|
+
sedad: 'sedad',
|
|
14
|
+
bimBank: 'bim_bank',
|
|
15
|
+
amanty: 'amanty',
|
|
16
|
+
bCIpay: 'bci_pay',
|
|
17
|
+
};
|
|
18
|
+
const METHOD_TO_STR = {
|
|
19
|
+
[PaymentMethodTypes.masrivi]: 'masrivi',
|
|
20
|
+
[PaymentMethodTypes.bankily]: 'bankily',
|
|
21
|
+
[PaymentMethodTypes.sedad]: 'sedad',
|
|
22
|
+
[PaymentMethodTypes.bimBank]: 'bim_bank',
|
|
23
|
+
[PaymentMethodTypes.amanty]: 'amanty',
|
|
24
|
+
[PaymentMethodTypes.bCIpay]: 'bci_pay',
|
|
25
|
+
};
|
|
26
|
+
/** Human-readable titles for payment methods (no i18n in core). */
|
|
27
|
+
export const PaymentMethodTitles = {
|
|
28
|
+
masrivi: 'Masrivi',
|
|
29
|
+
bankily: 'Bankily',
|
|
30
|
+
sedad: 'Sedad',
|
|
31
|
+
bim_bank: 'Bim Bank',
|
|
32
|
+
amanty: 'Amanty',
|
|
33
|
+
bci_pay: 'BCIpay',
|
|
34
|
+
};
|
|
35
|
+
export function paymentMethodTypesFromString(method) {
|
|
36
|
+
const entry = Object.entries(METHOD_TO_STR).find(([, v]) => v === method);
|
|
37
|
+
if (entry)
|
|
38
|
+
return entry[1];
|
|
39
|
+
throw new Error('This payment method is not supported');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Base payment method (id, method type, payment type).
|
|
43
|
+
*/
|
|
44
|
+
export class PaymentMethod {
|
|
45
|
+
id;
|
|
46
|
+
method;
|
|
47
|
+
type;
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.id = options.id;
|
|
50
|
+
this.method = options.method;
|
|
51
|
+
this.type = options.type;
|
|
52
|
+
}
|
|
53
|
+
static fromMap(map) {
|
|
54
|
+
return new PaymentMethod({
|
|
55
|
+
id: String(map.id),
|
|
56
|
+
method: paymentMethodTypesFromString(String(map.type)),
|
|
57
|
+
type: paymentTypeFromString(String(map.configurationType)),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static fromPaymentMethod(map) {
|
|
61
|
+
paymentMethodTypesFromString(String(map.type));
|
|
62
|
+
return BankilyConfigModel.fromMap(map);
|
|
63
|
+
}
|
|
64
|
+
static fromPaymentType(map) {
|
|
65
|
+
const configType = paymentTypeFromString(String(map.configurationType));
|
|
66
|
+
if (configType === PaymentType.auto) {
|
|
67
|
+
return PaymentMethod.fromPaymentMethod(map);
|
|
68
|
+
}
|
|
69
|
+
return ManualConfigModel.fromMap(map);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Bankily payment method config (adds bPayNumber).
|
|
74
|
+
*/
|
|
75
|
+
export class BankilyConfigModel extends PaymentMethod {
|
|
76
|
+
bPayNumber;
|
|
77
|
+
constructor(options) {
|
|
78
|
+
super(options);
|
|
79
|
+
this.bPayNumber = options.bPayNumber;
|
|
80
|
+
}
|
|
81
|
+
static fromMap(map) {
|
|
82
|
+
const base = PaymentMethod.fromMap(map);
|
|
83
|
+
const config = map.config && typeof map.config === 'object' ? map.config : {};
|
|
84
|
+
return new BankilyConfigModel({
|
|
85
|
+
id: base.id,
|
|
86
|
+
method: base.method,
|
|
87
|
+
type: base.type,
|
|
88
|
+
bPayNumber: String(config.code ?? ''),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Manual payment method config (adds merchantCode).
|
|
94
|
+
*/
|
|
95
|
+
export class ManualConfigModel extends PaymentMethod {
|
|
96
|
+
merchantCode;
|
|
97
|
+
constructor(options) {
|
|
98
|
+
super(options);
|
|
99
|
+
this.merchantCode = options.merchantCode;
|
|
100
|
+
}
|
|
101
|
+
static fromMap(map) {
|
|
102
|
+
const base = PaymentMethod.fromMap(map);
|
|
103
|
+
const config = map.config && typeof map.config === 'object' ? map.config : {};
|
|
104
|
+
return new ManualConfigModel({
|
|
105
|
+
id: base.id,
|
|
106
|
+
method: base.method,
|
|
107
|
+
type: base.type,
|
|
108
|
+
merchantCode: String(config.code ?? ''),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=payment-method-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-method-model.js","sourceRoot":"","sources":["../../../src/models/payment-method-model.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,IAAI,IAAI,KAAK,WAAW,CAAC,MAAM,IAAI,IAAI,KAAK,WAAW,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAC1E,MAAM,IAAI,KAAK,CAAC,sCAAsC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id: string;
|
|
6
|
+
readonly phoneNumber: string | null;
|
|
7
|
+
readonly amount: number;
|
|
8
|
+
constructor(options: {
|
|
9
|
+
id: string;
|
|
10
|
+
phoneNumber?: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
});
|
|
13
|
+
static fromMap(map: Record<string, unknown>): PaymentRequestModel;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=payment-request-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-request-model.d.ts","sourceRoot":"","sources":["../../../src/models/payment-request-model.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAMzE,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,mBAAmB;CAQlE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment request details (id, phoneNumber, amount).
|
|
3
|
+
*/
|
|
4
|
+
export class PaymentRequestModel {
|
|
5
|
+
id;
|
|
6
|
+
phoneNumber;
|
|
7
|
+
amount;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.id = options.id;
|
|
10
|
+
this.phoneNumber = options.phoneNumber ?? null;
|
|
11
|
+
this.amount = options.amount;
|
|
12
|
+
}
|
|
13
|
+
static fromMap(map) {
|
|
14
|
+
const amount = map.amount;
|
|
15
|
+
return new PaymentRequestModel({
|
|
16
|
+
id: String(map.id),
|
|
17
|
+
phoneNumber: map.phoneNumber != null ? String(map.phoneNumber) : undefined,
|
|
18
|
+
amount: typeof amount === 'number' ? amount : Number(amount),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=payment-request-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-request-model.js","sourceRoot":"","sources":["../../../src/models/payment-request-model.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,mBAAmB;IACrB,EAAE,CAAS;IACX,WAAW,CAAgB;IAC3B,MAAM,CAAS;IAExB,YAAY,OAA6D;QACvE,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,GAA4B;QACzC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QAC1B,OAAO,IAAI,mBAAmB,CAAC;YAC7B,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;YAC1E,MAAM,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;SAC7D,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PaymentMethod } from "../models/payment-method-model.js";
|
|
2
|
+
/**
|
|
3
|
+
* Fetches available payment methods from the backend.
|
|
4
|
+
*/
|
|
5
|
+
export declare class GetPaymentMethodsService {
|
|
6
|
+
readonly publishableApiKey: string;
|
|
7
|
+
constructor(publishableApiKey: string);
|
|
8
|
+
get(isTestingMode: boolean): Promise<PaymentMethod[]>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=get-payment-methods-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-payment-methods-service.d.ts","sourceRoot":"","sources":["../../../src/services/get-payment-methods-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE;;GAEG;AACH,qBAAa,wBAAwB;aACP,iBAAiB,EAAE,MAAM;gBAAzB,iBAAiB,EAAE,MAAM;IAE/C,GAAG,CAAC,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAU5D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fetcher, Endpoints } from "../helpers/fetcher.js";
|
|
2
|
+
import { PaymentMethod } from "../models/payment-method-model.js";
|
|
3
|
+
/**
|
|
4
|
+
* Fetches available payment methods from the backend.
|
|
5
|
+
*/
|
|
6
|
+
export class GetPaymentMethodsService {
|
|
7
|
+
publishableApiKey;
|
|
8
|
+
constructor(publishableApiKey) {
|
|
9
|
+
this.publishableApiKey = publishableApiKey;
|
|
10
|
+
}
|
|
11
|
+
async get(isTestingMode) {
|
|
12
|
+
const result = await new Fetcher(this.publishableApiKey).get(Endpoints.paymentMethods(isTestingMode));
|
|
13
|
+
const data = result.data;
|
|
14
|
+
const list = Array.isArray(data?.data) ? data.data : [];
|
|
15
|
+
return list.map((e) => PaymentMethod.fromPaymentType(e));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=get-payment-methods-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-payment-methods-service.js","sourceRoot":"","sources":["../../../src/services/get-payment-methods-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACP;IAA5B,YAA4B,iBAAyB;QAAzB,sBAAiB,GAAjB,iBAAiB,CAAQ;IAAG,CAAC;IAEzD,KAAK,CAAC,GAAG,CAAC,aAAsB;QAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAC1D,SAAS,CAAC,cAAc,CAAC,aAAa,CAAC,CACxC,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAwC,CAAC;QAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACpB,aAAa,CAAC,eAAe,CAAC,CAA4B,CAAC,CAC5D,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PaymentRequestModel } from '../models/payment-request-model.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches Payment Request details by transaction ID.
|
|
4
|
+
*/
|
|
5
|
+
export declare class GetPaymentRequestService {
|
|
6
|
+
readonly authorizations: string;
|
|
7
|
+
constructor(authorizations: string);
|
|
8
|
+
get(transactionId: string): Promise<PaymentRequestModel>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=get-payment-request-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-payment-request-service.d.ts","sourceRoot":"","sources":["../../../src/services/get-payment-request-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;GAEG;AACH,qBAAa,wBAAwB;aACP,cAAc,EAAE,MAAM;gBAAtB,cAAc,EAAE,MAAM;IAE5C,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAU/D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fetcher, Endpoints } from '../helpers/fetcher.js';
|
|
2
|
+
import { PaymentRequestModel } from '../models/payment-request-model.js';
|
|
3
|
+
/**
|
|
4
|
+
* Fetches Payment Request details by transaction ID.
|
|
5
|
+
*/
|
|
6
|
+
export class GetPaymentRequestService {
|
|
7
|
+
authorizations;
|
|
8
|
+
constructor(authorizations) {
|
|
9
|
+
this.authorizations = authorizations;
|
|
10
|
+
}
|
|
11
|
+
async get(transactionId) {
|
|
12
|
+
const result = await new Fetcher(this.authorizations).get(Endpoints.paymentRequest(transactionId));
|
|
13
|
+
const data = result.data;
|
|
14
|
+
const payload = data && typeof data === 'object' && 'data' in data ? data.data : data;
|
|
15
|
+
return PaymentRequestModel.fromMap(typeof payload === 'object' && payload !== null ? payload : {});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=get-payment-request-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-payment-request-service.js","sourceRoot":"","sources":["../../../src/services/get-payment-request-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACP;IAA5B,YAA4B,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAG,CAAC;IAEtD,KAAK,CAAC,GAAG,CAAC,aAAqB;QAC7B,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,CACvD,SAAS,CAAC,cAAc,CAAC,aAAa,CAAC,CACxC,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAgF,CAAC;QACrG,MAAM,OAAO,GAAG,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QACtF,OAAO,mBAAmB,CAAC,OAAO,CAChC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,CAAE,OAAmC,CAAC,CAAC,CAAC,EAAE,CAC5F,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FetcherResponse } from '../helpers/fetcher.js';
|
|
2
|
+
export type ManualPayImageInput = File | {
|
|
3
|
+
name: string;
|
|
4
|
+
data: Buffer | Uint8Array | ArrayBuffer;
|
|
5
|
+
type?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Service for processing payments (auto and manual) via the Moosyl API.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PayService {
|
|
11
|
+
readonly publishableApiKey: string;
|
|
12
|
+
constructor(publishableApiKey: string);
|
|
13
|
+
pay(transactionId: string, phoneNumber: string, passCode: string, paymentMethodId: string): Promise<FetcherResponse>;
|
|
14
|
+
manualPay(transactionId: string, paymentMethodId: string, selectedImage: ManualPayImageInput): Promise<FetcherResponse>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=pay-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay-service.d.ts","sourceRoot":"","sources":["../../../src/services/pay-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE5E,MAAM,MAAM,mBAAmB,GAC3B,IAAI,GACJ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E;;GAEG;AACH,qBAAa,UAAU;aACO,iBAAiB,EAAE,MAAM;gBAAzB,iBAAiB,EAAE,MAAM;IAE/C,GAAG,CACP,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,eAAe,CAAC;IAUrB,SAAS,CACb,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,eAAe,CAAC;CAS5B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Fetcher, Endpoints } from '../helpers/fetcher.js';
|
|
2
|
+
/**
|
|
3
|
+
* Service for processing payments (auto and manual) via the Moosyl API.
|
|
4
|
+
*/
|
|
5
|
+
export class PayService {
|
|
6
|
+
publishableApiKey;
|
|
7
|
+
constructor(publishableApiKey) {
|
|
8
|
+
this.publishableApiKey = publishableApiKey;
|
|
9
|
+
}
|
|
10
|
+
async pay(transactionId, phoneNumber, passCode, paymentMethodId) {
|
|
11
|
+
const response = await new Fetcher(this.publishableApiKey).post(Endpoints.pay, {
|
|
12
|
+
transactionId,
|
|
13
|
+
phoneNumber,
|
|
14
|
+
passCode,
|
|
15
|
+
configurationId: paymentMethodId,
|
|
16
|
+
});
|
|
17
|
+
return response;
|
|
18
|
+
}
|
|
19
|
+
async manualPay(transactionId, paymentMethodId, selectedImage) {
|
|
20
|
+
const attachment = await toAttachment(selectedImage);
|
|
21
|
+
const response = await new Fetcher(this.publishableApiKey).post(Endpoints.manualPayment, {
|
|
22
|
+
transactionId,
|
|
23
|
+
configurationId: paymentMethodId,
|
|
24
|
+
attachments: [attachment],
|
|
25
|
+
});
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function toAttachment(input) {
|
|
30
|
+
if (input instanceof File) {
|
|
31
|
+
const buffer = await input.arrayBuffer();
|
|
32
|
+
const base64 = bufferToBase64(buffer);
|
|
33
|
+
return {
|
|
34
|
+
name: input.name,
|
|
35
|
+
type: input.type || 'application/octet-stream',
|
|
36
|
+
size: input.size,
|
|
37
|
+
data: base64,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const { name, data, type = 'application/octet-stream' } = input;
|
|
41
|
+
const buf = data instanceof Buffer ? data : new Uint8Array(data);
|
|
42
|
+
const size = buf.byteLength ?? buf.length;
|
|
43
|
+
return {
|
|
44
|
+
name,
|
|
45
|
+
type,
|
|
46
|
+
size,
|
|
47
|
+
data: bufferToBase64(buf),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function bufferToBase64(buf) {
|
|
51
|
+
if (typeof Buffer !== 'undefined') {
|
|
52
|
+
return (Buffer.isBuffer(buf) ? buf : Buffer.from(buf)).toString('base64');
|
|
53
|
+
}
|
|
54
|
+
const bytes = buf instanceof Uint8Array ? buf : new Uint8Array(buf);
|
|
55
|
+
let binary = '';
|
|
56
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
57
|
+
binary += String.fromCharCode(bytes[i]);
|
|
58
|
+
}
|
|
59
|
+
return btoa(binary);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=pay-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay-service.js","sourceRoot":"","sources":["../../../src/services/pay-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAmB,MAAM,uBAAuB,CAAC;AAM5E;;GAEG;AACH,MAAM,OAAO,UAAU;IACO;IAA5B,YAA4B,iBAAyB;QAAzB,sBAAiB,GAAjB,iBAAiB,CAAQ;IAAG,CAAC;IAEzD,KAAK,CAAC,GAAG,CACP,aAAqB,EACrB,WAAmB,EACnB,QAAgB,EAChB,eAAuB;QAEvB,MAAM,QAAQ,GAAG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE;YAC7E,aAAa;YACb,WAAW;YACX,QAAQ;YACR,eAAe,EAAE,e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5D,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAkB,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3F,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,YAAY,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IACpE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "moosyl",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "integrating payment solutions with Mauritania's popular banking apps",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"test": "echo \"No tests configured\""
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.0.0",
|
|
21
|
+
"typescript": "^5.6.0"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/SoftwareSavants/moosyl_js.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"moosyl",
|
|
29
|
+
"payments"
|
|
30
|
+
],
|
|
31
|
+
"author": "software-savants",
|
|
32
|
+
"license": "ISC",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/SoftwareSavants/moosyl_js/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/SoftwareSavants/moosyl_js#readme",
|
|
37
|
+
"files": ["dist", "README.md"]
|
|
38
|
+
}
|