One click (1-click) purchase - PayPal
Overview
2Checkout supports 1-click purchases for returning customers who paid for their previous orders with PayPal.
Availability
Select 2Checkout accounts. Contact 2Checkout for more details.
Requirements
- Shoppers enabled recurring billing (auto-renewal) for their initial purchase with PayPal.
- The 2Checkout risk department needs to have approved the initial order whose reference you're using to place another order. 2Checkout 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 2Checkout 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
2Checkout 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, 2Checkout considers both the initial and the subsequent order, new purchases.
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. |
Required (Object) |
|
|
Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. |
Response
Parameter | Type/Description |
---|---|
Object |
Request example
<?php
echo "<pre>";
$host = "https://api.2checkout.com";
$client = new SoapClient($host . "/soap/4.0/?wsdl", array(
'location' => $host . "/order/4.0/soap",
"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 = "MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key = "SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.2checkout.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;
}
$orderReference = '45452071';
try {
$validOrderRef = $client->isValidOrderReference($sessionID, $orderReference);
}
catch (SoapFault $e) {
echo "validOrderRef: " . $e->getMessage();
exit;
}
var_dump("validOrderRef", $validOrderRef);
$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_2';
$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@2checkout.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 = $orderReference;
try {
$prevrefOrder = $client->placeOrder($sessionID, $newOrder);
}
catch (SoapFault $e) {
echo "prevrefOrder: " . $e->getMessage();
exit;
}
var_dump("prevrefOrder", $prevrefOrder);
?>