@vibiz/app 0.2.4 → 0.3.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/dist/index.d.ts +66 -5
- package/dist/index.js +31 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -66,11 +66,16 @@ export interface Payment {
|
|
|
66
66
|
object: 'payment';
|
|
67
67
|
id: string;
|
|
68
68
|
status: 'succeeded' | 'refunded' | 'partially_refunded' | 'disputed' | 'failed';
|
|
69
|
+
/** In `currency`, its smallest unit (cents; whole units for jpy, krw, clp). */
|
|
69
70
|
amount_cents: number;
|
|
70
71
|
refunded_cents: number;
|
|
72
|
+
/** Through Vibiz in another currency: in USD, the balance's (as `net_cents`). */
|
|
71
73
|
fee_cents: number;
|
|
72
74
|
net_cents: number;
|
|
73
|
-
|
|
75
|
+
/** Lowercase ISO 4217: what the buyer paid in. */
|
|
76
|
+
currency: string;
|
|
77
|
+
/** Through Vibiz: what the sale added to the balance before fees, in US cents; null on your own account. */
|
|
78
|
+
settled_usd_cents: number | null;
|
|
74
79
|
description: string | null;
|
|
75
80
|
user: string | null;
|
|
76
81
|
customer_email: string | null;
|
|
@@ -98,19 +103,43 @@ export interface Subscription {
|
|
|
98
103
|
user: string | null;
|
|
99
104
|
customer_email: string | null;
|
|
100
105
|
price_id: string | null;
|
|
101
|
-
/** `own`: billed on the owner's own Stripe account. The app's code is the same either way. */
|
|
106
|
+
/** `own`: billed on the owner's own Stripe account (or paid by a store). The app's code is the same either way. */
|
|
102
107
|
account: 'vibiz' | 'own';
|
|
108
|
+
/**
|
|
109
|
+
* Where it was bought: `web` (a checkout), or `app_store` / `play_store` (in the app, through
|
|
110
|
+
* the owner's own RevenueCat account; the user cancels those in the store). Older servers leave it out.
|
|
111
|
+
*/
|
|
112
|
+
source?: 'web' | 'app_store' | 'play_store';
|
|
113
|
+
/** Store purchases: the store's product id (`com.acme.app.pro_monthly`). */
|
|
114
|
+
store_product_id?: string | null;
|
|
115
|
+
/** Store purchases: the entitlements it gives (`pro`). */
|
|
116
|
+
entitlements?: string[];
|
|
103
117
|
current_period_end: string | null;
|
|
104
118
|
cancel_at_period_end: boolean;
|
|
105
119
|
created_at: string;
|
|
106
120
|
}
|
|
121
|
+
/** One thing a user has now, and where it comes from (docs: app-store "One answer"). */
|
|
122
|
+
export interface Entitlement {
|
|
123
|
+
object: 'entitlement';
|
|
124
|
+
/** The plan's key, one per product in the catalog (`pro`). */
|
|
125
|
+
key: string;
|
|
126
|
+
active: true;
|
|
127
|
+
source: 'web' | 'app_store' | 'play_store';
|
|
128
|
+
subscription_id: string;
|
|
129
|
+
price_id: string | null;
|
|
130
|
+
lookup_key: string | null;
|
|
131
|
+
store_product_id: string | null;
|
|
132
|
+
expires_at: string | null;
|
|
133
|
+
will_renew: boolean;
|
|
134
|
+
}
|
|
107
135
|
export interface Price {
|
|
108
136
|
object: 'price';
|
|
109
137
|
id: string;
|
|
110
138
|
product_id: string;
|
|
111
139
|
active: boolean;
|
|
140
|
+
/** In the smallest unit of `currency`. */
|
|
112
141
|
unit_amount_cents: number;
|
|
113
|
-
currency:
|
|
142
|
+
currency: string;
|
|
114
143
|
type: 'one_time' | 'recurring';
|
|
115
144
|
interval: 'day' | 'week' | 'month' | 'year' | null;
|
|
116
145
|
interval_count: number | null;
|
|
@@ -129,9 +158,11 @@ export interface CheckoutInput {
|
|
|
129
158
|
/** One of these… */
|
|
130
159
|
price_id?: string;
|
|
131
160
|
lookup_key?: string;
|
|
132
|
-
/** …or an ad-hoc one-time item. */
|
|
161
|
+
/** …or an ad-hoc one-time item, in the smallest unit of `currency` (cents; whole yen for jpy). */
|
|
133
162
|
amount_cents?: number;
|
|
134
163
|
name?: string;
|
|
164
|
+
/** With `amount_cents`: lowercase ISO 4217 (`eur`, `gbp`, `jpy`…); left out: usd. A price has its own. */
|
|
165
|
+
currency?: string;
|
|
135
166
|
quantity?: number;
|
|
136
167
|
/** Your own user's id: their payments and subscriptions are found by it. */
|
|
137
168
|
user?: string;
|
|
@@ -140,6 +171,25 @@ export interface CheckoutInput {
|
|
|
140
171
|
cancel_url: string;
|
|
141
172
|
/** Up to 20 keys, echoed on the payment and in webhooks. */
|
|
142
173
|
metadata?: Record<string, string>;
|
|
174
|
+
/** Your business's look on the checkout page, over the project's brand field by field. */
|
|
175
|
+
brand?: CheckoutBrand;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* How the hosted checkout page looks. Left out, a field comes from the
|
|
179
|
+
* project's brand (console ▸ Payments, or `PATCH …/payments { brand }`).
|
|
180
|
+
*/
|
|
181
|
+
export interface CheckoutBrand {
|
|
182
|
+
/** At the top of the page instead of the business name. */
|
|
183
|
+
name?: string;
|
|
184
|
+
/** https URLs; with both, the logo shows and the (square) icon is the tab's. */
|
|
185
|
+
logo_url?: string;
|
|
186
|
+
icon_url?: string;
|
|
187
|
+
/** Hex: `#rrggbb` or `#rgb`. */
|
|
188
|
+
background_color?: string;
|
|
189
|
+
button_color?: string;
|
|
190
|
+
/** e.g. `inter`, `roboto`, `lato`, `montserrat`, `open_sans`, `default`. */
|
|
191
|
+
font?: string;
|
|
192
|
+
border_style?: 'pill' | 'rectangular' | 'rounded';
|
|
143
193
|
}
|
|
144
194
|
/** An event Vibiz sent to your webhook, verified. */
|
|
145
195
|
/** A connector as the app sees it: what it may call, never a key. */
|
|
@@ -481,6 +531,7 @@ export declare class VibizApp {
|
|
|
481
531
|
* first call, before the owner has verified anything. Refunds and
|
|
482
532
|
* withdrawals are the owner's, in the console.
|
|
483
533
|
*/
|
|
534
|
+
private entitlementList;
|
|
484
535
|
readonly payments: {
|
|
485
536
|
/** A hosted checkout page for a price (one-time or a subscription) or an ad-hoc item. */
|
|
486
537
|
checkout: (input: CheckoutInput) => Promise<{
|
|
@@ -491,7 +542,17 @@ export declare class VibizApp {
|
|
|
491
542
|
}>;
|
|
492
543
|
/** The user's live subscription (active, trialing or past due), or null. */
|
|
493
544
|
subscription: (user: string) => Promise<Subscription | null>;
|
|
494
|
-
/**
|
|
545
|
+
/**
|
|
546
|
+
* What the user has now, across web checkout subscriptions and App Store / Google Play
|
|
547
|
+
* purchases: one entry per thing it gives, with its `source`. Server-side only.
|
|
548
|
+
*/
|
|
549
|
+
entitlements: (user: string) => Promise<Entitlement[]>;
|
|
550
|
+
/**
|
|
551
|
+
* Whether the user has it now: anything (no `key`), or one thing, matched in this order:
|
|
552
|
+
* an entitlement key (`pro`; a string that is one of the project's entitlement keys is
|
|
553
|
+
* matched only as that), else a lookup key (`pro-monthly`), a price id, a store product id.
|
|
554
|
+
* Counts the web checkout and the App Store / Google Play alike.
|
|
555
|
+
*/
|
|
495
556
|
hasActive: (user: string, price?: string) => Promise<boolean>;
|
|
496
557
|
/** A link where the user manages their subscription and card. */
|
|
497
558
|
portal: (user: string, opts: {
|
package/dist/index.js
CHANGED
|
@@ -348,6 +348,11 @@ var VibizApp = class _VibizApp {
|
|
|
348
348
|
* first call, before the owner has verified anything. Refunds and
|
|
349
349
|
* withdrawals are the owner's, in the console.
|
|
350
350
|
*/
|
|
351
|
+
entitlementList(user) {
|
|
352
|
+
return this.request(
|
|
353
|
+
`/app/payments/entitlements?user=${encodeURIComponent(user)}`
|
|
354
|
+
);
|
|
355
|
+
}
|
|
351
356
|
payments = {
|
|
352
357
|
/** A hosted checkout page for a price (one-time or a subscription) or an ad-hoc item. */
|
|
353
358
|
checkout: (input) => this.request(
|
|
@@ -361,8 +366,33 @@ var VibizApp = class _VibizApp {
|
|
|
361
366
|
);
|
|
362
367
|
return r.data[0] ?? null;
|
|
363
368
|
},
|
|
364
|
-
/**
|
|
369
|
+
/**
|
|
370
|
+
* What the user has now, across web checkout subscriptions and App Store / Google Play
|
|
371
|
+
* purchases: one entry per thing it gives, with its `source`. Server-side only.
|
|
372
|
+
*/
|
|
373
|
+
entitlements: async (user) => (await this.entitlementList(user)).data,
|
|
374
|
+
/**
|
|
375
|
+
* Whether the user has it now: anything (no `key`), or one thing, matched in this order:
|
|
376
|
+
* an entitlement key (`pro`; a string that is one of the project's entitlement keys is
|
|
377
|
+
* matched only as that), else a lookup key (`pro-monthly`), a price id, a store product id.
|
|
378
|
+
* Counts the web checkout and the App Store / Google Play alike.
|
|
379
|
+
*/
|
|
365
380
|
hasActive: async (user, price) => {
|
|
381
|
+
let list = null;
|
|
382
|
+
try {
|
|
383
|
+
list = await this.entitlementList(user);
|
|
384
|
+
} catch (err) {
|
|
385
|
+
if (!(err instanceof VibizAppError) || err.status !== 404) throw err;
|
|
386
|
+
}
|
|
387
|
+
if (list) {
|
|
388
|
+
const grants = list.data;
|
|
389
|
+
if (!price) return grants.length > 0;
|
|
390
|
+
if (grants.some((g) => g.key === price)) return true;
|
|
391
|
+
if (list.entitlement_keys?.includes(price)) return false;
|
|
392
|
+
return grants.some(
|
|
393
|
+
(g) => g.lookup_key === price || g.price_id === price || g.store_product_id === price
|
|
394
|
+
);
|
|
395
|
+
}
|
|
366
396
|
const r = await this.request(
|
|
367
397
|
`/app/payments/subscriptions?user=${encodeURIComponent(user)}&status=active,trialing`
|
|
368
398
|
);
|