cynojine/mtn-momo

集成MTN的MomoPay支付网关的SDK

dev-master 2020-04-18 14:03 UTC

This package is auto-updated.

Last update: 2024-09-18 23:37:57 UTC


README

Mtn MoMo php Sdk

composer require cynojine/mtn-momo

Collections用于请求客户支付并检查交易状态。

  • collectionPrimaryKey: 开发者门户上Collections产品的主键。
  • collectionUserId: 在开发环境中,使用沙盒凭据,否则使用开发者门户上的凭据。
  • collectionApiSecret: 在开发环境中,使用沙盒凭据,否则使用开发者门户上的凭据。
<?php
require_once( MOMOPAY_PLUGIN_DIR_PATH . 'mtn-momopay-php-sdk/lib/Momopay.php' );
require_once( MOMOPAY_PLUGIN_DIR_PATH . 'mtn-momopay-php-sdk/lib/EventHandlerInterface.php' );
require_once( MOMOPAY_PLUGIN_DIR_PATH . 'mtn-momopay-php-sdk/lib/MomopayEventHandler.php' );

use MTN\MomopayEventHandler;
use MTN\Momopay;

$config = new Momopayconfig([ 
    // mandatory credentials
    'baseUrl'               => 'https://sandbox.momodeveloper.mtn.com', 
    'currency'              => 'EUR', 
    'targetEnvironment'     => 'sandbox', 

    // collection credentials
    "collectionApiSecret"   => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
    "collectionPrimaryKey"  => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
    "collectionUserId"      => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
]);


$collection = new MtnCollection($config); 

$params = [
    "mobileNumber"      => '0964686107', 
    "amount"            => '100', 
    "externalId"        => '554000302',
    "payerMessage"      => 'some note',
    "payeeNote"         => '1212'
];

$transactionId = $collection->requestToPay($params);

$transaction = $collection->getTransaction($transactionId);