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

Commit eb72deb

Browse files
committed
Update README
1 parent e7750a7 commit eb72deb

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

README.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,35 @@
22

33
**React Native Billing** is built to provide an easy interface to InApp Billing on **Android**, accomplished by wrapping [anjlab's InApp Billing library](https://github.com/anjlab/android-inapp-billing-v3).
44

5-
```javascript
6-
const InAppBilling = require("react-native-billing");
5+
```js
6+
import InAppBilling from "react-native-billing";
77

8-
InAppBilling.open()
9-
.then(() => InAppBilling.purchase("android.test.purchased"))
10-
.then(details => {
8+
async purchase() {
9+
try {
10+
await InAppBilling.open();
11+
const details = await InAppBilling.purchase("android.test.purchased");
1112
console.log("You purchased: ", details);
12-
return InAppBilling.close();
13-
})
14-
.catch(err => {
13+
} catch (err) {
1514
console.log(err);
16-
});
15+
} finally {
16+
await InAppBilling.close();
17+
}
18+
}
19+
20+
async checkSubscription() {
21+
try {
22+
await InAppBilling.open();
23+
// If subscriptions/products are updated server-side you
24+
// will have to update cache with loadOwnedPurchasesFromGoogle()
25+
await InAppBilling.loadOwnedPurchasesFromGoogle();
26+
const isSubscribed = await InAppBilling.isSubscribed("myapp.productId")
27+
console.log("Customer subscribed: ", isSubscribed);
28+
} catch (err) {
29+
console.log(err);
30+
} finally {
31+
await InAppBilling.close();
32+
}
33+
}
1734
```
1835

1936
## Installation and linking

0 commit comments

Comments
 (0)