Getting the necessary info for creating a recurring payments profile.
support, ws.webtv, api, store, get, recirring, payment, info
GET vars specific to this request:
Var | Value | Description |
go | store | The API section |
do | get_subscription_pre_rp_info | 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_subscription_pre_rp_info&iq={user_id}&{required information}
One of the following POST vars is required.
Var | Value | Description |
productID | (int) Product ID | [Only if subscriptionID is not provided] This is the data you will provide before processing an order. |
subscriptionID | (int) Subscription ID | [Only if productID is not provided] |
If the request was successful, you'll receive a response containing:
• data: (array) The data will include:
- id_subscription: (int) ID of the subscription (in case there is already a subscription created).
- subscription_number: (string) The number of the subscription (in case there is already a subscription created).
- amount: (decimal) The amount to be billed on each renewal.
- currency_code: (string) The currency code.
- date_first_payment: (int) Unix timestamp, the date when the User must be automatically billed for the first time.
- date_first_payment_with_trial: (int) [Since WS.WebTV 3.0.2] Unix timestamp. If this is a subscription with free trial, the value will be different than -1 and will correspond to the date when the User must be automatically billed for the first time.
- id_product: (int) ID of the associated product.
- product_sku: (string) SKU of the associated product.
- period: (int) The time unit of the billing period (DAY, WEEK, MONTH or YEAR).
- period_frequency: (int) The amount/frequency of the billing period.
Example:
{ "data": { "amount": "10.00", "currency_code": "EUR", "date_first_payment": 1509174392, "id_product": "6", "id_subscription": -1, "period": "MONTH", "period_frequency": "1", "product_sku": "CHNACCSUB_3", "subscription_number": "" } }
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:
The User ID was not specified or it is invalid/lower than 1.
• REQUEST_ERROR | Invalid Product/Subscription ID:
The productID and/or subscriptionID were not specified or they are invalid/lower than 1.
• ERROR_NO_SUBSCRIPTION | The User does not have any subscription associated with the provided subscription ID:
You provided an invalid subscription ID.
• ERROR_SUBSCRIPTION_NOT_RENEWABLE | This subscription is not renewable. It must be reactivated first:
There is already a subscription but it is not renewable.
• ERROR_ACTIVE_RP_PROFILE | The subscription already has an active recurring payments profile:
There is already a recurring payment profile associated with the subscription.
• ERROR_NO_PRODUCT | The associated product does not exist:
Maybe you provided an invalid product ID or the product is not available anymore.
Preparing GET and POST data.
// The GET vars $GET_VARS = array( "go" => "store", "do" => "get_subscription_pre_rp_info", "iq" => "2" ); // The POST vars (two cases) // 1. If providing the product ID $POST_VARS = array( "productID" => 6 ); // 2. If providing the subscription ID $POST_VARS = array( "subscriptionID" => 19 );
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 the salt, timestamp and validation signature $salt = md5(mt_rand()); $timestamp = time(); $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // 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)); }