Hosted checkout (PHP / Node)

Get key and token, redirect, verify sid. Curl, PHP, and Node.

📘

Testing on staging? Use the .net hosts from Sandbox. Examples below use live hosts.

1. Request key + token (server)

cURL

curl -X POST "https://api.sifalopay.com/gateway/" \
  -u "$SIFALO_API_USER:$SIFALO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "22",
    "gateway": "checkout",
    "currency": "USD",
    "return_url": "https://yoursite.com/pay/return?order_id=ORD-42",
    "webhook_url": "https://yoursite.com/hooks/sifalopay"
  }'

Optional webhook_url: we POST payment status after the customer pays. See Webhooks.

PHP

<?php
$ch = curl_init('https://api.sifalopay.com/gateway/');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPAUTH       => CURLAUTH_BASIC,
    CURLOPT_USERPWD        => getenv('SIFALO_API_USER') . ':' . getenv('SIFALO_API_KEY'),
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'amount'      => '22',
        'gateway'     => 'checkout',
        'currency'    => 'USD',
        'return_url'  => 'https://yoursite.com/pay/return?order_id=ORD-42',
        'webhook_url' => 'https://yoursite.com/hooks/sifalopay',
    ]),
    CURLOPT_TIMEOUT        => 120,
]);
$start = json_decode(curl_exec($ch), true);
curl_close($ch);
// $start['key'], $start['token']

Node

const auth = Buffer.from(
  `${process.env.SIFALO_API_USER}:${process.env.SIFALO_API_KEY}`
).toString('base64');

const start = await fetch('https://api.sifalopay.com/gateway/', {
  method: 'POST',
  headers: {
    Authorization: `Basic ${auth}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    amount: '22',
    gateway: 'checkout',
    currency: 'USD',
    return_url: 'https://yoursite.com/pay/return?order_id=ORD-42',
    webhook_url: 'https://yoursite.com/hooks/sifalopay',
  }),
}).then((r) => r.json());
// start.key, start.token

You receive:

{ "key": "YWVm=.........", "token": "uVKqEYi......." }

2. Redirect the customer

https://pay.sifalo.com/checkout/?key=YWVm=.........&token=uVKqEYi.......

3. On return, verify sid

Verify does not use Basic auth. Customer lands on:

https://yoursite.com/pay/return?order_id=ORD-42&sid=ABC123

cURL

curl -X POST "https://api.sifalopay.com/gateway/verify.php" \
  -H "Content-Type: application/json" \
  -d '{"sid":"ABC123"}'

PHP

<?php
$ch = curl_init('https://api.sifalopay.com/gateway/verify.php');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode(['sid' => $_GET['sid'] ?? '']),
    CURLOPT_TIMEOUT        => 30,
]);
$verify = json_decode(curl_exec($ch), true);
curl_close($ch);
if (($verify['status'] ?? '') === 'success' && (int) $verify['code'] === 601) {
    // fulfill the order
}

Node

const verify = await fetch('https://api.sifalopay.com/gateway/verify.php', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ sid: new URL(request.url).searchParams.get('sid') }),
}).then((r) => r.json());

if (verify.status === 'success' && Number(verify.code) === 601) {
  // fulfill the order
}

Fulfill only if status is success and code is 601.

Full explanation: Hosted checkout.


Did this page help you?