跑通当前mini提交创建订单后,调用微信小程序支付,支付回调,更新订单状态。订单支付成功后,在min订单列表进入订单详情,点击取消订单后,可以取消订单并调用微信支付sdk退款,最后更新订单状态。
Current relevant functionality:
Technology stack:
Integration points:
What's being added/changed:
How it integrates:
Success criteria:
Story 1: 完善支付回调处理逻辑 - 确保支付回调正确更新订单状态,支持多租户隔离
Story 2: 实现订单取消功能 - 支持已支付订单的取消和退款流程
Story 3: 集成微信支付退款功能 - 调用微信支付SDK实现退款
Story 4: 优化订单状态流转和退款记录 - 完善订单状态管理和退款跟踪
Primary Risk: 退款功能可能影响现有支付流程的稳定性
Mitigation: 分阶段实施,先完善支付回调,再实现退款功能
Rollback Plan: 如果出现问题,可以暂时禁用退款功能,保持现有支付流程正常工作
// 支付回调接口
app.post('/api/payment/callback', async (c) => {
const { tenantId } = c.get('tenant');
const notification = await validateWechatPaymentNotification(c.req.raw);
// 更新订单状态
await orderService.updateOrderPaymentStatus(
tenantId,
notification.out_trade_no,
'paid',
{
paymentTime: new Date(),
transactionId: notification.transaction_id,
totalFee: notification.total_fee
}
);
return c.text('<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>');
});
// 订单取消服务
class OrderService {
async cancelOrder(tenantId: number, orderId: number, reason: string) {
const order = await this.getOrder(tenantId, orderId);
if (order.status === 'paid') {
// 触发退款
const refundResult = await paymentService.refund(
tenantId,
order.transactionId,
order.totalAmount,
order.outTradeNo
);
// 更新订单状态和退款记录
await this.updateOrderStatus(tenantId, orderId, 'cancelled', {
cancelReason: reason,
refundTransactionId: refundResult.refund_id
});
} else {
// 直接取消未支付订单
await this.updateOrderStatus(tenantId, orderId, 'cancelled', {
cancelReason: reason
});
}
}
}
@Entity('order_refund')
export class OrderRefund {
@PrimaryGeneratedColumn()
id!: number;
@Column()
tenantId!: number;
@Column()
orderId!: number;
@Column()
refundAmount!: number;
@Column()
refundStatus!: 'pending' | 'success' | 'failed';
@Column()
refundTransactionId?: string;
@Column()
refundReason?: string;
@Column()
createdAt!: Date;
@Column()
updatedAt!: Date;
}
Story Manager Handoff:
"请为这个棕地史诗开发详细的用户故事。关键考虑因素:
该史诗应在保持系统完整性的同时交付完整的支付退款流程功能。"