Edits history of script submission #12635 for ' Manage order lines (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Manage order lines
     * **⚠️ We no longer recommend implementing the Orders API.
     */
    export async function main(
      auth: Mollie,
      orderId: string,
      body: {
        operations: {
          operation: string;
          data: {
            id?: string;
            quantity?: number;
            amount?: { currency: string; value: string };
          };
        }[];
        testmode?: false | true;
      },
    ) {
      const url = new URL(`https://api.mollie.com/v2/orders/${orderId}/lines`);
    
      const response = await fetch(url, {
        method: "PATCH",
        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