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

Commit f97fae6

Browse files
committed
added more ispurchased, + list methods
1 parent d10da35 commit f97fae6

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,33 @@ InAppBilling.subscribe('android.test.purchased')
167167
InAppBilling.isSubscribed('android.test.purchased').then(...);
168168
```
169169

170+
### isPurchased(productId)
171+
##### Parameter(s)
172+
* **productId (required):** String
173+
174+
##### Returns:
175+
* **purchased:** Boolean
176+
177+
```javascript
178+
InAppBilling.isPurchased('android.test.purchased').then(...);
179+
```
180+
181+
### listOwnedProducts()
182+
##### Returns:
183+
* **ownedProductIds:** Array of String
184+
185+
```javascript
186+
InAppBilling.listOwnedProducts().then(...);
187+
```
188+
189+
### listOwnedSubscriptions()
190+
##### Returns:
191+
* **ownedSubscriptionIds:** Array of String
192+
193+
```javascript
194+
InAppBilling.listOwnedSubscriptions().then(...);
195+
```
196+
170197
### getProductDetails(productId)
171198
##### Parameter(s)
172199
* **productId (required):** String

android/src/main/java/com/idehub/Billing/InAppBillingBridge.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,48 @@ public void isSubscribed(final String productId, final Promise promise){
191191
}
192192
}
193193

194+
@ReactMethod
195+
public void isPurchased(final String productId, final Promise promise){
196+
if (bp != null) {
197+
boolean purchased = bp.isPurchased(productId);
198+
promise.resolve(purchased);
199+
} else {
200+
promise.reject("Channel is not opened. Call open() on InAppBilling.");
201+
}
202+
}
203+
204+
@ReactMethod
205+
public void listOwnedProducts(final Promise promise){
206+
if (bp != null) {
207+
List<String> purchasedProductIds = bp.listOwnedProducts();
208+
WritableArray arr = Arguments.createArray();
209+
210+
for (int i = 0; i < purchasedProductIds.size(); i++) {
211+
arr.pushString(purchasedProductIds.get(i));
212+
}
213+
214+
promise.resolve(arr);
215+
} else {
216+
promise.reject("Channel is not opened. Call open() on InAppBilling.");
217+
}
218+
}
219+
220+
@ReactMethod
221+
public void listOwnedSubscriptions(final Promise promise){
222+
if (bp != null) {
223+
List<String> ownedSubscriptionsIds = bp.listOwnedSubscriptions();
224+
WritableArray arr = Arguments.createArray();
225+
226+
for (int i = 0; i < ownedSubscriptionsIds.size(); i++) {
227+
arr.pushString(ownedSubscriptionsIds.get(i));
228+
}
229+
230+
promise.resolve(arr);
231+
} else {
232+
promise.reject("Channel is not opened. Call open() on InAppBilling.");
233+
}
234+
}
235+
194236
@ReactMethod
195237
public void getProductDetails(final ReadableArray productIds, final Promise promise) {
196238
if (bp != null) {

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ class InAppBilling {
2727
return InAppBillingBridge.isSubscribed(productId);
2828
}
2929

30+
static isPurchased(productId) {
31+
return InAppBillingBridge.isPurchased(productId);
32+
}
33+
34+
static listOwnedProducts() {
35+
return InAppBillingBridge.listOwnedProducts();
36+
}
37+
38+
static listOwnedSubscriptions() {
39+
return InAppBillingBridge.listOwnedSubscriptions();
40+
}
41+
3042
static getProductDetails(productId) {
3143
return InAppBillingBridge.getProductDetails([productId])
3244
.then((arr) => {

0 commit comments

Comments
 (0)