Edits history of script submission #12583 for ' Get mandate (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Get mandate
     * Retrieve a single mandate by its ID. Depending on the type of mandate, the object will contain the customer's bank account details, card details, or PayPal account details.
    
    > 🔑 Access with
    >
    > API key
    >
    > Access token with **mandates.read**
     */
    export async function main(
      auth: Mollie,
      customerId: string,
      id: string,
      testmode: string | undefined,
    ) {
      const url = new URL(
        `https://api.mollie.com/v2/customers/${customerId}/mandates/${id}`,
      );
      for (const [k, v] of [["testmode", testmode]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago