Skip to content

Commit

Permalink
Released to 2.2.0. resolve #257.
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Sep 16, 2018
1 parent 589013a commit a5f225d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,8 @@
## Changelogs
- **[2.2.0]**
+ Added `clearTransaction` method which resolve #257.
- **[2.1.3]**
+ Use mutable array in ios not to clear up the array each time products are fetched.
- **[2.0.3]**
+ Properly setup new method `initConnection` and deprecate `prepare`.
- **[2.0.0]**
Expand Down
27 changes: 26 additions & 1 deletion README.md
Expand Up @@ -69,6 +69,7 @@ Also, note that this is our last migration for renaming method names without any
| buyProductWithQuantityIOS | `string` Product ID/sku, `number` Quantity | `Promise<Purchase>` | Buy a product with a specified quantity (iOS only) |
| buyProductWithoutFinishTransaction | `string` Product ID/sku | `Promise<Purchase>` | Buy a product without finish transaction call (iOS only) |
| finishTransaction | `void` | `void` | Send finishTransaction call to Apple IAP server. Call this function after receipt validation process |
| clearTransaction | `void` | `void` | Clear up the unfinished transanction which sometimes causes problem. Read more in below readme. |
| consumeProduct | `string` Purchase token | `Promise<void>` | Consume a product (on Android.) No-op on iOS. |
| endConnection | | `Promise<void>` | End billing connection (on Android.) No-op on iOS. |
| consumeAllItems | | `Promise<void>` | Consume all items in android so they are able to buy again (on Android.) No-op on iOS. |
Expand Down Expand Up @@ -298,8 +299,32 @@ Step 3 : Apply the product to the Application

But, sometimes app doesn't make it to step 3, and user loose the product with successful payment.
Non-consumable products can be restored via getPurchaseHistory function, but consumable products can be lost.
In this case, use buyProductWithoutFinishTransaction to purchase action and use finishTransaction to finish payment after receipt validation and supply the products to user.
In this case, use `buyProductWithoutFinishTransaction` to purchase action and use `finishTransaction` to finish payment after receipt validation and supply the products to user.

```javascript
const purchase = await RNIap.buyProductWithoutFinishTransaction(productId);
// to something in your server
const { transactionReceipt, purchaseToken } = purchase;
sendToServer(transactionReceipt, {
onSuccess: () => {
RNIap.finishTransaction();
},
});
```

However, sometimes apple internally causes problem itself before `finishTransaction` which queues are not resolved which may result in failure in next purchase ([related issue #256](https://github.com/dooboolab/react-native-iap/issues/257)). Therefore, we've made another method that may resolve this kind of issue in after purchase which is to finish up the queues at the start of each purchase. To resolve this, try code like below.
```javascript
await RNIap.clearTransaction(); // add this method at the start of purchase.
const purchase = await RNIap.buyProductWithoutFinishTransaction(productId);
// to something in your server
const { transactionReceipt, purchaseToken } = purchase;
sendToServer(transactionReceipt, {
onSuccess: () => {
RNIap.finishTransaction();
},
});
```
We've like to update this solution as version changes in `react-native-iap`.
----

## Supporting react-native-iap
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -156,7 +156,7 @@ export const finishTransaction = () => Platform.select({
*/
export const clearTransaction = () => Platform.select({
ios: () => RNIapIos.clearTransaction(),
android: () => console.log(' No effect on Android!'),
android: () => console.log(' No ops in Android!'),
})();

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-iap",
"version": "2.1.3",
"version": "2.2.0",
"description": "React Native In App Purchase Module.",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit a5f225d

Please sign in to comment.