Skip to main content

Upgrade subscription

Overview

Use the setSubscriptionUpgrade method to upgrade a subscription.

Requirements

You can only upgrade subscriptions with automatic renewal enabled.

   The upgrade will not work if the subscription has a refund request that was not yet processed.

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.

subscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

productCode

Required (string)

 

Unique identifier of the target product for the subscription upgrade process. You control the product code and can set it up in the Control Panel.

options

Optional (string)

 

Pricing options of the target product for the subscription upgrade process.

 

String - ';' separated list of 'OptionValue' returned by getProductUpgradeOptions function.

If the pricing options groups is "scale" (interval), the Options parameter should be sent like this: [option group unique code] + "=" + value

e.g. Users=7

customPrice

Optional (string)

 

The price you want to charge customers for the upgrade. The currency used by default is the same as in the previous payment customers made.

Response

Parameters Type/Description

Boolean

true or false depending on whether or not the operation succeeded.

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';
$productCode = 'YOUR_PRODUCT_CODE';
$options = 'YOUR_PRICE_CODES'; //case sensitive; include only price options codes (exclude spaces)
$customPrice = 1;

$jsonRpcRequest = array (
'method' => 'setSubscriptionUpgrade',
'params' => array($sessionID, $subscriptionReference, $productCode, $options, $customPrice),
'id' => $i++,
'jsonrpc' => '2.0');

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

Set the shipping details in the InLine Checkout

Overview

Pre-set the shipping details for the InLine checkout.

Use case

  1. Add an HTML link or button in your page like the one below.
  2. Create a JavaScript click handler to execute the Inline Client desired methods.
  3. Use theTwoCoInlineCart.products.add({code, quantity, options})method to prepare your catalog product.
  4. Call any of the following methods to pre-set the shipping details:
TwoCoInlineCart.shipping.setName('Shopper name');
  TwoCoInlineCart.shipping.setEmail('shopper.email@example.com');
  TwoCoInlineCart.shipping.setPhone('+1 202 555 0115');
  TwoCoInlineCart.shipping.setCountry('US');
  TwoCoInlineCart.shipping.setCity('Denver');
  TwoCoInlineCart.shipping.setState('Colorado');
  TwoCoInlineCart.shipping.setZip('80249');
  TwoCoInlineCart.shipping.setAddress('Pena Blvd');
  TwoCoInlineCart.shipping.setAddress2('');

5. If you want to reset the shipping details, call theTwoCoInlineCart.shipping.reset()method.
6. Use theTwoCoInlineCart.cart.checkout()method to show the cart on your page.

Sample request

HTML

<a href="#" class="btn btn-success" id="buy-button">Buy now!</a>

JavaScript

window.document.getElementById('buy-button').addEventListener('click', function() {
  TwoCoInlineCart.products.add({
    code: "74B8E17CC0"
  });
  
  // Style 1 (all data at once)
  TwoCoInlineCart.shipping.setData({
        name    : 'Shopper name',
        country : 'US',
        email   : 'shopper.email@example.com',
        city    : 'Denver',
        state   : 'Colorado',
        zip     : '80249',
        phone   : '+1 202 555 0115',
        address : '',
        address2: 'Pena Blvd'
  });

  // Reset
  TwoCoInlineCart.shipping.reset();
  
  // Style 2 (simple)
  TwoCoInlineCart.shipping.setName('Shopper name');
  TwoCoInlineCart.shipping.setEmail('shopper.email@example.com');
  TwoCoInlineCart.shipping.setPhone('+1 202 555 0115');
  TwoCoInlineCart.shipping.setCountry('US');
  TwoCoInlineCart.shipping.setCity('Denver');
  TwoCoInlineCart.shipping.setState('Colorado');
  TwoCoInlineCart.shipping.setZip('80249');
  TwoCoInlineCart.shipping.setAddress('Pena Blvd');
  TwoCoInlineCart.shipping.setAddress2('');
  
  // Reset
  TwoCoInlineCart.shipping.reset();
  
   // Style 3 (chained)
  TwoCoInlineCart.shipping
    .setName('Shopper name')
    .setEmail('shopper.email@example.com')
    .setPhone('+1 202 555 0115')
    .setCountry('US')
    .setCity('Denver')
    .setState('Colorado')
    .setZip('80249')
    .setAddress('Peña Blvd')
    .setAddress2('');
  
  TwoCoInlineCart.cart.checkout();
});

Demo

After setting the shipping details for the InLine checkout using the above methods, your cart should look like this:

Subscription

Overview

The object below is returned directly or within a successful response from the following API requests:

Retrieve a subscription             Search subscriptions            Retrieve customer's subscriptions          Retrieve specific subscriptions

Subscription object

Parameters Type/Description

SubscriptionReference

String

 

Unique, system-generated subscription identifier.

StartDate

String

 

Subscription start date(YYYY-MM-DD) - StartDate is mandatory when importing subscription data. If you changed the time zone for the Avangate API by editing system settings under Account settings, then the StartDate you provide must be in accordance with your custom configuration.

ExpirationDate

String

 

Subscription expiration date(YYYY-MM-DD) - ExpirationDate is mandatory when importing subscription data. If you changed the time zone for the Avangate API by editing system settings under Account settings, then the ExpirationDate you provide must be in accordance with your custom configuration.

RecurringEnabled

Boolean

 

Possible values:

TRUE – recurring billing/automatic subscription renewals enabled

FALSE– recurring billing/automatic subscription renewals disabled

SubscriptionEnabled

Boolean

Possible values:

TRUE –subscription enabled

FALSE–subscription disabled

Product

Required (object)

 

The product for which Avangate generated the subscription. Details below.

 

ProductCode

String

 

 

Unique product identifier that you control.

 

ProductId

Int

 

 

Unique, system-generated product identifier.

 

ProductName

String

 

 

Product name.

 

ProductQuantity

Int

 

 

Ordered number of units.

 

ProductVersion

String

 

 

Product version.

 

PriceOptionCodes

Array

 

 

The product options codes the customer selected when acquiring the subscription. Pricing options codes are case sensitive.

EndUser

Object

 

The end user of the subscription. Details below.

 

Person

Object

 

 

FirstName

String

 

 

 

End user's first name

 

 

LastName

String

 

 

 

End user's last name

 

 

CountryCode

String

 

 

 

End user country code [ISO3166-1 Alpha 2].

 

 

State

String

 

 

 

End user state.

 

 

City

String

 

 

 

End user city.

 

 

Address1

String

 

 

 

End user first address line.

 

 

Address2

String

 

 

 

End user second address line.

 

 

Zip

String

 

 

 

End user zip code.

 

 

Email

String

 

 

 

End user email address.

 

 

Phone

String

 

 

 

End user phone number.

 

 

Company

String

 

 

 

Company name.

 

 

Fax  

String

 

 

End user fax.

 

 

Language  

String

 

 

Language [ISO639-2] the Avangate system uses for communications.

SKU

String

 

Stock keeping unit you defined.

DeliveryInfo

Object

 

The object contains information about the delivery/fulfillment made to the customer.

 

Description

String

 

 

Delivery description.

 

Codes

Array of objects

 

 

Code

String

 

 

 

Activation key/license code of the first order from this subscription. Use getSubscriptionHistory method if you want to retrieve the activation keys/license codes for all orders belonging to a subscription.

 

 

Description

String

 

 

 

Code description for dynamic lists from your key generator. 

 

 

ExtraInfo

Object

 

 

 

Info set by your key generator for dynamic lists only.

 

 

 

CodeExtraInfo

Object

 

 

 

Type

String

 

 

 

Label

String

 

 

 

Value

String

 

 

File

Array of objects

 

 

 

Content

String

 

 

 

 

Content of the file (base64 encoded).

 

 

 

ContentLength

Int

 

 

 

 

File size.

 

 

 

Filename

String

 

 

 

 

The name of the delivered file.

 

 

 

FileType

String

 

 

 

 

The type of the delivered file.

ReceiveNotifications

Boolean

 

1 – Subscribe: Avangate sends subscription notifications to the end user.

0 – Unsubscribe – Avangate does not send subscription notifications to the end user.

