Activates an application charge
One script reply has been approved by the moderators Verified

Activates an accepted application charge

Created by hugo697 883 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 337 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Activates an application charge
7
 * Activates an accepted application charge
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  application_charge_id: string,
13
  body: {
14
    application_charge?: {
15
      api_client_id?: number;
16
      charge_type?: { [k: string]: unknown };
17
      created_at?: string;
18
      decorated_return_url?: string;
19
      id?: number;
20
      name?: string;
21
      price?: string;
22
      return_url?: string;
23
      status?: string;
24
      test?: { [k: string]: unknown };
25
      updated_at?: string;
26
      [k: string]: unknown;
27
    };
28
    [k: string]: unknown;
29
  }
30
) {
31
  const url = new URL(
32
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/application_charges/${application_charge_id}/activate.json`
33
  );
34

35
  const response = await fetch(url, {
36
    method: "POST",
37
    headers: {
38
      "Content-Type": "application/json",
39
      "X-Shopify-Access-Token": auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49