Confirm a stripe PaymentIntent using node js

After the PaymentIntent is created, attach a payment method and confirm to continue the payment. Confirm that your customer intends to pay with current or provided payment method. Upon confirmation, the PaymentIntent will attempt to initiate a payment. If the selected payment method requires additional authentication steps,the PaymentIntent will transition to the requires_action status and suggest additional actions via next_action.
If payment fails, the PaymentIntent will transition to the requires_payment_method status. If payment succeeds, the PaymentIntent will transition to the succeeded status(or requires_capture, if capture_method is set to manual). If the confirmation_method is automatic, payment may be attempted using our client SDK and the PaymentIntent’s client secret.
After next_actions are handled by the client, no additional confirmation is required to complete the payment. If the confirmation_method is manual, all payment attempts must be initiated using a secret key. If any actions are required for the payment, the PaymentIntent will return to the requires_confirmation state after those actions are completed.
Your server needs to then explicitly re-confirm the PaymentIntent to initiate the next payment attempt.

const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');

// To create a PaymentIntent for confirmation, see our guide at: https://stripe.com/docs/payments/payment-intents/creating-payment-intents#creating-for-automatic
const paymentIntent = await stripe.paymentIntents.confirm(
  'pi_1GszXs2eZvKYlo2CysG8qMFI',
  {payment_method: 'pm_card_visa'}
);
Parameters
  • payment_methodoptionalID of the payment method (a PaymentMethod, Card, or compactable object) to attach to this PaymentIntent.
Returns

Returns a PaymentIntent object.

Response


{
  "id": "pi_1GszXs2eZvKYlo2CysG8qMFI",
  "object": "payment_intent",
  "amount": 1000,
  "amount_capturable": 0,
  "amount_details": {
    "tip": {}
  },
  "amount_received": 1000,
  "application": null,
  "application_fee_amount": null,
  "automatic_payment_methods": null,
  "canceled_at": null,
  "cancellation_reason": null,
  "capture_method": "automatic",
  "client_secret": "pi_1GszXs2eZvKYlo2CysG8qMFI_secret_BgHJZOI16D0p7cUnucAJqmnCq",
  "confirmation_method": "automatic",
  "created": 1591916741,
  "currency": "usd",
  "customer": null,
  "description": "Created by stripe.com/docs demo",
  "invoice": null,
  "last_payment_error": null,
  "latest_charge": "ch_1Mvy932eZvKYlo2C1fU2shgK",
  "livemode": false,
  "metadata": {},
  "next_action": null,
  "on_behalf_of": null,
  "payment_method": "pm_1Mvy922eZvKYlo2CBxNvqrQ5",
  "payment_method_options": {
    "card": {
      "installments": null,
      "mandate_options": null,
      "network": null,
      "request_three_d_secure": "automatic"
    }
  },
  "payment_method_types": [
    "card"
  ],
  "processing": null,
  "receipt_email": null,
  "redaction": null,
  "review": null,
  "setup_future_usage": null,
  "shipping": null,
  "statement_descriptor": null,
  "statement_descriptor_suffix": null,
  "status": "succeeded",
  "transfer_data": null,
  "transfer_group": null
}

Leave a comment

Your email address will not be published. Required fields are marked *