Lifetime

Boolean

 

Possible values:

  • True – the subscription is evergreen

False – the subscription has a recurring billing cycle less than or equal to three years.

PartnerCode

String

 

  • Empty: for ecommerce orders
  • Partner Code

AvangateCustomerReference

Int

 

Unique, system-generated customer identifier.

ExternalCustomerReference

String

 

Customer identifier that you control.

TestSubscription

Boolean

 

True for test subscriptions, false otherwise.

IsTrial

Boolean

 

True for trial subscriptions, false otherwise.

MerchantCode String
  Unique, system-generated ID in the Avangate system.

Subscription upgrade

Overview

Retrieve information about the upgrade options for a specific subscription.

Trigger upgrade for your existing subscriptions, or set external references to a subscription by using the API methods displayed below.

 

Place orders with cross-sell campaigns

Overview

Cross-selling allows you to recommend additional products to customers and increase the average order value. The 2Checkout Public API supports classic cross-sell campaigns which means you can recommend more products from your own product catalog to your shoppers.

CrossSell Object for the placeOrder API method

Use the CrossSell object below to recommend additional products to customers via the SOAP API 6.0.

Parameter name Type Required/Optional Description
ParentCode String Required Product code of the product to be recommended to the shopper.
CampaignCode String Required The upsell campaign code.

Request Example

{ 
  "Currency": "USD", 
  "Language": "EN", 
  "Country": "US", 
  "CustomerIP": "10.10.10.10", 
  "Source": "sourceAPI.net", 
  "CustomerReference": 421820775, 
  "Items": [ 

    { 
      "Code": "15", 
      "Quantity": 1 
    }, 
    { 
      "Code": "34924C876E", 
      "Quantity": 1, 
      "CrossSell":{ 
        "ParentCode" : "15", 
        "CampaignCode" : "2Xrl83KSkemCv3G3dL%2B9eA%3D%3D" 
      } 
    } 
  ], 

   "BillingDetails":{ 

      "FirstName":"Customer First Name", 
      "LastName":"Customer Last Name", 
      "CountryCode":"US", 
      "State":"California", 
      "City":"San Francisco", 
      "Address1":"Example Street", 
      "Zip":"90210", 
      "Email":"example@email.com" 

   }, 

  "PaymentDetails": { 
    "Type": "CC", 
    "Currency": "USD", 
    "CustomerIP": "10.10.10.10", 
    "PaymentMethod": { 

      "Vendor3DSReturnURL": "https:\/\/example.com", 
      "Vendor3DSCancelURL": "https:\/\/example.com", 
      "CardNumber": "4111111111111111", 
      "CardType": "VISA", 
      "ExpirationYear": "2020", 
      "ExpirationMonth": "12", 
      "CCID": "123", 
    } 
  } 
} 

Response

Using the same structure, the getContents method will take into account the discount associated with the cross-sell campaign and display the appropriate prices and taxes.

{ 
    "Country": "DE", 
    "Currency": "EUR", 
    "Items": [ 
        { 
            "Code": "NIQRPI0GTU", 
            "Quantity": 1 
        }, 

        { 
            "Code": "0XICS3OVDK", 
            "Quantity": 1, 

"CrossSell":{ 
        "ParentCode" : " NIQRPI0GTU ", 
        "CampaignCode" : "2Xrl83KSkemCv3G3dL%2B9eA%3D%3D" 
      } 

        } 
    ], 

    "BillingDetails": { 
        "FirstName": "Customer First Name", 
        "LastName": "Customer Last Name", 
        "CountryCode": "DE", 
        "City": "Bucharest", 
        "Address1": "Example Street", 
        "Zip": "73331", 
        "Email": "example@email.com" 
    } 
} 

 

Implement Google Universal Analytics in ConvertPlus and InLine Checkout (with GTM)

Overview

You can implement Google Universal Analytics and Google Tag Manager tracking tools to help you track and monitor your ConvertPlus and InLine checkout orders to improve the shopping experience and increase the conversion rate.

   This documentation refers to Google Universal Analytics, which is a deprecated version that will be sunset starting July 1st 2023 for free Universal Analytics properties and starting July 1st 2024 for 360 Universal Analytics properties. We strongly recommend you to migrate as soon as possible to Google Analytics 4 using the data layer that we have on GA4 format.

