JavaScript API
Integration of JavaScript API into the page
To take advantage of JavaScript API portal 101XP.com, you need to integrate API into the page of your game and make an initialization.
<script type="text/javascript" src="//101xp.com/js/api.js"></script>
<script type="text/javascript">
XP.init(
function(){
// Code after successful API initialization
}
);
</script>
If the initialization of JavaScript API will end successfully then you'll see message «*** Welcome to 101XP Portal! ***» in JavaScript Console of a browser
if you are using jQuery version 1.7.1 above in your application, it is necessary to place it higher than API integration in header of the page, otherwise jQuery 1.7.1 version will be connected after initialization of API.
if there are no errors in the initialization process, but message «*** Welcome to 101XP Portal! ***» didn't appeared, check the links are whether correctly specified in iFrame (including the script that processes the requests).
redirect
The method allows you to redirect inside the frame, while maintaining the link easyxdm.
var url = url; // Loacation
XP.callMethod('redirect', url);
It is important that there was no link parameters xdm_*
resizeWindow
The method produces a change of the size of iFrame. Now available only to change height.
var width = 1024; // Width of iFrame
var height = 768; // Height of iFrame
XP.callMethod('resizeWindow', width, height);
showOrderBox
The method sends a request to the portal 101XP.com for placing the order. In the case of a successful payment, dialog box appears to the user with the data of payment.
var name = 'Transaction name'; // Title (show indialog box with successful payment information)
var descr = 'Description'; // Decription (currently not show)
var item_id = 4; // Game item that user want buy
var price = 20; // The cost of purchased item in rubles
XP.callMethod('showOrderBox', name, descr, item_id, price);
Also in this method, there are several handlers are described below.
XP.addCallback('onOrderSuccess', function(order_id){
alert('onOrderSuccess');
});
// The event is triggered if the payment failed
XP.addCallback('onOrderFailure', function(){
alert('onOrderFailure');
});
// The event is triggered if the user canceled the payment
XP.addCallback('onOrderCancel', function(){
alert('onOrderCancel');
});