@ariary/pay 1.0.1 → 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 +46 -8
- package/dist/index.d.mts +16 -9
- package/dist/index.d.ts +16 -9
- package/dist/index.js +16 -11
- package/dist/index.mjs +16 -11
- package/package.json +1 -1
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
|
|
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
|
|
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://
|
|
55
|
-
|
|
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: `
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type Data = {
|
|
2
|
-
body?: Record<string,
|
|
3
|
-
params?: Record<string,
|
|
2
|
+
body?: Record<string, unknown>;
|
|
3
|
+
params?: Record<string, string>;
|
|
4
4
|
public?: boolean;
|
|
5
5
|
};
|
|
6
6
|
type PData = Omit<Data, 'body'>;
|
|
@@ -10,11 +10,11 @@ type Config = {
|
|
|
10
10
|
baseUrl?: string;
|
|
11
11
|
};
|
|
12
12
|
declare const createRequester: (config: Config) => {
|
|
13
|
-
get: <T
|
|
14
|
-
post: <T
|
|
15
|
-
patch: <T
|
|
16
|
-
put: <T
|
|
17
|
-
delete: <T =
|
|
13
|
+
get: <T>(url: string, data?: PData) => Promise<T>;
|
|
14
|
+
post: <T>(url: string, data?: Data) => Promise<T>;
|
|
15
|
+
patch: <T>(url: string, data?: Data) => Promise<T>;
|
|
16
|
+
put: <T>(url: string, data?: Data) => Promise<T>;
|
|
17
|
+
delete: <T = void>(url: string, data?: PData) => Promise<T>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
declare enum Status {
|
|
@@ -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(
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type Data = {
|
|
2
|
-
body?: Record<string,
|
|
3
|
-
params?: Record<string,
|
|
2
|
+
body?: Record<string, unknown>;
|
|
3
|
+
params?: Record<string, string>;
|
|
4
4
|
public?: boolean;
|
|
5
5
|
};
|
|
6
6
|
type PData = Omit<Data, 'body'>;
|
|
@@ -10,11 +10,11 @@ type Config = {
|
|
|
10
10
|
baseUrl?: string;
|
|
11
11
|
};
|
|
12
12
|
declare const createRequester: (config: Config) => {
|
|
13
|
-
get: <T
|
|
14
|
-
post: <T
|
|
15
|
-
patch: <T
|
|
16
|
-
put: <T
|
|
17
|
-
delete: <T =
|
|
13
|
+
get: <T>(url: string, data?: PData) => Promise<T>;
|
|
14
|
+
post: <T>(url: string, data?: Data) => Promise<T>;
|
|
15
|
+
patch: <T>(url: string, data?: Data) => Promise<T>;
|
|
16
|
+
put: <T>(url: string, data?: Data) => Promise<T>;
|
|
17
|
+
delete: <T = void>(url: string, data?: PData) => Promise<T>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
declare enum Status {
|
|
@@ -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(
|
|
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://
|
|
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(
|
|
77
|
-
|
|
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() {
|
|
@@ -82,31 +87,30 @@ var Payment = class {
|
|
|
82
87
|
return res.data;
|
|
83
88
|
}
|
|
84
89
|
async pay(ticketCode) {
|
|
85
|
-
|
|
86
|
-
return res.data;
|
|
90
|
+
return this._requester.put(`/api/payments/${this.id}/pay`, { body: { ticketCode } });
|
|
87
91
|
}
|
|
88
92
|
};
|
|
89
93
|
var _Ariari = class _Ariari {
|
|
90
94
|
constructor({ name = "main", ...config }) {
|
|
91
95
|
this.create = async (data) => {
|
|
92
96
|
const res = await this._requester.post("/api/payments", { body: data });
|
|
93
|
-
return new Payment(res
|
|
97
|
+
return new Payment(res, this._requester);
|
|
94
98
|
};
|
|
95
99
|
this.getPayment = (id) => new Payment(id, this._requester);
|
|
96
100
|
this.products = {
|
|
97
101
|
create: async (data) => {
|
|
98
|
-
|
|
99
|
-
return res.data;
|
|
102
|
+
return this._requester.post("/api/products", { body: data });
|
|
100
103
|
},
|
|
101
104
|
list: async () => {
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
return this._requester.get("/api/products");
|
|
106
|
+
},
|
|
107
|
+
update: async (id, data) => {
|
|
108
|
+
return this._requester.put(`/api/products/${id}`, { body: data });
|
|
104
109
|
},
|
|
105
110
|
delete: async (id) => {
|
|
106
111
|
await this._requester.delete(`/api/products/${id}`);
|
|
107
112
|
}
|
|
108
113
|
};
|
|
109
|
-
this._config = config;
|
|
110
114
|
this._requester = createRequester(config);
|
|
111
115
|
instances[name] = this;
|
|
112
116
|
}
|
|
@@ -122,6 +126,7 @@ _Ariari.getPayment = (id) => _Ariari.get("main")?.getPayment(id);
|
|
|
122
126
|
_Ariari.products = {
|
|
123
127
|
create: async (data) => await _Ariari.get("main")?.products.create(data),
|
|
124
128
|
list: async () => await _Ariari.get("main")?.products.list(),
|
|
129
|
+
update: async (id, data) => await _Ariari.get("main")?.products.update(id, data),
|
|
125
130
|
delete: async (id) => await _Ariari.get("main")?.products.delete(id)
|
|
126
131
|
};
|
|
127
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://
|
|
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(
|
|
50
|
-
|
|
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() {
|
|
@@ -55,31 +60,30 @@ var Payment = class {
|
|
|
55
60
|
return res.data;
|
|
56
61
|
}
|
|
57
62
|
async pay(ticketCode) {
|
|
58
|
-
|
|
59
|
-
return res.data;
|
|
63
|
+
return this._requester.put(`/api/payments/${this.id}/pay`, { body: { ticketCode } });
|
|
60
64
|
}
|
|
61
65
|
};
|
|
62
66
|
var _Ariari = class _Ariari {
|
|
63
67
|
constructor({ name = "main", ...config }) {
|
|
64
68
|
this.create = async (data) => {
|
|
65
69
|
const res = await this._requester.post("/api/payments", { body: data });
|
|
66
|
-
return new Payment(res
|
|
70
|
+
return new Payment(res, this._requester);
|
|
67
71
|
};
|
|
68
72
|
this.getPayment = (id) => new Payment(id, this._requester);
|
|
69
73
|
this.products = {
|
|
70
74
|
create: async (data) => {
|
|
71
|
-
|
|
72
|
-
return res.data;
|
|
75
|
+
return this._requester.post("/api/products", { body: data });
|
|
73
76
|
},
|
|
74
77
|
list: async () => {
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
return this._requester.get("/api/products");
|
|
79
|
+
},
|
|
80
|
+
update: async (id, data) => {
|
|
81
|
+
return this._requester.put(`/api/products/${id}`, { body: data });
|
|
77
82
|
},
|
|
78
83
|
delete: async (id) => {
|
|
79
84
|
await this._requester.delete(`/api/products/${id}`);
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
|
-
this._config = config;
|
|
83
87
|
this._requester = createRequester(config);
|
|
84
88
|
instances[name] = this;
|
|
85
89
|
}
|
|
@@ -95,6 +99,7 @@ _Ariari.getPayment = (id) => _Ariari.get("main")?.getPayment(id);
|
|
|
95
99
|
_Ariari.products = {
|
|
96
100
|
create: async (data) => await _Ariari.get("main")?.products.create(data),
|
|
97
101
|
list: async () => await _Ariari.get("main")?.products.list(),
|
|
102
|
+
update: async (id, data) => await _Ariari.get("main")?.products.update(id, data),
|
|
98
103
|
delete: async (id) => await _Ariari.get("main")?.products.delete(id)
|
|
99
104
|
};
|
|
100
105
|
var Ariari = _Ariari;
|