feat: 处理web端expoiap报错问题
This commit is contained in:
parent
7b7c39ce36
commit
fbb71aa36d
@ -8,12 +8,25 @@ import ProRights from '@/components/owner/rights/proRights';
|
||||
import { createOrder, createPayment, getPAy, isOrderExpired, payFailure, payProcessing, paySuccess } from '@/components/owner/rights/utils';
|
||||
import { ThemedText } from '@/components/ThemedText';
|
||||
import { CreateOrder } from '@/types/personal-info';
|
||||
import { ErrorCode, getPurchaseHistories, useIAP } from 'expo-iap';
|
||||
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ActivityIndicator, Image, ScrollView, StyleSheet, TouchableOpacity, View } from 'react-native';
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { ActivityIndicator, Image, Platform, ScrollView, StyleSheet, TouchableOpacity, View } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
|
||||
// 根据平台动态导入 expo-iap
|
||||
let useIAP: any, requestPurchase: any, getPurchaseHistories: any;
|
||||
if (Platform.OS !== 'web') {
|
||||
const iap = require('expo-iap');
|
||||
useIAP = iap.useIAP;
|
||||
requestPurchase = iap.requestPurchase;
|
||||
getPurchaseHistories = iap.getPurchaseHistories;
|
||||
} else {
|
||||
// 为 Web 端提供 mock 实现
|
||||
useIAP = () => ({ connected: false });
|
||||
requestPurchase = async () => { console.log('IAP is not available on web.'); };
|
||||
getPurchaseHistories = async () => [];
|
||||
}
|
||||
|
||||
export default function Rights() {
|
||||
const insets = useSafeAreaInsets();
|
||||
@ -22,19 +35,18 @@ export default function Rights() {
|
||||
const {
|
||||
connected,
|
||||
requestProducts,
|
||||
requestPurchase,
|
||||
ErrorCode
|
||||
} = useIAP();
|
||||
const { pro } = useLocalSearchParams<{
|
||||
credit: string;
|
||||
pro: string;
|
||||
}>();
|
||||
// 用户勾选协议
|
||||
const [agree, setAgree] = useState<boolean>(false);
|
||||
// 用户选择购买的loading
|
||||
const [confirmLoading, setConfirmLoading] = useState<boolean>(false);
|
||||
// 选择购买方式
|
||||
const [payChoice, setPayChoice] = useState<'ApplePay'>('ApplePay');
|
||||
// 获取路由参数
|
||||
const { credit, pro } = useLocalSearchParams<{
|
||||
credit: string;
|
||||
pro: string;
|
||||
}>();
|
||||
// 普通用户,会员
|
||||
const [userType, setUserType] = useState<'normal' | 'premium'>('normal');
|
||||
|
||||
@ -88,7 +100,7 @@ export default function Rights() {
|
||||
},
|
||||
});
|
||||
// 支付成功
|
||||
await paySuccess(res?.transaction_id || "", "2000000971679717")
|
||||
await paySuccess(transaction_id, res?.transaction_id || "")
|
||||
} catch (error: any) {
|
||||
console.log('Purchase failed:', error);
|
||||
// 支付失败
|
||||
@ -214,7 +226,7 @@ export default function Rights() {
|
||||
</ThemedText>
|
||||
<View style={styles.cardPoints}>
|
||||
<StarSvg />
|
||||
<ThemedText style={styles.cardPointsText}>{credit}</ThemedText>
|
||||
<ThemedText style={styles.cardPointsText}>{pro}</ThemedText>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user