Availability

Google Universal Analytics and Google Tag Manager can be set for all 2Checkout accounts.

Google Universal Analytics Settings

Implement Google Universal Analytics

To implement Google Universal Analytics through Google Tag Manager (GTM) for your ConvertPlus and InLine Checkout, follow these steps:

1. In your browser window, navigate to Tag manager → All accounts.

2. Click on the Create Account button.

Google analytics via GTM_1.png

3. Fill in all the required fields:

  • Account Name
  • Country
  • Container name
  • Target platform → Web

4. Click on the Create button.

5. Copy the Google Tag Manager Container ID. It will be used in the 2Checkout Merchant Control Panel for the Google Tag Manager set-up.

Google analytics via GTM_2.png

Create a Google Universal Analytics Settings variable in Google Tag Manager

If you already have a Google Universal Analytics Settings variable with your Google Universal Analytics Tracking ID, then skip to step 5.

If you do not have a Google Universal Analytics Settings variable created for your website tracking, you will need to create one to add the Google Universal Analytics property to which you want to send data by following these steps:

1. In your Google Tag Manager account, navigate to Variables → User-Defined Variables → New.

Google analytics via GTM_3.png

2. From the list provided by Google, select the Google Universal Analytics Settings option as Variable Type. Name your variable “Google Analytics Settings”, so you can easily identify it.

3. Under Tracking ID add the Google Universal Analytics Tracking ID to which you wish to send data.

4. To get your Google Universal Analytics Tracking ID, navigate to Google Universal Analytics → Admin → Tracking Info → Tracking Code. You will find the code under Tracking ID. Copy and add it to your variable.

google analytics tracking id.png

5. For cross-domain tracking between your website and the 2Checkout shopping cart, you need to configure cross-domain settings in the Google Universal Analytics variable. This set-up is needed so that Google Universal Analytics counts a shopper coming from your website to the 2Checkout shopping cart, as the same visitor.

Go to More Settings → Cross Domain Tracking and type the following domains separated by a comma in the field named Auto Link Domains: secure.2checkout.com,tracking.avangate.net.

6. Append flags to the Google Universal Analytics cookie with “secure” and “samesite=none”. To do this, in the Google Universal Analytics Settings variable, click on Fields to set, add a new field and type cookieFlags as Field Name and samesite=none as Value secure, as in the example below.

google analytics with GTM_step6_new.png

7. Click Save.

Create the trigger for the Google Universal Analytics Convert Plus Tag

1. In Google Tag Manager, click on the Triggers section and then click to add a new trigger.

Google analytics via GTM_5.png

2. Create two triggers to track the Convert Plus and InLine shopping carts:

  • One for non-interactive events: checkout and purchase.
  • One for interactive events: removeFromCart (for the removeFromCart type of event, the user interacts with an element on the page by clicking the Remove from cart button. This is why this type of event is considered an interactive event by Google Universal Analytics) and addToCart.

Create the non-interactive event trigger

  1. Name your trigger Event Ecommerce Non-interactive.
  2. From the list provided, choose Custom event as Trigger Type.
  3. In the field Event name, type  .*  and check the box Use RegEx matching.
  4. For the "This trigger fires on" section, select Some custom events.
  5. As rule, fill in the boxes with Event matches RegEx (Ignore case) checkout|purchase.
  6. Click Save.

Google analytics via GTM_6.png 

Create the interactive event trigger

  1. Name your trigger Event Ecommerce Interactive.
  2. From the list provided, choose Custom event as Trigger Type.
  3. In the field Event name, type  .*  and check the box Use RegEx matching.
  4. For the "This trigger fires on" section, select Some custom events.
  5. As rule, fill in the boxes with Event matches RegEx (Ignore case) addToCart|removeFromCart .
  6. Click Save.

trigger configuration.jpg

