Skip to main content
knowledgecenter.2checkout.com

Use Alipay

Overview

Alipay is a third-party online payment solution, allowing customers to make and receive payments on the Internet. Alipay's market share of online payments exceeds 54% in China.

Supported currencies

Alipay supports USD and CNY transactions.

Workflow

  1. Shoppers select Alipay as a payment option in the checkout interface you provide to them.
  2. Create the order object. Use “ALIPAY” as the type of the PaymentDetails object.
  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, 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. Using the provided URL, make a request using the provided method (usually a GET request) and add the parameters (located in the Params object) as key-value pairs to the body of the request. 

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.

See code sample for more details. 

Request Example

<?php
// Api Name & Method
$apiName = ' '.'placeOrderwithAlipay';
// include(dirname(__DIR__) . '/../Config.php');
include('Config.php');

// Grab Config Values
$config = new ConfigScripts();
$apiVersion = '6.0';
// $host = 'http://api.sandbox' . $config->SandboxNr . '.avangate.local/rpc/' . $apiVersion . '/';
$host = 'http://api.wwwtest2.dev.corp.2co.com:8081/rpc/' . $apiVersion . "/";


// Login to get the session id;
$sessionID = $config->rpcLogin($host);

// Electronic product - ELEDELPROD
// Physical product - 089F06CC45
// Useful variables
$productCode = 'ghiocel_tangible';
$productQuantity = 1;
// $defaultCurr = "NZD";
// $defaultCountry = "NZ";
$i = 1;


$defaultCountry = "cn";
$Currency = "USD";

$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = $Currency ;
// $Order->Currency = 'ron' ;
$Order->Country = $defaultCountry;
$Order->Language = 'EN';
$Order->CustomerIP = '10.5.22.197';
$Order->ExternalReference = NULL;
$Order->Source = NULL;
$Order->AffiliateId = NULL;
$Order->CustomerReference = NULL;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = $productCode;
$Order->Items[0]->Quantity = $productQuantity;
$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 = 'John';
$Order->BillingDetails->LastName = 'Doe';
$Order->BillingDetails->CountryCode = $defaultCountry;
$Order->BillingDetails->State = 'Espírito Santo';
$Order->BillingDetails->City = 'City';
$Order->BillingDetails->Address1 = '-';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '1111111';
$Order->BillingDetails->Email = 'brazil1@2checkout.com';
$Order->BillingDetails->Phone = '123432323212';
$Order->BillingDetails->Company = 'blank';
$Order->DeliveryDetails = new stdClass();
$Order->DeliveryDetails->FirstName = 'John';
$Order->DeliveryDetails->LastName = 'Doe';
$Order->DeliveryDetails->CountryCode = 'NZ';
$Order->DeliveryDetails->State = 'Espírito Santo';
$Order->DeliveryDetails->City = 'City';
$Order->DeliveryDetails->Address1 = '-';
$Order->DeliveryDetails->Address2 = NULL;
$Order->DeliveryDetails->Zip = '1111111';
$Order->DeliveryDetails->Email = 'brazil1@2checkout.com';
$Order->DeliveryDetails->Phone = '123432323212';
$Order->DeliveryDetails->Company = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'ALIPAY';
$Order->PaymentDetails->Currency = $Currency ;
$Order->PaymentDetails->HadPayPalToken = false;
$Order->PaymentDetails->CustomerIP = '10.5.22.197';

$Order->PaymentDetails->PaymentMethod = new stdClass ();


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


print_r($host);
// Perform the RPC call
print "\n\n**********************";
print "\nAPI:".$apiName;
print "\nAPI Version:".$apiVersion;

$response = $config->callRPC($jsonRpcRequest, $host, true);
$strJsonFormat_with_space = json_encode($response, JSON_PRETTY_PRINT);

print "\n\n**********************\n";

print "\nBODY:\n\n" . $strJsonFormat_with_space;
print "\n\n**********************";

Response Example

Parameter Type/Description

Order information

Object

  Object containing order information.
  • Was this article helpful?