Backend Integration
The integration flow between the frontend application, the backend of the application, and the EcartPay service is outlined below.
1. Workflow Description
The workflow between the Frontend App, the application's Backend, and Ecart Pay for customer creation and payment processing includes the following steps:
- The user enters their information in the app.
- The Frontend App sends the information to the App Backend.
- The App Backend receives and sends the customer information to Ecart Pay.
- Ecart Pay creates the customer and returns a customer_id, which is stored in the database.
- The Frontend App then receives the card details and sends them to the App Backend.
- The App Backend sends the card information to Ecart Pay for storage.
- Once the card is stored, Ecart Pay returns the card_id.
- Finally, the App Backend creates the token to process the order and sends it to Ecart Pay.
- Ecart Pay generates the card token and returns it to the App Backend.

2. Ecart Pay API Requests
2.1 Create Customer (POST /customers)
This request creates a customer on the Ecart Pay platform. The backend sends customer data (phone number, first name, last name, and user_id) to Ecart Pay.
curl --location --request POST 'https://sandbox.ecartpay.com/api/customers' \
--header 'Authorization: {{token}}' \
--data-raw '{
"phone": "8114854378",
"first_name": "Roberto Alejandro",
"last_name": "de la Cruz Martinez",
"user_id": "004"
}'
2.2 Create Customer's Card (POST /customers/{customer_id}/cards)
This request is used to create a card associated with a customer in Ecart Pay. The backend receives the card information and sends it to the API for storage.
curl --location --request POST 'https://sandbox.ecartpay.com/api/customers/{{customer_id}}/cards' \
--header 'Authorization: {{token}}' \
--header 'Content-Type: application/json' \
--header 'Cookie: lang=en' \
--data-raw '{
"name": "Roberto Alejandro de la Cruz",
"number": "4242424242424242",
"exp_month": "10",
"exp_year": "2028",
"cvc": "111"
}'
2.3 Create Card Token (POST /tokens)
To process payments, it's necessary to create a card token. In this request, the card_id and the CVC (for digital cards) are sent to generate the token.
curl --location --request POST 'https://sandbox.ecartpay.com/api/tokens' \
--header 'Authorization: {{token}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": "{{card_id}}",
"cvc": "123"
}'
2.4 Create Order (POST /orders)
Once the customer and card have been registered, and the token has been generated, the backend creates the payment order in Ecart Pay. The token is included in the request to process the payment.
curl --location --request POST 'https://sandbox.ecartpay.com/api/orders' \
--header 'Authorization: {{token}}' \
--header 'Content-Type: application/json' \
--header 'Cookie: lang=en' \
--data-raw '{
"customer_id": "{{customer_id}}",
"currency": "MXN",
"items": [
{
"name": "Brazalete religioso plateado BR3017",
"quantity": 1,
"price": 243.33
}
],
"notify_url": "https://example.com/customer/290",
"token": "{{token}}"
}'
3. Summary of API Services
- Create customer:
/api/customers
- Create customer card:
/api/customers/{customer_id}/cards
- Create token:
/api/tokens
- Create order:
/api/orders
You can review the complete Ecart Pay API documentation at docs.ecartpay.com.
4. Conclusion
This workflow between the frontend, backend, and Ecart Pay enables customer creation, secure card storage, token generation, and order creation. The process follows security and scalability principles when handling sensitive data such as credit card information.
Updated about 2 months ago