Skip to content

Commit

Permalink
test: 增加epay测试用例&修复测试用例发现的的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaojie committed Jun 17, 2024
1 parent f0f4c7c commit 1f5f035
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 120 deletions.
6 changes: 4 additions & 2 deletions src/Plugin/Epay/CallbackPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Closure;
use Yansongda\Artful\Contract\PluginInterface;
use Yansongda\Artful\Direction\NoHttpRequestDirection;
use Yansongda\Artful\Exception\InvalidConfigException;
use Yansongda\Artful\Exception\InvalidParamsException;
use Yansongda\Artful\Exception\InvalidResponseException;
Expand All @@ -25,7 +26,7 @@ public function assembly(Rocket $rocket, Closure $next): Rocket
$this->formatRequestAndParams($rocket);

$params = $rocket->getParams();
$config = get_provider_config('alipay', $params);
$config = get_provider_config('epay', $params);

$payload = $rocket->getPayload();
$signature = $payload->get('sign');
Expand All @@ -35,7 +36,8 @@ public function assembly(Rocket $rocket, Closure $next): Rocket

$this->verifySign($config, $payload, $signature);

$rocket->setDestination($rocket->getPayload());
$rocket->setDirection(NoHttpRequestDirection::class)
->setDestination($rocket->getPayload());

Logger::info('[epay][CallbackPlugin] 插件装载完毕', ['rocket' => $rocket]);

Expand Down
33 changes: 0 additions & 33 deletions src/Plugin/Epay/GeneralPlugin.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Plugin/Epay/Pay/Scan/CancelPlugin.php

This file was deleted.

36 changes: 17 additions & 19 deletions src/Plugin/Epay/Pay/Scan/PrepayPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,39 @@

namespace Yansongda\Pay\Plugin\Epay\Pay\Scan;

use Yansongda\Artful\Exception\ContainerException;
use Closure;
use Yansongda\Artful\Contract\PluginInterface;
use Yansongda\Artful\Exception\InvalidConfigException;
use Yansongda\Artful\Exception\ServiceNotFoundException;
use Yansongda\Artful\Logger;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Plugin\Epay\GeneralPlugin;

use function Yansongda\Pay\get_provider_config;

class PrepayPlugin extends GeneralPlugin
class PrepayPlugin implements PluginInterface
{
protected function getService(): string
public function assembly(Rocket $rocket, Closure $next): Rocket
{
return 'atPay';
}
Logger::debug('[Epay][Pay][Scan][PrepayPlugin] 插件开始装载', ['rocket' => $rocket]);

/**
* @throws ServiceNotFoundException
* @throws ContainerException
*/
protected function doSomethingBefore(Rocket $rocket): void
{
if (!empty($rocket->getPayload()['notify_url'])) {
return;
}
$backUrl = $rocket->getPayload()['notify_url'] ?? null;
if (empty($backUrl)) {
$params = $rocket->getParams();
$config = get_provider_config('epay', $params);

$params = $rocket->getParams();
$config = get_provider_config('epay', $params);
$backUrl = $config['notify_url'] ?? null;
}

$backUrl = $config['notify_url'] ?? null;
if (!$backUrl) {
throw new InvalidConfigException(Exception::CONFIG_EPAY_INVALID, 'Missing Epay Config -- [notify_url]');
}
$rocket->mergePayload([
'service' => 'atPay',
'backUrl' => $backUrl,
]);

Logger::info('[Epay][Pay][Scan][PrepayPlugin] 插件装载完毕', ['rocket' => $rocket]);

return $next($rocket);
}
}
18 changes: 11 additions & 7 deletions src/Plugin/Epay/Pay/Scan/QueryPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

namespace Yansongda\Pay\Plugin\Epay\Pay\Scan;

use Closure;
use Yansongda\Artful\Contract\PluginInterface;
use Yansongda\Artful\Logger;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Plugin\Epay\GeneralPlugin;

class QueryPlugin extends GeneralPlugin
class QueryPlugin implements PluginInterface
{
protected function getService(): string
public function assembly(Rocket $rocket, Closure $next): Rocket
{
return 'payCheck';
}
Logger::debug('[Epay][Pay][Scan][QueryPlugin] 插件开始装载', ['rocket' => $rocket]);

protected function doSomethingBefore(Rocket $rocket): void
{
$rocket->mergePayload([
'deviceNo' => '1234567890',
'service' => 'payCheck',
]);

Logger::info('[Epay][Pay][Scan][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]);

return $next($rocket);
}
}
18 changes: 11 additions & 7 deletions src/Plugin/Epay/Pay/Scan/RefundPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

namespace Yansongda\Pay\Plugin\Epay\Pay\Scan;

use Closure;
use Yansongda\Artful\Contract\PluginInterface;
use Yansongda\Artful\Logger;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Plugin\Epay\GeneralPlugin;

class RefundPlugin extends GeneralPlugin
class RefundPlugin implements PluginInterface
{
protected function getService(): string
public function assembly(Rocket $rocket, Closure $next): Rocket
{
return 'payRefund';
}
Logger::debug('[Epay][Pay][Scan][RefundPlugin] 插件开始装载', ['rocket' => $rocket]);

protected function doSomethingBefore(Rocket $rocket): void
{
$rocket->mergePayload([
'deviceNo' => '1234567890',
'service' => 'payRefund',
]);

Logger::info('[Epay][Pay][Scan][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]);

return $next($rocket);
}
}
3 changes: 2 additions & 1 deletion src/Plugin/Epay/StartPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Closure;
use Yansongda\Artful\Contract\PluginInterface;
use Yansongda\Artful\Logger;
use Yansongda\Artful\Packer\QueryPacker;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Exception\ContainerException;
use Yansongda\Pay\Exception\InvalidConfigException;
Expand All @@ -29,7 +30,7 @@ public function assembly(Rocket $rocket, Closure $next): Rocket
$params = $rocket->getParams();
$config = get_provider_config('epay', $params);

$rocket->mergePayload(array_merge(
$rocket->setPacker(QueryPacker::class)->mergePayload(array_merge(
$params,
[
'createData' => date('Ymd'),
Expand Down
8 changes: 2 additions & 6 deletions src/Provider/Epay.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ public function mergeCommonPlugins(array $plugins): array

public function cancel($order): Collection|Rocket
{
$order = is_array($order) ? $order : ['outTradeNo' => $order];

Event::dispatch(new MethodCalled('epay', __METHOD__, $order, null));

return $this->__call('cancel', [$order]);
throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, 'Epay does not support cancel api');
}

public function close($order): Collection|Rocket
Expand All @@ -89,7 +85,7 @@ public function callback(null|array|ServerRequestInterface $contents = null, ?ar
{
$request = $this->getCallbackParams($contents);

Event::dispatch(new CallbackReceived('epay', $request, $params, null));
Event::dispatch(new CallbackReceived('epay', $request->all(), $params, null));

return $this->pay(
[CallbackPlugin::class],
Expand Down
30 changes: 0 additions & 30 deletions src/Shortcut/Epay/CancelShortcut.php

This file was deleted.

Loading

0 comments on commit 1f5f035

Please sign in to comment.