@boelabs/billete-sdk 0.4.0 → 0.6.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 CHANGED
@@ -109,12 +109,14 @@ Todos los métodos devuelven promesas con el recurso tipado. Los recursos con li
109
109
  | --- | --- |
110
110
  | `customers` | — |
111
111
  | `customerSessions` | `create` |
112
+ | `portalSessions` | `create` (enlace al portal del cliente, válido 60 minutos) |
112
113
  | `products` | `retire`, `retireVariant` |
113
114
  | `plans` | — |
114
115
  | `features` | `check`, `isEnabled`, `listForCustomer`, `consume`, `release`, `set` |
115
116
  | `coupons` | — |
116
117
  | `checkouts` | `expire` |
117
118
  | `paymentLinks` | `retire` |
119
+ | `invoices` | `void` (cobros: renovaciones y cobros sueltos, con página de pago en `url`) |
118
120
  | `subscriptions` | `cancel`, `resume` |
119
121
  | `payments` | `refund`, `listRefunds` |
120
122
  | `payouts` | — |
@@ -231,8 +233,18 @@ const { data: subscriptions } = await billete.customer.subscriptions();
231
233
  const tokens = await billete.customer.feature("tokens");
232
234
  ```
233
235
 
236
+ Para no construir esa pantalla, envía a tu cliente al portal alojado:
237
+
238
+ ```ts
239
+ const portal = await billete.portalSessions.create({
240
+ customer: "user_123",
241
+ returnUrl: "https://tuapp.com/cuenta",
242
+ });
243
+ // Redirige a portal.url: allí ve sus suscripciones y cobros, cambia su ciclo o cancela.
244
+ ```
245
+
234
246
  `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.
247
+ cliente puede leer y pagar checkouts, cobros y links de pago, y consultar tasas y monedas.
236
248
 
237
249
  ## Webhooks
238
250
 
