2

I am experimenting with DrupalGap and it's great what it already provides out of the box. One feature that module is missing is in-app-purchasing (where payments go via Apple).

Cordova provides a great cross-platform plugin with some good documentation.

This is a full example, and this a minimal example.

document.addEventListener('deviceready', initializeStore, false);

function initializeStore() {

// Let's set a pretty high verbosity level, so that we see a lot of stuff
// in the console (reassuring us that something is happening).
store.verbosity = store.INFO;

// We register a dummy product. It's ok, it shouldn't
// prevent the store "ready" event from firing.
store.register({
    id:    "com.example.app.inappid1",
    alias: "100 coins",
    type:  store.CONSUMABLE
});

// When every goes as expected, it's time to celebrate!
// The "ready" event should be welcomed with music and fireworks,
// go ask your boss about it! (just in case)
store.ready(function() {
    console.log("\\o/ STORE READY \\o/");
});

// After we've done our setup, we tell the store to do
// it's first refresh. Nothing will happen if we do not call store.refresh()
store.refresh();
} 

How can I add the document.Eventlistener and the initalization function within DrupalGap?

The cordova plugin is installed, the products are set up in iTunes and the provisioning profiles with in-app-purchasing feature are created. I have created a custom module with a menu link in DrupalGap where the user can make his in-app-purchases.

UPDATE:

This code works (Thanks, Tyler) and connects to the iTunesConnect store and pulls the requested/registered products.

You don't need a sandbox user to pull the products.

You do need to submit Apple the 3 legal documents even if you only use a development provisioning profile. It takes a few hours until the docs are submitted.

Here is another useful link (when your product is invalid): http://troybrant.net/blog/2010/01/invalid-product-ids/

/**
 * Implements hook_deviceready().
 */
function my_module_deviceready() {
// Let's set a pretty high verbosity level, so that we see a lot of stuff in the console (reassuring us that something is happening).
//store.verbosity = store.INFO;
store.verbosity = store.DEBUG; // even higher

// We register/request a product:
store.register({
id: "130points", // this is id of your product in iTunesConnect
alias: "130points_alias",
type: store.CONSUMABLE
});
// When every goes as expected, it's time to celebrate!
// The "ready" event should be welcomed with music and fireworks,
// go ask your boss about it! (just in case)
store.ready(function() {
console.log("\\o/ STORE READY \\o/");
});
// When any product gets updated, refresh the HTML.
store.when("product").updated(function (product_item) {
console.log("product_item: " + JSON.stringify(product_item)); // this is the response from iTunesConnect
});
// After we've done our setup, we tell the store to do it's first refresh. Nothing will happen if we do not call 
store.refresh();
return true; // Let DrupalGap know it is OK to continue.
}
1

In a DrupalGap Custom Module, you'll use hook_deviceready():

/**
 * Implements hook_deviceready().
 */
function my_module_deviceready() {
  // Place your initializeStore function's code here...

  return true; // Let DrupalGap know it is OK to continue.
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.