Edits history of script submission #16808 for ' Add or edit a credit card (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Add or edit a credit card
     * __Deprecated__ Please run [Add a payment method](https://techdocs.akamai.com/linode-api/reference/post-payment-method).
    
    Adds a credit card Payment Method to your account and sets it as the default method.
    
    
    >
    
    ---
    
    
    - __OAuth scopes__.
    
        ```
        account:read_write
        ```
    
        [Learn more...](https://techdocs.akamai.com/linode-api/reference/get-started#oauth)
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      body: {
        card_number: string;
        cvv: string;
        expiry_month: number;
        expiry_year: number;
      },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/account/credit-card`,
      );
    
      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.json();
    }
    

    Submitted by hugo697 235 days ago