Download the PHP package klev-o/crypto-pay-api without Composer
On this page you can find all versions of the php package klev-o/crypto-pay-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package crypto-pay-api
klev-o/crypto-pay-api
Simple and convenient implementation Crypto Pay API with php version ^7.4 support. Based on the Official Crypto Pay Api
📖 Intro
Fully object-oriented and simple code. All available types and methods are described using classes with documentation of all fields. For each class, the url to the documentation is indicated, where you can study the nuances, etc.
🛠 Installation
Run this command in your command line:
🔌Usage
Common
First, you need to create an object of the CryptoPay class, passing the API key of your application to the constructor:
To create an app and get an api token, open @CryptoBot or @CryptoTestnetBot (for testnet), send /pay command, then go to ‘Create App’.
You can pass the second parameter $isTestnet to the CryproPay constructor to make all requests go through the testnet. This is useful for any experiments)
Then you can call all possible methods. To check that everything is working correctly, you can call the $api->getMe()
method, which will return basic information about your application.
If everything works well, then you will see something like this
For more complex methods, value objects are used, for example, this is how you can create invoices:
As you can see above, required parameters are passed through the constructor, while optional parameters can be set directly. Also, for values that expect "one of", special enums are created, located at the namespace Klev\CryptoPayApi\Enums
.
By the same principle, objects are created for the methods getInvoice()
and Transfer()
More detailed examples can be found in the demo directory
All available methods can be viewed at the $api
object, or refer to the official documentation
Webhooks
Using a webhook, you can receive updates for your application
Please note that the interceptor must first be activated in your application. This can be done in the following way: open @CryptoBot or @CryptoTestnetBot (for testnet), send /pay command, then go to ‘My Apps’, choose your app, open ‘Webhooks’ and click ‘Enable Webhooks’. Read more here
To receive updates, you need to use the $api->getWebhookUpdates()
method and subscribe to listen for the necessary events. There is currently only one event (or update type) available - invoice_paid. It also has an enum - PaidType::INVOICE_PAID
:
You can register multiple handlers for the same event.
You can also just get the result from the
$api->getWebhookUpdates()
method without subscribing to eventsBy default, events are disabled. To enable them, you need to use the method
$api->setEnableEvents(true);
📟Advanced
Also, as an event handler, you can use anything that corresponds to the callable type. Let's take an example:
Let's say we have installed
composer require php-di/php-di
, although you can use any other psr-compatible
You can use your dependency injection container to pipe all the necessary functionality from your code into handlers
🎁Dontations
Support the project if you like it. Funds will go towards food.
Network | Currency | Wallet |
---|---|---|
Bitcoin | BTC |
1M1qhSE6sN34a4d7ZtCh6y17Vf3LtdoW62 or 14cvXywCMucKMhFYDCbmQ1ZHhayDgbD65R |
The Open Network | TON |
EQAYZK8rWrS9Fhojdc486BpplDmTSLHum440f-L2--SA2Oid or ton://transfer/UQBVsumSIvsq4PfeFMhxSV9m_zPB31cHJX4X2lAVh9BUJXm3 |
Binance Smart Chain – BEP20 | BNB, BUSD, USDT |
0x674B09Ab418bb41C075847bde004bb7F492c2121 |
🧨Troubleshooting
Please, if you find any errors or not exactly - report this problem page
And finally...
Happy botting 🤖
All versions of crypto-pay-api with dependencies
ext-json Version *
ext-curl Version *
guzzlehttp/guzzle Version ^7.2
psr/http-client Version ^1.0
psr/http-message Version ^2.0