daika7ana / mobilpay

Laravel 5 mobilpay 包装器,基于 omnipay 和 omnipay-mobilpay 驱动程序

1.1.1 2021-05-24 13:22 UTC

This package is auto-updated.

Last update: 2024-09-05 14:23:24 UTC


README

Laravel 5 mobilpay 包装器,基于 omnipay 和 omnipay-mobilpay 驱动程序 编辑 添加主题

目录

安装

Composer

通过 composer 安装此包

composer require adrianbarbos/mobilpay

或者将包添加到你的 composer.json 文件中。

{
    "require": {
        "adrianbarbos/mobilpay": "^1.0"
    }
}

然后运行 composer update 以获取包的最新版本。

Laravel

Mobilpay 为 Laravel 提供了一个服务提供者。你需要在 composer.json 中添加它,如上述步骤中所述,然后注册服务提供者到你的应用程序。

从 Laravel 5.5 开始,服务提供者和外观将自动注册。

打开 config/app.php 并找到 providers 键。将 MobilpayServiceProvider 添加到数组中。

...
Adrianbarbos\Mobilpay\MobilpayServiceProvider::class,
...

在同一文件中将所需的别名添加到类别名列表中。

...
'Omnipay' => Omnipay\Omnipay::class,
'Mobilpay'	=> Adrianbarbos\Mobilpay\Mobilpay::class,
...

发布配置。

php artisan vendor:publish --provider="Adrianbarbos\Mobilpay\MobilpayServiceProvider"

基本用法

初始化支付请求

// controller function

Mobilpay::setOrderId(1)
        ->setAmount('10.00')
        ->setDetails('Some details')
        ->purchase();

处理响应

// controller function

$response = Mobilpay::response();

$data = $response->getData(); //array

switch($response->getMessage())
{
    case 'confirmed_pending': // transaction is pending review. After this is done, a new IPN request will be sent with either confirmation or cancellation

        //update DB, SET status = "pending"

        break;
    case 'paid_pending': // transaction is pending review. After this is done, a new IPN request will be sent with either confirmation or cancellation

        //update DB, SET status = "pending"

        break;
    case 'paid': // transaction is pending authorization. After this is done, a new IPN request will be sent with either confirmation or cancellation

        //update DB, SET status = "open/preauthorized"

        break;
    case 'confirmed': // transaction is finalized, the money have been captured from the customer's account

        //update DB, SET status = "confirmed/captured"

        break;
    case 'canceled': // transaction is canceled

        //update DB, SET status = "canceled"

        break;
    case 'credit': // transaction has been refunded

        //update DB, SET status = "refunded"

        break;
}	                

选项

订单号

/**
 * @param $value string
 * @return $this
 */

public function setOrderId($value)

金额

/**
 * @param $value string
 * @return $this
 */

public function setAmount($value)

货币

/**
 * @param $value string
 * @return $this
 */

public function setCurrency($value)

详细信息

/**
 * @param $value string
 * @return $this
 */

public function setDetails($value)

确认 URL

/**
 * @param $value string
 * @return $this
 */

public function setConfirmUrl($value)

返回 URL

/**
 * @param $value string
 * @return $this
 */

public function setReturnUrl($value)

测试模式

/**
 * @param $value boolean
 * @return $this
 */

public function setTestMode($value)

附加参数

/**
 * @param $value array
 * @return $this
 */

public function setAdditionalParams($value)