@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/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:
|
|
@@ -36400,6 +36649,70 @@ components:
|
|
|
36400
36649
|
- data
|
|
36401
36650
|
- hasMore
|
|
36402
36651
|
- next
|
|
36652
|
+
PaymentSyncInput:
|
|
36653
|
+
type: object
|
|
36654
|
+
properties:
|
|
36655
|
+
appId:
|
|
36656
|
+
type: string
|
|
36657
|
+
since:
|
|
36658
|
+
type: string
|
|
36659
|
+
after:
|
|
36660
|
+
type: string
|
|
36661
|
+
PaymentSyncResult:
|
|
36662
|
+
type: object
|
|
36663
|
+
properties:
|
|
36664
|
+
checked:
|
|
36665
|
+
type: number
|
|
36666
|
+
saved:
|
|
36667
|
+
type: number
|
|
36668
|
+
hasMore:
|
|
36669
|
+
type: boolean
|
|
36670
|
+
next:
|
|
36671
|
+
type: string
|
|
36672
|
+
required:
|
|
36673
|
+
- checked
|
|
36674
|
+
- saved
|
|
36675
|
+
- hasMore
|
|
36676
|
+
- next
|
|
36677
|
+
AppPaymentRecordData:
|
|
36678
|
+
type: object
|
|
36679
|
+
properties:
|
|
36680
|
+
paymentIntentId:
|
|
36681
|
+
type: string
|
|
36682
|
+
amount:
|
|
36683
|
+
type: number
|
|
36684
|
+
currency:
|
|
36685
|
+
type: string
|
|
36686
|
+
amountRefunded:
|
|
36687
|
+
type: number
|
|
36688
|
+
fee:
|
|
36689
|
+
type: number
|
|
36690
|
+
email:
|
|
36691
|
+
type: string
|
|
36692
|
+
reference:
|
|
36693
|
+
type: string
|
|
36694
|
+
metadata:
|
|
36695
|
+
type: object
|
|
36696
|
+
additionalProperties:
|
|
36697
|
+
type: string
|
|
36698
|
+
paidAt:
|
|
36699
|
+
type: string
|
|
36700
|
+
refundedAt:
|
|
36701
|
+
type: string
|
|
36702
|
+
dispute:
|
|
36703
|
+
type: object
|
|
36704
|
+
additionalProperties: true
|
|
36705
|
+
required:
|
|
36706
|
+
- paymentIntentId
|
|
36707
|
+
- amount
|
|
36708
|
+
- currency
|
|
36709
|
+
- amountRefunded
|
|
36710
|
+
- fee
|
|
36711
|
+
- email
|
|
36712
|
+
- reference
|
|
36713
|
+
- metadata
|
|
36714
|
+
- paidAt
|
|
36715
|
+
- refundedAt
|
|
36403
36716
|
PaymentDomainResult:
|
|
36404
36717
|
type: object
|
|
36405
36718
|
properties:
|
|
@@ -36413,6 +36726,14 @@ components:
|
|
|
36413
36726
|
- domain
|
|
36414
36727
|
- applePay
|
|
36415
36728
|
- googlePay
|
|
36729
|
+
AppPaymentStatus:
|
|
36730
|
+
type: string
|
|
36731
|
+
enum:
|
|
36732
|
+
- paid
|
|
36733
|
+
- partially_refunded
|
|
36734
|
+
- refunded
|
|
36735
|
+
- disputed
|
|
36736
|
+
- dispute_lost
|
|
36416
36737
|
ProductKey:
|
|
36417
36738
|
type: object
|
|
36418
36739
|
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>;
|