Retrieves a single payment
One script reply has been approved by the moderators Verified

Retrieves the payment information for an existing payment

Created by hugo697 883 days ago Picked 1 time
Submitted by hugo697 Typescript (fetch-only)
Verified 337 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Retrieves a single payment
7
 * Retrieves the payment information for an existing payment
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  token: string,
13
  payment_id: string
14
) {
15
  const url = new URL(
16
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/checkouts/${token}/payments/${payment_id}.json`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      "X-Shopify-Access-Token": auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32