Уведомление об оплате

Пример тела callback запроса
{
  "signature": "9eabbecc21c8bc968b73291bb19def2a10c8251c",
  "id": "123456789_abcdefghij",
  "url": "https://pay.crystalpay.io/?i=123456789_abcdefghij",
  "state": "payed",
  "type": "purchase",
  "method": "BITCOIN",
  "required_method": "",
  "currency": "BTC",
  "service_commission": 0,
  "extra_commission": 0,
  "amount": 100,
  "pay_amount": 0.1,
  "remaining_amount": 0.1,
  "balance_amount": 0.1,
  "description": "",
  "redirect_url": "https://crystalpay.io/",
  "callback_url": "https://example.com/crystalpay.php",
  "extra": "",
  "created_at": "2023-01-01 00:00:00",
  "expired_at": "2023-01-03 12:34:56"
}

Валидация callback запроса по signature

<?php
$content = json_decode(file_get_contents('php://input'), true);
...
$id = $content["id"];
$signature = $content["signature"];

$salt = "Salt кассы";

$hash = sha1($id.":".$salt);

if (!hash_equals($hash, $signature)) { //Безопасное сравнение подписи callback
    exit("Invalid signature!");
}

...

Last updated