Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
scrid2000
Posts: 142
Registered: ‎07-27-2011
My Device: Red Z10, 32GB PlayBook, Numerous Android/WP8/FirefoxOS/Other devices
Accepted Solution

WebWorks Payment API question; persistence/identification of purchase.

[ Edited ]

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-WebWorks-Development/Sample-App-BlackBerry-WebWorks-P... and https://developer.blackberry.com/html5/apis/blackberry.payment.html and couldn't find an answer from either of those.

Thanks in advance to anyone who can help.

-----------------------------------------------------------------------------------------



Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: WebWorks Payment API question; persistence/identification of purchase.

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.

If it helped you, click like. :smileyhappy:
Developer
scrid2000
Posts: 142
Registered: ‎07-27-2011
My Device: Red Z10, 32GB PlayBook, Numerous Android/WP8/FirefoxOS/Other devices

Re: WebWorks Payment API question; persistence/identification of purchase.

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.

-----------------------------------------------------------------------------------------



Developer
scrid2000
Posts: 142
Registered: ‎07-27-2011
My Device: Red Z10, 32GB PlayBook, Numerous Android/WP8/FirefoxOS/Other devices

Re: WebWorks Payment API question; persistence/identification of purchase.

Bit late, but I can confirm that the above code works.

-----------------------------------------------------------------------------------------