Edits history of script submission #12644 for ' Update payment link (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Update payment link
     * Certain details of an existing payment link can be updated.
    
    > 🔑 Access with
    >
    > API key
    >
    > Access token with **payment-links.write**
     */
    export async function main(
      auth: Mollie,
      paymentLinkId: string,
      testmode: string | undefined,
      body: {
        description?: string;
        minimumAmount?: { currency: string; value: string };
        archived?: false | true;
        allowedMethods?:
          | "applepay"
          | "bancomatpay"
          | "bancontact"
          | "banktransfer"
          | "belfius"
          | "blik"
          | "creditcard"
          | "eps"
          | "giftcard"
          | "ideal"
          | "kbc"
          | "mybank"
          | "paybybank"
          | "paypal"
          | "paysafecard"
          | "pointofsale"
          | "przelewy24"
          | "satispay"
          | "trustly"
          | "twint"[];
      },
    ) {
      const url = new URL(
        `https://api.mollie.com/v2/payment-links/${paymentLinkId}`,
      );
      for (const [k, v] of [["testmode", testmode]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      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