myanmyanpay/mmpay-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

myanmyanpay/mmpay-php-sdk

Composer 安装命令:

composer require myanmyanpay/mmpay-php-sdk

包简介

PHP One Time MMQR generation and Payment integration software developement kit created by MyanMyanPay Team

README 文档

README

A professional, comprehensive PHP client library for integrating with the MMPay Payment Gateway. This SDK mimics the official Node.js SDK structure, providing robust utilities for payment creation, handshake authentication, and secure webhook verification.

📦 1. Installation

Requires PHP 7.4 or higher.

Install the package via Composer:

composer require myanmyanpay/mmpay-php-sdk

🚀 2. Configuration

To start, initialize the SDK with your Merchant credentials found in the MMPay Dashboard.

Implementation

use MMPay\MMPay;

$options = [
    'appId'          => 'YOUR_APP_ID',
    'publishableKey' => 'YOUR_PUBLISHABLE_KEY',
    'secretKey'      => 'YOUR_SECRET_KEY',
    'apiBaseUrl'     => '[https://api.mmpay.com](https://api.mmpay.com)'
];

$mmpayx = new MMPay($options);

Configuration Parameters

Parameter Type Required Description
appId string Yes Your unique Application ID.
publishableKey string Yes Public key used for identification.
secretKey string Yes Private key used for HMAC SHA256 signing.
apiBaseUrl string Yes The base URL for the MMPay API.

🛠 3. Create a Payment

pay This method automatically handles the required handshake and signature generation.

Method Signature

$mmpayx->pay($payload);

Implementation

try {
    $payload = [
        'orderId'       => 'ORD-SANDBOX-001',
        'amount'        => 5000,
        'currency'      => 'MMK',
        'callbackUrl'   => '[https://yoursite.com/webhook/mmpay](https://yoursite.com/webhook/mmpay)',
        'customMessage' => 'Thank you for shopping with us!', // Optional
        'items'         => [
            [
                'name'     => 'Premium Subscription',
                'amount'   => 5000,
                'quantity' => 1
            ]
        ]
    ];

    $response = $mmpayx->pay($payload);
    print_r($response);

} catch (Exception $e) {
    echo "Payment Failed: " . $e->getMessage();
}

Request Body (payload structure)

Field Type Required Description Example
orderId string Yes Your generated order ID for the order or system initiating the payment. "ORD-3983833"
amount number Yes The total transaction amount. 1500.50
callbackUrl string No The URL where the payment gateway will send transaction status updates. "https://yourserver.com/webhook"
currency string No The currency code (e.g., 'MMK'). "MMK"
customMessage string No Your Customization String
items Array<Object> No List of items included in the purchase. [{name: "Hat", amount: 1000, quantity: 1}]

Item Object

Field Type Description
name string The name of the item.
amount number The unit price of the item.
quantity number The number of units purchased.

Response Body Code (201)

{
  "orderId": "_trx_0012345",
  "status": "PENDING",
  "vendorQrRefId": "39233043003345",
  "transactionRefId": "39233043003345", // This is deprecated - transactionRefId will show only after payment is confirmed
  "amount": 2800,
  "currency": "MMK",
  "qr": "EMVco MMQR String => You_have_to_embed_as_qr_image_yourself"
}

🛠 4. Retrieve Payment

This method is used to retrieve a payment and MMQR related events.

Method Signature

$mmpayx->get($payload);

Implementation

