Skip to content

Commit

Permalink
(android): Enable purchases to be acknowledged by purchase token (in …
Browse files Browse the repository at this point in the history
…addition to by SKU)
  • Loading branch information
dpa99c committed Oct 3, 2022
1 parent 2310e05 commit 3bc786e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/android/cc/fovea/PurchasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
});
}
Expand Down
6 changes: 6 additions & 0 deletions src/js/platforms/plugin-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()');
Expand Down
6 changes: 6 additions & 0 deletions www/store-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()');
Expand Down
6 changes: 6 additions & 0 deletions www/store-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()');
Expand Down

0 comments on commit 3bc786e

Please sign in to comment.