Skip to main content

Use WeChat Pay

Overview

Place an order for catalog products defined in your Control Panel and collect the payment using WeChat Pay.

Requirements

Only Chinese shoppers are able to purchase using WeChat Pay. Make sure the billing country code is set to CN.

Supported currencies

  • USD
  • HKD
  • CNY

Workflow

  1. Shoppers select WeChat as payment option in the interface you provide to them.
  2. Create the order object. Use WE_CHAT_PAY as the type of the PaymentDetails object, and include ReturnURL and CancelURL.
  3. Use the placeOrder method to send the data to 2Checkout.
  4. Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING.
  5. 2Checkout returns an Order object as the output of the placeOrder method. 
  6. Use the PaymentMethod object to create a redirect URL for the shoppers, concatenating the values of the Href and avng8apitoken parameters. Here's an example of the redirect URL:
    https://api.2checkout.com/4.0/scripts/we_chat_pay/authorize/?avng8apitoken=1abc7fd72d008428
  7. After being redirected to WeChat Pay, shoppers need to scan the QR code provided, using the WeChat smartphone app.
  8. After customers enter their payment password, WeChat notifies 2Checkout if the payment is approved, and the status of the order becomes COMPLETE.
  9. Shoppers are redirected to the RedirectURL from the Order information object. In case the payment fails, shoppers are redirected to the CancelURL. 

Parameters

Parameters Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

Order

Required (Object)

 

Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

To place an order with WeChat, use WE_CHAT_PAY as the type of the PaymentDetails object and provide a ReturnURL and a CancelURL as part of the PaymentMethod object. See code sample. 

Response

Parameters Type/Description
Order information Object
  Object containing order information.

Request

<?php

require ('PATH_TO_AUTH');

$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'usd';
$Order->Country = 'CN';
$Order->Language = 'en';
$Order->CustomerIP = '91.220.121.21';
$Order->ExternalReference = NULL;
$Order->Source = NULL;
$Order->Affiliate = new stdClass();
$Order->Affiliate->AffiliateCode = 'Partner123'
$Order->Affiliate->AffiliateSource = 'MobilePlatform'
$Order->CustomerReference = NULL;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1;
$Order->Items[0]->PriceOptions = NULL;
$Order->Items[0]->SKU = NULL;
$Order->Items[0]->Price = NULL;
$Order->Items[0]->CrossSell = NULL;
$Order->Items[0]->Trial = false;
$Order->Items[0]->AdditionalFields = NULL;
$Order->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'Test Cosmin API';
$Order->BillingDetails->LastName = 'Cosmin API';
$Order->BillingDetails->CountryCode = 'CN';
$Order->BillingDetails->State = 'California';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '90210';
$Order->BillingDetails->Email = 'cosmin.deftu@2checkout.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;

$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'WE_CHAT_PAY';
$Order->PaymentDetails->Currency = 'USD';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '91.220.121.21';
$Order->PaymentDetails->PaymentMethod->ReturnURL = 'http://yourreturnurl.com';
$Order->PaymentDetails->PaymentMethod->CancelURL= 'http://yourcancelurl.com';

$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;

$jsonRpcRequest = array (
'method' => 'placeOrder',
'params' => array($sessionID, $Order),
'id' => $i++,
'jsonrpc' => '2.0'
);

$output = callRPC($jsonRpcRequest, $host);

$wechatredirect = $output->PaymentDetails->PaymentMethod->Authorize->Href."/?avng8apitoken=".$output->PaymentDetails->PaymentMethod->Authorize->Params->avng8apitoken;

header('Location:' . $wechatredirect);

Retrieve installment information

Overview

Use the getInstallments method to retrieve information about the number of installments available for a specific selection of product/services.

Supported payment methods

Credit/Debit cards: local Visa and MasterCard Brazilian cards.

Parameters

Parameters

Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

Order

Required (Object)

 

Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

Example response

Attributes Type/Description

InstallmentsOption

Array of objects

 

Details below.

 

Number

Int

 

 

Number of installments.

 

Amount

Double

 

 

Standalone installment value. (Total order value/Number of installments)

 

Currency

String

 

 

Order currency.

Example request

 


<?php

require ('PATH_TO_AUTH');
 
$Order = new stdClass();
$Order->RefNo = null;
$Order->Currency = 'brl';
$Order->Country = 'BR';
$Order->Language = 'en';
$Order->CustomerIP = '91.220.121.21';
$Order->ExternalReference = null;
$Order->Source = null;
$Order->AffiliateId = null;
$Order->CustomerReference = null;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1; 
$Order->Items[0]->PriceOptions = null;
$Order->Items[0]->SKU = null;
$Order->Items[0]->Price = null;
$Order->Items[0]->CrossSell = null;
$Order->Items[0]->Trial = false; 
$Order->Items[0]->AdditionalFields = null;
$Order->Items[0]->Promotion = null;
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'FirstName';
$Order->BillingDetails->LastName = 'LastName';
$Order->BillingDetails->CountryCode = 'BR';
$Order->BillingDetails->State = 'DF';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = null;
$Order->BillingDetails->Zip = '70403-900';
$Order->BillingDetails->Email = 'customer@email.com';
$Order->BillingDetails->Phone = "556133127400";
$Order->BillingDetails->FiscalCode = "056.027.963-98";
$Order->BillingDetails->Company = null;
$Order->DeliveryDetails = null;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'CC';
$Order->PaymentDetails->Currency = 'brl';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->CardNumber = "4111111111111111";
$Order->PaymentDetails->PaymentMethod->CardType = 'visa';
$Order->PaymentDetails->PaymentMethod->ExpirationYear = '2019';
$Order->PaymentDetails->PaymentMethod->ExpirationMonth = '12';
$Order->PaymentDetails->PaymentMethod->HolderName = 'John';
$Order->PaymentDetails->PaymentMethod->CCID = '123';
$Order->Promotions = null;
$Order->AdditionalFields = null;
$Order->LocalTime = null;
$Order->GiftDetails = null;

