spondonit/mobilpay

Laravel 10 mobilpay 包装器,基于 omnipay,使用 omnipay-mobilpay 驱动程序

v1.0.0 2023-08-09 07:53 UTC

This package is auto-updated.

Last update: 2024-09-09 10:29:07 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;
}	                

选项

订单 ID

/**
 * @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)