Files
Xboard/plugins/Epay/Plugin.php
xboard b14477098d fix(epay): allow custom payment types via string input
- Replace select dropdown with string input for `type`
2025-09-05 16:16:30 +08:00

96 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Plugin\Epay;
use App\Services\Plugin\AbstractPlugin;
use App\Contracts\PaymentInterface;
class Plugin extends AbstractPlugin implements PaymentInterface
{
public function boot(): void
{
$this->filter('available_payment_methods', function ($methods) {
if ($this->getConfig('enabled', true)) {
$methods['EPay'] = [
'name' => $this->getConfig('display_name', '易支付'),
'icon' => $this->getConfig('icon', '💳'),
'plugin_code' => $this->getPluginCode(),
'type' => 'plugin'
];
}
return $methods;
});
}
public function form(): array
{
return [
'url' => [
'label' => '支付网关地址',
'type' => 'string',
'required' => true,
'description' => '请填写完整的支付网关地址包括协议http或https'
],
'pid' => [
'label' => '商户ID',
'type' => 'string',
'description' => '请填写商户ID',
'required' => true
],
'key' => [
'label' => '通信密钥',
'type' => 'string',
'required' => true,
'description' => '请填写通信密钥'
],
'type' => [
'label' => '支付类型',
'type' => 'string',
'description' => '支付类型,如: alipay, wxpay, qqpay 等,可自定义'
],
];
}
public function pay($order): array
{
$params = [
'money' => $order['total_amount'] / 100,
'name' => $order['trade_no'],
'notify_url' => $order['notify_url'],
'return_url' => $order['return_url'],
'out_trade_no' => $order['trade_no'],
'pid' => $this->getConfig('pid')
];
if ($paymentType = $this->getConfig('type')) {
$params['type'] = $paymentType;
}
ksort($params);
$str = stripslashes(urldecode(http_build_query($params))) . $this->getConfig('key');
$params['sign'] = md5($str);
$params['sign_type'] = 'MD5';
return [
'type' => 1,
'data' => $this->getConfig('url') . '/submit.php?' . http_build_query($params)
];
}
public function notify($params): array|bool
{
$sign = $params['sign'];
unset($params['sign'], $params['sign_type']);
ksort($params);
$str = stripslashes(urldecode(http_build_query($params))) . $this->getConfig('key');
if ($sign !== md5($str)) {
return false;
}
return [
'trade_no' => $params['out_trade_no'],
'callback_no' => $params['trade_no']
];
}
}