Edits history of script submission #12574 for ' Enable payment method issuer (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Enable payment method issuer
     * Enable an issuer for a payment method on a specific profile.
    
    Currently only the payment methods `voucher` and `giftcard` are supported.
    
    When using a profile-specific API credential, the alias `me` can be used instead of the profile ID to refer to the current profile.
    
    > 🔑 Access with
    >
    > API key
    >
    > Access token with **profiles.write**
     */
    export async function main(
      auth: Mollie,
      profileId: string,
      methodId: "voucher" | "giftcard",
      id: string,
      body: { contractId?: string },
    ) {
      const url = new URL(
        `https://api.mollie.com/v2/profiles/${profileId}/methods/${methodId}/issuers/${id}`,
      );
    
      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