moosyl 0.0.2 → 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
@@ -26,31 +26,31 @@ Install the package:
26
26
  npm install moosyl
27
27
  ```
28
28
 
29
- ### Import the package
29
+ ### Create a Moosyl instance
30
+
31
+ Create a single client with your publishable API key. All operations use this instance:
30
32
 
31
33
  ```javascript
32
- import {
33
- GetPaymentMethodsService,
34
- GetPaymentRequestService,
35
- PayService,
36
- PaymentRequestModel,
37
- PaymentMethodTitles,
38
- } from "moosyl";
34
+ import { Moosyl, PaymentMethodTitles } from "moosyl";
35
+
36
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
39
37
  ```
40
38
 
41
39
  ---
42
40
 
43
41
  ## Usage
44
42
 
43
+ All functionality is available on the **Moosyl** instance: `moosyl.getPaymentMethods()`, `moosyl.getPaymentRequest()`, `moosyl.pay()`, and `moosyl.manualPay()`.
44
+
45
45
  ### Fetch payment methods
46
46
 
47
47
  Get the list of payment methods (e.g. to show options to the user):
48
48
 
49
49
  ```javascript
50
- import { GetPaymentMethodsService } from "moosyl";
50
+ import { Moosyl, PaymentMethodTitles } from "moosyl";
51
51
 
52
- const service = new GetPaymentMethodsService("YOUR_PUBLISHABLE_API_KEY");
53
- 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
54
54
 
55
55
  methods.forEach((m) => {
56
56
  const title = PaymentMethodTitles[m.method] ?? m.method;
@@ -64,10 +64,10 @@ methods.forEach((m) => {
64
64
  Get details for a given transaction (after creating a payment request from your backend):
65
65
 
66
66
  ```javascript
67
- import { GetPaymentRequestService } from "moosyl";
67
+ import { Moosyl } from "moosyl";
68
68
 
69
- const service = new GetPaymentRequestService("YOUR_PUBLISHABLE_API_KEY");
70
- const request = await service.get("TRANSACTION_ID");
69
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
70
+ const request = await moosyl.getPaymentRequest("TRANSACTION_ID");
71
71
 
72
72
  console.log(request.id, request.amount, request.phoneNumber);
73
73
  ```
@@ -87,39 +87,43 @@ curl -X POST https://api.moosyl.com/payment-request \
87
87
  }'
88
88
  ```
89
89
 
90
- 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.
91
91
 
92
92
  ### Process payment (auto)
93
93
 
94
- For automatic payment methods (e.g. Bankily), send the transaction ID, customer phone number, passcode, and the selected payment method (configuration) ID:
94
+ For automatic payment methods (e.g. Bankily):
95
95
 
96
96
  ```javascript
97
- import { PayService } from "moosyl";
97
+ import { Moosyl } from "moosyl";
98
98
 
99
- const pay = new PayService("YOUR_PUBLISHABLE_API_KEY");
99
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
100
100
 
101
- await pay.pay(
101
+ await moosyl.pay(
102
102
  "TRANSACTION_ID",
103
103
  "+22212345678",
104
104
  "PASSCODE",
105
- "PAYMENT_METHOD_ID" // configuration ID from GetPaymentMethodsService
105
+ "PAYMENT_METHOD_ID" // configuration ID from getPaymentMethods()
106
106
  );
107
107
  ```
108
108
 
109
109
  ### Process manual payment
110
110
 
111
- For manual payment methods, send the transaction ID, payment method ID, and a screenshot of the payment (File in the browser, or `{ name, data, type? }` in Node):
111
+ For manual payment methods, send a screenshot (File in the browser, or `{ name, data, type? }` in Node):
112
112
 
113
113
  ```javascript
114
- import { PayService } from "moosyl";
114
+ import { Moosyl } from "moosyl";
115
115
 
116
- const pay = new PayService("YOUR_PUBLISHABLE_API_KEY");
116
+ const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
117
117
 
118
118
  // Browser: pass a File from an input
119
- await pay.manualPay("TRANSACTION_ID", "PAYMENT_METHOD_ID", fileInput.files[0]);
119
+ await moosyl.manualPay(
120
+ "TRANSACTION_ID",
121
+ "PAYMENT_METHOD_ID",
122
+ fileInput.files[0]
123
+ );
120
124
 
121
125
  // Node: pass { name, data (Buffer), type? }
122
- await pay.manualPay("TRANSACTION_ID", "PAYMENT_METHOD_ID", {
126
+ await moosyl.manualPay("TRANSACTION_ID", "PAYMENT_METHOD_ID", {
123
127
  name: "proof.png",
124
128
  data: imageBuffer,
125
129
  type: "image/png",
@@ -128,26 +132,10 @@ await pay.manualPay("TRANSACTION_ID", "PAYMENT_METHOD_ID", {
128
132
 
129
133
  ---
130
134
 
131
- ## API overview
132
-
133
- | Export | Description |
134
- | ---------------------------------------------------------- | ------------------------------------------------------ |
135
- | `GetPaymentMethodsService` | Fetches available payment methods. |
136
- | `GetPaymentRequestService` | Fetches payment request by transaction ID. |
137
- | `PayService` | Processes payments: `pay()` (auto) and `manualPay()` (with screenshot). |
138
- | `PaymentRequestModel` | Model for payment request (id, amount, phoneNumber). |
139
- | `PaymentMethod`, `BankilyConfigModel`, `ManualConfigModel` | Payment method models. |
140
- | `PaymentMethodTitles` | Display names for payment method types. |
141
- | `PaymentType`, `PaymentMethodTypes` | Enums/constants for method and type. |
142
- | `Fetcher`, `Endpoints` | Low-level HTTP client and API URLs (for advanced use). |
143
- | `AppException` | Error type thrown on failed API calls. |
144
-
145
- ---
146
-
147
135
  ## Configuration
148
136
 
149
- - **API key**: Use your **publishable** API key for `GetPaymentMethodsService`, `GetPaymentRequestService`, and `PayService`. Get keys at [moosyl.com](https://moosyl.com).
150
- - **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.
151
139
 
152
140
  ---
153
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.2",
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
  }