From 483a5e0beaf61bb8928b3c33df8702923eb801ad Mon Sep 17 00:00:00 2001 From: jinyaqiu Date: Tue, 29 Jul 2025 14:28:10 +0800 Subject: [PATCH] feat: apple --- app/(tabs)/rights.tsx | 51 +++++++++++------------------ components/owner/rights/premium.tsx | 7 ++-- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/app/(tabs)/rights.tsx b/app/(tabs)/rights.tsx index 1fb9eda..9a78980 100644 --- a/app/(tabs)/rights.tsx +++ b/app/(tabs)/rights.tsx @@ -8,7 +8,7 @@ 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, getAvailablePurchases, getPurchaseHistories, ProductPurchase, useIAP } from 'expo-iap'; +import { ErrorCode, getPurchaseHistories, useIAP } from 'expo-iap'; import { useLocalSearchParams, useRouter } from "expo-router"; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -21,14 +21,8 @@ export default function Rights() { const { t } = useTranslation(); const { connected, - products, - subscriptions, - currentPurchase, - currentPurchaseError, requestProducts, requestPurchase, - finishTransaction, - validateReceipt, } = useIAP(); // 用户勾选协议 const [agree, setAgree] = useState(false); @@ -66,19 +60,19 @@ export default function Rights() { }; // 恢复购买 - const restorePurchases = async () => { - try { - const purchases = await getAvailablePurchases(); - console.log('Available purchases:', purchases); - // Process and validate restored purchases - for (const purchase of purchases) { - await validateAndGrantPurchase(purchase); - } - alert(t('personal:rights.restoreSuccess')); - } catch (error) { - console.error('Restore failed:', error); - } - }; + // const restorePurchases = async () => { + // try { + // const purchases = await getAvailablePurchases(); + // console.log('Available purchases:', purchases); + // // Process and validate restored purchases + // for (const purchase of purchases) { + // await validateAndGrantPurchase(purchase); + // } + // alert(t('personal:rights.restoreSuccess')); + // } catch (error) { + // console.error('Restore failed:', error); + // } + // }; // 处理购买 const handlePurchase = async (sku: string, transaction_id: string) => { @@ -88,15 +82,13 @@ export default function Rights() { const res = await requestPurchase({ request: { ios: { - sku: payType, + sku: sku, andDangerouslyFinishTransactionAutomaticallyIOS: false, }, }, }); - console.log('Purchase success:', res); - - // 支付成功 - await paySuccess(transaction_id, res?.transactionId || "") + // 支付成功 + await paySuccess(res?.transaction_id || "", "2000000971679717") } catch (error: any) { console.log('Purchase failed:', error); // 支付失败 @@ -248,7 +240,7 @@ export default function Rights() { {/* 普通权益 */} {/* 会员权益 */} - + {/* 支付方式 */} {/* */} @@ -306,7 +298,7 @@ export default function Rights() { {/* 协议弹窗 */} - + ); } @@ -454,7 +446,4 @@ const styles = StyleSheet.create({ color: '#4C320C', lineHeight: 32 } -}); -function validateAndGrantPurchase(purchase: ProductPurchase) { - throw new Error('Function not implemented.'); -} +}); \ No newline at end of file diff --git a/components/owner/rights/premium.tsx b/components/owner/rights/premium.tsx index 2a64dcc..6492705 100644 --- a/components/owner/rights/premium.tsx +++ b/components/owner/rights/premium.tsx @@ -11,7 +11,6 @@ interface Props { premiumPay: any; loading: boolean; setShowTerms: (visible: boolean) => void; - restorePurchases: () => void; } export interface PayItem { @@ -31,7 +30,7 @@ export interface PayItem { } const Premium = (props: Props) => { - const { style, payType, setPayType, premiumPay, loading, setShowTerms, restorePurchases } = props; + const { style, payType, setPayType, premiumPay, loading } = props; const bestValue = maxDiscountProduct(premiumPay)?.product_code const { t } = useTranslation(); @@ -80,7 +79,7 @@ const Premium = (props: Props) => { }) } - + {/* {t('personal:rights.restorePurchase')} @@ -89,7 +88,7 @@ const Premium = (props: Props) => { {t('personal:rights.restore')} - + */} ); }