-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic Code setup * Namespace changed from LNPay to LNPayClient * PHPDoc Block updated * get and post methods now return string. Update the PHPDoc block * Added example code for Waller and LightNetwork Transaction library * Readme is updated * new file: init.php - File includer for manual installation new file: src/LnNode.php - Sub library for Lightning Network Nodes new file: src/Paywall.php - Sub library for Paywall modified: src/LNPayClient.php - New sub-library referal properties added - Documentation updated modified: src/Request.php modified: src/LightingNetworkTx.php - Documentation updated modified: src/Wallet.php - Documentation updated - Some methodes name changed - permanentLnUrlWithdraw() and keysend() * modified: src/LNPayClient.php - added listAll() method modified: src/Wallet.php - removed listAll() method modified: README.md - Fixed typo * new file: src/WalletTransaction.php - Wallet transaction have it's own class with methods getWalletTransactions() and getAllTransactions() modified: README.md - Get Wallet Transactions example code updated modified: init.php - WalletTransaction.php added modified: src/LNPayClient.php modified: src/Request.php modified: src/LightingNetworkTx.php - PSR issue fixed modified: src/Wallet.php - getWalletTransactions() and getAllTransactions() method removed Co-authored-by: bapi <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,037 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# Generated files | ||
.idea/**/contentModel.xml | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Gradle and Maven with auto-import | ||
# When using Gradle or Maven with auto-import, you should exclude module files, | ||
# since they will be recreated, and may cause churn. Uncomment if using | ||
# auto-import. | ||
# .idea/artifacts | ||
# .idea/compiler.xml | ||
# .idea/jarRepositories.xml | ||
# .idea/modules.xml | ||
# .idea/*.iml | ||
# .idea/modules | ||
# *.iml | ||
# *.ipr | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
#Composer | ||
composer.lock | ||
phpunit.xml | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,126 @@ | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
|
||
# lnpay-php | ||
LNPay PHP Helper Library | ||
The LNPay PHP library provides convenient access to the LNPay API from PHP applications. | ||
|
||
The Api follows the following practices: | ||
- Namespaced under LNPayClient | ||
- Call $api->class->function() to access the API | ||
- API throws exceptions instead of returning errors | ||
- Options are passed as an array instead of multiple arguments wherever possible. | ||
- All requests and responses will be communicated over JSON | ||
|
||
## Requirements | ||
- PHP 7.3.0 or higher. | ||
- Extensions - curl, json and mbstring | ||
|
||
## Installation via composer | ||
Run in console below command to download package to your project: | ||
``` | ||
composer lnpay/LNPayClient | ||
``` | ||
|
||
## Installation Manually | ||
To manually install the library, you can download the latest release. Then, include the init.php file. | ||
``` | ||
require_once('/path/to/lnpay-php/init.php'); | ||
``` | ||
|
||
## Documentation | ||
The first alpha version of this SDK is mainly a wrapper for the [LNPay API](https://docs.lnpay.co/) | ||
|
||
Everything revolves around the wallet and Wallet Access Keys (WAK) which grant various levels of permission. | ||
|
||
## Setup | ||
``` | ||
// For Composer | ||
// Load the autoload file from composer's vendor directory | ||
require '../vendor/autoload.php'; | ||
use LNPay\LNPayClient; | ||
// Creating Client object | ||
$lnPayClient = new LNPayClient( | ||
'sak_KEY', | ||
'wak_KEY' | ||
); | ||
``` | ||
``` | ||
// For Manual | ||
require 'init.php'; | ||
use LNPay\LNPayClient; | ||
// Creating Client object | ||
$lnPayClient = new LNPayClient( | ||
'sak_KEY', | ||
'wak_KEY' | ||
); | ||
``` | ||
``` | ||
// Wallet Access Key setup if not added while LNPayClient object creationation. | ||
$lnPayClient->wallet->setWalletAccessKey('wak_KEY') | ||
``` | ||
|
||
## Usage | ||
Follow the instruction given SetUp section and initialize the LNPayClient. | ||
|
||
### Check Balance | ||
``` | ||
$response = $lnPayClient->wallet->getInfo(); | ||
print_r($response); | ||
``` | ||
|
||
### Create a wallet | ||
``` | ||
$response = $lnPayClient->wallet->create(array( | ||
'user_label' => 'My New Wallet' | ||
)); | ||
print_r($response); | ||
``` | ||
|
||
### Generate Invoice | ||
``` | ||
$response = $lnPayClient->wallet->createInvoice(array( | ||
"num_satoshis" => "2", | ||
"memo" => "Tester", | ||
)); | ||
print_r($response); | ||
``` | ||
|
||
### Pay Invoice | ||
``` | ||
$response = $lnPayClient->wallet->payInvoice(array( | ||
"payment_request" => "2" | ||
)); | ||
print_r($response); | ||
``` | ||
|
||
### Transfers between wallets | ||
``` | ||
$response = $lnPayClient->wallet->transfer(array( | ||
"num_satoshis" => 1, | ||
"memo" => "SateBack", | ||
)); | ||
print_r($response); | ||
``` | ||
|
||
### Get Wallet Transactions | ||
``` | ||
$response = $lnPayClient->walletTransaction->getWalletTransactions(); | ||
print_r($response); | ||
``` | ||
|
||
### Get LNURL | ||
``` | ||
$response = $lnPayClient->lightingNetworkTx->getInfo('lntx_id'); | ||
print_r($response); | ||
``` | ||
|
||
See this [example files](). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "lnpay/lnpay-php", | ||
"description": "LNPay PHP Client Library", | ||
"keywords": [ | ||
"LNPay", | ||
"Payment Processing", | ||
"API", | ||
"client" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "LNPay and contributors", | ||
"homepage": "https://github.com/lnpay/lnpay-php" | ||
} | ||
], | ||
"support": { | ||
"email": "[email protected]", | ||
"issues": "https://github.com/lnpay/lnpay-php/issues", | ||
"source": "https://github.com/lnpay/lnpay-php" | ||
}, | ||
"homepage": "https://www.lnpay.co", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.3", | ||
"guzzlehttp/guzzle": "^7.3", | ||
"ext-curl": "*", | ||
"ext-intl": "*", | ||
"ext-json": "*", | ||
"ext-mbstring": "*" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"LNPayClient\\": "src/", | ||
"LNPayClient\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "lnpay/lnpay-php", | ||
"description": "LNPay PHP Client Library", | ||
"keywords": [ | ||
"LNPay", | ||
"Payment Processing", | ||
"API", | ||
"client" | ||
], | ||
"homepage": "https://www.lnpay.co/", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.3", | ||
"ext-curl": "*", | ||
"ext-intl": "*", | ||
"ext-json": "*", | ||
"ext-mbstring": "*" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"LNPay\\": "lib/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.1", | ||
"guzzlehttp/guzzle": "^7.3" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "LNPay and contributors", | ||
"homepage": "https://github.com/lnpay/lnpay-php" | ||
} | ||
], | ||
"support": { | ||
"source": "https://github.com/lnpay/lnpay-php" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
use LNPay\LNPayClient; | ||
|
||
// Creating Client object | ||
$lnPayClient = new LNPayClient( | ||
'sak_KEY', | ||
); | ||
|
||
/** | ||
* Gets the invoice information for the `tx_id` | ||
* @see https://docs.lnpay.co/lntx/ | ||
**/ | ||
$response = $lnPayClient->lightingNetworkTx->getInfo('lntx_id'); | ||
print_r($response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
require '../vendor/autoload.php'; | ||
|
||
use LNPay\LNPayClient; | ||
|
||
// Creating Client object | ||
$lnPayClient = new LNPayClient( | ||
'sak_KEY', | ||
'waka_KEY' | ||
); | ||
|
||
/** | ||
* Create a wallet | ||
* @see https://docs.lnpay.co/wallet/create-wallet | ||
**/ | ||
$response = $lnPayClient->wallet->create(array( | ||
'user_label' => 'My New Wallet' | ||
)); | ||
print_r($response); | ||
|
||
/** | ||
* Get the wallet object which includes current balance. | ||
* @see https://docs.lnpay.co/wallet/get-balance | ||
**/ | ||
$response = $lnPayClient->wallet->getBalance(); | ||
print_r($response); | ||
|
||
/** | ||
* Get a list of wallet transactions that have been SETTLED. | ||
* @see https://docs.lnpay.co/wallet/get-transactions | ||
**/ | ||
$response = $lnPayClient->wallet->getTransactions(); | ||
print_r($response); | ||
|
||
/** | ||
* Generates an invoice for this wallet | ||
* @see https://docs.lnpay.co/wallet/generate-invoice | ||
**/ | ||
$response = $lnPayClient->wallet->createInvoice(array( | ||
"num_satoshis" => "2", | ||
"meno" => "Tester", | ||
)); | ||
print_r($response); | ||
|
||
/** | ||
* Pay a LN invoice from the specified wallet. | ||
* @see https://docs.lnpay.co/wallet/pay-invoice | ||
**/ | ||
$response = $lnPayClient->wallet->payInvoice(array( | ||
"payment_request" => "2" | ||
)); | ||
print_r($response); | ||
|
||
/** | ||
* Transfer satoshis from source wallet to destination wallet. | ||
* @see https://docs.lnpay.co/wallet/transfers-between-wallets | ||
**/ | ||
$response = $lnPayClient->wallet->internalTransfer(array( | ||
"num_satoshis" => 1, | ||
"Memo" => "SateBack", | ||
)); | ||
print_r($response); | ||
|
||
/** | ||
* Generate an LNURL-withdraw link. | ||
* @see https://docs.lnpay.co/wallet/lnurl-withdraw | ||
**/ | ||
$response = $lnPayClient->wallet->internalTransfer(array( | ||
"num_satoshis" => 1, | ||
"Memo" => "SateBack", | ||
)); | ||
print_r($response); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
// File used for manual installation | ||
|
||
// Libraries | ||
require __DIR__ . '/src/Request.php'; | ||
require __DIR__ . '/src/LightingNetworkTx.php'; | ||
require __DIR__ . '/src/LnNode.php'; | ||
require __DIR__ . '/src/Paywall.php'; | ||
require __DIR__ . '/src/Wallet.php'; | ||
require __DIR__ . '/src/WalletTransaction.php'; | ||
require __DIR__ . '/src/LNPayClient.php'; |
Oops, something went wrong.