// Refunds. import { collect, request, segment } from "./stripe" import type { Client, Page, RequestOptions, StripeError } from "./stripe" /// A refund. `charge` and `payment_intent` are expandable: `idOf` gives their ids. export type Refund = { id: string, amount: float, currency: string, status?: string, reason?: string, charge?: json, payment_intent?: json, failure_reason?: string, receipt_number?: string, metadata?: json, created?: float, } /// A new refund of a `payment_intent` or a `charge`: all of it unless `amount` is given. export type RefundParams = { payment_intent?: string, charge?: string, amount?: float, reason?: "duplicate" | "fraudulent" | "requested_by_customer", metadata?: Map, refund_application_fee?: boolean, reverse_transfer?: boolean, extra?: json, } /// What to list. export type RefundListParams = { payment_intent?: string, charge?: string, limit?: float, starting_after?: string, ending_before?: string, extra?: json, } /// Refunds a payment. export async fn create( c: Client, params: RefundParams, options: RequestOptions = {}, ): Refund ! StripeError { return try await request(c, "POST", "/v1/refunds", params, options, j => try j as Refund) } /// Gets a refund by id. export async fn retrieve( c: Client, id: string, options: RequestOptions = {}, ): Refund ! StripeError { return try await request( c, "GET", `/v1/refunds/${segment(id)}`, null, options, j => try j as Refund, ) } /// One page of refunds, newest first. export async fn list(c: Client, params: RefundListParams = {}, options: RequestOptions = {}): Page< Refund, > ! StripeError { return try await request(c, "GET", "/v1/refunds", params, options, j => try j as Page) } /// Every refund matching `params`, up to `max`. export async fn listAll( c: Client, params: RefundListParams = {}, options: RequestOptions = {}, max: int = 10000, ): Refund[] ! StripeError { return try await collect( c, "/v1/refunds", params, options, j => try j as Page, x => x.id, max, ) }