const axios = require('axios');

async function testFrontendPayload() {
  // Simulate the exact payload sent from CheckoutPage.tsx AutoSnapPayment
  const payload = {
    transaction_details: {
      order_id: 'order-1733280000000-12345', // example orderId
      gross_amount: 3500000
    },
    customer_details: {
      first_name: 'Demo User',
      email: 'demo@example.com',
      phone: undefined // as sent from frontend when contact is email
    },
    item_details: [{
      id: 'order-1733280000000-12345',
      name: 'Payment',
      price: 3500000,
      quantity: 1
    }]
  };

  try {
    console.log('Testing frontend-like payload...');
    console.log('Payload:', JSON.stringify(payload, null, 2));

    const response = await axios.post('http://localhost:8000/api/payments/snap/token', payload);
    console.log('Success:', response.data);
  } catch (error) {
    console.log('Error:', error.response?.status, error.response?.data);
    console.log('Full error:', error.message);
  }
}

testFrontendPayload();