Skip to main content

Place an order with WeChat

Last updated: 16-Apr-2018
Rate this article:

Overview

Use the placeOrder method to create an order and collect the payment from WeChat.

Requirements

WeChat Pay is available only for orders with a minimum value of 0.01 USD, placed by shoppers in China or Hong Kong and using one of the supported currencies. You're required to include the following text when using Avangate API and to make it visible for your customers in the ordering interface.

Order processed by Avangate, authorized reseller and merchant of the products and services offered within this store. 

Supported currencies

  • CNY
  • USD
  • HKD

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 Avangate.
  4. Once you place the order, Avangate logs it into the system. At this point in time, the status of the order is PENDING.
  5. Avangate 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.avangate.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 Avangate 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. 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 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

    Order information

    Object

    Request

    
    <?php
    
    // authentication script: https://knowledgecenter.avangate.com/Integration/JSON-RPC_API/API_4.0/00Authentication
    
    require ('PATH_TO_AUTH');
    
    $Order = new stdClass();
    $Order->RefNo = NULL;
    $Order->Currency = 'cny';
    $Order->Country = 'cn';
    $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->BillingDetails = new stdClass();
    $Order->BillingDetails->FirstName = 'FirstName';
    $Order->BillingDetails->LastName = 'LastName';
    $Order->BillingDetails->CountryCode = 'CN';
    $Order->BillingDetails->State = 'State Example';
    $Order->BillingDetails->City = 'City Example';
    $Order->BillingDetails->Address1 = 'Address example';
    $Order->BillingDetails->Address2 = NULL;
    $Order->BillingDetails->Zip = '12345';
    $Order->BillingDetails->Email = 'email@address.com';
    $Order->BillingDetails->Phone = NULL;
    $Order->BillingDetails->Company = NULL;
    $Order->PaymentDetails = new stdClass ();
    $Order->PaymentDetails->Type = 'WE_CHAT_PAY';
    $Order->PaymentDetails->Currency = 'cny';
    $Order->PaymentDetails->PaymentMethod = new stdClass ();
    $Order->PaymentDetails->CustomerIP = '91.220.121.21';
    $Order->PaymentDetails->PaymentMethod->ReturnURL = 'YOUR_RETURN_URL';
    $Order->PaymentDetails->PaymentMethod->CancelURL= 'YOUR_CANCEL_URL';
    
    $jsonRpcRequest = new stdClass();
    $jsonRpcRequest->jsonrpc = '2.0';
    $jsonRpcRequest->method = 'placeOrder';
    $jsonRpcRequest->params = array($sessionID, $Order);
    $jsonRpcRequest->id = $i++;
     
    $output = callRPC($jsonRpcRequest, $host);
    
    $wechatredirect = $output->PaymentDetails->PaymentMethod->Authorize->Href."/?avng8apitoken=".$output->PaymentDetails->PaymentMethod->Authorize->Params->avng8apitoken;
    
    header('Location:' . $wechatredirect);
    
    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