package/dist/client.d.ts CHANGED
@@ -1,15 +1,16 @@
1
- import { $ as SubscriptionRenewal, A as Payment, At as ENVIRONMENTS, B as Product, C as FEATURE_TYPES, Ct as MobilePrefix, D as FeatureUsageResult, Dt as isLandlinePhone, E as FeatureType, Et as Timestamp, F as PaymentStatus, G as Refund, H as ProductVariant, I as Payout, J as RiskLevel, K as ResetFrequency, L as Plan, M as PaymentFailure, Mt as TokenKind, N as PaymentLink, Nt as tokenEnvironment, O as PAYMENT_STATUSES, Ot as isMobilePhone, P as PaymentSettlement, Pt as tokenPrefix, Q as Subscription, R as PlanFeatureValues, S as ExchangeRate, St as Metadata, T as FeatureReset, Tt as TaxBehavior, U as RESET_FREQUENCIES, V as ProductCategory, W as RISK_LEVELS, X as SUBSCRIPTION_STATUSES, Y as SUBMIT_LABELS, Z as SubmitLabel, _ as Customer, _t as GracePeriodDays, a as Actor, at as ApiErrorBody, b as CustomerSession, bt as MAX_QUANTITY, c as BalanceAmount, ct as PAYMENT_FAILURE_CODES, d as CheckoutItem, dt as AddressInput, et as SubscriptionStatus, f as CheckoutPurpose, ft as BILLING_MONTHS, g as CustomField, gt as GRACE_PERIOD_DAYS, h as CurrencyAvailability, ht as Currency, i as WebhookEvent, it as API_ERROR_TYPES, j as PaymentAttempt, jt as Environment, k as PRODUCT_CATEGORIES, kt as nationalPhone, l as CHECKOUT_PURPOSES, lt as PaymentFailureCode, m as Coupon, mt as CURRENCIES, n as EventDataMap, nt as WebhookEndpoint, o as AfterCompletion, ot as ApiErrorEnvelope, p as CollectSettings, pt as BillingMonths, q as Retirement, r as EventType, rt as Weekday, s as Balance, st as ApiErrorType, t as EVENT_TYPES, tt as USAGE_FEATURE_TYPES, u as Checkout, ut as Address, v as CustomerDetails, vt as List, w as Feature, wt as TAX_BEHAVIORS, x as Event, xt as MOBILE_PREFIXES, y as CustomerFeature, yt as ListQuery, z as PlanPrice } from "./events-oZ08-Zz2.js";
2
- import { A as ProductCheckoutCreate, B as WebhookEndpointCreate, C as PaymentLinkUpdate, D as PlanLinkCreate, E as PlanFeaturesInput, F as RetireInput, G as PaymentTestScenario, H as CheckoutPaymentMethod, I as SubscriptionCancel, K as PublicCheckout, L as SubscriptionCreate, M as ProductLinkCreate, N as ProductUpdate, O as PlanPriceInput, P as RefundCreate, R as SubscriptionUpdate, S as PaymentLinkCreate, T as PlanCreate, U as PaymentInstructions, V as WebhookEndpointUpdate, W as PaymentMethodField, _ as CustomerUpdate, a as CheckoutCreate, b as FeatureUpdate, c as ClientCheckoutUpdate, d as CouponCreate, f as CouponUpdate, g as CustomerSessionCreate, h as CustomerInput, i as AfterCompletionInput, j as ProductCreate, k as PlanUpdate, l as ClientLinkCheckout, m as CustomerCreate, n as RequestOptions, o as CheckoutItemInput, p as CustomFieldInput, q as PublicPaymentLink, r as TransportOptions, s as ClientCheckoutPay, t as BilleteError, u as CollectInput, v as EventSelector, w as PlanCheckoutCreate, x as KEY_PATTERN, y as FeatureCreate, z as VariantInput } from "./errors-gwEcSkzi.js";
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-DjO9ARae.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-BzzXE5C2.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 unguessable ID
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<CheckoutPaymentMethod>>;
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 payment link. */
46
- subscriptions: (options?: RequestOptions) => Promise<List<Subscription>>;
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 CheckoutPaymentMethod, type CheckoutPurpose, type ClientCheckoutPay, type ClientCheckoutUpdate, type ClientLinkCheckout, type ClientOptions, 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 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 KEY_PATTERN, 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 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 Product, type ProductCategory, type ProductCheckoutCreate, type ProductCreate, type ProductLinkCreate, type ProductUpdate, type ProductVariant, type PublicCheckout, type PublicPaymentLink, 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 };
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-B5DzcQK9.js";
1
+ import { n as segment, r as BilleteError, t as createTransport } from "./http-Q-RXDFbe.js";
2
2
  //#region src/create-client.ts
