mirror of
https://gitee.com/yansongda/pay.git
synced 2024-11-29 18:58:38 +08:00
update
This commit is contained in:
parent
b260957148
commit
f9011f0993
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Data;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class BillDownloadUrlQueryPlugin extends GeneralPayPlugin
|
||||
class BillDownloadUrlQueryPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Data;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class BillEreceiptQueryPlugin extends GeneralPayPlugin
|
||||
class BillEreceiptQueryPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Ebpp;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class PdeductBillPayStatusPlugin extends GeneralPayPlugin
|
||||
class PdeductBillStatusPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Fund;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class AuthOrderUnfreezePlugin extends GeneralPayPlugin
|
||||
class AuthOrderUnfreezePlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Fund;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class TransOrderQueryPlugin extends GeneralPayPlugin
|
||||
class TransOrderQueryPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -9,18 +9,18 @@ use Yansongda\Pay\Contract\PluginInterface;
|
||||
use Yansongda\Pay\Logger;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
abstract class GeneralPayPlugin implements PluginInterface
|
||||
abstract class GeneralPlugin implements PluginInterface
|
||||
{
|
||||
public function assembly(Rocket $rocket, Closure $next): Rocket
|
||||
{
|
||||
Logger::info('[alipay][GeneralPayPlugin] 通用插件开始装载', ['rocket' => $rocket]);
|
||||
Logger::info('[alipay][GeneralPlugin] 通用插件开始装载', ['rocket' => $rocket]);
|
||||
|
||||
$rocket->mergePayload([
|
||||
'method' => $this->getMethod(),
|
||||
'biz_content' => $rocket->getParams(),
|
||||
]);
|
||||
|
||||
Logger::info('[alipay][GeneralPayPlugin] 通用插件装载完毕', ['rocket' => $rocket]);
|
||||
Logger::info('[alipay][GeneralPlugin] 通用插件装载完毕', ['rocket' => $rocket]);
|
||||
|
||||
return $next($rocket);
|
||||
}
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Open;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class AuthTokenAppPlugin extends GeneralPayPlugin
|
||||
class AuthTokenAppPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Open;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class AuthTokenAppQueryPlugin extends GeneralPayPlugin
|
||||
class AuthTokenAppQueryPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ namespace Yansongda\Pay\Plugin\Alipay\Shortcut;
|
||||
use Yansongda\Pay\Contract\ShortcutInterface;
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Alipay\Fund\TransOrderQueryPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\Trade\FastPayRefundQueryPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\Trade\FastRefundQueryPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\Trade\QueryPlugin;
|
||||
|
||||
class QueryShortcut implements ShortcutInterface
|
||||
@ -40,7 +40,7 @@ class QueryShortcut implements ShortcutInterface
|
||||
protected function refundPlugins(): array
|
||||
{
|
||||
return [
|
||||
FastPayRefundQueryPlugin::class,
|
||||
FastRefundQueryPlugin::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class CancelPlugin extends GeneralPayPlugin
|
||||
class CancelPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class ClosePlugin extends GeneralPayPlugin
|
||||
class ClosePlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class CreatePlugin extends GeneralPayPlugin
|
||||
class CreatePlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class FastPayRefundQueryPlugin extends GeneralPayPlugin
|
||||
class FastRefundQueryPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class OrderPayPlugin extends GeneralPayPlugin
|
||||
class OrderPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class OrderSettlePlugin extends GeneralPayPlugin
|
||||
class OrderSettlePlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class PreCreatePlugin extends GeneralPayPlugin
|
||||
class PreCreatePlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class QueryPlugin extends GeneralPayPlugin
|
||||
class QueryPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Alipay\Trade;
|
||||
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
|
||||
class RefundPlugin extends GeneralPayPlugin
|
||||
class RefundPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
@ -26,7 +26,9 @@ class ParserPlugin implements PluginInterface
|
||||
|
||||
$packer = $this->getPacker($rocket);
|
||||
|
||||
return $rocket->setDestination($packer->parse($rocket->getDestination()));
|
||||
return $rocket->setDestination(
|
||||
$packer->parse($rocket->getDestination())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
77
src/Plugin/Wechat/GeneralPlugin.php
Normal file
77
src/Plugin/Wechat/GeneralPlugin.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat;
|
||||
|
||||
use Closure;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Yansongda\Pay\Contract\PluginInterface;
|
||||
use Yansongda\Pay\Logger;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Provider\Wechat;
|
||||
use Yansongda\Pay\Request;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
abstract class GeneralPlugin implements PluginInterface
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
*/
|
||||
public function assembly(Rocket $rocket, Closure $next): Rocket
|
||||
{
|
||||
Logger::info('[wechat][GeneralPlugin] 通用插件开始装载', ['rocket' => $rocket]);
|
||||
|
||||
$this->checkPayload($rocket);
|
||||
$rocket->setRadar($this->getRequest($rocket));
|
||||
|
||||
Logger::info('[wechat][GeneralPlugin] 通用插件装载完毕', ['rocket' => $rocket]);
|
||||
|
||||
return $next($rocket);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function getRequest(Rocket $rocket): RequestInterface
|
||||
{
|
||||
return new Request(
|
||||
$this->getMethod(),
|
||||
$this->getUrl($rocket),
|
||||
$this->getHeaders(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getMethod(): string
|
||||
{
|
||||
return 'POST';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function getUrl(Rocket $rocket): string
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
return Wechat::URL[$config->get('mode', Pay::MODE_NORMAL)].
|
||||
$this->getUri($rocket);
|
||||
}
|
||||
|
||||
protected function getHeaders(): array
|
||||
{
|
||||
return [
|
||||
'Content-Type' => 'application/json',
|
||||
];
|
||||
}
|
||||
|
||||
abstract protected function checkPayload(Rocket $rocket): void;
|
||||
|
||||
abstract protected function getUri(Rocket $rocket): string;
|
||||
}
|
55
src/Plugin/Wechat/LaunchPlugin.php
Normal file
55
src/Plugin/Wechat/LaunchPlugin.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat;
|
||||
|
||||
use Closure;
|
||||
use Yansongda\Pay\Contract\PluginInterface;
|
||||
use Yansongda\Pay\Exception\InvalidResponseException;
|
||||
use Yansongda\Pay\Logger;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
class LaunchPlugin implements PluginInterface
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidResponseException
|
||||
*/
|
||||
public function assembly(Rocket $rocket, Closure $next): Rocket
|
||||
{
|
||||
Logger::info('[wechat][LaunchPlugin] 插件开始装载', ['rocket' => $rocket]);
|
||||
|
||||
/* @var Rocket $rocket */
|
||||
$rocket = $next($rocket);
|
||||
|
||||
if (should_do_http_request($rocket)) {
|
||||
$this->verifySign($rocket);
|
||||
|
||||
$rocket->setDestination($this->formatResponse($rocket));
|
||||
}
|
||||
|
||||
Logger::info('[wechat][LaunchPlugin] 插件装载完毕', ['rocket' => $rocket]);
|
||||
|
||||
return $rocket;
|
||||
}
|
||||
|
||||
protected function verifySign(Rocket $rocket): void
|
||||
{
|
||||
// todo
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidResponseException
|
||||
*/
|
||||
protected function formatResponse(Rocket $rocket): Collection
|
||||
{
|
||||
$response = $rocket->getDestination();
|
||||
|
||||
if (isset($response['code'])) {
|
||||
throw new InvalidResponseException(InvalidResponseException::INVALID_RESPONSE_CODE);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -4,13 +4,29 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi;
|
||||
|
||||
use Closure;
|
||||
use Yansongda\Pay\Contract\PluginInterface;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class PrepayPlugin implements PluginInterface
|
||||
class PrepayPlugin extends GeneralPlugin
|
||||
{
|
||||
public function assembly(Rocket $rocket, Closure $next): Rocket
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
return 'v3/pay/transactions/jsapi';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
$rocket->mergePayload([
|
||||
'appid' => $config->get('mp_app_id', ''),
|
||||
'mchid' => $config->get('mch_id', ''),
|
||||
'notify_url' => $config->get('notify_url'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
29
src/Plugin/Wechat/Pay/Jsapi/QueryPlugin.php
Normal file
29
src/Plugin/Wechat/Pay/Jsapi/QueryPlugin.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Jsapi;
|
||||
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryPlugin extends GeneralPlugin
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
return 'v3/pay/transactions/id/'.
|
||||
($rocket->getParams()['transaction_id'] ?? '').
|
||||
'?mchid='.$config->get('mch_id', '');
|
||||
}
|
||||
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
{
|
||||
}
|
||||
}
|
29
src/Plugin/Wechat/PreparePlugin.php
Normal file
29
src/Plugin/Wechat/PreparePlugin.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat;
|
||||
|
||||
use Closure;
|
||||
use Yansongda\Pay\Contract\PluginInterface;
|
||||
use Yansongda\Pay\Logger;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class PreparePlugin implements PluginInterface
|
||||
{
|
||||
public function assembly(Rocket $rocket, Closure $next): Rocket
|
||||
{
|
||||
Logger::info('[wechat][PreparePlugin] 插件开始装载', ['rocket' => $rocket]);
|
||||
|
||||
$rocket->mergePayload($this->getPayload($rocket->getParams()));
|
||||
|
||||
Logger::info('[wechat][PreparePlugin] 插件装载完毕', ['rocket' => $rocket]);
|
||||
|
||||
return $next($rocket);
|
||||
}
|
||||
|
||||
protected function getPayload(array $params): array
|
||||
{
|
||||
return $params;
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ namespace Yansongda\Pay\Tests\Plugin\Alipay;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Yansongda\Pay\Parser\ResponseParser;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPayPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class GeneralPayPluginTest extends TestCase
|
||||
@ -22,7 +22,7 @@ class GeneralPayPluginTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
class FooPlugin extends GeneralPayPlugin
|
||||
class FooPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function getMethod(): string
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user