passimpay/passimpay-php-api

该软件包最新版本(v1.0.0)没有可用的许可证信息。

Passimpay API PHP 封装

v1.0.0 2023-08-08 16:28 UTC

This package is not auto-updated.

Last update: 2024-09-28 12:11:19 UTC


README

这是一个用于将 Passimpay API 简单集成到您的 PHP 项目的库。

要求

  • PHP >= 7.1.0
  • ext-mbstring
  • ext-json
  • ext-curl

您还需要在此处创建您的平台(平台)并在代码中指定某些值

  • 平台 ID
  • 密钥

Composer 安装

$ composer require passimpay/passimpay-php-api

示例

  1. 获取余额
use Passimpay/PassimpayApi;

$api = new PassimpayApi(123, 'secret key');

list($balance, $error) = $api->balance();

if (null !== $error) {
  throw new Exception($error);
}

dosomething($balance);
  1. 获取货币列表
use Passimpay/PassimpayApi;

$api = new PassimpayApi(123, 'secret key');

list($currencies, $error) = $api->currencies();

if (null !== $error) {
  throw new Exception($error);
}

dosomething($currencies);
  1. 创建发票链接
use Passimpay/PassimpayApi;

$api = new PassimpayApi(123, 'secret key');

list($url, $error) = $api->invoice('your invoice id', 999.0);

if (null !== $error) {
  throw new Exception($error);
}

dosomething($url);
  1. 检查发票状态
use Passimpay/PassimpayApi;

$api = new PassimpayApi(123, 'secret key');

list($status, $error) = $api->invoiceStatus('your invoice id');

if (null !== $error) {
  throw new Exception($error);
}

dosomething($status);
  1. 获取付款钱包地址
use Passimpay/PassimpayApi;

$api = new PassimpayApi(123, 'secret key');

list($address, $error) = $api->paymentWallet('order id', 'payment id');

if (null !== $error) {
  throw new Exception($error);
}

dosomething($address);
  1. 提款
use Passimpay/PassimpayApi;

$api = new PassimpayApi(123, 'secret key');

list($response, $error) = $api->withdraw('payment id', 'addressTo', 999.0);

if (null !== $error) {
  throw new Exception($error);
}

dosomething($response);
  1. 检查交易状态
use Passimpay/PassimpayApi;

$api = new PassimpayApi(123, 'secret key');

list($response, $error) = $api->transactionStatus('transaction hash');

if (null !== $error) {
  throw new Exception($error);
}

dosomething($response);
  1. 处理通知

passimpay.io创建平台时,您可以指定当发票状态更改时调用的端点。
使用以下代码处理此通知

$secretKey = '123';

$hash = $_POST['hash'];

$data = [
  'platform_id'  => (int) $_POST['platform_id'],  // Platform ID
  'payment_id'   => (int) $_POST['payment_id'],   // currency ID
  'order_id'     => (int) $_POST['order_id'],     // Payment ID of your platform
  'amount'       => $_POST['amount'],             // transaction amount
  'txhash'       => $_POST['txhash'],             // Hash or transaction ID. You can find the transaction ID in the PassimPay transaction history in your account.
  'address_from' => $_POST['address_from'],       // sender address
  'address_to'   => $_POST['address_to'],         // recipient address
  'fee'          => $_POST['fee'],                // network fee
];

if (isset($_POST['confirmations']))
{
  $data['confirmations'] = $_POST['confirmations']; // number of network confirmations (Bitcoin, Litecoin, Dogecoin, Bitcoin Cash)
}

$payload = http_build_query($data);

if (!isset($hash) || hash_hmac('sha256', $payload, $secretKey) != $hash)
{
  return false;
}

// payment credited
// your code...

贡献

如果您发现了一个错误或有一些建议,请随意创建一个问题