Confirmar un Payment Intent
Confirma un Payment Intent para obtener la URL a la que redirigir a tu cliente para que complete el pago.
Endpoint
POST /api/v1/payment_intents/:id/confirm
Autenticación
Este endpoint admite ambos métodos de autenticación:
- Token Bearer (JWT):
Authorization: Bearer YOUR_JWT_TOKEN - Clave de API (Basic Auth):
Authorization: Basic base64(key:secret)
Petición
Parámetros de ruta
| Parámetro | Tipo | Obligatorio | Descripción |
|---|---|---|---|
id | string | Sí | El ID del Payment Intent que se confirma (por ejemplo 550e8400-e29b-41d4-a716-446655440000). |
Cuerpo de la petición
{
"client_secret": "550e8400-e29b-41d4-a716-446655440000_secret_abc123",
"return_url": "https://merchant.example.com/return",
"payment_method_data": {
"type": "crypto"
}
}
Parámetros
| Parámetro | Tipo | Obligatorio | Descripción |
|---|---|---|---|
client_secret | string | Sí | El client secret de la respuesta de creación del Payment Intent. |
return_url | string | No | Sustituye la URL de retorno indicada al crear el Payment Intent. |
payment_method_data | object | No | Datos del método de pago. Actualmente solo se admite type: "crypto". |
Respuesta
Respuesta correcta
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"amount": "100.00",
"currency": "usd",
"status": "processing",
"payment_method_types": ["crypto"],
"return_url": "https://merchant.example.com/return",
"next_action": {
"type": "redirect_to_url",
"redirect_to_url": {
"url": "https://pay.orcarail.com/pl_abc123?payment_intent=550e8400-e29b-41d4-a716-446655440000&payment_intent_client_secret=550e8400-e29b-41d4-a716-446655440000_secret_abc123"
}
},
"payment_link": {
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"unique_slug": "pl_abc123",
"link": "https://pay.orcarail.com/pl_abc123"
}
}
Campos de la respuesta
| Campo | Tipo | Descripción |
|---|---|---|
id | string | El ID del Payment Intent. |
status | string | Estado actualizado (normalmente processing). |
next_action | object | Contiene la URL de redirección en redirect_to_url.url. |
next_action.type | string | Siempre "redirect_to_url" en los pagos cripto. |
next_action.redirect_to_url.url | string | La URL a la que debes redirigir a tu cliente. Es la página de pago alojada. |
Ejemplo
cURL
curl https://api.orcarail.com/api/v1/payment_intents/550e8400-e29b-41d4-a716-446655440000/confirm \
-X POST \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"client_secret": "550e8400-e29b-41d4-a716-446655440000_secret_abc123"
}'
JavaScript (Node.js)
const paymentIntentId = '550e8400-e29b-41d4-a716-446655440000'
const clientSecret = '550e8400-e29b-41d4-a716-446655440000_secret_abc123'
const response = await fetch(
`https://api.orcarail.com/api/v1/payment_intents/${paymentIntentId}/confirm`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
client_secret: clientSecret,
}),
}
)
const confirmedIntent = await response.json()
const redirectUrl = confirmedIntent.next_action.redirect_to_url.url
// Redirect your customer to this URL
window.location.href = redirectUrl
Python
import requests
payment_intent_id = '550e8400-e29b-41d4-a716-446655440000'
client_secret = '550e8400-e29b-41d4-a716-446655440000_secret_abc123'
response = requests.post(
f'https://api.orcarail.com/api/v1/payment_intents/{payment_intent_id}/confirm',
headers={
'Authorization': f'Bearer {jwt_token}',
'Content-Type': 'application/json',
},
json={
'client_secret': client_secret,
},
)
confirmed_intent = response.json()
redirect_url = confirmed_intent['next_action']['redirect_to_url']['url']
# Redirect your customer to this URL
print(f"Redirect customer to: {redirect_url}")
PHP (SDK)
$confirmed = $orcarail->paymentIntents->confirm($intentId, [
'client_secret' => $clientSecret,
'return_url' => 'https://merchant.example.com/return',
]);
$payUrl = $confirmed->pay_url ?? $confirmed->next_action?->redirect_to_url?->url;
header('Location: ' . $payUrl);
El SDK de PHP envía tu clave de API junto con el client secret, así que la confirmación funciona desde un servidor sin JWT de usuario.
Flujo de pago alojado
Tras confirmar el Payment Intent, redirige a tu cliente a la URL de next_action.redirect_to_url.url. Esta página de pago alojada:
- Muestra el importe y los detalles del pago
- Permite al cliente conectar su wallet cripto
- Procesa el pago on-chain
- Redirige de vuelta a tu
return_urlcon parámetros de consulta
Gestión de la URL de retorno
Tras completar (o cancelar) el pago, los clientes vuelven a tu return_url con parámetros de consulta:
https://merchant.example.com/return?payment_intent=550e8400-e29b-41d4-a716-446655440000&payment_intent_client_secret=550e8400-e29b-41d4-a716-446655440000_secret_abc123
Deberías:
- Extraer
payment_intentypayment_intent_client_secretde la cadena de consulta - Obtener el Payment Intent para comprobar su estado
- Gestionar el pago en consecuencia (por ejemplo, mostrar una página de éxito o actualizar el estado del pedido)
Ejemplo de gestor de la URL de retorno
// Your return_url route (server side). The hosted pay page redirects here with
// ?payment_intent=...&payment_intent_client_secret=...
const paymentIntentId = req.query.payment_intent
if (paymentIntentId) {
// Required: complete the intent. It becomes `completed` once the payment is
// confirmed on-chain; while it is still `processing`, call complete again.
const response = await fetch(
`https://api.orcarail.com/api/v1/payment_intents/${paymentIntentId}/complete`,
{
method: 'POST',
headers: {
Authorization: `Basic ${Buffer.from(`${apiKey}:${apiSecret}`).toString('base64')}`,
},
}
)
const paymentIntent = await response.json()
if (paymentIntent.status === 'completed') {
// Payment successful!
showSuccessPage()
} else if (paymentIntent.status === 'canceled') {
// Payment was canceled
showCanceledPage()
} else {
// Payment is still processing
showProcessingPage()
}
}
Próximos pasos
- Obtener un Payment Intent: comprueba el estado del pago
- Configurar webhooks: recibe notificaciones de pago en tiempo real