Create the tag for ConvertPlus eCommerce tracking in Google Tag Manager

  1. In the Google Tag Manager interface, click on New Tag.
  2. Create two tags to track the ConvertPlus & InLine shopping carts.
  • One tag for non-interactive events: checkout and purchase
  • One tag for interactive events: removeFromCart

Google analytics via GTM_8.png

Create the tag for Non-interactive events

  1. Name your tag "Google Analytics Convert Plus – Event Type Non-Interactive”, to keep track of your tags easier.
  2. From the list provided by Google, select the option “Google Analytics: Universal Analytics” as Tag Type.
  3. For Category type Ecommerce, select Event as Track Type.
  4. For Action, select Event from the list provided by Google.
  5. In the Non-Interaction Hit field, select True.
  6. For the “Google Universal Analytics Settings” section, select your Google Universal Analytics Settings variable that contains the Google Analytics ID of your account.
  7. Check the box Enable overriding settings in this tag.

Google analytics via GTM_9.png

8. Under More Settings → Ecommerce → Enable Enhanced Ecommerce Features, select True.

9. Check the Use Data Layer box to capture eCommerce information from the data layer provided by 2Checkout.

Google analytics via GTM_10.png

10. In the Triggering section, select the previously configured trigger for non-interactive events: Event Ecommerce Non-interactive.

Google analytics via GTM_11.png

11. Click Save.

Create the tag for Interactive events

  1. Name your tag “Google Analytics Convert Plus – Event Type Interactive”, to keep track of your tags easier.
  2. From the list provided by Google, select the Google Analytics: Universal Analytics option as Tag Type.
  3. Select Event as Track Type.
  4. Select Ecommerce for Category type.
  5. From the list provided by Google, select Event for Action.
  6. In the Non-Interaction Hit field, select False.
  7. For the Google Universal Analytics Settings section, select your Google Universal Analytics Settings variable that contains the Google Analytics ID of your account.
  8. Check the Enable overriding settings in this tag box.

Google analytics via GTM_12.png

 9. Under More Settings → Ecommerce → Enable Enhanced Ecommerce Features, select True.

10. Check the Use Data Layer box to capture eCommerce information from the data layer provided by 2Checkout.

Google analytics via GTM_13.png

11. In the Triggering section, select the previously configured trigger for Interactive events: Event Ecommerce Interactive.

Event Ecommerce Interactive.JPG

12. Click Save.

Enable Enhanced Ecommerce in your Google Universal Analytics account

1. To enable Enhanced Ecommerce in your Google Universal Analytics account, go to Admin → View Settings → Ecommerce settings.

2. Make sure the settings for Enable Ecommerce & Enable Enhanced Ecommerce Reporting are both ON.

Google analytics via GTM_15.png

This information applies to Google Universal Analytics without GTM as well.

Exclude the 2Checkout domains from the referral list

To exclude the 2Checkout domains from the referral list in your Google Universal Analytics account, follow these steps:

 1. Go to Admin → Property settings → Tracking info → Referral Exclusion List.

 2. Add your website’s domain and the following 2Checkout domains: secure.2checkout.com and tracking.avangate.net.

 

Google analytics via GTM_16.png

This information applies to Google Universal Analytics without GTM as well.

Test your Google Universal Analytics Settings

To test if your Google Universal Analytics settings are correct, follow the steps below (make sure your browser is not set to Incognito mode):

 1. Download and install the Tag Assistant Companion browser extension found here.

 2. Click on Preview.

preview GTM.png

3. Delete all existing domains.

delete all domains.png

4. Click on Add domain.

add domain.png

5. Add https://tracking.avangate.net/ and click Start.

click start.png

6. Go back to the Google Tag Manager tab but DON’T close the tab with tracking.avangate.local.

tracking URL.png

7. Click on X in the top-left corner.

connecting to avangate.png

8. In the Tag Assistant Tab, click on Add domain.

add domain tag assisstant tab.png

9. Enter the buy-link you want to debug and click Start.

debug buy-link.png

10. Go back to the Google Tag Manager debugger tab.

debugger.png

11. Click on the Enable button behind the “Connecting this window to avangate.net” pop-up.

enable popup.png

12. Click on Continue.

click continue.png

13. You are now debugging tracking.avangate.net, but this domain receives tags from the shopping cart.

