malico/momo

此包已被放弃,不再维护。作者建议使用 malico/laravel-mesomb 包。

Laravel 插件,用于简化 MTN 移动支付。

2.2.0 2020-04-10 20:24 UTC

This package is auto-updated.

Last update: 2020-08-12 00:53:42 UTC


README

安装

composer require malico/momo

设置

Laravel(仅限)

  1. 使用 php artisan vendor:publish --tag=momo-configuration 发布配置文件

  2. 更新 app/momo.php 文件,包含适当的配置。

    配置

    • email - 用于在 https://developer.mtn.cm 上创建账户的服务

      MOMO_EMAIL=email_address (.env)

    • default_price - 默认价格(金额)

      MOMO_DEFAULT_PRICE=100 (.env),默认:100

    • foreign_key - 在你的迁移中持有交易的列名

      • 确保你更新了迁移以匹配配置文件中提供的 foreign_key,如果你想要使用 MomoTransaction 特性。
        Schema::table('sales', function (Blueprint $table) {
              $table->integer('momo_transaction_id')->nullable();
          });
  3. 运行 php artisan migrate 来运行数据库迁移

用法

PHP
<?php

require 'composer/autoload.php';

use Malico\Momo\Momo;

$momo = new Momo('67777777', 100);
/**
 * Availabe Methods
 * 
 * $momo = (new Momo())
 *         ->amount(100)
 *         ->email('yourEmail@domain.com')
 *         ->tel(67777777);
 */

$momo->email('yourEmail@domain.com');

$transaction = $momo->pay();

/**
 * Transaction Properties
 *  - amount  // Amount [Int]
    - tel // User's tel [String]
    - status // Transaction Status [Bool]
    - comment // Comment [String]
    - reference // Reference ID [String]
    - receiver_tel // [String]
    - operation_type
    - transaction_id // Transaction ID [String]
    - desc // Trnsaction Description [Text]
 *  - 
 */
if($transaction->status){
    // Payment was successful
    // do something, save to Database or anyting
} else {
    // Failed Transaction
    // do something Display error message 
    // echo $transaction->desc;
}
  • 使用原生 PHP,始终包含 email() 方法来配置支付电子邮件
Laravel

将 MomoTransaction 特性添加到你的模型中,以将模型与交易模型和其他支付方法相关联

<?php
// app/Sale.php
// Eloquent Model
namespace App;

use Malico\Momo\Support\MomoTransaction;
use Illuminate\Database\Eloquent\Model;

class Sale extends Model
{
	// use Momo\Support\MomoTransaction Trait
    use MomoTransaction;

    ...
}
<?php
// SalesController.php
namespace App\Http\Controllers;

use App\Sale;
use Malico\Momo\Momo;
use Illuminate\Http\Request;

class SalesController extends Controller
{
    public function index()
    {
    	...
        $sale = new Sale();

        $sale->pay('672727272', 100);
        /**
         * Also 
         *    $sale->momo(676956703, 100)
                ->tel(678513819)
                ->amount(300)
                ->pay();
         */
        
        if ($sale->momo_transaction->status) {
            // Do something
            // ... code
        }  else {
           // Payment was unsucessful;
           // return view('incomeplte_payment', ['message' => $sale->momo_transaction->desc])
        }
    }
}

贡献

欢迎所有贡献,但在开始工作于一个新特性之前,请先作为一个新问题提出。记住,干净代码很重要。

许可证

MIT