@proveanything/smartlinks 2.2.9 → 2.2.11
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/api/bookings.d.ts +49 -2
- package/dist/api/bookings.js +59 -2
- package/dist/api/payments.d.ts +7 -1
- package/dist/api/payments.js +9 -0
- package/dist/docs/API_SUMMARY.md +146 -7
- package/dist/docs/bookings.md +107 -8
- package/dist/docs/payments.md +33 -2
- package/dist/openapi.yaml +321 -0
- package/dist/testing/bookingsMemory.d.ts +29 -1
- package/dist/testing/bookingsMemory.js +89 -1
- package/dist/testing/index.js +4 -1
- package/dist/types/appManifest.d.ts +26 -4
- package/dist/types/bookings.d.ts +102 -1
- package/dist/types/payments.d.ts +43 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +146 -7
- package/docs/bookings.md +107 -8
- package/docs/payments.md +33 -2
- package/openapi.yaml +321 -0
- package/package.json +1 -1
package/dist/api/bookings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Booking, BookingSlot, BookingAllocation, CreateBookingInput, UpdateBookingInput, MoveBookingInput, BookingListQueryParams, CreateSlotInput, UpdateSlotInput, SlotListQueryParams, CreateBlockInput, BlockListQueryParams, FreeBusyQuery, FreeBusyResponse, BookingAccessOptions, MessageBookersInput, MessageBookersResult } from '../types/bookings.js';
|
|
1
|
+
import type { Booking, BookingSlot, BookingAllocation, CreateBookingInput, UpdateBookingInput, MoveBookingInput, BookingListQueryParams, CreateSlotInput, UpdateSlotInput, SlotListQueryParams, CreateBlockInput, BlockListQueryParams, FreeBusyQuery, FreeBusyResponse, BookingAccessOptions, MessageBookersInput, MessageBookersResult, BookingCheckoutInput, BookingCheckoutResult, BookingPayLinkResult, BookingRefundResult } from '../types/bookings.js';
|
|
2
2
|
import type { PaginatedResponse } from '../types/appObjects.js';
|
|
3
3
|
export declare namespace bookings {
|
|
4
4
|
/**
|
|
@@ -26,17 +26,64 @@ export declare namespace bookings {
|
|
|
26
26
|
/**
|
|
27
27
|
* held / pending / waitlisted → confirmed (idempotent). A held booking whose hold has run out fails
|
|
28
28
|
* with HOLD_EXPIRED. Public: only the booker's own hold, when `ownerActions.bookings.confirm` allows.
|
|
29
|
+
*
|
|
30
|
+
* Paid bookings: a booking waiting for its payment is confirmed by the payment (PAYMENT_REQUIRED
|
|
31
|
+
* otherwise). Admin confirming a REQUEST that has a price turns it into a hold with a pay link for the
|
|
32
|
+
* booker (`payment.link`, emailed through `booking.payment_requested`); `{ payment: 'waive' }` confirms
|
|
33
|
+
* without payment (paid in cash, a free place).
|
|
29
34
|
* POST /bookings/:bookingId/confirm
|
|
30
35
|
*/
|
|
31
|
-
function confirm(collectionId: string, appId: string, bookingId: string, admin?: boolean, opts?: BookingAccessOptions
|
|
36
|
+
function confirm(collectionId: string, appId: string, bookingId: string, admin?: boolean, opts?: BookingAccessOptions & {
|
|
37
|
+
payment?: 'waive';
|
|
38
|
+
}): Promise<Booking>;
|
|
32
39
|
/**
|
|
33
40
|
* Cancel and give the places back (idempotent). Public: per `ownerActions.bookings.cancel` and its
|
|
34
41
|
* cutoff. `reason` is admin-only (public cancels record 'owner').
|
|
42
|
+
*
|
|
43
|
+
* Paid bookings are refunded: the booker's cancel follows the app's `bookingPayments.ownerCancelRefund`
|
|
44
|
+
* (full by default); staff choose with `refund`: 'full' (default) | 'none' | an amount in minor units.
|
|
35
45
|
* POST /bookings/:bookingId/cancel
|
|
36
46
|
*/
|
|
37
47
|
function cancel(collectionId: string, appId: string, bookingId: string, admin?: boolean, opts?: BookingAccessOptions & {
|
|
38
48
|
reason?: string;
|
|
49
|
+
refund?: 'full' | 'none' | number;
|
|
39
50
|
}): Promise<Booking>;
|
|
51
|
+
/**
|
|
52
|
+
* Book and pay. The same rules as `create` (public), then the app's `bookingPayments` decide:
|
|
53
|
+
* - pay now (the rules book as held / confirmed): the booking is held while the person pays on
|
|
54
|
+
* Stripe's page → go to `checkoutUrl`; Stripe's webhook confirms it.
|
|
55
|
+
* - a request (the rules book as pending): priced, nothing paid, `checkoutUrl: null`; staff approving it
|
|
56
|
+
* sends the booker a pay link.
|
|
57
|
+
* - free (no prices): booked the normal way, `checkoutUrl: null`.
|
|
58
|
+
* Name prices by id (`lines` for ticket types on a slot, `priceId` for an appointment's service); the
|
|
59
|
+
* server sets every amount.
|
|
60
|
+
* POST /bookings/checkout
|
|
61
|
+
*/
|
|
62
|
+
function checkout(collectionId: string, appId: string, input: BookingCheckoutInput): Promise<BookingCheckoutResult>;
|
|
63
|
+
/**
|
|
64
|
+
* The thank-you page: the booking a Checkout Session paid for (`session_id` in the success address).
|
|
65
|
+
* `confirming: true` while Stripe's webhook is still on its way: show "confirming your payment…" and
|
|
66
|
+
* read again in a moment.
|
|
67
|
+
* GET /bookings/by-session/:sessionId
|
|
68
|
+
*/
|
|
69
|
+
function bySession(collectionId: string, appId: string, sessionId: string): Promise<Booking & {
|
|
70
|
+
confirming: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* An approved request's pay link, for an app with its own pay page (the link in the email goes straight
|
|
74
|
+
* to Stripe). `token` is the `t` of `payment.link`. → `{ checkoutUrl }`, or `{ done: 'paid' | 'closed', url }`.
|
|
75
|
+
* POST /bookings/:bookingId/pay
|
|
76
|
+
*/
|
|
77
|
+
function pay(collectionId: string, appId: string, bookingId: string, token: string): Promise<BookingPayLinkResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Refund a paid booking without cancelling it (admin): all that's left, or `amount` (minor units). A
|
|
80
|
+
* refund Stripe can't take now is retried by the platform (`refundPending: true`).
|
|
81
|
+
* POST /bookings/:bookingId/refund
|
|
82
|
+
*/
|
|
83
|
+
function refund(collectionId: string, appId: string, bookingId: string, opts?: {
|
|
84
|
+
amount?: number;
|
|
85
|
+
reason?: string;
|
|
86
|
+
}): Promise<BookingRefundResult>;
|
|
40
87
|
/**
|
|
41
88
|
* Move to a new slot / time, all-or-nothing (a failed move leaves the booking as it was).
|
|
42
89
|
* Public: per `ownerActions.bookings.move`; the create rules are re-checked for the new time.
|
package/dist/api/bookings.js
CHANGED
|
@@ -73,21 +73,78 @@ export var bookings;
|
|
|
73
73
|
/**
|
|
74
74
|
* held / pending / waitlisted → confirmed (idempotent). A held booking whose hold has run out fails
|
|
75
75
|
* with HOLD_EXPIRED. Public: only the booker's own hold, when `ownerActions.bookings.confirm` allows.
|
|
76
|
+
*
|
|
77
|
+
* Paid bookings: a booking waiting for its payment is confirmed by the payment (PAYMENT_REQUIRED
|
|
78
|
+
* otherwise). Admin confirming a REQUEST that has a price turns it into a hold with a pay link for the
|
|
79
|
+
* booker (`payment.link`, emailed through `booking.payment_requested`); `{ payment: 'waive' }` confirms
|
|
80
|
+
* without payment (paid in cash, a free place).
|
|
76
81
|
* POST /bookings/:bookingId/confirm
|
|
77
82
|
*/
|
|
78
83
|
async function confirm(collectionId, appId, bookingId, admin = false, opts) {
|
|
79
|
-
return post(`${basePath(collectionId, appId, admin)}/${encodeURIComponent(bookingId)}/confirm`, {}, tokenHeaders(opts));
|
|
84
|
+
return post(`${basePath(collectionId, appId, admin)}/${encodeURIComponent(bookingId)}/confirm`, (opts === null || opts === void 0 ? void 0 : opts.payment) ? { payment: opts.payment } : {}, tokenHeaders(opts));
|
|
80
85
|
}
|
|
81
86
|
bookings.confirm = confirm;
|
|
82
87
|
/**
|
|
83
88
|
* Cancel and give the places back (idempotent). Public: per `ownerActions.bookings.cancel` and its
|
|
84
89
|
* cutoff. `reason` is admin-only (public cancels record 'owner').
|
|
90
|
+
*
|
|
91
|
+
* Paid bookings are refunded: the booker's cancel follows the app's `bookingPayments.ownerCancelRefund`
|
|
92
|
+
* (full by default); staff choose with `refund`: 'full' (default) | 'none' | an amount in minor units.
|
|
85
93
|
* POST /bookings/:bookingId/cancel
|
|
86
94
|
*/
|
|
87
95
|
async function cancel(collectionId, appId, bookingId, admin = false, opts) {
|
|
88
|
-
|
|
96
|
+
const body = {};
|
|
97
|
+
if (opts === null || opts === void 0 ? void 0 : opts.reason)
|
|
98
|
+
body.reason = opts.reason;
|
|
99
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.refund) !== undefined)
|
|
100
|
+
body.refund = opts.refund;
|
|
101
|
+
return post(`${basePath(collectionId, appId, admin)}/${encodeURIComponent(bookingId)}/cancel`, body, tokenHeaders(opts));
|
|
89
102
|
}
|
|
90
103
|
bookings.cancel = cancel;
|
|
104
|
+
// ==================== PAID BOOKINGS (docs/bookings.md, "Paid bookings") ====================
|
|
105
|
+
/**
|
|
106
|
+
* Book and pay. The same rules as `create` (public), then the app's `bookingPayments` decide:
|
|
107
|
+
* - pay now (the rules book as held / confirmed): the booking is held while the person pays on
|
|
108
|
+
* Stripe's page → go to `checkoutUrl`; Stripe's webhook confirms it.
|
|
109
|
+
* - a request (the rules book as pending): priced, nothing paid, `checkoutUrl: null`; staff approving it
|
|
110
|
+
* sends the booker a pay link.
|
|
111
|
+
* - free (no prices): booked the normal way, `checkoutUrl: null`.
|
|
112
|
+
* Name prices by id (`lines` for ticket types on a slot, `priceId` for an appointment's service); the
|
|
113
|
+
* server sets every amount.
|
|
114
|
+
* POST /bookings/checkout
|
|
115
|
+
*/
|
|
116
|
+
async function checkout(collectionId, appId, input) {
|
|
117
|
+
return post(`${basePath(collectionId, appId, false)}/checkout`, input);
|
|
118
|
+
}
|
|
119
|
+
bookings.checkout = checkout;
|
|
120
|
+
/**
|
|
121
|
+
* The thank-you page: the booking a Checkout Session paid for (`session_id` in the success address).
|
|
122
|
+
* `confirming: true` while Stripe's webhook is still on its way: show "confirming your payment…" and
|
|
123
|
+
* read again in a moment.
|
|
124
|
+
* GET /bookings/by-session/:sessionId
|
|
125
|
+
*/
|
|
126
|
+
async function bySession(collectionId, appId, sessionId) {
|
|
127
|
+
return request(`${basePath(collectionId, appId, false)}/by-session/${encodeURIComponent(sessionId)}`);
|
|
128
|
+
}
|
|
129
|
+
bookings.bySession = bySession;
|
|
130
|
+
/**
|
|
131
|
+
* An approved request's pay link, for an app with its own pay page (the link in the email goes straight
|
|
132
|
+
* to Stripe). `token` is the `t` of `payment.link`. → `{ checkoutUrl }`, or `{ done: 'paid' | 'closed', url }`.
|
|
133
|
+
* POST /bookings/:bookingId/pay
|
|
134
|
+
*/
|
|
135
|
+
async function pay(collectionId, appId, bookingId, token) {
|
|
136
|
+
return post(`${basePath(collectionId, appId, false)}/${encodeURIComponent(bookingId)}/pay`, { token });
|
|
137
|
+
}
|
|
138
|
+
bookings.pay = pay;
|
|
139
|
+
/**
|
|
140
|
+
* Refund a paid booking without cancelling it (admin): all that's left, or `amount` (minor units). A
|
|
141
|
+
* refund Stripe can't take now is retried by the platform (`refundPending: true`).
|
|
142
|
+
* POST /bookings/:bookingId/refund
|
|
143
|
+
*/
|
|
144
|
+
async function refund(collectionId, appId, bookingId, opts) {
|
|
145
|
+
return post(`${basePath(collectionId, appId, true)}/${encodeURIComponent(bookingId)}/refund`, opts || {});
|
|
146
|
+
}
|
|
147
|
+
bookings.refund = refund;
|
|
91
148
|
/**
|
|
92
149
|
* Move to a new slot / time, all-or-nothing (a failed move leaves the booking as it was).
|
|
93
150
|
* Public: per `ownerActions.bookings.move`; the create rules are re-checked for the new time.
|
package/dist/api/payments.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PaymentsPublicConfig, PaymentIntentInput, PaymentIntentResult, PaymentsStatus, PaymentsConnectInput, PaymentListParams, PaymentList, PaymentDomainResult } from '../types/payments.js';
|
|
1
|
+
import type { PaymentsPublicConfig, PaymentIntentInput, PaymentIntentResult, PaymentsStatus, PaymentsConnectInput, PaymentListParams, PaymentList, PaymentSyncInput, PaymentSyncResult, PaymentDomainResult } from '../types/payments.js';
|
|
2
2
|
export declare namespace payments {
|
|
3
3
|
/**
|
|
4
4
|
* Can this business take payments, and what Stripe.js needs. `ready` is false until the business has
|
|
@@ -54,6 +54,12 @@ export declare namespace payments {
|
|
|
54
54
|
}>;
|
|
55
55
|
/** An app's in-page payments on the business's account, newest first (for reconciling). */
|
|
56
56
|
function intents(collectionId: string, params?: PaymentListParams): Promise<PaymentList>;
|
|
57
|
+
/**
|
|
58
|
+
* Bring the app's payment records up to date from Stripe (payments made before payment records
|
|
59
|
+
* existed, or whose events never arrived). One Stripe page per call; call again with `next` while
|
|
60
|
+
* `hasMore`. The records are app records of type `payment`: read them with `app.records.list`.
|
|
61
|
+
*/
|
|
62
|
+
function sync(collectionId: string, input?: PaymentSyncInput): Promise<PaymentSyncResult>;
|
|
57
63
|
/** Let Apple Pay and Google Pay run on a site's own domain (smartlinks.app needs nothing). */
|
|
58
64
|
function registerDomain(collectionId: string, domain: string): Promise<PaymentDomainResult>;
|
|
59
65
|
}
|
package/dist/api/payments.js
CHANGED
|
@@ -85,6 +85,15 @@ export var payments;
|
|
|
85
85
|
return request(`${adm(collectionId)}/intents${s ? `?${s}` : ''}`);
|
|
86
86
|
}
|
|
87
87
|
admin.intents = intents;
|
|
88
|
+
/**
|
|
89
|
+
* Bring the app's payment records up to date from Stripe (payments made before payment records
|
|
90
|
+
* existed, or whose events never arrived). One Stripe page per call; call again with `next` while
|
|
91
|
+
* `hasMore`. The records are app records of type `payment`: read them with `app.records.list`.
|
|
92
|
+
*/
|
|
93
|
+
async function sync(collectionId, input = {}) {
|
|
94
|
+
return post(`${adm(collectionId)}/sync`, input);
|
|
95
|
+
}
|
|
96
|
+
admin.sync = sync;
|
|
88
97
|
/** Let Apple Pay and Google Pay run on a site's own domain (smartlinks.app needs nothing). */
|
|
89
98
|
async function registerDomain(collectionId, domain) {
|
|
90
99
|
return post(`${adm(collectionId)}/domains`, { domain });
|
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.11 | Generated: 2026-12-05T10:45:08.620Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -2797,8 +2797,10 @@ interface ServerFunctionBookings {
|
|
|
2797
2797
|
query(params?: BookingListQueryParams): Promise<PaginatedResponse<Booking>>;
|
|
2798
2798
|
mine(params?: BookingListQueryParams): Promise<PaginatedResponse<Booking>>;
|
|
2799
2799
|
update(bookingId: string, fields: UpdateBookingInput): Promise<Booking>;
|
|
2800
|
-
confirm(bookingId: string): Promise<Booking>;
|
|
2801
|
-
cancel(bookingId: string, opts?: { reason?: string }): Promise<Booking>;
|
|
2800
|
+
confirm(bookingId: string, opts?: { payment?: 'waive' }): Promise<Booking>;
|
|
2801
|
+
cancel(bookingId: string, opts?: { reason?: string; refund?: 'full' | 'none' | number }): Promise<Booking>;
|
|
2802
|
+
checkout(input: BookingCheckoutInput): Promise<Omit<BookingCheckoutResult, 'editToken'> & { replayed?: boolean }>;
|
|
2803
|
+
refund(bookingId: string, opts?: { amount?: number; reason?: string }): Promise<{ booking: Booking; refunded: number; pending: boolean }>;
|
|
2802
2804
|
move(bookingId: string, input: MoveBookingInput): Promise<Booking>;
|
|
2803
2805
|
extendHold(bookingId: string, holdMinutes: number): Promise<Booking>;
|
|
2804
2806
|
complete(bookingId: string): Promise<Booking>;
|
|
@@ -5600,6 +5602,7 @@ interface Booking {
|
|
|
5600
5602
|
admin?: Record<string, any>
|
|
5601
5603
|
allocations: BookingAllocation[]
|
|
5602
5604
|
editToken?: string
|
|
5605
|
+
payment?: BookingPayment
|
|
5603
5606
|
}
|
|
5604
5607
|
```
|
|
5605
5608
|
|
|
@@ -5874,6 +5877,87 @@ interface StandardSchedule {
|
|
|
5874
5877
|
}
|
|
5875
5878
|
```
|
|
5876
5879
|
|
|
5880
|
+
**BookingPaymentLine** (interface)
|
|
5881
|
+
```typescript
|
|
5882
|
+
interface BookingPaymentLine {
|
|
5883
|
+
priceId: string
|
|
5884
|
+
label: string
|
|
5885
|
+
unitAmount: number
|
|
5886
|
+
quantity: number
|
|
5887
|
+
}
|
|
5888
|
+
```
|
|
5889
|
+
|
|
5890
|
+
**BookingPayment** (interface)
|
|
5891
|
+
```typescript
|
|
5892
|
+
interface BookingPayment {
|
|
5893
|
+
status: 'awaiting' | 'paid' | 'partially_refunded' | 'refunded' | 'waived'
|
|
5894
|
+
total: number
|
|
5895
|
+
currency: string
|
|
5896
|
+
refunded: number
|
|
5897
|
+
lines: BookingPaymentLine[]
|
|
5898
|
+
paidAt?: string
|
|
5899
|
+
payBy?: string
|
|
5900
|
+
requested?: boolean
|
|
5901
|
+
link?: string
|
|
5902
|
+
}
|
|
5903
|
+
```
|
|
5904
|
+
|
|
5905
|
+
**BookingPrice** (interface)
|
|
5906
|
+
```typescript
|
|
5907
|
+
interface BookingPrice {
|
|
5908
|
+
id: string
|
|
5909
|
+
label: string
|
|
5910
|
+
amount: number
|
|
5911
|
+
durationMinutes?: number
|
|
5912
|
+
resourceIds?: string[]
|
|
5913
|
+
}
|
|
5914
|
+
```
|
|
5915
|
+
|
|
5916
|
+
**BookingPaymentsConfig** (interface)
|
|
5917
|
+
```typescript
|
|
5918
|
+
interface BookingPaymentsConfig {
|
|
5919
|
+
required?: boolean
|
|
5920
|
+
currency?: string
|
|
5921
|
+
prices?: BookingPrice[]
|
|
5922
|
+
sessionMinutes?: number
|
|
5923
|
+
ownerCancelRefund?: 'full' | 'none'
|
|
5924
|
+
payWithinHours?: number
|
|
5925
|
+
successUrl?: string
|
|
5926
|
+
cancelUrl?: string
|
|
5927
|
+
allowedHosts?: string[]
|
|
5928
|
+
}
|
|
5929
|
+
```
|
|
5930
|
+
|
|
5931
|
+
**BookingPriceLine** (interface)
|
|
5932
|
+
```typescript
|
|
5933
|
+
interface BookingPriceLine {
|
|
5934
|
+
priceId: string
|
|
5935
|
+
quantity?: number
|
|
5936
|
+
}
|
|
5937
|
+
```
|
|
5938
|
+
|
|
5939
|
+
**BookingCheckoutResult** (interface)
|
|
5940
|
+
```typescript
|
|
5941
|
+
interface BookingCheckoutResult {
|
|
5942
|
+
booking: Booking
|
|
5943
|
+
editToken?: string
|
|
5944
|
+
checkoutUrl: string | null
|
|
5945
|
+
expiresAt: string | null
|
|
5946
|
+
total: number
|
|
5947
|
+
currency: string | null
|
|
5948
|
+
request?: boolean
|
|
5949
|
+
}
|
|
5950
|
+
```
|
|
5951
|
+
|
|
5952
|
+
**BookingPayLinkResult** (interface)
|
|
5953
|
+
```typescript
|
|
5954
|
+
interface BookingPayLinkResult {
|
|
5955
|
+
checkoutUrl?: string
|
|
5956
|
+
done?: 'paid' | 'closed'
|
|
5957
|
+
url?: string | null
|
|
5958
|
+
}
|
|
5959
|
+
```
|
|
5960
|
+
|
|
5877
5961
|
**BookingStatus** = ``
|
|
5878
5962
|
|
|
5879
5963
|
**BookingVisibility** = `'public' | 'owner' | 'admin'`
|
|
@@ -5897,6 +5981,8 @@ type BookingResourceRef = { type: string; id: string }
|
|
|
5897
5981
|
|
|
5898
5982
|
**ScheduleDay** = `'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun'`
|
|
5899
5983
|
|
|
5984
|
+
**BookingRefundResult** = `Booking & { refunded: number`
|
|
5985
|
+
|
|
5900
5986
|
### broadcasts
|
|
5901
5987
|
|
|
5902
5988
|
**ListBroadcastsQuery** (interface)
|
|
@@ -11638,6 +11724,42 @@ interface PaymentList {
|
|
|
11638
11724
|
}
|
|
11639
11725
|
```
|
|
11640
11726
|
|
|
11727
|
+
**PaymentSyncInput** (interface)
|
|
11728
|
+
```typescript
|
|
11729
|
+
interface PaymentSyncInput {
|
|
11730
|
+
appId?: string
|
|
11731
|
+
since?: string
|
|
11732
|
+
after?: string
|
|
11733
|
+
}
|
|
11734
|
+
```
|
|
11735
|
+
|
|
11736
|
+
**PaymentSyncResult** (interface)
|
|
11737
|
+
```typescript
|
|
11738
|
+
interface PaymentSyncResult {
|
|
11739
|
+
checked: number
|
|
11740
|
+
saved: number
|
|
11741
|
+
hasMore: boolean
|
|
11742
|
+
next: string | null
|
|
11743
|
+
}
|
|
11744
|
+
```
|
|
11745
|
+
|
|
11746
|
+
**AppPaymentRecordData** (interface)
|
|
11747
|
+
```typescript
|
|
11748
|
+
interface AppPaymentRecordData {
|
|
11749
|
+
paymentIntentId: string
|
|
11750
|
+
amount: number
|
|
11751
|
+
currency: string
|
|
11752
|
+
amountRefunded: number
|
|
11753
|
+
fee: number
|
|
11754
|
+
email: string | null
|
|
11755
|
+
reference: string | null
|
|
11756
|
+
metadata: Record<string, string>
|
|
11757
|
+
paidAt: string
|
|
11758
|
+
refundedAt: string | null
|
|
11759
|
+
dispute?: { status: string; reason: string | null; amount: number | null; at: string }
|
|
11760
|
+
}
|
|
11761
|
+
```
|
|
11762
|
+
|
|
11641
11763
|
**PaymentDomainResult** (interface)
|
|
11642
11764
|
```typescript
|
|
11643
11765
|
interface PaymentDomainResult {
|
|
@@ -11647,6 +11769,8 @@ interface PaymentDomainResult {
|
|
|
11647
11769
|
}
|
|
11648
11770
|
```
|
|
11649
11771
|
|
|
11772
|
+
**AppPaymentStatus** = `'paid' | 'partially_refunded' | 'refunded' | 'disputed' | 'dispute_lost'`
|
|
11773
|
+
|
|
11650
11774
|
### product
|
|
11651
11775
|
|
|
11652
11776
|
**ProductKey** (interface)
|
|
@@ -14945,11 +15069,23 @@ Get one booking. Public: the signed-in booker, or a guest passing `{ editToken }
|
|
|
14945
15069
|
**update**(collectionId: string, appId: string, bookingId: string, input: UpdateBookingInput, admin: boolean = true) → `Promise<Booking>`
|
|
14946
15070
|
Update zones and descriptive fields (admin). PATCH /bookings/:bookingId
|
|
14947
15071
|
|
|
14948
|
-
**confirm**(collectionId: string, appId: string, bookingId: string, admin: boolean = false, opts?: BookingAccessOptions) → `Promise<Booking>`
|
|
14949
|
-
held / pending / waitlisted → confirmed (idempotent). A held booking whose hold has run out fails with HOLD_EXPIRED. Public: only the booker's own hold, when `ownerActions.bookings.confirm` allows. POST /bookings/:bookingId/confirm
|
|
15072
|
+
**confirm**(collectionId: string, appId: string, bookingId: string, admin: boolean = false, opts?: BookingAccessOptions & { payment?: 'waive' }) → `Promise<Booking>`
|
|
15073
|
+
held / pending / waitlisted → confirmed (idempotent). A held booking whose hold has run out fails with HOLD_EXPIRED. Public: only the booker's own hold, when `ownerActions.bookings.confirm` allows. Paid bookings: a booking waiting for its payment is confirmed by the payment (PAYMENT_REQUIRED otherwise). Admin confirming a REQUEST that has a price turns it into a hold with a pay link for the booker (`payment.link`, emailed through `booking.payment_requested`); `{ payment: 'waive' }` confirms without payment (paid in cash, a free place). POST /bookings/:bookingId/confirm
|
|
15074
|
+
|
|
15075
|
+
**cancel**(collectionId: string, appId: string, bookingId: string, admin: boolean = false, opts?: BookingAccessOptions & { reason?: string; refund?: 'full' | 'none' | number }) → `Promise<Booking>`
|
|
15076
|
+
Cancel and give the places back (idempotent). Public: per `ownerActions.bookings.cancel` and its cutoff. `reason` is admin-only (public cancels record 'owner'). Paid bookings are refunded: the booker's cancel follows the app's `bookingPayments.ownerCancelRefund` (full by default); staff choose with `refund`: 'full' (default) | 'none' | an amount in minor units. POST /bookings/:bookingId/cancel
|
|
14950
15077
|
|
|
14951
|
-
**
|
|
14952
|
-
|
|
15078
|
+
**checkout**(collectionId: string, appId: string, input: BookingCheckoutInput) → `Promise<BookingCheckoutResult>`
|
|
15079
|
+
Book and pay. The same rules as `create` (public), then the app's `bookingPayments` decide: - pay now (the rules book as held / confirmed): the booking is held while the person pays on Stripe's page → go to `checkoutUrl`; Stripe's webhook confirms it. - a request (the rules book as pending): priced, nothing paid, `checkoutUrl: null`; staff approving it sends the booker a pay link. - free (no prices): booked the normal way, `checkoutUrl: null`. Name prices by id (`lines` for ticket types on a slot, `priceId` for an appointment's service); the server sets every amount. POST /bookings/checkout
|
|
15080
|
+
|
|
15081
|
+
**bySession**(collectionId: string, appId: string, sessionId: string) → `Promise<Booking &`
|
|
15082
|
+
The thank-you page: the booking a Checkout Session paid for (`session_id` in the success address). `confirming: true` while Stripe's webhook is still on its way: show "confirming your payment…" and read again in a moment. GET /bookings/by-session/:sessionId
|
|
15083
|
+
|
|
15084
|
+
**pay**(collectionId: string, appId: string, bookingId: string, token: string) → `Promise<BookingPayLinkResult>`
|
|
15085
|
+
An approved request's pay link, for an app with its own pay page (the link in the email goes straight to Stripe). `token` is the `t` of `payment.link`. → `{ checkoutUrl }`, or `{ done: 'paid' | 'closed', url }`. POST /bookings/:bookingId/pay
|
|
15086
|
+
|
|
15087
|
+
**refund**(collectionId: string, appId: string, bookingId: string, opts?: { amount?: number; reason?: string }) → `Promise<BookingRefundResult>`
|
|
15088
|
+
Refund a paid booking without cancelling it (admin): all that's left, or `amount` (minor units). A refund Stripe can't take now is retried by the platform (`refundPending: true`). POST /bookings/:bookingId/refund
|
|
14953
15089
|
|
|
14954
15090
|
**move**(collectionId: string, appId: string, bookingId: string, input: MoveBookingInput, admin: boolean = false, opts?: BookingAccessOptions) → `Promise<Booking>`
|
|
14955
15091
|
Move to a new slot / time, all-or-nothing (a failed move leaves the booking as it was). Public: per `ownerActions.bookings.move`; the create rules are re-checked for the new time. POST /bookings/:bookingId/move
|
|
@@ -16336,6 +16472,9 @@ Stop using the business's Stripe account. SmartLinks forgets it (apps can no lon
|
|
|
16336
16472
|
**intents**(collectionId: string, params?: PaymentListParams) → `Promise<PaymentList>`
|
|
16337
16473
|
An app's in-page payments on the business's account, newest first (for reconciling).
|
|
16338
16474
|
|
|
16475
|
+
**sync**(collectionId: string, input: PaymentSyncInput = {}) → `Promise<PaymentSyncResult>`
|
|
16476
|
+
Bring the app's payment records up to date from Stripe (payments made before payment records existed, or whose events never arrived). One Stripe page per call; call again with `next` while `hasMore`. The records are app records of type `payment`: read them with `app.records.list`.
|
|
16477
|
+
|
|
16339
16478
|
**registerDomain**(collectionId: string, domain: string) → `Promise<PaymentDomainResult>`
|
|
16340
16479
|
Let Apple Pay and Google Pay run on a site's own domain (smartlinks.app needs nothing).
|
|
16341
16480
|
|
package/dist/docs/bookings.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Generic booking objects for **any** booking app: event tickets, classes, tours, table reservations,
|
|
4
4
|
one-to-one appointments, room and equipment hire. The platform gives you the objects and the
|
|
5
|
-
guarantees. Your app owns the rest: schedule, policy
|
|
5
|
+
guarantees. Your app owns the rest: schedule, policy and UI. Payment can be the platform's too: see
|
|
6
|
+
[Paid bookings](#paid-bookings).
|
|
6
7
|
|
|
7
8
|
```ts
|
|
8
9
|
import { bookings, utils } from '@proveanything/smartlinks'
|
|
@@ -16,7 +17,7 @@ import { bookings, utils } from '@proveanything/smartlinks'
|
|
|
16
17
|
|---|---|
|
|
17
18
|
| **No double-booking** of a person / room / table, however many requests arrive at once | The schedule (opening hours) and its UI |
|
|
18
19
|
| **No overselling** a slot's capacity | Booking policy: notice, durations, who may book |
|
|
19
|
-
| **Atomic** writes: a booking with several parts (a stylist *and* a chair) succeeds whole or not at all |
|
|
20
|
+
| **Atomic** writes: a booking with several parts (a stylist *and* a chair) succeeds whole or not at all | Prices and ticket types (the platform can take the payment and refund: [Paid bookings](#paid-bookings)) |
|
|
20
21
|
| **Idempotent** creates (`idempotencyKey`): a retried request never books twice | Queues, waiting rooms, throttling for high-demand sales |
|
|
21
22
|
| **Holds** that expire and give the place back | Confirmation / reminder content (flows on booking events) |
|
|
22
23
|
| Who may book publicly, by **per-app rules** (like records / cases) | |
|
|
@@ -228,8 +229,8 @@ admin zone, buffers, `customId` or `sourceSystem`.
|
|
|
228
229
|
|
|
229
230
|
Default: nothing. `cutoffMinutes` = not within that time of the start (`CUTOFF_PASSED`). `move`
|
|
230
231
|
re-checks the create rules for the new time. `confirm` turns the booker's own **held** booking into
|
|
231
|
-
`confirmed` — only for apps that take no payment
|
|
232
|
-
confirm.
|
|
232
|
+
`confirmed` — only for apps that take no payment (a hold waiting for its payment answers
|
|
233
|
+
`PAYMENT_REQUIRED`); `pending` and `waitlisted` are the business's to confirm.
|
|
233
234
|
|
|
234
235
|
```ts
|
|
235
236
|
// Signed-in booker
|
|
@@ -269,15 +270,106 @@ export async function book(ctx, req) {
|
|
|
269
270
|
```
|
|
270
271
|
|
|
271
272
|
`create`, `get`, `query`, `mine` (the caller's own), `update`, `confirm`, `cancel`, `move`,
|
|
272
|
-
`extendHold`, `complete`, `noShow`, `freebusy`, `slots.*`, `blocks.*`. Errors carry `code`,
|
|
273
|
+
`extendHold`, `complete`, `noShow`, `freebusy`, `checkout`, `refund`, `slots.*`, `blocks.*`. Errors carry `code`,
|
|
273
274
|
`status` and `details` exactly as over HTTP. The local test harness
|
|
274
275
|
(`@proveanything/smartlinks/testing`) runs bookings in memory with the same rules.
|
|
275
276
|
|
|
276
277
|
---
|
|
277
278
|
|
|
278
|
-
##
|
|
279
|
+
## Paid bookings
|
|
279
280
|
|
|
280
|
-
The platform
|
|
281
|
+
The platform can take the payment for you: on the business's own Stripe account (connected once in
|
|
282
|
+
Studio → Payments), with our fee for your app, and refunds when bookings are cancelled. Your app
|
|
283
|
+
names prices; it never handles card details, Stripe keys or webhooks.
|
|
284
|
+
|
|
285
|
+
**1. Prices, set by admins only.** On a slot, ticket types in `data.prices`; for appointments, the
|
|
286
|
+
app's price list in its config, `bookingPayments.prices`. Amounts are minor units (pence).
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
await bookings.slots.create(collectionId, appId, {
|
|
290
|
+
startsAt, endsAt, capacity: 40,
|
|
291
|
+
data: { title: 'Santa\'s grotto', prices: [{ id: 'adult', label: 'Adult', amount: 1200 }, { id: 'child', label: 'Child', amount: 600 }] },
|
|
292
|
+
})
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"bookingPayments": {
|
|
298
|
+
"required": true,
|
|
299
|
+
"prices": [{ "id": "cut", "label": "Haircut", "amount": 2500, "durationMinutes": 30, "resourceIds": ["staff-1"] }],
|
|
300
|
+
"ownerCancelRefund": "full",
|
|
301
|
+
"successUrl": "https://example.com/booked",
|
|
302
|
+
"cancelUrl": "https://example.com/book"
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
- `required: true` closes the free way in: a plain `bookings.create` of a priced booking fails with
|
|
308
|
+
`PAYMENT_REQUIRED`, so nobody skips the payment by calling the API. `required: false` (set
|
|
309
|
+
explicitly) is payment switched off: `checkout` books for free and the prices stay for later. Unset,
|
|
310
|
+
a priced booking through `checkout` is charged.
|
|
311
|
+
- An appointment price is tied to what's booked: the booked length must be its `durationMinutes`, the
|
|
312
|
+
resource one of its `resourceIds` (`PRICE_MISMATCH` otherwise), and the booking's `data.service`
|
|
313
|
+
is set from the price.
|
|
314
|
+
- `sessionMinutes` (30–120, default 30): time on Stripe's page; the place is held 10 minutes longer.
|
|
315
|
+
`payWithinHours` (1–168, default 48): for requests, see below. `allowedHosts`: other hosts a page may
|
|
316
|
+
pass as `successUrl` / `cancelUrl` (the business's own hosts only).
|
|
317
|
+
|
|
318
|
+
**2. Book and pay.**
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
const r = await bookings.checkout(collectionId, appId, {
|
|
322
|
+
slotId, lines: [{ priceId: 'adult', quantity: 2 }, { priceId: 'child', quantity: 1 }], // 3 places
|
|
323
|
+
email, customer: { name, email },
|
|
324
|
+
})
|
|
325
|
+
if (r.checkoutUrl) location.href = r.checkoutUrl // pay on Stripe's page
|
|
326
|
+
else if (r.request) showRequestSent() // approval first: a pay link follows
|
|
327
|
+
else showBooked(r.booking) // free
|
|
328
|
+
// Appointments: { resourceType, resourceId, startsAt, endsAt, priceId: 'cut' }
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
The booking is **held** while the person pays; Stripe's webhook confirms it (`booking.paid`, then
|
|
332
|
+
`booking.confirmed` as usual, so your confirmation emails don't change). Not paid in time: cancelled
|
|
333
|
+
(`payment_not_completed`) and the places go back at once. On the success page:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
const b = await bookings.bySession(collectionId, appId, new URLSearchParams(location.search).get('session_id')!)
|
|
337
|
+
if (b.confirming) setTimeout(reload, 2000) // the webhook is a moment behind
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Every booking response carries a read-only `payment`: `{ status: 'awaiting' | 'paid' |
|
|
341
|
+
'partially_refunded' | 'refunded' | 'waived', total, currency, refunded, lines }`, and emails get it
|
|
342
|
+
formatted as `{{ booking.payment.totalText }}`, `{{ booking.payment.lines }}`.
|
|
343
|
+
|
|
344
|
+
**3. Bookings that need approval** (the rules book as `pending`): nobody pays for a booking they don't
|
|
345
|
+
have yet. `checkout` keeps the place and fixes the price, `checkoutUrl: null, request: true`. When
|
|
346
|
+
staff confirm it (`bookings.confirm(…, true)`), it becomes a hold until the pay-by time and
|
|
347
|
+
`booking.payment_requested` fires: put `{{ booking.payment.link }}` and `{{ booking.payment.payByText }}`
|
|
348
|
+
in that flow's email. The link goes straight to Stripe; an app with its own pay page calls
|
|
349
|
+
`bookings.pay(collectionId, appId, bookingId, token)`. Unpaid by then, the place goes back. Staff can
|
|
350
|
+
confirm without payment with `{ payment: 'waive' }` (paid in cash).
|
|
351
|
+
|
|
352
|
+
**4. Cancelling and refunds.** The booker cancelling (per `ownerActions.bookings.cancel`) is refunded
|
|
353
|
+
by `bookingPayments.ownerCancelRefund` (`'full'`, default, or `'none'`). Staff choose:
|
|
354
|
+
`bookings.cancel(…, true, { refund: 'full' | 'none' | 500 })`. A refund without cancelling:
|
|
355
|
+
`bookings.refund(collectionId, appId, bookingId, { amount })`. A refund Stripe can't take right away is
|
|
356
|
+
retried by the platform; the booking is flagged `refund_failed` after three tries. A paid booking
|
|
357
|
+
moves only to a place at the same price.
|
|
358
|
+
|
|
359
|
+
Events: `booking.paid`, `booking.refunded`, `booking.payment_requested`, `booking.payment_refunded` (paid
|
|
360
|
+
after the place had gone: refunded in full and flagged `refunded_no_place`). Flags on the booking:
|
|
361
|
+
`paid_late`, `payment_mismatch`, `refunded_no_place`, `refund_failed`.
|
|
362
|
+
|
|
363
|
+
In a server function, `ctx.sl.bookings.checkout({ …, status: 'held' | 'pending' })` does the same
|
|
364
|
+
without the public rules; `ctx.sl.bookings.refund(id, { amount })`. In the local test harness there is
|
|
365
|
+
no Stripe: `checkoutUrl` is pretend and `ctx.sl.bookings.payWith(bookingId)` stands in for the payment.
|
|
366
|
+
|
|
367
|
+
**Your own payments instead.** Nothing here is required: an app that takes payment its own way (its own
|
|
368
|
+
Stripe keys, credits, vouchers) uses holds and confirm as below.
|
|
369
|
+
|
|
370
|
+
## Payments your app takes itself, and high-demand sales
|
|
371
|
+
|
|
372
|
+
The platform gives you what your own payment or credits flow needs:
|
|
281
373
|
|
|
282
374
|
1. Create the booking **`held`** (claims the place; `holdMinutes`).
|
|
283
375
|
2. Take payment. Slow step? `bookings.extendHold(…, minutes)` (admin; capped at 24h from creation).
|
|
@@ -311,6 +403,11 @@ Booking calls fail with HTTP 409 and an `errorCode` you can show or act on:
|
|
|
311
403
|
| `TOO_SOON` / `TOO_FAR_AHEAD` / `IN_THE_PAST` / `DURATION_NOT_ALLOWED` | Public time rules |
|
|
312
404
|
| `OUTSIDE_SCHEDULE` / `NO_SCHEDULE` / `SCHEDULE_INVALID` | Public schedule check |
|
|
313
405
|
| `CUTOFF_PASSED` | Owner action inside its cutoff |
|
|
406
|
+
| `PAYMENT_REQUIRED` | A priced booking made without `checkout`, or confirming one that isn't paid |
|
|
407
|
+
| `PAYMENTS_NOT_READY` | The business hasn't connected Stripe yet (Studio → Payments) |
|
|
408
|
+
| `PRICE_MISMATCH` | The price doesn't fit what's booked (length, staff), or a paid move to another price |
|
|
409
|
+
| `NOT_PAID` | Refunding a booking with no payment |
|
|
410
|
+
| `PRICE_NOT_FOUND` (400) | Unknown `priceId`, or several ticket types and no `lines` |
|
|
314
411
|
|
|
315
412
|
`403 FORBIDDEN` when the app's rules don't allow the call; `404` for unknown ids.
|
|
316
413
|
|
|
@@ -321,7 +418,9 @@ Booking calls fail with HTTP 409 and an `errorCode` you can show or act on:
|
|
|
321
418
|
Recorded after each write commits, for flows and app functions (`trigger: { type: 'event', eventTypes: [...] }`):
|
|
322
419
|
|
|
323
420
|
`booking.created`, `booking.confirmed`, `booking.cancelled`, `booking.moved`, `booking.completed`,
|
|
324
|
-
`booking.no_show`, `booking.hold_expired`, `slot.full`, `slot.place_freed` (for waitlist promotion)
|
|
421
|
+
`booking.no_show`, `booking.hold_expired`, `slot.full`, `slot.place_freed` (for waitlist promotion);
|
|
422
|
+
paid bookings add `booking.paid`, `booking.refunded`, `booking.payment_requested`,
|
|
423
|
+
`booking.payment_refunded`.
|
|
325
424
|
Context: `{ appId, status, slotIds }` (bookings) / `{ appId, remaining }` (slots).
|
|
326
425
|
|
|
327
426
|
Reminders before a booking (`booking.starts_in`) are coming; until then, send a reminder template to
|
package/dist/docs/payments.md
CHANGED
|
@@ -90,5 +90,36 @@ let page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate',
|
|
|
90
90
|
while (page.hasMore) page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate', after: page.next! })
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
### Payment records: what Stripe says happened
|
|
94
|
+
|
|
95
|
+
SmartLinks keeps every in-page payment's true state for you, from Stripe's own events, never from the
|
|
96
|
+
payer's browser: one **app record of type `payment`** per payment, in your app (visibility admin,
|
|
97
|
+
`customId` = the Stripe payment id). Its `status` follows the money:
|
|
98
|
+
|
|
99
|
+
| status | meaning |
|
|
100
|
+
|---|---|
|
|
101
|
+
| `paid` | taken |
|
|
102
|
+
| `partially_refunded` / `refunded` | refunded in part / in full (from Stripe's dashboard or anywhere else) |
|
|
103
|
+
| `disputed` / `dispute_lost` | the payer's bank is disputing it / the dispute was lost (a won dispute goes back to `paid`) |
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { app, type AppPaymentRecordData } from '@proveanything/smartlinks'
|
|
107
|
+
|
|
108
|
+
const page = await app.records.list(collectionId, 'tap-to-donate', { recordType: 'payment' }, true)
|
|
109
|
+
for (const r of page.data) {
|
|
110
|
+
const p = r.data as AppPaymentRecordData // amounts in pence: p.amount, p.amountRefunded, p.fee
|
|
111
|
+
console.log(r.status, p.paymentIntentId, p.amount - p.amountRefunded, p.metadata.campaignId)
|
|
112
|
+
}
|
|
113
|
+
// one payment: { recordType: 'payment', customId: paymentIntentId }
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Keep `paymentIntentId` (from `createIntent`) on your own record (a donation, a ticket) and read its status
|
|
117
|
+
from the payment record. A payment with no record of yours (the page closed before you saved it) still has
|
|
118
|
+
its payment record: show it, so nothing is missed. Totals should use `amount - amountRefunded`.
|
|
119
|
+
|
|
120
|
+
Payments made before payment records existed, or whose events never arrived, are brought in with:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
let r = await payments.admin.sync(collectionId, { appId: 'tap-to-donate' }) // → { checked, saved, hasMore, next }
|
|
124
|
+
while (r.hasMore) r = await payments.admin.sync(collectionId, { appId: 'tap-to-donate', after: r.next! })
|
|
125
|
+
```
|