3
3
  /**
4
- * Browser client. It never holds a secret key: checkouts are addressed by their unguessable ID
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 payment link. */
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 Timestamp, F as PaymentStatus, M as PaymentFailure, St as Metadata, T as FeatureReset, Tt as TaxBehavior, V as ProductCategory, Z as SubmitLabel, _t as GracePeriodDays, at as ApiErrorBody, d as CheckoutItem, dt as AddressInput, f as CheckoutPurpose, g as CustomField, ht as Currency, jt as Environment, o as AfterCompletion, p as CollectSettings, pt as BillingMonths, r as EventType, st as ApiErrorType, v as CustomerDetails, z as PlanPrice } from "./events-oZ08-Zz2.js";
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-DjO9ARae.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;
@@ -27,6 +113,16 @@ interface PublicCheckout {
27
113
  adjustableQuantity: boolean;
28
114
  /** Most units the customer can choose right now: the link's limit, capped by stock. */
29
115
  maxQuantity: number;
116
+ /**
117
+ * Variants the customer may switch between for a product checkout. `maxQuantity` is the most
118
+ * units of that variant one purchase can take right now; `0` means it is sold out.
119
+ */
120
+ variants: Array<{
121
+ id: string;
122
+ name: string;
123
+ amount: number;
124
+ maxQuantity: number;
125
+ }> | null;
30
126
  /** Billing cycles the customer may switch between for a plan checkout. */
31
127
  cycles: Array<{
32
128
  months: BillingMonths;
@@ -39,13 +135,28 @@ interface PublicCheckout {
39
135
  afterCompletion: AfterCompletion;
40
136
  successUrl: string | null;
41
137
  expiresAt: Timestamp;
42
- payment: {
43
- id: string;
44
- status: PaymentStatus;
45
- method: string | null;
46
- failure: PaymentFailure | null;
47
- } | null;
138
+ payment: PublicPaymentState | null;
48
139
  }
140
+ /**
141
+ * The step a provider asks of the payer after starting a charge: leave for its page and come back
142
+ * (`redirect`), or send the funds to what is shown, often as a QR code (`display`).
143
+ */
144
+ type PaymentNextAction = {
145
+ type: "redirect";
146
+ url: string;
147
+ } | {
148
+ type: "display";
149
+ /** What the value is: "Dirección USDT (TRC20)", "Código de pago". */
150
+ label: string;
151
+ /** Where to send the funds: a wallet address, a payment code. */
152
+ value: string;
153
+ /** Encoded in a QR code for the payer's app to scan, when the provider offers one. */
154
+ qr: string | null;
155
+ amount: number;
156
+ currency: Currency;
157
+ /** After this the payer must not send funds: the attempt fails if nothing arrived. */
158
+ expiresAt: Timestamp | null;
159
+ };
49
160
  interface PaymentMethodField {
50
161
  key: string;
51
162
  label: string;
@@ -76,7 +187,7 @@ interface PaymentTestScenario {
76
187
  description: string;
77
188
  fields: Record<string, string>;
78
189
  }
79
- interface CheckoutPaymentMethod {
190
+ interface PaymentMethodOption {
80
191
  id: string;
81
192
  name: string;
82
193
  description: string | null;
@@ -281,6 +392,13 @@ interface SubscriptionUpdate {
281
392
  interface SubscriptionCancel {
282
393
  /** `false` ends the subscription immediately. */
283
394
  atPeriodEnd?: boolean;
395
+ feedback?: CancellationFeedback;
396
+ comment?: string;
397
+ }
398
+ /** Canceling from the portal always waits for the period's end. */
399
+ interface ClientSubscriptionCancel {
400
+ feedback?: CancellationFeedback;
401
+ comment?: string;
284
402
  }
285
403
  /** Exactly one of `percentOff` and `amountOff`; `amountOff` needs a `currency`. */
286
404
  interface CouponCreate {
@@ -375,6 +493,28 @@ interface PlanCheckoutCreate extends CheckoutFields {
375
493
  months: BillingMonths;
376
494
  }
377
495
  type CheckoutCreate = ProductCheckoutCreate | PlanCheckoutCreate;
496
+ interface InvoiceLineInput {
497
+ description: string;
498
+ quantity?: number;
499
+ /** Per unit, in minor units. */
500
+ unitAmount: number;
501
+ }
502
+ /** A one-off Cobro for a customer, payable from its page (`url`). */
503
+ interface InvoiceCreate {
504
+ customer: CustomerInput;
505
+ currency: Currency;
506
+ lines: InvoiceLineInput[];
507
+ /** Defaults to the business's tax behavior for new prices (`inclusive`). */
508
+ taxBehavior?: TaxBehavior;
509
+ /** Days to pay it; without it the Cobro has no due date. */
510
+ daysUntilDue?: number;
511
+ description?: string;
512
+ metadata?: Metadata;
513
+ }
514
+ interface ClientInvoicePay {
515
+ method: string;
516
+ fields?: Record<string, string>;
517
+ }
378
518
  interface ClientLinkCheckout {
379
519
  variant?: string;
380
520
  quantity?: number;
@@ -401,6 +541,15 @@ interface CustomerSessionCreate {
401
541
  customer: string;
402
542
  expiresInMinutes?: number;
403
543
  }
544
+ interface PortalSessionCreate {
545
+ /** A `cus_…` ID or your own `externalId`. */
546
+ customer: string;
547
+ returnUrl?: string;
548
+ }
549
+ /** The cycle a customer switches to from the portal; it applies from the next renewal. */
550
+ interface ClientSubscriptionUpdate {
551
+ months: BillingMonths;
552
+ }
404
553
  interface ClientCheckoutUpdate {
405
554
  quantity?: number;
406
555
  variant?: string;
@@ -449,4 +598,4 @@ declare class BilleteError extends Error {
449
598
  }, status: number);
450
599
  }
451
600
  //#endregion
452
- export { ProductCheckoutCreate as A, WebhookEndpointCreate as B, PaymentLinkUpdate as C, PlanLinkCreate as D, PlanFeaturesInput as E, RetireInput as F, PaymentTestScenario as G, CheckoutPaymentMethod as H, SubscriptionCancel as I, PublicCheckout as K, SubscriptionCreate as L, ProductLinkCreate as M, ProductUpdate as N, PlanPriceInput as O, RefundCreate as P, SubscriptionUpdate as R, PaymentLinkCreate as S, PlanCreate as T, PaymentInstructions as U, WebhookEndpointUpdate as V, PaymentMethodField as W, CustomerUpdate as _, CheckoutCreate as a, FeatureUpdate as b, ClientCheckoutUpdate as c, CouponCreate as d, CouponUpdate as f, CustomerSessionCreate as g, CustomerInput as h, AfterCompletionInput as i, ProductCreate as j, PlanUpdate as k, ClientLinkCheckout as l, CustomerCreate as m, RequestOptions as n, CheckoutItemInput as o, CustomFieldInput as p, PublicPaymentLink as q, TransportOptions as r, ClientCheckoutPay as s, BilleteError as t, CollectInput as u, EventSelector as v, PlanCheckoutCreate as w, KEY_PATTERN as x, FeatureCreate as y, VariantInput as z };
601
+ 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
- checkoutId: string | null;
281
- checkoutUrl: string | null;
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
- interface CheckoutItem {
365
- type: "product" | "plan";
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", "renewal"];
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,6 +425,8 @@ 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>;
@@ -409,6 +436,46 @@ interface Checkout extends Resource<"checkout"> {
409
436
  completedAt: Timestamp | null;
410
437
  metadata: Metadata;
411
438
  }
439
+ declare const INVOICE_STATUSES: readonly ["open", "paid", "void", "uncollectible"];
440
+ type InvoiceStatus = (typeof INVOICE_STATUSES)[number];
441
+ /** `checkout`: the record of a paid checkout. `subscription_cycle`: a renewal. `manual`: one-off. */
442
+ declare const INVOICE_REASONS: readonly ["checkout", "subscription_cycle", "manual"];
443
+ type InvoiceReason = (typeof INVOICE_REASONS)[number];
444
+ /**
445
+ * A Cobro: what a customer owes and how it was paid, with its own payment page (`url`).
446
+ * Subscriptions issue one per renewal; businesses issue one-off ones; every paid checkout leaves
447
+ * one as the record of the sale. Not a fiscal invoice.
448
+ */
449
+ interface Invoice extends Resource<"invoice"> {
450
+ /** Sequential per business and environment. */
451
+ number: string;
452
+ url: string;
453
+ reason: InvoiceReason;
454
+ /** `open` until paid. `void`: withdrawn. `uncollectible`: its deadline passed unpaid. */
455
+ status: InvoiceStatus;
456
+ customerId: string;
457
+ email: string;
458
+ subscriptionId: string | null;
459
+ checkoutId: string | null;
460
+ paymentId: string | null;
461
+ description: string | null;
462
+ lines: LineItem[];
463
+ currency: Currency;
464
+ subtotal: number;
465
+ discount: number;
466
+ tax: number;
467
+ total: number;
468
+ taxBehavior: TaxBehavior;
469
+ couponCode: string | null;
470
+ /** The subscription period a renewal pays for. */
471
+ periodStart: Timestamp | null;
472
+ periodEnd: Timestamp | null;
473
+ /** When it should be paid; past it a renewal enters its grace period. */
474
+ dueAt: Timestamp | null;
475
+ paidAt: Timestamp | null;
476
+ voidedAt: Timestamp | null;
477
+ metadata: Metadata;
478
+ }
412
479
  declare const RISK_LEVELS: readonly ["normal", "elevated", "high"];
413
480
  type RiskLevel = (typeof RISK_LEVELS)[number];
414
481
  interface PaymentFailure {
@@ -439,7 +506,10 @@ interface PaymentSettlement {
439
506
  net: number;
440
507
  }
441
508
  interface Payment extends Resource<"payment"> {
442
- checkoutId: string;
509
+ /** The checkout it paid, for purchases; `null` when it paid a Cobro directly. */
510
+ checkoutId: string | null;
511
+ /** Its Cobro: the one it paid, or the record a checkout issued when it completed. */
512
+ invoiceId: string | null;
443
513
  customerId: string;
444
514
  subscriptionId: string | null;
445
515
  status: PaymentStatus;
@@ -527,6 +597,15 @@ interface CustomerSession {
527
597
  customerId: string;
528
598
  expiresAt: Timestamp;
529
599
  }
600
+ /** A link to the customer portal: send the customer to `url` before `expiresAt`. */
601
+ interface PortalSession {
602
+ object: "portal_session";
603
+ url: string;
604
+ customerId: string;
605
+ /** Where the portal's "Volver" button leads; `null` hides it. */
606
+ returnUrl: string | null;
607
+ expiresAt: Timestamp;
608
+ }
530
609
  //#endregion
531
610
  //#region ../contracts/src/events.d.ts
532
611
  interface EventDataMap {
@@ -541,6 +620,13 @@ interface EventDataMap {
541
620
  "payment.failed": Payment;
542
621
  "payment.refunded": Payment;
543
622
  "refund.created": Refund;
623
+ /** The provider could not return the funds; the amount is back in the balance. */
624
+ "refund.failed": Refund;
625
+ "invoice.created": Invoice;
626
+ "invoice.paid": Invoice;
627
+ "invoice.voided": Invoice;
628
+ /** Its deadline passed unpaid (a renewal whose grace period ended). */
629
+ "invoice.uncollectible": Invoice;
544
630
  "subscription.created": Subscription;
545
631
  "subscription.updated": Subscription;
546
632
  /** The renewal checkout is open; reminders start going out to the customer. */
@@ -553,7 +639,7 @@ interface EventDataMap {
553
639
  "subscription.expired": Subscription;
554
640
  }
555
641
  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"];
642
+ 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
643
  /** A delivered webhook, discriminated by `type` so `data` narrows automatically. */
558
644
  type WebhookEvent = { [TType in EventType]: {
559
645
  id: string;
@@ -564,4 +650,4 @@ type WebhookEvent = { [TType in EventType]: {
564
650
  data: EventDataMap[TType];
565
651
  }; }[EventType];
566
652
  //#endregion
567
- export { SubscriptionRenewal as $, Payment as A, ENVIRONMENTS as At, Product as B, FEATURE_TYPES as C, MobilePrefix as Ct, FeatureUsageResult as D, isLandlinePhone as Dt, FeatureType as E, Timestamp as Et, PaymentStatus as F, Refund as G, ProductVariant as H, Payout as I, RiskLevel as J, ResetFrequency as K, Plan as L, PaymentFailure as M, TokenKind as Mt, PaymentLink as N, tokenEnvironment as Nt, PAYMENT_STATUSES as O, isMobilePhone as Ot, PaymentSettlement as P, tokenPrefix as Pt, Subscription as Q, PlanFeatureValues as R, ExchangeRate as S, Metadata as St, FeatureReset as T, TaxBehavior as Tt, RESET_FREQUENCIES as U, ProductCategory as V, RISK_LEVELS as W, SUBSCRIPTION_STATUSES as X, SUBMIT_LABELS as Y, SubmitLabel as Z, Customer as _, GracePeriodDays as _t, Actor as a, ApiErrorBody as at, CustomerSession as b, MAX_QUANTITY as bt, BalanceAmount as c, PAYMENT_FAILURE_CODES as ct, CheckoutItem as d, AddressInput as dt, SubscriptionStatus as et, CheckoutPurpose as f, BILLING_MONTHS as ft, CustomField as g, GRACE_PERIOD_DAYS as gt, CurrencyAvailability as h, Currency as ht, WebhookEvent as i, API_ERROR_TYPES as it, PaymentAttempt as j, Environment as jt, PRODUCT_CATEGORIES as k, nationalPhone as kt, CHECKOUT_PURPOSES as l, PaymentFailureCode as lt, Coupon as m, CURRENCIES as mt, EventDataMap as n, WebhookEndpoint as nt, AfterCompletion as o, ApiErrorEnvelope as ot, CollectSettings as p, BillingMonths as pt, Retirement as q, EventType as r, Weekday as rt, Balance as s, ApiErrorType as st, EVENT_TYPES as t, USAGE_FEATURE_TYPES as tt, Checkout as u, Address as ut, CustomerDetails as v, List as vt, Feature as w, TAX_BEHAVIORS as wt, Event as x, MOBILE_PREFIXES as xt, CustomerFeature as y, ListQuery as yt, PlanPrice as z };
653
+ 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.4.0";
21
+ const SDK_VERSION = "0.6.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 SubscriptionRenewal, A as Payment, At as ENVIRONMENTS, B as Product, C as FEATURE_TYPES, Ct as MobilePrefix, D as FeatureUsageResult, Dt as isLandlinePhone, E as FeatureType, Et as Timestamp, F as PaymentStatus, G as Refund, H as ProductVariant, I as Payout, J as RiskLevel, K as ResetFrequency, L as Plan, M as PaymentFailure, Mt as TokenKind, N as PaymentLink, Nt as tokenEnvironment, O as PAYMENT_STATUSES, Ot as isMobilePhone, P as PaymentSettlement, Pt as tokenPrefix, Q as Subscription, R as PlanFeatureValues, S as ExchangeRate, St as Metadata, T as FeatureReset, Tt as TaxBehavior, U as RESET_FREQUENCIES, V as ProductCategory, W as RISK_LEVELS, X as SUBSCRIPTION_STATUSES, Y as SUBMIT_LABELS, Z as SubmitLabel, _ as Customer, _t as GracePeriodDays, a as Actor, at as ApiErrorBody, b as CustomerSession, bt as MAX_QUANTITY, c as BalanceAmount, ct as PAYMENT_FAILURE_CODES, d as CheckoutItem, dt as AddressInput, et as SubscriptionStatus, f as CheckoutPurpose, ft as BILLING_MONTHS, g as CustomField, gt as GRACE_PERIOD_DAYS, h as CurrencyAvailability, ht as Currency, i as WebhookEvent, it as API_ERROR_TYPES, j as PaymentAttempt, jt as Environment, k as PRODUCT_CATEGORIES, kt as nationalPhone, l as CHECKOUT_PURPOSES, lt as PaymentFailureCode, m as Coupon, mt as CURRENCIES, n as EventDataMap, nt as WebhookEndpoint, o as AfterCompletion, ot as ApiErrorEnvelope, p as CollectSettings, pt as BillingMonths, q as Retirement, r as EventType, rt as Weekday, s as Balance, st as ApiErrorType, t as EVENT_TYPES, tt as USAGE_FEATURE_TYPES, u as Checkout, ut as Address, v as CustomerDetails, vt as List, w as Feature, wt as TAX_BEHAVIORS, x as Event, xt as MOBILE_PREFIXES, y as CustomerFeature, yt as ListQuery, z as PlanPrice } from "./events-oZ08-Zz2.js";
2
- import { A as ProductCheckoutCreate, B as WebhookEndpointCreate, C as PaymentLinkUpdate, D as PlanLinkCreate, E as PlanFeaturesInput, F as RetireInput, G as PaymentTestScenario, H as CheckoutPaymentMethod, I as SubscriptionCancel, K as PublicCheckout, L as SubscriptionCreate, M as ProductLinkCreate, N as ProductUpdate, O as PlanPriceInput, P as RefundCreate, R as SubscriptionUpdate, S as PaymentLinkCreate, T as PlanCreate, U as PaymentInstructions, V as WebhookEndpointUpdate, W as PaymentMethodField, _ as CustomerUpdate, a as CheckoutCreate, b as FeatureUpdate, c as ClientCheckoutUpdate, d as CouponCreate, f as CouponUpdate, g as CustomerSessionCreate, h as CustomerInput, i as AfterCompletionInput, j as ProductCreate, k as PlanUpdate, l as ClientLinkCheckout, m as CustomerCreate, n as RequestOptions, o as CheckoutItemInput, p as CustomFieldInput, q as PublicPaymentLink, r as TransportOptions, s as ClientCheckoutPay, t as BilleteError, u as CollectInput, v as EventSelector, w as PlanCheckoutCreate, x as KEY_PATTERN, y as FeatureCreate, z as VariantInput } from "./errors-gwEcSkzi.js";
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-DjO9ARae.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-BzzXE5C2.js";
3
3
  import { WebhookVerificationError, verifyWebhook } from "./webhooks.js";
4
4
  //#region src/server.d.ts
5
5
  type Filters<T> = ListQuery & T;
@@ -39,6 +39,9 @@ export declare function createBillete(options: BilleteOptions): {
39
39
  /** Short-lived token for the client SDK to read one customer's billing state. */
40
40
  create: (input: CustomerSessionCreate, options?: RequestOptions) => Promise<CustomerSession>;
41
41
  };
42
+ portalSessions: {
43
+ create: (input: PortalSessionCreate, options?: RequestOptions) => Promise<PortalSession>;
44
+ };
42
45
  products: {
43
46
  create: (input: ProductCreate, options?: RequestOptions) => Promise<Product>;
44
47
  retrieve: (id: string, options?: RequestOptions) => Promise<Product>;
@@ -118,6 +121,22 @@ export declare function createBillete(options: BilleteOptions): {
118
121
  }>) => AsyncGenerator<PaymentLink, any, any>;
119
122
  retire: (id: string, input?: RetireInput, options?: RequestOptions) => Promise<PaymentLink>;
120
123
  };
124
+ invoices: {
125
+ create: (input: InvoiceCreate, options?: RequestOptions) => Promise<Invoice>;
126
+ retrieve: (id: string, options?: RequestOptions) => Promise<Invoice>;
127
+ list: (query?: Filters<{
128
+ customer?: string;
129
+ subscription?: string;
130
+ status?: InvoiceStatus;
131
+ }>, options?: RequestOptions) => Promise<List<Invoice>>;
132
+ iterate: (query?: Filters<{
133
+ customer?: string;
134
+ subscription?: string;
135
+ status?: InvoiceStatus;
136
+ }>) => AsyncGenerator<Invoice, any, any>;
137
+ /** Withdraws an open one-off Cobro; a renewal's is withdrawn by canceling its subscription. */
138
+ void: (id: string, options?: RequestOptions) => Promise<Invoice>;
139
+ };
121
140
  subscriptions: {
122
141
  create: (input: SubscriptionCreate, options?: RequestOptions) => Promise<Subscription>;
123
142
  retrieve: (id: string, options?: RequestOptions) => Promise<Subscription>;
@@ -194,4 +213,4 @@ export declare function createBillete(options: BilleteOptions): {
194
213
  /** The server client: what `createBillete` returns. */
195
214
  type Billete = ReturnType<typeof createBillete>;
196
215
  //#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 CheckoutPaymentMethod, type CheckoutPurpose, type ClientCheckoutPay, type ClientCheckoutUpdate, type ClientLinkCheckout, 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 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 KEY_PATTERN, 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 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 Product, type ProductCategory, type ProductCheckoutCreate, type ProductCreate, type ProductLinkCreate, type ProductUpdate, type ProductVariant, type PublicCheckout, type PublicPaymentLink, 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 };
216
+ 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-B5DzcQK9.js";
1
+ import { n as segment, r as BilleteError, t as createTransport } from "./http-Q-RXDFbe.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,
@@ -1,4 +1,4 @@
1
- import { i as WebhookEvent } from "./events-oZ08-Zz2.js";
1
+ import { i as WebhookEvent } from "./events-DjO9ARae.js";
2
2
  //#region src/webhooks.d.ts
3
3
  export declare class WebhookVerificationError extends Error {
4
4
  constructor(message: string);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boelabs/billete-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Billete SDK: server client, browser client and webhook verification",
5
5
  "keywords": [
6
6
  "billete",