feat : Bridge pay

This commit is contained in:
2025-09-07 18:22:41 +08:00
parent cb7e8842d6
commit 33cd767477
11 changed files with 369 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?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\Bridge;
use App\Service\Test\Bridge\Pay\PaymentGateway;
use App\Service\Test\TestBaseService;
use Hyperf\Di\Annotation\Inject;
class PayService extends TestBaseService
{
/**
* @var PaymentGateway
*/
#[Inject('standard_payment')]
protected PaymentGateway $standardPaymentGateway;
/**
* @var PaymentGateway
*/
#[Inject('premium_payment')]
protected PaymentGateway $premiumPaymentGateway;
/**
* @return array
*/
public function handle(): array
{
$amount = $this->request->input('amount',100);
$type = $this->request->input('type','standard');
$payment = $type === 'premium' ? $this->premiumPaymentGateway : $this->standardPaymentGateway;
$payRes = $payment->processPayment($amount);
$refundRes = $payment->processRefund($amount);
$refundPreRes = $this->premiumPaymentGateway->processRefund($amount);
$payPreRes = $this->premiumPaymentGateway->processPayment($amount);
return $this->return->success('success',[
'pay_res' => $payRes,
'refund_res' => $refundRes,
'refund_pre_res' => $refundPreRes,
'pay_pre_res' => $payPreRes,
]);
}
}