moosyl 0.0.1 → 0.0.3

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/moosyl.svg)](https://www.npmjs.com/package/moosyl)
4
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.
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, payment request details, and process payments (auto or manual) via the Moosyl API.
6
6
 
7
7
  ---
8
8
 
@@ -10,6 +10,7 @@ The **Moosyl JavaScript SDK** helps you integrate payment solutions with Maurita
10
10
 
11
11
  - **Payment methods**: Fetch available payment methods (including testing mode).
12
12
  - **Payment request**: Get payment request details by transaction ID.
13
+ - **Pay**: Process automatic payments (e.g. Bankily) or manual payments with a screenshot.
13
14
  - **Lightweight**: No UI; use your own front end or backend flows.
14
15
  - **ESM**: Native ES modules (`import`).
15
16
 
@@ -25,30 +26,31 @@ Install the package:
25
26
  npm install moosyl
26
27
  ```
27
28
 
28
- ### Import the package
29
+ ### Create a Moosyl instance
30
+
31
+ Create a single client with your publishable API key. All operations use this instance:
29
32
 
30
33
  ```javascript
31
- import {
32
- GetPaymentMethodsService,
33
- GetPaymentRequestService,
34
- PaymentRequestModel,
35
- PaymentMethodTitles,
36
- } from "moosyl";
34
+ import { Moosyl, PaymentMethodTitles } from "moosyl";
35
+
36
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
37
37
  ```
38
38
 
39
39
  ---
40
40
 
41
41
  ## Usage
42
42
 
43
+ All functionality is available on the **Moosyl** instance: `moosyl.getPaymentMethods()`, `moosyl.getPaymentRequest()`, `moosyl.pay()`, and `moosyl.manualPay()`.
44
+
43
45
  ### Fetch payment methods
44
46
 
45
47
  Get the list of payment methods (e.g. to show options to the user):
46
48
 
47
49
  ```javascript
48
- import { GetPaymentMethodsService } from "moosyl";
50
+ import { Moosyl, PaymentMethodTitles } from "moosyl";
49
51
 
50
- const service = new GetPaymentMethodsService("YOUR_PUBLISHABLE_API_KEY");
51
- const methods = await service.get(true); // true = testing mode
52
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
53
+ const methods = await moosyl.getPaymentMethods(true); // true = testing mode
52
54
 
53
55
  methods.forEach((m) => {
54
56
  const title = PaymentMethodTitles[m.method] ?? m.method;
@@ -62,10 +64,10 @@ methods.forEach((m) => {
62
64
  Get details for a given transaction (after creating a payment request from your backend):
63
65
 
64
66
  ```javascript
65
- import { GetPaymentRequestService } from "moosyl";
67
+ import { Moosyl } from "moosyl";
66
68
 
67
- const service = new GetPaymentRequestService("YOUR_PUBLISHABLE_API_KEY");
68
- const request = await service.get("TRANSACTION_ID");
69
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
70
+ const request = await moosyl.getPaymentRequest("TRANSACTION_ID");
69
71
 
70
72
  console.log(request.id, request.amount, request.phoneNumber);
71
73
  ```
@@ -85,29 +87,55 @@ curl -X POST https://api.moosyl.com/payment-request \
85
87
  }'
86
88
  ```
87
89
 
88
- Once created, use the returned **transactionId** with `GetPaymentRequestService` and your payment flow.
90
+ Once created, use the returned **transactionId** with `moosyl.getPaymentRequest()` and your payment flow.
89
91
 
90
- ---
92
+ ### Process payment (auto)
93
+
94
+ For automatic payment methods (e.g. Bankily):
95
+
96
+ ```javascript
97
+ import { Moosyl } from "moosyl";
91
98
 
92
- ## API overview
99
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
93
100
 
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. |
101
+ await moosyl.pay(
102
+ "TRANSACTION_ID",
103
+ "+22212345678",
104
+ "PASSCODE",
105
+ "PAYMENT_METHOD_ID" // configuration ID from getPaymentMethods()
106
+ );
107
+ ```
108
+
109
+ ### Process manual payment
110
+
111
+ For manual payment methods, send a screenshot (File in the browser, or `{ name, data, type? }` in Node):
112
+
113
+ ```javascript
114
+ import { Moosyl } from "moosyl";
115
+
116
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
117
+
118
+ // Browser: pass a File from an input
119
+ await moosyl.manualPay(
120
+ "TRANSACTION_ID",
121
+ "PAYMENT_METHOD_ID",
122
+ fileInput.files[0]
123
+ );
124
+
125
+ // Node: pass { name, data (Buffer), type? }
126
+ await moosyl.manualPay("TRANSACTION_ID", "PAYMENT_METHOD_ID", {
127
+ name: "proof.png",
128
+ data: imageBuffer,
129
+ type: "image/png",
130
+ });
131
+ ```
104
132
 
105
133
  ---
106
134
 
107
135
  ## Configuration
108
136
 
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.
137
+ - **API key**: Use your **publishable** API key when creating `new Moosyl(apiKey)`. Get keys at [moosyl.com](https://moosyl.com).
138
+ - **Testing mode**: Pass `true` to `moosyl.getPaymentMethods(true)` for test configuration.
111
139
 
112
140
  ---
113
141
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Moosyl JS – integrating payment solutions with Mauritania's popular banking apps.
3
3
  */
4
+ export { Moosyl } from './src/moosyl.js';
4
5
  export { Fetcher, FetcherResponse, Endpoints } from './src/helpers/fetcher.js';
5
6
  export { AppException, AppExceptionCode } from './src/helpers/exceptions.js';
6
7
  export { PaymentType, PaymentMethodTypes, PaymentMethodTitles, paymentTypeFromString, paymentMethodTypesFromString, PaymentMethod, BankilyConfigModel, ManualConfigModel, } from './src/models/payment-method-model.js';
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,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 CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Moosyl JS – integrating payment solutions with Mauritania's popular banking apps.
3
3
  */
4
+ export { Moosyl } from './src/moosyl.js';
4
5
  export { Fetcher, FetcherResponse, Endpoints } from './src/helpers/fetcher.js';
5
6
  export { AppException, AppExceptionCode } from './src/helpers/exceptions.js';
6
7
  export { PaymentType, PaymentMethodTypes, PaymentMethodTitles, paymentTypeFromString, paymentMethodTypesFromString, PaymentMethod, BankilyConfigModel, ManualConfigModel, } from './src/models/payment-method-model.js';
package/dist/index.js.map CHANGED
@@ -1 +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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,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,47 @@
1
+ import type { PaymentMethod } from './models/payment-method-model.js';
2
+ import type { PaymentRequestModel } from './models/payment-request-model.js';
3
+ import type { FetcherResponse } from './helpers/fetcher.js';
4
+ import type { ManualPayImageInput } from './services/pay-service.js';
5
+ /**
6
+ * Main Moosyl SDK client. Create an instance with your publishable API key,
7
+ * then use the methods to fetch payment methods, payment requests, and process payments.
8
+ */
9
+ export declare class Moosyl {
10
+ private readonly getPaymentMethodsService;
11
+ private readonly getPaymentRequestService;
12
+ private readonly payService;
13
+ /**
14
+ * @param apiKey - Your Moosyl publishable API key
15
+ */
16
+ constructor(apiKey: string);
17
+ /**
18
+ * Fetches available payment methods (e.g. Bankily, Sedad, Masrivi).
19
+ * @param isTestingMode - Pass `true` for test configuration
20
+ * @returns List of payment methods
21
+ */
22
+ getPaymentMethods(isTestingMode: boolean): Promise<PaymentMethod[]>;
23
+ /**
24
+ * Fetches payment request details for a transaction.
25
+ * @param transactionId - The transaction ID from your backend
26
+ * @returns Payment request (id, amount, phoneNumber)
27
+ */
28
+ getPaymentRequest(transactionId: string): Promise<PaymentRequestModel>;
29
+ /**
30
+ * Processes an automatic payment (e.g. Bankily).
31
+ * @param transactionId - Transaction ID
32
+ * @param phoneNumber - Customer phone number
33
+ * @param passCode - Customer passcode
34
+ * @param paymentMethodId - Configuration ID from getPaymentMethods()
35
+ * @returns API response
36
+ */
37
+ pay(transactionId: string, phoneNumber: string, passCode: string, paymentMethodId: string): Promise<FetcherResponse>;
38
+ /**
39
+ * Processes a manual payment with a screenshot.
40
+ * @param transactionId - Transaction ID
41
+ * @param paymentMethodId - Configuration ID from getPaymentMethods()
42
+ * @param selectedImage - File (browser) or { name, data, type? } (Node)
43
+ * @returns API response
44
+ */
45
+ manualPay(transactionId: string, paymentMethodId: string, selectedImage: ManualPayImageInput): Promise<FetcherResponse>;
46
+ }
47
+ //# sourceMappingURL=moosyl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moosyl.d.ts","sourceRoot":"","sources":["../../src/moosyl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE;;;GAGG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA2B;IACpE,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA2B;IACpE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;OAEG;gBACS,MAAM,EAAE,MAAM;IAM1B;;;;OAIG;IACH,iBAAiB,CAAC,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAInE;;;;OAIG;IACH,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAItE;;;;;;;OAOG;IACH,GAAG,CACD,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,eAAe,CAAC;IAI3B;;;;;;OAMG;IACH,SAAS,CACP,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,eAAe,CAAC;CAG5B"}
@@ -0,0 +1,58 @@
1
+ import { GetPaymentMethodsService } from './services/get-payment-methods-service.js';
2
+ import { GetPaymentRequestService } from './services/get-payment-request-service.js';
3
+ import { PayService } from './services/pay-service.js';
4
+ /**
5
+ * Main Moosyl SDK client. Create an instance with your publishable API key,
6
+ * then use the methods to fetch payment methods, payment requests, and process payments.
7
+ */
8
+ export class Moosyl {
9
+ getPaymentMethodsService;
10
+ getPaymentRequestService;
11
+ payService;
12
+ /**
13
+ * @param apiKey - Your Moosyl publishable API key
14
+ */
15
+ constructor(apiKey) {
16
+ this.getPaymentMethodsService = new GetPaymentMethodsService(apiKey);
17
+ this.getPaymentRequestService = new GetPaymentRequestService(apiKey);
18
+ this.payService = new PayService(apiKey);
19
+ }
20
+ /**
21
+ * Fetches available payment methods (e.g. Bankily, Sedad, Masrivi).
22
+ * @param isTestingMode - Pass `true` for test configuration
23
+ * @returns List of payment methods
24
+ */
25
+ getPaymentMethods(isTestingMode) {
26
+ return this.getPaymentMethodsService.get(isTestingMode);
27
+ }
28
+ /**
29
+ * Fetches payment request details for a transaction.
30
+ * @param transactionId - The transaction ID from your backend
31
+ * @returns Payment request (id, amount, phoneNumber)
32
+ */
33
+ getPaymentRequest(transactionId) {
34
+ return this.getPaymentRequestService.get(transactionId);
35
+ }
36
+ /**
37
+ * Processes an automatic payment (e.g. Bankily).
38
+ * @param transactionId - Transaction ID
39
+ * @param phoneNumber - Customer phone number
40
+ * @param passCode - Customer passcode
41
+ * @param paymentMethodId - Configuration ID from getPaymentMethods()
42
+ * @returns API response
43
+ */
44
+ pay(transactionId, phoneNumber, passCode, paymentMethodId) {
45
+ return this.payService.pay(transactionId, phoneNumber, passCode, paymentMethodId);
46
+ }
47
+ /**
48
+ * Processes a manual payment with a screenshot.
49
+ * @param transactionId - Transaction ID
50
+ * @param paymentMethodId - Configuration ID from getPaymentMethods()
51
+ * @param selectedImage - File (browser) or { name, data, type? } (Node)
52
+ * @returns API response
53
+ */
54
+ manualPay(transactionId, paymentMethodId, selectedImage) {
55
+ return this.payService.manualPay(transactionId, paymentMethodId, selectedImage);
56
+ }
57
+ }
58
+ //# sourceMappingURL=moosyl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moosyl.js","sourceRoot":"","sources":["../../src/moosyl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAMvD;;;GAGG;AACH,MAAM,OAAO,MAAM;IACA,wBAAwB,CAA2B;IACnD,wBAAwB,CAA2B;IACnD,UAAU,CAAa;IAExC;;OAEG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,wBAAwB,GAAG,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;QACrE,IAAI,CAAC,wBAAwB,GAAG,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;QACrE,IAAI,CAAC,UAAU,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,aAAsB;QACtC,OAAO,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,aAAqB;QACrC,OAAO,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;OAOG;IACH,GAAG,CACD,aAAqB,EACrB,WAAmB,EACnB,QAAgB,EAChB,eAAuB;QAEvB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CACP,aAAqB,EACrB,eAAuB,EACvB,aAAkC;QAElC,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,aAAa,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC;IAClF,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moosyl",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "integrating payment solutions with Mauritania's popular banking apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -34,5 +34,8 @@
34
34
  "url": "https://github.com/SoftwareSavants/moosyl_js/issues"
35
35
  },
36
36
  "homepage": "https://github.com/SoftwareSavants/moosyl_js#readme",
37
- "files": ["dist", "README.md"]
37
+ "files": [
38
+ "dist",
39
+ "README.md"
40
+ ]
38
41
  }