$jsonRpcRequest = array (
'method' => 'getInstallments',
'params' => array($sessionID, $Order),
'id' => $i++,
'jsonrpc' => '2.0'
);
echo '<BR>';
echo 'The content of the current session:';
echo '<BR>';
$installments = callRPC((Object)$jsonRpcRequest, $host, true);
var_dump ($installments);
?>

Retention tools customization guide

Overview

2Checkout offers the option of configuring churn prevention campaigns in the Control Panel, that take effect in myAccount. You can configure these campaigns according to your own preferences, part of the customization being brought into play by the chance to create your own personalized message that 2Checkout will display to the shoppers when they try to cancel an auto-renewing subscription.

Control Panel customization

How to customize auto-renewal enrollment campaigns

To customize auto-renewal enrollment campaigns, you first need to create them. Refer to our detailed documentation for instructions on how to create an auto-renewal enrollment campaign. After you’ve set the campaign’s details, you can start the campaign. You cannot customize auto-renewal enrollment campaigns from the Control Panel. You can customize how they appear in myAccount via CSS.

How to customize churn prevention campaigns

To customize churn prevention campaigns, you first need to create them. Refer to our detailed documentation for instructions on how to create a churn prevention campaign. After you’ve set the campaign’s details, you can include a personalized message in it. 2Checkout will display this message to your shoppers when they attempt to stop the auto-renewal of the subscription you choose in the campaign’s settings.

You can use the following elements in the personalized message:

  • HTML tags
  • Custom variables, such as PRIMARY_PRODUCT_NAME and PRIMARY_PRODUCT_PRICE

Additionally, you can choose to display the message only for orders that were placed in a specific language. Simply select the desired languages from the available list.

Important: An English version of the custom text is mandatory. The English version will be displayed for any selected language that doesn’t have a translated text.

2Checkout myAccount customization

What can I customize in myAccount

Important: Any retention campaign displayed in myAccount inherits by default the style of the myAccount template.

You can further customize the way the retention campaigns are displayed by applying custom CSS styles to specific HTML IDs. The next section details each of the customizable elements together with their IDs and the CSS classes they inherit by default.

Any customization made to the following elements applies to every retention campaign displayed in myAccount.

Customize auto-renewal campaign pop-ups in myAccount

Identify and customize the elements described below.

Title bar icon

Customize the look of the title bar icon by applying your own styles to id="secureLocked". The icon inherits the style of the secureLocked and retentionModal CSS classes.

Pop-up title

Customize the look of the pop-up title by applying your own styles to id="secureLockedTitle". The title inherits the style of the secure_locked_title CSS class.

Auto-renewal enrollment dialog

Customize the look of the auto-renewal enrollment dialog by applying your own styles to id="autoRenewalEnrollment". The dialog inherits the style of the ui-dialog-content and ui-widget-content CSS classes.

Discount details

Customize the look of the discount details section by applying your own styles to id=" autoRenewalEnrollmentDiscount". The section inherits the style of the myaccount__myproductsrenewal__page__price CSS class.

Next billing amount (initial value)

Customize the look of the next billing amount (initial value) text by applying your own styles to id="autoRenewalEnrollmentDiscountInitialAmount". The text inherits the style of the myaccount__myproductsrenewal__page__price__value__initial CSS class.

Next billing amount (discounted value)

Customize the look of the next billing amount (discounted value) text by applying your own styles to id="autoRenewalEnrollmentDiscountDiscountedAmount". The text inherits the style of the myaccount__myproductsrenewal__page__price__value__amount CSS class.

Discount text

Customize the look of the discount text by applying your own styles to id="autoRenewalEnrollmentDiscountBillingCycles". The text inherits the style of the myaccount__myproductsrenewal__page__price__value CSS class.

Cancel enrollment button

Customize the look of the Cancel auto-renewal enrollment button by applying your own styles to id="autoRenewalEnrollmentCancelButton". The button inherits the styles of the button and buttonRetentionCancel classes.

Confirm enrollment button

Customize the look of the Confirm auto-renewal enrollment button by applying your own styles to id="autoRenewalEnrollmentSubmitButton". The button inherits the styles of the button and buttonRetentionSubmit CSS classes.

Customize churn prevention campaign pop-ups in myAccount

Identify and customize the elements described below.

Title bar icon

Customize the look of the title bar icon by applying your own styles to id="secureLocked". The icon inherits the style of the secureLocked, retentionModal and cancelAutoEnroll CSS classes.

Pop-up title

Customize the look of the pop-up title by applying your own styles to id="secureLockedTitle". The title inherits the style of the secure_locked_title CSS class.

Campaign message

Customize the look of the campaign text message by applying your own styles to id=" autoRenewalCancellationText". The text inherits the style of the template by default.

Stop auto-renewal button

Customize the look of the Stop auto-renewal button by applying your own styles to id=" autoRenewalCancellationSubmitButton". The button inherits the styles of the button and buttonRetentionCancel classes.

Keep auto-renewal button

Customize the look of the Keep auto-renewal button by applying your own styles to id=" autoRenewalCancellationCancelButton". The button inherits the styles of the button class.

Auto-renewal cancelation reason dialog

Customize the look of the cancellation reason dialog by applying your own styles to id=" autoRenewalCancellationStepREASON". The area inherits the style of the template by default.

Auto-renewal cancelation reason input

Customize the look of the cancelation reason input by applying your own styles to id=" autoRenewalCancellationReasonInput". The input inherits the style of the select and reasonField CSS classes.

