Skip to main content

Place orders via API using a 2Pay.js token

Place orders via API using a 2Pay.js token

Last updated: 17-Jan-2023
Rate this article:

Overview

You can use a 2Pay.js token to place orders via APIv6 by following the flow below.

How to use a 2Pay.js token

Placing orders using 2Pay.js tokens in API works like a normal credit card order. Once a token has been obtained using the 2Pay.js library, this can be used to place an order by using API version 6.

In order to do this, the payment type used in the payment details of the placeOrder call must be EES_TOKEN_PAYMENT and the token must be specified in the payment method object.

Place an order with 2Pay.js Token example

{
  "Country": "br",
  "Currency": "brl",
  "CustomerIP": "91.220.121.21",
  "CustomerReference": "GFDFE",
  "ExternalCustomerReference": "IOUER",
  "ExternalReference": "REST_API_AVANGTE",
  "Language": "en",
  "Source": "testAPI.com",
  "Affiliate": {},
  "BillingDetails": {
    "Address1": "Test Address",
    "City": "LA",
    "CountryCode": "BR",
    "Email": "customer@2Checkout.com",
    "FirstName": "Customer",
    "FiscalCode": "056.027.963-98",
    "LastName": "2Checkout",
    "Phone": "556133127400",
    "State": "DF",
    "Zip": "70403-900"
  },
  "Items": [
    {
      "Code": "my_subscription_1",
      "Quantity": "1"
    }
  ],
  "PaymentDetails": {
    "Currency": "BRL",
    "CustomerIP": "91.220.121.21",
    "PaymentMethod": {
      "EesToken": "7b88d2cf-6121-4cac-90a1-8eefc4cb3e6e",
      "Vendor3DSReturnURL": "www.test.com",
      "Vendor3DSCancelURL": "www.test.com"
    },
    "Type": "EES_TOKEN_PAYMENT"
  }
}

Place a test order with 2Pay.js token example

To place a test order with 2Pay.js token, use the above code sample and simply replace the value of the TYPE parameter with "Type": "TEST".

Response errors

If a token is invalid, then an HTTP 400 response containing the INVALID_EES_TOKEN error code is returned. In this case, a new token must be generated via the 2Pay.js library.

Once payment is placed successfully, then the standard processing flow of any credit card payment will continue. For transactions that require 3D Secure for authorization, the standard flow needs to be followed; this can be found here.

How to use a 2Pay.js token with API 3D Secure

  1. When placing an order via API 3D Secure, the Return and Cancel URLs must be provided​.
  2. Once the order is placed successfully, the response provides the URL where the shopper needs to be redirected (the redirect URL must be built from the base URL + the provided list of parameters as a GET request)​
  3. Once the 3D Secure step is fulfilled, the shopper is redirected to the 3D Secure Return parameter specified when placing the order​.

Recurring Payments and 1-Click Purchases with 2Pay.js Token

Recurring payments and 1-click purchases with previous order references are available​ when using the 2Pay.js token.

​Recurring payment​

Recurring payments for an order are enabled in the same way as for credit card orders​.

$CartObj->PaymentDetails->PaymentMethod->RecurringEnabled = true;

1-Click Purchase​

1-click purchase is supported out of the box​. An order paid via a 2Pay.js token works just like a regular credit card order.

$CartObj->PaymentDetails->Type = "PREVIOUS_ORDER";
$CartObj->PaymentDetails->PaymentMethod->RefNo = "11658744";

Rate this article:

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo