회원목록

This commit is contained in:
2025-08-01 16:45:26 +09:00
parent a996def67a
commit ed8c7eacba
191 changed files with 17491 additions and 0 deletions
@@ -685,3 +685,141 @@ exports.getPlanSubscriptions = async (req, res) => {
res.status(500).json({ message: '플랜별 구독 목록 조회 중 오류가 발생했습니다.' });
}
};
// 인앱 결제 영수증 검증
exports.verifyReceipt = async (req, res) => {
try {
const { receipt, transactionId, productId, platform } = req.body;
const userId = req.user.id;
const clubId = req.body.clubId;
if (!receipt) {
return res.status(400).json({ message: '영수증 데이터가 없습니다.' });
}
// 플랫폼별 검증 로직
let verificationResult = false;
let purchaseData = {};
if (platform === 'ios') {
// iOS 영수증 검증
verificationResult = await verifyIosReceipt(receipt);
purchaseData = {
platform: 'ios',
transactionId,
productId,
receipt
};
} else if (platform === 'android') {
// Android 영수증 검증
verificationResult = await verifyAndroidReceipt(receipt, productId);
purchaseData = {
platform: 'android',
transactionId,
productId,
receipt
};
} else {
return res.status(400).json({ message: '지원하지 않는 플랫폼입니다.' });
}
if (!verificationResult) {
return res.status(400).json({ message: '영수증 검증에 실패했습니다.' });
}
// 구독 플랜 타입 확인
const planType = getPlanTypeFromProductId(productId);
if (!planType) {
return res.status(400).json({ message: '유효하지 않은 상품 ID입니다.' });
}
// 해당 플랜 정보 가져오기
const plan = await SubscriptionPlan.findOne({
where: { type: planType }
});
if (!plan) {
return res.status(404).json({ message: '해당 플랜을 찾을 수 없습니다.' });
}
// 기존 구독 정보 확인
let subscription = await ClubSubscription.findOne({
where: { clubId }
});
// 구독 생성 또는 업데이트
const startDate = new Date();
const endDate = new Date();
endDate.setMonth(endDate.getMonth() + 1); // 기본 1개월 구독
if (subscription) {
// 기존 구독 업데이트
await subscription.update({
planId: plan.id,
status: 'active',
startDate,
endDate,
lastPaymentDate: startDate,
transactionId,
receiptData: JSON.stringify(purchaseData)
});
} else {
// 새 구독 생성
subscription = await ClubSubscription.create({
clubId,
planId: plan.id,
status: 'active',
startDate,
endDate,
lastPaymentDate: startDate,
transactionId,
receiptData: JSON.stringify(purchaseData)
});
}
// 검증 결과 및 구독 정보 반환
res.json({
success: true,
message: '영수증 검증 및 구독 처리가 완료되었습니다.',
subscription: {
id: subscription.id,
planId: subscription.planId,
planType: planType,
status: subscription.status,
startDate: subscription.startDate,
endDate: subscription.endDate,
lastPaymentDate: subscription.lastPaymentDate
}
});
} catch (error) {
console.error('Error in verifyReceipt:', error);
res.status(500).json({ message: '영수증 검증 중 오류가 발생했습니다.' });
}
};
// iOS 영수증 검증 함수 (실제 구현에서는 Apple 서버와 통신 필요)
async function verifyIosReceipt(receipt) {
// 실제 구현에서는 Apple 서버에 영수증 검증 요청
// 테스트를 위해 현재는 항상 true 반환
return true;
}
// Android 영수증 검증 함수 (실제 구현에서는 Google Play API와 통신 필요)
async function verifyAndroidReceipt(receipt, productId) {
// 실제 구현에서는 Google Play API를 통해 영수증 검증
// 테스트를 위해 현재는 항상 true 반환
return true;
}
// 상품 ID에서 플랜 타입 추출
function getPlanTypeFromProductId(productId) {
if (productId.includes('basic')) {
return 'basic';
} else if (productId.includes('premium')) {
return 'premium';
} else if (productId.includes('pro')) {
return 'pro';
}
return null;
}