feat : Bridge pay
This commit is contained in:
55
app/Service/Test/Bridge/PayService.php
Normal file
55
app/Service/Test/Bridge/PayService.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user