feat : pay Adapter
Some checks are pending
Build Docker / build (push) Waiting to run

This commit is contained in:
2025-09-04 23:08:54 +08:00
parent 595d3d3276
commit f4b812f861
25 changed files with 694 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Adapter;
use App\Service\Test\TestBaseService;
class CacheService extends TestBaseService
{
public function handle()
{
//todo Write logic
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Adapter\Pay;
use App\Interface\Test\Adapter\PaymentGateway;
class AlipayAdapter implements PaymentGateway
{
/**
* @var AlipayService
*/
private AlipayService $alipay;
public function __construct(AlipayService $alipay)
{
$this->alipay = $alipay;
}
/**
* @param float $amount
* @return array
*/
public function pay(float $amount): array
{
return $this->alipay->sendPayment($amount);
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Adapter\Pay;
class AlipayService
{
/**
* @param float $amount
* @return array
*/
public function sendPayment(float $amount): array
{
return [
'code' => 'success',
'amount' => $amount,
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Adapter\Pay;
use App\Interface\Test\Adapter\PaymentGateway;
class WechatPayAdapter implements PaymentGateway
{
/**
* @var WechatPayService
*/
private WechatPayService $wechatPay;
public function __construct(WechatPayService $wechatPay)
{
$this->wechatPay = $wechatPay;
}
/**
* @param float $amount
* @return array
*/
public function pay(float $amount): array
{
return $this->wechatPay->makePayment($amount);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Adapter\Pay;
class WechatPayService
{
/**
* @param float $amount
* @return array
*/
public function makePayment(float $amount): array
{
return [
'code' => 'error',
'status' => 'fail',
'amount' => $amount,
];
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Adapter;
use App\Service\Test\Adapter\Pay\AlipayAdapter;
use App\Service\Test\Adapter\Pay\AlipayService;
use App\Service\Test\Adapter\Pay\WechatPayAdapter;
use App\Service\Test\Adapter\Pay\WechatPayService;
use App\Service\Test\TestBaseService;
class PayService extends TestBaseService
{
public function handle()
{
$alipayRes = (new AlipayAdapter(new AlipayService))->pay(100.00);
echo 'alipayRes:'. json_encode($alipayRes).PHP_EOL;
$wechatPay = new WechatPayService();
$wechatPayAdapter = new WechatPayAdapter($wechatPay);
$wechatPayRes = $wechatPayAdapter->pay(100.00);
echo 'wechatPayRes:'. json_encode($wechatPayRes).PHP_EOL;
return $this->return->success('success',[
'alipayRes' => $alipayRes,
'wechatPayRes' => $wechatPayRes,
]);
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test;
use App\Service\BaseService;
class AdapterTestService extends TestBaseService
{
public function handle(): array
{
return $this->return->success();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Service\Test;
use App\Lib\Return\TestReturn;
use App\Service\BaseService;
use Hyperf\Di\Annotation\Inject;
abstract class TestBaseService extends BaseService
{
/**
* @var TestReturn
*/
#[Inject]
protected TestReturn $return;
abstract public function handle();
}