Jump to content

How to get working In-App Purchases (IAP) using Cordova on iOS?


Doyban
 Share

Recommended Posts

After successful delivery In-App Purchases (IAPs) on Android using Apache Cordova and https://github.com/j3k0/cordova-plugin-purchase I can't get it working properly on iOS. The problem is that once the item is clicked the price shows its details etc., but if use clicks "Cancel" then the user can't purchase anything anymore. Unless restarting the game, as far as I'm aware I should handle rejection/cancellation events. Tried these, but so far no success.

This is how I was trying to handle these events (rejection/cancellation), including playing with store.refresh() in different locations of the code and without it as well:

// Handle rejection and cancel events.
store.when("com.XX.YY.gems5").rejected(function(order) {
  store.refresh();
  that.game.state.start("GemsState");
  store.refresh();
});
store.when("com.XX.YY.gems5").cancelled(function(order) {
  store.refresh();
  that.game.state.start("GemsState");
  store.refresh();
});

Code, which correctly works on Android (the handling wasn't required there in order to work properly):

'use strict';
var that = this;
    
// Prepare product.
store.register({
  id:    "com.XX.YY.gems5",
  alias: "Gems 5",
  type:  store.CONSUMABLE
 });
    
// Purchase product.
store.order("com.XX.YY.gems5");
store.refresh();
store.when("com.XX.YY.gems5").approved(function (order) {
  order.finish();
  store.refresh();
      
  // Add extra gems.
  localStorage.gems = parseInt(localStorage.gems) + 5; // Add 5 gems.
  that.upgrade_sound.play(); // Play upgrade sound.
  that.game.state.start("GemsState");
  that.menu_items[1].select(); // Select second item.
});


I'm using Phaser 2 & ES5.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...