Auto-renewal cancelation comment text box

Customize the look of the cancelation reason comment box by applying your own styles to id=" autoRenewalCancellationCommentInput"The text box inherits the style of the text and reasonField CSS classes.

Auto-renewal cancelation error message box

Customize the look of the cancellation reason error message box by applying your own styles to id=" cPreventionError". The box inherits the style of the showError CSS class.

Auto-renewal cancelation discount pop-up

Customize the look of the discount pop-up by applying your own styles to id=" autoRenewalCancellationStepDISCOUNT"The box inherits the style of the myaccount__myproductsrenewal__page__step CSS class.

Auto-renewal cancelation discount message

Customize the look of the discount message by applying your own styles to id=" autoRenewalCancellationDiscountBillingCycles"The box inherits the style of the myaccount__myproductsrenewal__page__price__value CSS class.

Mobile bank transfers in the Czech Republic

Overview

As a faster and easier alternative to classic bank transfers, shoppers based in the Czech Republic can choose to pay for their purchases through their bank's mobile application by scanning a QR code.

Traditional bank transfers are also available, should shoppers prefer not to use mobile banking applications.

QR code payments are available to all Czech shoppers and support CZK (Czech Koruna) transactions through multiple banks, such as:

  • Raiffeisen Bank
  • mBank
  • Air Bank
  • ČSOB (Československá obchodní banka)
  • Commerzbank

Availability

Contact 2Checkout for availability details.

QR code display

2Checkout displays QR codes only on default purchase flow resources that you have not customized:

  • Default shopping cart
  • Default payment confirmation emails
  • Default pro forma invoices

If you have customized any of the above resources and you want to include QR codes in your purchase flows, please contact 2Checkout.

Benefits

By adding QR code payments, we offer a great alternative to classic bank transfers, avoiding the transaction commission shoppers would traditionally need to pay to the bank while minimizing the time to finalize the payment.

Additionally, this brings an increase in your conversion rates of at least 2%.

Usage

2Checkout displays the QR code during multiple stages of the checkout process, in areas that contain the bank details:

  • Thank You page
  • Pro forma invoice
  • Payment confirmation email

Use PayPal

Overview

Place an order with dynamic product information, and collect the payment using PayPal.

Parameters

Parameters Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

Order

Required (Object)

 

Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

To place an order with PayPal rather than PayPal Express, use PAYPAL as the type of the PaymentDetails object and send the shopper email and a return URL as part of the PaymentMethod object. See code sample. 

Workflow

  1. Create the order object. Use PAYPAL as the type of the PaymentDetails object and send the shopper email and a return URL as part of the PaymentMethod object. Place the order.
  2. Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING. 2Checkout responds with the Order information object.
  3. Redirect shoppers to the RedirectURL from the Order information object you receive as response from 2Checkout.
  4. Once shoppers log into their PayPal account and complete the transaction, they're redirected to the ReturnURL you set in the order object. 2Checkout also authorizes the order and updates the status to AUTHRECEIVED. 

Response

Order information Type/Description
Order Information Object containing order information.

Request 

<?php
declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/soap/6.0';
    public const ACTION = 'placeOrder';
    public const ADDITIONAL_OPTIONS = null;
    //array or JSON
    public const PAYLOAD = <<<JSON
{
  "Country": "us",
  "Currency": "USD",
  "CustomerIP": "91.220.121.21",
  "ExternalReference": "SOAP_API_AVANGTE",
  "Language": "en",
  "Source": "testAPI.com",
  "BillingDetails": {
    "Address1": "Test Address",
    "City": "LA",
    "State": "California",
    "CountryCode": "US",
    "Email": "testcustomer@2Checkout.com",
    "FirstName": "Customer",
    "LastName": "2Checkout",
    "Zip": "12345"
  },
  "Items": [
    {
      "Name": "Dynamic product",
      "Description": "Test description",
      "Quantity": 1,
      "IsDynamic": true,
      "Tangible": false,
      "PurchaseType": "PRODUCT",
      "Price": {
        "Amount": 100,
        "Type": "CUSTOM"
      },
      "PriceOptions": [
        {
          "Name": "OPT1",
          "Options": [
            {
              "Name": "Name LR",
              "Value": "Value LR",
              "Surcharge": 7
            }
          ]
        }
      ],
      "RecurringOptions": {
        "CycleLength": 2,
        "CycleUnit": "DAY",
        "CycleAmount": 12.2,
        "ContractLength": 3,
        "ContractUnit": "DAY"
      }
    }
  ],
  "PaymentDetails": {
    "Currency": "USD",
    "CustomerIP": "91.220.121.21",
    "PaymentMethod": {
      "RecurringEnabled": false,
      "ReturnURL": "http://secure.avangate.local/test/index.php",
      "CancelURL": "http://secure.avangate.local/test/create_order.php"
    },
    "Type": "PAYPAL"
  }
}
JSON;
}

class Client
{
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?object {
        if (is_array($payload)) {
            $payload = json_encode($payload);
        }
        if (!empty($payload)) {
            // SoapClient works with objects(StdClass)
            $payload = json_decode($payload);
        }
        $soapClient = $this->getClient($url);
        $sessionId = $this->getSession($soapClient);
        $args = array_filter([$sessionId, $payload]);

        return $soapClient->$action(...$args);
    }

    public function getClient(string $url): SoapClient
    {
        return new SoapClient(
            $url.'?wsdl',
            [
                'location' => $url,
                'cache_wsdl' => WSDL_CACHE_NONE,
            ]
        );
    }

    public function getSession(SoapClient $client)
    {
        $date = gmdate('Y-m-d H:i:s');
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $string = strlen($merchantCode).$merchantCode.strlen($date).$date;
        $hash = hash_hmac('md5', $string, $key);
        $client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');

        return $client->login($merchantCode, $date, $hash);
    }
}

try {
    $client = new Client();
    var_dump($client->call());
} catch (Exception $ex) {
    var_dump($ex);
}

Retrieve a shipping fee configuration

Overview

Use the getShippingFee method to extract information about a specific shipping fee configuration you defined for your account. 

Parameters

Parameters

Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

ShippingCode

Required (string)

 

Shipping fee configuration code.

Response

Paremeter Type/Description

ShippingFees

Array of objects

Request

<?php

$host   = "https://api.avangate.com";
$client = new SoapClient($host . "/soap/6.0/?wsdl", array(
    'location' => $host . "/soap/6.0/",
    "stream_context" => stream_context_create(array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    ))
));


function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}

$merchantCode = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key          = "SECRET_KEY"; //your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$now          = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')

$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash   = hmac($key, $string);

try {
    $sessionID = $client->login($merchantCode, $now, $hash);
}

catch (SoapFault $e) {
    echo "Authentication: " . $e->getMessage();
    exit;
}

$ShippingCode = "235320E8A0";

try {
    $oneShippingFees = $client->getShippingFee($sessionID, $ShippingCode);
}

catch (SoapFault $e) {
    echo "oneShippingFees: " . $e->getMessage();
    exit;
}

var_dump("oneShippingFees", $oneShippingFees);


?>

Update credit card details for your customers

Overview

Update per-subscription credit and debit card details for your customers to support the automatic billing process for subscriptions and ensure no usage interruptions and their inherent impact. Note: PCI compliance is strongly recommended.

2Checkout enjoys Level 1 PCI DSS Certification, a statement of our continued commitment to ensuring the security of customer data including through the use of encryption, network and traffic monitoring, and strict user access privileges.

Benefits

  • Ensure continuous automatic billing for ongoing subscriptions despite issues such as card expiration.
  • Enable the purchase of subscriptions using PayPal and Direct Debit and then switching the payment method to credit/debit cards.
  • Better control over customer credit/debit card information.
  • Simplified customer payment data update process which no longer needs to involve myAccount.

Requirements

Compliance with the PCI Data Security Standard (PCI DSS) when dealing with credit card information is strongly recommended before using this feature.

Subscription pricing user rights

The availability of the Update credit card feature is governed by user rights. To enable access to this functionality for users of your account, go to Account settings, and select Manage user access. Click on the Roles associated with specific accounts, and make sure that the Subscription pricing checkbox is checked.

Availability

Auto-renewable subscriptions: Payment data can be updated only for subscriptions with the auto-renewal system enabled. This is valid for active, trial and expired subscriptions. Imported subscriptions that feature credit/debit card data can also have their cardholder details updated.

Update credit card capabilities are not available for:

  • Manually renewable subscriptions
  • Lifetime subscriptions
  • Disabled subscriptions

Supported credit/debit cards

Supported credit/debit cards must be enabled for your account and must be approved to perform transactions in at least one of the currencies available for your account.

Examples of supported cards: VISA, VISA Electron, MasterCard, Maestro and AMEX (American Express).

 

Payment info update flow

Supported

Credit/debit card to credit/debit card

YES

PayPal to credit/debit card

YES

Credit/debit card to PayPal

NO

DirectDebit to credit/debit card

YES

Credit/debit card to DirectDebit

NO

Other payment methods to credit/debit card

NO

Credit/debit card to other payment methods

NO

Limitations

While you can provide new credit/debit card details to update/replace the initial payment method used, including credit/debit cards, PayPal and Direct Debit, you won't be able to switch auto-renewal transactions from a credit/debit card to PayPal or Direct Debit.

How to update credit card details

  1. Go to Orders & customers -> Subscriptions.
  2. Use the search functionality available in this area to identify the subscription for which you want the credit card details updated
  3. Click View. 
  4. On the next screen, click Update credit card.
  5. Enter the new payment details associated with the customer's credit/debit card.
  6. Click Update.

The 2Checkout system will check the validity of the credit/debit card and will update the customer's payment information accordingly. Pre-authorization is performed for the credit/debit cards you're updating. The pre-authorization involves a temporary hold of a certain sum of money to ensure the validity of the payment method. This is not a charge and your customer won't pay any money for the pre-authorization.

For invalid credit/debit cards, as well as in scenarios involving incorrect details, the system will fail to refresh existing card info.

Following a successful update, the Subscription info area will be updated with the details of the new valid credit/debit card. The next transaction scheduled for the subscription with the updated payment details will be done using the new credit/debit card.

The last four digits of the card number are immediately available when viewing a particular subscription for which the customer is using a credit or debit card.

All successful payment details changes are reflected in the Subscription history area, both the ones made by you or your customers. Shoppers can also update the payment details for the subscriptions they acquired from you through 2Checkout by logging into myAccount.

Update subscription payment information

Overview

Use the updateSubscriptionPaymentInformation method to update the credit card information related to the payment to be made for a subscription. To be able to do this, you need to generate a payment token using the credit card information via the 2Pay.js library, and then use this token in the request of the method as indicated below.

Request Parameters

Parameter Name Type Required/Optional Description

sessionID

String

Required

The session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes.

subscriptionReference

String

Required

The reference of the subscription for which you want to retrieve the payment information.

paymentInformation

Object

Required

The payment information object, details below:

PaymentDetails

Object

Required

The payment details object, details below:

Type

String

Required

The payment details type. Restricted to EES_TOKEN_PAYMENT for now.

PaymentMethod

Object

Required

The payment method object, details below:

EesToken

String

Required

