import axios from "axios";

/**
 * 9PSB Webhook Test Script
 * This script simulates a successful 9PSB transfer notification to the Airpero sandbox server.
 */

const WEBHOOK_URL = "https://sandbox.v1.airpero.com/api/v1/webhooks/9psb";

const payload = {
  "Hash": "A31021D28E212A0D95AC378938F8B6A3CFE102D939BA3CB077D210FD8A426E6208E1FCF4D5558B1B054D09BBFB7D2A91BFFE467395CA3DF13B08ED5AEAC66FEC",
  "transaction": {
    "reference": "CUST-VA-a2660622",
    "sessionid": "100004260401162601156125796185",
    "date": "2026-04-01T17:26:16"
  },
  "customer": {
    "account": {
      "name": "AIRPERO/DAVID OLARINDE",
      "number": "6400001252",
      "bank": "120001",
      "senderbankcode": "100004",
      "senderbankname": "Opay Digital Services",
      "senderaccountnumber": "7055989199",
      "sendername": "JOSEPH ADELEKE ADEDIRAN"
    }
  },
  "order": {
    "amount": "50000",
    "currency": "NGN",
    "description": "Transfer from JOSEPH ADELEKE ADEDIRAN"
  },
  "message": "Success",
  "code": "00"
};

async function sendWebhook() {
  try {
    console.log(`🚀 Sending webhook to ${WEBHOOK_URL}...`);
    const response = await axios.post(WEBHOOK_URL, payload, {
      headers: {
        "Content-Type": "application/json",
        "X-Airpero-Event": "TRANSFER_SUCCESS" // Included as seen in app.js allowedHeaders
      }
    });

    console.log("✅ Server Response Status:", response.status);
    console.log("📄 Server Response Data:", response.data);
  } catch (error) {
    console.error("❌ Error sending webhook:");
    if (error.response) {
      console.error("Status:", error.response.status);
      console.error("Data:", error.response.data);
    } else {
      console.error(error.message);
    }
  }
}

sendWebhook();
