mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Billplzs\ControllersLogic;
|
|
|
|
use ErrorException;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\Modules\Billplzs\Services\GetBillplzBill;
|
|
use App\Classes\Modules\Billplzs\DataTransferObjects\BillplzXSignatureObject;
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
|
|
|
class CallbackBillplzLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Callback Billplz',
|
|
'message' => 'You have successfully receive Billplz callback'
|
|
];
|
|
}
|
|
|
|
/** @var GetBillplzBill */
|
|
private $getBillplzBill;
|
|
|
|
/** @var UpdatesTransactionStatus */
|
|
private $updatesTransactionStatus;
|
|
|
|
|
|
/**
|
|
* CreateBookingLogic constructor.
|
|
* @param CreateGetBillplzBillsBillplzBill $getBillplzBill
|
|
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
|
*/
|
|
public function __construct(GetBillplzBill $getBillplzBill, UpdatesTransactionStatus $updatesTransactionStatus)
|
|
{
|
|
$this->getBillplzBill = $getBillplzBill;
|
|
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
* @throws \App\Classes\Exceptions\RequestValidationException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$billplzXSignatureObject = new BillplzXSignatureObject($request);
|
|
|
|
if(!$billplzXSignatureObject->isValidSignature()) throw new MalformedRequestException('Unable to get correct response from billplz server.');
|
|
|
|
$billPlz = $this->getBillplzBill->execute($request->input('id'));
|
|
|
|
if(!$billPlz) throw new MalformedRequestException('Unable to get correct response from billplz server.');
|
|
|
|
if($billPlz->state == 'paid') $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION);
|
|
|
|
return $this->response(['data' => $billPlz]);
|
|
|
|
}
|
|
} |