Billing API review
Common API package view:
<?xml version="1.0" encoding="UTF-8"?>
<request>
<version>1.0</version>
<operation_envelope> <!--Package which consists of XML and a signature-->
<operation_xml><!--XML of operation-->
wersadfweorksladfhlkjhFDfsdFSfadfsafdeasfrtty==
</operation_xml>
<signature><!--Signature-->
werewrgsadeww=
</signature>
</operation_envelope>
</request>
Inside of the <operation_xml> tags located XML which specifies the operation needs.
Example (customer add XML):
<request>
<action>customer_add</action>
<operator_id>6543</operator_id>
<customer>
<first_name>Joe</first_name>
<last_name>Shmoe</last_name>
<username>joe</username>
<email>joe.shmoe@gmail.com</email>
<dealer_id>0</dealer_id>
<address>120 Mills Ave</address>
<city>San Francisco</city>
<zip_code>94121</zip_code>
<phone>+11234561234</phone>
<country>USA</country>
<tag>hotel1</tag>
<auth_method>all, device, login</auth_method>
<device1_id>A00332FA34</device1_id>
<status>active</status>
<md5_password>AD432355FD34355FD324A324</md5_password>
</customer>
</request>
Source text of this XML is used for generation of a signature which located in <signature/> tags;
To generate this signature, do the following:
PHP: $sign = base64_encode(sha1($oper_sign.$xml.$oper_sign,1));
Perl: $sign = encode_base64(sha1($oper_sign.$xml.$oper_sign,1));
User Base64 function (base64_encode(PHP) or encode_base64(Perl)) to pack the signed XML.
Perl: $xml_encoded = encode_base64($xml);
PHP: $xml_encoded = base64_encode($xml);
Now we have everything we need to create our API operation:
<?xml version="1.0" encoding="UTF-8"?>
<request>
<version>1.0</version>
<operation_envelope>
<operation_xml>$xml_encoded</operation_xml>
<signature>$signature</signature>
</operation_envelope>
</request>
Created request is to be sent by following URL:
http://tv.broadlink.com.np /api/engine
Response package:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<version>1.0</version>
<operation_envelope>
<operation_xml>awerawerlkhWFEfdasfEWAFfdsafFEDFLksdj==</operation_xml>
<signature>sdfEFDfdsfd=</signature>
</operation_envelope>
</response>
Result checking:
1) Unpack the contents of <operation_xml/> tag
2) Generate a signature
3) Compare the generated signature with the received one (<signature/>)
4) If signatures are equal - process the package, otherwise drop it
Login API
To login a customer in the system you just need to send an HTTP GET request by the following URL:
http://tv.broadlink.com.np/channels/list
Additional HTTP headers must be included:
time = current time in UTC
user = username or email of the customer
hash = md5(time + '*' + md5(password))
You will get an XML with unique temporary url to watch live channels, thumbs, information about servers, VoD,
etc...
Subscription renew types
0 = No auto renew
1 = Renew when finished, if user has enough balance
2 = Renew when finished, even user has not enough balance
3 = Charge every day, until user has enough balance
4 = Charge every day, even user has not enough balance
Request and Response examples:
- Customer Add
Request
<request>
<action>customer_add</action>
<operator_id>6543</operator_id>
<customer>
<first_name>Joe</first_name>
<last_name>Shmoe</last_name>
<username>joe</username>
<email>joe.shmoe@gmail.com</email>
<dealer_id>0</dealer_id>
<address>120 Mills Ave</address>
<city>San Francisco</address>
<country>USA</country>
<zip_code>94121</zip_code>
<phone>+11234561234</phone>
<tag>hotel1</tag>
<auth_method>all, device, login</auth_method>
<device1_id>A00332FA34</device1_id>
<status>active</status>
<md5_password>AD432355FD34355FD324A324</md5_password>
</customer>
</request>
Response
<response>
<!--Original message-->
<action>customer_add</action>
<operator_id>6543</operator_id>
<customer>
<first_name>Joe</first_name>
<last_name>Shmoe</last_name>
<username>joe</username>
<email>joe.shmoe@gmail.com</email>
<dealer_id>0</dealer_id>
<address>120 Mills Ave</address>
<city>San Francisco</address>
<zip_code>94121</zip_code>
<phone>+11234561234</phone>
<country>USA</country>
<tag>hotel1</tag>
<device1_id>A00332FA34</device1_id>
<status>active</status>
<auth_method>all</auth_method>
<md5_password>AD432355FD34355FD324A324</md5_password>
</customer>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
<customer_id>23434</customer_id><!--if successefull-->
</response>
- Customer View
Request
<request>
<action>customer_view</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>customer_view</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
<customer>
<id>23434</id>
<first_name>Joe</first_name>
<last_name>Shmoe</last_name>
<username>joe</username>
<email>joe.shmoe@gmail.com</email>
<address>120 Mills Ave</address>
<city>San Francisco</address>
<zip_code>94121</zip_code>
<country>USA</country>
<phone>+1233123322</phone>
<balance>0</balance>
<device1_id>A00332FA34</device1_id>
<device2_id>B01511CD31</device2_id>
<status>active</status>
<registered_at>2012-03-18 23:14:16</registered_at>
<subscribed_till>2012-05-18</subscribed_till>
<active_packages>
<package>
<id>1</id>
<title>Basic Package - 1 Year</title>
<description>Description of package 1</description>
<logo>http://example.com/images/packages/logo243234.png</logo>
<period_type>month</period_type>
<period_number>12</period_number>
<price>10</price>
<currency>USD</currency>
<tax_rate>0</tax_rate>
<start_time>2015-09-26 13:45:05</start_time>
<expiration_time>2016-09-26 13:45:05</expiration_time>
</package>
</active_packages>
</customer>
</response>
- Customer Edit
Request
<request>
<action>customer_edit</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
<customer>
<first_name>Joe</first_name>
<last_name>Shmoe</last_name>
<username>joe</username>
<email>joe.shmoe@gmail.com</email>
<address>120 Mills Ave</address>
<city>San Francisco</address>
<country>USA</country>
<phone>+1233123322</phone>
<zip_code>94121</zip_code>
<auth_method>all, device, login</auth_method>
<device1_id>A00332FA34</device1_id>
<device2_id>B0233C4324</device2_id>
<status>active</status>
<md5_password>AD432355FD34355FD324A324</md5_password>
</customer>
</request>
Response
<response>
<!--Original message-->
<action>customer_edit</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
<customer>
<first_name>Joe</first_name>
<last_name>Shmoe</last_name>
<username>joe</username>
<email>joe.shmoe@gmail.com</email>
<address>120 Mills Ave</address>
<city>San Francisco</address>
<country>USA</country>
<phone>+1233123322</phone>
<zip_code>94121</zip_code>
<auth_method>all, device, login</auth_method>
<device1_id>A00332FA34</device1_id>
<device2_id>B0233C4324</device2_id>
<status>active</status>
<md5_password>AD432355FD34355FD324A324</md5_password>
</customer>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
</response>
- Customer Delete
Request
<request>
<action>customer_delete</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>customer_delete</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
</response>
- Add a subscription for a customer
Request
<request>
<action>add_subscription</action>
<package_id>9</package_id>
<external_package_id>g92453</external_package_id><!-- External id of package if special identifications used by client system. Optional -->
<start_at>2013-09-01 12:00:00</start_at>
<customer_id>23434</customer_id>
<txn_id>payment_paynow_242FDA322125432</txn_id>
<renew_type>0</renew_type>
<operator_id>6543</operator_id>
<activate_on_login>false</activate_on_login>
</request>
Response
<response>
<!--Original message-->
<action>add_subscription</action>
<package_id>9</package_id>
<start_at>2013-09-01 12:00:00</start_at>
<customer_id>23434</customer_id>
<txn_id>payment_paynow_242FDA322125432</txn_id>
<operator_id>6543</operator_id>
<activate_on_login>false</activate_on_login>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
<commission>18.7425</commission><!--USD, if successefull-->
<subscribed_till>2012-05-18</subscribed_till><!-- if successefull-->
</response>
- Get package list
Request
<request>
<action>package_list</action>
<operator_id>6543</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>package_list</action>
<operator_id>6543</operator_id>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
<packages>
<package>
<id>1</id>
<title>Basic Package - 1 Year</title>
<description>Description of package 1</description>
<logo>http://example.com/images/packages/logo243234.png</logo>
<period_type>month</period_type>
<period_number>12</period_number>
<price>10</price>
<currency>USD</currency>
<tax_rate>0</tax_rate>
</package>
<package>
<id>2</id>
<title>Second Package - 30 days</title>
<description>Description of package 2</description>
<logo>http://example.com/images/packages/logo2323.png</logo>
<period_type>day</period_type>
<period_number>30</period_number>
<price>1</price>
<currency>USD</currency>
<tax_rate>17</tax_rate>
</package>
</packages><!--if successefull-->
</response>
- Change balance of a user
Request
<request>
<action>balance</action>
<amount>100</amount>
<customer_id>23434</customer_id>
<txn_id>payment_paynow_242FDA322125432</txn_id>
<operator_id>6543</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>balance</action>
<amount>100</amount>
<customer_id>23434</customer_id>
<txn_id>payment_paynow_242FDA322125432</txn_id>
<operator_id>6543</operator_id>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
<current_balance>200</current_balance><!-- if successefull-->
</response>
- View Customer's Payment History
Request
<request>
<action>payment_history</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>payment_history</action>
<customer_id>23434</customer_id>
<operator_id>6543</operator_id>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
<payments>
<payment>
<id>434322</id>
<date_time>23423423</date_time>
<txn_id>paypal_421DSSA34</amount>
<amount>24.99</amount>
<currency>USD</currency>
<subscription>
<subscription_id>4232</subscription_id>
<create_time>2015-10-11 12:24:11</create_time>
<start_time>2015-10-11 12:24:11</start_time>
<expiration_time>2016-10-11 12:24:11</expiration_time>
<package_id>3</package_id>
</subscription>
</payment>
<payment>
<id>434364</id>
<date_time>2012-03-18 23:14:16</date_time>
<txn_id>braintree_342432434</amount>
<amount>24.99</amount>
<currency>USD</currency>
<subscription>
<subscription_id>4232</subscription_id>
<create_time>2015-10-11 12:24:11</create_time>
<start_time>2015-10-11 12:24:11</start_time>
<expiration_time>2016-10-11 12:24:11</expiration_time>
<package_id>3</package_id>
</subscription>
</payment>
</payments><!--if successefull-->
</response>
- View Customers List
Request
<request>
<action>customers_list</action>
<operator_id>6543</operator_id>
<filter>Add filter here. It will search by Firstname/Lastname/Email/Username/Phone/ID. Leave empty to get all customers.</filter>
</request>
Response
<response>
<!--Original message-->
<action>customers_list</action>
<operator_id>6543</operator_id>
<!--Server Response-->
<status>
success <!--Operation status: failure - error, success - success -->
</status>
<error></error><!--description of the error-->
<customers>
<customer>
<id>434322</id>
<first_name>Joe</first_name>
<last_name>Shmoe</last_name>
<email>joe.shmoe@gmail.com</email>
<status>active</status>
<subscribed_till>2012-05-18</subscribed_till>
</customer>
<!-- Could be many customers -->
</customers><!--if successefull-->
</response>
- Add unique subscription to a plan. Used for external billings which need to open permanent access to selected plan. This method checks if subscription already exists.
Request
<request>
<action>add_unique_subscription</action>
<customer_id>7597</customer_id>
<plan_id>409</plan_id>
<operator_id>7595</operator_id>
<renew_type>0</renew_type>
<expired_at>06/01/2018</expired_at>
</request>
Response
<response>
<!--Original message-->
<action>add_unique_subscription</action><customer_id>7597</customer_id><plan_id>409</plan_id><operator_id>6543</operator_id><activate_on_login>false</activate_on_login><expired_at>06/01/2018</expired_at>
<!--Server message-->
<status>success</status>
<error></error>
<subscribed_till>2018-06-01 00:00:00</subscribed_till>
<subscription_id>830108303</subscription_id>
<activated>1</activated>
</response>
- Update unique subscription expiration date.
Request
<request>
<action>update_unique_subscription</action>
<customer_id>7597</customer_id>
<plan_id>111</plan_id>
<operator_id>7595</operator_id>
<expired_at>06/01/2018</expired_at>
</request>
Response
<response>
<!--Original message-->
<action>update_unique_subscription</action>
<customer_id>7597</customer_id>
<plan_id>111</plan_id>
<operator_id>7595</operator_id>
<expired_at>06/01/2018</expired_at>
<!--Server message-->
<status>success</status>
<error/>
<error_info/>
<subscription_id>77777</subscription_id>
<subscribed_till>2018-06-01 00:00:00</subscribed_till>
</response>
- Stop subscription by plan. Used for external billings which need to close access to selected plan. If customer has few subscriptions to selected plan - latest will be deleted.
Request
<request>
<action>stop_subscription</action>
<customer_id>7597</customer_id>
<plan_id>409</plan_id>
<operator_id>6543</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>stop_subscription</action><customer_id>7597</customer_id><plan_id>409</plan_id><operator_id>7595</operator_id>
<!--Server message-->
<status>success</status>
<error></error>
<response>subscription_deleted</response>
</response>
- Stop subscription renew by plan. Use it to cancel subscription renew when customer has not enough funds in your system, etc.
Request
<request>
<action>stop_renew</action>
<customer_id>7597</customer_id>
<plan_id>409</plan_id>
<operator_id>7595</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>stop_renew</action><customer_id>7597</customer_id><plan_id>409</plan_id><operator_id>7595</operator_id>
<!--Server message-->
<status>success</status>
<error></error>
<error_info></error_info>
<response>subscription_stopped</response>
</response>
- Start subscription renew by plan. Use it to continue subscription renew when customer has added funds to balance, etc.
Request
<request>
<action>start_renew</action>
<customer_id>7597</customer_id>
<plan_id>409</plan_id>
<operator_id>7595</operator_id>
</request>
Response
<response>
<!--Original message-->
<action>start_renew</action> <customer_id>7597</customer_id> <plan_id>409</plan_id> <operator_id>7595</operator_id>
<!--Server message-->
<status>success</status>
<error></error>
<error_info></error_info>
<response>subscription_started_again</response>
</response>
- PHP example (add subscription)
<?php
$operator_signature = "sfasdfasdf234f234234234fd23434";
$operator_id = 324543;
$str = "<request>
<action>add_subscription</action>
<customer_id>23434</customer_id>
<operator_id>$operator_id</operator_id>
<txn_id>payment_paynow_242FDA322125432</txn_id>
</request>";
$operation_xml = base64_encode($str);
$signature = base64_encode(sha1($operator_signature.$str.$operator_signature, 1));
$operation_envelop = "<operation_envelope>
<operation_xml>".$operation_xml."</operation_xml>
<signature>".$signature."</signature>
</operation_envelope>";
$post = "api=".urlencode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<version>1.0</version>
<request>
".$operation_envelop."
</request>");
$url = "http://tv.broadlink.com.np/api/engine";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>