Edits history of script submission #12554 for ' Create capture (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Create capture
     * **This feature is currently in open beta.
     */
    export async function main(
      auth: Mollie,
      paymentId: string,
      body: {
        resource?: string;
        id?: string;
        mode?: string;
        description?: string;
        amount?: { currency: string; value: string };
        settlementAmount?: { currency: string; value: string };
        status?: string;
        metadata?: string | {} | string[];
        paymentId?: string;
        shipmentId?: string;
        settlementId?: string;
        createdAt?: string;
        _links?: {
          self?: { href?: string; type?: string };
          payment?: { href?: string; type?: string };
          settlement?: { href?: string; type?: string };
          shipment?: { href?: string; type?: string };
          documentation?: { href?: string; type?: string };
        };
      },
    ) {
      const url = new URL(
        `https://api.mollie.com/v2/payments/${paymentId}/captures`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago