|
@@ -110,40 +110,39 @@ export class PaymentService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async handlePaymentNotify(params: PaymentNotifyParams): Promise<void> {
|
|
async handlePaymentNotify(params: PaymentNotifyParams): Promise<void> {
|
|
|
- try {
|
|
|
|
|
- if (!this.verifyNotifySign(params)) {
|
|
|
|
|
- throw new Error('Verify notify sign failed')
|
|
|
|
|
|
|
+ if (!this.verifyNotifySign(params)) {
|
|
|
|
|
+ throw new Error('Verify notify sign failed')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (params.trade_status === 'TRADE_SUCCESS') {
|
|
|
|
|
+ this.app.log.info('Payment success, start processing')
|
|
|
|
|
+
|
|
|
|
|
+ const incomeRecord = await this.incomeRecordsService.findByOrderNo(params.trade_no)
|
|
|
|
|
+ if (!incomeRecord) {
|
|
|
|
|
+ throw new Error('Failed to find corresponding income record')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (params.trade_status === 'TRADE_SUCCESS') {
|
|
|
|
|
- this.app.log.info('Payment success, out_trade_no: ' + params.out_trade_no)
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- const incomeRecord = await this.incomeRecordsService.findByOrderNo(params.out_trade_no)
|
|
|
|
|
- if (incomeRecord) {
|
|
|
|
|
- // 更新收入记录状态
|
|
|
|
|
- await this.incomeRecordsService.update({
|
|
|
|
|
- id: incomeRecord.id,
|
|
|
|
|
- status: true
|
|
|
|
|
- })
|
|
|
|
|
- this.app.log.info('Updated income record status success', incomeRecord.id)
|
|
|
|
|
-
|
|
|
|
|
- // 更新会员等级
|
|
|
|
|
- await this.memberService.updateVipLevel(
|
|
|
|
|
- incomeRecord.userId,
|
|
|
|
|
- this.getVipLevelByOrderType(incomeRecord.orderType)
|
|
|
|
|
- )
|
|
|
|
|
- this.app.log.info('Updated member level success', incomeRecord.userId)
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- this.app.log.error('Failed to process payment success:', error)
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- this.app.log.warn('Payment failed, out_trade_no: ' + params.out_trade_no + ', trade_no: ' + params.trade_no)
|
|
|
|
|
|
|
+ await this.incomeRecordsService.update({
|
|
|
|
|
+ id: incomeRecord.id,
|
|
|
|
|
+ status: true
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 更新会员等级
|
|
|
|
|
+ const vipLevel = this.getVipLevelByOrderType(incomeRecord.orderType)
|
|
|
|
|
+
|
|
|
|
|
+ const member = await this.memberService.findByUserId(incomeRecord.userId)
|
|
|
|
|
+ if (!member) {
|
|
|
|
|
+ throw new Error('Failed to find corresponding member record')
|
|
|
}
|
|
}
|
|
|
- } catch (error) {
|
|
|
|
|
- this.app.log.error('Failed to handle payment notification:', error)
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ await this.memberService.updateVipLevel(member.id, vipLevel)
|
|
|
|
|
+ this.app.log.info('Member level updated successfully')
|
|
|
|
|
+ this.app.log.info('Payment processing completed')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.app.log.warn('支付失败', {
|
|
|
|
|
+ out_trade_no: params.out_trade_no,
|
|
|
|
|
+ trade_status: params.trade_status
|
|
|
|
|
+ })
|
|
|
|
|
+ throw new Error('支付失败')
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -175,15 +174,16 @@ export class PaymentService {
|
|
|
pid: Number(this.pid),
|
|
pid: Number(this.pid),
|
|
|
type: 'alipay',
|
|
type: 'alipay',
|
|
|
out_trade_no,
|
|
out_trade_no,
|
|
|
- notify_url: `http://${this.app.config.HOST}:${this.app.config.PORT}/payment/notify`,
|
|
|
|
|
- return_url: `https://www.baidu.com/`,
|
|
|
|
|
|
|
+ notify_url: `https://9g15.vip/api/payment/notify`,
|
|
|
|
|
+ return_url: `https://yz1df.cc/account`,
|
|
|
name: `${params.type} 订单`,
|
|
name: `${params.type} 订单`,
|
|
|
money: price,
|
|
money: price,
|
|
|
client_ip: params.ip
|
|
client_ip: params.ip
|
|
|
}
|
|
}
|
|
|
|
|
+ console.log('paymentParams:', paymentParams)
|
|
|
|
|
|
|
|
const result = await this.createOrder(paymentParams)
|
|
const result = await this.createOrder(paymentParams)
|
|
|
- console.log(result)
|
|
|
|
|
|
|
+ console.log('result:', result)
|
|
|
|
|
|
|
|
// 创建收入记录
|
|
// 创建收入记录
|
|
|
try {
|
|
try {
|
|
@@ -222,7 +222,7 @@ export class PaymentService {
|
|
|
})
|
|
})
|
|
|
} catch (incomeError) {
|
|
} catch (incomeError) {
|
|
|
this.app.log.error('Failed to create income record:', incomeError)
|
|
this.app.log.error('Failed to create income record:', incomeError)
|
|
|
- throw new Error('创建记录失败')
|
|
|
|
|
|
|
+ throw new Error('Failed to create income record')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|