Edits history of script submission #12563 for ' Create payment link (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Create payment link
     * With the Payment links API you can generate payment links that by default, unlike regular payments, do not expire. The payment link can be shared with your customers and will redirect them to them the payment page where they can complete the payment. A [payment](get-payment) will only be created once the customer initiates the payment.
    
    > 🔑 Access with
    >
    > API key
    >
    > Access token with **payment-links.write**
     */
    export async function main(
      auth: Mollie,
      body: {
        resource?: string;
        id?: string;
        mode?: string;
        description: string;
        amount?: { currency: string; value: string };
        minimumAmount?: { currency: string; value: string };
        archived?: false | true;
        redirectUrl?: string;
        webhookUrl?: string;
        profileId?: string;
        reusable?: false | true;
        createdAt?: string;
        paidAt?: string;
        expiresAt?: string;
        allowedMethods?:
          | "applepay"
          | "bancomatpay"
          | "bancontact"
          | "banktransfer"
          | "belfius"
          | "blik"
          | "creditcard"
          | "eps"
          | "giftcard"
          | "ideal"
          | "kbc"
          | "mybank"
          | "paybybank"
          | "paypal"
          | "paysafecard"
          | "pointofsale"
          | "przelewy24"
          | "satispay"
          | "trustly"
          | "twint"[];
        sequenceType?: "oneoff" | "first" | "recurring";
        customerId?: string;
        applicationFee?: {
          amount?: { currency: string; value: string };
          description?: string;
        };
        _links?: {
          self?: { href?: string; type?: string };
          paymentLink?: { href?: string; type?: string };
          documentation?: { href?: string; type?: string };
        };
      },
    ) {
      const url = new URL(`https://api.mollie.com/v2/payment-links`);
    
      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