55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?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,
|
|
]);
|
|
}
|
|
} |