Attach payment method to a payment intent
Attach a payment method resource to a payment intent resource.
This endpoint is normally used to charge a customer using their saved payment method. Please refer to this guide for more details.
Endpoint
POST /payment_intents/:id/attach
Sample code
- curl
- Node
- PHP
- Python
- Ruby
curl --request POST --location 'https://api.payrexhq.com/payment_intents/<ID of a payment intent resource>/attach' \
-u replace_with_secret_api_key: \
--data-urlencode 'payment_method_id=<insert payment method id>'
const client = require('payrex-node')('insert your PayRex Secret API key.');
const paymentIntent = await client.paymentIntents.attach(
// Payment intent ID where the payment method will be attached to.
'<ID of a payment intent resource>',
{
payment_method_id: '<insert payment method id>',
}
)
$client = new \Payrex\PayrexClient('insert your PayRex Secret API key.');
$paymentIntent = $client->paymentIntents->attach([
// Payment intent ID where the payment method will be attached to.
'id' => '<ID of a payment intent resource>',
'payment_method_id' => '<insert payment method id>'
]);
from payrex import Client as PayrexClient
client = PayrexClient('insert your PayRex Secret API key.')
payment_intent = client.payment_intents.attach(
# Payment intent ID where the payment method will be attached to.
'<ID of a payment intent resource>',
{
'payment_method_id': '<insert payment method id>'
}
)
client = Payrex::Client.new("insert your PayRex Secret API key.")
payment_intent = client.payment_intents.attach(
# Payment intent ID where the payment method will be attached to.
"<ID of a payment intent resource>",
{
payment_method_id: '<insert payment method id>'
}
)
Parameters
id REQUIRED
The id of the payment intent where the payment method id will be attached
payment_method_id REQUIRED
The payment method ID to be attached to the payment intent
Returns
Returns a Payment Intent resource.