Skip to main content
knowledgecenter.2checkout.com

Place orders via API using a 2Pay.js token

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.

// Order payment details
$CartObj->PaymentDetails = new stdClass();
$CartObj->PaymentDetails->Type = "EES_TOKEN_PAYMENT";
$CartObj->PaymentDetails->Currency = $defaultCurr;
$CartObj->PaymentDetails->CustomerIP = '91.220.121.21';
 
// Order payment method
$CartObj->PaymentDetails->PaymentMethod = new stdClass();
$CartObj->PaymentDetails->PaymentMethod->EesToken = "cdefa07d-0595-4469-8aa8-c54d2edd445f";
$CartObj->PaymentDetails->PaymentMethod->Vendor3DSReturnURL = "https://example.com";
$CartObj->PaymentDetails->PaymentMethod->Vendor3DSCancelURL = "https://example.com";

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 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";

  • Was this article helpful?