Documentation
Feedback
Guides
API Reference

Guides
Integration Guides
Payments
Implementing a Payment Provider

The following sections show how to develop the middleware that will interpret the calls made between VTEX and the provider.

It also shows that the payment provider protocol consists of nine endpoints, divided into two sessions: Payment flow and Configuration flow. The middleware must be able to receive the information supplied by all these calls properly.

To develop a new payment connector, it is mandatory to follow the prerequisites determined by VTEX. You can learn about them in the Implementation prerequisites section of our Payment Provider Protocol article.

Developing the middleware

Requirements

The middleware can be developed using any programming language, there are no restrictions. However, we established four requirements for this stage:

  • The endpoint must be served over HTTPS on port 443 with TLS 1.2 support. That format is required, in no case endpoints served over HTTP will be accepted in the implementation process.
  • The partner’s API must be public. In the homologation process, we will **not **accept any kind of restricted APIs.
  • The partner must create a subdomain or a domain name to the endpoint. IP addresses will not be accepted as names under any circumstances.
  • We want our processes to run quickly, so it is important that the endpoint responds in less than 5 seconds to the homologation tests. Also, the endpoint must respond in less than 20 seconds to any call.

With the requirements aligned, we can proceed to the Payment Flow.

Payment Flow

The following endpoints are used to implement the operations that happen in the authorization, cancellation or refund, and settlement flows.

1. GET Manifest

Through this endpoint, the provider's manifest is displayed, consisting of a variety of metadata settings such as payment methods, split configuration, and custom fields.


_32
{
_32
"paymentMethods": [
_32
{
_32
"name": "Visa",
_32
"allowsSplit": "onCapture"
_32
},
_32
{
_32
"name": "Pix",
_32
"allowsSplit": "disabled"
_32
},
_32
{
_32
"name": "MasterCard",
_32
"allowsSplit": "onCapture"
_32
},
_32
{
_32
"name": "American Express",
_32
"allowsSplit": "onCapture"
_32
},
_32
{
_32
"name": "BankInvoice",
_32
"allowsSplit": "onAuthorize"
_32
},
_32
{
_32
"name": "Privatelabels",
_32
"allowsSplit": "disabled"
_32
},
_32
{
_32
"name": "Promissories",
_32
"allowsSplit": "disabled"
_32
}
_32
]
_32
}

If you support any type of custom payment, please indicate only the method supported type (Cobranded, Privatelabels or Promissories) in the "name" field. It is not necessary to describe the specific name of the supported custom payment (e.g., Colombian Bank Promissory).

For more information about this step, you can check the GET List Payment Provider Manifest endpoint documentation.

2. POST Create Payment

When a customer makes a purchase at the checkout, the provider must create a payment related to the order. Therefore, the provider must be ready to receive the request body that will contain all the cart information:


_75
{
_75
"reference": "32478982",
_75
"orderId": "1047232106697",
_75
"selerId": "xpto",
_75
"transactionId": "611966",
_75
"paymentId": "5B127F1E0C944EF9ACE264FEC1FC0E91",
_75
"paymentMethod": "cash",
_75
"paymentMethodCustomCode": "{{paymentMethodCustomCode}}",
_75
"merchantName": "lojaexemplo",
_75
"value": "29,90",
_75
"currency": "BRL",
_75
"installments": "0",
_75
"deviceFingerprint": "12ade389087fe",
_75
"card": {
_75
"holder": "{{cardHolder}}",
_75
"number": "{{cardNumber}}",
_75
"csc": "{{cardSecurityCode}}",
_75
"expiration": {
_75
"month": "{{cardExpirationMonth}}",
_75
"year": "{{cardExpirationYear}}"
_75
}
_75
},
_75
"miniCart": {
_75
"shippingValue": 11.44,
_75
"taxValue": 10.01,
_75
"buyer": {
_75
"id": "c1245228-1c68-11e6-94ac-0afa86a846a5",
_75
"firstName": "John",
_75
"lastName": "Doe",
_75
"document": "01234567890",
_75
"documentType": "CPF",
_75
"email": "john.doe@example.com",
_75
"phone": "+12125357200"
_75
},
_75
"shippingAddress": {
_75
"country": "USA",
_75
"street": "12 E 49th St",
_75
"number": "10017",
_75
"complement": "Tower 49 Gallery",
_75
"neighborhood": "Central Midtown",
_75
"postalCode": "10017",
_75
"city": "New York",
_75
"state": "NY"
_75
},
_75
"billingAddress": {
_75
"country": "USA",
_75
"street": "12 E 49th St",
_75
"number": "10017",
_75
"complement": "Tower 49 Gallery",
_75
"neighborhood": "Central Midtown",
_75
"postalCode": "10017",
_75
"city": "New York",
_75
"state": "NY"
_75
},
_75
"items": [
_75
{
_75
"id": "132981",
_75
"name": "My First Product",
_75
"price": 2134.90,
_75
"quantity": 2,
_75
"discount": 5.00
_75
},
_75
{
_75
"id": "123242",
_75
"name": "My Second Product",
_75
"price": 21.98,
_75
"quantity": 1,
_75
"discount": 1.00
_75
}
_75
]
_75
},
_75
"url": "https://admin.mystore.example.com/orders/v32478982",
_75
"callbackUrl": "{{callbackUrl}}",
_75
"returnUrl": "{{returnUrl}}"
_75
}

