mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 12:51:42 +03:00
Added puschase listeners
This commit is contained in:
parent
7db333212d
commit
7d1d955dec
@ -1,13 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { Platform, Alert } from 'react-native';
|
import { Platform, Alert } from 'react-native';
|
||||||
import RNIap, {
|
import RNIap, { purchaseErrorListener, purchaseUpdatedListener } from 'react-native-iap';
|
||||||
purchaseErrorListener,
|
|
||||||
purchaseUpdatedListener,
|
|
||||||
ProductPurchase,
|
|
||||||
PurchaseError,
|
|
||||||
} from 'react-native-iap';
|
|
||||||
// import { Alert } from 'react-native';
|
|
||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
|
|
||||||
// import { toastNotification } from '../../../redux/actions/uiAction';
|
// import { toastNotification } from '../../../redux/actions/uiAction';
|
||||||
@ -22,12 +16,6 @@ import { injectIntl } from 'react-intl';
|
|||||||
// Component
|
// Component
|
||||||
import BoostScreen from '../screen/boostScreen';
|
import BoostScreen from '../screen/boostScreen';
|
||||||
|
|
||||||
/*
|
|
||||||
* Props Name Description Value
|
|
||||||
*@props --> props name here description here Value Type Here
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
const ITEM_SKUS = Platform.select({
|
const ITEM_SKUS = Platform.select({
|
||||||
ios: ['099points', '199points', '499points', '999points', '4999points', '9999points'],
|
ios: ['099points', '199points', '499points', '999points', '4999points', '9999points'],
|
||||||
android: ['099points', '199points', '499points', '999points', '4999points', '9999points'],
|
android: ['099points', '199points', '499points', '999points', '4999points', '9999points'],
|
||||||
@ -37,31 +25,47 @@ class BoostContainer extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
receipt: '',
|
|
||||||
productList: [],
|
productList: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component Life Cycle Functions
|
// Component Life Cycle Functions
|
||||||
|
componentDidMount() {
|
||||||
|
this._getItems();
|
||||||
|
this._purchaseUpdatedListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
if (this.purchaseUpdateSubscription) {
|
||||||
|
this.purchaseUpdateSubscription.remove();
|
||||||
|
this.purchaseUpdateSubscription = null;
|
||||||
|
}
|
||||||
|
if (this.purchaseErrorSubscription) {
|
||||||
|
this.purchaseErrorSubscription.remove();
|
||||||
|
this.purchaseErrorSubscription = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
async componentDidMount() {
|
|
||||||
this._getItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
_getAvailablePurchases = async () => {
|
_purchaseUpdatedListener = () => {
|
||||||
try {
|
this.purchaseUpdateSubscription = purchaseUpdatedListener(purchase => {
|
||||||
const purchases = await RNIap.getAvailablePurchases();
|
console.log('purchaseUpdatedListener', purchase);
|
||||||
console.info('Available purchases :: ', purchases);
|
const receipt = purchase.transactionReceipt;
|
||||||
if (purchases && purchases.length > 0) {
|
if (receipt) {
|
||||||
this.setState({
|
// yourAPI.deliverOrDownloadFancyInAppPurchase(receipt).then(deliveryResult => {
|
||||||
receipt: purchases[0].transactionReceipt,
|
// if (Platform.OS === 'ios') {
|
||||||
|
// RNIap.finishTransactionIOS(purchase.transactionId);
|
||||||
|
// } else if (Platform.OS === 'android') {
|
||||||
|
// RNIap.consumePurchaseAndroid(purchase.purchaseToken);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.purchaseErrorSubscription = purchaseErrorListener(error => {
|
||||||
|
Alert.alert('Warning', error);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(err.code, err.message);
|
|
||||||
Alert.alert(err.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_getItems = async () => {
|
_getItems = async () => {
|
||||||
@ -83,25 +87,6 @@ class BoostContainer extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// _buyItem = async sku => {
|
|
||||||
// console.info('buyItem', sku);
|
|
||||||
// // const purchase = await RNIap.buyProduct(sku);
|
|
||||||
// // const products = await RNIap.buySubscription(sku);
|
|
||||||
// // const purchase = await RNIap.buyProductWithoutFinishTransaction(sku);
|
|
||||||
// try {
|
|
||||||
// const purchase = await RNIap.buyProduct(sku);
|
|
||||||
// // console.log('purchase', purchase);
|
|
||||||
// // await RNIap.consumePurchaseAndroid(purchase.purchaseToken);
|
|
||||||
// this.setState({ receipt: purchase.transactionReceipt }, () => this.goNext());
|
|
||||||
// } catch (err) {
|
|
||||||
// console.warn(err.code, err.message);
|
|
||||||
// const subscription = RNIap.addAdditionalSuccessPurchaseListenerIOS(async purchase => {
|
|
||||||
// this.setState({ receipt: purchase.transactionReceipt }, () => this.goNext());
|
|
||||||
// subscription.remove();
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { productList } = this.state;
|
const { productList } = this.state;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user