atsareva/monopay
Composer 安装命令:
composer require atsareva/monopay
包简介
A lightweight library for Monobank Acquiring, named 'Plata by Mono,' built on REST API (v2410). Documentation available at https://api.monobank.ua/docs/acquiring.html.
README 文档
README
A simple PHP library to work with Monobank Acquiring. For detailed API documentation, refer to Monobank Acquiring API.
Dependencies
- guzzlehttp/guzzle >= 7.9.0
- PHP >= 7.4
How to Use
First, obtain an API token, which is required to access Monobank's API. You can register one in your Monobank personal account to activate a token or enable a test token.
Run the next command to install the library with all dependencies:
composer require atsareva/monopay
Usage Examples
Initialize Mono Client
require_once 'vendor/autoload.php';
/** Initialize Mono client */
$client = new MonoPay\ClientMono('TOKEN');
Invoice Examples
Create an Invoice
$options = [
'amount' => 5000,
'merchantPaymInfo' => [
'reference' => '1000000021',
'destination' => 'Order #1000000021',
'basketOrder' => [
[
'name' => 'Product ABC',
'qty' => 1,
'sum' => 5000, // Amount in the smallest currency unit per product unit
'icon' => 'https://example.com/media/catalog/product/product_abc.jpg',
'unit' => 'kg',
],
],
],
'redirectUrl' => 'https://example.com/monopay/success.php',
'webHookUrl' => 'https://example.com/monopay/webhook.php',
'paymentType' => 'hold', // Options: debit | hold
];
try {
$invoice = new MonoPay\Invoice();
$invoice
->setClient($client)
->create($options);
// Save invoice ID for future reference
echo "Invoice ID: " . $invoice->getInvoiceId() . '<br/>';
echo "Invoice Payment URL: " . $invoice->getPageUrl() . '<br/>';
echo "Invoice Status: " . $invoice->getStatus() . '<br/>';
// Redirect customer to payment page
header("Location: " . $invoice->getPageUrl());
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
Get Updated Invoice Data
try {
$invoice
->setClient($client)
->setInvoiceId('INVOICE_ID')
->updateInfo();
echo "Invoice ID: " . $invoice->getInvoiceId() . '<br/>';
echo "Invoice Status: " . $invoice->getStatus() . '<br/>';
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
Finalize Invoice (Hold Status)
try {
$invoice
->setClient($client)
->setInvoiceId('INVOICE_ID')
->capture();
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
Refund Invoice (Successful Payment)
try {
$invoice
->setClient($client)
->setInvoiceId('INVOICE_ID')
->refund()
->updateInfo();
echo "Invoice Status: " . $invoice->getStatus() . '<br/>';
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
Merchant Examples
try {
$merchant = new MonoPay\Merchant();
$merchant
->setClient($client)
->load();
echo "Merchant ID: " . $merchant->getMerchantId() . '<br/>';
echo "Merchant Name: " . $merchant->getMerchantName() . '<br/>';
echo "Public Key: " . $merchant->getPublicKey() . '<br/>';
// Load all statements from the last 4 days
$statements = $merchant->getStatement(time() - 60 * 60 * 96);
foreach ($statements as $statement) {
var_dump($statement);
}
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
Note: This library is currently in development. Please create a ticket if you encounter any issues.
Thanks!
atsareva/monopay 适用场景与选型建议
atsareva/monopay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 atsareva/monopay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atsareva/monopay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-11-13