Overview
The complete payment flow consists of the following steps:- Create a customer
- Create a card token
- Assign the card to the customer
- Create a payment intent
- Confirm the payment
- Handle refunds (optional)
curl -X POST http://localhost:3000/api/customers \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"name": "John Doe",
"phone": "+34612345678"
}'
{
"status": true,
"message": "Cliente creado correctamente",
"data": {
"id": "cus_xxxxxxxxxx",
"email": "[email protected]",
"name": "John Doe",
"phone": "+34612345678"
}
}
Tokenize the customer’s card details securely. This converts sensitive card information into a one-time-use token.
curl -X POST http://localhost:3000/api/cards \
-H "Content-Type: application/json" \
-d '{
"number": "4242424242424242",
"exp_month": 12,
"exp_year": 2025,
"cvc": "123"
}'
{
"status": true,
"message": "Tarjeta tokenizada correctamente",
"data": {
"token_id": "tok_xxxxxxxxxx",
"card_id": "card_xxxxxxxxxx",
"card_brand": "visa",
"card_last4": "4242"
}
}
curl -X POST http://localhost:3000/api/cards/assign \
-H "Content-Type: application/json" \
-d '{
"userId": "cus_xxxxxxxxxx",
"source": "tok_xxxxxxxxxx"
}'
{
"status": true,
"message": "Tarjeta añadida con éxito",
"data": {
"cardId": "card_xxxxxxxxxx",
"brand": "visa",
"last4": "4242"
}
}
Create a payment intent with the amount and payment method. The amount is automatically converted to cents (multiplied by 100) by the API.
curl -X POST http://localhost:3000/api/payments \
-H "Content-Type: application/json" \
-d '{
"customer_id": "cus_xxxxxxxxxx",
"amount": 50.00,
"payment_method": "card_xxxxxxxxxx"
}'
{
"status": true,
"message": "Intento de pago creado correctamente",
"data": {
"id": "pi_xxxxxxxxxx",
"amount": 5000,
"currency": "eur",
"status": "requires_confirmation",
"customer": "cus_xxxxxxxxxx",
"payment_method": "card_xxxxxxxxxx"
}
}
curl -X POST http://localhost:3000/api/payments/confirm \
-H "Content-Type: application/json" \
-d '{
"paymentId": "pi_xxxxxxxxxx"
}'
{
"status": true,
"message": "Pago confirmado correctamente",
"data": {
"id": "pi_xxxxxxxxxx",
"amount": 5000,
"currency": "eur",
"status": "succeeded",
"charges": {
"data": [
{
"id": "ch_xxxxxxxxxx",
"amount": 5000,
"paid": true,
"status": "succeeded"
}
]
}
}
}
Implementation Notes
Amount Handling
When creating payments, provide the amount in your currency (e.g., 50.00). The API automatically multiplies by 100 to convert to cents for Stripe.
Currency
All payments are processed in EUR. If you need to support other currencies, you’ll need to modify the payment intent creation logic.
Payment Method Types
Currently, only card payments are supported. The API is configured with
payment_method_types: ['card'] in the payment intent creation.Next Steps
- Learn how to test webhooks locally
- Understand error handling patterns
- Set up Docker deployment