1 | |
2 | type Basistheory = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Three DS.Authenticate Session |
7 | * Three DS.Authenticate Session |
8 | */ |
9 | export async function main( |
10 | auth: Basistheory, |
11 | sessionId: string, |
12 | body: { |
13 | authentication_category?: string; |
14 | authentication_type?: string; |
15 | broadcast_info?: { nullable?: false | true }; |
16 | cardholder_info?: { |
17 | account_id?: string; |
18 | account_info?: { |
19 | account_age?: string; |
20 | account_change_date?: string; |
21 | account_created_date?: string; |
22 | account_last_changed?: string; |
23 | account_pwd_change_date?: string; |
24 | account_pwd_last_changed?: string; |
25 | payment_account_age?: string; |
26 | payment_account_created?: string; |
27 | purchase_count_half_year?: string; |
28 | shipping_account_name_match?: string; |
29 | shipping_address_first_used?: string; |
30 | shipping_address_usage_date?: string; |
31 | suspicious_activity_observed?: string; |
32 | transaction_count_day?: string; |
33 | transaction_count_year?: string; |
34 | }; |
35 | account_type?: string; |
36 | authentication_info?: { |
37 | data?: string; |
38 | method?: string; |
39 | timestamp?: string; |
40 | }; |
41 | billing_address?: { |
42 | city?: string; |
43 | country_code?: string; |
44 | line1?: string; |
45 | line2?: string; |
46 | line3?: string; |
47 | postal_code?: string; |
48 | state_code?: string; |
49 | }; |
50 | billing_shipping_address_match?: string; |
51 | email?: string; |
52 | mobile_phone_number?: { country_code?: string; number?: string }; |
53 | name?: string; |
54 | phone_number?: { country_code?: string; number?: string }; |
55 | prior_authentication_info?: { |
56 | data?: string; |
57 | method?: string; |
58 | reference_id?: string; |
59 | timestamp?: string; |
60 | }; |
61 | shipping_address?: { |
62 | city?: string; |
63 | country_code?: string; |
64 | line1?: string; |
65 | line2?: string; |
66 | line3?: string; |
67 | postal_code?: string; |
68 | state_code?: string; |
69 | }; |
70 | work_phone_number?: { country_code?: string; number?: string }; |
71 | }; |
72 | challenge_preference?: string; |
73 | decoupled_challenge_max_time?: string; |
74 | merchant_info?: { |
75 | acquirer_bin?: string; |
76 | category_code?: string; |
77 | country_code?: string; |
78 | mid?: string; |
79 | name?: string; |
80 | risk_info?: { |
81 | delivery_email?: string; |
82 | delivery_time_frame?: string; |
83 | gift_card_amount?: string; |
84 | gift_card_count?: string; |
85 | gift_card_currency?: string; |
86 | pre_order_date?: string; |
87 | pre_order_purchase?: string; |
88 | reordered_purchase?: string; |
89 | shipping_method?: string; |
90 | }; |
91 | url?: string; |
92 | }; |
93 | message_extensions?: { |
94 | critical?: string; |
95 | data?: { nullable?: false | true }; |
96 | id?: string; |
97 | name?: string; |
98 | }[]; |
99 | purchase_info?: { |
100 | amount?: string; |
101 | currency?: string; |
102 | date?: string; |
103 | exponent?: string; |
104 | installment_count?: string; |
105 | recurring_expiration?: string; |
106 | recurring_frequency?: string; |
107 | transaction_type?: string; |
108 | }; |
109 | request_decoupled_challenge?: string; |
110 | requestor_info?: { |
111 | amex_requestor_type?: string; |
112 | cb_siret_number?: string; |
113 | discover_client_id?: string; |
114 | discover_requestor_id?: string; |
115 | id?: string; |
116 | name?: string; |
117 | url?: string; |
118 | }; |
119 | }, |
120 | ) { |
121 | const url = new URL( |
122 | `https://api.basistheory.com/3ds/sessions/${sessionId}/authenticate`, |
123 | ); |
124 |
|
125 | const response = await fetch(url, { |
126 | method: "POST", |
127 | headers: { |
128 | "Content-Type": "application/json", |
129 | "BT-API-KEY": auth.apiKey, |
130 | }, |
131 | body: JSON.stringify(body), |
132 | }); |
133 | if (!response.ok) { |
134 | const text = await response.text(); |
135 | throw new Error(`${response.status} ${text}`); |
136 | } |
137 | return await response.json(); |
138 | } |
139 |
|