Developer / Documentation / Netlog OpenSocial Credits Extension
Monetizing your OpenSocial app can be done through various ways. Apart form the ways mentioned in our application guidelines, we're also offering an OpenSocial Extension, which gives developers access to the "Credits Economy" on Netlog.
The Netlog user base is used to spending credits for certain features. Members can deserve - through frequent usage or inviting friends - and/or buy - through micro-payments (sms / ivr / credit card) - credits, which they can spend on putting their items in the Spotlight or more premium features.
While we expect most applications to be free, we offer the opportunity to monetize your application by charging credits. Operating similar to the iPhone App Store, you could be charging for application installs, but even more useful use cases would be to charge for certain premium features or for buying items.
How to implement?
In order to request credits from our users, you need to require access to our credits API. For this matter, you will need to provide us with an URL to your payment callback page (see confirming the payment).
Once you've got access, you will receive a Credits Key.
Both your payment callback page and the Credits Key are required for using the credits API.
1. Request credits from the user
Netlog provides its own extentions to the opensocial standards. To use these set of extra functions, you have to require the feature payment.
<Require feature="payment"/>
To request credits from the viewer, first, you need to create an instance of the Payment class. See the constructor documentation.
Next, you have to request the payment using the function Payment.requestPayment().
<input type="button" id="credits" value="Send" onclick="upgrade()"/>
<div id="result"></div>
<script>
function upgrade()
{
var payment = new Payment(20, 'Sending a christmas tree will cost you 20 credits');
var opt_params = {};
Payment.requestPayment(payment, handlePayment, opt_params};
}
function handlePayment(response)
{
//handle returned responseitem (see step 3)
}
</script>
When requesting a certain amount of credits, the user will be prompted with a dialog where he can verify the payment.
Screenshot
2. Confirm the payment on your server
When the user accepts or denies the payment, the payment information is sent to your payment callback page (the URL which you need to give us) through a signed makeRequest call.
This way, you can verify the payment on your backend securely.
The data is sent using HTTP POST and contains following fields:
- userid
- the userid of the user who accepted or denied the payment
- amount
- amount of credits for this payment
- action
- whether the user has accepted or denied the payment. Possible values are ACCEPTED and DENIED
- token
- unique token for this payment
When processed, your payment callback page should return a HTTP 200 OK status code with the following body: md5(concat(token, creditsKey));
The payment will only be done when your server sends back this answer correctly. Otherwise the payment will not occur and result in an error.
<?php //Verify the signed request first $creditsKey = 'some_key'; echo md5($_POST['token'] . $creditsKey); ?>
3. Handle the payment on the client side
Once your server has responded in a correct way, an error occured, or when the user cancelled the request, your callback function will be called.
This function should accept one parameter, which is an opensocial.ResponseItem.
If no errors occured, the data in this ResponseItem is a Payment.
function handlePayment(response)
{
if (data.hadError())
{
document.getElementById('result').innerHTML = 'Error: ' + response.getErrorMessage();
}
else
{
var state = data.getField('state');
if (state == Payment.State.ACCEPTED)
{
document.getElementById('result').innerHTML = 'Credits received';
}
elseif (state == Payment.State.DENIED)
{
document.getElementById('result').innerHTML = 'Credits not received';
}
elseif (state == Payment.State.CANCELLED)
{
document.getElementById('result').innerHTML = 'Cancelled by user';
}
}
}
Articles
- Introduction
- Application Guidelines
- OpenSocial
- Netlog REST API (depricated)
- Flash Applications (depricated)
- PHP Applications (depricated)
- Syndication (feeds)
- Widgets: Link, blog or shout
- Bookmarklets: link, blog or shout
- Terms & Conditions