Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
added more ispurchased, + list methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrevik committed Feb 13, 2016
1 parent d10da35 commit f97fae6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions android/src/main/java/com/idehub/Billing/InAppBillingBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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) {
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit f97fae6

Please sign in to comment.