Legacy GM In App Purchases - Android Issues

T

The Shatner

Guest
Hey there!
I've been trying to use IAP, but I can't make it work.
Here's what I've tried so far:
*Following the tutorial on https://help.yoyogames.com/hc/en-us/articles/216755198-In-App-Purchases-Example;
*Checking everything on the "Android" tab (Enable Services, IAPs, Licensing, APK Expansion) and adding the corresponding extension;
*Starting from scratch following a tutorial and a marketplace extension that gave an example of how it's done.
*Double-checking if my Google Account is OK to receive payments (and yes, it is...)

Here's my code:
<<First object in the game>>
CREATE EVENT
Code:
var map_create = false;
if file_exists("iap_data.json")
   {
    global.purchaseMap = ds_map_secure_load("iap_data.json");
    map_create = true;
   } else map_create = true;
if map_create //Creating a map with information about purchases
   {
    global.purchaseMap = ds_map_create();
    var pNoAds = "game_noads"; //Non-consumable
    ds_map_add(global.purchaseMap, pNoAds, 0);
    ds_map_secure_save(global.purchaseMap, "iap_data.json");
   }
 
var productList = ds_list_create();
var pNoAds = ds_map_create();
ds_map_add(pNoAds, "id", "game_noads"); /*purchase id, must be the same in the playmarket developer panel
                                                        or in ios developer panel */
ds_map_add(pNoAds, "title", "Enables the full game experience."); //Description
ds_map_add(pNoAds, "type", "Durable"); //Type (Durable or Consumable)


ds_list_add(productList, pNoAds);

iap_activate(productList);
ds_list_destroy(productList);

alarm[0]=30;
ALARM 0 :
Code:
room_goto_next();
<<The button object that's supposed to send the player to the in-app purchase>>
GLOBAL LEFT RELEASED EVENT
Code:
if mouse_x=median(mouse_x,x-dimension_x,x+dimension_x) and mouse_y=median(mouse_y,y-dimension_y,y-dimension_y) //This checks if mouse position is in the button
 {
  //need to receive a status about purchase
  var status = iap_status();
  if status == iap_status_available //
   {
   var product = "game_noads"; //Non-consumable product (noAds)
   if ds_map_find_value(global.purchaseMap, product) == 0
    {
     iap_acquire(product, ""); //When you use iap_acquire it will trigger IAP event
    }
   } else show_message_async(errormsg); //if you have no connection or store is not available
 }

if mouse_x=median(mouse_x,x-dimension_x,x+dimension_x)
and mouse_y=median(mouse_y,y-dimension_y,y+dimension_y)
 {
  if (iap_status() == iap_status_available){ //
   iap_restore_all(); //Restoring in-apps. It will trigger the IAP event (iap_ev_restore), but code below works at well too

   if (iap_is_purchased("game_noads")) //is noAds purchased? if Yes, see below
   {
    //Need to save our info about noAds. haveads=0 till now, and remember to load that info on the start of the game
    ini_open('data.ini');
    ini_write_string("settings","fullversion","yes");
    ini_close();
    global.Fullversion = "on";
    show_message_async(restoredmsg); //Restored message!
   }} else if (iap_status()!=iap_status_available) show_message_async(errormsg);
 }
IAP EVENT
Code:
var val = ds_map_find_value(iap_data, "type"); //Checking the function which trigger IAP
switch (val)
   {
   //all purchases
   case iap_ev_purchase:
      var map = ds_map_create();
      var purchase_id = ds_map_find_value(iap_data, "index"); //need to find iap index to received the details about that iap
      iap_purchase_details(purchase_id, map); //receivind details to check the purchasing status
      if ds_map_find_value(map, "status") == iap_purchased //our in-app triggers this code (IAP), if iap_purchased, need to check
                                                           //product's name
         {
         //which product is acquire? Checking
         var product_id = ds_map_find_value(map, "product");
         ds_map_replace(global.purchaseMap, product_id, 1);
         switch(product_id)
            {
             case "game_noads": //Saving noAds IAP to .ini file, no need to trigger the iap_ev_restore (because in this example
             //we use another way to restore iap)
                ini_open('data.ini')
                ini_write_string('settings','fullversion','yes');
                ini_close();
                global.Fullversion= "on";
                break;
            }
         }
      ds_map_destroy(map);
      break;
   //Restoring the IAP, do not fill
   case iap_ev_restore:
      break;
   }
ds_map_secure_save(global.purchaseMap, "iap_data.json");

The thing is... It gives no message at all. When I compile for Windows and click the object, it returns a message saying that the store could not be accessed (which is what the 'errormsg' string above contains). So, I'm doing something right...

Anything I might be missing?
 
Last edited by a moderator:
Top