The 2Pay token obtained by integrating the 2Pay.js library.

Vendor3DSReturnURL String Required URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.
Vendor3DSCancelURL String Required URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.

Request Example

<?php

declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/rpc/6.0';
    public const ACTION = 'updateSubscriptionPaymentInformation';
    public const ADDITIONAL_OPTIONS = null;
    public const SUBSCRIPTION_REF = 'YC9XXMGOYO';
    //array or JSON
    public const PAYLOAD = <<<JSON
{
  "PaymentDetails": {
    "Type": "EES_TOKEN_PAYMENT",
    "PaymentMethod": {
      "EesToken": "b8de22d1-1378-4a9a-be21-aa2145a6eb54",
      "Vendor3DSReturnURL": "www.3dsReturnURL.com",
      "Vendor3DSCancelURL": "www.3dsCancelURL.com"
    }
  }
}
JSON;
}

class Client
{
    private const LOGIN_METHOD = 'login';
    private $calls = 1;
    private $sessionId;
    private function generateAuth(): array
    {
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $date = gmdate('Y-m-d H:i:s');
        $string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
        $hash = hash_hmac('md5', $string, $key);
        return compact('merchantCode', 'date', 'hash');
    }
    public function login(string $url)
    {
        $payload = $this->generateAuth();
        $response = $this->call($url, array_values($payload), self::LOGIN_METHOD);
        $this->sessionId = $response['result'];
    }
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?array {
        if (empty($this->sessionId) && $action !== self::LOGIN_METHOD) {
            $this->login($url);
        }

        if(is_string($payload)) {
            $payload = json_decode($payload, true);
        }
        if (!empty($this->sessionId)) {
            $payload = [$this->sessionId, Configuration::SUBSCRIPTION_REF, $payload];
        }
        $payload = array_filter($payload);

        $request = json_encode([
            'jsonrpc' => '2.0',
            'method' => $action,
            'params' => $payload,
            'id' => $this->calls++,
        ]);

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($curl, CURLOPT_SSLVERSION, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Cookie: XDEBUG_SESSION=PHPSTORM'));
        curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
        $response = curl_exec($curl);
        if(empty($response)) {
            die('Server unavailable');
        }
        echo $response . '</br>';
        return json_decode($response, true);;
    }
}
$client = new Client();
$result = $client->call();
var_dump($result);

Response

The method responds with Boolean True when the payment information update was successfully performed.
Otherwise, in case of validation or access rights failures, it returns the usual error response with specific messages indicating the cause of the failure.

{
    "jsonrpc": "2.0",
    "id": 2,
    "result": {
        "FirstDigits": "4012",
        "LastDigits": "9936",
        "Authorize3DSUrl": "https://...",
        "CardType": "visa"
    }
}

How to use 2Checkout Signature Generation API Endpoint

Overview

Before starting to use the 2Checkout Signature Generation API endpoint make sure you read about How to generate a JSON Web Token (JWT) and you have generated your merchant token.

To connect to the 2Checkout Signature Generation API endpoint you need to pass the merchant token to request headers and add the JSON formatted product payload.

Catalog Products Use Cases

Catalog products with lock

Signature parameter(s):

  • lock: 1 (boolean, required) – Set TRUE or "1" to lock products.
  • products: [] (array, required) – The products array.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

cURL 

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        },
        {
            "code": "PRODUCT_CODE_2"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        },
        {
            "code": "PRODUCT_CODE_2"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with expiration date and lock

Signature parameter(s):

  • lock: 1 (boolean, required) – Set TRUE or "1" to lock products.
  • expiration: 1581003962 (string, optional) – Buy-link expiry date. The link becomes invalid after the date of this parameter. Send as a UTC UNIX timestamp.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "expiration": "1893456001",
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}'

 PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "expiration": "1893456001",
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with expiration date and custom price

Signature parameter(s):

  • currency: USD (string, required) – Pre-selected billing currency is used to charge your customers.
  • expiration: 1581003962 (string, optional) – Buy-link expiry date. The link becomes invalid after the date of this parameter. Send as a UTC UNIX timestamp.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.
  • products[][custom-price]: {} (object, required) – The products prices for different currencies.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "expiration": "1893456001",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "custom-price": {
                "EUR": 10,
                "USD": 8
            }
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "expiration": "1893456001",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "custom-price": {
                "EUR": 10,
                "USD": 8
            }
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with return method parameter

Signature parameter(s):

  • return-method[url]: https://www.example.com (string, optional) – URL to which customers are redirected after their finalized purchase.
  • return-method[type]: link (string, optional) – The return method used for redirecting your customers after a successful sale. Possible values: link, header.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

