DateP
구독 갱신 로직 android 에러 수정
Solo.dev
2025. 4. 28. 01:04
구독 로직 수정 요약
프로젝트 개요
- 프로젝트: 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에 데이터 저장. - 예상:
isSubscribedtrue, 구독 성공 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설정 확인.