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

Commit 0124c09

Browse files
committed
Merge pull request #6 from idehub/rewrite
Rewrite of module, more features
2 parents c8e20d4 + 6d3616d commit 0124c09

File tree

12 files changed

+594
-268
lines changed

12 files changed

+594
-268
lines changed

README.md

Lines changed: 153 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
InApp Billing for Android ![npm version](https://img.shields.io/npm/v/react-native-billing.svg)
22
=============
3-
This is a simple bridge for InApp Billing (Purchase) on Android for React Native, accomplished by wrapping [anjlab's inapp library](https://github.com/anjlab/android-inapp-billing-v3).
3+
**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-
**Important**: The JavaScript API and native module is very much subject to change in the near future, and should be viewed as just a simple implementation at the moment.
5+
```javascript
6+
const InAppBilling = require("react-native-billing");
7+
8+
InAppBilling.open()
9+
.then(() => InAppBilling.purchase('android.test.purchased'))
10+
.then((details) => {
11+
console.log("You purchased: ", details)
12+
return InAppBilling.close()
13+
})
14+
.catch((err) => {
15+
console.log(err);
16+
});
17+
```
618

719
## Installation with rnpm
820
1. `npm install --save react-native-billing`
@@ -63,21 +75,152 @@ With this, [rnpm](https://github.com/rnpm/rnpm) will do most of the heavy liftin
6375
```xml
6476
<string name="RNB_GOOGLE_PLAY_LICENSE_KEY">YOUR_GOOGLE_PLAY_LICENSE_KEY_HERE</string>
6577
```
78+
Alternatively, you can add your license key as a parameter when registering the `InAppBillingBridgePackage`, like so:
79+
```java
80+
.addPackage(new InAppBillingBridgePackage("YOUR_LICENSE_KEY", this))
81+
```
6682

6783
## Javascript API
68-
All three methods returns `Promises`.
84+
All methods returns a `Promise`.
85+
86+
### open()
87+
88+
**Important:** Must be called to open the service channel to Google Play. Must be called (once!) before any other billing methods can be called.
89+
6990
```javascript
70-
const InAppBilling = require("react-native-billing");
91+
InAppBilling.open()
92+
.then(() => InAppBilling.purchase('android.test.purchased'));
93+
```
7194

72-
InAppBilling.getProductDetails(productId).then((details) => {
73-
console.log(details);
95+
### close()
96+
**Important:** Must be called to close the service channel to Google Play, when you are done doing billing related work. Failure to close the service channel may degrade the performance of your app.
97+
```javascript
98+
InAppBilling.open()
99+
.then(() => InAppBilling.purchase('android.test.purchased'))
100+
.then((details) => {
101+
console.log("You purchased: ", details)
102+
return InAppBilling.close()
74103
});
104+
```
75105

76-
InAppBilling.purchase(productId).then((purchaseDetails) => {
77-
console.log(purchaseDetails);
106+
### purchase(productId)
107+
##### Parameter(s)
108+
* **productId (required):** String
109+
110+
##### Returns:
111+
* **transactionDetails:** Object:
112+
* **productId:** String
113+
* **orderId:** String
114+
* **purchaseToken:** String
115+
* **purchaseTime:** String
116+
* **purchaseState:** String
117+
* **receiptSignature:** String
118+
* **receiptData:** String
119+
120+
```javascript
121+
InAppBilling.purchase('android.test.purchased')
122+
.then((details) => {
123+
console.log(details)
78124
});
125+
```
126+
127+
### consumePurchase(productId)
128+
##### Parameter(s)
129+
* **productId (required):** String
130+
131+
##### Returns:
132+
* **consumed:** Boolean (If consumed or not)
79133

80-
InAppBilling.consumePurchase(productId).then((consumed) => {
81-
console.log("Is consumed: " + consumed);
134+
```javascript
135+
InAppBilling.consumePurchase('android.test.purchased').then(...);
136+
```
137+
138+
### subscribe(productId)
139+
##### Parameter(s)
140+
* **productId (required):** String
141+
142+
##### Returns:
143+
* **transactionDetails:** Object:
144+
* **productId:** String
145+
* **orderId:** String
146+
* **purchaseToken:** String
147+
* **purchaseTime:** String
148+
* **purchaseState:** String
149+
* **receiptSignature:** String
150+
* **receiptData:** String
151+
152+
```javascript
153+
InAppBilling.subscribe('android.test.purchased')
154+
.then((details) => {
155+
console.log(details)
82156
});
83157
```
158+
159+
### isSubscribed(productId)
160+
##### Parameter(s)
161+
* **productId (required):** String
162+
163+
##### Returns:
164+
* **subscribed:** Boolean
165+
166+
```javascript
167+
InAppBilling.isSubscribed('android.test.purchased').then(...);
168+
```
169+
170+
### getProductDetails(productId)
171+
##### Parameter(s)
172+
* **productId (required):** String
173+
174+
##### Returns:
175+
* **productDetails:** Object:
176+
* **productId:** String
177+
* **title:** String
178+
* **description:** String
179+
* **isSubscription:** Boolean
180+
* **currency:** String
181+
* **priceValue:** Double
182+
* **priceText:** String
183+
184+
```javascript
185+
InAppBilling.getProductDetails('android.test.purchased').then(...);
186+
```
187+
188+
### getProductDetailsArray(productIds)
189+
##### Parameter(s)
190+
* **productIds (required):** String-array
191+
192+
##### Returns:
193+
* **productDetailsArray:** Array of the productDetails (same as above)
194+
195+
```javascript
196+
InAppBilling.getProductDetailsArray(['android.test.purchased', 'android.test.purchased2']).then(...);
197+
```
198+
199+
### getSubscriptionDetails(productId)
200+
##### Parameter(s)
201+
* **productId (required):** String
202+
203+
##### Returns:
204+
* **productDetails:** Object:
205+
* **productId:** String
206+
* **title:** String
207+
* **description:** String
208+
* **isSubscription:** Boolean
209+
* **currency:** String
210+
* **priceValue:** Double
211+
* **priceText:** String
212+
213+
```javascript
214+
InAppBilling.getSubscriptionDetails('android.test.subscription').then(...);
215+
```
216+
217+
### getSubscriptionDetailsArray(productIds)
218+
##### Parameter(s)
219+
* **productIds (required):** String-Array
220+
221+
##### Returns:
222+
* **productDetailsArray:** Array of the productDetails (same as above)
223+
224+
```javascript
225+
InAppBilling.getSubscriptionDetailsArray(['android.test.subscription', 'android.test.subscription2']).then(...);
226+
```

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

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)