vlodapostol / mobilpay
Laravel 5 mobilpay包装器,基于omnipay和omnipay-mobilpay驱动程序
1.0.15
2020-12-14 12:35 UTC
Requires
- php: >=5.3.0
- illuminate/support: 5.* || 6.* || 7.*
- omnipay/common: ~3.0
- vlodapostol/omnipay-mobilpay: ^1.2.4
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') ->setTransactionType('sms') //add this parameter only if you want a transaction using SMS ->setService('your-product-hash') //add this parameter only if you want a transaction using SMS ->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)