Skip to content
eCommerce payments using PHP and Lightning (lnd)
PHP JavaScript CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
images
resources
.gitignore
LICENSE
README.md

README.md

LightningPay-PHP

A simple way to accept order payments via the Lightning Network on your eCommerce website. LightningPay GIF

If want to tip me you can use my LightningTip as below. (https not used as this is hosted on a free web server without SSL certificates. You will not be entering any sensitive data.)

Credit

LightningPay-PHP is based on LightningTip-PHP, which in turn is based on LightningTip by michael1011.

Requirements

  • one lnd instance
  • a webserver that supports PHP and curl

Security

The invoice.macroon file limits the functionality available to LightningPay.php to only invoice related functions. Importantly, if someone steals your invoice.macaroon, they can NOT spend any of your funds.

eCommerce Example

The intended audience for this project is users that have an existing online eCommerce site. Typically the customer ends up at a checkout confirmation webpage with some Pay Now button(s).

In this project we include a very simple dummy eCommerce checkout page that serves as an example of how to deploy lightningPay.

Prepare LND

  • Enable REST on your lnd instance(s). See the restlisten parameter in the lnd documentation.
  • Open any necessary firewall ports on your lnd host, and router port-forwards as needed.
  • Generate a hex version of the invoice.macaroon file on your lnd instance.

Prepare Web Server

Your webserver will need to have the php-curl package installed.

On a typical Linux webserver you can check as follows. The example below shows that it is installed.

$ dpkg -l php-curl
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                   Version          Architecture     Description
+++-======================-================-================-=================================================
ii  php-curl               1:7.0+49         all              CURL module for PHP [default]

If you see no packages found matching php-curl then install as follows.

$ sudo apt-get update
$ sudo apt-get install php-curl

How to install

  • Download the latest release, and unzip.
  • From the resources folder: Upload these files to your webserver:
    • StoreCheckout.php
    • lightningPay_conf.php
    • lightningPay.php
    • lightningPay.js
    • lightningPay.css
    • lightningPay_light.css (Optional)
  • Edit
    • lightningPay_conf.php. This is where you enter the HEX version of your invoice.macaroon.
    • the CHANGE ME section of lightningPay.js.

How to test

Use your browser to visit these URLs:

  • https://your.web.server/path/StoreCheckout.php
  • https://your.web.server/path/StoreCheckout.php?order_id=100
  • https://your.web.server/path/StoreCheckout.php?testnet=1
  • https://your.web.server/path/StoreCheckout.php?testnet=1&order_id=100

or you can check my test sites here:

(https not used as this is hosted on a free web server without SSL certificates. You will not be entering any sensitive data.)

How to Use

Copy the contents of the head tag from lightningPay.php into the head section of the HTML file you want to show LightningPay in. The div below the head tag is LightningPay itself. Paste it into any place in the already edited HTML file on your server.

There is a light theme available for LightningPay. If you want to use it, uncomment this line in your lightningPay.php file:

<link rel="stylesheet" href="lightningPay_light.css">

Do not use LightningPay on XHTML sites. That causes some weird scaling issues.

That's it! The only things you need to take care of is keeping the LND node and web server online. LightningPay will take care of everything else.

You can’t perform that action at this time.