consumable inapp purchase already bought popup












0















I am implementing consumable inapp purchases using this module https://github.com/appcelerator-modules/ti.storekit.
Everything was working fine when suddenly it stopped working saying In-APP purchase has already been bought.
I google and found that the transaction has to be finished. Since Storekit.autoFinishTransactions is set to false it is finished in transactionState listener . Also the other solution was to set the Observer
which already exists "Storekit.addTransactionObserver()".
Thank you



var Storekit = require('ti.storekit');
Storekit.autoFinishTransactions = false;
Storekit.bundleVersion = "1.4";
Storekit.bundleIdentifier = "com.xxx.xyz";

var verifyingReceipts = false;

var loading = Ti.UI.createActivityIndicator({
bottom : 10,
height : 50,
width : 50,
backgroundColor : 'black',
borderRadius : 10,
style : Ti.UI.ActivityIndicatorStyle.BIG
});
var loadingCount = 0;

function showLoading() {
loadingCount += 1;
if (loadingCount == 1) {
loading.show();
}
}

function hideLoading() {
if (loadingCount > 0) {
loadingCount -= 1;
if (loadingCount == 0) {
loading.hide();
}
}
}

function requestProduct(identifier, success) {
showLoading();
Storekit.requestProducts([identifier], function(evt) {
hideLoading();
if (!evt.success) {
Ti.API.error('ERROR: We failed to talk to Apple!');
} else if (evt.invalid) {
Ti.API.error('ERROR: We requested an invalid product (' + identifier + '):' + "--" + JSON.stringify(evt));
Ti.API.error(evt);
} else {
Ti.API.info('Valid Product:');
Ti.API.info("evt:---" + JSON.stringify(evt) + "---" + evt.products[0].formattedPrice);
success(evt.products[0]);
}
});
}

Storekit.addEventListener('transactionState', function(evt) {
hideLoading();
switch (evt.state) {
case Storekit.TRANSACTION_STATE_FAILED:
if (evt.cancelled) {
Ti.API.warn('Purchase cancelled');
} else {
Ti.API.error('ERROR: Buying failed! ' + evt.message);
}
evt.transaction && evt.transaction.finish();
break;
case Storekit.TRANSACTION_STATE_PURCHASED:
if (verifyingReceipts) {
var msg = Storekit.validateReceipt() ? 'Receipt is Valid!' : 'Receipt is Invalid.';
Ti.API.info('Validation: ' + msg);
Ti.API.info("Purchase is valid");
console.log("evt.productIdentifier:" + evt.productIdentifier);
evt.transaction && evt.transaction.finish();
}
break;
case Storekit.TRANSACTION_STATE_PURCHASING:
Ti.API.info('Purchasing ' + evt.productIdentifier+"---"+JSON.stringify(evt));
break;
case Storekit.TRANSACTION_STATE_DEFERRED:
Ti.API.info('Deferring ' + evt.productIdentifier + ': The transaction is in the queue, but its final status is pending external action.');
break;
case Storekit.TRANSACTION_STATE_RESTORED:
Ti.API.info('Restored ' + evt.productIdentifier);
evt.transaction && evt.transaction.finish();
break;
}
});

Storekit.addEventListener('updatedDownloads', function(evt) {});

function purchaseProduct(product) {
if (product.downloadable) {
Ti.API.info('Purchasing a product that is downloadable');
}
showLoading();
Storekit.purchase({
product : product
// applicationUsername is a opaque identifier for the user’s account on your system.
// Used by Apple to detect irregular activity. Should hash the username before setting.
// applicationUsername: '<HASHED APPLICATION USERNAME>'
});
}

Storekit.addEventListener('restoredCompletedTransactions', function(evt) {
console.log("inside restoredCompletion");
hideLoading();
if (evt.error) {
Ti.API.error(evt.error);
} else if (evt.transactions == null || evt.transactions.length == 0) {
Ti.API.warn('There were no purchases to restore!');
} else {
if (verifyingReceipts) {
if (Storekit.validateReceipt()) {
Ti.API.info('Restored Receipt is Valid!');
} else {
Ti.API.error('Restored Receipt is Invalid.');
}
}
for (var i = 0; i < evt.transactions.length; i++) {
Ti.API.info("---"+evt.transactions[i].productIdentifier);
}
Ti.API.info('Restored ' + evt.transactions.length + ' purchases!');
}
});

Storekit.addTransactionObserver();

