定制 kemo/monri-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kemo/monri-client

Composer 安装命令:

composer require kemo/monri-client

包简介

Monri payment gateway PHP client

README 文档

README

CI

PHP client for the Monri payment gateway. Supports PHP 8.1+.

Installation

composer require kemo/monri-client

Configuration

use Kemo\Monri\Config;
use Kemo\Monri\Environment;
use Kemo\Monri\MonriClient;

$client = new MonriClient(new Config(
    merchantKey: 'your-merchant-key',
    authenticityToken: 'your-authenticity-token',
    environment: Environment::Production, // or Environment::Test
));

Or from environment variables (MONRI_MERCHANT_KEY, MONRI_AUTHENTICITY_TOKEN, MONRI_ENVIRONMENT):

$client = MonriClient::fromEnv();

Both credentials are available in the Monri merchant dashboard.

Authentication

All requests are signed using the documented WP3-v2.1 digest scheme:

Authorization: WP3-v2.1 {authenticity_token} {timestamp} {SHA512(key+timestamp+token+path+body)}

This is handled automatically — no manual token management required.

Payments

Create a payment

$payment = $client->payments()->create([
    'order_number'     => 'ORD-' . uniqid(),
    'amount'           => 5000,        // minor units (5000 = €50.00)
    'currency'         => 'EUR',
    'order_info'       => 'GOD Club membership',
    'transaction_type' => 'purchase',  // or 'authorize'
]);

echo $payment->id;           // payment ID to pass to the frontend SDK
echo $payment->clientSecret; // client secret for frontend SDK
echo $payment->status;       // 'approved' | 'invalid-request' | 'error'

Optional params: scenario, customer_uuid, supported_payment_methods, success_url_override, cancel_url_override, callback_url_override.

Update a payment (change amount before capture)

$payment = $client->payments()->update('pay_123', ['amount' => 3000]);

Check payment status

$status = $client->payments()->status('pay_123');

echo $status->status;        // 'approved' | 'invalid-request' | 'error'
echo $status->paymentStatus; // e.g. 'completed'

if ($status->result !== null) {
    echo $status->result->amount;      // int, minor units
    echo $status->result->currency;    // 'EUR'
    echo $status->result->orderNumber;
}

Customers

Create a customer

$customer = $client->customers()->create([
    'merchant_customer_id' => 'user-42', // your internal user ID
    'email'  => 'fan@god.ba',
    'name'   => 'Adnan Fest',
    'phone'  => '+38761000000',
]);

echo $customer->uuid; // Monri's UUID for this customer

Find a customer

// By Monri UUID
$customer = $client->customers()->find('cust-uuid-123');

// By your own customer ID
$customer = $client->customers()->findByMerchantId('user-42');

Update a customer

$customer = $client->customers()->update('cust-uuid-123', [
    'email' => 'new@god.ba',
    'city'  => 'Sarajevo',
]);

List customers

$customers = $client->customers()->list(limit: 50, offset: 0);

Delete a customer

$client->customers()->delete('cust-uuid-123');

Saved payment methods

$methods = $client->customers()->paymentMethods('cust-uuid-123');

foreach ($methods as $method) {
    echo $method->maskedPan;      // '411111******1111'
    echo $method->expirationDate; // '12/27'
    echo $method->token;          // pan_token for card-on-file payments
    echo $method->expired;        // bool
}

Card tokenization (frontend)

Generate a temporary token to pass to the Monri frontend SDK:

$token = $client->tokens()->generate();

// Pass these to your frontend
echo $token->id;
echo $token->timestamp;
echo $token->digest;

Error handling

use Kemo\Monri\Exception\ApiException;
use Kemo\Monri\Exception\MonriException;
use Kemo\Monri\Exception\NetworkException;

try {
    $payment = $client->payments()->create([...]);
} catch (ApiException $e) {
    // HTTP 4xx/5xx from Monri
    echo $e->statusCode;          // e.g. 422
    $data = $e->decodedBody();    // parsed response array
} catch (NetworkException $e) {
    // Connection failure, timeout
} catch (MonriException $e) {
    // Configuration error
}

Custom HTTP client

The default transport uses cURL. To use a PSR-18 client (e.g. Guzzle):

use Kemo\Monri\Http\PsrHttpClient;

$http = new PsrHttpClient($guzzle, $requestFactory, $streamFactory);

$client = new MonriClient($config, $http);

Development

composer test        # PHPUnit
composer cs-check    # php-cs-fixer (dry-run)
composer cs-fix      # php-cs-fixer (apply)
composer phpcs       # PHP_CodeSniffer
composer phpcbf      # PHP_CodeSniffer (auto-fix)
composer phpstan     # PHPStan (level max)

Environments

Constant Base URL
Environment::Test https://ipgtest.monri.com
Environment::Production https://ipg.monri.com

License

MIT - see LICENSE.

kemo/monri-client 适用场景与选型建议

kemo/monri-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 kemo/monri-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kemo/monri-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 kemo/monri-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-08