@ariary/pay 1.0.2 → 1.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
@@ -8,6 +8,12 @@ Payment and product SDK for the Ariary API.
8
8
  yarn add @ariary/pay
9
9
  ```
10
10
 
11
+ ## Get your credentials
12
+
13
+ 1. Sign in at [ariari.mg](https://ariari.mg)
14
+ 2. Create a project
15
+ 3. You'll receive a `projectId` and a `secret`
16
+
11
17
  ## Setup
12
18
 
13
19
  ```ts
@@ -30,29 +36,47 @@ const product = await Ariari.products.create({ name: 'Forfait Premium', price: 5
30
36
  // list all
31
37
  const products = await Ariari.products.list()
32
38
 
39
+ // update
40
+ const updated = await Ariari.products.update(product.id, { name: 'Forfait Gold', price: 8000 })
41
+
33
42
  // delete
34
43
  await Ariari.products.delete(product.id)
35
44
  ```
36
45
 
37
46
  ## Create a Payment
38
47
 
39
- `Ariari.create()` returns a `Payment` object with the generated payment URL.
48
+ `Ariari.create()` returns a `Payment` object with `id` and `url`.
49
+
50
+ | Field | Type | Required | Description |
51
+ |---|---|---|---|
52
+ | `productId` | string | No | Product ID — resolves `amount`, `name`, `imgUrl` automatically |
53
+ | `amount` | number | Yes (without `productId`) | Payment amount in Ariary |
54
+ | `name` | string | No | Payment label |
55
+ | `imgUrl` | string | No | Image URL for the payment page |
56
+ | `hooks.success` | string | No | Webhook called when payment is fully completed |
57
+ | `hooks.progress` | string | No | Webhook called on each partial payment |
58
+ | `hooks.failure` | string | No | Webhook called on payment failure |
40
59
 
41
60
  ```ts
42
- // with amount
61
+ // with amount only
43
62
  const payment = await Ariari.create({ amount: 5000 })
63
+ console.log(payment.url) // https://pay.ariari.mg/abc123encrypted
44
64
 
45
- // with product
65
+ // with product (amount, name, imgUrl resolved automatically)
46
66
  const payment = await Ariari.create({ productId: product.id })
47
67
 
48
- // with hooks and metadata
68
+ // with product + override
69
+ const payment = await Ariari.create({ productId: product.id, amount: 3000 })
70
+
71
+ // with hooks
49
72
  const payment = await Ariari.create({
50
73
  amount: 10000,
51
74
  name: 'T-shirt bleu',
52
75
  imgUrl: 'https://example.com/img.png',
53
76
  hooks: {
54
- success: 'https://example.com/success',
55
- failure: 'https://example.com/failure',
77
+ success: 'https://yoursite.com/api/webhook/payment-success',
78
+ progress: 'https://yoursite.com/api/webhook/payment-progress',
79
+ failure: 'https://yoursite.com/api/webhook/payment-failure',
56
80
  },
57
81
  })
58
82
  ```
@@ -70,7 +94,7 @@ const info = await payment.status()
70
94
  const result = await payment.pay('Y-1234')
71
95
  ```
72
96
 
73
- Payment statuses: `pending` | `incomplete` | `paid` | `failed`
97
+ Payment statuses: `Status.PENDING` | `Status.INCOMPLETE` | `Status.PAID` | `Status.FAILED`
74
98
 
75
99
  A `Status` enum is also exported:
76
100
 
@@ -82,7 +106,21 @@ if (info.status === Status.PAID) { ... }
82
106
 
83
107
  ## Retrieve an existing Payment
84
108
 
85
- Store `payment.id` to retrieve it later with `.getPayment()`.
109
+ Store `payment.id` to retrieve it later with `.getPayment()`. Calling `.status()` returns the full payment details:
110
+
111
+ | Field | Type | Description |
112
+ |---|---|---|
113
+ | `id` | string | Payment ID |
114
+ | `amount` | number | Total amount in Ariary |
115
+ | `rest` | number | Remaining amount to pay |
116
+ | `productId` | string? | Linked product ID |
117
+ | `name` | string? | Payment label |
118
+ | `imgUrl` | string? | Image URL |
119
+ | `status` | Status | `PENDING` \| `INCOMPLETE` \| `PAID` \| `FAILED` |
120
+ | `parts` | PaymentPart[] | List of partial payments |
121
+ | `createdAt` | string | Creation date |
122
+ | `updatedAt` | string | Last update date |
123
+ | `url` | string | Payment page URL |
86
124
 
87
125
  ```ts
88
126
  const payment = await Ariari.create({ amount: 5000 })
package/dist/index.d.mts CHANGED
@@ -59,6 +59,11 @@ type CreateProductData = {
59
59
  price: number;
60
60
  imgUrl?: string;
61
61
  };
62
+ type UpdateProductData = {
63
+ name?: string;
64
+ price?: number;
65
+ imgUrl?: string;
66
+ };
62
67
  type Product = {
63
68
  id: string;
64
69
  name: string;
@@ -70,13 +75,13 @@ type Product = {
70
75
 
71
76
  declare class Payment {
72
77
  id: string;
78
+ url?: string;
73
79
  private _requester;
74
- constructor(id: string, requester: ReturnType<typeof createRequester>);
80
+ constructor(idOrData: string | PaymentResponse, requester: ReturnType<typeof createRequester>);
75
81
  status(): Promise<PaymentResponse>;
76
82
  pay(ticketCode: string): Promise<PaymentResponse>;
77
83
  }
78
84
  declare class Ariari {
79
- private _config;
80
85
  private _requester;
81
86
  private constructor();
82
87
  static config: (nameAndConfig: Config & {
@@ -91,6 +96,7 @@ declare class Ariari {
91
96
  products: {
92
97
  create: (data: CreateProductData) => Promise<Product>;
93
98
  list: () => Promise<Product[]>;
99
+ update: (id: string, data: UpdateProductData) => Promise<Product>;
94
100
  delete: (id: string) => Promise<void>;
95
101
  };
96
102
  static create: (data: CreatePaymentData) => Promise<Payment>;
@@ -98,6 +104,7 @@ declare class Ariari {
98
104
  static products: {
99
105
  create: (data: CreateProductData) => Promise<Product>;
100
106
  list: () => Promise<Product[]>;
107
+ update: (id: string, data: UpdateProductData) => Promise<Product>;
101
108
  delete: (id: string) => Promise<void>;
102
109
  };
103
110
  }
package/dist/index.d.ts CHANGED
@@ -59,6 +59,11 @@ type CreateProductData = {
59
59
  price: number;
60
60
  imgUrl?: string;
61
61
  };
62
+ type UpdateProductData = {
63
+ name?: string;
64
+ price?: number;
65
+ imgUrl?: string;
66
+ };
62
67
  type Product = {
63
68
  id: string;
64
69
  name: string;
@@ -70,13 +75,13 @@ type Product = {
70
75
 
71
76
  declare class Payment {
72
77
  id: string;
78
+ url?: string;
73
79
  private _requester;
74
- constructor(id: string, requester: ReturnType<typeof createRequester>);
80
+ constructor(idOrData: string | PaymentResponse, requester: ReturnType<typeof createRequester>);
75
81
  status(): Promise<PaymentResponse>;
76
82
  pay(ticketCode: string): Promise<PaymentResponse>;
77
83
  }
78
84
  declare class Ariari {
79
- private _config;
80
85
  private _requester;
81
86
  private constructor();
82
87
  static config: (nameAndConfig: Config & {
@@ -91,6 +96,7 @@ declare class Ariari {
91
96
  products: {
92
97
  create: (data: CreateProductData) => Promise<Product>;
93
98
  list: () => Promise<Product[]>;
99
+ update: (id: string, data: UpdateProductData) => Promise<Product>;
94
100
  delete: (id: string) => Promise<void>;
95
101
  };
96
102
  static create: (data: CreatePaymentData) => Promise<Payment>;
@@ -98,6 +104,7 @@ declare class Ariari {
98
104
  static products: {
99
105
  create: (data: CreateProductData) => Promise<Product>;
100
106
  list: () => Promise<Product[]>;
107
+ update: (id: string, data: UpdateProductData) => Promise<Product>;
101
108
  delete: (id: string) => Promise<void>;
102
109
  };
103
110
  }
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(src_exports);
28
28
  // ../common/http.ts
29
29
  async function request(verb, endpoint, options, config) {
30
30
  if (!config) throw new Error("Ariari package not configured.");
31
- const url = `${config.baseUrl || "https://back.ariari.mg"}${endpoint}`;
31
+ const url = `${config.baseUrl || "https://api.ariari.mg"}${endpoint}`;
32
32
  const headers = { "Content-Type": "application/json" };
33
33
  if (!options.public) {
34
34
  headers["x-project-id"] = config.projectId;
@@ -73,8 +73,13 @@ var Status = /* @__PURE__ */ ((Status2) => {
73
73
  // src/index.ts
74
74
  var instances = {};
75
75
  var Payment = class {
76
- constructor(id, requester) {
77
- this.id = id;
76
+ constructor(idOrData, requester) {
77
+ if (typeof idOrData === "string") {
78
+ this.id = idOrData;
79
+ } else {
80
+ this.id = idOrData.id;
81
+ this.url = idOrData.url;
82
+ }
78
83
  this._requester = requester;
79
84
  }
80
85
  async status() {
@@ -89,7 +94,7 @@ var _Ariari = class _Ariari {
89
94
  constructor({ name = "main", ...config }) {
90
95
  this.create = async (data) => {
91
96
  const res = await this._requester.post("/api/payments", { body: data });
92
- return new Payment(res.id, this._requester);
97
+ return new Payment(res, this._requester);
93
98
  };
94
99
  this.getPayment = (id) => new Payment(id, this._requester);
95
100
  this.products = {
@@ -99,11 +104,13 @@ var _Ariari = class _Ariari {
99
104
  list: async () => {
100
105
  return this._requester.get("/api/products");
101
106
  },
107
+ update: async (id, data) => {
108
+ return this._requester.put(`/api/products/${id}`, { body: data });
109
+ },
102
110
  delete: async (id) => {
103
111
  await this._requester.delete(`/api/products/${id}`);
104
112
  }
105
113
  };
106
- this._config = config;
107
114
  this._requester = createRequester(config);
108
115
  instances[name] = this;
109
116
  }
@@ -119,6 +126,7 @@ _Ariari.getPayment = (id) => _Ariari.get("main")?.getPayment(id);
119
126
  _Ariari.products = {
120
127
  create: async (data) => await _Ariari.get("main")?.products.create(data),
121
128
  list: async () => await _Ariari.get("main")?.products.list(),
129
+ update: async (id, data) => await _Ariari.get("main")?.products.update(id, data),
122
130
  delete: async (id) => await _Ariari.get("main")?.products.delete(id)
123
131
  };
124
132
  var Ariari = _Ariari;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // ../common/http.ts
2
2
  async function request(verb, endpoint, options, config) {
3
3
  if (!config) throw new Error("Ariari package not configured.");
4
- const url = `${config.baseUrl || "https://back.ariari.mg"}${endpoint}`;
4
+ const url = `${config.baseUrl || "https://api.ariari.mg"}${endpoint}`;
5
5
  const headers = { "Content-Type": "application/json" };
6
6
  if (!options.public) {
7
7
  headers["x-project-id"] = config.projectId;
@@ -46,8 +46,13 @@ var Status = /* @__PURE__ */ ((Status2) => {
46
46
  // src/index.ts
47
47
  var instances = {};
48
48
  var Payment = class {
49
- constructor(id, requester) {
50
- this.id = id;
49
+ constructor(idOrData, requester) {
50
+ if (typeof idOrData === "string") {
51
+ this.id = idOrData;
52
+ } else {
53
+ this.id = idOrData.id;
54
+ this.url = idOrData.url;
55
+ }
51
56
  this._requester = requester;
52
57
  }
53
58
  async status() {
@@ -62,7 +67,7 @@ var _Ariari = class _Ariari {
62
67
  constructor({ name = "main", ...config }) {
63
68
  this.create = async (data) => {
64
69
  const res = await this._requester.post("/api/payments", { body: data });
65
- return new Payment(res.id, this._requester);
70
+ return new Payment(res, this._requester);
66
71
  };
67
72
  this.getPayment = (id) => new Payment(id, this._requester);
68
73
  this.products = {
@@ -72,11 +77,13 @@ var _Ariari = class _Ariari {
72
77
  list: async () => {
73
78
  return this._requester.get("/api/products");
74
79
  },
80
+ update: async (id, data) => {
81
+ return this._requester.put(`/api/products/${id}`, { body: data });
82
+ },
75
83
  delete: async (id) => {
76
84
  await this._requester.delete(`/api/products/${id}`);
77
85
  }
78
86
  };
79
- this._config = config;
80
87
  this._requester = createRequester(config);
81
88
  instances[name] = this;
82
89
  }
@@ -92,6 +99,7 @@ _Ariari.getPayment = (id) => _Ariari.get("main")?.getPayment(id);
92
99
  _Ariari.products = {
93
100
  create: async (data) => await _Ariari.get("main")?.products.create(data),
94
101
  list: async () => await _Ariari.get("main")?.products.list(),
102
+ update: async (id, data) => await _Ariari.get("main")?.products.update(id, data),
95
103
  delete: async (id) => await _Ariari.get("main")?.products.delete(id)
96
104
  };
97
105
  var Ariari = _Ariari;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariary/pay",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Payment SDK pour l'API Ariary",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",