PHP code example of analogic / lightning-charge-client-php7

1. Go to this page and download the library: Download analogic/lightning-charge-client-php7 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/ */

    

analogic / lightning-charge-client-php7 example snippets



nitialize client
$charge = new \LightningCharge\Client('http://localhost:8009', '[TOKEN]');

// Create invoice
$request = new \LightningCharge\InvoiceRequest();
$request->setMilliSatoshi(50);
$request->setMetadata(['customer' => [ 'customer' => 'Satoshi', 'products' => [ 'potato', 'chips']]]);
$invoice = $charge->invoice($request);

tell_user("to pay, send ".$invoice->getMilliSatoshi()." milli-satoshis with rhash ".$invoice->getRhash().", or copy the BOLT11 payment request: ".$invoice->getPayreq());


// Create invoice denominated in USD
$request = new \LightningCharge\InvoiceRequest();
$request->setCurrency('USD');
$request->setAmount(0.15);
$invoice = $charge->invoice($request);

// Fetch invoice by id
$invoice = $charge->fetch('m51vlVWuIKGumTLbJ1RPb');

// Fetch all invoices
$invoices = $charge->fetchAll();

// Register web hook
$charge->registerHook('m51vlVWuIKGumTLbJ1RPb', 'http://my-server.com/my-callback-url');
bash
$ composer