1

Confirm Payment Intent

by
Published Aug 23, 2022

Confirm a PaymentIntent to attempt the payment. `return_url` is needed for redirect-based methods (3D Secure, bank redirects); `off_session` marks a payment made while the customer is not present. `extra_params` passes any other documented field through as-is.

Script stripe Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Confirm Payment Intent
5
 * Confirm a PaymentIntent to attempt the payment. `return_url` is needed for redirect-based methods (3D Secure, bank redirects); `off_session` marks a payment made while the customer is not present. `extra_params` passes any other documented field through as-is.
6
 */
7
export async function main(
8
  auth: RT.Stripe,
9
  payment_intent_id: string,
10
  payment_method: string | undefined,
11
  return_url: string | undefined,
12
  receipt_email: string | undefined,
13
  off_session: boolean | undefined,
14
  extra_params: { [key: string]: any } | undefined
15
) {
16
  const response = await fetch(
17
    `https://api.stripe.com/v1/payment_intents/${payment_intent_id}/confirm`,
18
    {
19
      method: "POST",
20
      headers: {
21
        Authorization: `Bearer ${auth.token}`,
22
        "Content-Type": "application/x-www-form-urlencoded",
23
        Accept: "application/json",
24
        "Stripe-Version": "2025-03-31.basil",
25
      },
26
      body: toForm({
27
        payment_method,
28
        return_url,
29
        receipt_email,
30
        off_session: off_session || undefined,
31
        ...extra_params,
32
      }),
33
    }
34
  )
35

36
  if (!response.ok) {
37
    throw new Error(`${response.status} ${await response.text()}`)
38
  }
39

40
  return await response.json()
41
}
42

43
// Stripe takes form-encoded params with bracketed nesting: metadata[key]=v, items[0][price]=p
44
function toForm(
45
  params: { [key: string]: any },
46
  prefix = "",
47
  out = new URLSearchParams()
48
) {
49
  for (const [key, value] of Object.entries(params)) {
50
    if (value == null || value === "") continue
51
    const name = prefix ? `${prefix}[${key}]` : key
52
    if (typeof value === "object") toForm(value, name, out)
53
    else out.append(name, String(value))
54
  }
55
  return out
56
}
57

Other submissions
  • Submitted by rossmccrann Deno
    Created 528 days ago
    1
    type Stripe = {
    2
      token: string;
    3
    };
    4
    export async function main(stripe_con: Stripe, id: string) {
    5
      const STRIPE_CONFIRM_PAYMENT_URL = `https://api.stripe.com/v1/payment_intents/:${id}/confirm`;
    6
    
    
    7
      const token = stripe_con["token"];
    8
    
    
    9
      const response = await fetch(STRIPE_CONFIRM_PAYMENT_URL, {
    10
        method: "POST",
    11
        headers: {
    12
          Authorization: "Bearer " + token,
    13
          "Content-Type": "application/json",
    14
        },
    15
      });
    16
    
    
    17
      return await response.json();
    18
    }
    19