|
1 | 1 | InApp Billing for Android 
|
2 | 2 | =============
|
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). |
4 | 4 |
|
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 | +``` |
6 | 18 |
|
7 | 19 | ## Installation with rnpm
|
8 | 20 | 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
|
63 | 75 | ```xml
|
64 | 76 | <string name="RNB_GOOGLE_PLAY_LICENSE_KEY">YOUR_GOOGLE_PLAY_LICENSE_KEY_HERE</string>
|
65 | 77 | ```
|
| 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 | +``` |
66 | 82 |
|
67 | 83 | ## 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 | + |
69 | 90 | ```javascript
|
70 |
| -const InAppBilling = require("react-native-billing"); |
| 91 | +InAppBilling.open() |
| 92 | +.then(() => InAppBilling.purchase('android.test.purchased')); |
| 93 | +``` |
71 | 94 |
|
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() |
74 | 103 | });
|
| 104 | +``` |
75 | 105 |
|
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) |
78 | 124 | });
|
| 125 | +``` |
| 126 | + |
| 127 | +### consumePurchase(productId) |
| 128 | +##### Parameter(s) |
| 129 | +* **productId (required):** String |
| 130 | + |
| 131 | +##### Returns: |
| 132 | +* **consumed:** Boolean (If consumed or not) |
79 | 133 |
|
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) |
82 | 156 | });
|
83 | 157 | ```
|
| 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 | +``` |
0 commit comments