Download the PHP package moki74/laravel-btc without Composer
On this page you can find all versions of the php package moki74/laravel-btc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moki74/laravel-btc
More information about moki74/laravel-btc
Files in moki74/laravel-btc
Package laravel-btc
Short Description Payment system for btc with bitcoind
License MIT
Informations about the package laravel-btc
laravel-btc
Package for receive payments via BTC
Prerequisites
Laravel version >= 5.5
There is lot of docs about installing Laravel, not covered here ...
Running Bitcoind server
You can find docs here : https://bitcoin.org/en/full-node#what-is-a-full-node
Installation
First, make laravel application :
then cd in first-bitcoin-app:
Install package via composer:
After installation publish package with artisan command :
and choose by tag bitcoin.
In config folder you'll find new config file - bitcoind.php You can change values in file directly, but most common way is to put values in Laravel .env file, like this :
Next, run migrations :
Usage
There are two main objects in package :
1. moki74\LaravelBtc\Bitcoind - this is a wrapper for RPC commands to bitcoin server. You can make this object via Laravel app helper function like this:
and then call RPC method on object :
You can use just this object for simpler projects ...
2. moki74\LaravelBtc\Models\Payment - this object is model for payment with Bitcoin , creates for you new Bitcoin address, amount, track if customer made payment, store it to database ...
Again, use app helper function like this:
This object contains following properties:
user_id - id of user who made order
order_id - order id (not mandatory)
address - bitcoin address (this is automatically generated for you when you call $payment = app("bitcoinPayment"))
paid - this is indicator if user is made payment and number of confirmations on block chain is ok (there is configuration parameter for minimum number of confirmations BITCOIND_MIN_CONFIRMATIONS in .env file or directly in bitcoind.conf file in config folder)
amount - price that user need to pay
amount_received - amount of bitcoin that is actually received (some user can make mistake and send bitcoins with fee deducted from amount send from their wallet, than you wont get expected amount)
txid - transaction id in block chain for this payment (this is populated in database when user actually make payment)
confirmations - number of confirmations for payment.
Typical workflow
When order is made by user, you make new Payment object and populate its properties :
Checking payments and confirmations:
Package contains class moki74\LaravelBtc\Commands\CheckPayment. This is Laravel Command and you can call it via php artisan :
Each time you call it, it scan for payments and confirmations on block chain. You can call it manually for testing purposes like mentioned above , but there is no much sense to do so, because it's job is to check for payments and it needs to run always.
You need to make crontab entry on linux servers or task scheduler on Win servers to call this command every minute.
This script also fires events that we can listen ...
Listening for payments
You'll find new classes in app\Listeners folder of your app when you published pakage ( see installation section). Those are :
ConfirmedPaymentListener.php
UnconfirmedPaymentListener.php
UnknownTransactionListener.php
Each of these Listeners correspond to Events which are placed in vendor folder of project : vendor\moki74\laravel-btc\src\Events
ConfirmedPaymentEvent.php
UnconfirmedPaymentEvent.php
UnknownTransactionEvent.php
To activate these Listeners copy this code in app\Providers\EventServiceProvider.php class (this class exists by default installation of Laravel), in $listen attribute of this class.
Like this:
In each of these class there is handle method, where you can put logic for actions that need to be done when event is fired (DB insert-update, sending mails ...).
Below is example of ConfimedPaymentListener, event is generated when number of confirmations is equal to BITCOIND_MIN_CONFIRMATIONS in .env file and we can be sure that payment is ok.
Events
-
moki74\LaravelBtc\Events\UnconfirmedPaymentEvent - Payment is made by user. Transaction id is generated on block chain, number of conifrmation on block chain is 0 - so you have to wait for additional confirmations.
-
moki74\LaravelBtc\Events\ConfirmedPaymentEvent - Payment is made and number of confirmations is equal or greater than value of BITCOIND_MIN_CONFIRMATIONS in .env file.
- moki74\LaravelBtc\Events\UnknownTransactionEvent - Usually this happens when user make payment and transaction fee is deducted from amount that he sends from his wallet and you don't receive whole amount. This payments are stored in separate table and you can make logic how to resolve situation like this.
Models
moki74\LaravelBtc\Models\Payment - Represents Confirmed and Unconfirmed Payments (see Usage section)
moki74\LaravelBtc\Models\UnknownTransaction - Represent transaction on block chain with amount that does not correspond to amount in Payment model.
License
MIT License
To help this project grow, please make donation in bitcoin:
BTC address : 1D3PDXSQDjvyLXeMb34XR6UeCwZX7tcjXP