@boelabs/billete-sdk 0.5.0 → 0.7.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/README.md +16 -1
- package/dist/client.d.ts +25 -8
- package/dist/client.js +56 -3
- package/dist/{errors-CoLmEszH.d.ts → errors-f5Ne3UQC.d.ts} +165 -10
- package/dist/{events-oZ08-Zz2.d.ts → events-D_VB-i7R.d.ts} +96 -9
- package/dist/{http-F2X2zd4c.js → http-8zfGyXd_.js} +1 -1
- package/dist/index.d.ts +24 -3
- package/dist/index.js +24 -1
- package/dist/webhooks.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,9 @@ const checkout = await billete.checkouts.create({
|
|
|
64
64
|
plan: "plan_…",
|
|
65
65
|
months: 1,
|
|
66
66
|
customer: { email: "ana@example.com", externalId: "user_123" },
|
|
67
|
+
// {CHECKOUT_ID} se reemplaza por el ID del checkout.
|
|
68
|
+
successUrl: "https://tuapp.com/gracias?checkout={CHECKOUT_ID}",
|
|
69
|
+
cancelUrl: "https://tuapp.com/planes",
|
|
67
70
|
});
|
|
68
71
|
|
|
69
72
|
// Redirige a tu cliente a checkout.url para que pague.
|
|
@@ -109,12 +112,14 @@ Todos los métodos devuelven promesas con el recurso tipado. Los recursos con li
|
|
|
109
112
|
| --- | --- |
|
|
110
113
|
| `customers` | — |
|
|
111
114
|
| `customerSessions` | `create` |
|
|
115
|
+
| `portalSessions` | `create` (enlace al portal del cliente, válido 60 minutos) |
|
|
112
116
|
| `products` | `retire`, `retireVariant` |
|
|
113
117
|
| `plans` | — |
|
|
114
118
|
| `features` | `check`, `isEnabled`, `listForCustomer`, `consume`, `release`, `set` |
|
|
115
119
|
| `coupons` | — |
|
|
116
120
|
| `checkouts` | `expire` |
|
|
117
121
|
| `paymentLinks` | `retire` |
|
|
122
|
+
| `invoices` | `void` (cobros: renovaciones y cobros sueltos, con página de pago en `url`) |
|
|
118
123
|
| `subscriptions` | `cancel`, `resume` |
|
|
119
124
|
| `payments` | `refund`, `listRefunds` |
|
|
120
125
|
| `payouts` | — |
|
|
@@ -231,8 +236,18 @@ const { data: subscriptions } = await billete.customer.subscriptions();
|
|
|
231
236
|
const tokens = await billete.customer.feature("tokens");
|
|
232
237
|
```
|
|
233
238
|
|
|
239
|
+
Para no construir esa pantalla, envía a tu cliente al portal alojado:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
const portal = await billete.portalSessions.create({
|
|
243
|
+
customer: "user_123",
|
|
244
|
+
returnUrl: "https://tuapp.com/cuenta",
|
|
245
|
+
});
|
|
246
|
+
// Redirige a portal.url: allí ve sus suscripciones y cobros, cambia su ciclo o cancela.
|
|
247
|
+
```
|
|
248
|
+
|
|
234
249
|
`customerSession` también acepta una función, útil cuando el token se renueva. Sin sesión, el
|
|
235
|
-
cliente puede leer y pagar checkouts y links de pago, y consultar tasas y monedas.
|
|
250
|
+
cliente puede leer y pagar checkouts, cobros y links de pago, y consultar tasas y monedas.
|
|
236
251
|
|
|
237
252
|
## Webhooks
|
|
238
253
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { A as
|
|
1
|
+
import { $ as RISK_LEVELS, A as INVOICE_REASONS, At as MOBILE_PREFIXES, B as PaymentFailure, Bt as Environment, C as Event, Ct as CURRENCIES, D as FeatureReset, Dt as List, E as Feature, Et as GracePeriodDays, F as LineItem, Ft as Timestamp, G as Plan, H as PaymentSettlement, Ht as tokenEnvironment, I as PAYMENT_STATUSES, It as isLandlinePhone, J as PortalSession, K as PlanFeatureValues, L as PRODUCT_CATEGORIES, Lt as isMobilePhone, M as Invoice, Mt as MobilePrefix, N as InvoiceReason, Nt as TAX_BEHAVIORS, O as FeatureType, Ot as ListQuery, P as InvoiceStatus, Pt as TaxBehavior, Q as RESET_FREQUENCIES, R as Payment, Rt as nationalPhone, S as CustomerSession, St as BillingMonths, T as FEATURE_TYPES, Tt as GRACE_PERIOD_DAYS, U as PaymentStatus, Ut as tokenPrefix, V as PaymentLink, Vt as TokenKind, W as Payout, X as ProductCategory, Y as Product, Z as ProductVariant, _ as CurrencyAvailability, _t as PAYMENT_FAILURE_CODES, a as Actor, at as SUBSCRIPTION_STATUSES, b as CustomerDetails, bt as AddressInput, c as BalanceAmount, ct as SubscriptionRenewal, d as CancellationFeedback, dt as WebhookEndpoint, et as Refund, f as Checkout, ft as Weekday, g as Coupon, gt as ApiErrorType, h as CollectSettings, ht as ApiErrorEnvelope, i as WebhookEvent, it as SUBMIT_LABELS, j as INVOICE_STATUSES, jt as Metadata, k as FeatureUsageResult, kt as MAX_QUANTITY, l as CANCELLATION_FEEDBACK, lt as SubscriptionStatus, m as CheckoutPurpose, mt as ApiErrorBody, n as EventDataMap, nt as Retirement, o as AfterCompletion, ot as SubmitLabel, p as CheckoutItem, pt as API_ERROR_TYPES, q as PlanPrice, r as EventType, rt as RiskLevel, s as Balance, st as Subscription, t as EVENT_TYPES, tt as ResetFrequency, u as CHECKOUT_PURPOSES, ut as USAGE_FEATURE_TYPES, v as CustomField, vt as PaymentFailureCode, w as ExchangeRate, wt as Currency, x as CustomerFeature, xt as BILLING_MONTHS, y as Customer, yt as Address, z as PaymentAttempt, zt as ENVIRONMENTS } from "./events-D_VB-i7R.js";
|
|
2
|
+
import { $ as PaymentTestScenario, A as PlanCreate, B as RefundCreate, C as FeatureUpdate, D as PaymentLinkCreate, E as KEY_PATTERN, F as PortalSessionCreate, G as VariantInput, H as SubscriptionCancel, I as ProductCheckoutCreate, J as CustomerSubscription, K as WebhookEndpointCreate, L as ProductCreate, M as PlanLinkCreate, N as PlanPriceInput, O as PaymentLinkUpdate, P as PlanUpdate, Q as PaymentNextAction, R as ProductLinkCreate, S as FeatureCreate, T as InvoiceLineInput, U as SubscriptionCreate, V as RetireInput, W as SubscriptionUpdate, X as PaymentMethodField, Y as PaymentInstructions, Z as PaymentMethodOption, _ as CustomerCreate, a as CheckoutCreate, at as PublicPortal, b as CustomerUpdate, c as ClientCheckoutUpdate, d as ClientSubscriptionCancel, et as PortalFeatures, f as ClientSubscriptionUpdate, g as CustomFieldInput, h as CouponUpdate, i as AfterCompletionInput, it as PublicPaymentState, j as PlanFeaturesInput, k as PlanCheckoutCreate, l as ClientInvoicePay, m as CouponCreate, n as RequestOptions, nt as PublicInvoice, o as CheckoutItemInput, p as CollectInput, q as WebhookEndpointUpdate, r as TransportOptions, rt as PublicPaymentLink, s as ClientCheckoutPay, t as BilleteError, tt as PublicCheckout, u as ClientLinkCheckout, v as CustomerInput, w as InvoiceCreate, x as EventSelector, y as CustomerSessionCreate, z as ProductUpdate } from "./errors-f5Ne3UQC.js";
|
|
3
3
|
//#region src/create-client.d.ts
|
|
4
4
|
interface ClientOptions extends TransportOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Token from `billete.customerSessions.create()` on your server. Needed only for the
|
|
7
|
-
* `customer` methods; paying checkouts works without it.
|
|
7
|
+
* `customer` methods; paying checkouts and Cobros works without it.
|
|
8
8
|
*/
|
|
9
9
|
customerSession?: string | (() => string | undefined);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Browser client. It never holds a secret key: checkouts are addressed by their
|
|
12
|
+
* Browser client. It never holds a secret key: checkouts and Cobros are addressed by their
|
|
13
|
+
* unguessable ID
|
|
13
14
|
* and customer data requires a short-lived customer session minted by your server.
|
|
14
15
|
*
|
|
15
16
|
* ```ts
|
|
@@ -24,10 +25,17 @@ export declare function createClient(options?: ClientOptions): {
|
|
|
24
25
|
/** Changes quantity, variant, billing cycle or coupon on a payment link checkout. */
|
|
25
26
|
update: (id: string, changes: ClientCheckoutUpdate, options?: RequestOptions) => Promise<PublicCheckout>;
|
|
26
27
|
/** Methods that can pay this checkout, with the converted amount and transfer details. */
|
|
27
|
-
paymentMethods: (id: string, options?: RequestOptions) => Promise<List<
|
|
28
|
+
paymentMethods: (id: string, options?: RequestOptions) => Promise<List<PaymentMethodOption>>;
|
|
28
29
|
/** Submits the payment; the returned checkout carries the payment status and any failure. */
|
|
29
30
|
pay: (id: string, input: ClientCheckoutPay, options?: RequestOptions) => Promise<PublicCheckout>;
|
|
30
31
|
};
|
|
32
|
+
invoices: {
|
|
33
|
+
retrieve: (id: string, options?: RequestOptions) => Promise<PublicInvoice>;
|
|
34
|
+
/** Methods that can pay this Cobro, with the converted amount and transfer details. */
|
|
35
|
+
paymentMethods: (id: string, options?: RequestOptions) => Promise<List<PaymentMethodOption>>;
|
|
36
|
+
/** Submits the payment; the returned Cobro carries the payment status and any failure. */
|
|
37
|
+
pay: (id: string, input: ClientInvoicePay, options?: RequestOptions) => Promise<PublicInvoice>;
|
|
38
|
+
};
|
|
31
39
|
paymentLinks: {
|
|
32
40
|
retrieve: (id: string, options?: RequestOptions) => Promise<PublicPaymentLink>;
|
|
33
41
|
createCheckout: (id: string, selection?: ClientLinkCheckout, options?: RequestOptions) => Promise<PublicCheckout>;
|
|
@@ -42,12 +50,21 @@ export declare function createClient(options?: ClientOptions): {
|
|
|
42
50
|
/** The customer behind the session token. */
|
|
43
51
|
customer: {
|
|
44
52
|
retrieve: (options?: RequestOptions) => Promise<Customer>;
|
|
45
|
-
/** Subscriptions with their `renewal` block: due date, grace period and
|
|
46
|
-
subscriptions: (options?: RequestOptions) => Promise<List<
|
|
53
|
+
/** Subscriptions with their `renewal` block: due date, grace period and the Cobro to pay. */
|
|
54
|
+
subscriptions: (options?: RequestOptions) => Promise<List<CustomerSubscription>>;
|
|
55
|
+
/** Everything the customer portal shows: subscriptions, Cobros and what the business allows. */
|
|
56
|
+
portal: (options?: RequestOptions) => Promise<PublicPortal>;
|
|
57
|
+
/** Cancels at the end of the paid period; `resumeSubscription` undoes it until then. */
|
|
58
|
+
cancelSubscription: (id: string, input?: ClientSubscriptionCancel, options?: RequestOptions) => Promise<CustomerSubscription>;
|
|
59
|
+
resumeSubscription: (id: string, options?: RequestOptions) => Promise<CustomerSubscription>;
|
|
60
|
+
/** Switches the billing cycle from the next renewal. */
|
|
61
|
+
updateSubscription: (id: string, input: ClientSubscriptionUpdate, options?: RequestOptions) => Promise<CustomerSubscription>;
|
|
62
|
+
/** Withdraws the mandate: renewals are then paid by hand from their Cobro. */
|
|
63
|
+
stopAutoCharge: (id: string, options?: RequestOptions) => Promise<CustomerSubscription>;
|
|
47
64
|
features: (options?: RequestOptions) => Promise<List<CustomerFeature>>;
|
|
48
65
|
feature: (key: string, options?: RequestOptions) => Promise<CustomerFeature>;
|
|
49
66
|
};
|
|
50
67
|
};
|
|
51
68
|
type BilleteClient = ReturnType<typeof createClient>;
|
|
52
69
|
//#endregion
|
|
53
|
-
export { type API_ERROR_TYPES, type Actor, type Address, type AddressInput, type AfterCompletion, type AfterCompletionInput, type ApiErrorBody, type ApiErrorEnvelope, type ApiErrorType, type BILLING_MONTHS, type Balance, type BalanceAmount, type BilleteClient, BilleteError, type BillingMonths, type CHECKOUT_PURPOSES, type CURRENCIES, type Checkout, type CheckoutCreate, type CheckoutItem, type CheckoutItemInput, type
|
|
70
|
+
export { type API_ERROR_TYPES, type Actor, type Address, type AddressInput, type AfterCompletion, type AfterCompletionInput, type ApiErrorBody, type ApiErrorEnvelope, type ApiErrorType, type BILLING_MONTHS, type Balance, type BalanceAmount, type BilleteClient, BilleteError, type BillingMonths, type CANCELLATION_FEEDBACK, type CHECKOUT_PURPOSES, type CURRENCIES, type CancellationFeedback, type Checkout, type CheckoutCreate, type CheckoutItem, type CheckoutItemInput, type CheckoutPurpose, type ClientCheckoutPay, type ClientCheckoutUpdate, type ClientInvoicePay, type ClientLinkCheckout, type ClientOptions, type ClientSubscriptionCancel, type ClientSubscriptionUpdate, type CollectInput, type CollectSettings, type Coupon, type CouponCreate, type CouponUpdate, type Currency, type CurrencyAvailability, type CustomField, type CustomFieldInput, type Customer, type CustomerCreate, type CustomerDetails, type CustomerFeature, type CustomerInput, type CustomerSession, type CustomerSessionCreate, type CustomerSubscription, type CustomerUpdate, type ENVIRONMENTS, type EVENT_TYPES, type Environment, type Event, type EventDataMap, type EventSelector, type EventType, type ExchangeRate, type FEATURE_TYPES, type Feature, type FeatureCreate, type FeatureReset, type FeatureType, type FeatureUpdate, type FeatureUsageResult, type GRACE_PERIOD_DAYS, type GracePeriodDays, type INVOICE_REASONS, type INVOICE_STATUSES, type Invoice, type InvoiceCreate, type InvoiceLineInput, type InvoiceReason, type InvoiceStatus, type KEY_PATTERN, type LineItem, type List, type ListQuery, type MAX_QUANTITY, type MOBILE_PREFIXES, type Metadata, type MobilePrefix, type PAYMENT_FAILURE_CODES, type PAYMENT_STATUSES, type PRODUCT_CATEGORIES, type Payment, type PaymentAttempt, type PaymentFailure, type PaymentFailureCode, type PaymentInstructions, type PaymentLink, type PaymentLinkCreate, type PaymentLinkUpdate, type PaymentMethodField, type PaymentMethodOption, type PaymentNextAction, type PaymentSettlement, type PaymentStatus, type PaymentTestScenario, type Payout, type Plan, type PlanCheckoutCreate, type PlanCreate, type PlanFeatureValues, type PlanFeaturesInput, type PlanLinkCreate, type PlanPrice, type PlanPriceInput, type PlanUpdate, type PortalFeatures, type PortalSession, type PortalSessionCreate, type Product, type ProductCategory, type ProductCheckoutCreate, type ProductCreate, type ProductLinkCreate, type ProductUpdate, type ProductVariant, type PublicCheckout, type PublicInvoice, type PublicPaymentLink, type PublicPaymentState, type PublicPortal, type RESET_FREQUENCIES, type RISK_LEVELS, type Refund, type RefundCreate, type RequestOptions, type ResetFrequency, type RetireInput, type Retirement, type RiskLevel, type SUBMIT_LABELS, type SUBSCRIPTION_STATUSES, type SubmitLabel, type Subscription, type SubscriptionCancel, type SubscriptionCreate, type SubscriptionRenewal, type SubscriptionStatus, type SubscriptionUpdate, type TAX_BEHAVIORS, type TaxBehavior, type Timestamp, type TokenKind, type USAGE_FEATURE_TYPES, type VariantInput, type WebhookEndpoint, type WebhookEndpointCreate, type WebhookEndpointUpdate, type WebhookEvent, type Weekday, type isLandlinePhone, type isMobilePhone, type nationalPhone, type tokenEnvironment, type tokenPrefix };
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { n as segment, r as BilleteError, t as createTransport } from "./http-
|
|
1
|
+
import { n as segment, r as BilleteError, t as createTransport } from "./http-8zfGyXd_.js";
|
|
2
2
|
//#region src/create-client.ts
|
|
3
3
|
/**
|
|
4
|
-
* Browser client. It never holds a secret key: checkouts are addressed by their
|
|
4
|
+
* Browser client. It never holds a secret key: checkouts and Cobros are addressed by their
|
|
5
|
+
* unguessable ID
|
|
5
6
|
* and customer data requires a short-lived customer session minted by your server.
|
|
6
7
|
*
|
|
7
8
|
* ```ts
|
|
@@ -17,6 +18,7 @@ function createClient(options = {}) {
|
|
|
17
18
|
token: typeof session === "function" ? session : () => session
|
|
18
19
|
});
|
|
19
20
|
const checkoutPath = (id) => `/v1/client/checkouts/${segment(id)}`;
|
|
21
|
+
const invoicePath = (id) => `/v1/client/invoices/${segment(id)}`;
|
|
20
22
|
return {
|
|
21
23
|
checkouts: {
|
|
22
24
|
retrieve: (id, options) => http.request({
|
|
@@ -45,6 +47,26 @@ function createClient(options = {}) {
|
|
|
45
47
|
options
|
|
46
48
|
})
|
|
47
49
|
},
|
|
50
|
+
invoices: {
|
|
51
|
+
retrieve: (id, options) => http.request({
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: invoicePath(id),
|
|
54
|
+
options
|
|
55
|
+
}),
|
|
56
|
+
/** Methods that can pay this Cobro, with the converted amount and transfer details. */
|
|
57
|
+
paymentMethods: (id, options) => http.request({
|
|
58
|
+
method: "GET",
|
|
59
|
+
path: `${invoicePath(id)}/payment-methods`,
|
|
60
|
+
options
|
|
61
|
+
}),
|
|
62
|
+
/** Submits the payment; the returned Cobro carries the payment status and any failure. */
|
|
63
|
+
pay: (id, input, options) => http.request({
|
|
64
|
+
method: "POST",
|
|
65
|
+
path: `${invoicePath(id)}/pay`,
|
|
66
|
+
body: input,
|
|
67
|
+
options
|
|
68
|
+
})
|
|
69
|
+
},
|
|
48
70
|
paymentLinks: {
|
|
49
71
|
retrieve: (id, options) => http.request({
|
|
50
72
|
method: "GET",
|
|
@@ -77,12 +99,43 @@ list: (options) => http.request({
|
|
|
77
99
|
path: "/v1/client/customer",
|
|
78
100
|
options
|
|
79
101
|
}),
|
|
80
|
-
/** Subscriptions with their `renewal` block: due date, grace period and
|
|
102
|
+
/** Subscriptions with their `renewal` block: due date, grace period and the Cobro to pay. */
|
|
81
103
|
subscriptions: (options) => http.request({
|
|
82
104
|
method: "GET",
|
|
83
105
|
path: "/v1/client/customer/subscriptions",
|
|
84
106
|
options
|
|
85
107
|
}),
|
|
108
|
+
/** Everything the customer portal shows: subscriptions, Cobros and what the business allows. */
|
|
109
|
+
portal: (options) => http.request({
|
|
110
|
+
method: "GET",
|
|
111
|
+
path: "/v1/client/customer/portal",
|
|
112
|
+
options
|
|
113
|
+
}),
|
|
114
|
+
/** Cancels at the end of the paid period; `resumeSubscription` undoes it until then. */
|
|
115
|
+
cancelSubscription: (id, input = {}, options) => http.request({
|
|
116
|
+
method: "POST",
|
|
117
|
+
path: `/v1/client/customer/subscriptions/${segment(id)}/cancel`,
|
|
118
|
+
body: input,
|
|
119
|
+
options
|
|
120
|
+
}),
|
|
121
|
+
resumeSubscription: (id, options) => http.request({
|
|
122
|
+
method: "POST",
|
|
123
|
+
path: `/v1/client/customer/subscriptions/${segment(id)}/resume`,
|
|
124
|
+
options
|
|
125
|
+
}),
|
|
126
|
+
/** Switches the billing cycle from the next renewal. */
|
|
127
|
+
updateSubscription: (id, input, options) => http.request({
|
|
128
|
+
method: "PATCH",
|
|
129
|
+
path: `/v1/client/customer/subscriptions/${segment(id)}`,
|
|
130
|
+
body: input,
|
|
131
|
+
options
|
|
132
|
+
}),
|
|
133
|
+
/** Withdraws the mandate: renewals are then paid by hand from their Cobro. */
|
|
134
|
+
stopAutoCharge: (id, options) => http.request({
|
|
135
|
+
method: "POST",
|
|
136
|
+
path: `/v1/client/customer/subscriptions/${segment(id)}/stop-auto-charge`,
|
|
137
|
+
options
|
|
138
|
+
}),
|
|
86
139
|
features: (options) => http.request({
|
|
87
140
|
method: "GET",
|
|
88
141
|
path: "/v1/client/customer/features",
|
|
@@ -1,5 +1,91 @@
|
|
|
1
|
-
import { Et as
|
|
1
|
+
import { B as PaymentFailure, Bt as Environment, D as FeatureReset, Et as GracePeriodDays, F as LineItem, Ft as Timestamp, N as InvoiceReason, P as InvoiceStatus, Pt as TaxBehavior, St as BillingMonths, U as PaymentStatus, X as ProductCategory, b as CustomerDetails, bt as AddressInput, d as CancellationFeedback, gt as ApiErrorType, h as CollectSettings, jt as Metadata, m as CheckoutPurpose, mt as ApiErrorBody, o as AfterCompletion, ot as SubmitLabel, p as CheckoutItem, q as PlanPrice, r as EventType, st as Subscription, v as CustomField, wt as Currency } from "./events-D_VB-i7R.js";
|
|
2
2
|
//#region ../contracts/src/client.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A subscription as its customer sees it, in the browser: without the business's `metadata`, with
|
|
5
|
+
* its plan's name and the cycles the customer may switch to.
|
|
6
|
+
*/
|
|
7
|
+
interface CustomerSubscription extends Omit<Subscription, "metadata"> {
|
|
8
|
+
plan: {
|
|
9
|
+
name: string;
|
|
10
|
+
cycles: PlanPrice[];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** What the business lets its customers do from the portal. */
|
|
14
|
+
interface PortalFeatures {
|
|
15
|
+
/** Paid and closed Cobros are listed; open ones always are, so they can be paid. */
|
|
16
|
+
invoiceHistory: boolean;
|
|
17
|
+
/** Cancel at the end of the period, and resume before it. */
|
|
18
|
+
cancel: boolean;
|
|
19
|
+
/** Ask why when canceling. */
|
|
20
|
+
cancellationReasons: boolean;
|
|
21
|
+
/** Switch between the plan's billing cycles, from the next renewal. */
|
|
22
|
+
switchCycle: boolean;
|
|
23
|
+
/** Turn off automatic charging and pay each renewal by hand. */
|
|
24
|
+
stopAutoCharge: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** What the customer portal shows: the customer's subscriptions and Cobros at one business. */
|
|
27
|
+
interface PublicPortal {
|
|
28
|
+
object: "portal";
|
|
29
|
+
environment: Environment;
|
|
30
|
+
merchant: {
|
|
31
|
+
name: string;
|
|
32
|
+
supportEmail: string | null;
|
|
33
|
+
supportPhone: string | null;
|
|
34
|
+
};
|
|
35
|
+
customer: {
|
|
36
|
+
email: string;
|
|
37
|
+
name: string | null;
|
|
38
|
+
};
|
|
39
|
+
/** The business's message at the top of the portal. */
|
|
40
|
+
headline: string | null;
|
|
41
|
+
features: PortalFeatures;
|
|
42
|
+
returnUrl: string | null;
|
|
43
|
+
expiresAt: Timestamp;
|
|
44
|
+
subscriptions: CustomerSubscription[];
|
|
45
|
+
/** The latest Cobros, newest first; open ones are paid on their page (`url`). */
|
|
46
|
+
invoices: PublicInvoice[];
|
|
47
|
+
}
|
|
48
|
+
/** Where a payment stands, as a payment page shows it. */
|
|
49
|
+
interface PublicPaymentState {
|
|
50
|
+
id: string;
|
|
51
|
+
status: PaymentStatus;
|
|
52
|
+
method: string | null;
|
|
53
|
+
failure: PaymentFailure | null;
|
|
54
|
+
/** What the payer must do to finish a pending payment; `null` when it only awaits the provider. */
|
|
55
|
+
nextAction: PaymentNextAction | null;
|
|
56
|
+
}
|
|
57
|
+
/** Browser-safe view of a Cobro: what its page needs to show and pay it. */
|
|
58
|
+
interface PublicInvoice {
|
|
59
|
+
id: string;
|
|
60
|
+
object: "invoice";
|
|
61
|
+
environment: Environment;
|
|
62
|
+
number: string;
|
|
63
|
+
/** The Cobro's page. */
|
|
64
|
+
url: string;
|
|
65
|
+
status: InvoiceStatus;
|
|
66
|
+
reason: InvoiceReason;
|
|
67
|
+
merchant: {
|
|
68
|
+
name: string;
|
|
69
|
+
supportEmail: string | null;
|
|
70
|
+
supportPhone: string | null;
|
|
71
|
+
};
|
|
72
|
+
email: string;
|
|
73
|
+
description: string | null;
|
|
74
|
+
lines: LineItem[];
|
|
75
|
+
currency: Currency;
|
|
76
|
+
subtotal: number;
|
|
77
|
+
discount: number;
|
|
78
|
+
tax: number;
|
|
79
|
+
total: number;
|
|
80
|
+
taxBehavior: TaxBehavior;
|
|
81
|
+
couponCode: string | null;
|
|
82
|
+
periodStart: Timestamp | null;
|
|
83
|
+
periodEnd: Timestamp | null;
|
|
84
|
+
dueAt: Timestamp | null;
|
|
85
|
+
paidAt: Timestamp | null;
|
|
86
|
+
createdAt: Timestamp;
|
|
87
|
+
payment: PublicPaymentState | null;
|
|
88
|
+
}
|
|
3
89
|
/** Browser-safe view of a checkout: everything needed to render and pay it, nothing internal. */
|
|
4
90
|
interface PublicCheckout {
|
|
5
91
|
id: string;
|
|
@@ -46,16 +132,33 @@ interface PublicCheckout {
|
|
|
46
132
|
customFields: CustomField[];
|
|
47
133
|
customerDetails: CustomerDetails;
|
|
48
134
|
submitLabel: SubmitLabel;
|
|
135
|
+
/** What follows payment; a redirect's URL already has `{CHECKOUT_ID}` replaced. */
|
|
49
136
|
afterCompletion: AfterCompletion;
|
|
50
|
-
|
|
137
|
+
/** Where "Volver" leads, resolved like the redirect; `null` hides it. */
|
|
138
|
+
cancelUrl: string | null;
|
|
51
139
|
expiresAt: Timestamp;
|
|
52
|
-
payment:
|
|
53
|
-
id: string;
|
|
54
|
-
status: PaymentStatus;
|
|
55
|
-
method: string | null;
|
|
56
|
-
failure: PaymentFailure | null;
|
|
57
|
-
} | null;
|
|
140
|
+
payment: PublicPaymentState | null;
|
|
58
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* The step a provider asks of the payer after starting a charge: leave for its page and come back
|
|
144
|
+
* (`redirect`), or send the funds to what is shown, often as a QR code (`display`).
|
|
145
|
+
*/
|
|
146
|
+
type PaymentNextAction = {
|
|
147
|
+
type: "redirect";
|
|
148
|
+
url: string;
|
|
149
|
+
} | {
|
|
150
|
+
type: "display";
|
|
151
|
+
/** What the value is: "Dirección USDT (TRC20)", "Código de pago". */
|
|
152
|
+
label: string;
|
|
153
|
+
/** Where to send the funds: a wallet address, a payment code. */
|
|
154
|
+
value: string;
|
|
155
|
+
/** Encoded in a QR code for the payer's app to scan, when the provider offers one. */
|
|
156
|
+
qr: string | null;
|
|
157
|
+
amount: number;
|
|
158
|
+
currency: Currency;
|
|
159
|
+
/** After this the payer must not send funds: the attempt fails if nothing arrived. */
|
|
160
|
+
expiresAt: Timestamp | null;
|
|
161
|
+
};
|
|
59
162
|
interface PaymentMethodField {
|
|
60
163
|
key: string;
|
|
61
164
|
label: string;
|
|
@@ -86,7 +189,7 @@ interface PaymentTestScenario {
|
|
|
86
189
|
description: string;
|
|
87
190
|
fields: Record<string, string>;
|
|
88
191
|
}
|
|
89
|
-
interface
|
|
192
|
+
interface PaymentMethodOption {
|
|
90
193
|
id: string;
|
|
91
194
|
name: string;
|
|
92
195
|
description: string | null;
|
|
@@ -291,6 +394,13 @@ interface SubscriptionUpdate {
|
|
|
291
394
|
interface SubscriptionCancel {
|
|
292
395
|
/** `false` ends the subscription immediately. */
|
|
293
396
|
atPeriodEnd?: boolean;
|
|
397
|
+
feedback?: CancellationFeedback;
|
|
398
|
+
comment?: string;
|
|
399
|
+
}
|
|
400
|
+
/** Canceling from the portal always waits for the period's end. */
|
|
401
|
+
interface ClientSubscriptionCancel {
|
|
402
|
+
feedback?: CancellationFeedback;
|
|
403
|
+
comment?: string;
|
|
294
404
|
}
|
|
295
405
|
/** Exactly one of `percentOff` and `amountOff`; `amountOff` needs a `currency`. */
|
|
296
406
|
interface CouponCreate {
|
|
@@ -368,7 +478,13 @@ interface CheckoutFields {
|
|
|
368
478
|
customer?: CustomerInput;
|
|
369
479
|
coupon?: string;
|
|
370
480
|
collect?: CollectInput;
|
|
481
|
+
/**
|
|
482
|
+
* Where the customer goes after paying. `{CHECKOUT_ID}` is replaced by the checkout's ID, so
|
|
483
|
+
* the page can confirm the order: `https://tienda.com/gracias?checkout={CHECKOUT_ID}`.
|
|
484
|
+
*/
|
|
371
485
|
successUrl?: string;
|
|
486
|
+
/** Where "Volver" leads when the customer leaves without paying; `{CHECKOUT_ID}` works too. */
|
|
487
|
+
cancelUrl?: string;
|
|
372
488
|
expiresInMinutes?: number;
|
|
373
489
|
metadata?: Metadata;
|
|
374
490
|
}
|
|
@@ -385,6 +501,36 @@ interface PlanCheckoutCreate extends CheckoutFields {
|
|
|
385
501
|
months: BillingMonths;
|
|
386
502
|
}
|
|
387
503
|
type CheckoutCreate = ProductCheckoutCreate | PlanCheckoutCreate;
|
|
504
|
+
/**
|
|
505
|
+
* A line of a one-off Cobro: a product of the catalog, priced by it (units are held while its
|
|
506
|
+
* payment is verified, like a checkout's), or a line the business describes and prices.
|
|
507
|
+
*/
|
|
508
|
+
type InvoiceLineInput = {
|
|
509
|
+
product: string;
|
|
510
|
+
variant?: string;
|
|
511
|
+
quantity?: number;
|
|
512
|
+
} | {
|
|
513
|
+
description: string;
|
|
514
|
+
quantity?: number;
|
|
515
|
+
/** Per unit, in minor units. */
|
|
516
|
+
unitAmount: number;
|
|
517
|
+
};
|
|
518
|
+
/** A one-off Cobro for a customer, payable from its page (`url`). */
|
|
519
|
+
interface InvoiceCreate {
|
|
520
|
+
customer: CustomerInput;
|
|
521
|
+
currency: Currency;
|
|
522
|
+
lines: InvoiceLineInput[];
|
|
523
|
+
/** Defaults to the business's tax behavior for new prices (`inclusive`). */
|
|
524
|
+
taxBehavior?: TaxBehavior;
|
|
525
|
+
/** Days to pay it; without it the Cobro has no due date. */
|
|
526
|
+
daysUntilDue?: number;
|
|
527
|
+
description?: string;
|
|
528
|
+
metadata?: Metadata;
|
|
529
|
+
}
|
|
530
|
+
interface ClientInvoicePay {
|
|
531
|
+
method: string;
|
|
532
|
+
fields?: Record<string, string>;
|
|
533
|
+
}
|
|
388
534
|
interface ClientLinkCheckout {
|
|
389
535
|
variant?: string;
|
|
390
536
|
quantity?: number;
|
|
@@ -411,6 +557,15 @@ interface CustomerSessionCreate {
|
|
|
411
557
|
customer: string;
|
|
412
558
|
expiresInMinutes?: number;
|
|
413
559
|
}
|
|
560
|
+
interface PortalSessionCreate {
|
|
561
|
+
/** A `cus_…` ID or your own `externalId`. */
|
|
562
|
+
customer: string;
|
|
563
|
+
returnUrl?: string;
|
|
564
|
+
}
|
|
565
|
+
/** The cycle a customer switches to from the portal; it applies from the next renewal. */
|
|
566
|
+
interface ClientSubscriptionUpdate {
|
|
567
|
+
months: BillingMonths;
|
|
568
|
+
}
|
|
414
569
|
interface ClientCheckoutUpdate {
|
|
415
570
|
quantity?: number;
|
|
416
571
|
variant?: string;
|
|
@@ -459,4 +614,4 @@ declare class BilleteError extends Error {
|
|
|
459
614
|
}, status: number);
|
|
460
615
|
}
|
|
461
616
|
//#endregion
|
|
462
|
-
export {
|
|
617
|
+
export { PaymentTestScenario as $, PlanCreate as A, RefundCreate as B, FeatureUpdate as C, PaymentLinkCreate as D, KEY_PATTERN as E, PortalSessionCreate as F, VariantInput as G, SubscriptionCancel as H, ProductCheckoutCreate as I, CustomerSubscription as J, WebhookEndpointCreate as K, ProductCreate as L, PlanLinkCreate as M, PlanPriceInput as N, PaymentLinkUpdate as O, PlanUpdate as P, PaymentNextAction as Q, ProductLinkCreate as R, FeatureCreate as S, InvoiceLineInput as T, SubscriptionCreate as U, RetireInput as V, SubscriptionUpdate as W, PaymentMethodField as X, PaymentInstructions as Y, PaymentMethodOption as Z, CustomerCreate as _, CheckoutCreate as a, PublicPortal as at, CustomerUpdate as b, ClientCheckoutUpdate as c, ClientSubscriptionCancel as d, PortalFeatures as et, ClientSubscriptionUpdate as f, CustomFieldInput as g, CouponUpdate as h, AfterCompletionInput as i, PublicPaymentState as it, PlanFeaturesInput as j, PlanCheckoutCreate as k, ClientInvoicePay as l, CouponCreate as m, RequestOptions as n, PublicInvoice as nt, CheckoutItemInput as o, CollectInput as p, WebhookEndpointUpdate as q, TransportOptions as r, PublicPaymentLink as rt, ClientCheckoutPay as s, BilleteError as t, PublicCheckout as tt, ClientLinkCheckout as u, CustomerInput as v, InvoiceCreate as w, EventSelector as x, CustomerSessionCreate as y, ProductUpdate as z };
|
|
@@ -108,7 +108,9 @@ interface ApiErrorEnvelope {
|
|
|
108
108
|
error: ApiErrorBody;
|
|
109
109
|
}
|
|
110
110
|
/** Normalized payment failure codes, independent of the provider that produced them. */
|
|
111
|
-
declare const PAYMENT_FAILURE_CODES: readonly ["insufficient_funds", "payment_not_found", "amount_mismatch", "invalid_details", "declined", "provider_unavailable"
|
|
111
|
+
declare const PAYMENT_FAILURE_CODES: readonly ["insufficient_funds", "payment_not_found", "amount_mismatch", "invalid_details", "declined", "provider_unavailable",
|
|
112
|
+
/** The payer did not complete the payment in time (an address or code to pay expired). */
|
|
113
|
+
"expired"];
|
|
112
114
|
type PaymentFailureCode = (typeof PAYMENT_FAILURE_CODES)[number];
|
|
113
115
|
//#endregion
|
|
114
116
|
//#region ../contracts/src/resources.d.ts
|
|
@@ -277,9 +279,13 @@ interface SubscriptionRenewal {
|
|
|
277
279
|
daysRemaining: number;
|
|
278
280
|
amount: number;
|
|
279
281
|
currency: Currency;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
+
/** The Cobro to pay the renewal with, once it is open. */
|
|
283
|
+
invoiceId: string | null;
|
|
284
|
+
invoiceUrl: string | null;
|
|
282
285
|
}
|
|
286
|
+
/** Why a customer canceled, as they chose it (Stripe's `cancellation_details.feedback`). */
|
|
287
|
+
declare const CANCELLATION_FEEDBACK: readonly ["too_expensive", "missing_features", "switched_service", "unused", "customer_service", "too_complex", "low_quality", "other"];
|
|
288
|
+
type CancellationFeedback = (typeof CANCELLATION_FEEDBACK)[number];
|
|
283
289
|
interface Subscription extends Resource<"subscription"> {
|
|
284
290
|
customerId: string;
|
|
285
291
|
planId: string;
|
|
@@ -292,6 +298,11 @@ interface Subscription extends Resource<"subscription"> {
|
|
|
292
298
|
trialEndsAt: Timestamp | null;
|
|
293
299
|
cancelAtPeriodEnd: boolean;
|
|
294
300
|
canceledAt: Timestamp | null;
|
|
301
|
+
/** What the customer said when canceling; `null` when they said nothing. */
|
|
302
|
+
cancellationDetails: {
|
|
303
|
+
feedback: CancellationFeedback | null;
|
|
304
|
+
comment: string | null;
|
|
305
|
+
} | null;
|
|
295
306
|
endedAt: Timestamp | null;
|
|
296
307
|
/** A plan or cycle change that takes effect on the next renewal. */
|
|
297
308
|
pendingChange: {
|
|
@@ -299,6 +310,14 @@ interface Subscription extends Resource<"subscription"> {
|
|
|
299
310
|
months: BillingMonths;
|
|
300
311
|
} | null;
|
|
301
312
|
renewal: SubscriptionRenewal | null;
|
|
313
|
+
/**
|
|
314
|
+
* The mandate renewals are charged with, when the first payment's method allows it; `null`
|
|
315
|
+
* when the customer pays each renewal by hand.
|
|
316
|
+
*/
|
|
317
|
+
autoCharge: {
|
|
318
|
+
method: string;
|
|
319
|
+
label: string;
|
|
320
|
+
} | null;
|
|
302
321
|
metadata: Metadata;
|
|
303
322
|
updatedAt: Timestamp;
|
|
304
323
|
}
|
|
@@ -361,8 +380,10 @@ interface PaymentLink extends Resource<"payment_link">, Retirement {
|
|
|
361
380
|
metadata: Metadata;
|
|
362
381
|
updatedAt: Timestamp;
|
|
363
382
|
}
|
|
364
|
-
|
|
365
|
-
|
|
383
|
+
/** One line of a checkout or a Cobro: what is paid, how many and for how much. */
|
|
384
|
+
interface LineItem {
|
|
385
|
+
/** `custom`: a line of a one-off Cobro, described by the business. */
|
|
386
|
+
type: "product" | "plan" | "custom";
|
|
366
387
|
productId: string | null;
|
|
367
388
|
variantId: string | null;
|
|
368
389
|
planId: string | null;
|
|
@@ -372,12 +393,16 @@ interface CheckoutItem {
|
|
|
372
393
|
unitAmount: number;
|
|
373
394
|
amount: number;
|
|
374
395
|
}
|
|
396
|
+
/** A checkout sells catalog items only. */
|
|
397
|
+
interface CheckoutItem extends LineItem {
|
|
398
|
+
type: "product" | "plan";
|
|
399
|
+
}
|
|
375
400
|
interface CustomerDetails {
|
|
376
401
|
name: string | null;
|
|
377
402
|
phone: string | null;
|
|
378
403
|
address: Address | null;
|
|
379
404
|
}
|
|
380
|
-
declare const CHECKOUT_PURPOSES: readonly ["product", "plan"
|
|
405
|
+
declare const CHECKOUT_PURPOSES: readonly ["product", "plan"];
|
|
381
406
|
type CheckoutPurpose = (typeof CHECKOUT_PURPOSES)[number];
|
|
382
407
|
interface Checkout extends Resource<"checkout"> {
|
|
383
408
|
url: string;
|
|
@@ -400,15 +425,58 @@ interface Checkout extends Resource<"checkout"> {
|
|
|
400
425
|
subscriptionId: string | null;
|
|
401
426
|
paymentLinkId: string | null;
|
|
402
427
|
paymentId: string | null;
|
|
428
|
+
/** The Cobro issued when it was paid, as the record of the sale. */
|
|
429
|
+
invoiceId: string | null;
|
|
403
430
|
collect: CollectSettings;
|
|
404
431
|
customFields: CustomField[];
|
|
405
432
|
customFieldValues: Record<string, string | number>;
|
|
406
433
|
customerDetails: CustomerDetails;
|
|
407
434
|
successUrl: string | null;
|
|
435
|
+
cancelUrl: string | null;
|
|
408
436
|
expiresAt: Timestamp;
|
|
409
437
|
completedAt: Timestamp | null;
|
|
410
438
|
metadata: Metadata;
|
|
411
439
|
}
|
|
440
|
+
declare const INVOICE_STATUSES: readonly ["open", "paid", "void", "uncollectible"];
|
|
441
|
+
type InvoiceStatus = (typeof INVOICE_STATUSES)[number];
|
|
442
|
+
/** `checkout`: the record of a paid checkout. `subscription_cycle`: a renewal. `manual`: one-off. */
|
|
443
|
+
declare const INVOICE_REASONS: readonly ["checkout", "subscription_cycle", "manual"];
|
|
444
|
+
type InvoiceReason = (typeof INVOICE_REASONS)[number];
|
|
445
|
+
/**
|
|
446
|
+
* A Cobro: what a customer owes and how it was paid, with its own payment page (`url`).
|
|
447
|
+
* Subscriptions issue one per renewal; businesses issue one-off ones; every paid checkout leaves
|
|
448
|
+
* one as the record of the sale. Not a fiscal invoice.
|
|
449
|
+
*/
|
|
450
|
+
interface Invoice extends Resource<"invoice"> {
|
|
451
|
+
/** Sequential per business and environment. */
|
|
452
|
+
number: string;
|
|
453
|
+
url: string;
|
|
454
|
+
reason: InvoiceReason;
|
|
455
|
+
/** `open` until paid. `void`: withdrawn. `uncollectible`: its deadline passed unpaid. */
|
|
456
|
+
status: InvoiceStatus;
|
|
457
|
+
customerId: string;
|
|
458
|
+
email: string;
|
|
459
|
+
subscriptionId: string | null;
|
|
460
|
+
checkoutId: string | null;
|
|
461
|
+
paymentId: string | null;
|
|
462
|
+
description: string | null;
|
|
463
|
+
lines: LineItem[];
|
|
464
|
+
currency: Currency;
|
|
465
|
+
subtotal: number;
|
|
466
|
+
discount: number;
|
|
467
|
+
tax: number;
|
|
468
|
+
total: number;
|
|
469
|
+
taxBehavior: TaxBehavior;
|
|
470
|
+
couponCode: string | null;
|
|
471
|
+
/** The subscription period a renewal pays for. */
|
|
472
|
+
periodStart: Timestamp | null;
|
|
473
|
+
periodEnd: Timestamp | null;
|
|
474
|
+
/** When it should be paid; past it a renewal enters its grace period. */
|
|
475
|
+
dueAt: Timestamp | null;
|
|
476
|
+
paidAt: Timestamp | null;
|
|
477
|
+
voidedAt: Timestamp | null;
|
|
478
|
+
metadata: Metadata;
|
|
479
|
+
}
|
|
412
480
|
declare const RISK_LEVELS: readonly ["normal", "elevated", "high"];
|
|
413
481
|
type RiskLevel = (typeof RISK_LEVELS)[number];
|
|
414
482
|
interface PaymentFailure {
|
|
@@ -439,7 +507,10 @@ interface PaymentSettlement {
|
|
|
439
507
|
net: number;
|
|
440
508
|
}
|
|
441
509
|
interface Payment extends Resource<"payment"> {
|
|
442
|
-
|
|
510
|
+
/** The checkout it paid, for purchases; `null` when it paid a Cobro directly. */
|
|
511
|
+
checkoutId: string | null;
|
|
512
|
+
/** Its Cobro: the one it paid, or the record a checkout issued when it completed. */
|
|
513
|
+
invoiceId: string | null;
|
|
443
514
|
customerId: string;
|
|
444
515
|
subscriptionId: string | null;
|
|
445
516
|
status: PaymentStatus;
|
|
@@ -527,6 +598,15 @@ interface CustomerSession {
|
|
|
527
598
|
customerId: string;
|
|
528
599
|
expiresAt: Timestamp;
|
|
529
600
|
}
|
|
601
|
+
/** A link to the customer portal: send the customer to `url` before `expiresAt`. */
|
|
602
|
+
interface PortalSession {
|
|
603
|
+
object: "portal_session";
|
|
604
|
+
url: string;
|
|
605
|
+
customerId: string;
|
|
606
|
+
/** Where the portal's "Volver" button leads; `null` hides it. */
|
|
607
|
+
returnUrl: string | null;
|
|
608
|
+
expiresAt: Timestamp;
|
|
609
|
+
}
|
|
530
610
|
//#endregion
|
|
531
611
|
//#region ../contracts/src/events.d.ts
|
|
532
612
|
interface EventDataMap {
|
|
@@ -541,6 +621,13 @@ interface EventDataMap {
|
|
|
541
621
|
"payment.failed": Payment;
|
|
542
622
|
"payment.refunded": Payment;
|
|
543
623
|
"refund.created": Refund;
|
|
624
|
+
/** The provider could not return the funds; the amount is back in the balance. */
|
|
625
|
+
"refund.failed": Refund;
|
|
626
|
+
"invoice.created": Invoice;
|
|
627
|
+
"invoice.paid": Invoice;
|
|
628
|
+
"invoice.voided": Invoice;
|
|
629
|
+
/** Its deadline passed unpaid (a renewal whose grace period ended). */
|
|
630
|
+
"invoice.uncollectible": Invoice;
|
|
544
631
|
"subscription.created": Subscription;
|
|
545
632
|
"subscription.updated": Subscription;
|
|
546
633
|
/** The renewal checkout is open; reminders start going out to the customer. */
|
|
@@ -553,7 +640,7 @@ interface EventDataMap {
|
|
|
553
640
|
"subscription.expired": Subscription;
|
|
554
641
|
}
|
|
555
642
|
type EventType = keyof EventDataMap;
|
|
556
|
-
declare const EVENT_TYPES: readonly ["product.retired", "product.updated", "payment_link.retired", "customer.created", "customer.updated", "checkout.completed", "checkout.expired", "payment.succeeded", "payment.failed", "payment.refunded", "refund.created", "subscription.created", "subscription.updated", "subscription.renewal_due", "subscription.renewed", "subscription.past_due", "subscription.canceled", "subscription.expired"];
|
|
643
|
+
declare const EVENT_TYPES: readonly ["product.retired", "product.updated", "payment_link.retired", "customer.created", "customer.updated", "checkout.completed", "checkout.expired", "payment.succeeded", "payment.failed", "payment.refunded", "refund.created", "refund.failed", "invoice.created", "invoice.paid", "invoice.voided", "invoice.uncollectible", "subscription.created", "subscription.updated", "subscription.renewal_due", "subscription.renewed", "subscription.past_due", "subscription.canceled", "subscription.expired"];
|
|
557
644
|
/** A delivered webhook, discriminated by `type` so `data` narrows automatically. */
|
|
558
645
|
type WebhookEvent = { [TType in EventType]: {
|
|
559
646
|
id: string;
|
|
@@ -564,4 +651,4 @@ type WebhookEvent = { [TType in EventType]: {
|
|
|
564
651
|
data: EventDataMap[TType];
|
|
565
652
|
}; }[EventType];
|
|
566
653
|
//#endregion
|
|
567
|
-
export {
|
|
654
|
+
export { RISK_LEVELS as $, INVOICE_REASONS as A, MOBILE_PREFIXES as At, PaymentFailure as B, Environment as Bt, Event as C, CURRENCIES as Ct, FeatureReset as D, List as Dt, Feature as E, GracePeriodDays as Et, LineItem as F, Timestamp as Ft, Plan as G, PaymentSettlement as H, tokenEnvironment as Ht, PAYMENT_STATUSES as I, isLandlinePhone as It, PortalSession as J, PlanFeatureValues as K, PRODUCT_CATEGORIES as L, isMobilePhone as Lt, Invoice as M, MobilePrefix as Mt, InvoiceReason as N, TAX_BEHAVIORS as Nt, FeatureType as O, ListQuery as Ot, InvoiceStatus as P, TaxBehavior as Pt, RESET_FREQUENCIES as Q, Payment as R, nationalPhone as Rt, CustomerSession as S, BillingMonths as St, FEATURE_TYPES as T, GRACE_PERIOD_DAYS as Tt, PaymentStatus as U, tokenPrefix as Ut, PaymentLink as V, TokenKind as Vt, Payout as W, ProductCategory as X, Product as Y, ProductVariant as Z, CurrencyAvailability as _, PAYMENT_FAILURE_CODES as _t, Actor as a, SUBSCRIPTION_STATUSES as at, CustomerDetails as b, AddressInput as bt, BalanceAmount as c, SubscriptionRenewal as ct, CancellationFeedback as d, WebhookEndpoint as dt, Refund as et, Checkout as f, Weekday as ft, Coupon as g, ApiErrorType as gt, CollectSettings as h, ApiErrorEnvelope as ht, WebhookEvent as i, SUBMIT_LABELS as it, INVOICE_STATUSES as j, Metadata as jt, FeatureUsageResult as k, MAX_QUANTITY as kt, CANCELLATION_FEEDBACK as l, SubscriptionStatus as lt, CheckoutPurpose as m, ApiErrorBody as mt, EventDataMap as n, Retirement as nt, AfterCompletion as o, SubmitLabel as ot, CheckoutItem as p, API_ERROR_TYPES as pt, PlanPrice as q, EventType as r, RiskLevel as rt, Balance as s, Subscription as st, EVENT_TYPES as t, ResetFrequency as tt, CHECKOUT_PURPOSES as u, USAGE_FEATURE_TYPES as ut, CustomField as v, PaymentFailureCode as vt, ExchangeRate as w, Currency as wt, CustomerFeature as x, BILLING_MONTHS as xt, Customer as y, Address as yt, PaymentAttempt as z, ENVIRONMENTS as zt };
|
|
@@ -18,7 +18,7 @@ var BilleteError = class extends Error {
|
|
|
18
18
|
};
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/http.ts
|
|
21
|
-
const SDK_VERSION = "0.
|
|
21
|
+
const SDK_VERSION = "0.7.0";
|
|
22
22
|
const DEFAULT_BASE_URL = "https://api.billete.run";
|
|
23
23
|
const RETRYABLE_STATUS = /* @__PURE__ */ new Set([
|
|
24
24
|
429,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { A as
|
|
1
|
+
import { $ as RISK_LEVELS, A as INVOICE_REASONS, At as MOBILE_PREFIXES, B as PaymentFailure, Bt as Environment, C as Event, Ct as CURRENCIES, D as FeatureReset, Dt as List, E as Feature, Et as GracePeriodDays, F as LineItem, Ft as Timestamp, G as Plan, H as PaymentSettlement, Ht as tokenEnvironment, I as PAYMENT_STATUSES, It as isLandlinePhone, J as PortalSession, K as PlanFeatureValues, L as PRODUCT_CATEGORIES, Lt as isMobilePhone, M as Invoice, Mt as MobilePrefix, N as InvoiceReason, Nt as TAX_BEHAVIORS, O as FeatureType, Ot as ListQuery, P as InvoiceStatus, Pt as TaxBehavior, Q as RESET_FREQUENCIES, R as Payment, Rt as nationalPhone, S as CustomerSession, St as BillingMonths, T as FEATURE_TYPES, Tt as GRACE_PERIOD_DAYS, U as PaymentStatus, Ut as tokenPrefix, V as PaymentLink, Vt as TokenKind, W as Payout, X as ProductCategory, Y as Product, Z as ProductVariant, _ as CurrencyAvailability, _t as PAYMENT_FAILURE_CODES, a as Actor, at as SUBSCRIPTION_STATUSES, b as CustomerDetails, bt as AddressInput, c as BalanceAmount, ct as SubscriptionRenewal, d as CancellationFeedback, dt as WebhookEndpoint, et as Refund, f as Checkout, ft as Weekday, g as Coupon, gt as ApiErrorType, h as CollectSettings, ht as ApiErrorEnvelope, i as WebhookEvent, it as SUBMIT_LABELS, j as INVOICE_STATUSES, jt as Metadata, k as FeatureUsageResult, kt as MAX_QUANTITY, l as CANCELLATION_FEEDBACK, lt as SubscriptionStatus, m as CheckoutPurpose, mt as ApiErrorBody, n as EventDataMap, nt as Retirement, o as AfterCompletion, ot as SubmitLabel, p as CheckoutItem, pt as API_ERROR_TYPES, q as PlanPrice, r as EventType, rt as RiskLevel, s as Balance, st as Subscription, t as EVENT_TYPES, tt as ResetFrequency, u as CHECKOUT_PURPOSES, ut as USAGE_FEATURE_TYPES, v as CustomField, vt as PaymentFailureCode, w as ExchangeRate, wt as Currency, x as CustomerFeature, xt as BILLING_MONTHS, y as Customer, yt as Address, z as PaymentAttempt, zt as ENVIRONMENTS } from "./events-D_VB-i7R.js";
|
|
2
|
+
import { $ as PaymentTestScenario, A as PlanCreate, B as RefundCreate, C as FeatureUpdate, D as PaymentLinkCreate, E as KEY_PATTERN, F as PortalSessionCreate, G as VariantInput, H as SubscriptionCancel, I as ProductCheckoutCreate, J as CustomerSubscription, K as WebhookEndpointCreate, L as ProductCreate, M as PlanLinkCreate, N as PlanPriceInput, O as PaymentLinkUpdate, P as PlanUpdate, Q as PaymentNextAction, R as ProductLinkCreate, S as FeatureCreate, T as InvoiceLineInput, U as SubscriptionCreate, V as RetireInput, W as SubscriptionUpdate, X as PaymentMethodField, Y as PaymentInstructions, Z as PaymentMethodOption, _ as CustomerCreate, a as CheckoutCreate, at as PublicPortal, b as CustomerUpdate, c as ClientCheckoutUpdate, d as ClientSubscriptionCancel, et as PortalFeatures, f as ClientSubscriptionUpdate, g as CustomFieldInput, h as CouponUpdate, i as AfterCompletionInput, it as PublicPaymentState, j as PlanFeaturesInput, k as PlanCheckoutCreate, l as ClientInvoicePay, m as CouponCreate, n as RequestOptions, nt as PublicInvoice, o as CheckoutItemInput, p as CollectInput, q as WebhookEndpointUpdate, r as TransportOptions, rt as PublicPaymentLink, s as ClientCheckoutPay, t as BilleteError, tt as PublicCheckout, u as ClientLinkCheckout, v as CustomerInput, w as InvoiceCreate, x as EventSelector, y as CustomerSessionCreate, z as ProductUpdate } from "./errors-f5Ne3UQC.js";
|
|
3
3
|
import { WebhookVerificationError, verifyWebhook } from "./webhooks.js";
|
|
4
4
|
//#region src/server.d.ts
|
|
5
5
|
type Filters<T> = ListQuery & T;
|
|
@@ -29,16 +29,21 @@ export declare function createBillete(options: BilleteOptions): {
|
|
|
29
29
|
update: (id: string, input: CustomerUpdate, options?: RequestOptions) => Promise<Customer>;
|
|
30
30
|
list: (query?: Filters<{
|
|
31
31
|
email?: string;
|
|
32
|
+
search?: string;
|
|
32
33
|
}>, options?: RequestOptions) => Promise<List<Customer>>;
|
|
33
34
|
/** Iterates every item across pages: `for await (const item of iterate())`. */
|
|
34
35
|
iterate: (query?: Filters<{
|
|
35
36
|
email?: string;
|
|
37
|
+
search?: string;
|
|
36
38
|
}>) => AsyncGenerator<Customer, any, any>;
|
|
37
39
|
};
|
|
38
40
|
customerSessions: {
|
|
39
41
|
/** Short-lived token for the client SDK to read one customer's billing state. */
|
|
40
42
|
create: (input: CustomerSessionCreate, options?: RequestOptions) => Promise<CustomerSession>;
|
|
41
43
|
};
|
|
44
|
+
portalSessions: {
|
|
45
|
+
create: (input: PortalSessionCreate, options?: RequestOptions) => Promise<PortalSession>;
|
|
46
|
+
};
|
|
42
47
|
products: {
|
|
43
48
|
create: (input: ProductCreate, options?: RequestOptions) => Promise<Product>;
|
|
44
49
|
retrieve: (id: string, options?: RequestOptions) => Promise<Product>;
|
|
@@ -118,6 +123,22 @@ export declare function createBillete(options: BilleteOptions): {
|
|
|
118
123
|
}>) => AsyncGenerator<PaymentLink, any, any>;
|
|
119
124
|
retire: (id: string, input?: RetireInput, options?: RequestOptions) => Promise<PaymentLink>;
|
|
120
125
|
};
|
|
126
|
+
invoices: {
|
|
127
|
+
create: (input: InvoiceCreate, options?: RequestOptions) => Promise<Invoice>;
|
|
128
|
+
retrieve: (id: string, options?: RequestOptions) => Promise<Invoice>;
|
|
129
|
+
list: (query?: Filters<{
|
|
130
|
+
customer?: string;
|
|
131
|
+
subscription?: string;
|
|
132
|
+
status?: InvoiceStatus;
|
|
133
|
+
}>, options?: RequestOptions) => Promise<List<Invoice>>;
|
|
134
|
+
iterate: (query?: Filters<{
|
|
135
|
+
customer?: string;
|
|
136
|
+
subscription?: string;
|
|
137
|
+
status?: InvoiceStatus;
|
|
138
|
+
}>) => AsyncGenerator<Invoice, any, any>;
|
|
139
|
+
/** Withdraws an open one-off Cobro; a renewal's is withdrawn by canceling its subscription. */
|
|
140
|
+
void: (id: string, options?: RequestOptions) => Promise<Invoice>;
|
|
141
|
+
};
|
|
121
142
|
subscriptions: {
|
|
122
143
|
create: (input: SubscriptionCreate, options?: RequestOptions) => Promise<Subscription>;
|
|
123
144
|
retrieve: (id: string, options?: RequestOptions) => Promise<Subscription>;
|
|
@@ -194,4 +215,4 @@ export declare function createBillete(options: BilleteOptions): {
|
|
|
194
215
|
/** The server client: what `createBillete` returns. */
|
|
195
216
|
type Billete = ReturnType<typeof createBillete>;
|
|
196
217
|
//#endregion
|
|
197
|
-
export { type API_ERROR_TYPES, type Actor, type Address, type AddressInput, type AfterCompletion, type AfterCompletionInput, type ApiErrorBody, type ApiErrorEnvelope, type ApiErrorType, type BILLING_MONTHS, type Balance, type BalanceAmount, type Billete, BilleteError, type BilleteOptions, type BillingMonths, type CHECKOUT_PURPOSES, type CURRENCIES, type Checkout, type CheckoutCreate, type CheckoutItem, type CheckoutItemInput, type
|
|
218
|
+
export { type API_ERROR_TYPES, type Actor, type Address, type AddressInput, type AfterCompletion, type AfterCompletionInput, type ApiErrorBody, type ApiErrorEnvelope, type ApiErrorType, type BILLING_MONTHS, type Balance, type BalanceAmount, type Billete, BilleteError, type BilleteOptions, type BillingMonths, type CANCELLATION_FEEDBACK, type CHECKOUT_PURPOSES, type CURRENCIES, type CancellationFeedback, type Checkout, type CheckoutCreate, type CheckoutItem, type CheckoutItemInput, type CheckoutPurpose, type ClientCheckoutPay, type ClientCheckoutUpdate, type ClientInvoicePay, type ClientLinkCheckout, type ClientSubscriptionCancel, type ClientSubscriptionUpdate, type CollectInput, type CollectSettings, type Coupon, type CouponCreate, type CouponUpdate, type Currency, type CurrencyAvailability, type CustomField, type CustomFieldInput, type Customer, type CustomerCreate, type CustomerDetails, type CustomerFeature, type CustomerInput, type CustomerSession, type CustomerSessionCreate, type CustomerSubscription, type CustomerUpdate, type ENVIRONMENTS, type EVENT_TYPES, type Environment, type Event, type EventDataMap, type EventSelector, type EventType, type ExchangeRate, type FEATURE_TYPES, type Feature, type FeatureCreate, type FeatureReset, type FeatureType, type FeatureUpdate, type FeatureUsageResult, type GRACE_PERIOD_DAYS, type GracePeriodDays, type INVOICE_REASONS, type INVOICE_STATUSES, type Invoice, type InvoiceCreate, type InvoiceLineInput, type InvoiceReason, type InvoiceStatus, type KEY_PATTERN, type LineItem, type List, type ListQuery, type MAX_QUANTITY, type MOBILE_PREFIXES, type Metadata, type MobilePrefix, type PAYMENT_FAILURE_CODES, type PAYMENT_STATUSES, type PRODUCT_CATEGORIES, type Payment, type PaymentAttempt, type PaymentFailure, type PaymentFailureCode, type PaymentInstructions, type PaymentLink, type PaymentLinkCreate, type PaymentLinkUpdate, type PaymentMethodField, type PaymentMethodOption, type PaymentNextAction, type PaymentSettlement, type PaymentStatus, type PaymentTestScenario, type Payout, type Plan, type PlanCheckoutCreate, type PlanCreate, type PlanFeatureValues, type PlanFeaturesInput, type PlanLinkCreate, type PlanPrice, type PlanPriceInput, type PlanUpdate, type PortalFeatures, type PortalSession, type PortalSessionCreate, type Product, type ProductCategory, type ProductCheckoutCreate, type ProductCreate, type ProductLinkCreate, type ProductUpdate, type ProductVariant, type PublicCheckout, type PublicInvoice, type PublicPaymentLink, type PublicPaymentState, type PublicPortal, type RESET_FREQUENCIES, type RISK_LEVELS, type Refund, type RefundCreate, type RequestOptions, type ResetFrequency, type RetireInput, type Retirement, type RiskLevel, type SUBMIT_LABELS, type SUBSCRIPTION_STATUSES, type SubmitLabel, type Subscription, type SubscriptionCancel, type SubscriptionCreate, type SubscriptionRenewal, type SubscriptionStatus, type SubscriptionUpdate, type TAX_BEHAVIORS, type TaxBehavior, type Timestamp, type TokenKind, type TransportOptions, type USAGE_FEATURE_TYPES, type VariantInput, type WebhookEndpoint, type WebhookEndpointCreate, type WebhookEndpointUpdate, type WebhookEvent, WebhookVerificationError, type Weekday, type isLandlinePhone, type isMobilePhone, type nationalPhone, type tokenEnvironment, type tokenPrefix, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as segment, r as BilleteError, t as createTransport } from "./http-
|
|
1
|
+
import { n as segment, r as BilleteError, t as createTransport } from "./http-8zfGyXd_.js";
|
|
2
2
|
import { WebhookVerificationError, verifyWebhook } from "./webhooks.js";
|
|
3
3
|
//#region ../contracts/src/environment.ts
|
|
4
4
|
/**
|
|
@@ -88,6 +88,13 @@ create: (input, options) => http.request({
|
|
|
88
88
|
body: input,
|
|
89
89
|
options
|
|
90
90
|
}) };
|
|
91
|
+
/** Links to the hosted customer portal, where a customer manages subscriptions and Cobros. */
|
|
92
|
+
const portalSessions = { create: (input, options) => http.request({
|
|
93
|
+
method: "POST",
|
|
94
|
+
path: "/v1/portal-sessions",
|
|
95
|
+
body: input,
|
|
96
|
+
options
|
|
97
|
+
}) };
|
|
91
98
|
const products = {
|
|
92
99
|
...collection(http, "/v1/products"),
|
|
93
100
|
retire: (id, input = {}, options) => http.request({
|
|
@@ -172,6 +179,20 @@ create: (input, options) => http.request({
|
|
|
172
179
|
options
|
|
173
180
|
})
|
|
174
181
|
};
|
|
182
|
+
const invoiceCrud = collection(http, "/v1/invoices");
|
|
183
|
+
/** Cobros: what a customer owes and pays from its page (`url`), one-off or per renewal. */
|
|
184
|
+
const invoices = {
|
|
185
|
+
create: invoiceCrud.create,
|
|
186
|
+
retrieve: invoiceCrud.retrieve,
|
|
187
|
+
list: invoiceCrud.list,
|
|
188
|
+
iterate: invoiceCrud.iterate,
|
|
189
|
+
/** Withdraws an open one-off Cobro; a renewal's is withdrawn by canceling its subscription. */
|
|
190
|
+
void: (id, options) => http.request({
|
|
191
|
+
method: "POST",
|
|
192
|
+
path: `/v1/invoices/${segment(id)}/void`,
|
|
193
|
+
options
|
|
194
|
+
})
|
|
195
|
+
};
|
|
175
196
|
const subscriptions = {
|
|
176
197
|
...collection(http, "/v1/subscriptions"),
|
|
177
198
|
/** Cancels at period end by default; pass `{ atPeriodEnd: false }` to end it now. */
|
|
@@ -227,12 +248,14 @@ create: (input, options) => http.request({
|
|
|
227
248
|
return {
|
|
228
249
|
customers,
|
|
229
250
|
customerSessions,
|
|
251
|
+
portalSessions,
|
|
230
252
|
products,
|
|
231
253
|
plans,
|
|
232
254
|
features,
|
|
233
255
|
coupons,
|
|
234
256
|
checkouts,
|
|
235
257
|
paymentLinks,
|
|
258
|
+
invoices,
|
|
236
259
|
subscriptions,
|
|
237
260
|
payments,
|
|
238
261
|
balance,
|
package/dist/webhooks.d.ts
CHANGED