Skip to content

Commit

Permalink
Preparing for release 2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Sep 3, 2019
1 parent ad418cd commit fc8698e
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 80 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2.4.1

- Fixes expirationDate in the EntitlementInfo object in iOS

## 2.4.0

- Deprecates activeEntitlements in PurchaserInfo and adds entitlements object to RCPurchaserInfo. For more info check out https://docs.revenuecat.com/docs/purchaserinfo
- Fixes trial info being lost in Android. Access intro_price in the product information to get information around the trial period.
- Fixes exception when trying to purchase a product that doesn't exist.

## 2.3.4

- Fixes permissions of install scripts
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ When it comes time to make a purchase, *Purchases* has a simple method, `makePur
```javascript
try {
const purchaseMade = await Purchases.makePurchase(entitlements.pro.monthly.identifier);
if (purchaseMade.purchaserInfo.activeEntitlements !== "undefined" && purchaseMade.purchaserInfo.activeEntitlements.includes("my_entitlement_identifier")) {
if (typeof purchaseMade.purchaserInfo.entitlements.active.my_entitlement_identifier !== "undefined") {
// Unlock that great "pro" content
}
} catch (e) {
Expand All @@ -144,12 +144,7 @@ try {
// Get purchaser info
try {
const purchaserInfo = await Purchases.getPurchaserInfo();
// Option 1: Check if user has access to entitlement (from RevenueCat dashboard)
if(purchaserInfo.activeEntitlements !== "undefined" && purchaserInfo.activeEntitlements.includes("my_entitlement_identifier")) {
// Grant user "pro" access
}
// Option 2: Check if user has active subscription (from App Store Connect or Play Store)
if (purchaserInfo.activeSubscriptions !== "undefined" && purchaserInfo.activeSubscriptions.includes("my_product_identifier")) {
if(typeof purchaserInfo.entitlements.active.my_entitlement_identifier !== "undefined") {
// Grant user "pro" access
}
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| Version | iOS version | Android version | Common files version |
|---------|-------------|-----------------|----------------------|
| 2.4.1 | 2.6.0 | 2.4.0 | 0.1.4 |
| 2.4.0 | 2.6.0 | 2.4.0 | 0.1.3 |
| 2.3.4 | 2.5.0 | 2.3.1 | 0.1.2 |
| 2.3.3 | 2.5.0 | 2.3.1 | 0.1.2 |
Expand Down
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (os.type() === "Linux") {
);
downloadProcess.stdout.pipe(process.stdout);
const downloadProcessCommon = exec(
"./scripts/download-purchases-common.sh 0.1.3"
"./scripts/download-purchases-common.sh 0.1.4"
);
downloadProcessCommon.stdout.pipe(process.stdout);
} else if (os.type() === "Windows_NT") {
Expand Down
79 changes: 53 additions & 26 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,68 @@ import InitialScreen from "./app/screens/InitialScreen";
import UpsellScreen from "./app/screens/UpsellScreen";
import CatsScreen from "./app/screens/CatsScreen";

const MainNavigator = createStackNavigator(
{
Initial: {
screen: InitialScreen,
navigationOptions: {
header: null
const createRootNavigator = (load = "<Your Initial Screen>") => {
return createStackNavigator(
{
Initial: {
screen: InitialScreen,
navigationOptions: {
header: null
}
},
Upsell: {
screen: UpsellScreen,
navigationOptions: {
header: null
}
},
Cats: {
screen: CatsScreen,
navigationOptions: {
header: null
}
}
},
Upsell: {
screen: UpsellScreen,
navigationOptions: {
header: null
}
},
Cats: {
screen: CatsScreen,
navigationOptions: {
header: null
}
{
initialRouteName: load
}
},
{
initialRouteName: "Initial"
}
);

const AppContainer = createAppContainer(MainNavigator);
);
};

export default class App extends React.Component {
componentWillMount() {
constructor() {
super();
this.state = {
load: "Initial"
};
}

async componentDidMount() {
Purchases.setDebugLogsEnabled(true);
Purchases.setup("my_api_key");
Purchases.setup("VtDdmbdWBySmqJeeQUTyrNxETUVkhuaJ", "cesarsandbox1");
try {
const purchaserInfo = await Purchases.getPurchaserInfo();
if (typeof purchaserInfo.entitlements.active.pro_cat !== "undefined") {
this.setState({
load: "Cats",
loading: false
});
} else {
this.setState({
load: "Upsell",
loading: false
});
}
} catch (e) {
// eslint-disable-next-line no-console
console.log(`Error ${JSON.stringify(e)}`);
}
}

render() {
const AppContainer = createAppContainer(
createRootNavigator(this.state.load)
);
return <AppContainer />;
}
}
6 changes: 2 additions & 4 deletions example/app/screens/CatsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class CatsScreen extends React.Component {
};
}

async componentWillMount() {
async componentDidMount() {
try {
const info = await Purchases.getPurchaserInfo();
this.handleInfo(info);
Expand All @@ -51,9 +51,7 @@ export default class CatsScreen extends React.Component {
}

handleInfo(info) {
const isPro =
info.activeEntitlements !== "undefined" &&
info.activeEntitlements.includes("pro_cat");
const isPro = typeof info.entitlements.active.pro_cat !== "undefined";
this.setState({
isPro,
purchaseDate: isPro
Expand Down
40 changes: 10 additions & 30 deletions example/app/screens/InitialScreen.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
import React from "react";
import Purchases from "react-native-purchases";
import { StackActions, NavigationActions } from "react-navigation";
import { SafeAreaView, ScrollView, View, Text } from "react-native";

export default class InitialScreen extends React.Component {
async componentDidMount() {
try {
const purchaserInfo = await Purchases.getPurchaserInfo();
if (
purchaserInfo.activeEntitlements !== "undefined" &&
purchaserInfo.activeEntitlements.includes("pro_cat")
) {
this.props.navigation.dispatch(
StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Cats" })]
})
);
} else {
this.props.navigation.dispatch(
StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Upsell" })]
})
);
}
} catch (e) {
// eslint-disable-next-line no-console
console.log(`Error ${JSON.stringify(e)}`);
}
}

render() {
return null;
return (
<SafeAreaView style={{ flex: 1, backgroundColor: "#fff" }}>
<ScrollView style={{ flex: 1 }}>
<View style={{ margin: 50, alignItems: "center" }}>
<Text style={{ fontSize: 20 }}>Loading</Text>
</View>
</ScrollView>
</SafeAreaView>
);
}
}
31 changes: 20 additions & 11 deletions example/app/screens/UpsellScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@ const styles = StyleSheet.create({
const makePurchase = navigation => async product => {
try {
const purchaseMade = await Purchases.makePurchase(product);
if (
purchaseMade.purchaserInfo.activeEntitlements !== "undefined" &&
purchaseMade.purchaserInfo.activeEntitlements.includes("pro_cat")
) {
navigation.dispatch(
StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Cats" })]
})
);
}
checkIfPro(purchaseMade.purchaserInfo, navigation);
} catch (e) {
if (!e.userCancelled) {
// eslint-disable-next-line no-console
Expand All @@ -57,6 +47,7 @@ const makePurchase = navigation => async product => {
};

export default class UpsellScreen extends React.Component {

constructor() {
super();
this.state = {
Expand All @@ -68,6 +59,10 @@ export default class UpsellScreen extends React.Component {

async componentDidMount() {
try {
this.purchaserInfoUpdateListener = (info) => {
checkIfPro(info, this.props.navigation);
};
Purchases.addPurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);
const entitlements = await Purchases.getEntitlements();
// eslint-disable-next-line no-console
console.log(JSON.stringify(entitlements));
Expand All @@ -86,6 +81,10 @@ export default class UpsellScreen extends React.Component {
}
}

async componentWillUnmount() {
Purchases.removePurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);
}

render() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: "#fff" }}>
Expand Down Expand Up @@ -126,3 +125,13 @@ export default class UpsellScreen extends React.Component {
);
}
}

function checkIfPro(purchaserInfo, navigation) {
if (typeof purchaserInfo.entitlements.active.pro_cat !== "undefined") {
navigation.dispatch(StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Cats" })]
}));
}
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-purchases",
"title": "React Native Purchases",
"version": "2.4.0",
"version": "2.4.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit fc8698e

Please sign in to comment.