diff --git a/README.md b/README.md index 85721aa..3604543 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,33 @@ InAppBilling.subscribe('android.test.purchased') InAppBilling.isSubscribed('android.test.purchased').then(...); ``` +### isPurchased(productId) +##### Parameter(s) +* **productId (required):** String + +##### Returns: +* **purchased:** Boolean + +```javascript +InAppBilling.isPurchased('android.test.purchased').then(...); +``` + +### listOwnedProducts() +##### Returns: +* **ownedProductIds:** Array of String + +```javascript +InAppBilling.listOwnedProducts().then(...); +``` + +### listOwnedSubscriptions() +##### Returns: +* **ownedSubscriptionIds:** Array of String + +```javascript +InAppBilling.listOwnedSubscriptions().then(...); +``` + ### getProductDetails(productId) ##### Parameter(s) * **productId (required):** String diff --git a/android/src/main/java/com/idehub/Billing/InAppBillingBridge.java b/android/src/main/java/com/idehub/Billing/InAppBillingBridge.java index 35df973..46e661d 100644 --- a/android/src/main/java/com/idehub/Billing/InAppBillingBridge.java +++ b/android/src/main/java/com/idehub/Billing/InAppBillingBridge.java @@ -191,6 +191,48 @@ public void isSubscribed(final String productId, final Promise promise){ } } + @ReactMethod + public void isPurchased(final String productId, final Promise promise){ + if (bp != null) { + boolean purchased = bp.isPurchased(productId); + promise.resolve(purchased); + } else { + promise.reject("Channel is not opened. Call open() on InAppBilling."); + } + } + + @ReactMethod + public void listOwnedProducts(final Promise promise){ + if (bp != null) { + List purchasedProductIds = bp.listOwnedProducts(); + WritableArray arr = Arguments.createArray(); + + for (int i = 0; i < purchasedProductIds.size(); i++) { + arr.pushString(purchasedProductIds.get(i)); + } + + promise.resolve(arr); + } else { + promise.reject("Channel is not opened. Call open() on InAppBilling."); + } + } + + @ReactMethod + public void listOwnedSubscriptions(final Promise promise){ + if (bp != null) { + List ownedSubscriptionsIds = bp.listOwnedSubscriptions(); + WritableArray arr = Arguments.createArray(); + + for (int i = 0; i < ownedSubscriptionsIds.size(); i++) { + arr.pushString(ownedSubscriptionsIds.get(i)); + } + + promise.resolve(arr); + } else { + promise.reject("Channel is not opened. Call open() on InAppBilling."); + } + } + @ReactMethod public void getProductDetails(final ReadableArray productIds, final Promise promise) { if (bp != null) { diff --git a/index.js b/index.js index ee494d8..85691be 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,18 @@ class InAppBilling { return InAppBillingBridge.isSubscribed(productId); } + static isPurchased(productId) { + return InAppBillingBridge.isPurchased(productId); + } + + static listOwnedProducts() { + return InAppBillingBridge.listOwnedProducts(); + } + + static listOwnedSubscriptions() { + return InAppBillingBridge.listOwnedSubscriptions(); + } + static getProductDetails(productId) { return InAppBillingBridge.getProductDetails([productId]) .then((arr) => {