try {
    $payload = [
        'orderId'     => 'ORD-LIVE-888'
    ];
    $response = $mmpayx->get($payload);
    if (isset($response['url'])) {
        header('Location: ' . $response['url']);
        exit;
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

Request Body (payload structure)

Field Type Required Description Example
orderId string Yes Your generated order ID for the order or system initiating the payment. "ORD-3983833"

Response Body Code (200)

{
  "orderId": "ORD-111111111",
  "appId": "MMP3883483",
  "amount": 1000,
  "vendor": "KBZPay",
  "method": "QR",
  "customMessage": "",
  "callbackUrl": "",
  "callbackUrlAt": "JSDateObject",
  "callbackUrlStatus": "SUCCESS",
  "status": "SUCCESS", //  'PENDING' | 'SUCCESS' | 'FAILED' | 'REFUNDED' | 'CANCELLED' | 'EXPIRED';
  "disbursementId": "289348734939",
  "disStatus": "SUCCESS",
  "condition": "TOUCHED", // TOUCHED | 'PRISTINE' | 'DIRTY' | 'EXPIRED'
  "createdAt": "JSDateObject",
  "transactionRefId": "939583046594",
  "vendorQrRefId": "48309449034",
  "qr": "EMVCo QR String::MMQR Standard",
}

🛠 5. Cancel Payment

This method is used to cancel a payment and all of its MMQR releated instances

Method Signature

$mmpayx->cancel($payload);

Implementation

try {
    $payload = [
        'orderId'     => 'ORD-LIVE-888'
    ];
    $response = $mmpayx->cancel($payload);
    if (isset($response['url'])) {
        header('Location: ' . $response['url']);
        exit;
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

Request Body (payload structure)

Field Type Required Description Example
orderId string Yes Your generated order ID for the order or system initiating the payment. "ORD-3983833"

Response Body Code (200)

{
  "amount": 1000,
  "orderId": "ORD-111111111",
  "status": "CANCELLED",
  "vendorQrRefId": "289348734939",
}

🔐 6. Handling Webhooks

To secure your webhook endpoint that receives callbacks from the MMPay server, use this event listener to handle the events. The listen performs the mandatory Signature and Nonce verification and emits events

Handling callbacks

Incoming HTTP POST Parameters

Header

Field Name Type Required Description
Content-Type string Yes 'application/json'
X-Mmpay-Signature string Yes '34834890vfgh9hnf94irfg_48932i4rt90349849'
X-Mmpay-Nonce string Yes '94843943949349'

Body

Field Name Type Required Description
orderId string Yes Unique identifier for the specific order.
amount number Yes The transaction amount.
currency string Yes The 3-letter currency code (e.g., MMK, USD).
vendor string Yes Identifier for the vendor initiating the request.
method 'QR', 'PIN', 'PWA', 'CARD' Yes Identifier for the method.
status 'PENDING','SUCCESS','FAILED','REFUNDED', 'EXPIRED', 'CANCELLED' Yes Current status of the transaction.
condition 'PRESTINE', 'TOUCHED', 'EXPIRED', 'DIRTY' Yes Used QR Code scan again or not
transactionRefId string Yes The reference ID generated by the payment provider after success payment
vendorQrRefId string Yes The MMQR reference ID generated by the payment provider.
callbackUrl string No Optional URL to receive webhooks or updates.
customMessage string No User provided custom message

Example Implementation With Laravel

In Laravel, you should use the Request object to fetch headers and the raw content.

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use MMPay\MMPay;

class PaymentWebhookController extends Controller
{
    public function handle(Request $request)
    {
        $mmpayx = new MMPay([
            'appId' => config('services.mmpay.app_id'),
            'publishableKey' => config('services.mmpay.publish_key'),
            'secretKey' => config('services.mmpay.secret_key'),
            'apiBaseUrl' => 'https://api.myanmyanpay.com'
        ]);

        $mmpayx->onTxCreate(function ($tx) {
            \Log::info("Payment Created for order: " . $tx['orderId']);
            // Verify Source of truth here if you are using browser mmpayx showPaymentModal()
        });

        // Attach listeners
        $mmpayx->onTxSuccess(function ($tx) {
            // Update your database order status here
            \Log::info("Payment Successful for order: " . $tx['orderId']);
        });

        $mmpayx->onTxFail(function ($tx) {
            \Log::error("Payment Failed for order: " . $tx['orderId']);
        });

        $mmpayx->onTxCancel(function ($tx) {
            \Log::info("Payment Cancelled for order: " . $tx['orderId']);
        });

        $mmpayx->onTxExpire(function ($tx) {
            \Log::info("Payment Expired for order: " . $tx['orderId']);
        });

        $mmpayx->onHeartbeat(function ($tx) {
            \Log::info("Already Sent Event Coming in Again: " . $tx['orderId']);
        });

        // Get headers and raw body
        $nonce = $request->header('X-Mmpay-Nonce');
        $signature = $request->header('X-Mmpay-Signature');
        $payload = $request->getContent();

        // Listen triggers the events
        $mmpayx->listen($payload, $nonce, $signature);

        return response()->json(['received' => true], 200);
    }
}

⚠️ 7. Error Handling

The mmpayx throws standard PHP \Exception when errors occur (e.g., network issues, API validation errors, or handshake failures).

try {
    $sdk->pay($params);
} catch (\Exception $e) {
    // Log the error for debugging
    error_log($e->getMessage());
    
    // Return a user-friendly message
    echo "We could not process your payment at this time.";
}

⚠️ 8. Error Codes

HMac Layer (SERVER Side)

Code Description
KA0001 Bearer Token Not Included In Your Request
KA0002 API Key Not 'LIVE'
KA0003 Signature mismatch
KA0004 Internal Server Error ( Talk to our support immediately fot this )
KA0005 IP Not whitelisted
429 Ratelimit hit only 1000 request / minute allowed

JWT Layer (SERVER Side)

Code Description
BA001 Btoken is nonce one time token is not included
BA002 Btoken one time nonce mismatch
BA000 Internal Server Error ( Talk to our support immediately fot this )
429 Ratelimit hit only 1000 request / minute allowed

Response Codes

Code Status Description
201 Created Transaction initiated successfully. Response contains QR code URL/details.
401 Unauthorized Invalid or missing Publishable Key.
400 Bad Request Missing required body fields (validated by schema, if implemented).
503 Service Unavailable Upstream payment API failed or is unreachable.
500 Internal Server Error General server error during payment initiation.

📄 License

MIT License.

myanmyanpay/mmpay-php-sdk 适用场景与选型建议

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

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

围绕 myanmyanpay/mmpay-php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-23