baselrabia/paymob

帮助进行Paymob集成的包

1.0.0 2021-08-19 01:07 UTC

This package is auto-updated.

Last update: 2024-09-19 08:23:52 UTC


README

Laravel PayMob
Latest Stable Version Total Downloads

Paymob 对 Laravel 的集成。

当前支持

安装

  • 安装此包

    composer require baselrabia/paymob
  • 使用以下命令发布包资源

    php artisan vendor:publish --provider="Basel\PayMob\PayMobServiceProvider"

配置


  • 更新您的 .env 文件
ACCEPT_API_KEY=
ACCEPT_MERCHANT_ID=
ACCEPT_CARD_IFRAME_ID=
ACCEPT_CARD_INTEGRATION_ID=
ACCEPT_MW_INTEGRATION_ID=

设置

  • 将包路由添加到您的 routes/web.php 中,例如。

    Route::group([
        'prefix'     => 'orders',
        'as'         => 'order.',
        'middleware' => 'auth',
    ], function () {
        Basel\PayMob\PayMobRoutes::routes();
    });
    
    // OR You Can Use your Own routes like this 
    // I used the package in Apis to provide Payment with the mobile APP
        Route::group([
          'prefix'     => 'payment',
          'as'         => 'order.',
          // 'middleware' => ,
      ],
          function () {
              // ctf0\PayMob\PayMobRoutes::routes();
    
              $controller = config('paymob.controller', '\Basel\PayMob\Controllers\DummyController');
    
              // Route::get('checkout', [
              //     'as'   => 'checkout',
              //     'uses' => "$controller@checkOut",
              // ]);
    
              Route::post('process', [
                  'as'   => 'process',
                  'uses' => "$controller@process",
              ])->middleware(['auth:student', 'scopes:student']);
    
              Route::get('complete', [
                  'as'   => 'complete',
                  'uses' => "$controller@complete",
              ]);
    
              Route::get('failed', [
                  'as'   => 'failed',
                  'uses' => "$controller@failed",
              ]);
          }
      );
  • Billable 添加到您将进行账单的模型中。

  • 接下来添加 getBillingData(),它应返回创建订单所需的所有字段,有关更多信息,请参阅paymob 要求

    • 所有 可选 字段已处理。
    use Basel\PayMob\Integrations\Contracts\Billable;
    
    class Client implements Billable
    {
        // ...
    
        public function getBillingData(): array
        {
            return [
                'email'        => $this->email,
                'first_name'   => $this->first_name,
                'last_name'    => $this->last_name,
                'street'       => $this->address ?? "NA",
                'phone_number' => $this->phone_number,
            ];
        }
    }

用法

# 正常

# 退款

  • 您需要做的就是调用 PayMob::refund 并传递给它的 transaction_id 以及将退回的 amount_in_pounds,例如。

    有关更多信息,请查看

    PayMob::refund(655, 10);