@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/types/bookings.d.ts
CHANGED
|
@@ -58,6 +58,8 @@ export interface Booking {
|
|
|
58
58
|
* Returned ONCE — store it to let the guest view / cancel / move / confirm their booking.
|
|
59
59
|
*/
|
|
60
60
|
editToken?: string;
|
|
61
|
+
/** A paid booking's payment (read-only; absent when the booking has none). See "Paid bookings". */
|
|
62
|
+
payment?: BookingPayment;
|
|
61
63
|
}
|
|
62
64
|
export interface BookingSlot {
|
|
63
65
|
id: string;
|
|
@@ -307,7 +309,7 @@ export type BookingList = PaginatedResponse<Booking>;
|
|
|
307
309
|
export type SlotList = PaginatedResponse<BookingSlot>;
|
|
308
310
|
export type BlockList = PaginatedResponse<BookingAllocation>;
|
|
309
311
|
/** Error codes a booking call can fail with (HTTP 409 unless noted). */
|
|
310
|
-
export type BookingErrorCode = 'SLOT_FULL' | 'SLOT_CLOSED' | 'RESOURCE_TAKEN' | 'PER_CONTACT_LIMIT' | 'QUANTITY_LIMIT' | 'HOLD_EXPIRED' | 'INVALID_STATE' | 'SLOT_OVERBOOKED' | 'SLOT_HAS_BOOKINGS' | 'TOO_SOON' | 'TOO_FAR_AHEAD' | 'IN_THE_PAST' | 'DURATION_NOT_ALLOWED' | 'OUTSIDE_SCHEDULE' | 'NO_SCHEDULE' | 'SCHEDULE_INVALID' | 'CUTOFF_PASSED' | 'FORBIDDEN' | 'NOT_FOUND' | 'BAD_REQUEST';
|
|
312
|
+
export type BookingErrorCode = 'SLOT_FULL' | 'SLOT_CLOSED' | 'RESOURCE_TAKEN' | 'PER_CONTACT_LIMIT' | 'QUANTITY_LIMIT' | 'HOLD_EXPIRED' | 'INVALID_STATE' | 'SLOT_OVERBOOKED' | 'SLOT_HAS_BOOKINGS' | 'TOO_SOON' | 'TOO_FAR_AHEAD' | 'IN_THE_PAST' | 'DURATION_NOT_ALLOWED' | 'OUTSIDE_SCHEDULE' | 'NO_SCHEDULE' | 'SCHEDULE_INVALID' | 'CUTOFF_PASSED' | 'FORBIDDEN' | 'NOT_FOUND' | 'BAD_REQUEST' | 'PAYMENT_REQUIRED' | 'PAYMENTS_NOT_READY' | 'PRICE_MISMATCH' | 'NOT_PAID' | 'PRICE_NOT_FOUND' | 'PAYMENT_REFUSED' | 'PAYMENTS_NOT_CONFIGURED';
|
|
311
313
|
export interface ScheduleHours {
|
|
312
314
|
/** 'HH:MM' (24h) */
|
|
313
315
|
start: string;
|
|
@@ -332,3 +334,102 @@ export interface StandardSchedule {
|
|
|
332
334
|
/** Dated exceptions; the last matching one wins over `weekly`. */
|
|
333
335
|
overrides?: ScheduleOverride[];
|
|
334
336
|
}
|
|
337
|
+
/** One priced line of a paid booking. Amounts are minor units (pence, cents). */
|
|
338
|
+
export interface BookingPaymentLine {
|
|
339
|
+
priceId: string;
|
|
340
|
+
label: string;
|
|
341
|
+
unitAmount: number;
|
|
342
|
+
quantity: number;
|
|
343
|
+
}
|
|
344
|
+
/** A booking's payment, as every booking response shows it (built from the server's own record). */
|
|
345
|
+
export interface BookingPayment {
|
|
346
|
+
status: 'awaiting' | 'paid' | 'partially_refunded' | 'refunded' | 'waived';
|
|
347
|
+
total: number;
|
|
348
|
+
currency: string;
|
|
349
|
+
refunded: number;
|
|
350
|
+
lines: BookingPaymentLine[];
|
|
351
|
+
paidAt?: string;
|
|
352
|
+
/** An approved request: pay by then, or the place goes back. */
|
|
353
|
+
payBy?: string;
|
|
354
|
+
/** An approved request waiting for its payment. */
|
|
355
|
+
requested?: boolean;
|
|
356
|
+
/** The pay link of an approved request (the booker and staff only). */
|
|
357
|
+
link?: string;
|
|
358
|
+
}
|
|
359
|
+
/** A price, in a slot's `data.prices` (ticket types) or the app's `bookingPayments.prices` (services). */
|
|
360
|
+
export interface BookingPrice {
|
|
361
|
+
id: string;
|
|
362
|
+
label: string;
|
|
363
|
+
/** Minor units (pence). 0 = free. */
|
|
364
|
+
amount: number;
|
|
365
|
+
/** Appointments: the booked length must be this. */
|
|
366
|
+
durationMinutes?: number;
|
|
367
|
+
/** Appointments: only these resources (staff, rooms) offer it; empty = all. */
|
|
368
|
+
resourceIds?: string[];
|
|
369
|
+
}
|
|
370
|
+
/** The app's `bookingPayments` config (sites/{collectionId}/apps/{appId}), written by admins only. */
|
|
371
|
+
export interface BookingPaymentsConfig {
|
|
372
|
+
/**
|
|
373
|
+
* true: close the free way in (a plain create of a priced booking fails with PAYMENT_REQUIRED).
|
|
374
|
+
* false, set explicitly: payment switched off; checkout books for free. Unset: checkout charges priced bookings.
|
|
375
|
+
*/
|
|
376
|
+
required?: boolean;
|
|
377
|
+
currency?: string;
|
|
378
|
+
/** Appointments' price list (slots carry their own `data.prices`). */
|
|
379
|
+
prices?: BookingPrice[];
|
|
380
|
+
/** How long the person has on Stripe's page, 30–120 (default 30). The place is held 10 minutes longer. */
|
|
381
|
+
sessionMinutes?: number;
|
|
382
|
+
/** The booker cancelling a paid booking: 'full' refund (default) or 'none'. */
|
|
383
|
+
ownerCancelRefund?: 'full' | 'none';
|
|
384
|
+
/** Requests: hours to pay once approved, 1–168 (default 48). */
|
|
385
|
+
payWithinHours?: number;
|
|
386
|
+
/** Where Stripe sends the person back; `{CHECKOUT_SESSION_ID}` (or `session_id` added) for bySession. */
|
|
387
|
+
successUrl?: string;
|
|
388
|
+
cancelUrl?: string;
|
|
389
|
+
/** Other hosts a page may pass as successUrl / cancelUrl. */
|
|
390
|
+
allowedHosts?: string[];
|
|
391
|
+
}
|
|
392
|
+
export interface BookingPriceLine {
|
|
393
|
+
priceId: string;
|
|
394
|
+
quantity?: number;
|
|
395
|
+
}
|
|
396
|
+
export interface BookingCheckoutInput extends CreateBookingInput {
|
|
397
|
+
/** Ticket types on a slot: the quantities add up to the places taken. */
|
|
398
|
+
lines?: BookingPriceLine[];
|
|
399
|
+
/** An appointment's service (from the price list), or a slot's only ticket type. */
|
|
400
|
+
priceId?: string;
|
|
401
|
+
/** For Stripe's receipt. */
|
|
402
|
+
email?: string;
|
|
403
|
+
/** Default: the app's bookingPayments.successUrl / cancelUrl. Must be on the business's own hosts. */
|
|
404
|
+
successUrl?: string;
|
|
405
|
+
cancelUrl?: string;
|
|
406
|
+
/** A guest's details (as for create): gives them a contact for the confirmation email. */
|
|
407
|
+
customer?: {
|
|
408
|
+
email?: string;
|
|
409
|
+
phone?: string;
|
|
410
|
+
name?: string;
|
|
411
|
+
[k: string]: any;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
export interface BookingCheckoutResult {
|
|
415
|
+
booking: Booking;
|
|
416
|
+
/** Anonymous guests, once (as for create). */
|
|
417
|
+
editToken?: string;
|
|
418
|
+
/** Go here to pay. null for a free booking, or a request (pay link once approved). */
|
|
419
|
+
checkoutUrl: string | null;
|
|
420
|
+
expiresAt: string | null;
|
|
421
|
+
/** Minor units; 0 when free. */
|
|
422
|
+
total: number;
|
|
423
|
+
currency: string | null;
|
|
424
|
+
/** A request waiting for approval: "we'll email you a link to pay once it's confirmed". */
|
|
425
|
+
request?: boolean;
|
|
426
|
+
}
|
|
427
|
+
export interface BookingPayLinkResult {
|
|
428
|
+
checkoutUrl?: string;
|
|
429
|
+
done?: 'paid' | 'closed';
|
|
430
|
+
url?: string | null;
|
|
431
|
+
}
|
|
432
|
+
export type BookingRefundResult = Booking & {
|
|
433
|
+
refunded: number;
|
|
434
|
+
refundPending: boolean;
|
|
435
|
+
};
|
package/dist/types/payments.d.ts
CHANGED
|
@@ -93,6 +93,49 @@ export interface PaymentList {
|
|
|
93
93
|
hasMore: boolean;
|
|
94
94
|
next: string | null;
|
|
95
95
|
}
|
|
96
|
+
export interface PaymentSyncInput {
|
|
97
|
+
/** Only this app's payments. */
|
|
98
|
+
appId?: string;
|
|
99
|
+
/** Only payments made on or after this date (ISO). */
|
|
100
|
+
since?: string;
|
|
101
|
+
/** Where to carry on: the `next` of the last call. */
|
|
102
|
+
after?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface PaymentSyncResult {
|
|
105
|
+
/** The app payments found on this page. */
|
|
106
|
+
checked: number;
|
|
107
|
+
/** Payment records written (new or brought up to date). */
|
|
108
|
+
saved: number;
|
|
109
|
+
hasMore: boolean;
|
|
110
|
+
next: string | null;
|
|
111
|
+
}
|
|
112
|
+
/** A payment record's status (`record.status`), kept by SmartLinks from Stripe. */
|
|
113
|
+
export type AppPaymentStatus = 'paid' | 'partially_refunded' | 'refunded' | 'disputed' | 'dispute_lost';
|
|
114
|
+
/**
|
|
115
|
+
* `data` of a payment record: an app record of type `payment` (visibility admin, customId = the Stripe
|
|
116
|
+
* payment id), one per in-page payment, written by SmartLinks from Stripe — never by the payer's browser.
|
|
117
|
+
* Amounts are in minor units (pence).
|
|
118
|
+
*/
|
|
119
|
+
export interface AppPaymentRecordData {
|
|
120
|
+
paymentIntentId: string;
|
|
121
|
+
amount: number;
|
|
122
|
+
currency: string;
|
|
123
|
+
amountRefunded: number;
|
|
124
|
+
/** What SmartLinks took (the app's fee), minor units. */
|
|
125
|
+
fee: number;
|
|
126
|
+
email: string | null;
|
|
127
|
+
reference: string | null;
|
|
128
|
+
/** The app's own metadata from `createIntent`. */
|
|
129
|
+
metadata: Record<string, string>;
|
|
130
|
+
paidAt: string;
|
|
131
|
+
refundedAt: string | null;
|
|
132
|
+
dispute?: {
|
|
133
|
+
status: string;
|
|
134
|
+
reason: string | null;
|
|
135
|
+
amount: number | null;
|
|
136
|
+
at: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
96
139
|
export interface PaymentDomainResult {
|
|
97
140
|
domain: string;
|
|
98
141
|
/** Stripe's status for Apple Pay on the domain: 'active', 'inactive', … */
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.2.
|
|
1
|
+
export declare const SDK_VERSION = "2.2.11";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/write-version.mjs from package.json. Do not edit.
|
|
2
|
-
export const SDK_VERSION = "2.2.
|
|
2
|
+
export const SDK_VERSION = "2.2.11";
|
package/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/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/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
|
+
```
|