1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-28 13:21:37 +08:00
course-tencent-cloud/app/Services/Pay/AlipayGateway.php
2020-05-12 16:06:33 +08:00

70 lines
1.5 KiB
PHP

<?php
namespace App\Services\Pay;
use App\Services\Service;
use Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Pay;
class AlipayGateway extends Service
{
/**
* @var array
*/
protected $settings;
public function __construct($options = [])
{
$defaults = $this->getSectionSettings('pay.alipay');
$this->settings = array_merge($defaults, $options);
}
public function getSettings()
{
return $this->settings;
}
public function setReturnUrl($returnUrl)
{
$this->settings['return_url'] = $returnUrl;
}
public function setNotifyUrl($notifyUrl)
{
$this->settings['notify_url'] = $notifyUrl;
}
/**
* @return Alipay
*/
public function getInstance()
{
$config = $this->getDI()->get('config');
$level = $config->env == ENV_DEV ? 'debug' : 'info';
$payConfig = [
'app_id' => $this->settings['app_id'],
'ali_public_key' => $this->settings['public_key'],
'private_key' => $this->settings['private_key'],
'return_url' => $this->settings['return_url'],
'notify_url' => $this->settings['notify_url'],
'log' => [
'file' => log_path('alipay.log'),
'level' => $level,
'type' => 'daily',
'max_file' => 30,
],
];
if ($config->env == ENV_DEV) {
$payConfig['mode'] = 'dev';
}
return Pay::alipay($payConfig);
}
}