Initiating a purchase

You can initiate a purchase in your app by calling the purchase method.

When a user starts a purchase transaction, the blackberry.payment.purchase function is called. When the user finishes interacting with the device to engage the payment process, the app receives a response.

When the blackberry.payment.purchase function is called, only the ID or SKU of the digital good to be purchased is required; you don't need to provide both. If you do provide both, the ID takes precedence.

function purchase() {    
      alert("Trying to call purchase");    
      blackberry.payment.developmentMode = true;    
      try {       
            "digitalGoodID":       "16823864",
            "digitalGoodSKU":      "BB10-CG-02",
            "digitalGoodName":     "SomeName",
            "metaData":            "metadata",
            "purchaseAppName":     "WebWorks APP",
            "purchaseAppIcon":      null,
            "extraParameters":      {
            "key1":                "value1",
            "key2":                "value2"
        }, onPurchaseSuccess,        onPurchaseError);
    } catch (e) {
        alert("Purchase exception");

The Payment Service SDK for BlackBerry WebWorks includes metaData property. You can use this property to provide extra information that remains associated with the purchased good. For example, if a book vendor offers multiple titles at a single price point and represents them on the vendor portal as a single digital good, when a book is purchased, the vendor could set the metaData value as the ISBN for that book. Then, if the user checks past purchases, the metaData property can be used to differentiate between past book purchases.

By default, users see the app name and the icon that you registered with BlackBerry World when they interact with purchase dialog banners. If you want users to see a customized name and icon on the purchase dialog banners when they purchase your app, you can set the purchaseAppName and purchaseAppIcon properties.

Using the purchaseAppName and purchaseAppIcon properties can be a good solution if you offer digital goods with a single name and price point. For example, if you sell additional levels of a game at a single price point, you can use a generic digital good called "My game level" for all such levels. When a user makes a purchase, the game app should override "My game level" with the name of the level that the user purchased (using the purchaseAppName property). This approach makes sure that the user is aware of exactly what they are purchasing on the purchase confirmation screen.

If you use the purchaseAppIcon property, you can supply an icon in any standard format set to ?height=100for a 100 x 100 size.

<script type="text/javascript">
  function purchase() {
      try {
              "purchaseAppName":"WebWorks APP",
              "extraParameters": {
                  "key1": "value1",
                  "key2": "value2"
          onSuccess, onFailure);
      } catch (e) {
          alert ("Error" + e);

Last modified: 2014-10-09

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus