|
|
@@ -10,6 +10,8 @@ import { ColorType } from "@/context/themes/color";
|
|
|
import { payInfo } from "@/services/user";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
import showAlert from "@/components/basic/Alert";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
+import { AtActivityIndicator } from "taro-ui";
|
|
|
|
|
|
let useNavigation, TouchableOpacity;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
@@ -23,6 +25,7 @@ export default function ProductList() {
|
|
|
// - State for displaying an overlay view
|
|
|
const [isPurchasing, setIsPurchasing] = useState(false);
|
|
|
const [errorCode, setErrorCode] = useState<any>(-1)
|
|
|
+ const { t } = useTranslation()
|
|
|
|
|
|
let navigation;
|
|
|
if (useNavigation) {
|
|
|
@@ -33,21 +36,21 @@ export default function ProductList() {
|
|
|
if (navigation) {
|
|
|
navigation.setOptions({
|
|
|
gestureEnabled: !isPurchasing,
|
|
|
- headerLeft: () => (<TouchableOpacity activeOpacity={1} style={{ marginLeft: 5, padding: 5 }} onPress={() => {
|
|
|
- if (!isPurchasing) {
|
|
|
- navigation.goBack()
|
|
|
- }
|
|
|
- else {
|
|
|
- showAlert({
|
|
|
- title: '支付进行中',
|
|
|
- content: '禁止返回',
|
|
|
- showCancel: false
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- }}>
|
|
|
- <Image style={{ width: 30, height: 30 }} src={require('@/assets/images/navi_back.png')} />
|
|
|
- </TouchableOpacity>),
|
|
|
+ // headerLeft: () => (<TouchableOpacity activeOpacity={1} style={{ marginLeft: 5, padding: 5 }} onPress={() => {
|
|
|
+ // if (!isPurchasing) {
|
|
|
+ // navigation.goBack()
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // showAlert({
|
|
|
+ // title: '支付进行中',
|
|
|
+ // content: '禁止返回',
|
|
|
+ // showCancel: false
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }}>
|
|
|
+ // <Image style={{ width: 30, height: 30 }} src={require('@/assets/images/navi_back.png')} />
|
|
|
+ // </TouchableOpacity>),
|
|
|
});
|
|
|
}
|
|
|
}, [isPurchasing])
|
|
|
@@ -82,7 +85,7 @@ export default function ProductList() {
|
|
|
const offerings = await Purchases.getOfferings();
|
|
|
console.log('product list offerings', offerings)
|
|
|
console.log('product list detail', (offerings as any).current.availablePackages[1])
|
|
|
- console.log('dddd',JSON.stringify(offerings))
|
|
|
+ console.log('dddd', JSON.stringify(offerings))
|
|
|
|
|
|
if (offerings.current !== null && offerings.current.availablePackages.length !== 0) {
|
|
|
setPackages((offerings as any).current.availablePackages);
|
|
|
@@ -92,19 +95,6 @@ export default function ProductList() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- async function hi() {
|
|
|
- try {
|
|
|
- // 启动购买流程
|
|
|
- const purchaseResult = await Purchases.purchaseProduct('pro_lifelong_test');
|
|
|
- console.log(purchaseResult);
|
|
|
- // 检查购买是否成功
|
|
|
- // setIsSubscribed(purchaseResult.purchaserInfo.activeSubscriptions.length > 0);
|
|
|
- } catch (error) {
|
|
|
- console.error('Purchase error:', error);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
async function pay(item: any) {
|
|
|
setIsPurchasing(true);
|
|
|
try {
|
|
|
@@ -113,8 +103,8 @@ export default function ProductList() {
|
|
|
customerInfo,
|
|
|
productIdentifier,
|
|
|
transaction,
|
|
|
- store:kIsIOS?'app_store':'play_store',
|
|
|
- storeProductIdentifier:item.product.identifier //后端要求额外传入商品id,用于同步数据,区别于productIdentifier
|
|
|
+ store: kIsIOS ? 'app_store' : 'play_store',
|
|
|
+ storeProductIdentifier: item.product.identifier //后端要求额外传入商品id,用于同步数据,区别于productIdentifier
|
|
|
}).then(res => {
|
|
|
global.paySuccess(res)
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
@@ -128,7 +118,10 @@ export default function ProductList() {
|
|
|
});
|
|
|
console.log('result', customerInfo)
|
|
|
} catch (e) {
|
|
|
- debugger
|
|
|
+ if (e.code === Purchases.PURCHASES_ERROR_CODE.NETWORK_ERROR) {
|
|
|
+ pay(item)
|
|
|
+ return;
|
|
|
+ }
|
|
|
setErrorCode(e.code)
|
|
|
if (e.code === Purchases.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR) {
|
|
|
|
|
|
@@ -138,7 +131,7 @@ export default function ProductList() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return <View>
|
|
|
+ return <View style={{flex:1,position:'relative'}}>
|
|
|
<View style={{ height: 40 }} />
|
|
|
{
|
|
|
packages.map((item, index) => {
|
|
|
@@ -169,10 +162,16 @@ export default function ProductList() {
|
|
|
/> */}
|
|
|
|
|
|
{
|
|
|
- isPurchasing && <Text style={{ color: '#fff', fontSize: 40 }}>正在付款</Text>
|
|
|
+ isPurchasing && <View className="pop_loading_bg">
|
|
|
+ <View className="pop_loading">
|
|
|
+ <AtActivityIndicator size={40} color="#fff" />
|
|
|
+ <Text className="pop_loading_title">{t('feature.pay.paying_title')}</Text>
|
|
|
+ <Text className="pop_loading_desc">{t('feature.pay.paying_desc')}</Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
}
|
|
|
- {
|
|
|
+ {/* {
|
|
|
errorCode != -1 && <Text style={{ color: '#fff', fontSize: 40 }}>出错了,错误代码{errorCode}</Text>
|
|
|
- }
|
|
|
+ } */}
|
|
|
</View>
|
|
|
}
|