Skip to main content

One click (1-click) purchase - PayPal

One click (1-click) purchase - PayPal

Last updated: 13-Oct-2021
Rate this article:

Overview

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

Availability

Select Avangate accounts. Contact Avangate for more details. 

Requirements

  • 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. 

Workflow 

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 = '10.10.10.10';
$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). 

Cross-sell

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. 

Parameters

Response

Request

<?php
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) {
        $RequestString;
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        $ResponseString;
    }

    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 = 'https://api.avangate.com/rpc/3.0/';

$merchantCode = "MERCHANT_CODE";// 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

$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);

var_dump($sessionID);

$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 = 'shopper@avangate.com';

$newOrder->DeliveryDetails = NULL;

$newOrder->PaymentDetails = new stdClass ();
$newOrder->PaymentDetails->Type = 'PREVIOUS_ORDER';
$newOrder->PaymentDetails->Currency = 'usd';
$newOrder->PaymentDetails->PaymentMethod = new stdClass ();
$newOrder->PaymentDetails->CustomerIP = '10.10.10.10';
$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));
Rate this article:

Need help?

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

Not yet a Verifone customer?

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

Verifone logo