lnpay/lnpay-php

LNPay PHP 客户端库

v0.1 2021-07-21 22:00 UTC

This package is auto-updated.

Last update: 2024-09-23 21:19:03 UTC


README

License: MIT

lnpay-php

LNPay PHP 库提供了从 PHP 应用程序方便访问 LNPay API 的功能。

该 API 采用了以下实践

  • 在 LNPayClient 命名空间下
  • 通过调用 $api->class->function() 访问 API
  • API 抛出异常而不是返回错误
  • 尽可能以数组形式传递选项而不是多个参数。
  • 所有请求和响应将通过 JSON 进行通信

要求

  • PHP 7.3.0 或更高版本。
  • 扩展 - curl、json 和 mbstring

通过 composer 安装

在控制台运行以下命令将包下载到您的项目中

composer require lnpay/lnpay-php

手动安装

要手动安装库,您可以下载最新版本。然后,包含 init.php 文件。

require_once('/path/to/lnpay-php/init.php');

文档

此 SDK 的第一个 alpha 版本主要是 LNPay API 的包装器 LNPay API

设置

// For Composer

// Load the autoload file from composer's vendor directory
require '../vendor/autoload.php';

use LNPayClient\LNPayClient;

// Creating Client object
$lnPayClient = new LNPayClient(
        'sak_KEY'
    );

// For Manual

require 'init.php';

use LNPayClient\LNPayClient;

// Creating Client object
$lnPayClient = new LNPayClient(
        'sak_KEY'
    );

// Wallet Access Key setup if not added while LNPayClient object creationation.

$lnPayClient->wallet->setWalletAccessKey('wal_KEY');

用法

遵循 SetUp 部分的说明并初始化 LNPayClient。

检查余额

$response = $lnPayClient->wallet->getInfo();
print_r($response);

创建钱包

$response = $lnPayClient->wallet->create(array(
        'user_label' => 'My New Wallet'
    ));
print_r($response);

生成发票

$response = $lnPayClient->wallet->createInvoice(array(
        "num_satoshis" => "2",
        "memo" => "Tester",
    ));
print_r($response);

支付发票

$response = $lnPayClient->wallet->payInvoice(array(
        "payment_request" => "lnXXXX"
    ));
print_r($response);

钱包间转账

$response = $lnPayClient->wallet->transfer(array(
        "num_satoshis" => 1,
        "memo" => "SateBack",
    ));
print_r($response);

获取钱包交易

$response = $lnPayClient->walletTransaction->getWalletTransactions();
print_r($response);

获取交易信息

$response = $lnPayClient->lightingNetworkTx->getInfo('lntx_id');
print_r($response);

生成可丢弃的 LNURL-withdraw 链接。

$response = $lnPayClient->wallet->disposableLnUrlWithdraw(['num_satoshis'=> 1, 'memo'=> '1 sat over LNURL once']);
print_r($response);

生成永久的 LNURL-withdraw 链接。

$response = $lnPayClient->wallet->permanentLnUrlWithdraw(['num_satoshis'=> 1, 'memo'=> '1 sat over LNURL again and again']);
print_r($response);

查看 示例文件