diff --git a/src/android/cc/fovea/PurchasePlugin.java b/src/android/cc/fovea/PurchasePlugin.java index 9475b34f..c5f68b1e 100644 --- a/src/android/cc/fovea/PurchasePlugin.java +++ b/src/android/cc/fovea/PurchasePlugin.java @@ -163,8 +163,9 @@ public boolean execute(final String action, final String sku = data.getString(0); consumePurchase(sku); } else if ("acknowledgePurchase".equals(action)) { - final String sku = data.getString(0); - acknowledgePurchase(sku); + acknowledgePurchaseBySku(data.getString(0)); + } else if ("acknowledgePurchaseByToken".equals(action)) { + acknowledgePurchaseByToken(data.getString(0)); } else if ("buy".equals(action)) { buy(data); } else if ("subscribe".equals(action)) { @@ -873,8 +874,8 @@ private void consumePurchase(final String productId) throws JSONException { } // Acknowledge a purchase - private void acknowledgePurchase(final String sku) throws JSONException { - Log.d(mTag, "acknowledgePurchase(" + sku + ")"); + private void acknowledgePurchaseBySku(final String sku) throws JSONException { + Log.d(mTag, "acknowledgePurchaseBySku(" + sku + ")"); // Find the purchaseToken from sku final Purchase purchase = findPurchaseByProductId(sku); if (purchase == null) { @@ -883,11 +884,28 @@ private void acknowledgePurchase(final String sku) throws JSONException { return; } final String purchaseToken = purchase.getPurchaseToken(); + acknowledgePurchase(purchaseToken); + } + + private void acknowledgePurchaseByToken(final String purchaseToken) throws JSONException { + Log.d(mTag, "acknowledgePurchaseByToken(" + purchaseToken + ")"); + // Find the purchaseToken from sku + final Purchase purchase = findPurchaseByToken(purchaseToken); + if (purchase == null) { + Log.w(mTag, "acknowledgePurchaseByToken() -> No such purchase"); + callError(Constants.ERR_PURCHASE, "ITEM_NOT_OWNED"); + return; + } + acknowledgePurchase(purchaseToken); + } + + + private void acknowledgePurchase(final String purchaseToken) { executeServiceRequest(() -> { final AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder() - .setPurchaseToken(purchaseToken) - // .setDeveloperPayload(developerPayload) (removed in v3) - .build(); + .setPurchaseToken(purchaseToken) + // .setDeveloperPayload(developerPayload) (removed in v3) + .build(); mBillingClient.acknowledgePurchase(params, this); }); } diff --git a/src/js/platforms/plugin-bridge.js b/src/js/platforms/plugin-bridge.js index be844e6b..8fe9e8b0 100644 --- a/src/js/platforms/plugin-bridge.js +++ b/src/js/platforms/plugin-bridge.js @@ -137,6 +137,12 @@ InAppBilling.prototype.acknowledgePurchase = function (success, fail, productId, } return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "acknowledgePurchase", [productId, transactionId, developerPayload]); }; +InAppBilling.prototype.acknowledgePurchaseByToken = function (success, fail, purchaseToken) { + if (this.options.showLog) { + log('acknowledgePurchaseByToken()'); + } + return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "acknowledgePurchaseByToken", [purchaseToken]); +}; InAppBilling.prototype.getAvailableProducts = function (success, fail) { if (this.options.showLog) { log('getAvailableProducts()'); diff --git a/www/store-android.js b/www/store-android.js index 1a376465..fa793772 100644 --- a/www/store-android.js +++ b/www/store-android.js @@ -3158,6 +3158,12 @@ InAppBilling.prototype.acknowledgePurchase = function (success, fail, productId, } return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "acknowledgePurchase", [productId, transactionId, developerPayload]); }; +InAppBilling.prototype.acknowledgePurchaseByToken = function (success, fail, purchaseToken) { + if (this.options.showLog) { + log('acknowledgePurchaseByToken()'); + } + return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "acknowledgePurchaseByToken", [purchaseToken]); +}; InAppBilling.prototype.getAvailableProducts = function (success, fail) { if (this.options.showLog) { log('getAvailableProducts()'); diff --git a/www/store-windows.js b/www/store-windows.js index 14710fed..627fe3aa 100644 --- a/www/store-windows.js +++ b/www/store-windows.js @@ -3158,6 +3158,12 @@ InAppBilling.prototype.acknowledgePurchase = function (success, fail, productId, } return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "acknowledgePurchase", [productId, transactionId, developerPayload]); }; +InAppBilling.prototype.acknowledgePurchaseByToken = function (success, fail, purchaseToken) { + if (this.options.showLog) { + log('acknowledgePurchaseByToken()'); + } + return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "acknowledgePurchaseByToken", [purchaseToken]); +}; InAppBilling.prototype.getAvailableProducts = function (success, fail) { if (this.options.showLog) { log('getAvailableProducts()');