Learn more about the redirect URL in this article.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "return-method": {
        "url": "https:\/\/www.example.com",
        "type": "link"
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "return-method": {
        "url": "https:\/\/www.example.com",
        "type": "link"
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with order external reference

Signature parameter(s):

  • reference[external][order]: ref-1 (string, required) – Use this parameter to set an external reference to the order.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "reference": {
        "external": {
            "order": "order_external_reference"
        }
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "reference": {
        "external": {
            "order": "order_external_reference"
        }
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with customer reference

Signature parameter(s):

  • reference[customer]: ref-1 (string, required) – Customer numerical (integer) identifier/reference.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

It can be used for new acquisitions aggregating new subscriptions under an existing Customer account.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "reference": {
        "customer": "customer_reference"
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "reference": {
        "customer": "customer_reference"
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with external customer reference

Signature parameter(s):

  • reference[external][customer]: ref-1 (string, required) – The external customer reference.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "reference": {
        "external": {
            "customer": "customer_external_reference"
        }
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "reference": {
        "external": {
            "customer": "customer_external_reference"
        }
    },
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with custom parameters

Signature parameter(s):

  • custom-parameters: [] (array, required) – The name field for all custom parameters is mandatory.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "custom-parameters": [
        {
            "name": "custom_param_name",
            "value": "custom_param_value"
        }
    ],
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "custom-parameters": [
        {
            "name": "custom_param_name",
            "value": "custom_param_value"
        }
    ],
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with coupons and lock parameter

Signature parameter(s):

  • lock: 1 (boolean, required) – Set TRUE or "1" to lock products.
  • coupons: [] (array, required) – An array of coupon codes.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "coupons": [
        "COUPON-CODE"
    ],
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "coupons": [
        "COUPON-CODE"
    ],
    "products": [
        {
            "code": "PRODUCT_CODE_1"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with coupons and custom price

Signature parameter(s):

  • currency: USD (string, required) – Pre-selected billing currency is used to charge your customers.
  • coupons: [] (array, required) – An array of coupon codes.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.
  • products[][custom-price]: {} (object, required) – The products prices for different currencies.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "coupons": [
        "COUPON-CODE"
    ],
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "custom-price": {
                "EUR": 1
            }
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "coupons": [
        "COUPON-CODE"
    ],
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "custom-price": {
                "EUR": 1
            }
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with quantity and lock parameters

Signature parameter(s):

  • lock: 1 (boolean, required) – Set TRUE or "1" to lock products.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.
  • products[][quantity]: integer (integer, required) – The number of units (quantity) for each product in checkout.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "quantity": 1
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "quantity": 1
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

 {"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with quantity and custom price parameters

Signature parameter(s):

  • currency: USD (string, required) – Pre-selected billing currency is used to charge your customers.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.
  • products[][quantity]: integer (integer, required) – The number of units (quantity) for each product in checkout.
  • products[][custom-price]: {} (object, required) – The products prices for different currencies.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "quantity": 1,
            "custom-price": {
                "EUR": 1
            }
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "quantity": 1,
            "custom-price": {
                "EUR": 1
            }
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with custom options and lock

Signature parameter(s):

  • lock: 1 (boolean, required) – Set TRUE or "1" to lock products.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.
  • products[][options]: {} (object, required) – The product options.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "options": [
                {
                    "name": "option_name_1",
                    "value": "option_value2"
                }
            ]
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "lock": 1,
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "options": [
                {
                    "name": "option_name_1",
                    "value": "option_value2"
                }
            ]
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with custom options and custom price

Signature parameter(s):

  • currency: USD (string, required) – Pre-selected billing currency is used to charge your customers.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.
  • products[][options]: {} (object, required) – The product options.
  • products[][custom-price]: {} (object, required) – The products prices for different currencies.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "options": [
                {
                    "name": "option_name_1",
                    "value": "option_value2"
                }
            ],
            "custom-price": {
                "EUR": 1
            }
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "options": [
                {
                    "name": "option_name_1",
                    "value": "option_value2"
                }
            ],
            "custom-price": {
                "EUR": 1
            }
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Catalog product with custom price

Signature parameter(s):

  • currency: USD (string, required) – Pre-selected billing currency is used to charge your customers.
  • products[][code]: PRODUCT_CODE_1 (string, required) – The product code.
  • products[][price]: {} (object, required) – The product prices for different currencies.
  • products[][custom-price]: {} (object, required) – The product custom prices for different currencies.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "custom-price": {
                "EUR": 10,
                "USD": 8
            }
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "currency": "USD",
    "products": [
        {
            "code": "PRODUCT_CODE_1",
            "custom-price": {
                "EUR": 10,
                "USD": 8
            }
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic Products Use Cases

Dynamic products

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Pre-selected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][price]: 10 (integer, required) - The products prices value.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME_1",
            "price": 10
        },
        {
            "name": "PRODUCT_NAME_2",
            "price": 8
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME_1",
            "price": 10
        },
        {
            "name": "PRODUCT_NAME_2",
            "price": 8
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with product quantity

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][quantity]: 1 (integer, required) - The number of units (quantity) for each product in checkout.
  • products[][price]: 10 (integer, required) - The products prices value.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME_1",
            "quantity": 1,
            "price": 10
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME_1",
            "quantity": 1,
            "price": 10
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with options

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][price]: 10 (integer, required) - The products prices value.
  • products[][options]: [] (array, required) - The product options.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME_1",
            "price": 10,
            "options": [
                {
                    "name": "option_name_1",
                    "value": "option_value_1",
                    "surcharge": 3
                }
            ]
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME_1",
            "price": 10,
            "options": [
                {
                    "name": "option_name_1",
                    "value": "option_value_1",
                    "surcharge": 3
                }
            ]
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with price

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][price]: 10 (integer, required) - The products prices value.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with product type

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][price]: 10 (integer, required) - The products prices value.
  • products[][type]: product (string, required) - The type of dynamic product. Possible values: product, shipping, tax.

If the type parameter is empty or not send, the default line item is considered product.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "TAX_VALUE",
            "price": 10,
            "type": "tax"
        },
        {
            "name": "SHIPPING_NAME",
            "price": 10,
            "type": "shipping"
        },
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "type": "product"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "TAX_VALUE",
            "price": 10,
            "type": "tax"
        },
        {
            "name": "SHIPPING_NAME",
            "price": 10,
            "type": "shipping"
        },
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "type": "product"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with tangible parameter

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][type]: product (string, required) - The type of dynamic product. Possible values: product, shipping, tax.
  • products[][price]: 10 (integer, required) - The products prices value.
  • products[][tangible]: 1 (boolean, required) - Send TRUE or 1 for products that require physical delivery.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "EUR",
    "products": [
        {
            "name": "TAX_VALUE",
            "type": "tax",
            "quantity": 1,
            "price": 1
        },
        {
            "name": "SHIPPING_NAME",
            "type": "shipping",
            "quantity": 1,
            "price": 1
        },
        {
            "name": "PRODUCT_NAME",
            "type": "product",
            "quantity": 1,
            "price": 1,
            "tangible": 1
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "EUR",
    "products": [
        {
            "name": "TAX_VALUE",
            "type": "tax",
            "quantity": 1,
            "price": 1
        },
        {
            "name": "SHIPPING_NAME",
            "type": "shipping",
            "quantity": 1,
            "price": 1
        },
        {
            "name": "PRODUCT_NAME",
            "type": "product",
            "quantity": 1,
            "price": 1,
            "tangible": 1
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with description

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][price]: 10 (integer, required) - The products prices value.
  • products[][description]: text... (string, required) - Description is displayed in the checkout page.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "dynamic": "1",
    "currency": "USD",
    "merchant": "MERCHANT_CODE",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "description": "product description"
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "dynamic": "1",
    "currency": "USD",
    "merchant": "MERCHANT_CODE",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "description": "product description"
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with recurrence, duration and renewal price

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][price]: 10 (integer, required) - The products prices value.
  • products[][recurrence][length]: 1 (integer, required) - Set product recurring period.
  • products[][recurrence][unit]: day (string, required) - Set product recurring unit. Example: day
  • products[][duration][length]: 1 (integer, required) - Set the duration of the recurrence period.
  • products[][duration][unit]: day (string, required) - Set the duration of the recurrence unit. Example: day
  • products[][renewal-price]: 20 (integer, required) - Set the price that should be applied to the renewal order. This parameter is conditioned by two other parameters: duration and renewal-price.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "recurrence": {
                "length": 1,
                "unit": "day"
            },
            "duration": {
                "length": 1,
                "unit": "day"
            },
            "renewal-price": 20
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "recurrence": {
                "length": 1,
                "unit": "day"
            },
            "duration": {
                "length": 1,
                "unit": "day"
            },
            "renewal-price": 20
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

Dynamic product with item external reference

Signature parameter(s):

  • dynamic: 1 (boolean, required) - Set TRUE or "1" for dynamic products.
  • currency: USD (string, required) - Preselected billing currency is used to charge your customers.
  • products[][name]: PRODUCT_NAME_1 (string, required) - The name of the dynamic product.
  • products[][price]: 10 (integer, required) - The products prices value.
  • products[][reference][external][item]: ref-1 (string, required) - Set product identifier for your dynamic products. You can send multiple values separated by semicolon.

cURL

curl -X POST \
  https://secure.2checkout.com/checkout/api/encrypt/generate/signature \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg' \
  -d '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "reference": {
                "external": {
                    "item": "item_external_reference"
                }
            }
        }
    ]
}'

PHP

$curl = curl_init();
$payload = '{
    "merchant": "MERCHANT_CODE",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "PRODUCT_NAME",
            "price": 10,
            "reference": {
                "external": {
                    "item": "item_external_reference"
                }
            }
        }
    ]
}';
curl_setopt_array($curl, [
    CURLOPT_URL            => "https://secure.2checkout.com/checkout/api/encrypt/generate/signature",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'content-type: application/json',
        'merchant-token: eyJhbGciOiJIUz.............oXW6ykmEMx7XjGQPTMFg',
    ],
]);
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response . PHP_EOL;
}

