11-01-2012 05:11 PM - edited 11-01-2012 06:30 PM
I have a question for anyone who's familliar with the WebWorks Payment API.
In an app I've got pretty much done, I plan to have some nonconsumable purchasable content.
I've got everything set up so that if you complete a purchase, a localStorage value is created. The function to launch the purchased content checks if the localStorage value exists, and if it does the user is directed to the premium content section. Here's the code if it helps:
function getPremium() {
try{
blackberry.payment.purchase({
"digitalGoodID":"myGoodID",
"digitalGoodSKU":"myGoodSKU",
"digitalGoodName":"Digital Good",
"metaData":"metadata",
"purchaseAppName":"App Name",
"purchaseAppIcon":null},
success,failure);
}catch (e){
alert ("Error" + e);
}
}
function success(purchase) {
localStorage.setItem('premiumpurchased','yes');
}
function failure(errorText, errorId) {
alert("Error occured: " + errorText + ", " + errorId);
}
//Function called to check if premium content was purchased
function checkPremium() {
if (localStorage.getItem('premiumpurchased') == 'yes') {
bb.pushScreen('premium/index.html','premium');}
else {getPremium();}
}
Now, if the user of the app purchases content and then deletes the app, the localStorage will be deleted.
If they attempt to make the purchase again, my understanding is that they will be denied (because it is nonconsumable), which is what I want to happen (that is, I don't want people to be charged twice).
But in that scenario, how would the app recreate the localStorage value so that the premium content can be accessed? Or is there another, better way other than creating a localStorage value to do this?
I've read http://supportforums.blackberry.com/t5/Web-and-Web
Thanks in advance to anyone who can help.
Solved! Go to Solution.
11-02-2012 01:09 AM
I think its as you said, localstorage IS after all local storage... In such cases I would investigate the option of local storage AND an online license backup. Like a web service or website to store the users and their purchases. Although that gets more complicated because how would you identify users? BB pin? logins? facebook id's?
Check out also some of the payment API's there is one that stores purchases, but I may be wrong. <- not my area of expertise. You could also post in the app world and payments forum.
11-02-2012 03:46 PM
Ok, so upon looking at the sample code again, it looks like all I have to do is call
blackberry.payment.getExistingPurchases(true, checkPremium, onFailure);
And have this in my .js file:
function checkPremium(data)
{
for (i = 0; i < data.length; i++)
{
if (data[i].digitalGoodID = "myGoodID") {
localStorage.setItem('premiumpurchases','yes');
break;
}
}
}
Can anyone confirm that that's all I need? I'm a bit leery of submitting this to app world without knowing that it will work, but I can't test it without submitting.
Wednesday
Bit late, but I can confirm that the above code works.