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
Contributor
Posts: 23
Registered: ‎03-07-2013
My Device: Blackberry Z10
My Carrier: Vodafone
Accepted Solution

Payment Integration help

Sir
I am trying to add in-app payment in my Blackberry 10 webworks app. 
My code for "checking if paid" and "paying" is:-

// checking if paid

 function checkpurchase() {
       try {
          blackberry.payment.checkExisting({
              "id": "33683893"
          }, onSuccess, onFailure);
      } catch (e) {
          alert ("Error" + e);
  purchase();
      }
 }
 
 function onSuccess(data) {
      if(data.subscriptionExists)
        {
         bb.pushScreen('pcancel.htm', 'PCancel');
}
      else
    {
 
    alert("It's the paid Feature you need pay for it from menu");
purchase();
}
 }
 
 function onFailure(error) {
     alert("Error occurred: " + error.errorText + ", " + error.errorID);
 }

//payment
function purchasex() {
    console.log('purchasing');
 
    try {
        blackberry.payment.purchase({
            "digitalGoodID": "33683893",
            "digitalGoodSKU": "UAFRA1",
            "digitalGoodName": "Unlock All Features and Remove Ads",
            "metaData": "Unlock All Features and Remove Ads",
            "purchaseAppName": "WebWorks APP",
            "purchaseAppIcon": null,
            "extraParameters": {
                "key1": "value1",
                "key2": "value2"
            }
        },
        onSuccessa, onFailurea);
    } catch (e) {
        alert("Error" + e);
    }
}
 
 function onSuccessa(purchasedItem) {
      var transId = purchasedItem.transactionID;
      var sku = purchasedItem.digitalGoodSKU;
      var dgId = purchasedItem.digitalGoodID;
      alert("Purchased Item: " + transId + "," + sku +  "," + dgId);
  }
 
  function onFailurea(error) {
      alert("Error occurred: " + error.errorText + ", " + error.errorID);
  }

The Error I am getting in both cases are:-
While executing purchasex() function :-
ErrorTypeError:'undefined' is not an object (evaluating 'blackberry.payment.purchase')

While executing checkpurchase() function :-
ErrorTypeError:'undefined' is not an object (evaluating 'blackberry.payment.checkExisting')

I have added 
  <feature id="blackberry.payment" required="true" version="1.0.0.0" /> in config file but still I am getting this Error Please help me in resolving it 

With Regards 
Pulkit
BlackBerry Development Advisor
Posts: 762
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Payment Integration help

Hello,

 

If you use Web Inspector to debug, and type "blackberry" into the console, do you see an Object?

 

Are you including the webworks.js file in your index.html?

 

   <!-- webworks -->
    <script src="local:///chrome/webworks.js" type="text/javascript"></script>

 

 

Contributor
Posts: 23
Registered: ‎03-07-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Payment Integration help

Yup I have included that in index.htm
Highlighted
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Payment Integration help

By chance are you testing with Ripple? The Payment APIs are only supported on physical devices / the simulator. Also, can you please confirm that you are waiting for webworksready to fire and only after that event are you making the call?

Just as a side note, generally the recommended approach would be to retrieve all purchases at startup / once and store them into Local Storage. This way you don't need to make an external connection to validate, and anytime a purchase is make you can simply update your Local Storage.

With that in mind, if you have a basic, Hello World sample (config.xml and index.html) that shows your implementation, we can test it out here.

When sharing code, there is also a code insertion button you can click which will format it as in Chad's post; it keeps it just a little easier to read.

Cheers!

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Contributor
Posts: 23
Registered: ‎03-07-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Payment Integration help

Sir
You asked me to share my payment code demo I have sent you an Email with my code zip attached Please check it out once


and one more thing sir I have also tried to add "Invite to download feature of BBM" but that is also not working I have added it in the same code please check that out
you may also download the zip here https://docs.google.com/file/d/0B5gSPy2LyTguNHhmRFRxdzlWTm8/edit?usp=sharing

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Payment Integration help

[ Edited ]

Thanks, files received. I will give these a look over the weekend and will do my best to narrow down / provide my feedback as soon as I can. Cheers!

 

EDIT: Just to double-check, are you using Ripple for testing? If you are using a Simulator of Physical Device, can you please confirm the full OS version that you are testing on?


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
Posts: 1,230
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Payment Integration help

Just about to start that

 

Looks OK and easy-ish (but things always go wrong)

 

PM me as I loo into it if you want help - I'll be going thru the same stuff as you




Click the like button if you find my posts useful!
Contributor
Posts: 23
Registered: ‎03-07-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Payment Integration help

Hey friend Have you tested the code Please help me to correct as I wish to launch next update of my app as soon as i succesfully manage to add in-app payments 

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Payment Integration help

Hi there, I haven't been able to narrow down the cause yet.

From before...are you using Ripple for testing? If you are using a Simulator of Physical Device, can you please confirm the full OS version that you are testing on?

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Payment Integration help

For future visitors, the issue was a result of an older WebWorks SDK version that did not include the Payment APIs. Updating to the latest SDK resolved the issue.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.