debug success.png

Submit and publish your settings

Google analytics via GTM_20.png

Merchant Control Panel Settings

The Analytics section in your Merchant Control Panel allows you to integrate Google Universal Analytics or/and Google Tag Manager in the ConvertPlus or InLine ordering engines and thus track the behavior of your shoppers on the 2Checkout pages.

Follow these steps to complete your analytics integration:

  1. Log into your Merchant Control Panel.
  2. Navigate to Setup → Ordering options.
  3. Click on the Analytics tab.
  4. Click on the ConvertPlus and InLine Checkout tab.

web analytics in Merchant Control Panel_5.png

 

5. In the Google Tag Manager box, click on Set up.

Select Google Tag Manager with UA

 

6. Fill in the Google Tag Manager code (Here is how you obtain it) and click Save.

GTM with UA insert container ID

7. Complete the integration by using the slider to activate Google Tag Manager. It is not recommended to activate both Universal Analytics and Google Tag Manager to send data to the same Google Universal Analytics view, otherwise, duplicate data will occur.

ConvertPlus & Inline Checkout - Activate Google Tag Manager with UA

1. 2Checkout data layer for tracking through Google Tag Manager is placed in an iFrame. This data layer has an eCommerce object, that contains eCommerce information built on the structure required by Google Universal Analytics reporting for the following events: checkout, add to cart, product impressions (for cross-sells), purchase, and remove from cart.

2. For fully enhanced eCommerce reporting in Google Universal Analytics, it is recommended that you send information to Google Universal Analytics from your website that includes product impression, product detail, and add to cart. More information on enhanced eCommerce reporting and how to send Product View and Add to Cart data to Google Universal Analytics can be found here: https://developers.google.com/tag-manager/enhanced-ecommerce

3. In addition to the eCommerce object, the data layer also contains an event called cartUpdated that includes additional parameters with information on the shopping cart. These parameters can be used to capture further information in custom dimensions. Refer to the Google Documentation on how to build custom dimension through Google Tag Manager: https://support.google.com/tagmanager/answer/6164990?hl=en .

Subscription end user update

Overview

Use the updateSubscriptionEndUser method to update the details of a subscription’s end user. This method changes per-subscription end user data and not customer details.

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.

SubscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

EndUser

Required (Object)

  Use this object to update end user information.

Response

Parameter Type/Description

Boolean

true or false depending on whether the changes were successful or not.

Request


<?php
 
 
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 = "YOUR_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 = "YOUR_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);
$subscriptionReference = '8F749B63E7';
$EndUser = new stdClass ();
$EndUser->Address1 = 'Address line 1';
$EndUser->Address2 = 'Address line 2';
$EndUser->City = 'LA';
$EndUser->Company = 'Company Name';
$EndUser->CountryCode = "US";
$EndUser->Email = 'customerAPI@avangate.com';
$EndUser->FirstName = 'New Customer 2.0';
$EndUser->Language = 'en';
$EndUser->LastName = 'Avangate';
$EndUser->Phone = '1234567890';
$EndUser->State = 'California';
$EndUser->Zip = '90210';
$EndUser->Fax = null;

$jsonRpcRequest = array (
'method' => 'updateSubscriptionEndUser',
'params' => array($sessionID, $subscriptionReference, $EndUser),
'id' => $i++,
'jsonrpc' => '2.0');

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

 

Add product coupon

Overview

Apply discount coupons to products added to the shopping cart.

Requirements

Parameters

Parameter Type/Description
sessionID Required (String)
  Session identifier, which is the output of the Login method. An exception is thrown if the values are incorrect.
coupon Required (String)
  The coupon/voucher code for a promotion impacting a product added to cart.

Response

Parameter Type/Description
Result Boolean
  True or false

Request

<?php

require ('PATH_TO_AUTH');  // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/02Authentication
require ('PATH_TO_SET_PARTNER'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/Partner/00Set_partner
require ('PATH_TO_ADD_PRODUCT'); // addProduct example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/08Place_an_order/00Add_product_to_cart

$couponCode = 'YOUR_COUPON_CODE';

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'setCoupon',
'params' => array($sessionID,$couponCode)
);

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

