구독 로직 수정 요약
구독 로직 수정 요약
프로젝트 개요
- 프로젝트: DateP
- 문제:
startPurchase에서 다중 offerToken 전달로 E_DEVELOPER_ERROR 발생.
- 목표: 단일
offerToken 선택, 갱신 로직 안정성 강화.
startPurchase 함수 수정
- 문제: 모든
offerToken 전달로 Google Play Billing 오류.
- 수정: 단일
offerToken 선택.
- 로그:
subscriptionOffers와 오류 상세 출력 추가.
- UX:
E_DEVELOPER_ERROR 시 재시도 버튼 추가.
const selectedOfferToken = offerTokenToPlanMap
? Object.keys(offerTokenToPlanMap).find(token => offerTokenToPlanMap[token] === plan)
: null;
if (Platform.OS === 'android' && !selectedOfferToken) {
console.error('❌ 선택된 플랜에 해당하는 offerToken 없음:', plan);
throw new Error('No valid offerToken found for the selected plan');
}
const subscriptionOffers = selectedOfferToken
? [{ sku: targetProductId, offerToken: selectedOfferToken }]
: [];
console.log('전달된 subscriptionOffers:', JSON.stringify(subscriptionOffers, null, 2));
const purchase = await RNIap.requestSubscription({
sku: targetProductId,
...(Platform.OS === 'android' && selectedOfferToken ? { subscriptionOffers } : {}),
});
checkSubscriptionStatus 함수 수정
- 문제:
offerToken 매핑 실패 시 free 플랜 전환 가능성.
- 수정:
offerTokenToPlanMap으로 플랜 복구, 실패 시 free 폴백.
- 로그:
offerTokenToPlanMap과 복구 결과 출력 추가.
if (Platform.OS === 'android') {
if (subscription) {
currentPlan = subscription.plan;
limit = subscription.limit;
console.log('✅ Firebase DB 기준으로 구독 정보 복구:', currentPlan);
} else if (activePurchase.purchaseToken) {
const { offerTokenToPlanMap } = await getSubscriptionDetails(activePurchase.productId, 'basic');
console.log('offerTokenToPlanMap for recovery:', JSON.stringify(offerTokenToPlanMap, null, 2));
currentPlan = offerTokenToPlanMap[activePurchase.purchaseToken] || 'free';
limit = currentPlan === 'basic' ? 50 : currentPlan === 'premium' ? 100 : 1;
console.log('✅ offerToken 매핑으로 plan 복구:', currentPlan);
} else {
console.warn('⚠️ purchaseToken 없음, free plan으로 설정');
currentPlan = 'free';
limit = 1;
}
}
테스트 시나리오
테스트 계획
- 시나리오 1: Google Play 결제 성공, Firebase DB 저장 성공
- 확인:
basic과 premium 플랜 구매 후 Firebase에 데이터 저장.
- 예상:
isSubscribed true, 구독 성공 Alert.
- 시나리오 2: Google Play 결제 성공, Firebase DB 저장 실패
- 확인: 네트워크 오류 시
set 호출 실패, 오류 로그 출력.
- 예상:
PurchaseResult에서 valid: false, 사용자에게 오류 Alert.
- 시나리오 3: Google Play 결제 실패, Firebase DB 저장 없음
- 확인:
offerToken 매핑 실패 또는 결제 취소 시 동작.
- 예상:
E_DEVELOPER_ERROR 또는 E_USER_CANCELED, free 플랜 반환.
개선 제안
- Firebase 저장: 저장 실패 시 재시도 로직 추가.
- 만료 판단: 월 단위 대신 명시적
expiryDate 사용.
- 검증: Google Play Console에서
basePlanId와 offerToken 설정 확인.