Skip to content
Guarantee Pay Docs

API

Code examples

A complete integration: create a charge, then verify it from the webhook and from the return page.

cURL

curl -X POST "https://payment.yamin.bd/api/create-charge" \
  -H "MHS-GUARANTEEPAY-API-KEY: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"full_name":"Rahim Uddin","email_mobile":"rahim@example.com","amount":"500","currency":"BDT","metadata":{"order_id":"ORD-1001"},"redirect_url":"https://shop.example.com/pay/return?order_id=ORD-1001","webhook_url":"https://shop.example.com/hooks/guaranteepay"}'

PHP

<?php
const GP_BASE = 'https://payment.yamin.bd';
const GP_KEY  = 'YOUR_API_KEY'; // load from env / config, never commit it

function gp_call(string $path, array $body): array {
    $ch = curl_init(GP_BASE . $path);
    curl_setopt_array($ch, [
        CURLOPT_POST           => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 30,
        CURLOPT_HTTPHEADER     => [
            'MHS-GUARANTEEPAY-API-KEY: ' . GP_KEY,
            'Content-Type: application/json',
            'Accept: application/json',
        ],
        CURLOPT_POSTFIELDS     => json_encode($body),
    ]);
    $raw  = curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    $data = json_decode((string)$raw, true) ?: [];
    if ($code !== 200) {
        throw new RuntimeException(($data['error']['code'] ?? 'HTTP_' . $code) . ': ' . ($data['error']['message'] ?? ''));
    }
    return $data;
}

// 1) Create the charge and redirect
$orderId = 'ORD-1001';
$charge = gp_call('/api/create-charge', [
    'full_name'    => 'Rahim Uddin',
    'email_mobile' => 'rahim@example.com',
    'amount'       => '500',
    'currency'     => 'BDT',
    'metadata'     => ['order_id' => $orderId],
    'redirect_url' => 'https://shop.example.com/pay/return?order_id=' . $orderId,
    'webhook_url'  => 'https://shop.example.com/hooks/guaranteepay',
]);
save_pp_id($orderId, $charge['pp_id']);     // your DB
header('Location: ' . $charge['pp_url']);

// 2) Shared confirmation (call from the webhook AND the return page)
function gp_confirm(string $orderId): bool {
    $order = load_order_for_update($orderId); // SELECT … FOR UPDATE
    if (!$order || $order['paid']) return (bool)$order;
    $p = gp_call('/api/verify-payment', ['pp_id' => $order['pp_id']]);
    $ok = $p['status'] === 'completed'
        && ($p['metadata']['order_id'] ?? '') === $orderId
        && $p['currency'] === 'BDT'
        && abs((float)$p['amount'] - (float)$order['amount']) < 0.01;
    if ($ok) mark_order_paid($orderId, $p['transaction_id']);
    return $ok;
}

// 3) Webhook endpoint
$in = json_decode(file_get_contents('php://input'), true) ?: [];
$orderId = (string)($in['metadata']['order_id'] ?? '');
if ($orderId !== '' && ($in['status'] ?? '') === 'completed') {
    gp_confirm($orderId);
}
http_response_code(200);
echo 'ok';

Node.js (fetch)

const GP_BASE = 'https://payment.yamin.bd';

async function gpCall(path, body) {
  const res = await fetch(GP_BASE + path, {
    method: 'POST',
    headers: {
      'MHS-GUARANTEEPAY-API-KEY': process.env.GP_KEY,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(body),
  });
  const data = await res.json();
  if (!res.ok) throw new Error(`${data.error?.code}: ${data.error?.message}`);
  return data;
}

const { pp_id, pp_url } = await gpCall('/api/create-charge', {
  full_name: 'Rahim Uddin',
  email_mobile: 'rahim@example.com',
  amount: '500',
  metadata: { order_id: 'ORD-1001' },
  redirect_url: 'https://shop.example.com/pay/return?order_id=ORD-1001',
  webhook_url: 'https://shop.example.com/hooks/guaranteepay',
});

const payment = await gpCall('/api/verify-payment', { pp_id });
if (payment.status === 'completed' && payment.metadata.order_id === 'ORD-1001') {
  // fulfil once
}