$.window.addEventListener('open', function() {
function validate() {
Ti.API.info('Receipt is Valid: ' + Storekit.validateReceipt());
}

if (!Storekit.receiptExists) {
Ti.API.info('Receipt does not exist yet. Refreshing to get one.');
Storekit.refreshReceipt(null, function() {
validate();
});
} else {
Ti.API.info('Receipt does exist.');
validate();
}
});

if (!Storekit.canMakePayments)
Ti.API.error('This device cannot make purchases!');
else {

requestProduct("com.xxx.xyz.unlock", function(product) {
console.log('product.formattedPrice---'+product.formattedPrice);
$.allPrice.setText(product.formattedPrice);
$.allCategories.addEventListener('click', function() {
purchaseProduct(product);
});
});

}

$.window.open();









share|improve this question



























    0















    I am implementing consumable inapp purchases using this module https://github.com/appcelerator-modules/ti.storekit.
    Everything was working fine when suddenly it stopped working saying In-APP purchase has already been bought.
    I google and found that the transaction has to be finished. Since Storekit.autoFinishTransactions is set to false it is finished in transactionState listener . Also the other solution was to set the Observer
    which already exists "Storekit.addTransactionObserver()".
    Thank you



    var Storekit = require('ti.storekit');
    Storekit.autoFinishTransactions = false;
    Storekit.bundleVersion = "1.4";
    Storekit.bundleIdentifier = "com.xxx.xyz";

    var verifyingReceipts = false;

    var loading = Ti.UI.createActivityIndicator({
    bottom : 10,
    height : 50,
    width : 50,
    backgroundColor : 'black',
    borderRadius : 10,
    style : Ti.UI.ActivityIndicatorStyle.BIG
    });
    var loadingCount = 0;

    function showLoading() {
    loadingCount += 1;
    if (loadingCount == 1) {
    loading.show();
    }
    }

    function hideLoading() {
    if (loadingCount > 0) {
    loadingCount -= 1;
    if (loadingCount == 0) {
    loading.hide();
    }
    }
    }

    function requestProduct(identifier, success) {
    showLoading();
    Storekit.requestProducts([identifier], function(evt) {
    hideLoading();
    if (!evt.success) {
    Ti.API.error('ERROR: We failed to talk to Apple!');
    } else if (evt.invalid) {
    Ti.API.error('ERROR: We requested an invalid product (' + identifier + '):' + "--" + JSON.stringify(evt));
    Ti.API.error(evt);
    } else {
    Ti.API.info('Valid Product:');
    Ti.API.info("evt:---" + JSON.stringify(evt) + "---" + evt.products[0].formattedPrice);
    success(evt.products[0]);
    }
    });
    }

    Storekit.addEventListener('transactionState', function(evt) {
    hideLoading();
    switch (evt.state) {
    case Storekit.TRANSACTION_STATE_FAILED:
    if (evt.cancelled) {
    Ti.API.warn('Purchase cancelled');
    } else {
    Ti.API.error('ERROR: Buying failed! ' + evt.message);
    }
    evt.transaction && evt.transaction.finish();
    break;
    case Storekit.TRANSACTION_STATE_PURCHASED:
    if (verifyingReceipts) {
    var msg = Storekit.validateReceipt() ? 'Receipt is Valid!' : 'Receipt is Invalid.';
    Ti.API.info('Validation: ' + msg);
    Ti.API.info("Purchase is valid");
    console.log("evt.productIdentifier:" + evt.productIdentifier);
    evt.transaction && evt.transaction.finish();
    }
    break;
    case Storekit.TRANSACTION_STATE_PURCHASING:
    Ti.API.info('Purchasing ' + evt.productIdentifier+"---"+JSON.stringify(evt));
    break;
    case Storekit.TRANSACTION_STATE_DEFERRED:
    Ti.API.info('Deferring ' + evt.productIdentifier + ': The transaction is in the queue, but its final status is pending external action.');
    break;
    case Storekit.TRANSACTION_STATE_RESTORED:
    Ti.API.info('Restored ' + evt.productIdentifier);
    evt.transaction && evt.transaction.finish();
    break;
    }
    });

    Storekit.addEventListener('updatedDownloads', function(evt) {});

    function purchaseProduct(product) {
    if (product.downloadable) {
    Ti.API.info('Purchasing a product that is downloadable');
    }
    showLoading();
    Storekit.purchase({
    product : product
    // applicationUsername is a opaque identifier for the user’s account on your system.
    // Used by Apple to detect irregular activity. Should hash the username before setting.
    // applicationUsername: '<HASHED APPLICATION USERNAME>'
    });
    }

    Storekit.addEventListener('restoredCompletedTransactions', function(evt) {
    console.log("inside restoredCompletion");
    hideLoading();
    if (evt.error) {
    Ti.API.error(evt.error);
    } else if (evt.transactions == null || evt.transactions.length == 0) {
    Ti.API.warn('There were no purchases to restore!');
    } else {
    if (verifyingReceipts) {
    if (Storekit.validateReceipt()) {
    Ti.API.info('Restored Receipt is Valid!');
    } else {
    Ti.API.error('Restored Receipt is Invalid.');
    }
    }
    for (var i = 0; i < evt.transactions.length; i++) {
    Ti.API.info("---"+evt.transactions[i].productIdentifier);
    }
    Ti.API.info('Restored ' + evt.transactions.length + ' purchases!');
    }
    });

    Storekit.addTransactionObserver();

    $.window.addEventListener('open', function() {
    function validate() {
    Ti.API.info('Receipt is Valid: ' + Storekit.validateReceipt());
    }

    if (!Storekit.receiptExists) {
    Ti.API.info('Receipt does not exist yet. Refreshing to get one.');
    Storekit.refreshReceipt(null, function() {
    validate();
    });
    } else {
    Ti.API.info('Receipt does exist.');
    validate();
    }
    });

    if (!Storekit.canMakePayments)
    Ti.API.error('This device cannot make purchases!');
    else {

    requestProduct("com.xxx.xyz.unlock", function(product) {
    console.log('product.formattedPrice---'+product.formattedPrice);
    $.allPrice.setText(product.formattedPrice);
    $.allCategories.addEventListener('click', function() {
    purchaseProduct(product);
    });
    });

    }

    $.window.open();









    share|improve this question

























      0












      0








      0








      I am implementing consumable inapp purchases using this module https://github.com/appcelerator-modules/ti.storekit.
      Everything was working fine when suddenly it stopped working saying In-APP purchase has already been bought.
      I google and found that the transaction has to be finished. Since Storekit.autoFinishTransactions is set to false it is finished in transactionState listener . Also the other solution was to set the Observer
      which already exists "Storekit.addTransactionObserver()".
      Thank you



      var Storekit = require('ti.storekit');
      Storekit.autoFinishTransactions = false;
      Storekit.bundleVersion = "1.4";
      Storekit.bundleIdentifier = "com.xxx.xyz";

      var verifyingReceipts = false;

      var loading = Ti.UI.createActivityIndicator({
      bottom : 10,
      height : 50,
      width : 50,
      backgroundColor : 'black',
      borderRadius : 10,
      style : Ti.UI.ActivityIndicatorStyle.BIG
      });
      var loadingCount = 0;

      function showLoading() {
      loadingCount += 1;
      if (loadingCount == 1) {
      loading.show();
      }
      }

      function hideLoading() {
      if (loadingCount > 0) {
      loadingCount -= 1;
      if (loadingCount == 0) {
      loading.hide();
      }
      }
      }

      function requestProduct(identifier, success) {
      showLoading();
      Storekit.requestProducts([identifier], function(evt) {
      hideLoading();
      if (!evt.success) {
      Ti.API.error('ERROR: We failed to talk to Apple!');
      } else if (evt.invalid) {
      Ti.API.error('ERROR: We requested an invalid product (' + identifier + '):' + "--" + JSON.stringify(evt));
      Ti.API.error(evt);
      } else {
      Ti.API.info('Valid Product:');
      Ti.API.info("evt:---" + JSON.stringify(evt) + "---" + evt.products[0].formattedPrice);
      success(evt.products[0]);
      }
      });
      }

      Storekit.addEventListener('transactionState', function(evt) {
      hideLoading();
      switch (evt.state) {
      case Storekit.TRANSACTION_STATE_FAILED:
      if (evt.cancelled) {
      Ti.API.warn('Purchase cancelled');
      } else {
      Ti.API.error('ERROR: Buying failed! ' + evt.message);
      }
      evt.transaction && evt.transaction.finish();
      break;
      case Storekit.TRANSACTION_STATE_PURCHASED:
      if (verifyingReceipts) {
      var msg = Storekit.validateReceipt() ? 'Receipt is Valid!' : 'Receipt is Invalid.';
      Ti.API.info('Validation: ' + msg);
      Ti.API.info("Purchase is valid");
      console.log("evt.productIdentifier:" + evt.productIdentifier);
      evt.transaction && evt.transaction.finish();
      }
      break;
      case Storekit.TRANSACTION_STATE_PURCHASING:
      Ti.API.info('Purchasing ' + evt.productIdentifier+"---"+JSON.stringify(evt));
      break;
      case Storekit.TRANSACTION_STATE_DEFERRED:
      Ti.API.info('Deferring ' + evt.productIdentifier + ': The transaction is in the queue, but its final status is pending external action.');
      break;
      case Storekit.TRANSACTION_STATE_RESTORED:
      Ti.API.info('Restored ' + evt.productIdentifier);
      evt.transaction && evt.transaction.finish();
      break;
      }
      });

      Storekit.addEventListener('updatedDownloads', function(evt) {});

      function purchaseProduct(product) {
      if (product.downloadable) {
      Ti.API.info('Purchasing a product that is downloadable');
      }
      showLoading();
      Storekit.purchase({
      product : product
      // applicationUsername is a opaque identifier for the user’s account on your system.
      // Used by Apple to detect irregular activity. Should hash the username before setting.
      // applicationUsername: '<HASHED APPLICATION USERNAME>'
      });
      }

      Storekit.addEventListener('restoredCompletedTransactions', function(evt) {
      console.log("inside restoredCompletion");
      hideLoading();
      if (evt.error) {
      Ti.API.error(evt.error);
      } else if (evt.transactions == null || evt.transactions.length == 0) {
      Ti.API.warn('There were no purchases to restore!');
      } else {
      if (verifyingReceipts) {
      if (Storekit.validateReceipt()) {
      Ti.API.info('Restored Receipt is Valid!');
      } else {
      Ti.API.error('Restored Receipt is Invalid.');
      }
      }
      for (var i = 0; i < evt.transactions.length; i++) {
      Ti.API.info("---"+evt.transactions[i].productIdentifier);
      }
      Ti.API.info('Restored ' + evt.transactions.length + ' purchases!');
      }
      });

      Storekit.addTransactionObserver();

      $.window.addEventListener('open', function() {
      function validate() {
      Ti.API.info('Receipt is Valid: ' + Storekit.validateReceipt());
      }

      if (!Storekit.receiptExists) {
      Ti.API.info('Receipt does not exist yet. Refreshing to get one.');
      Storekit.refreshReceipt(null, function() {
      validate();
      });
      } else {
      Ti.API.info('Receipt does exist.');
      validate();
      }
      });

      if (!Storekit.canMakePayments)
      Ti.API.error('This device cannot make purchases!');
      else {

      requestProduct("com.xxx.xyz.unlock", function(product) {
      console.log('product.formattedPrice---'+product.formattedPrice);
      $.allPrice.setText(product.formattedPrice);
      $.allCategories.addEventListener('click', function() {
      purchaseProduct(product);
      });
      });

      }

      $.window.open();









      share|improve this question














      I am implementing consumable inapp purchases using this module https://github.com/appcelerator-modules/ti.storekit.
      Everything was working fine when suddenly it stopped working saying In-APP purchase has already been bought.
      I google and found that the transaction has to be finished. Since Storekit.autoFinishTransactions is set to false it is finished in transactionState listener . Also the other solution was to set the Observer
      which already exists "Storekit.addTransactionObserver()".
      Thank you



      var Storekit = require('ti.storekit');
      Storekit.autoFinishTransactions = false;
      Storekit.bundleVersion = "1.4";
      Storekit.bundleIdentifier = "com.xxx.xyz";

      var verifyingReceipts = false;

      var loading = Ti.UI.createActivityIndicator({
      bottom : 10,
      height : 50,
      width : 50,
      backgroundColor : 'black',
      borderRadius : 10,
      style : Ti.UI.ActivityIndicatorStyle.BIG
      });
      var loadingCount = 0;

      function showLoading() {
      loadingCount += 1;
      if (loadingCount == 1) {
      loading.show();
      }
      }

      function hideLoading() {
      if (loadingCount > 0) {
      loadingCount -= 1;
      if (loadingCount == 0) {
      loading.hide();
      }
      }
      }

      function requestProduct(identifier, success) {
      showLoading();
      Storekit.requestProducts([identifier], function(evt) {
      hideLoading();
      if (!evt.success) {
      Ti.API.error('ERROR: We failed to talk to Apple!');
      } else if (evt.invalid) {
      Ti.API.error('ERROR: We requested an invalid product (' + identifier + '):' + "--" + JSON.stringify(evt));
      Ti.API.error(evt);
      } else {
      Ti.API.info('Valid Product:');
      Ti.API.info("evt:---" + JSON.stringify(evt) + "---" + evt.products[0].formattedPrice);
      success(evt.products[0]);
      }
      });
      }

      Storekit.addEventListener('transactionState', function(evt) {
      hideLoading();
      switch (evt.state) {
      case Storekit.TRANSACTION_STATE_FAILED:
      if (evt.cancelled) {
      Ti.API.warn('Purchase cancelled');
      } else {
      Ti.API.error('ERROR: Buying failed! ' + evt.message);
      }
      evt.transaction && evt.transaction.finish();
      break;
      case Storekit.TRANSACTION_STATE_PURCHASED:
      if (verifyingReceipts) {
      var msg = Storekit.validateReceipt() ? 'Receipt is Valid!' : 'Receipt is Invalid.';
      Ti.API.info('Validation: ' + msg);
      Ti.API.info("Purchase is valid");
      console.log("evt.productIdentifier:" + evt.productIdentifier);
      evt.transaction && evt.transaction.finish();
      }
      break;
      case Storekit.TRANSACTION_STATE_PURCHASING:
      Ti.API.info('Purchasing ' + evt.productIdentifier+"---"+JSON.stringify(evt));
      break;
      case Storekit.TRANSACTION_STATE_DEFERRED:
      Ti.API.info('Deferring ' + evt.productIdentifier + ': The transaction is in the queue, but its final status is pending external action.');
      break;
      case Storekit.TRANSACTION_STATE_RESTORED:
      Ti.API.info('Restored ' + evt.productIdentifier);
      evt.transaction && evt.transaction.finish();
      break;
      }
      });

      Storekit.addEventListener('updatedDownloads', function(evt) {});

      function purchaseProduct(product) {
      if (product.downloadable) {
      Ti.API.info('Purchasing a product that is downloadable');
      }
      showLoading();
      Storekit.purchase({
      product : product
      // applicationUsername is a opaque identifier for the user’s account on your system.
      // Used by Apple to detect irregular activity. Should hash the username before setting.
      // applicationUsername: '<HASHED APPLICATION USERNAME>'
      });
      }

      Storekit.addEventListener('restoredCompletedTransactions', function(evt) {
      console.log("inside restoredCompletion");
      hideLoading();
      if (evt.error) {
      Ti.API.error(evt.error);
      } else if (evt.transactions == null || evt.transactions.length == 0) {
      Ti.API.warn('There were no purchases to restore!');
      } else {
      if (verifyingReceipts) {
      if (Storekit.validateReceipt()) {
      Ti.API.info('Restored Receipt is Valid!');
      } else {
      Ti.API.error('Restored Receipt is Invalid.');
      }
      }
      for (var i = 0; i < evt.transactions.length; i++) {
      Ti.API.info("---"+evt.transactions[i].productIdentifier);
      }
      Ti.API.info('Restored ' + evt.transactions.length + ' purchases!');
      }
      });

      Storekit.addTransactionObserver();

      $.window.addEventListener('open', function() {
      function validate() {
      Ti.API.info('Receipt is Valid: ' + Storekit.validateReceipt());
      }

      if (!Storekit.receiptExists) {
      Ti.API.info('Receipt does not exist yet. Refreshing to get one.');
      Storekit.refreshReceipt(null, function() {
      validate();
      });
      } else {
      Ti.API.info('Receipt does exist.');
      validate();
      }
      });

      if (!Storekit.canMakePayments)
      Ti.API.error('This device cannot make purchases!');
      else {

      requestProduct("com.xxx.xyz.unlock", function(product) {
      console.log('product.formattedPrice---'+product.formattedPrice);
      $.allPrice.setText(product.formattedPrice);
      $.allCategories.addEventListener('click', function() {
      purchaseProduct(product);
      });
      });

      }

      $.window.open();






      titanium appcelerator appcelerator-titanium






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 28 '18 at 7:33









      MarioMario

      163




      163
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53514307%2fconsumable-inapp-purchase-already-bought-popup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53514307%2fconsumable-inapp-purchase-already-bought-popup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)