定制 mtgofa/laravel-fawrypay 二次开发

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

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

mtgofa/laravel-fawrypay

最新稳定版本:1.2

Composer 安装命令:

composer require mtgofa/laravel-fawrypay

包简介

Laravel FawryPay online payment gateway package

README 文档

README

A Laravel online payment gateway.

Installation

Require via composer

composer require mtgofa/laravel-fawrypay

run this command to generate the FawryPay configuration file

php artisan vendor:publish --provider="MTGofa\FawryPay\FawryPayServiceProvider"

Any method gets the credentials from config/fawrypay.php file, so fill in merchant_code and secure_key before make any request.

config/fawrypay.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | FawryPay Enviroment
    |--------------------------------------------------------------------------
    |
    | should be on of this ('TEST','LIVE').
    |
    */

    'enviroment' => 'TEST',

    /*
    |--------------------------------------------------------------------------
    | FawryPay Credentials (Test)
    |--------------------------------------------------------------------------
    |
    | use your fawrypay test credentials
    |
    */
    'merchant_code_test' => '',
    'secure_key_test' => '',

    /*
    |--------------------------------------------------------------------------
    | FawryPay Credentials (LIVE)
    |--------------------------------------------------------------------------
    |
    | use your fawrypay live credentials
    |
    */
    'merchant_code' => '',
    'secure_key' => '',
    
    /*
    |--------------------------------------------------------------------------
    | FawryPay Expiry
    |--------------------------------------------------------------------------
    |
    | use 1 for one hour, 24 for one day, 72 for 3 days and etc
    |
    */
    'expiry_in_hours' => '72',
];

How to use

Generate fawry pay url

use MTGofa\FawryPay\FawryPay;

public function generate(){
    $fawryPay = new FawryPay;

    //optional if you have the customer data
    $fawryPay->customer([
    	'customerProfileId' => '1',
    	'name'              => 'Mohamed Tarek',
    	'email'             => 'example@site.com',
    	'mobile'            => '010******',
    ]);
        
    //you can add this method info foreach if you have multible items
    $fawryPay->addItem([
    	'productSKU'    => '1', //item id
    	'description'   => 'Order 100001 Invoice', //item name
    	'price'         => '50.00', //item price
    	'quantity'      => '1', //item quantity
    ]);

    //generatePayURL('your order unique id','your order discription','success url','failed url')
    $pay_url = $fawryPay->generatePayURL('100001','Order 100001 Invoice','http://success_url','http://failed_url');
    return redirect($pay_url);
}

Redirect response / Callback Response / Check status

use MTGofa\FawryPay\FawryPay;

public function callback(){

    $ref_id = NULL;
    if(request('merchantRefNum')){ //fawry failed
        $ref_id = request('merchantRefNum');
    } elseif(request('MerchantRefNo')){ //fawry ipn
        $ref_id = request('MerchantRefNo');
    } elseif(request('chargeResponse')){ //fawry response is success
        $chargeResponse = json_decode(request('chargeResponse'));
        $ref_id = isset($chargeResponse->merchantRefNumber)?$chargeResponse->merchantRefNumber:NULL;
    }

    if(!$ref_id) return abort('404');

    $response = (new FawryPay)->checkStatus($ref_id);
    if (isset($response->paymentStatus) and $response->paymentStatus=='PAID') { //paid
        dd('Paid Successfully',$response);
    } else {
        dd($response);
    }
}

Don't forget to excute the callback route from csrf token

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        '/your_callback_url_here'
    ];
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-01