To make use of the services of Lightning Checkout two REST API calls needs to be implemented..
- One for creating the Lightning invoice
- One for checking the payment status of previously created Lightning invoice.
Creating the Lightning Invoice
The code snippet below is showing a curl example of the API call for creating the invoice.
After calling this API the JSON response like below is returned when the invoice is created successfully.
For Lightning payments it’s common to show the Lightning invoice as a QR code. The QR should be a hyperlink as well with the prefix ‘lightning:’, the complete hyperlink does look like: lightning:<payment_request>. when using this best practice the phone’s lighting wallet is opened when he clicks the QR code so the customer can pay directly.
Next to that it common and user friendly to give a ‘one-click’ option to copy the invoice string to the clipboard. An example of this implementation is shown in our demo shop.
Retrieving payment status Lightning Invoice
After creating and showing the QR code of the Lightning invoice the customer will pay. So it’s necessary to check the payment status of the invoice.
The snippet below shows a curl example of the call to be performed. This call should take the payment_hash of the created invoice into account.
This call needs to be performed every 3 to 5 seconds to verify if the payment is completed. An example response is shown below. And invoice is paid completely when the tag paid in the response has the value true.
When the invoice is paid, you can redirect to the confirmation page of your shop or app. This is all that is needed to start implement Lightning payments in your website or application. When you have questions during the implementation please let us know.