0

Apple Pay Tokenize

by
Published Oct 17, 2025

Apple Pay Tokenize

Script basis_theory Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Basistheory = {
3
  apiKey: string;
4
};
5
/**
6
 * Apple Pay Tokenize
7
 * Apple Pay Tokenize
8
 */
9
export async function main(
10
  auth: Basistheory,
11
  body: {
12
    apple_payment_method_token?: {
13
      paymentData?: {
14
        data?: string;
15
        header?: {
16
          applicationData?: string;
17
          ephemeralPublicKey?: string;
18
          publicKeyHash?: string;
19
          transactionId?: string;
20
        };
21
        signature?: string;
22
        version?: string;
23
      };
24
      transactionIdentifier?: string;
25
    };
26
  },
27
) {
28
  const url = new URL(
29
    `https://api.basistheory.com/connections/apple-pay/tokenize`,
30
  );
31

32
  const response = await fetch(url, {
33
    method: "POST",
34
    headers: {
35
      "Content-Type": "application/json",
36
      "BT-API-KEY": auth.apiKey,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46