1. Go to this page and download the library: Download klev-o/crypto-pay-api 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/ */
klev-o / crypto-pay-api example snippets
composer
= new \Klev\CryptoPayApi\CryptoPay('YOUR_APP_TOKEN');
second parameter true - activates the testnet
$api = new \Klev\CryptoPayApi\CryptoPay('YOUR_APP_TOKEN', true);
= new \Klev\CryptoPayApi\CryptoPay('YOUR_APP_TOKEN');
$result = $api->getMe();
print_r($result)
//Display if everything is working well
Array
(
[app_id] => 12345 //your id will be different
[name] => Some App //your name will be different
[payment_processing_bot_username] => CryptoBot
)
use Klev\CryptoPayApi\Methods\CreateInvoice;
use Klev\CryptoPayApi\CryptoPay;
use Klev\CryptoPayApi\Enums\PaidBtnName;
d_btn_name = PaidBtnName::OPEN_CHANNEL;
$createdInvoice = $api->createInvoice($data)
use Klev\CryptoPayApi\Methods\CreateInvoice;
use Klev\CryptoPayApi\CryptoPay;
use Klev\CryptoPayApi\Enums\PaidType;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
oPay('YOUR_APP_TOKEN');
$api->setEnableEvents(true);
//subscribe to an event
$api->on(PaidType::INVOICE_PAID, static function(Update $update) use ($log) {
//do something with the data
$log->info('webhook data: ', (array)$update);
});
$api->getWebhookUpdates();
use Klev\CryptoPayApi\CryptoPay;
use Klev\CryptoPayApi\Enums\PaidType;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
to create an object
LoggerInterface::class => function(\DI\Container $c) {
$log = new Logger('App');
$log->pushHandler(new StreamHandler('../var/logs/app.log'));
return $log;
},
//specify the rules on how to create an object
InvoicePaidListener::class => function(\DI\Container $c) {
return new InvoicePaidListener($c->get(LoggerInterface::class));
}
]);
$container = $builder->build();
//Instead of using an anonymous function, we can now use a custom class, into which,
//if necessary, we can pull everything we need (working with the database, sending by mail, etc.)
class InvoicePaidListener
{
private Logger $log;
public function __construct(Logger $log)
{
$this->log = $log;
}
public function __invoke(Update $update)
{
$this->log->info('payload', (array)$update);
}
}
//Now the event subscription looks more concise
$api->on(PaidType::INVOICE_PAID, $container->get(InvoicePaidListener::class));
$api->getWebhookUpdates();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.