|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Controller\Payment;
|
|
|
|
|
|
|
|
use App\Exception\BusinessException;
|
|
|
|
use App\Helper\Efps\Api;
|
|
|
|
use App\Request\BindCardConfirmRequest;
|
|
|
|
use App\Request\BindCardRequest;
|
|
|
|
use App\Request\JsapiPayRequest;
|
|
|
|
use App\Request\ProtocolPayConfirmRequest;
|
|
|
|
use App\Request\ProtocolPayPreRequest;
|
|
|
|
use App\Request\RegisterRequest;
|
|
|
|
use App\Request\UnBindCardRequest;
|
|
|
|
use Hyperf\HttpServer\Contract\RequestInterface;
|
|
|
|
use App\Service\PaymentService;
|
|
|
|
|
|
|
|
class PayController extends AbstractController
|
|
|
|
{
|
|
|
|
private PaymentService $paymentService;
|
|
|
|
|
|
|
|
public function __construct(PaymentService $paymentService)
|
|
|
|
{
|
|
|
|
$this->paymentService = $paymentService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function jsapi(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$form = new JsapiPayRequest($request->all());
|
|
|
|
$order = $this->paymentService->jsapiPay($form->getApp(), $form->getData());
|
|
|
|
return $this->success([
|
|
|
|
'pay_url' => $order->pay_url,
|
|
|
|
'order_no' => $order->order_no,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function register(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$req = new RegisterRequest($request->all());
|
|
|
|
$result = Api::register($req->getData());
|
|
|
|
if (!$result->isSuccess()) {
|
|
|
|
throw new BusinessException($result->getMessage());
|
|
|
|
}
|
|
|
|
return $this->success($result->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bindCard(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$req = new BindCardRequest($request->all());
|
|
|
|
$result = Api::bindCard($req->getData());
|
|
|
|
if (!$result->isSuccess()) {
|
|
|
|
throw new BusinessException($result->getMessage());
|
|
|
|
}
|
|
|
|
return $this->success($result->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bindCardConfirm(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$req = new BindCardConfirmRequest($request->all());
|
|
|
|
$result = Api::bindCardConfirm($req->getData());
|
|
|
|
if (!$result->isSuccess()) {
|
|
|
|
throw new BusinessException($result->getMessage());
|
|
|
|
}
|
|
|
|
return $this->success($result->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unBindCard(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$req = new UnBindCardRequest($request->all());
|
|
|
|
$result = Api::unBindCard($req->getData());
|
|
|
|
if (!$result->isSuccess()) {
|
|
|
|
throw new BusinessException($result->getMessage());
|
|
|
|
}
|
|
|
|
return $this->success($result->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function protocolPayPreRequest(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$req = new ProtocolPayPreRequest($request->all());
|
|
|
|
$result = Api::protocolPayPre($req->getData());
|
|
|
|
if (!$result->isSuccess()) {
|
|
|
|
throw new BusinessException($result->getMessage());
|
|
|
|
}
|
|
|
|
return $this->success($result->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function protocolPayConfirm(RequestInterface $request)
|
|
|
|
{
|
|
|
|
$req = new ProtocolPayConfirmRequest($request->all());
|
|
|
|
$result = Api::protocolPayConfirm($req->getData());
|
|
|
|
if (!$result->isSuccess()) {
|
|
|
|
throw new BusinessException($result->getMessage());
|
|
|
|
}
|
|
|
|
return $this->success($result->getData());
|
|
|
|
}
|
|
|
|
}
|