This commit is contained in:
yansongda 2021-07-05 22:40:29 +08:00
parent 2812d6817a
commit 0e74e6146f
16 changed files with 106 additions and 28 deletions

View File

@ -6,12 +6,15 @@ namespace Yansongda\Pay\Plugin\Alipay\Data;
use Closure;
use Yansongda\Pay\Contract\PluginInterface;
use Yansongda\Pay\Logger;
use Yansongda\Pay\Rocket;
class BillEreceiptApplyPlugin implements PluginInterface
{
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::info('[alipay][BillEreceiptApplyPlugin] 插件开始装载', ['rocket' => $rocket]);
$rocket->mergePayload([
'method' => 'alipay.data.bill.ereceipt.apply',
'biz_content' => array_merge(
@ -22,6 +25,8 @@ class BillEreceiptApplyPlugin implements PluginInterface
),
]);
Logger::info('[alipay][BillEreceiptApplyPlugin] 插件装载完毕', ['rocket' => $rocket]);
return $next($rocket);
}
}

View File

@ -6,12 +6,15 @@ namespace Yansongda\Pay\Plugin\Alipay\Ebpp;
use Closure;
use Yansongda\Pay\Contract\PluginInterface;
use Yansongda\Pay\Logger;
use Yansongda\Pay\Rocket;
class PdeductPayPlugin implements PluginInterface
{
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::info('[alipay][PdeductPayPlugin] 插件开始装载', ['rocket' => $rocket]);
$rocket->mergePayload([
'method' => 'alipay.ebpp.pdeduct.pay',
'biz_content' => array_merge(
@ -22,6 +25,8 @@ class PdeductPayPlugin implements PluginInterface
),
]);
Logger::info('[alipay][PdeductPayPlugin] 插件装载完毕', ['rocket' => $rocket]);
return $next($rocket);
}
}

View File

@ -6,12 +6,15 @@ namespace Yansongda\Pay\Plugin\Alipay\Ebpp;
use Closure;
use Yansongda\Pay\Contract\PluginInterface;
use Yansongda\Pay\Logger;
use Yansongda\Pay\Rocket;
class PdeductSignAddPlugin implements PluginInterface
{
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::info('[alipay][PdeductSignAddPlugin] 插件开始装载', ['rocket' => $rocket]);
$rocket->mergePayload([
'method' => 'alipay.ebpp.pdeduct.sign.add',
'biz_content' => array_merge(
@ -24,6 +27,8 @@ class PdeductSignAddPlugin implements PluginInterface
),
]);
Logger::info('[alipay][PdeductSignAddPlugin] 插件装载完毕', ['rocket' => $rocket]);
return $next($rocket);
}
}

View File

@ -6,12 +6,15 @@ namespace Yansongda\Pay\Plugin\Alipay\Ebpp;
use Closure;
use Yansongda\Pay\Contract\PluginInterface;
use Yansongda\Pay\Logger;
use Yansongda\Pay\Rocket;
class PdeductSignCancelPlugin implements PluginInterface
{
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::info('[alipay][PdeductSignCancelPlugin] 插件开始装载', ['rocket' => $rocket]);
$rocket->mergePayload([
'method' => 'alipay.ebpp.pdeduct.sign.cancel',
'biz_content' => array_merge(
@ -22,6 +25,8 @@ class PdeductSignCancelPlugin implements PluginInterface
),
]);
Logger::info('[alipay][PdeductSignCancelPlugin] 插件装载完毕', ['rocket' => $rocket]);
return $next($rocket);
}
}

View File

