Getting the product list from shopping cart or from current order.
support, ws.webtv, api, store, cart, order
GET vars specific to this request:
Var | Value | Description |
go | store | The API section |
do | get_cart | The API action |
iq | User ID | The User ID |
Resulting Request URL:
The resulting request URL would be similar to this (don't forget to append the required info: key, timestamp, salt and signature):
https://....../api.php?go=store&do=get_cart&iq={user_id}&{required information}
None. No POST vars are required for this request.
If the request was successful, you'll receive a response containing:
• data: An array with the cart or current order data. It will inlude:
- order_contains_subscription: (int) 0|1 Whether the cart/order contains a subscription product.
- order_contains_subscription_trial: (int) 0|1 [Since WS.WebTV 3.0.2] Whether the cart/order contains a subscription product with free trial.
...
Trials:
- order_trial_requires_rp: (int) 0|1 [Since WS.WebTV 3.0.2] Only applies if previous data is 1. Whether the trial requires recurring payments - If this is the case, and the external payment processor does not support recurring payments, then you must remove the product from the cart; otherwise, you must create the recurring payment profile after processing the order.
- order_has_credit_product: (int) 0|1 Whether the cart/order contains a credit product (if it has, then credit won't be used for paying).
...
- order_id: (int) In case this is a current order, this is the Order ID.
- order_min_purchase_check: (int) 0|1 Whether the cart meets the minimum purchase requirement.
- order_num_products: (int) Amount/number of products in the cart/order.
- buyer_credit: (decimal) The available User credit.
- buyer_credit_formatted:(string) The previous value, formatted.
- order_amount_due: (decimal) In case this is a current order, this is the amount that has to be paid.
- order_amount_paid: (decimal) In case this is a current order, this is the amount paid so far by the User.
- order_credit_used: (decimal) The credit that can be used to partially (or fullty) paid the products on cart/order.
- order_credit_used_formatted:(string) The previous value, formatted.
- order_subtotal: (decimal) The total of the cart/order, before applying credits.
- order_subtotal_formatted:(string) The previous value, formatted.
NOTE: "order_amount_paid" + "order_amount_due" + "order_credit_used" = "order_subtotal"
- order_total: (decimal) The total of the cart/order
- order_total_formatted:(string) The previous value, formatted.
- product_list: (array) The list of products from the cart or current order. Each product on the list will inlude:
- id: (int) The product ID. This is the ID that you will use for removing the product from the cart.
- id_clip: (int) In case this is a Clip product, this will be Clip ID (number > 0).
- id_channel: (int) In case this is a Channel product, this will be Channel ID (number > 0).
- id_type: (int) ID of the product type.
- type_name: (string) the name of the product type (CREDIT, ENDDATE, PERIOD, SUBSCRIPTION, SUBSCRIPTIONRENEWAL, DONATION, SERVICE, MEMBERSHIPPERIODAUTHORING, MEMBERSHIPPERIODCONTRIBUTING)
- ctype: (int) Content type of the product (-1:Other, 0:Site, 1:Channel, 2:Clip, 3:Membersip).
- sku: (string) SKU of the product.
- price: (decimal) The unit price of the product.
- price_formatted: (string) The previous value, formatted.
- price_after_trial: (decimal) [Since WS.WebTV 3.0.2] Applicable to product with "type_name" equal to "SUBSCRIPTIONTRIAL", the unit price of the product, after the free trial period.
- price_after_trial_formatted: (decimal) [Since WS.WebTV 3.0.2] Applicable to product with "type_name" equal to "SUBSCRIPTIONTRIAL", the previous value, formatted..
- quantity: (int) ...
- price_by_qty: (decimal) The multiplication of "price" by "quantity".
- price_by_qty_formatted: (string) The previous value, formatted.
- title: (string) The product title.
- description: (string) The product description.
- img_thumbnail, img_social, img_poster: (string) The product image, in several sizes.
- period_unit: (string) In case of a product with "type_name" equal to "PERIOD", then this is the time unit (DAY, WEEK, MONTH or YEAR).
- period_amount: (int) In case of a product with "type_name" equal to "PERIOD", then this is the amount of the period.
- subs_period_unit: (string) In case of a product with "type_name" equal to "SUBSCRIPTION", "SUBSCRIPTIONTRIAL" or "SUBSCRIPTIONRENEWAL", then this is the time unit for the billing (DAY, WEEK, MONTH or YEAR).
- subs_period_amount: (int) In case of a product with "type_name" equal to "SUBSCRIPTION", "SUBSCRIPTIONTRIAL" or "SUBSCRIPTIONRENEWAL", then this is the frequency of the billing period.
...
Trials:
- trial_period_unit: (string) [Since WS.WebTV 3.0.2] Applicable to product with "type_name" equal to "SUBSCRIPTIONTRIAL", then this is the time unit for the free trial (DAY, WEEK, MONTH or YEAR).
- trial_period_amount: (int) [Since WS.WebTV 3.0.2] Applicable to product with "type_name" equal to "SUBSCRIPTIONTRIAL", then this is the amount of units for the free trial period.
- trial_requires_rp: (int) [Since WS.WebTV 3.0.2] Applicable to product with "type_name" equal to "SUBSCRIPTIONTRIAL", whether it is required recurring payments for enabling the free trial period.
Example:
{ "data": { "buyer_credit": "1.00", "buyer_credit_formatted": "1.00\u20ac", "order_amount_due": 9.5, "order_amount_paid": 0, "order_contains_subscription": 0, "order_contains_subscription_trial": 0, "order_trial_requires_rp": 0, "order_credit_used": 0, "order_credit_used_formatted": "0.00\u20ac", "order_has_credit_product": 1, "order_id": -1, "order_min_purchase_check": 1, "order_num_products": 2, "order_subtotal": 9.5, "order_subtotal_formatted": "9.50\u20ac", "order_total": 9.5, "order_total_formatted": "9.50\u20ac", "product_list": [{ "id": "1", "id_clip": null, "id_channel": null, "id_type": "1", "ctype": "0", "sku": "CREDIT", "price": "1.00", "price_formatted": "1.00\u20ac", "quantity": "5", "price_by_qty": 5, "price_by_qty_formatted": "5.00\u20ac", "title": "Credit Recharge", "description": "Add credit to your account and use it any time to purchase WebTV content access.
Purchasing with your credit balance is very fast and easy. If you have enough credit to purchase an item you will be able to use the Quick Purchase option that does not require going through the check out process. <br>NOTE: Credits can not be used to pay subscription renewals when recurring payments (automatic payments) are active for a subscription.", "img_thumbnail": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_thumb.jpg", "img_social": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_social.jpg", "img_poster": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_poster.jpg", "type_name": "CREDIT", "period_unit": "", "period_amount": 0, "subs_period_unit": "", "subs_period_amount": 0 }, { "id": "8", "id_clip": "1", "id_channel": null, "id_type": "3", "ctype": "2", "sku": "CLIPACCPER_1", "price": "4.50", "price_formatted": "4.50\u20ac", "quantity": 1, "price_by_qty": 4.5, "price_by_qty_formatted": "4.50\u20ac", "title": "Premium Clip - Clip Access Pass (during 1 week)", "description": "Access pass to watch this Clip during 1 week", "img_thumbnail": "http:\/\/www.mywebtvdomain.com\/uploads\/images\/clip_1_1467909401_thumb.jpg", "img_social": "http:\/\/www.mywebtvdomain.com\/uploads\/images\/clip_1_1467909401_social.jpg", "img_poster": "http:\/\/www.mywebtvdomain.com\/uploads\/images\/clip_1_1467909401_poster.jpg", "type_name": "PERIOD", "period_unit": "WEEK", "period_amount": "1", "subs_period_unit": "", "subs_period_amount": 0 }] } }
If the request failed (for example, if no signature was provided in the request), you'll receive a response like the following:
{ "error" : "REQUEST_ERROR", "error_long" : "Missing signature" }
Possible Error Messages
Besides the general errors, this request can return the following errors:
• REQUEST_ERROR | Invalid User ID:
User ID is not numeric or lower than 1.
Preparing GET and POST data.
// The GET vars $GET_VARS = array( "go" => "store", "do" => "get_cart", "iq" => "2" ); // The POST vars $POST_VARS = array();
Generating the salt, timestamp, signature and sending the request
*** The following code block is common to all signed requests ***
// Collect the API Base URL and Credential info $API_URL = "https://www.mywebtvdomain.tv/api.php"; $API_KEY_ID = "1b323a1cb879fd4e66530fbad07a32ee"; $API_SHARED_SECRET = "MWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWViOTQ3MDJiOGM2ZTU2NjE3"; // keep this safe!!! // Generating salt and timestamp $salt = md5(mt_rand()); $timestamp = time(); $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // Generating the validation signature // - Default method: using base64_encode(hash_hmac(...)) $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // comment this line if using the next method // - Simplified method - available since v60: using md5(). // This method requires the variable $API_SIGNATURE_GENERATION_MODE = 1; in the config/Config.inc.php file. // $signature = md5($salt."-".$timestamp."-".$API_SHARED_SECRET); // you must "uncomment" this line when using the simplified method // Append the timestamp, salt, key and signature to the GET vars $GET_VARS["timestamp"] = $timestamp; // UTC timestamp $GET_VARS["salt"] = $salt; $GET_VARS["key"] = $API_KEY_ID ; // The API Key ID: This is public and is used by the API to identify the application; $GET_VARS["signature"] = $signature; // Create the request URL. Please note that if you do not use PHP buit in function // to create the HTTP query then don't forget to URL encode the values $REQUEST_URL = $API_URL."?".http_build_query($GET_VARS); // The previous will build an URL like .../api.php?go=api_subject&do=api_action&etc... // Create a new cURL resource and set the appropriate options $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $REQUEST_URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $POST_VARS); // If your PHP host does not have a valid SSL certificate, you will need to turn off SSL // Certificate Verification. This is dangerous (!), and should only be done temporarily // until a valid certificate has been installed curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate. // Sending the request to the API $response = curl_exec($ch); // Processing the response if (!$response) { echo 'API call failed'; } else { print_r(json_decode($response,true)); }