@abiyz/billing 0.0.0-stage → 0.2.0
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/LICENSE +99 -0
- package/README.md +121 -2
- package/index.d.ts +7518 -0
- package/index.js +52 -0
- package/package.json +23 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
ABIYZ BILLING SDK — TERMS OF USE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abiyz Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
These terms govern your use of the Abiyz Billing software development kit,
|
|
6
|
+
published on npm as @abiyz/billing (the "SDK"). By installing or using the
|
|
7
|
+
SDK you agree to them. If you use it on behalf of an organization, you agree
|
|
8
|
+
for that organization.
|
|
9
|
+
|
|
10
|
+
1. What you may do
|
|
11
|
+
|
|
12
|
+
Abiyz Inc. ("Abiyz") grants you a non-exclusive, non-transferable,
|
|
13
|
+
royalty-free, revocable licence to install, use, copy and modify the SDK
|
|
14
|
+
for the sole purpose of building, testing and running applications that
|
|
15
|
+
use Abiyz Billing (your "applications"), and to distribute the SDK, as
|
|
16
|
+
modified by you or not, as part of your applications — including in the
|
|
17
|
+
code your applications send to your users' browsers and devices. Your
|
|
18
|
+
users need no licence from Abiyz to run what you send them.
|
|
19
|
+
|
|
20
|
+
2. What you may not do
|
|
21
|
+
|
|
22
|
+
Except as these terms allow, or as applicable law permits despite them, you
|
|
23
|
+
may not:
|
|
24
|
+
(a) sell, rent, sublicense or distribute the SDK, or a modified version of
|
|
25
|
+
it, on its own or as part of a library, framework or development tool
|
|
26
|
+
for others to build with, rather than as part of your applications;
|
|
27
|
+
(b) remove or alter these terms or the copyright notice in the copies of
|
|
28
|
+
the SDK you distribute in source form;
|
|
29
|
+
(c) use the SDK with a billing service other than Abiyz Billing, use it
|
|
30
|
+
to access Abiyz Billing other than as your agreement for it allows, or
|
|
31
|
+
use it to interfere with the service; or
|
|
32
|
+
(d) use the SDK, or anything derived from it, to build a product that
|
|
33
|
+
competes with Abiyz Billing.
|
|
34
|
+
|
|
35
|
+
3. The service is governed separately
|
|
36
|
+
|
|
37
|
+
The SDK is a client for Abiyz Billing. Your use of the service itself —
|
|
38
|
+
your account, your instances, your customers' data, what you are charged —
|
|
39
|
+
is governed by the terms of service that apply to your account, not by
|
|
40
|
+
these terms. If the two conflict about the service, those terms prevail.
|
|
41
|
+
|
|
42
|
+
4. What the SDK does on the network
|
|
43
|
+
|
|
44
|
+
The SDK sends requests only to the Abiyz Billing address you name:
|
|
45
|
+
api.billing.abiyz.co, or the URL the console shows for your instance. It
|
|
46
|
+
sends them from your own server, with the instance key you give it, and
|
|
47
|
+
stores that key nowhere. The types it holds for the management API send
|
|
48
|
+
nothing. The SDK collects no usage data and sends nothing to Abiyz beyond
|
|
49
|
+
the requests you make with it.
|
|
50
|
+
|
|
51
|
+
5. Third-party software
|
|
52
|
+
|
|
53
|
+
The SDK contains no third-party code and has no dependencies.
|
|
54
|
+
|
|
55
|
+
6. Ownership
|
|
56
|
+
|
|
57
|
+
Abiyz and its licensors own the SDK and all rights in it, except those
|
|
58
|
+
granted to you here; you own your modifications, subject to these terms.
|
|
59
|
+
"Abiyz" and "Abiyz Billing", however capitalized, are names of Abiyz;
|
|
60
|
+
these terms grant no right to use them. Other names that appear in the SDK
|
|
61
|
+
or its documentation belong to their owners, and their appearance implies
|
|
62
|
+
no affiliation or endorsement.
|
|
63
|
+
|
|
64
|
+
7. No warranty
|
|
65
|
+
|
|
66
|
+
THE SDK IS PROVIDED "AS IS" AND "AS AVAILABLE", WITHOUT WARRANTY OF ANY
|
|
67
|
+
KIND, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY,
|
|
68
|
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT, TO THE FULLEST
|
|
69
|
+
EXTENT PERMITTED BY LAW.
|
|
70
|
+
|
|
71
|
+
8. Limitation of liability
|
|
72
|
+
|
|
73
|
+
TO THE FULLEST EXTENT PERMITTED BY LAW, ABIYZ WILL NOT BE LIABLE FOR ANY
|
|
74
|
+
INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL OR PUNITIVE DAMAGES, OR FOR
|
|
75
|
+
ANY LOSS OF DATA, PROFITS OR REVENUE, ARISING FROM THE SDK OR YOUR USE OF
|
|
76
|
+
IT, AND ITS TOTAL LIABILITY ARISING FROM THE SDK WILL NOT EXCEED ONE
|
|
77
|
+
HUNDRED US DOLLARS (US$100). This section does not limit liability that
|
|
78
|
+
cannot be limited by law, and it does not affect anything the terms of
|
|
79
|
+
service for your account say about the service.
|
|
80
|
+
|
|
81
|
+
9. Ending
|
|
82
|
+
|
|
83
|
+
These terms apply for as long as you use the SDK. They end automatically if
|
|
84
|
+
you breach them. When they end, stop using the SDK, delete your copies and
|
|
85
|
+
stop distributing it; copies already in the hands of your users under
|
|
86
|
+
section 1 may continue to be used by them. Sections 5 to 11 survive.
|
|
87
|
+
|
|
88
|
+
10. Export
|
|
89
|
+
|
|
90
|
+
You will comply with the export control and sanctions laws that apply to
|
|
91
|
+
your use of the SDK, and you will not use it where those laws forbid.
|
|
92
|
+
|
|
93
|
+
11. Law, changes and contact
|
|
94
|
+
|
|
95
|
+
These terms are governed by the laws of the State of Delaware, United
|
|
96
|
+
States, without regard to its conflict-of-laws rules. Each version of the
|
|
97
|
+
SDK comes with the terms that apply to it; a later version may come with
|
|
98
|
+
different terms. If any part of these terms is unenforceable, the rest
|
|
99
|
+
still applies. Questions: support@abiyz.com.
|
package/README.md
CHANGED
|
@@ -1,3 +1,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @abiyz/billing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Abiyz Billing for your application's server: sell credits, check a balance or a feature, charge
|
|
4
|
+
before the work and settle after it.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @abiyz/billing
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
ES modules, for Node 20 and later and for bundlers. The package has no dependencies. Its types use the
|
|
11
|
+
standard `fetch` types, which `@types/node` or TypeScript's `DOM` library provides.
|
|
12
|
+
|
|
13
|
+
## The runtime client
|
|
14
|
+
|
|
15
|
+
Your application's server calls Billing with an instance key. Create the instance and its key in the
|
|
16
|
+
console, at https://cloud.abiyz.com: the console shows the instance's URL and its key.
|
|
17
|
+
A test key starts with `abiyz_cloud_bil_test_` and a live key with `abiyz_cloud_bil_live_`.
|
|
18
|
+
|
|
19
|
+
Keep the key on your server, in its configuration and not in your source. Never ship it to a browser
|
|
20
|
+
or a mobile application.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { BillingError, createBillingRuntimeClient } from "@abiyz/billing";
|
|
24
|
+
|
|
25
|
+
const billing = createBillingRuntimeClient({ key: "abiyz_cloud_bil_test_..." });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The client calls `https://api.billing.abiyz.co`. Pass `baseUrl` when the console shows another URL for your
|
|
29
|
+
instance.
|
|
30
|
+
|
|
31
|
+
Money is a decimal string in the instance's currency, with up to eight decimals. Every method that
|
|
32
|
+
moves money takes an idempotency key that you choose: a retry with the same key answers the first
|
|
33
|
+
result and charges nothing twice.
|
|
34
|
+
|
|
35
|
+
### attach
|
|
36
|
+
|
|
37
|
+
A checkout page where a customer buys a pack of credits. Redirect the customer to the URL.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const checkout = await billing.attach({ customer: "user_123", pack: "credits_10", rail: "stripe", successUrl: "https://example.com/thanks" });
|
|
41
|
+
console.log(checkout.url);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### check
|
|
45
|
+
|
|
46
|
+
Whether a charge would pass, or whether a customer's plan has a feature. It moves nothing.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const answer = await billing.check({ customer: "user_123", amount: "0.50" });
|
|
50
|
+
if (!answer.allowed) console.log("not enough credit");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### track
|
|
54
|
+
|
|
55
|
+
Charge after the work, with no hold.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const tracked = await billing.track({ customer: "user_123", meter: "tokens", quantity: 1200 }, { idempotencyKey: "job_42:track" });
|
|
59
|
+
console.log(tracked.movements.length);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### hold
|
|
63
|
+
|
|
64
|
+
Charge before the work: reserve an amount, so that the work never runs on credit the customer does
|
|
65
|
+
not have.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const held = await billing.hold({ customer: "user_123", amount: "0.50", ttl: 600 }, { idempotencyKey: "job_43:hold" });
|
|
69
|
+
const holdId = held.hold.id;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### settle
|
|
73
|
+
|
|
74
|
+
Settle a hold after the work, for what the work cost.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
await billing.settle(holdId, { amount: "0.42" }, { idempotencyKey: "job_43:settle" });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### release
|
|
81
|
+
|
|
82
|
+
Release a hold and charge nothing, when the work did not happen.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
await billing.release(holdId, { idempotencyKey: "job_43:release" });
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Errors
|
|
89
|
+
|
|
90
|
+
An answer that is not a success throws `BillingError`, with the HTTP status and the problem Billing
|
|
91
|
+
answered with.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
try {
|
|
95
|
+
await billing.hold({ customer: "user_123", amount: "5000.00" }, { idempotencyKey: "job_44:hold" });
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof BillingError) console.log(error.status, error.problem?.code);
|
|
98
|
+
else throw error;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The client does not retry. A retry is your decision, and with the same idempotency key it is safe.
|
|
103
|
+
|
|
104
|
+
## The management client
|
|
105
|
+
|
|
106
|
+
The management API creates and changes what the console does: instances, keys, packs, plans and
|
|
107
|
+
policies. It answers at `https://api.abiyz.com/v1/billing` and takes a personal access token, which starts
|
|
108
|
+
with `abiyz_cloud_pat_`, not an instance key. It never moves money.
|
|
109
|
+
|
|
110
|
+
The package holds the management API's types, to use with `fetch` or with any typed client. The
|
|
111
|
+
runtime API's types are beside them, as `BillingRuntimePaths`, `BillingRuntimeOperations` and
|
|
112
|
+
`BillingRuntimeComponents`.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import type { BillingManagementOperations } from "@abiyz/billing";
|
|
116
|
+
|
|
117
|
+
type InstanceList = BillingManagementOperations["listBillingInstances"]["responses"][200]["content"]["application/json"];
|
|
118
|
+
|
|
119
|
+
const response = await fetch("https://api.abiyz.com/v1/billing/instances", { headers: { authorization: "Bearer abiyz_cloud_pat_..." } });
|
|
120
|
+
const instances = (await response.json()) as InstanceList;
|
|
121
|
+
console.log(instances);
|
|
122
|
+
```
|