0

Add a payment method

by
Published Oct 17, 2025

Adds a Payment Method to your Account with the option to set it as the default method.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Add a payment method
7
 * Adds a Payment Method to your Account with the option to set it as the default method.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  body: {
13
    data: {
14
      card_number: string;
15
      cvv: string;
16
      expiry_month: number;
17
      expiry_year: number;
18
    };
19
    is_default: false | true;
20
    type: "credit_card";
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.linode.com/${apiVersion}/account/payment-methods`,
25
  );
26

27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41