PHP code example of cryptoscan-one / cryptoscan-client-php

1. Go to this page and download the library: Download cryptoscan-one/cryptoscan-client-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cryptoscan-one / cryptoscan-client-php example snippets


$publicKey = '...';
$privateKey = '...'

// Аутентификация по приватному ключу
$auth = AuthFactory::privateKey($publicKey, $privateKey);

// Аутентификация по подписи
$auth = AuthFactory::signature($publicKey, $privateKey);

$auth = AuthFactory::signature($publicKey, $privateKey);
$client = new CryptoScanClient($auth);

// Стандартный вызов
$command = new InvoiceCreate(10, '123');
$result = $client->invoiceCreate($command);

// Добавление дополнительных данных
$command = new InvoiceCreate(10, '123');
$command
    ->setMetadata('Example text')
    ->setCurrency("EUR");
$result = $client->invoiceCreate($command);

...
// Стандартный вызов
$command = new WidgetCreate(10, '123');
$result = $client->widgetCreate($command);

// Добавление дополнительных данных
$command
    ->setBackUrl('https://')
    ->setCancelUrl('https://')
    ->setWidgetDescription('Description')
    ->setLang('ru-RU');
    ->setCurrency("EUR");
$result = $client->widgetCreate($command);

...
$invoiceId = 123456;
$result = $client->invoiceDetail($invoiceId);

...
$query = 123456;
$result = $client->invoiceSearch($query);

...
$result = $client->userDetail();

...
$result = $client->currencyRate();

...
$result = $client->currencyRateStatus('EUR');

// Создание своего HTTP клиента
class MyHTTPClient impliments HttpClientInterface
{
    ...
}
$httpClient = new MyHTTPClient();
// Создание провайдера данных
$provider = ProviderFactory::http($httpClient);
$client = new CryptoScanClient($auth, $provider);

// Заголовок переданного запроса
$headers = [
    'public-key' => '...',
    'signature' => '...',
//    'private-key' => '...',
];

// Тело запроса
$data = [
    'event_type' => 'paid',
    'retry_count' => 3,
    ...
];

// Формирование WebHook запроса
$webHookData = new WebHookRequest($headers, $data);

$auth = AuthFactory::privateKey($publicKey, $privateKey);
$webHookHandler = new WebHookHandler($auth);
$message = $webHookHandler->handle($webHookData);

class MyWebHookData impliments WebHookDataInterface
{
    ...
}
$webHookData = new MyWebHookData($headers, $data);
....