Errors

Error Description

EMPTY_CART

The shopping cart is empty.

INVALID_COUPON_CODE

The coupon code is empty or invalid.

 

Add reseller information

Overview

Use this method to add information about a reseller in the 2Checkout system.

Requirements

This method requires you to set a specific partner using setPartner.

Parameters

Parameters Type/Description
sessionID Required (string)
  Session identifier, output of the Login method. An exception will be thrown if the values are incorrect.
Reseller Required (object)

Response

Parameters Type/Description
ResellerCode String
  Unique code identifying a specific reseller.

Request

<?php
require ('PATH_TO_AUTH');  // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/02Authentication
require ('PATH_TO_SET_PARTNER'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/Partner/00Set_partner

$reseller = new stdClass();
$reseller->ResellerCode = '1234565';
$reseller->Company = 'Avangate';
$reseller->FirstName = 'John';
$reseller->LastName = 'Doe';
$reseller->Email = 'johndoe@example.com';
$reseller->Phone = '123456789';
$reseller->Fax = '12345';
$reseller->Country = 'US';
$reseller->State = 'CA';
$reseller->City = 'Palo Alto';
$reseller->Address = 'Street';
$reseller->PostaCode = '90210';

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'createReseller',
'params' => array($sessionID, $reseller)
);

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

Errors

Error Description

NOT_FOUND_PARTNER

A partner must be set first.

EMPTY_RESELLER_FIRST_NAME

Reseller first name is mandatory.

EMPTY_RESELLER_LAST_NAME

Reseller last name is mandatory.

EMPTY_RESELLER_COMPANY

Reseller company is mandatory.

INVALID_RESELLER_EMAIL

Reseller email is mandatory.

INVALID_RESELLER_EMAIL

Invalid reseller email provided.

INVALID_COUNTRY

Invalid reseller country code.

INTERNAL_ERROR

Reseller information could not be saved.

 

Use WeChat Pay

Overview

Place an order for catalog products defined in your Control Panel and collect the payment using WeChat Pay.

Requirements

Only Chinese shoppers are able to purchase using WeChat Pay. Make sure the billing country code is set to CN.

Supported currencies

  • USD
  • HKD
  • CNY

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 2Checkout.
  4. Once you place the order, 2Checkout logs it into the system. At this point in time, 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, concatenating the values of the Href and avng8apitoken parameters. Here's an example of the redirect URL:
    https://api.2checkout.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 2Checkout 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. 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.

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

Parameters Type/Description
Order information Object
  Object containing order information.

Request

<?php

require ('PATH_TO_AUTH');

$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'usd';
$Order->Country = 'CN';
$Order->Language = 'en';
$Order->CustomerIP = '91.220.121.21';
$Order->ExternalReference = NULL;
$Order->Source = NULL;
$Order->Affiliate = new stdClass();
$Order->Affiliate->AffiliateCode = 'Partner123'
$Order->Affiliate->AffiliateSource = 'MobilePlatform'
$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->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'Test Cosmin API';
$Order->BillingDetails->LastName = 'Cosmin API';
$Order->BillingDetails->CountryCode = 'CN';
$Order->BillingDetails->State = 'California';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '90210';
$Order->BillingDetails->Email = 'cosmin.deftu@2checkout.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;

$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'WE_CHAT_PAY';
$Order->PaymentDetails->Currency = 'USD';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '91.220.121.21';
$Order->PaymentDetails->PaymentMethod->ReturnURL = 'http://yourreturnurl.com';
$Order->PaymentDetails->PaymentMethod->CancelURL= 'http://yourcancelurl.com';

$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;

try {
   $newOrder = $client->placeOrder($sessionID, $Order);
}
catch (SoapFault $e) {
    echo "newOrder: " . $e->getMessage();
    exit;
}

$wechatredirect = $newOrder->PaymentDetails->PaymentMethod->Authorize->Href."/?avng8apitoken=".$newOrder->PaymentDetails->PaymentMethod->Authorize->Params->avng8apitoken;

header('Location:' . $wechatredirect);

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