@ -22,11 +22,11 @@ class LaunchPlugin implements PluginInterface
*/
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::info('[alipay][LaunchPlugin] 插件开始装载', ['rocket' => $rocket]);
/* @var Rocket $rocket */
$rocket = $next($rocket);
Logger::info('[alipay][LaunchPlugin] 插件开始装载', ['rocket' => $rocket]);
if (should_do_http_request($rocket)) {
$this->verifySign($rocket);

View File

@ -22,11 +22,11 @@ class LaunchPlugin implements PluginInterface
*/
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::info('[wechat][LaunchPlugin] 插件开始装载', ['rocket' => $rocket]);
/* @var Rocket $rocket */
$rocket = $next($rocket);
Logger::info('[wechat][LaunchPlugin] 插件开始装载', ['rocket' => $rocket]);
if (should_do_http_request($rocket)) {
verify_wechat_sign($rocket->getDestinationOrigin(), $rocket->getParams());

View File

@ -23,11 +23,11 @@ class InvokePrepayPlugin implements PluginInterface
*/
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::info('[wechat][InvokePrepayPlugin] 插件开始装载', ['rocket' => $rocket]);
/* @var Rocket $rocket */
$rocket = $next($rocket);
Logger::info('[wechat][InvokePrepayPlugin] 插件开始装载', ['rocket' => $rocket]);
$prepayId = $rocket->getPayload()->get('prepay_id');
if (is_null($prepayId)) {

View File

@ -3,9 +3,8 @@
namespace Yansongda\Pay\Tests\Plugin\Alipay;
use PHPUnit\Framework\TestCase;
use Yansongda\Pay\Parser\ResponseParser;
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\Stubs\Plugin\AlipayGeneralPluginStub;
class GeneralPayPluginTest extends TestCase
{
@ -14,7 +13,7 @@ class GeneralPayPluginTest extends TestCase
$rocket = new Rocket();
$rocket->setParams([]);
$plugin = new FooPlugin();
$plugin = new AlipayGeneralPluginStub();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
@ -22,10 +21,3 @@ class GeneralPayPluginTest extends TestCase
}
}
class FooPlugin extends GeneralPlugin
{
protected function getMethod(): string
{
return 'yansongda';
}
}

View File

@ -9,6 +9,7 @@ use Yansongda\Pay\Parser\NoHttpRequestParser;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\ParserPlugin;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\Stubs\FooPackerStub;
class ParserPluginTest extends TestCase
{
@ -52,7 +53,3 @@ class ParserPluginTest extends TestCase
self::assertSame($rocket, $result);
}
}
class FooPackerStub
{
}

View File

@ -0,0 +1,30 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat;
use GuzzleHttp\Psr7\Uri;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\Stubs\Plugin\WechatGeneralPluginStub;
class GeneralPluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([]);
$plugin = new WechatGeneralPluginStub();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertInstanceOf(RequestInterface::class, $radar);
self::assertEquals('POST', $radar->getMethod());
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'yansongda/pay'), $radar->getUri());
}
}

View File

@ -15,6 +15,7 @@ use Yansongda\Pay\Plugin\Alipay\PreparePlugin;
use Yansongda\Pay\Plugin\Alipay\RadarPlugin;
use Yansongda\Pay\Plugin\Alipay\SignPlugin;
use Yansongda\Pay\Plugin\ParserPlugin;
use Yansongda\Pay\Tests\Stubs\Plugin\FooPluginStub;
class AlipayTest extends TestCase
{
@ -224,11 +225,3 @@ class AlipayTest extends TestCase
), Pay::alipay()->mergeCommonPlugins($plugins));
}
}
class FooPluginStub
{
}
class FooShortcut
{
}

View File

@ -9,6 +9,7 @@ use Yansongda\Pay\Plugin\ParserPlugin;
use Yansongda\Pay\Plugin\Wechat\LaunchPlugin;
use Yansongda\Pay\Plugin\Wechat\PreparePlugin;
use Yansongda\Pay\Plugin\Wechat\SignPlugin;
use Yansongda\Pay\Tests\Stubs\Plugin\FooPluginStub;
class WechatTest extends TestCase
{

View File

@ -0,0 +1,7 @@
<?php
namespace Yansongda\Pay\Tests\Stubs;
class FooPackerStub
{
}

View File

@ -0,0 +1,13 @@
<?php
namespace Yansongda\Pay\Tests\Stubs\Plugin;
use Yansongda\Pay\Plugin\Alipay\GeneralPlugin;
class AlipayGeneralPluginStub extends GeneralPlugin
{
protected function getMethod(): string
{
return 'yansongda';
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace Yansongda\Pay\Tests\Stubs\Plugin;
class FooPluginStub
{
}

View File

@ -0,0 +1,18 @@
<?php
namespace Yansongda\Pay\Tests\Stubs\Plugin;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
class WechatGeneralPluginStub extends GeneralPlugin
{
protected function doSomething(Rocket $rocket): void
{
}
protected function getUri(Rocket $rocket): string
{
return 'yansongda/pay';
}
}