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

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Update payment
     * Certain details of an existing payment can be updated. For an in-depth explanation of each parameter, see [Create payment](create-payment).
    
    Updating the payment details will not result in a webhook call.
    
    > 🔑 Access with
    >
    > API key
    >
    > Access token with **payments.write**
     */
    export async function main(
      auth: Mollie,
      paymentId: string,
      body: {
        description?: string;
        redirectUrl?: string;
        cancelUrl?: string;
        webhookUrl?: string;
        metadata?: string | {} | string[];
        method?:
          | "alma"
          | "applepay"
          | "bacs"
          | "bancomatpay"
          | "bancontact"
          | "banktransfer"
          | "belfius"
          | "blik"
          | "creditcard"
          | "directdebit"
          | "eps"
          | "giftcard"
          | "ideal"
          | "in3"
          | "kbc"
          | "mbway"
          | "multibanco"
          | "mybank"
          | "payconiq"
          | "paypal"
          | "paysafecard"
          | "pointofsale"
          | "przelewy24"
          | "satispay"
          | "trustly"
          | "twint"
          | "voucher";
        locale?: string;
        restrictPaymentMethodsToCountry?: string;
        testmode?: false | true;
      },
    ) {
      const url = new URL(`https://api.mollie.com/v2/payments/${paymentId}`);
    
      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