export type PaymentProvisionalStatus = 'Paid' | 'Pending' | 'Failed'; export type PaymentSessionId = string; export type SessionOutcome = {status?: PaymentProvisionalStatus | undefined, payment_reference?: PaymentSessionId | undefined, paid_at?: string | undefined}; export type PatchApiSubmissionSubmissionIdPaymentArgs = {body: SessionOutcome}; export type PatchApiSubmissionSubmissionIdPaymentOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Update submission with payment session final outcome * * PATCH /submission/{submission-id}/payment */ export const patchApiSubmissionSubmissionIdPayment = async (args: PatchApiSubmissionSubmissionIdPaymentArgs, options: PatchApiSubmissionSubmissionIdPaymentOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/submission/${encodeURIComponent(String(args['submission-id']))}/payment${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };