🔒 PexiPay Payment Integration

Example: How to Capture Customer IP Address

⚠️ Critical Requirement

You MUST capture your customer's actual IP address on your frontend and pass it to PexiPay. If you call our API from your backend without the customer's IP, fraud detection will receive your server's IP instead.

Loading...

📝 Implementation Code

// Step 1: Capture customer IP on frontend
async function captureCustomerIP() {
  try {
    const response = await fetch('https://api.ipify.org?format=json');
    const data = await response.json();
    return data.ip;
  } catch (error) {
    console.error('Failed to get customer IP:', error);
    return null;
  }
}

// Step 2: Send to your backend
async function processPayment(formData) {
  const customerIP = await captureCustomerIP();
  
  // Your backend endpoint
  const response = await fetch('/api/create-payment', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      ...formData,
      ipAddress: customerIP  // ← REQUIRED
    })
  });
  
  return await response.json();
}

// Step 3: Your backend forwards to PexiPay
app.post('/api/create-payment', async (req, res) => {
  const payment = await fetch('https://gateway.pexipay.com/api/v1/payments', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': process.env.PEXIPAY_API_KEY,
      'x-api-secret': process.env.PEXIPAY_API_SECRET,
    },
    body: JSON.stringify({
      amount: req.body.amount,
      currency: 'USD',
      ipAddress: req.body.ipAddress,  // ← Customer's IP
      customer: req.body.customer,
      billing: req.body.billing,
      card: req.body.card
    })
  });
  
  res.json(await payment.json());
});
💡 Note: This is a frontend demonstration. In production, NEVER send raw card details from your frontend. Always use your backend server with proper PCI compliance measures.