@proveanything/smartlinks 2.2.8 → 2.2.10
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 +9 -0
- package/dist/api/payments.js +9 -0
- package/dist/docs/API_SUMMARY.md +108 -7
- package/dist/docs/bookings.md +539 -442
- package/dist/docs/payments.md +7 -0
- package/dist/openapi.yaml +249 -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 +99 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +108 -7
- package/docs/bookings.md +539 -442
- package/docs/payments.md +7 -0
- package/openapi.yaml +249 -0
- package/package.json +87 -87
package/dist/docs/payments.md
CHANGED
|
@@ -75,6 +75,13 @@ location.href = url
|
|
|
75
75
|
|
|
76
76
|
`shop.admin.connect` does the same thing: there is one account per business, whichever app connects it.
|
|
77
77
|
|
|
78
|
+
```typescript
|
|
79
|
+
await payments.admin.disconnect(collectionId) // → { connected: false, disconnectedAccountId }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Disconnecting stops every app taking payments until an account is connected again. SmartLinks forgets the
|
|
83
|
+
account; the Stripe account stays the business's own, with its payments. Connecting again makes a new one.
|
|
84
|
+
|
|
78
85
|
### Reconciling an app's payments
|
|
79
86
|
|
|
80
87
|
```typescript
|
package/dist/openapi.yaml
CHANGED
|
@@ -11163,6 +11163,32 @@ paths:
|
|
|
11163
11163
|
application/json:
|
|
11164
11164
|
schema:
|
|
11165
11165
|
$ref: "#/components/schemas/CreateBlockInput"
|
|
11166
|
+
/checkout:
|
|
11167
|
+
post:
|
|
11168
|
+
tags:
|
|
11169
|
+
- bookings
|
|
11170
|
+
summary: Book and pay.
|
|
11171
|
+
operationId: bookings_checkout
|
|
11172
|
+
security: []
|
|
11173
|
+
responses:
|
|
11174
|
+
200:
|
|
11175
|
+
description: Success
|
|
11176
|
+
content:
|
|
11177
|
+
application/json:
|
|
11178
|
+
schema:
|
|
11179
|
+
$ref: "#/components/schemas/BookingCheckoutResult"
|
|
11180
|
+
400:
|
|
11181
|
+
description: Bad request
|
|
11182
|
+
401:
|
|
11183
|
+
description: Unauthorized
|
|
11184
|
+
404:
|
|
11185
|
+
description: Not found
|
|
11186
|
+
requestBody:
|
|
11187
|
+
required: true
|
|
11188
|
+
content:
|
|
11189
|
+
application/json:
|
|
11190
|
+
schema:
|
|
11191
|
+
$ref: "#/components/schemas/BookingCheckoutInput"
|
|
11166
11192
|
/freebusy:
|
|
11167
11193
|
get:
|
|
11168
11194
|
tags:
|
|
@@ -15650,6 +15676,65 @@ paths:
|
|
|
15650
15676
|
description: Unauthorized
|
|
15651
15677
|
404:
|
|
15652
15678
|
description: Not found
|
|
15679
|
+
/{bookingId}/pay:
|
|
15680
|
+
post:
|
|
15681
|
+
tags:
|
|
15682
|
+
- bookings
|
|
15683
|
+
summary: "An approved request's pay link, for an app with its own pay page (the link in the email goes straight to Stripe)."
|
|
15684
|
+
operationId: bookings_pay
|
|
15685
|
+
security: []
|
|
15686
|
+
parameters:
|
|
15687
|
+
- name: bookingId
|
|
15688
|
+
in: path
|
|
15689
|
+
required: true
|
|
15690
|
+
schema:
|
|
15691
|
+
type: string
|
|
15692
|
+
responses:
|
|
15693
|
+
200:
|
|
15694
|
+
description: Success
|
|
15695
|
+
content:
|
|
15696
|
+
application/json:
|
|
15697
|
+
schema:
|
|
15698
|
+
$ref: "#/components/schemas/BookingPayLinkResult"
|
|
15699
|
+
400:
|
|
15700
|
+
description: Bad request
|
|
15701
|
+
401:
|
|
15702
|
+
description: Unauthorized
|
|
15703
|
+
404:
|
|
15704
|
+
description: Not found
|
|
15705
|
+
/{bookingId}/refund:
|
|
15706
|
+
post:
|
|
15707
|
+
tags:
|
|
15708
|
+
- bookings
|
|
15709
|
+
summary: "Refund a paid booking without cancelling it (admin): all that's left, or `amount` (minor units)."
|
|
15710
|
+
operationId: bookings_refund
|
|
15711
|
+
security: []
|
|
15712
|
+
parameters:
|
|
15713
|
+
- name: bookingId
|
|
15714
|
+
in: path
|
|
15715
|
+
required: true
|
|
15716
|
+
schema:
|
|
15717
|
+
type: string
|
|
15718
|
+
responses:
|
|
15719
|
+
200:
|
|
15720
|
+
description: Success
|
|
15721
|
+
content:
|
|
15722
|
+
application/json:
|
|
15723
|
+
schema:
|
|
15724
|
+
$ref: "#/components/schemas/BookingRefundResult"
|
|
15725
|
+
400:
|
|
15726
|
+
description: Bad request
|
|
15727
|
+
401:
|
|
15728
|
+
description: Unauthorized
|
|
15729
|
+
404:
|
|
15730
|
+
description: Not found
|
|
15731
|
+
requestBody:
|
|
15732
|
+
required: true
|
|
15733
|
+
content:
|
|
15734
|
+
application/json:
|
|
15735
|
+
schema:
|
|
15736
|
+
type: object
|
|
15737
|
+
additionalProperties: true
|
|
15653
15738
|
/{conditionId}:
|
|
15654
15739
|
get:
|
|
15655
15740
|
tags:
|
|
@@ -26533,6 +26618,8 @@ components:
|
|
|
26533
26618
|
$ref: "#/components/schemas/BookingAllocation"
|
|
26534
26619
|
editToken:
|
|
26535
26620
|
type: string
|
|
26621
|
+
payment:
|
|
26622
|
+
$ref: "#/components/schemas/BookingPayment"
|
|
26536
26623
|
required:
|
|
26537
26624
|
- id
|
|
26538
26625
|
- collectionId
|
|
@@ -27052,6 +27139,166 @@ components:
|
|
|
27052
27139
|
$ref: "#/components/schemas/ScheduleOverride"
|
|
27053
27140
|
required:
|
|
27054
27141
|
- timezone
|
|
27142
|
+
BookingPaymentLine:
|
|
27143
|
+
type: object
|
|
27144
|
+
properties:
|
|
27145
|
+
priceId:
|
|
27146
|
+
type: string
|
|
27147
|
+
label:
|
|
27148
|
+
type: string
|
|
27149
|
+
unitAmount:
|
|
27150
|
+
type: number
|
|
27151
|
+
quantity:
|
|
27152
|
+
type: number
|
|
27153
|
+
required:
|
|
27154
|
+
- priceId
|
|
27155
|
+
- label
|
|
27156
|
+
- unitAmount
|
|
27157
|
+
- quantity
|
|
27158
|
+
BookingPayment:
|
|
27159
|
+
type: object
|
|
27160
|
+
properties:
|
|
27161
|
+
status:
|
|
27162
|
+
type: string
|
|
27163
|
+
enum:
|
|
27164
|
+
- awaiting
|
|
27165
|
+
- paid
|
|
27166
|
+
- partially_refunded
|
|
27167
|
+
- refunded
|
|
27168
|
+
- waived
|
|
27169
|
+
total:
|
|
27170
|
+
type: number
|
|
27171
|
+
currency:
|
|
27172
|
+
type: string
|
|
27173
|
+
refunded:
|
|
27174
|
+
type: number
|
|
27175
|
+
lines:
|
|
27176
|
+
type: array
|
|
27177
|
+
items:
|
|
27178
|
+
$ref: "#/components/schemas/BookingPaymentLine"
|
|
27179
|
+
paidAt:
|
|
27180
|
+
type: string
|
|
27181
|
+
payBy:
|
|
27182
|
+
type: string
|
|
27183
|
+
requested:
|
|
27184
|
+
type: boolean
|
|
27185
|
+
link:
|
|
27186
|
+
type: string
|
|
27187
|
+
required:
|
|
27188
|
+
- status
|
|
27189
|
+
- total
|
|
27190
|
+
- currency
|
|
27191
|
+
- refunded
|
|
27192
|
+
- lines
|
|
27193
|
+
BookingPrice:
|
|
27194
|
+
type: object
|
|
27195
|
+
properties:
|
|
27196
|
+
id:
|
|
27197
|
+
type: string
|
|
27198
|
+
label:
|
|
27199
|
+
type: string
|
|
27200
|
+
amount:
|
|
27201
|
+
type: number
|
|
27202
|
+
durationMinutes:
|
|
27203
|
+
type: number
|
|
27204
|
+
resourceIds:
|
|
27205
|
+
type: array
|
|
27206
|
+
items:
|
|
27207
|
+
type: string
|
|
27208
|
+
required:
|
|
27209
|
+
- id
|
|
27210
|
+
- label
|
|
27211
|
+
- amount
|
|
27212
|
+
BookingPaymentsConfig:
|
|
27213
|
+
type: object
|
|
27214
|
+
properties:
|
|
27215
|
+
required:
|
|
27216
|
+
type: boolean
|
|
27217
|
+
currency:
|
|
27218
|
+
type: string
|
|
27219
|
+
prices:
|
|
27220
|
+
type: array
|
|
27221
|
+
items:
|
|
27222
|
+
$ref: "#/components/schemas/BookingPrice"
|
|
27223
|
+
sessionMinutes:
|
|
27224
|
+
type: number
|
|
27225
|
+
ownerCancelRefund:
|
|
27226
|
+
type: string
|
|
27227
|
+
enum:
|
|
27228
|
+
- full
|
|
27229
|
+
- none
|
|
27230
|
+
payWithinHours:
|
|
27231
|
+
type: number
|
|
27232
|
+
successUrl:
|
|
27233
|
+
type: string
|
|
27234
|
+
cancelUrl:
|
|
27235
|
+
type: string
|
|
27236
|
+
allowedHosts:
|
|
27237
|
+
type: array
|
|
27238
|
+
items:
|
|
27239
|
+
type: string
|
|
27240
|
+
BookingPriceLine:
|
|
27241
|
+
type: object
|
|
27242
|
+
properties:
|
|
27243
|
+
priceId:
|
|
27244
|
+
type: string
|
|
27245
|
+
quantity:
|
|
27246
|
+
type: number
|
|
27247
|
+
required:
|
|
27248
|
+
- priceId
|
|
27249
|
+
BookingCheckoutInput:
|
|
27250
|
+
type: object
|
|
27251
|
+
properties:
|
|
27252
|
+
lines:
|
|
27253
|
+
type: array
|
|
27254
|
+
items:
|
|
27255
|
+
$ref: "#/components/schemas/BookingPriceLine"
|
|
27256
|
+
priceId:
|
|
27257
|
+
type: string
|
|
27258
|
+
email:
|
|
27259
|
+
type: string
|
|
27260
|
+
successUrl:
|
|
27261
|
+
type: string
|
|
27262
|
+
cancelUrl:
|
|
27263
|
+
type: string
|
|
27264
|
+
customer:
|
|
27265
|
+
type: object
|
|
27266
|
+
additionalProperties: true
|
|
27267
|
+
BookingCheckoutResult:
|
|
27268
|
+
type: object
|
|
27269
|
+
properties:
|
|
27270
|
+
booking:
|
|
27271
|
+
$ref: "#/components/schemas/Booking"
|
|
27272
|
+
editToken:
|
|
27273
|
+
type: string
|
|
27274
|
+
checkoutUrl:
|
|
27275
|
+
type: string
|
|
27276
|
+
expiresAt:
|
|
27277
|
+
type: string
|
|
27278
|
+
total:
|
|
27279
|
+
type: number
|
|
27280
|
+
currency:
|
|
27281
|
+
type: string
|
|
27282
|
+
request:
|
|
27283
|
+
type: boolean
|
|
27284
|
+
required:
|
|
27285
|
+
- booking
|
|
27286
|
+
- checkoutUrl
|
|
27287
|
+
- expiresAt
|
|
27288
|
+
- total
|
|
27289
|
+
- currency
|
|
27290
|
+
BookingPayLinkResult:
|
|
27291
|
+
type: object
|
|
27292
|
+
properties:
|
|
27293
|
+
checkoutUrl:
|
|
27294
|
+
type: string
|
|
27295
|
+
done:
|
|
27296
|
+
type: string
|
|
27297
|
+
enum:
|
|
27298
|
+
- paid
|
|
27299
|
+
- closed
|
|
27300
|
+
url:
|
|
27301
|
+
type: string
|
|
27055
27302
|
BookingResourceRef:
|
|
27056
27303
|
type: object
|
|
27057
27304
|
properties:
|
|
@@ -27114,6 +27361,8 @@ components:
|
|
|
27114
27361
|
- fri
|
|
27115
27362
|
- sat
|
|
27116
27363
|
- sun
|
|
27364
|
+
BookingRefundResult:
|
|
27365
|
+
$ref: "#/components/schemas/Booking"
|
|
27117
27366
|
ListBroadcastsQuery:
|
|
27118
27367
|
type: object
|
|
27119
27368
|
properties:
|
|
@@ -28,9 +28,37 @@ export declare function bookingsMemoryImpl(mem: BookingsMemory, caller?: {
|
|
|
28
28
|
};
|
|
29
29
|
}>;
|
|
30
30
|
update(bookingId: string, fields?: any): Promise<any>;
|
|
31
|
-
confirm(bookingId: string): Promise<any>;
|
|
31
|
+
confirm(bookingId: string, opts?: any): Promise<any>;
|
|
32
32
|
cancel(bookingId: string, opts?: any): Promise<any>;
|
|
33
33
|
move(bookingId: string, input?: any): Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Paid bookings, in memory: prices from the slot's `data.prices` (ticket `lines`) or `input.prices`
|
|
36
|
+
* (pass the app's price list for appointments). No Stripe: `checkoutUrl` is pretend; call
|
|
37
|
+
* `payWith(bookingId)` to act as the payment arriving.
|
|
38
|
+
*/
|
|
39
|
+
checkout(input?: any): Promise<{
|
|
40
|
+
booking: any;
|
|
41
|
+
replayed: any;
|
|
42
|
+
checkoutUrl: null;
|
|
43
|
+
expiresAt: null;
|
|
44
|
+
total: number;
|
|
45
|
+
currency: null;
|
|
46
|
+
} | {
|
|
47
|
+
request?: boolean | undefined;
|
|
48
|
+
booking: any;
|
|
49
|
+
replayed: any;
|
|
50
|
+
checkoutUrl: string | null;
|
|
51
|
+
expiresAt: string | null;
|
|
52
|
+
total: number;
|
|
53
|
+
currency: string;
|
|
54
|
+
}>;
|
|
55
|
+
/** In memory only: the payment for a booking arrives (as Stripe's webhook would). */
|
|
56
|
+
payWith(bookingId: string): Promise<any>;
|
|
57
|
+
refund(bookingId: string, opts?: any): Promise<{
|
|
58
|
+
booking: any;
|
|
59
|
+
refunded: number;
|
|
60
|
+
pending: boolean;
|
|
61
|
+
}>;
|
|
34
62
|
extendHold(bookingId: string, holdMinutes: number): Promise<any>;
|
|
35
63
|
/** Counts who would be messaged (no sends in memory); inject `sl.bookings.message` to assert sends. */
|
|
36
64
|
message(input?: any): Promise<{
|
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
// creates, holds that expire, all-or-nothing writes. Each operation checks and writes without an
|
|
6
6
|
// `await` in between, so concurrent calls in one test behave like the database: of ten requests for
|
|
7
7
|
// the last seat, exactly one wins. Errors carry the platform's `code` / `status` / `details`.
|
|
8
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
9
|
+
var t = {};
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
13
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
14
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
15
|
+
t[p[i]] = s[p[i]];
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
};
|
|
8
19
|
export function createBookingsMemory() {
|
|
9
20
|
return { slots: [], bookings: [], allocations: [] };
|
|
10
21
|
}
|
|
@@ -193,12 +204,29 @@ export function bookingsMemoryImpl(mem, caller = {}) {
|
|
|
193
204
|
b.updatedAt = iso(now());
|
|
194
205
|
return copy(withAllocations(b));
|
|
195
206
|
},
|
|
196
|
-
async confirm(bookingId) {
|
|
207
|
+
async confirm(bookingId, opts = {}) {
|
|
197
208
|
const b = find(bookingId);
|
|
198
209
|
if (b.status === 'confirmed')
|
|
199
210
|
return copy(withAllocations(b));
|
|
200
211
|
if (!['held', 'pending', 'waitlisted'].includes(b.status))
|
|
201
212
|
fail('INVALID_STATE', `A ${b.status} booking can't be confirmed`, 409, { status: b.status });
|
|
213
|
+
// Paid bookings: confirmed by the payment, or waived. In memory there is no Stripe: a request
|
|
214
|
+
// becomes a hold with a pretend pay link, and `payWith(bookingId)` below stands in for the webhook.
|
|
215
|
+
const pay = b.admin && b.admin.payment;
|
|
216
|
+
if (pay && pay.status === 'awaiting') {
|
|
217
|
+
if (opts.payment === 'waive') {
|
|
218
|
+
pay.status = 'waived';
|
|
219
|
+
}
|
|
220
|
+
else if (b.status === 'pending') {
|
|
221
|
+
b.status = 'held';
|
|
222
|
+
b.holdExpiresAt = iso(now() + 48 * 3600000);
|
|
223
|
+
pay.payBy = b.holdExpiresAt;
|
|
224
|
+
pay.link = `https://pay.test/${b.id}`;
|
|
225
|
+
return copy(withAllocations(b));
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
fail('PAYMENT_REQUIRED', 'This booking is confirmed when it is paid for');
|
|
229
|
+
}
|
|
202
230
|
if (holdLapsed(b))
|
|
203
231
|
fail('HOLD_EXPIRED', 'The hold on this booking has run out');
|
|
204
232
|
if (b.status === 'waitlisted') {
|
|
@@ -231,6 +259,11 @@ export function bookingsMemoryImpl(mem, caller = {}) {
|
|
|
231
259
|
b.cancelReason = opts.reason || 'admin';
|
|
232
260
|
b.cancelledAt = iso(now());
|
|
233
261
|
b.holdExpiresAt = null;
|
|
262
|
+
// A paid booking is refunded: 'full' (default) | 'none' | an amount.
|
|
263
|
+
const pay = b.admin && b.admin.payment;
|
|
264
|
+
if (pay && ['paid', 'partially_refunded'].includes(pay.status) && opts.refund !== 'none') {
|
|
265
|
+
await this.refund(bookingId, { amount: opts.refund === 'full' || opts.refund == null ? undefined : Number(opts.refund), reason: 'cancelled' });
|
|
266
|
+
}
|
|
234
267
|
return copy(withAllocations(b));
|
|
235
268
|
},
|
|
236
269
|
async move(bookingId, input = {}) {
|
|
@@ -271,6 +304,61 @@ export function bookingsMemoryImpl(mem, caller = {}) {
|
|
|
271
304
|
}
|
|
272
305
|
return copy(withAllocations(b));
|
|
273
306
|
},
|
|
307
|
+
/**
|
|
308
|
+
* Paid bookings, in memory: prices from the slot's `data.prices` (ticket `lines`) or `input.prices`
|
|
309
|
+
* (pass the app's price list for appointments). No Stripe: `checkoutUrl` is pretend; call
|
|
310
|
+
* `payWith(bookingId)` to act as the payment arriving.
|
|
311
|
+
*/
|
|
312
|
+
async checkout(input = {}) {
|
|
313
|
+
const { lines, priceId, email, successUrl, cancelUrl, prices: priceList } = input, create = __rest(input, ["lines", "priceId", "email", "successUrl", "cancelUrl", "prices"]);
|
|
314
|
+
const slot = create.slotId ? mem.slots.find((x) => x.id === create.slotId) : null;
|
|
315
|
+
const prices = (slot ? (slot.data && slot.data.prices) : priceList) || [];
|
|
316
|
+
const wanted = Array.isArray(lines) && lines.length ? lines : priceId ? [{ priceId, quantity: 1 }] : prices.length === 1 ? [{ priceId: prices[0].id, quantity: create.quantity || 1 }] : [];
|
|
317
|
+
const priced = wanted.map((w) => {
|
|
318
|
+
const p = prices.find((x) => x.id === w.priceId);
|
|
319
|
+
if (!p)
|
|
320
|
+
fail('PRICE_NOT_FOUND', `There is no price "${w.priceId}"`, 400);
|
|
321
|
+
return { priceId: p.id, label: p.label, unitAmount: Number(p.amount), quantity: Number(w.quantity || 1) };
|
|
322
|
+
});
|
|
323
|
+
const total = priced.reduce((a, l) => a + l.unitAmount * l.quantity, 0);
|
|
324
|
+
if (!total) {
|
|
325
|
+
const booking = await this.create(create);
|
|
326
|
+
return { booking, replayed: booking.replayed, checkoutUrl: null, expiresAt: null, total: 0, currency: null };
|
|
327
|
+
}
|
|
328
|
+
const status = create.status === 'pending' ? 'pending' : 'held';
|
|
329
|
+
const quantity = slot ? priced.reduce((a, l) => a + l.quantity, 0) : 1;
|
|
330
|
+
const payment = { status: 'awaiting', total, currency: 'GBP', refunded: 0, lines: priced, email: email || null, refunds: [] };
|
|
331
|
+
const booking = await this.create(Object.assign(Object.assign({}, create), { quantity, status, holdMinutes: 40, admin: Object.assign(Object.assign({}, (create.admin || {})), { payment }) }));
|
|
332
|
+
const checkoutUrl = status === 'held' ? `https://checkout.test/${booking.id}` : null;
|
|
333
|
+
return Object.assign({ booking, replayed: booking.replayed, checkoutUrl, expiresAt: checkoutUrl ? iso(now() + 30 * 60000) : null, total, currency: 'GBP' }, (status === 'pending' ? { request: true } : {}));
|
|
334
|
+
},
|
|
335
|
+
/** In memory only: the payment for a booking arrives (as Stripe's webhook would). */
|
|
336
|
+
async payWith(bookingId) {
|
|
337
|
+
const b = find(bookingId);
|
|
338
|
+
const pay = b.admin && b.admin.payment;
|
|
339
|
+
if (!pay)
|
|
340
|
+
fail('NOT_PAID', 'This booking has no payment');
|
|
341
|
+
pay.status = 'paid';
|
|
342
|
+
pay.paidAt = iso(now());
|
|
343
|
+
b.status = 'confirmed';
|
|
344
|
+
b.holdExpiresAt = null;
|
|
345
|
+
b.updatedAt = iso(now());
|
|
346
|
+
return copy(withAllocations(b));
|
|
347
|
+
},
|
|
348
|
+
async refund(bookingId, opts = {}) {
|
|
349
|
+
const b = find(bookingId);
|
|
350
|
+
const pay = b.admin && b.admin.payment;
|
|
351
|
+
if (!pay || !['paid', 'partially_refunded'].includes(pay.status))
|
|
352
|
+
fail('NOT_PAID', 'This booking has no payment to refund');
|
|
353
|
+
const left = pay.total - (pay.refunded || 0);
|
|
354
|
+
const amount = opts.amount == null ? left : Number(opts.amount);
|
|
355
|
+
if (!Number.isInteger(amount) || amount < 1 || amount > left)
|
|
356
|
+
fail('BAD_REQUEST', `amount must be from 1 to ${left}`, 400);
|
|
357
|
+
pay.refunded = (pay.refunded || 0) + amount;
|
|
358
|
+
pay.refunds = [...(pay.refunds || []), { id: id('re'), amount, reason: opts.reason || 'refund' }];
|
|
359
|
+
pay.status = pay.refunded >= pay.total ? 'refunded' : 'partially_refunded';
|
|
360
|
+
return { booking: copy(withAllocations(b)), refunded: amount, pending: false };
|
|
361
|
+
},
|
|
274
362
|
async extendHold(bookingId, holdMinutes) {
|
|
275
363
|
const b = find(bookingId);
|
|
276
364
|
if (b.status !== 'held')
|
package/dist/testing/index.js
CHANGED
|
@@ -427,9 +427,12 @@ export function createFunctionTestContext(opts) {
|
|
|
427
427
|
const bkFn = (obj, name) => (obj && typeof obj[name] === 'function' ? obj[name].bind(obj) : undefined);
|
|
428
428
|
const BOOKING_READS = new Set(['get', 'query', 'mine', 'freebusy']);
|
|
429
429
|
sl.bookings = {};
|
|
430
|
-
for (const m of ['create', 'get', 'query', 'mine', 'update', 'confirm', 'cancel', 'move', 'extendHold', 'complete', 'noShow', 'freebusy', 'message']) {
|
|
430
|
+
for (const m of ['create', 'get', 'query', 'mine', 'update', 'confirm', 'cancel', 'move', 'extendHold', 'complete', 'noShow', 'freebusy', 'message', 'checkout', 'refund']) {
|
|
431
431
|
sl.bookings[m] = gated('bookings', BOOKING_READS.has(m) ? 'read' : 'write', bkFn(bk, m), `bookings.${m}`);
|
|
432
432
|
}
|
|
433
|
+
// In memory only (no Stripe): the payment for a checkout arrives, as Stripe's webhook would make it.
|
|
434
|
+
if (!impl.bookings)
|
|
435
|
+
sl.bookings.payWith = bkFn(bk, 'payWith');
|
|
433
436
|
sl.bookings.slots = {};
|
|
434
437
|
for (const m of ['create', 'createMany', 'get', 'query', 'update', 'delete']) {
|
|
435
438
|
sl.bookings.slots[m] = gated('bookings', m === 'get' || m === 'query' ? 'read' : 'write', bkFn(bk.slots, m), `bookings.slots.${m}`);
|
|
@@ -6,7 +6,7 @@ import type { AppManifestAdminCards } from './adminCards.js';
|
|
|
6
6
|
import type { PaginatedResponse } from './appObjects.js';
|
|
7
7
|
import type { TypedMessage, MessageAbout, EmailAttachmentSpec } from './comms.js';
|
|
8
8
|
import type { WorkOrdersApi, StockApi, BomsApi, MadeFromApi, OperationsApi } from './operations.js';
|
|
9
|
-
import type { Booking, BookingSlot, BookingAllocation, CreateBookingInput, UpdateBookingInput, MoveBookingInput, BookingListQueryParams, CreateSlotInput, UpdateSlotInput, SlotListQueryParams, CreateBlockInput, BlockListQueryParams, FreeBusyQuery, FreeBusyResponse, MessageBookersInput, MessageBookersResult } from './bookings.js';
|
|
9
|
+
import type { Booking, BookingSlot, BookingAllocation, CreateBookingInput, BookingCheckoutInput, BookingCheckoutResult, UpdateBookingInput, MoveBookingInput, BookingListQueryParams, CreateSlotInput, UpdateSlotInput, SlotListQueryParams, CreateBlockInput, BlockListQueryParams, FreeBusyQuery, FreeBusyResponse, MessageBookersInput, MessageBookersResult } from './bookings.js';
|
|
10
10
|
/**
|
|
11
11
|
* A bundle (widget or container) as returned by the collection widgets endpoint.
|
|
12
12
|
*
|
|
@@ -464,12 +464,34 @@ export interface ServerFunctionBookings {
|
|
|
464
464
|
/** The signed-in caller's own bookings (empty when anonymous). */
|
|
465
465
|
mine(params?: BookingListQueryParams): Promise<PaginatedResponse<Booking>>;
|
|
466
466
|
update(bookingId: string, fields: UpdateBookingInput): Promise<Booking>;
|
|
467
|
-
/**
|
|
468
|
-
|
|
469
|
-
|
|
467
|
+
/**
|
|
468
|
+
* held / pending / waitlisted → confirmed (idempotent). A booking waiting for its payment: a request
|
|
469
|
+
* becomes a hold with a pay link; `{ payment: 'waive' }` confirms without payment.
|
|
470
|
+
*/
|
|
471
|
+
confirm(bookingId: string, opts?: {
|
|
472
|
+
payment?: 'waive';
|
|
473
|
+
}): Promise<Booking>;
|
|
474
|
+
/** Cancel and give the places back (idempotent). A paid booking is refunded: 'full' (default) | 'none' | an amount. */
|
|
470
475
|
cancel(bookingId: string, opts?: {
|
|
471
476
|
reason?: string;
|
|
477
|
+
refund?: 'full' | 'none' | number;
|
|
472
478
|
}): Promise<Booking>;
|
|
479
|
+
/**
|
|
480
|
+
* Book and pay (docs/bookings.md, "Paid bookings"): held while the person pays on Stripe
|
|
481
|
+
* (`status: 'held'`, the default), or a priced request (`status: 'pending'`). → `checkoutUrl` to send them to.
|
|
482
|
+
*/
|
|
483
|
+
checkout(input: BookingCheckoutInput): Promise<Omit<BookingCheckoutResult, 'editToken'> & {
|
|
484
|
+
replayed?: boolean;
|
|
485
|
+
}>;
|
|
486
|
+
/** Refund a paid booking without cancelling it: all that's left, or `amount` (minor units). */
|
|
487
|
+
refund(bookingId: string, opts?: {
|
|
488
|
+
amount?: number;
|
|
489
|
+
reason?: string;
|
|
490
|
+
}): Promise<{
|
|
491
|
+
booking: Booking;
|
|
492
|
+
refunded: number;
|
|
493
|
+
pending: boolean;
|
|
494
|
+
}>;
|
|
473
495
|
/** All-or-nothing move to new claims. */
|
|
474
496
|
move(bookingId: string, input: MoveBookingInput): Promise<Booking>;
|
|
475
497
|
extendHold(bookingId: string, holdMinutes: number): Promise<Booking>;
|
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,99 @@ 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
|
+
/** Close the free way in: a plain create of a priced booking fails with PAYMENT_REQUIRED. */
|
|
373
|
+
required?: boolean;
|
|
374
|
+
currency?: string;
|
|
375
|
+
/** Appointments' price list (slots carry their own `data.prices`). */
|
|
376
|
+
prices?: BookingPrice[];
|
|
377
|
+
/** How long the person has on Stripe's page, 30–120 (default 30). The place is held 10 minutes longer. */
|
|
378
|
+
sessionMinutes?: number;
|
|
379
|
+
/** The booker cancelling a paid booking: 'full' refund (default) or 'none'. */
|
|
380
|
+
ownerCancelRefund?: 'full' | 'none';
|
|
381
|
+
/** Requests: hours to pay once approved, 1–168 (default 48). */
|
|
382
|
+
payWithinHours?: number;
|
|
383
|
+
/** Where Stripe sends the person back; `{CHECKOUT_SESSION_ID}` (or `session_id` added) for bySession. */
|
|
384
|
+
successUrl?: string;
|
|
385
|
+
cancelUrl?: string;
|
|
386
|
+
/** Other hosts a page may pass as successUrl / cancelUrl. */
|
|
387
|
+
allowedHosts?: string[];
|
|
388
|
+
}
|
|
389
|
+
export interface BookingPriceLine {
|
|
390
|
+
priceId: string;
|
|
391
|
+
quantity?: number;
|
|
392
|
+
}
|
|
393
|
+
export interface BookingCheckoutInput extends CreateBookingInput {
|
|
394
|
+
/** Ticket types on a slot: the quantities add up to the places taken. */
|
|
395
|
+
lines?: BookingPriceLine[];
|
|
396
|
+
/** An appointment's service (from the price list), or a slot's only ticket type. */
|
|
397
|
+
priceId?: string;
|
|
398
|
+
/** For Stripe's receipt. */
|
|
399
|
+
email?: string;
|
|
400
|
+
/** Default: the app's bookingPayments.successUrl / cancelUrl. Must be on the business's own hosts. */
|
|
401
|
+
successUrl?: string;
|
|
402
|
+
cancelUrl?: string;
|
|
403
|
+
/** A guest's details (as for create): gives them a contact for the confirmation email. */
|
|
404
|
+
customer?: {
|
|
405
|
+
email?: string;
|
|
406
|
+
phone?: string;
|
|
407
|
+
name?: string;
|
|
408
|
+
[k: string]: any;
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
export interface BookingCheckoutResult {
|
|
412
|
+
booking: Booking;
|
|
413
|
+
/** Anonymous guests, once (as for create). */
|
|
414
|
+
editToken?: string;
|
|
415
|
+
/** Go here to pay. null for a free booking, or a request (pay link once approved). */
|
|
416
|
+
checkoutUrl: string | null;
|
|
417
|
+
expiresAt: string | null;
|
|
418
|
+
/** Minor units; 0 when free. */
|
|
419
|
+
total: number;
|
|
420
|
+
currency: string | null;
|
|
421
|
+
/** A request waiting for approval: "we'll email you a link to pay once it's confirmed". */
|
|
422
|
+
request?: boolean;
|
|
423
|
+
}
|
|
424
|
+
export interface BookingPayLinkResult {
|
|
425
|
+
checkoutUrl?: string;
|
|
426
|
+
done?: 'paid' | 'closed';
|
|
427
|
+
url?: string | null;
|
|
428
|
+
}
|
|
429
|
+
export type BookingRefundResult = Booking & {
|
|
430
|
+
refunded: number;
|
|
431
|
+
refundPending: boolean;
|
|
432
|
+
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.2.
|
|
1
|
+
export declare const SDK_VERSION = "2.2.10";
|
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.10";
|