The callbackURL is an URL used to make retries in the operation flow. In addition, if the partner adopts redirect as a payment flow, you should also include the returnURL in the request payload. Thus, VTEX will be able to realize the redirect flow, if necessary.

Both callbackURL and returnURL are developed by the provider.

On the other hand, we need that your provider returns this call with the following response:


_15
_15
{
_15
"paymentId": "5B127F1E0C944EF9ACE264FEC1FC0E91",
_15
"status": "undefined",
_15
"authorizationId": "AUT-E4B9C36034-ASYNC",
_15
"paymentUrl": "https://exemplo2.vtexpayments.com.br/api/pub/fake-payment-provider/payment-redirect/611966/payments/5B127F1E0C944EF9ACE264FEC1FC0E91",
_15
"nsu": "NSU-171BE62CB7-ASYNC",
_15
"tid": "TID-20E659E8E5-ASYNC",
_15
"acquirer": "TestPay",
_15
"code": "2000-ASYNC",
_15
"message": null,
_15
"delayToAutoSettle": 21600,
_15
"delayToAutoSettleAfterAntifraud": 1800,
_15
"delayToCancel": 21600
_15
}

The parameters delayToAutoSettle and delayToAutoSettleAfterAntifraud define the total of time that the system will wait to start the capture flow. A similar process happens for the parameter delayToCancel, but after the timeout, the system will proceed to the cancellation flow.

All of these three periods of time are established by the provider and should be counted in seconds.

Also, the parameters code and message are fields to which the provider can send us any information about the process. Both are optional and will appear in the next calls.

All the fields are described in the POST Create Payment documentation.

3. POST Cancel Payment

To cancel a payment, you must already have created one. Your provider must be ready to receive only two information: the paymentId, the identifier of the payment that will be canceled, and the requestId, the identifier that ensures its idempotency.

For “idempotency”, we mean an action ability to be done several times. As we explained in the Operations section, the cancellation flow can be retried during a whole day until the provider responds to the call.


_10
{
_10
"paymentId": "F5C1A4E20D3B4E07B7E871F5B5BC9F91",
_10
"requestId": "1234"
_10
}

After the provider realizes the payment cancelation, we expect a response like this:


_10
{
_10
"paymentId": "F5C1A4E20D3B4E07B7E871F5B5BC9F91",
_10
"message": "Successfully cancelled",
_10
"code": null,
_10
"cancellationId": "1457BD07E6",
_10
"requestId": "1234"
_10
}

Refer to the complete documentation for more details.

4. POST Capture Payment

If your transaction was completed successfully, the provider can capture the payment. In fact, it is really important for you to know that VTEX supports partial captures.

This happens because the payment can be captured in two different moments:

  • When the store invoices the order.
  • After the period defined in the fields delayToAutoSettle and delayToAutoSettleAfterAntifraud is timeout.

In this context, the field value is mandatory and crucial for the operation to be realized properly.

VTEX will send the information below to capture a payment:


_10
{
_10
"paymentId": "5B127F1E0C944EF9ACE264FEC1FC0E91",
_10
"transactionId": "611966",
_10
"value": 20.0,
_10
"requestId": "5678"
_10
}

The response will be similar to the request body. But the parameter value can be fulfilled with the full amount that was sent in the request or with a smaller one. It all depends on how much the provider wants to capture.


_10
{
_10
"paymentId": "5B127F1E0C944EF9ACE264FEC1FC0E91",
_10
"settleId": "CEE16492C6",
_10
"value": 20.0,
_10
"code": null,
_10
"message": null,
_10
"requestId": "5678"
_10
}

Refer to the Capture Payment endpoint documentation for more details.

5. POST Refund Payment

VTEX also supports partial refunds, it is a similar logic for the capture.

For example, consider a purchasing cart with two items. One scenario that can happen is that the store needs to return just one of the purchased items. In this case, we can refund just the value of that one single item instead of refunding the full value that includes both items and shipping.

In any case, the provider should be ready to receive the following request:


_10
{
_10
"paymentId": "VQKIIBUVOFDBIDLKZPOWSKETDYWCMJSACDVXWFCJVSKXGYVBBVISZRJLLQEKERJEMDYEINOUMFAZZGNEDVBQBABLUKLFBSEEIGLCAQTOGOGURKLFCAHJQTDMBNKYBIST",
_10
"transactionId": "611966",
_10
"settleId": "31018A3281",
_10
"value": 10.0,
_10
"requestId": "5678"
_10
}

The response expected is:


_10
{
_10
"paymentId": "VQKIIBUVOFDBIDLKZPOWSKETDYWCMJSACDVXWFCJVSKXGYVBBVISZRJLLQEKERJEMDYEINOUMFAZZGNEDVBQBABLUKLFBSEEIGLCAQTOGOGURKLFCAHJQTDMBNKYBIST",
_10
"refundId": null,
_10
"value": 0.0,
_10
"code": "refund-manually",
_10
"message": "Refund should be done manually",
_10
"requestId": "5678"
_10
}

Remember that, if needed, the provider can return the call with the field value fulfilled with an amount smaller than the value informed in the request to realize a partial refund.

Refer to the Post Refund Payment endpoint for more details.

6. POST Inbound Request (BETA)

The Inbound Request (BETA) implements an URL that facilitates a direct connection between our Gateway service and the Payment Provider.

It is responsible for the communication with the provider's backend through our gateway, relying on the security of sending the context of the transaction by VTEX.

An example of the request is:


_10
{
_10
"requestId": "LA4E20D3B4E07B7E871F5B5BC9F91",
_10
"transactionId": "D3AA1FC8372E430E8236649DB5EBD08E",
_10
"paymentId": "F5C1A4E20D3B4E07B7E871F5B5BC9F91",
_10
"authorizationId": "{{authorizationId}}",
_10
"tid": "{{tid}}",
_10
"requestData": {
_10
"body": "{{originalRequestBody}}"
_10
}
_10
}

An expected response would be:


_10
{
_10
"requestId": "LA4E20D3B4E07B7E871F5B5BC9F91",
_10
"paymentId": "F5C1A4E20D3B4E07B7E871F5B5BC9F91",
_10
"responseData": {
_10
"statusCode": 200,
_10
"contentType": "application/json",
_10
"content": "{\"myAttribute\":\"anyValue\"}"
_10
}
_10
}

Refer to the Post Inbound Request (BETA) endpoint for more details.

Configuration Flow

In VTEX, the merchant has to enable one or more connectors through the Admin. The setup is basically the same for all the partners and you can check the tutorial on our Help Center.

However, this operation follows an authentication flow that allows the provider to recognize and authorize the merchant’s solicitation. The following endpoints generate three credentials - appKey, appToken and applicationId - that are saved by the VTEX system, which allows the merchant to enable the connector without copying and pasting any credentials.

This flow is optional and does not impact your connection with VTEX. If you do not intend to implement it, skip to the Homologation section.

1. POST Create Authorization Token

For the first step, the request body will be:


_10
{
_10
"applicationId": "vtex",
_10
"returnUrl": "https://admin.mystore.example.com/provider-return?authorizationCode="
_10
}

The applicationId will always be "vtex".

Then, the provider should return an identification token so we can redirect the merchant to the provider application.


_10
{
_10
"applicationId": "vtex",
_10
"token": "auth_token_39766d98535d43a491d03b8c3bea060f"
_10
}

Refer to the Create Authorization Token endpoint documentation to check all the details.

2. GET Provider Authentication

This call enables the merchant to analyse the provider’s terms and conditions to use its service.

With the token supplied in the previous response body, VTEX can redirect the merchant to the provider login page.

In the response body, we expect an authorizationCode related to the returnUrl sent to you in the first step of the configuration flow.


_10
{
_10
"authorizationCode": "auth_code_5b7be276c8e04e95bb1e",
_10
Grant access to "vtex" application
_10
}

Refer to the Get Provider Authentication endpoint for more details.

3. GET Credentials

Finally, the provider must send us the values of the three credentials.

We expect a response similar to this one:


_10
{
_10
"applicationId": "vtex",
_10
"appKey": "test_key_AE06E97A8C5B45DFA2DC665D6BE91E",
_10
"appToken": "test_token_90FB36380D114B37BC0557AEEE40ED"
_10
}

With that, the credentials will be saved in our system and activated at the moment the merchant decides to enable the conector.

Refer to the Get Credentials endpoint to check all the details.

Contributors
3
Photo of the contributor
Photo of the contributor
Photo of the contributor
+ 3 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
3
Photo of the contributor
Photo of the contributor
Photo of the contributor
+ 3 contributors
On this page