PHP code example of alissonlinneker / xgate-php-sdk
1. Go to this page and download the library: Download alissonlinneker/xgate-php-sdk 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/ */
alissonlinneker / xgate-php-sdk example snippets
use XGateGlobal\SDK\Client;
use XGateGlobal\SDK\Configuration;
use BcMath\Number;
// Configuração básica
$config = new Configuration([
'email' => '[email protected]',
'password' => 'sua-senha'
]);
$client = new Client($config);
// Login (automático na primeira requisição)
$client->auth->login();
// Listar moedas disponíveis
$currencies = $client->deposits->getCurrencies();
foreach ($currencies as $currency) {
echo "{$currency->symbol}: {$currency->name}\n";
}
// Criar depósito
$transaction = $client->deposits->create(
new Number('100.50'),
'customer_123',
'USD'
);
printf("Transação criada: %s\n", $transaction->id);
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('xgate');
$logger->pushHandler(new StreamHandler('path/to/xgate.log', Logger::DEBUG));
$client = new Client($config, $logger);
use GuzzleHttp\Client as GuzzleClient;
$httpClient = new GuzzleClient([
'proxy' => 'tcp://localhost:8080',
'verify' => false, // For development only
'headers' => [
'X-Custom-Header' => 'value'
]
]);
$config = new Configuration([
'email' => '[email protected]',
'password' => 'your-password',
'http_client' => $httpClient
]);
$client = new Client($config);
use XGateGlobal\SDK\Utils\RateLimiter;
// Create a rate limiter (60 requests per 60 seconds)
$rateLimiter = new RateLimiter(60, 60);
// Check if request is allowed
try {
$rateLimiter->allow('api_key_123');
// Make API request
$transaction = $client->deposits->create(
new Number('100.00'),
'customer_123',
'USD'
);
} catch (RateLimitException $e) {
echo "Rate limit exceeded. Wait {$e->getRetryAfter()} seconds\n";
}
// Get rate limit info
$info = $rateLimiter->getInfo('api_key_123');
echo "Remaining requests: {$info['remaining']}\n";
echo "Reset at: " . date('H:i:s', $info['reset_at']) . "\n";
use XGateGlobal\SDK\Utils\MoneyFormatter;
use BcMath\Number;
$formatter = new MoneyFormatter('en_US', 'USD');
// Format currency
echo $formatter->format(new Number('1234.56')); // $1,234.56
// Format crypto
echo $formatter->formatCrypto(new Number('0.00000123'), 'BTC'); // 0.00000123 BTC
// Calculate fees
$result = $formatter->calculateFee(
new Number('100.00'),
new Number('2.5'), // 2.5%
true // is percentage
);
echo "Amount: " . $formatter->format($result['amount']) . "\n";
echo "Fee: " . $formatter->format($result['fee']) . "\n";
echo "Total: " . $formatter->format($result['total']) . "\n";