61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
const axios = require('axios');
|
||
|
||
// 使用服务器实际运行的端口(根据netstat检查结果,服务器在3000端口运行)
|
||
const API_BASE_URL = 'http://localhost:3000/api';
|
||
|
||
// 模拟现金支付的订单数据
|
||
const orderData = {
|
||
items: [
|
||
{
|
||
product_id: 1,
|
||
quantity: 2,
|
||
price: 10.00
|
||
}
|
||
],
|
||
total_amount: 20.00,
|
||
payment_method: 'cash',
|
||
received_amount: 25.00,
|
||
change: 5.00
|
||
};
|
||
|
||
async function testCashPayment() {
|
||
console.log('开始测试现金支付流程...');
|
||
|
||
try {
|
||
// 发送创建订单请求
|
||
console.log('正在发送现金支付订单请求...');
|
||
console.log('请求URL:', `${API_BASE_URL}/orders`);
|
||
console.log('请求数据:', JSON.stringify(orderData, null, 2));
|
||
|
||
const response = await axios.post(`${API_BASE_URL}/orders`, orderData);
|
||
|
||
console.log('订单创建成功:');
|
||
console.log('订单ID:', response.data.id);
|
||
console.log('订单总额:', response.data.total_amount);
|
||
console.log('支付方式:', response.data.payment_method);
|
||
|
||
console.log('\n请检查钱箱是否已打开。如果钱箱正常打开,说明功能工作正常。');
|
||
console.log('如果钱箱未打开,请检查以下几点:');
|
||
console.log('1. 钱箱是否正确连接到电脑');
|
||
console.log('2. 钱箱连接的串口是否正确配置');
|
||
console.log('3. 钱箱是否处于可用状态');
|
||
|
||
} catch (error) {
|
||
console.error('测试过程中出现错误:');
|
||
console.error('错误类型:', error.constructor.name);
|
||
|
||
if (error.response) {
|
||
console.error('状态码:', error.response.status);
|
||
console.error('响应头:', JSON.stringify(error.response.headers, null, 2));
|
||
console.error('响应数据:', JSON.stringify(error.response.data, null, 2));
|
||
} else if (error.request) {
|
||
console.error('请求信息:', error.request);
|
||
console.error('请检查服务器是否正在运行');
|
||
} else {
|
||
console.error('错误信息:', error.message);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 运行测试
|
||
testCashPayment(); |