Skip to main content

One click (1-click) purchase - PayPal


Avangate supports 1-click purchases for returning customers who paid for their previous orders with PayPal. 


Select Avangate accounts. Contact Avangate for more details. 


  • Shoppers enabled recurring billing (auto-renewal) for their initial purchase with PayPal. 
  • The Avangate risk department needs to have approved the initial order whose reference you're using to place another order. Avangate uses complex fraud detection technology that blocks fraudulent transactions. This process is expected to take a few seconds. The time is usually covered by the action of showing a new offer to shoppers, but we recommend  checking that ApproveStatus is OK. 
  • Use only references of previous orders with one of the following statuses AUTHRECEIVED or COMPLETE.
  • The email address of the BillingDetails object is mandatory and it needs to match the email address used as a part of the billing details of the initial order whose reference you're now using to place a new order. 2Checkout checks whether the email addresses are identical, and throws an error if they're not, blocking the order placement process. Note: You need to provide only the email address of the shopper, and can ignore the rest of the required customer billing information. If you enter any billing details in addition to the email address, you'll have to provide all information required in the BillingDetails object.


Validate previous order references

For 1-click purchase scenarios use the isValidOrderReference method. The initial order must meet the following requirements:

  • Shoppers enabled recurring billing (auto-renewal).
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
  • Its status is either COMPLETE or AUTHRECEIVED
  • The Avangate risk department approved the order. 

Create the order object

  • Populate the BillingDetails object with the same details as the billing info of the initial order. Make sure that at least the email addresses match.
  • Build your PaymentDetails object using the reference of the initial order as a payment method.
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'PREVIOUS_ORDER';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->RefNo = $orderReference;

Place the new order 

Avangate charges returning customers using their payment-on-file information (their PayPal account). 


If you need to track cross-sells, we recommend using additional fields to mark orders as such. With this particular flow, Avangate considers both the initial and the subsequent order, new purchases. 





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.


Required (Object)


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


Parameter Type/Description

Order information



echo "<pre>";
function callRPC($Request, $hostUrl, $Debug = true) {
    $curl = curl_init($hostUrl);
    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'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);

    if ($Debug) {
    $ResponseString = curl_exec($curl);
    if ($Debug) {

    if (!empty($ResponseString)) {
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        if (!is_null($Response->error)) {
            var_dump($Request->method, $Response->error);
    } else {
        return null;

$host = '';

$merchantCode = "MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel:
$key = "SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel:

$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);

$i = 1; // counter for api calls

// call login
$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;

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


$refNo = '45452071';

$jsonRpcRequest = array (
'method' => 'isValidOrderReference',
'params' => array($sessionID, $refNo),
'id' => $i++,
'jsonrpc' => '2.0'

var_dump (callRPC((Object)$jsonRpcRequest, $host, true));

$newOrder = new stdClass();

$newOrder->RefNo = NULL;
$newOrder->Currency = 'usd';
$newOrder->Country = 'US';
$newOrder->Language = 'en';
$newOrder->Items = array();
$newOrder->Items[0] = new stdClass();
$newOrder->Items[0]->Code = 'my_subscription_1';
$newOrder->Items[0]->Quantity = 1; 

$newOrder->BillingDetails = new stdClass();
$newOrder->BillingDetails->FirstName = 'FirstName';
$newOrder->BillingDetails->LastName = 'LastName';
$newOrder->BillingDetails->CountryCode = 'us';
$newOrder->BillingDetails->State = 'California';
$newOrder->BillingDetails->City = 'LA';
$newOrder->BillingDetails->Address1 = 'Address example';
$newOrder->BillingDetails->Zip = '90210';
$newOrder->BillingDetails->Email = '';

$newOrder->DeliveryDetails = NULL;

$newOrder->PaymentDetails = new stdClass ();
$newOrder->PaymentDetails->Type = 'PREVIOUS_ORDER';
$newOrder->PaymentDetails->Currency = 'usd';
$newOrder->PaymentDetails->PaymentMethod = new stdClass ();
$newOrder->PaymentDetails->CustomerIP = '';
$newOrder->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$newOrder->PaymentDetails->PaymentMethod->RefNo = $refNo;

$jsonRpcRequest = array (
'method' => 'placeOrder',
'params' => array($sessionID, $newOrder),
'id' => $i++,
'jsonrpc' => '2.0'
var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
  • Was this article helpful?