Result

{"signature":"ffff1f2daef1.....................f771ac345efff"}

 

Use PayPal

Overview

Place an order with dynamic product information, and collect the payment using PayPal.

Parameters

Parameters Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

Order

Required (Object)

 

Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

To place an order with PayPal rather than PayPal Express, use PAYPAL as the type of the PaymentDetails object and send the shopper email and a return URL as part of the PaymentMethod object. See code sample. 

Workflow

  1. Create the order object. Use PAYPAL as the type of the PaymentDetails object and send the shopper email and a return URL as part of the PaymentMethod object. Place the order.
  2. Once you place the order, Avangate logs it into the system. At this point in time, the status of the order is PENDING. Avangate responds with the Order information object.
  3. Redirect shoppers to the RedirectURL from the Order information object you receive as response from Avangate.
  4. Once shoppers log into their PayPal account and complete the transaction, they're redirected to the ReturnURL you set in the order object. Avangate also authorizes the order and updates the status to AUTHRECEIVED. 

Response

Order information Type/Description
  Object containing order information.

Request 

<?php

require ('PATH_TO_AUTH');

$Order = new stdClass();
$Order->Currency = "EUR";
$Order->Language = "EN";
$Order->Country = "NL";
$Order->CustomerIP = '91.220.121.21';//"10.10.13.37";
$Order->Source = "sourceAPI.net";
$Order->LocalTime = date('Y-m-d H:i:s');
$Order->CustomerReference = 421820775;
$Order->Items = array();

/**
 * 1st Product
 */
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = null;
$Order->Items[0]->Quantity = 2;
$Order->Items[0]->PurchaseType = 'PRODUCT';
$Order->Items[0]->Tangible = true; // physical
$Order->Items[0]->IsDynamic = true;

$Order->Items[0]->Price = new stdClass();
$Order->Items[0]->Price->Amount = 100;
$Order->Items[0]->Price->Type = 'CUSTOM';

$Order->Items[0]->Name = 'Dynamic Product 1 '. date("Y-m-d H:i:s");
$Order->Items[0]->Description = 'Description Produs OTF';

$Order->Items[0]->PriceOptions = [];
$priceOption = new stdClass();
$priceOption->Name = 'Name';
$priceOption->Value = 'Value';
$priceOption->Surcharge = 10;
$Order->Items[0]->PriceOptions[] = $priceOption;

