@medalsocial/sdk 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -635,6 +635,20 @@ type BookingStatus = "pending" | "confirmed" | "completed" | "cancelled" | "no_s
635
635
  type BookingCancelledBy = "customer" | "staff" | "system";
636
636
  /** Payment state of a booking. */
637
637
  type BookingPaymentStatus = "none" | "reserved" | "captured" | "refunded";
638
+ /**
639
+ * What a booking must have paid before the business honours it: nothing, a
640
+ * reservation taken at booking time and captured later, or the full amount up
641
+ * front.
642
+ */
643
+ type BookingPaymentMode = "none" | "reserve" | "prepay";
644
+ /**
645
+ * The state of one attempt at paying for a booking.
646
+ *
647
+ * This is Medal's vocabulary, not the wallet's — a Vipps payment stays
648
+ * `AUTHORIZED` after a capture, so read the øre aggregates on
649
+ * {@link BookingPayment} to learn what actually moved.
650
+ */
651
+ type BookingPaymentState = "created" | "authorized" | "captured" | "cancelled" | "refunded" | "failed" | "expired";
638
652
  /** Surface a booking was created through. API-created bookings are `api`. */
639
653
  type BookingCreatedVia = "web" | "dashboard" | "walk_in" | "api";
640
654
  /** Kind of bookable resource a booking lands on. */
@@ -669,6 +683,13 @@ interface Booking {
669
683
  /** Set on the booking a reschedule created, pointing at the one it replaced. */
670
684
  rescheduled_from_id: string | null;
671
685
  payment_status: BookingPaymentStatus;
686
+ /**
687
+ * What this booking required when it was made — frozen at creation, so
688
+ * changing the workspace or service rule later does not rewrite history.
689
+ * `payment_status` alone cannot tell "owes nothing" from "has not paid yet";
690
+ * this is the field that does.
691
+ */
692
+ payment_mode: BookingPaymentMode;
672
693
  /** Price in integer øre. */
673
694
  amount_ore: number | null;
674
695
  /** Customer-visible note. */
@@ -694,6 +715,11 @@ interface BookingService {
694
715
  /** Resource types this service needs, e.g. `["staff"]`. */
695
716
  resource_requirements: string[];
696
717
  bookable_online: boolean;
718
+ /**
719
+ * Per-service payment requirement. `null` means "no override" — the
720
+ * workspace rule decides.
721
+ */
722
+ payment: BookingPaymentMode | null;
697
723
  max_per_booking: number | null;
698
724
  color: string | null;
699
725
  sort_order: number | null;
@@ -837,6 +863,12 @@ interface ManageSummary {
837
863
  /** Price in integer øre. */
838
864
  amount_ore: number | null;
839
865
  payment_status: BookingPaymentStatus | null;
866
+ /**
867
+ * What this booking requires. `payment_status: "none"` is the same answer
868
+ * for a booking that owes nothing and one that has not paid yet, so this is
869
+ * what a manage page checks before offering «Betal nå».
870
+ */
871
+ payment_mode: BookingPaymentMode;
840
872
  /** IANA zone the booking's local times should be rendered in. */
841
873
  time_zone: string | null;
842
874
  cancel_window_hours: number | null;
@@ -874,6 +906,78 @@ interface RescheduleBookingInput {
874
906
  new_start_ts: BookingTimestampInput;
875
907
  new_resource_id?: string;
876
908
  }
909
+ /**
910
+ * One payment attempt on a booking.
911
+ *
912
+ * Money is integer øre, and the four aggregates are numbers rather than nulls:
913
+ * "nothing has been captured" is `0`, so summing them never needs a null
914
+ * guard. `redirect_url` is deliberately absent — it is handed over once by
915
+ * {@link BookingPaymentStart} and never re-read.
916
+ */
917
+ interface BookingPayment {
918
+ reference: string;
919
+ provider: "vipps";
920
+ state: BookingPaymentState;
921
+ mode: Exclude<BookingPaymentMode, "none">;
922
+ /** 1 for the first attempt on this booking, incrementing per retry. */
923
+ attempt: number;
924
+ /** The amount the attempt is for, in integer øre. */
925
+ amount_ore: number;
926
+ authorized_ore: number;
927
+ captured_ore: number;
928
+ refunded_ore: number;
929
+ cancelled_ore: number;
930
+ currency: "NOK";
931
+ /**
932
+ * The last moment a capture is GUARANTEED to succeed. The card behind the
933
+ * wallet may release the reservation after this, so a capture past it can
934
+ * fail even though the payment still looks authorized. Null until the
935
+ * customer has approved.
936
+ */
937
+ capture_guaranteed_until: string | null;
938
+ terms_version: string | null;
939
+ terms_accepted_at: string | null;
940
+ /**
941
+ * The wallet's numeric error code from the last failed operation. Branch on
942
+ * this; the human-readable reason and the trace id stay in Medal's own logs.
943
+ */
944
+ failure_code: string | null;
945
+ created_at: string | null;
946
+ updated_at: string | null;
947
+ }
948
+ /** What `payment.start(...)` hands back. The redirect URL is shown ONCE. */
949
+ interface BookingPaymentStart {
950
+ reference: string;
951
+ /**
952
+ * Send the customer here UNCHANGED — hand it to the Vipps Widget SDK, do not
953
+ * put it in an iframe of your own and do not rewrite it. It is not returned
954
+ * again by `payment.get(...)`: the payment behind it expires after ten
955
+ * minutes, so a cached redirect leads into a payment that no longer exists.
956
+ * Start a new attempt instead of caching this.
957
+ */
958
+ redirect_url: string;
959
+ state: BookingPaymentState;
960
+ }
961
+ /** Input for `bookings.payment.start(...)` and its manage-token twin. */
962
+ interface StartBookingPaymentInput {
963
+ /**
964
+ * Where the wallet returns the customer. Must be a URL one of your own sites
965
+ * vouches for — anything else is refused with 422, not 400: the URL is
966
+ * well-formed, it is just not yours.
967
+ */
968
+ return_url: string;
969
+ /**
970
+ * REQUIRED, and must be `true`. The customer has to actively accept your
971
+ * terms BEFORE a payment is initiated — sending them to a payment link with
972
+ * no acceptance step makes the integration non-compliant, so the API refuses
973
+ * a body that omits it or sends `false` with a 400.
974
+ */
975
+ terms_accepted: true;
976
+ /** Your own version label for the terms they accepted. */
977
+ terms_version?: string;
978
+ /** The exact text they accepted, stored with the consent record. */
979
+ terms_text?: string;
980
+ }
877
981
  /**
878
982
  * Pagination for a bookings page.
879
983
  *
@@ -1034,6 +1138,62 @@ interface CreateBookingEventInput {
1034
1138
  resource_ids: string[];
1035
1139
  }
1036
1140
 
1141
+ /**
1142
+ * Payments on a booking addressed by BOOKING ID — the business starting or
1143
+ * inspecting a payment for one of its own bookings.
1144
+ *
1145
+ * The outcome reaches your system through Medal, never through the browser: a
1146
+ * customer can close the tab, hit back, or edit the return URL, so treat the
1147
+ * return redirect as a hint to re-read and nothing more. Poll {@link get} on
1148
+ * your return page, or read the booking's `payment_status`.
1149
+ *
1150
+ * @example
1151
+ * ```ts
1152
+ * const { data } = await medal.bookings.payment.start("bk_1", {
1153
+ * return_url: "https://example.no/retur",
1154
+ * terms_accepted: true,
1155
+ * });
1156
+ * // Hand data.redirect_url to the Vipps Widget SDK, unchanged.
1157
+ * ```
1158
+ */
1159
+ declare class BookingsPayment {
1160
+ private client;
1161
+ constructor(client: BaseClient);
1162
+ /**
1163
+ * Reserve (or charge) the booking's amount and get the wallet redirect.
1164
+ *
1165
+ * Automatically idempotent: the SDK mints an `Idempotency-Key` so its own
1166
+ * 5xx retries replay instead of reserving twice. One live payment per
1167
+ * booking — starting a second while one is outstanding answers 409; wait for
1168
+ * the first to be approved, aborted, or to expire (ten minutes).
1169
+ *
1170
+ * A `return_url` the workspace's own sites do not vouch for is refused with
1171
+ * 422, not 400: the URL parses, it is just not yours.
1172
+ */
1173
+ start(id: string, input: StartBookingPaymentInput, options?: RequestOptions): Promise<ApiResponse<BookingPaymentStart>>;
1174
+ /**
1175
+ * The newest payment attempt on the booking.
1176
+ *
1177
+ * Throws `MedalApiError` with status 404 when the booking has no payment at
1178
+ * all — "not started" and "unknown booking" answer alike, so this is not an
1179
+ * existence oracle. Earlier attempts are not returned; attempt N+1 is what
1180
+ * "the payment" means to a caller polling a retry.
1181
+ */
1182
+ get(id: string): Promise<ApiResponse<BookingPayment>>;
1183
+ }
1184
+ /**
1185
+ * The same two payment operations, authorized by the customer's manage token
1186
+ * instead of by booking id — for relaying a click on their own confirmation
1187
+ * link. Identical wire shapes; only the credential differs.
1188
+ */
1189
+ declare class BookingsManagePayment {
1190
+ private client;
1191
+ constructor(client: BaseClient);
1192
+ /** Start a payment on the customer's behalf. See {@link BookingsPayment.start}. */
1193
+ start(token: string, input: StartBookingPaymentInput, options?: RequestOptions): Promise<ApiResponse<BookingPaymentStart>>;
1194
+ /** Read the payment on the customer's own booking. 404 when there is none. */
1195
+ get(token: string): Promise<ApiResponse<BookingPayment>>;
1196
+ }
1037
1197
  /**
1038
1198
  * Customer-side booking management, addressed by the show-once manage token
1039
1199
  * from `bookings.create(...)` rather than by booking id.
@@ -1048,6 +1208,8 @@ interface CreateBookingEventInput {
1048
1208
  */
1049
1209
  declare class BookingsManage {
1050
1210
  private client;
1211
+ /** Payments authorized by the manage token rather than by booking id. */
1212
+ readonly payment: BookingsManagePayment;
1051
1213
  constructor(client: BaseClient);
1052
1214
  /**
1053
1215
  * Read what the holder of a manage token may see and do. Honour
@@ -1137,6 +1299,8 @@ declare class Bookings {
1137
1299
  readonly relations: BookingsRelations;
1138
1300
  /** Arrangementer — scheduled group sessions bookings register against. */
1139
1301
  readonly events: BookingsEvents;
1302
+ /** Vipps payments on a booking, as the business. */
1303
+ readonly payment: BookingsPayment;
1140
1304
  constructor(client: BaseClient);
1141
1305
  /** List the bookable service catalogue. Active-only unless asked otherwise. */
1142
1306
  listServices(options?: ListBookingServicesOptions): Promise<ApiResponse<BookingService[]>>;
@@ -2823,4 +2987,4 @@ declare class Medal {
2823
2987
  /** Convenience factory — equivalent to `new Medal(apiKey, options)`. */
2824
2988
  declare function createMedalClient(apiKey: string, options?: MedalOptions): Medal;
2825
2989
 
2826
- export { type Activity, type AddNoteInput, type ApiResponse, type AutoConfirmContext, type AutoConfirmOptions, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, type Booking, type BookingActionResult, type BookingAvailabilityOptions, type BookingCancelledBy, type BookingClaimableCreatedVia, type BookingContactInput, type BookingCreateResult, type BookingCreatedVia, type BookingEvent, type BookingEventStatus, type BookingEventTemplateKey, type BookingPaymentStatus, type BookingRescheduleResult, type BookingResource, type BookingResourceType, type BookingScheduleDay, type BookingScheduleOptions, type BookingService, type BookingSlot, type BookingStatus, type BookingTimestampInput, Bookings, type BookingsPage, type BookingsPagination, CAPABILITY_IDS, CAPABILITY_ROUTES, type CancelBookingInput, type CapabilityConfirmation, CapabilityConfirmations, CapabilityConfirmer, type CapabilityId, type CapabilityPathParamValue, type CapabilityRoute, type CapabilityWriteBodies, type CapabilityWriteRequest, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactPerson, type ContactRelation, type ContactRelations, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateBookingEventInput, type CreateBookingInput, type CreateBookingItemInput, type CreateConnectLinkInput, type CreateContactInput, type CreateContactPersonInput, type CreateContactRelationInput, type CreateContactRelationResult, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, type CreatedBooking, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type IssueCapabilityConfirmationInput, type ListBookingEventsOptions, type ListBookingServicesOptions, type ListBookingsOptions, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, type ManageSummary, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryStatus, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, Portal, type PortalBooking, type PortalBookingStatus, type PortalBookings, type PortalConsentRecord, type PortalContactSummary, type PortalExport, type PortalExportRelation, type PortalFamilyMember, type PortalLabels, type PortalLoginStartInput, type PortalLoginStartResult, type PortalPerson, type PortalProfile, type PortalProfilePatch, type PortalSession, type PortalVerifyInput, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type RelationType, type ReplyCreateResult, type RequestOptions, type RescheduleBookingInput, Scan, type ScanCompany, type ScanCreateInput, type ScanCreateResult, type ScanJob, type ScanResultPayload, type ScanStatus, type ScanSubScores, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type TestPingEvent, type UpdateBookingInput, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WaitForScanOptions, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };
2990
+ export { type Activity, type AddNoteInput, type ApiResponse, type AutoConfirmContext, type AutoConfirmOptions, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, type Booking, type BookingActionResult, type BookingAvailabilityOptions, type BookingCancelledBy, type BookingClaimableCreatedVia, type BookingContactInput, type BookingCreateResult, type BookingCreatedVia, type BookingEvent, type BookingEventStatus, type BookingEventTemplateKey, type BookingPayment, type BookingPaymentMode, type BookingPaymentStart, type BookingPaymentState, type BookingPaymentStatus, type BookingRescheduleResult, type BookingResource, type BookingResourceType, type BookingScheduleDay, type BookingScheduleOptions, type BookingService, type BookingSlot, type BookingStatus, type BookingTimestampInput, Bookings, type BookingsPage, type BookingsPagination, CAPABILITY_IDS, CAPABILITY_ROUTES, type CancelBookingInput, type CapabilityConfirmation, CapabilityConfirmations, CapabilityConfirmer, type CapabilityId, type CapabilityPathParamValue, type CapabilityRoute, type CapabilityWriteBodies, type CapabilityWriteRequest, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactPerson, type ContactRelation, type ContactRelations, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateBookingEventInput, type CreateBookingInput, type CreateBookingItemInput, type CreateConnectLinkInput, type CreateContactInput, type CreateContactPersonInput, type CreateContactRelationInput, type CreateContactRelationResult, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, type CreatedBooking, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type IssueCapabilityConfirmationInput, type ListBookingEventsOptions, type ListBookingServicesOptions, type ListBookingsOptions, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, type ManageSummary, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryStatus, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, Portal, type PortalBooking, type PortalBookingStatus, type PortalBookings, type PortalConsentRecord, type PortalContactSummary, type PortalExport, type PortalExportRelation, type PortalFamilyMember, type PortalLabels, type PortalLoginStartInput, type PortalLoginStartResult, type PortalPerson, type PortalProfile, type PortalProfilePatch, type PortalSession, type PortalVerifyInput, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type RelationType, type ReplyCreateResult, type RequestOptions, type RescheduleBookingInput, Scan, type ScanCompany, type ScanCreateInput, type ScanCreateResult, type ScanJob, type ScanResultPayload, type ScanStatus, type ScanSubScores, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type StartBookingPaymentInput, type TestPingEvent, type UpdateBookingInput, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WaitForScanOptions, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };
@@ -635,6 +635,20 @@ type BookingStatus = "pending" | "confirmed" | "completed" | "cancelled" | "no_s
635
635
  type BookingCancelledBy = "customer" | "staff" | "system";
636
636
  /** Payment state of a booking. */
637
637
  type BookingPaymentStatus = "none" | "reserved" | "captured" | "refunded";
638
+ /**
639
+ * What a booking must have paid before the business honours it: nothing, a
640
+ * reservation taken at booking time and captured later, or the full amount up
641
+ * front.
642
+ */
643
+ type BookingPaymentMode = "none" | "reserve" | "prepay";
644
+ /**
645
+ * The state of one attempt at paying for a booking.
646
+ *
647
+ * This is Medal's vocabulary, not the wallet's — a Vipps payment stays
648
+ * `AUTHORIZED` after a capture, so read the øre aggregates on
649
+ * {@link BookingPayment} to learn what actually moved.
650
+ */
651
+ type BookingPaymentState = "created" | "authorized" | "captured" | "cancelled" | "refunded" | "failed" | "expired";
638
652
  /** Surface a booking was created through. API-created bookings are `api`. */
639
653
  type BookingCreatedVia = "web" | "dashboard" | "walk_in" | "api";
640
654
  /** Kind of bookable resource a booking lands on. */
@@ -669,6 +683,13 @@ interface Booking {
669
683
  /** Set on the booking a reschedule created, pointing at the one it replaced. */
670
684
  rescheduled_from_id: string | null;
671
685
  payment_status: BookingPaymentStatus;
686
+ /**
687
+ * What this booking required when it was made — frozen at creation, so
688
+ * changing the workspace or service rule later does not rewrite history.
689
+ * `payment_status` alone cannot tell "owes nothing" from "has not paid yet";
690
+ * this is the field that does.
691
+ */
692
+ payment_mode: BookingPaymentMode;
672
693
  /** Price in integer øre. */
673
694
  amount_ore: number | null;
674
695
  /** Customer-visible note. */
@@ -694,6 +715,11 @@ interface BookingService {
694
715
  /** Resource types this service needs, e.g. `["staff"]`. */
695
716
  resource_requirements: string[];
696
717
  bookable_online: boolean;
718
+ /**
719
+ * Per-service payment requirement. `null` means "no override" — the
720
+ * workspace rule decides.
721
+ */
722
+ payment: BookingPaymentMode | null;
697
723
  max_per_booking: number | null;
698
724
  color: string | null;
699
725
  sort_order: number | null;
@@ -837,6 +863,12 @@ interface ManageSummary {
837
863
  /** Price in integer øre. */
838
864
  amount_ore: number | null;
839
865
  payment_status: BookingPaymentStatus | null;
866
+ /**
867
+ * What this booking requires. `payment_status: "none"` is the same answer
868
+ * for a booking that owes nothing and one that has not paid yet, so this is
869
+ * what a manage page checks before offering «Betal nå».
870
+ */
871
+ payment_mode: BookingPaymentMode;
840
872
  /** IANA zone the booking's local times should be rendered in. */
841
873
  time_zone: string | null;
842
874
  cancel_window_hours: number | null;
@@ -874,6 +906,78 @@ interface RescheduleBookingInput {
874
906
  new_start_ts: BookingTimestampInput;
875
907
  new_resource_id?: string;
876
908
  }
909
+ /**
910
+ * One payment attempt on a booking.
911
+ *
912
+ * Money is integer øre, and the four aggregates are numbers rather than nulls:
913
+ * "nothing has been captured" is `0`, so summing them never needs a null
914
+ * guard. `redirect_url` is deliberately absent — it is handed over once by
915
+ * {@link BookingPaymentStart} and never re-read.
916
+ */
917
+ interface BookingPayment {
918
+ reference: string;
919
+ provider: "vipps";
920
+ state: BookingPaymentState;
921
+ mode: Exclude<BookingPaymentMode, "none">;
922
+ /** 1 for the first attempt on this booking, incrementing per retry. */
923
+ attempt: number;
924
+ /** The amount the attempt is for, in integer øre. */
925
+ amount_ore: number;
926
+ authorized_ore: number;
927
+ captured_ore: number;
928
+ refunded_ore: number;
929
+ cancelled_ore: number;
930
+ currency: "NOK";
931
+ /**
932
+ * The last moment a capture is GUARANTEED to succeed. The card behind the
933
+ * wallet may release the reservation after this, so a capture past it can
934
+ * fail even though the payment still looks authorized. Null until the
935
+ * customer has approved.
936
+ */
937
+ capture_guaranteed_until: string | null;
938
+ terms_version: string | null;
939
+ terms_accepted_at: string | null;
940
+ /**
941
+ * The wallet's numeric error code from the last failed operation. Branch on
942
+ * this; the human-readable reason and the trace id stay in Medal's own logs.
943
+ */
944
+ failure_code: string | null;
945
+ created_at: string | null;
946
+ updated_at: string | null;
947
+ }
948
+ /** What `payment.start(...)` hands back. The redirect URL is shown ONCE. */
949
+ interface BookingPaymentStart {
950
+ reference: string;
951
+ /**
952
+ * Send the customer here UNCHANGED — hand it to the Vipps Widget SDK, do not
953
+ * put it in an iframe of your own and do not rewrite it. It is not returned
954
+ * again by `payment.get(...)`: the payment behind it expires after ten
955
+ * minutes, so a cached redirect leads into a payment that no longer exists.
956
+ * Start a new attempt instead of caching this.
957
+ */
958
+ redirect_url: string;
959
+ state: BookingPaymentState;
960
+ }
961
+ /** Input for `bookings.payment.start(...)` and its manage-token twin. */
962
+ interface StartBookingPaymentInput {
963
+ /**
964
+ * Where the wallet returns the customer. Must be a URL one of your own sites
965
+ * vouches for — anything else is refused with 422, not 400: the URL is
966
+ * well-formed, it is just not yours.
967
+ */
968
+ return_url: string;
969
+ /**
970
+ * REQUIRED, and must be `true`. The customer has to actively accept your
971
+ * terms BEFORE a payment is initiated — sending them to a payment link with
972
+ * no acceptance step makes the integration non-compliant, so the API refuses
973
+ * a body that omits it or sends `false` with a 400.
974
+ */
975
+ terms_accepted: true;
976
+ /** Your own version label for the terms they accepted. */
977
+ terms_version?: string;
978
+ /** The exact text they accepted, stored with the consent record. */
979
+ terms_text?: string;
980
+ }
877
981
  /**
878
982
  * Pagination for a bookings page.
879
983
  *
@@ -1034,6 +1138,62 @@ interface CreateBookingEventInput {
1034
1138
  resource_ids: string[];
1035
1139
  }
1036
1140
 
1141
+ /**
1142
+ * Payments on a booking addressed by BOOKING ID — the business starting or
1143
+ * inspecting a payment for one of its own bookings.
1144
+ *
1145
+ * The outcome reaches your system through Medal, never through the browser: a
1146
+ * customer can close the tab, hit back, or edit the return URL, so treat the
1147
+ * return redirect as a hint to re-read and nothing more. Poll {@link get} on
1148
+ * your return page, or read the booking's `payment_status`.
1149
+ *
1150
+ * @example
1151
+ * ```ts
1152
+ * const { data } = await medal.bookings.payment.start("bk_1", {
1153
+ * return_url: "https://example.no/retur",
1154
+ * terms_accepted: true,
1155
+ * });
1156
+ * // Hand data.redirect_url to the Vipps Widget SDK, unchanged.
1157
+ * ```
1158
+ */
1159
+ declare class BookingsPayment {
1160
+ private client;
1161
+ constructor(client: BaseClient);
1162
+ /**
1163
+ * Reserve (or charge) the booking's amount and get the wallet redirect.
1164
+ *
1165
+ * Automatically idempotent: the SDK mints an `Idempotency-Key` so its own
1166
+ * 5xx retries replay instead of reserving twice. One live payment per
1167
+ * booking — starting a second while one is outstanding answers 409; wait for
1168
+ * the first to be approved, aborted, or to expire (ten minutes).
1169
+ *
1170
+ * A `return_url` the workspace's own sites do not vouch for is refused with
1171
+ * 422, not 400: the URL parses, it is just not yours.
1172
+ */
1173
+ start(id: string, input: StartBookingPaymentInput, options?: RequestOptions): Promise<ApiResponse<BookingPaymentStart>>;
1174
+ /**
1175
+ * The newest payment attempt on the booking.
1176
+ *
1177
+ * Throws `MedalApiError` with status 404 when the booking has no payment at
1178
+ * all — "not started" and "unknown booking" answer alike, so this is not an
1179
+ * existence oracle. Earlier attempts are not returned; attempt N+1 is what
1180
+ * "the payment" means to a caller polling a retry.
1181
+ */
1182
+ get(id: string): Promise<ApiResponse<BookingPayment>>;
1183
+ }
1184
+ /**
1185
+ * The same two payment operations, authorized by the customer's manage token
1186
+ * instead of by booking id — for relaying a click on their own confirmation
1187
+ * link. Identical wire shapes; only the credential differs.
1188
+ */
1189
+ declare class BookingsManagePayment {
1190
+ private client;
1191
+ constructor(client: BaseClient);
1192
+ /** Start a payment on the customer's behalf. See {@link BookingsPayment.start}. */
1193
+ start(token: string, input: StartBookingPaymentInput, options?: RequestOptions): Promise<ApiResponse<BookingPaymentStart>>;
1194
+ /** Read the payment on the customer's own booking. 404 when there is none. */
1195
+ get(token: string): Promise<ApiResponse<BookingPayment>>;
1196
+ }
1037
1197
  /**
1038
1198
  * Customer-side booking management, addressed by the show-once manage token
1039
1199
  * from `bookings.create(...)` rather than by booking id.
@@ -1048,6 +1208,8 @@ interface CreateBookingEventInput {
1048
1208
  */
1049
1209
  declare class BookingsManage {
1050
1210
  private client;
1211
+ /** Payments authorized by the manage token rather than by booking id. */
1212
+ readonly payment: BookingsManagePayment;
1051
1213
  constructor(client: BaseClient);
1052
1214
  /**
1053
1215
  * Read what the holder of a manage token may see and do. Honour
@@ -1137,6 +1299,8 @@ declare class Bookings {
1137
1299
  readonly relations: BookingsRelations;
1138
1300
  /** Arrangementer — scheduled group sessions bookings register against. */
1139
1301
  readonly events: BookingsEvents;
1302
+ /** Vipps payments on a booking, as the business. */
1303
+ readonly payment: BookingsPayment;
1140
1304
  constructor(client: BaseClient);
1141
1305
  /** List the bookable service catalogue. Active-only unless asked otherwise. */
1142
1306
  listServices(options?: ListBookingServicesOptions): Promise<ApiResponse<BookingService[]>>;
@@ -2823,4 +2987,4 @@ declare class Medal {
2823
2987
  /** Convenience factory — equivalent to `new Medal(apiKey, options)`. */
2824
2988
  declare function createMedalClient(apiKey: string, options?: MedalOptions): Medal;
2825
2989
 
2826
- export { type Activity, type AddNoteInput, type ApiResponse, type AutoConfirmContext, type AutoConfirmOptions, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, type Booking, type BookingActionResult, type BookingAvailabilityOptions, type BookingCancelledBy, type BookingClaimableCreatedVia, type BookingContactInput, type BookingCreateResult, type BookingCreatedVia, type BookingEvent, type BookingEventStatus, type BookingEventTemplateKey, type BookingPaymentStatus, type BookingRescheduleResult, type BookingResource, type BookingResourceType, type BookingScheduleDay, type BookingScheduleOptions, type BookingService, type BookingSlot, type BookingStatus, type BookingTimestampInput, Bookings, type BookingsPage, type BookingsPagination, CAPABILITY_IDS, CAPABILITY_ROUTES, type CancelBookingInput, type CapabilityConfirmation, CapabilityConfirmations, CapabilityConfirmer, type CapabilityId, type CapabilityPathParamValue, type CapabilityRoute, type CapabilityWriteBodies, type CapabilityWriteRequest, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactPerson, type ContactRelation, type ContactRelations, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateBookingEventInput, type CreateBookingInput, type CreateBookingItemInput, type CreateConnectLinkInput, type CreateContactInput, type CreateContactPersonInput, type CreateContactRelationInput, type CreateContactRelationResult, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, type CreatedBooking, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type IssueCapabilityConfirmationInput, type ListBookingEventsOptions, type ListBookingServicesOptions, type ListBookingsOptions, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, type ManageSummary, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryStatus, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, Portal, type PortalBooking, type PortalBookingStatus, type PortalBookings, type PortalConsentRecord, type PortalContactSummary, type PortalExport, type PortalExportRelation, type PortalFamilyMember, type PortalLabels, type PortalLoginStartInput, type PortalLoginStartResult, type PortalPerson, type PortalProfile, type PortalProfilePatch, type PortalSession, type PortalVerifyInput, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type RelationType, type ReplyCreateResult, type RequestOptions, type RescheduleBookingInput, Scan, type ScanCompany, type ScanCreateInput, type ScanCreateResult, type ScanJob, type ScanResultPayload, type ScanStatus, type ScanSubScores, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type TestPingEvent, type UpdateBookingInput, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WaitForScanOptions, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };
2990
+ export { type Activity, type AddNoteInput, type ApiResponse, type AutoConfirmContext, type AutoConfirmOptions, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, type Booking, type BookingActionResult, type BookingAvailabilityOptions, type BookingCancelledBy, type BookingClaimableCreatedVia, type BookingContactInput, type BookingCreateResult, type BookingCreatedVia, type BookingEvent, type BookingEventStatus, type BookingEventTemplateKey, type BookingPayment, type BookingPaymentMode, type BookingPaymentStart, type BookingPaymentState, type BookingPaymentStatus, type BookingRescheduleResult, type BookingResource, type BookingResourceType, type BookingScheduleDay, type BookingScheduleOptions, type BookingService, type BookingSlot, type BookingStatus, type BookingTimestampInput, Bookings, type BookingsPage, type BookingsPagination, CAPABILITY_IDS, CAPABILITY_ROUTES, type CancelBookingInput, type CapabilityConfirmation, CapabilityConfirmations, CapabilityConfirmer, type CapabilityId, type CapabilityPathParamValue, type CapabilityRoute, type CapabilityWriteBodies, type CapabilityWriteRequest, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactPerson, type ContactRelation, type ContactRelations, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateBookingEventInput, type CreateBookingInput, type CreateBookingItemInput, type CreateConnectLinkInput, type CreateContactInput, type CreateContactPersonInput, type CreateContactRelationInput, type CreateContactRelationResult, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, type CreatedBooking, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type IssueCapabilityConfirmationInput, type ListBookingEventsOptions, type ListBookingServicesOptions, type ListBookingsOptions, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, type ManageSummary, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryStatus, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, Portal, type PortalBooking, type PortalBookingStatus, type PortalBookings, type PortalConsentRecord, type PortalContactSummary, type PortalExport, type PortalExportRelation, type PortalFamilyMember, type PortalLabels, type PortalLoginStartInput, type PortalLoginStartResult, type PortalPerson, type PortalProfile, type PortalProfilePatch, type PortalSession, type PortalVerifyInput, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type RelationType, type ReplyCreateResult, type RequestOptions, type RescheduleBookingInput, Scan, type ScanCompany, type ScanCreateInput, type ScanCreateResult, type ScanJob, type ScanResultPayload, type ScanStatus, type ScanSubScores, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type StartBookingPaymentInput, type TestPingEvent, type UpdateBookingInput, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WaitForScanOptions, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };
package/dist/src/index.js CHANGED
@@ -340,11 +340,67 @@ var CapabilityConfirmer = class {
340
340
  };
341
341
 
342
342
  // src/resources/bookings.ts
343
+ var BookingsPayment = class {
344
+ constructor(client) {
345
+ this.client = client;
346
+ }
347
+ client;
348
+ /**
349
+ * Reserve (or charge) the booking's amount and get the wallet redirect.
350
+ *
351
+ * Automatically idempotent: the SDK mints an `Idempotency-Key` so its own
352
+ * 5xx retries replay instead of reserving twice. One live payment per
353
+ * booking — starting a second while one is outstanding answers 409; wait for
354
+ * the first to be approved, aborted, or to expire (ten minutes).
355
+ *
356
+ * A `return_url` the workspace's own sites do not vouch for is refused with
357
+ * 422, not 400: the URL parses, it is just not yours.
358
+ */
359
+ async start(id, input, options) {
360
+ return this.client.postOnce(
361
+ `/api/v1/bookings/${encodeURIComponent(id)}/payment`,
362
+ input,
363
+ options
364
+ );
365
+ }
366
+ /**
367
+ * The newest payment attempt on the booking.
368
+ *
369
+ * Throws `MedalApiError` with status 404 when the booking has no payment at
370
+ * all — "not started" and "unknown booking" answer alike, so this is not an
371
+ * existence oracle. Earlier attempts are not returned; attempt N+1 is what
372
+ * "the payment" means to a caller polling a retry.
373
+ */
374
+ async get(id) {
375
+ return this.client.get(`/api/v1/bookings/${encodeURIComponent(id)}/payment`);
376
+ }
377
+ };
378
+ var BookingsManagePayment = class {
379
+ constructor(client) {
380
+ this.client = client;
381
+ }
382
+ client;
383
+ /** Start a payment on the customer's behalf. See {@link BookingsPayment.start}. */
384
+ async start(token, input, options) {
385
+ return this.client.postOnce(
386
+ `/api/v1/bookings/manage/${encodeURIComponent(token)}/payment`,
387
+ input,
388
+ options
389
+ );
390
+ }
391
+ /** Read the payment on the customer's own booking. 404 when there is none. */
392
+ async get(token) {
393
+ return this.client.get(`/api/v1/bookings/manage/${encodeURIComponent(token)}/payment`);
394
+ }
395
+ };
343
396
  var BookingsManage = class {
344
397
  constructor(client) {
345
398
  this.client = client;
399
+ this.payment = new BookingsManagePayment(client);
346
400
  }
347
401
  client;
402
+ /** Payments authorized by the manage token rather than by booking id. */
403
+ payment;
348
404
  /**
349
405
  * Read what the holder of a manage token may see and do. Honour
350
406
  * `can_cancel` / `can_reschedule` — they already apply the policy windows.
@@ -432,6 +488,7 @@ var Bookings = class {
432
488
  this.persons = new BookingsPersons(client);
433
489
  this.relations = new BookingsRelations(client);
434
490
  this.events = new BookingsEvents(client);
491
+ this.payment = new BookingsPayment(client);
435
492
  }
436
493
  client;
437
494
  /** Customer-side actions addressed by manage token. */
@@ -442,6 +499,8 @@ var Bookings = class {
442
499
  relations;
443
500
  /** Arrangementer — scheduled group sessions bookings register against. */
444
501
  events;
502
+ /** Vipps payments on a booking, as the business. */
503
+ payment;
445
504
  /** List the bookable service catalogue. Active-only unless asked otherwise. */
446
505
  async listServices(options) {
447
506
  const params = {};