56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
const axios = require('axios');
|
|
|
|
// API基础URL - 使用正确的端口
|
|
const API_BASE_URL = 'http://localhost:3001/api';
|
|
|
|
console.log('开始测试现金支付流程...');
|
|
|
|
// 测试数据
|
|
const orderData = {
|
|
items: [
|
|
{
|
|
product_id: 1,
|
|
quantity: 2
|
|
}
|
|
],
|
|
payment_method: 'cash',
|
|
paid_amount: 10,
|
|
cashier_id: 1
|
|
};
|
|
|
|
console.log('准备创建订单:', orderData);
|
|
|
|
// 创建订单
|
|
axios.post(`${API_BASE_URL}/orders`, orderData)
|
|
.then(response => {
|
|
console.log('订单创建成功:', response.data);
|
|
|
|
// 检查响应数据
|
|
if (response.data && response.data.id) {
|
|
console.log(`订单ID: ${response.data.id}`);
|
|
console.log(`订单总额: ${response.data.total_amount}`);
|
|
console.log(`支付方式: ${response.data.payment_method}`);
|
|
|
|
console.log('现金支付测试完成');
|
|
} else {
|
|
console.error('订单创建响应格式不正确:', response.data);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('订单创建失败:');
|
|
|
|
if (error.response) {
|
|
// 服务器响应了错误状态码
|
|
console.error('错误状态:', error.response.status);
|
|
console.error('错误数据:', error.response.data);
|
|
console.error('响应头:', error.response.headers);
|
|
} else if (error.request) {
|
|
// 请求已发出但没有收到响应
|
|
console.error('无响应:', error.request);
|
|
} else {
|
|
// 其他错误
|
|
console.error('错误信息:', error.message);
|
|
}
|
|
|
|
console.error('错误配置:', error.config);
|
|
}); |