$priceOption1 = new stdClass();
$priceOption1->Name = 'Name';
$priceOption1->Value = 'Value123';
$priceOption1->Surcharge = 11;
$Order->Items[0]->PriceOptions[] = $priceOption1;

$priceOption2 = new stdClass();
$priceOption2->Name = 'Name1';
$priceOption2->Value = 'Value1';
$priceOption2->Surcharge = 12;
$Order->Items[0]->PriceOptions[] = $priceOption2;

$Order->Items[0]->RecurringOptions = new stdClass();
$Order->Items[0]->RecurringOptions->CycleLength = 1;
$Order->Items[0]->RecurringOptions->CycleUnit = 'MONTH';
$Order->Items[0]->RecurringOptions->CycleAmount = 1234;
$Order->Items[0]->RecurringOptions->ContractLength = 3;
$Order->Items[0]->RecurringOptions->ContractUnit = 'YEaR';

/**
 * 3rd Product - SHIPPING
 */
$Order->Items[2] = new stdClass();
$Order->Items[2]->Name = 'Shipping Item '. date("Y-m-d H:i:s");
$Order->Items[2]->PurchaseType = 'SHIPPING';
$Order->Items[2]->Quantity = 1;
$Order->Items[2]->Price = new stdClass();
$Order->Items[2]->Price->Amount = 123;
$Order->Items[2]->IsDynamic = true;

/**
 * 4th Product - TAX
 */
$Order->Items[3] = new stdClass();
$Order->Items[3]->Name = 'Tax Item '. date("Y-m-d H:i:s");
$Order->Items[3]->PurchaseType = 'TAX';
$Order->Items[3]->Quantity = 1;
$Order->Items[3]->Price = new stdClass();
$Order->Items[3]->Price->Amount = 456;
$Order->Items[3]->IsDynamic = true;
$Order->Items[3]->RecurringOptions = new stdClass();
$Order->Items[3]->RecurringOptions->CycleLength = 1;
$Order->Items[3]->RecurringOptions->CycleUnit = 'MONTH';
$Order->Items[3]->RecurringOptions->CycleAmount = 10.2;
$Order->Items[3]->RecurringOptions->ContractLength = 3;
$Order->Items[3]->RecurringOptions->ContractUnit = 'YEaR';

/**
 * 5th Product - COUPON
 */
$Order->Items[4] = new stdClass();
$Order->Items[4]->Name = 'Coupon Item '. date("Y-m-d H:i:s");
$Order->Items[4]->PurchaseType = 'COUPON';
$Order->Items[4]->Quantity = 1;
$Order->Items[4]->Price = new stdClass();
$Order->Items[4]->Price->Amount = 234;
$Order->Items[4]->IsDynamic = true;

/**/
$additionalField1 = new stdClass();
$additionalField1->Code = "additional_field_order_1";
$additionalField1->Text = "REST";
$additionalField1->Value = "1";

$additionalField2 = new stdClass();
$additionalField2->Code = "additional_field_order_2";
$additionalField2->Text = "REST";
$additionalField2->Value = "a";

$additionalField3 = new stdClass();
$additionalField3->Code = "additional_field_order_3";
$additionalField3->Text = "REST";
$additionalField3->Value = "a";

$Order->AdditionalFields = array();
$Order->AdditionalFields[0] = $additionalField1;
$Order->AdditionalFields[1] = $additionalField2;
$Order->AdditionalFields[2] = $additionalField3;

$additionalField1 = new stdClass();
$additionalField1->Code = "REST";
$additionalField1->Text = "REST";
$additionalField1->Value = "REST";



$Order->MachineId = 'machineIdTestDan';
$Order->Discount = null;
$Order->ExternalReference = null;

$Order->BillingDetails = new stdClass();
$Order->BillingDetails->Address1 = 'Address 1';
$Order->BillingDetails->Address2 = 'Address 2';
$Order->BillingDetails->City = 'Billing City';
$Order->BillingDetails->State = 'Billing State';
$Order->BillingDetails->CountryCode = 'NL';
$Order->BillingDetails->Phone = US;
$Order->BillingDetails->Email = 'shopper@avangate.com';
$Order->BillingDetails->FirstName = 'John';
$Order->BillingDetails->LastName = 'Doe';
$Order->BillingDetails->Company = 'Billing Company';
$Order->BillingDetails->Zip = '12345';


/**/
$Order->DeliveryDetails = new stdClass();
$Order->DeliveryDetails->Address1 = 'Address 1';
$Order->DeliveryDetails->Address2 = 'Address 2';
$Order->DeliveryDetails->City = 'Billing City';
$Order->DeliveryDetails->State = 'Billing State';
$Order->DeliveryDetails->CountryCode = 'US';
$Order->DeliveryDetails->Phone = '12345';
$Order->DeliveryDetails->Email = 'customer@email.com';
$Order->DeliveryDetails->FirstName = 'John';
$Order->DeliveryDetails->LastName = 'Doe';
$Order->DeliveryDetails->Zip = 12345;
/**/

$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'PAYPAL';
$Order->PaymentDetails->Currency = 'eur';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '91.220.121.21';
$Order->PaymentDetails->PaymentMethod->ReturnURL = 'http://yourreturnurl.com';
$Order->PaymentDetails->PaymentMethod->Email= 'email@avangate.com';

$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'placeOrder';
$jsonRpcRequest->params = array($sessionID, $Order);
$jsonRpcRequest->id = $i++;

$APIOrderFullInfo = callRPC((Object)$jsonRpcRequest, $host);

$url = $APIOrderFullInfo->PaymentDetails->PaymentMethod->RedirectURL;

header ("Location: $url");

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