Edits history of script submission #12556 for ' Create customer (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Create customer
     * Creates a simple minimal representation of a customer. Payments, recurring mandates, and subscriptions can be linked to this customer object, which simplifies management of recurring payments.
    
    Once registered, customers will also appear in your Mollie dashboard.
    
    > 🔑 Access with
    >
    > API key
    >
    > Access token with **customers.write**
     */
    export async function main(
      auth: Mollie,
      body: {
        resource?: string;
        id?: string;
        mode?: string;
        name?: string;
        email?: string;
        locale?: string;
        metadata?: string | {} | string[];
        createdAt?: string;
        testmode?: false | true;
        _links?: {
          self?: { href?: string; type?: string };
          payments?: { href?: string; type?: string };
          mandates?: { href?: string; type?: string };
          subscriptions?: { href?: string; type?: string };
          documentation?: { href?: string; type?: string };
        };
      },
    ) {
      const url = new URL(`https://api.mollie.com/v2/customers`);
    
      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