Backend Integration

The integration flow between the frontend application, the backend of the application, and the EcartPay service is outlined below.

1. Workflow Description

This is a suggested workflow between the Frontend application, the application's Backend, and Ecart Pay API for customer creation and payment processing, which includes the following steps:

  1. The user enters their information in the app.
  2. The Frontend App sends the information to the App Backend.
  3. The App Backend receives and sends the customer information to Ecart Pay API.
  4. Ecart Pay API creates the customer and returns a customer_id, which is stored in the database.
  5. The Frontend App then receives customer_id and captures card details and sends them to Ecart Pay API.
  6. Once the card is securely stored, Ecart Pay API returns the card_id.
  7. Then, the Frontend recieves the card_id , which is sent to the Backend and used for the POST /api/tokens request to the Ecart Pay API for the card tokenization.
    1. (optional) During this part of the process, the Create Tokenized Card request can be used to set the interest-free or deferred payments configuration of that specific order.
  8. Ecart Pay generates the tokenized card and returns a token to the Backend in the payload.
  9. The tokenized card can then be used in the Create Order request to create and process orders.


⚠️

IMPORTANT

To follow the steps below, it is essential to have the corresponding Authorization Token. For more information, please refer to the following documentation page: Authorization Token

2. Ecart Pay API Requests Workflow

2.1 Create Customer

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.

Endpoint

  • POST /api/customers
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 Card

This request is used to create a customer card associated with a customer in Ecart Pay. The backend receives the card information and sends it to the API for storage.

Endpoint

  • POST /api/customers/{customer_id}/cards
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 Tokenized Card and configure Interest-free/Fixed Installments options

To process payments in this workflow, it is necessary to create a tokenized card. The card_id and the CVC (for digital cards) are sent to generate the token. Also, you can include additonal values to configure the Interest-free and Fixed Installments options for an specific order here.

Endpoint

  • POST /api/tokens
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"
}'
curl --location --request POST 'https://sandbox.ecartpay.com/api/tokens' \
--header 'Authorization: {{token}}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "cvc": "123",
  "id": "68a57024c534963c6e81c323",
  "fixed_installments": true,
  "installments": 3
  }'

Example response

{
    "token": "ca_ef686e4f4a2d92e99"
}

2.4 Create Order

Once the customer and card have been registered, and the token has been generated, you can use the backend to create an order in Ecart Pay via API request. The tokenized card is included in the request to process the payment.

Endpoint

  • POST /api/orders
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

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.