mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
payment transaction
This commit is contained in:
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Billplzs\ControllersLogic;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||||
|
use App\Classes\Modules\Wallets\Services\UpdatesWallet;
|
||||||
|
|
||||||
|
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||||
|
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
|
||||||
|
use App\Http\Resources\TransactionResource;
|
||||||
|
use App\Models\Booking;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Wallet;
|
||||||
|
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\FetchesTransaction;
|
||||||
|
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class CallbackBillplzLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/** @var GetBillplzBill */
|
||||||
|
private $getBillplzBill;
|
||||||
|
|
||||||
|
/** @var FetchesTransaction */
|
||||||
|
private $fetchesTransaction;
|
||||||
|
|
||||||
|
/** @var UpdatesTransactionStatus */
|
||||||
|
private $updatesTransactionStatus;
|
||||||
|
|
||||||
|
/** @var UpdatesWalletBalance */
|
||||||
|
private $updatesWalletBalance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CallbackBillplzLogic constructor.
|
||||||
|
* @param GetBillplzBill $getBillplzBill
|
||||||
|
* @param FetchesTransaction $fetchesTransaction
|
||||||
|
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||||
|
* @param UpdatesWalletBalance $updatesWalletBalance
|
||||||
|
*/
|
||||||
|
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdatesWalletBalance $updatesWalletBalance)
|
||||||
|
{
|
||||||
|
$this->getBillplzBill = $getBillplzBill;
|
||||||
|
$this->fetchesTransaction = $fetchesTransaction;
|
||||||
|
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||||
|
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
* @throws MalformedRequestException
|
||||||
|
* @throws ResourceNotFoundException
|
||||||
|
*/
|
||||||
|
public function execute(Request $request)
|
||||||
|
{
|
||||||
|
$billplzXSignatureObject = new BillplzXSignatureObject($request);
|
||||||
|
|
||||||
|
if(!$billplzXSignatureObject->isValidSignature()){
|
||||||
|
throw new MalformedRequestException('Billplz Payment validation failed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$billPlz = $this->getBillplzBill->execute($billplzXSignatureObject->getBillPlzId());
|
||||||
|
|
||||||
|
if(!$billPlz) throw new ResourceNotFoundException('Billplz bill not found.');
|
||||||
|
|
||||||
|
$transaction = $this->fetchesTransaction->execute(['payment_reference' => $billplzXSignatureObject->getBillPlzId()]);
|
||||||
|
|
||||||
|
if($billPlz->state === 'paid') {
|
||||||
|
$status = ApprovalStatus::APPROVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($billPlz->state === 'due') {
|
||||||
|
$status = $billplzXSignatureObject->getStatus() === 'failed' ? ApprovalStatus::REJECTED : ApprovalStatus::PENDING_VERIFICATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($transaction->status !== ApprovalStatus::COMPLETED){
|
||||||
|
|
||||||
|
if($transaction->owner instanceof Wallet && $transaction->status !== ApprovalStatus::APPROVED && $status === ApprovalStatus::APPROVED) {
|
||||||
|
$this->updatesWalletBalance->execute($transaction->owner, $transaction->amount);
|
||||||
|
}
|
||||||
|
$this->updatesTransactionStatus->execute($transaction, $status);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$token = Auth::fromUser(User::find(1));
|
||||||
|
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||||
|
|
||||||
|
$marking = $transaction->owner instanceof Booking ? $transaction->booking->marking : $transaction->owner->owner->bookings()->orderBy('id', 'DESC')->first()->marking;
|
||||||
|
|
||||||
|
return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $marking, 'transaction' => $transaction, 'status' => $status]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Billplzs\ControllersLogic;
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
||||||
|
|
||||||
|
use ErrorException;
|
||||||
|
use App\Classes\Exceptions\MalformedRequestException;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CreateBillplzBillLogic extends AbstractControllerLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function notification():array {
|
||||||
|
return [
|
||||||
|
'title' => 'Created Billplz Bill',
|
||||||
|
'message' => 'You have successfully created a new Bill'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var CreatesBillplzBill */
|
||||||
|
private $createsBillplzBill;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreateBookingLogic constructor.
|
||||||
|
* @param CreatesBillplzBill $createsBillplzBill
|
||||||
|
*/
|
||||||
|
public function __construct(CreatesBillplzBill $createsBillplzBill)
|
||||||
|
{
|
||||||
|
$this->createsBillplzBill = $createsBillplzBill;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return JsonResponse
|
||||||
|
* @throws MalformedRequestException
|
||||||
|
*/
|
||||||
|
public function logic(Request $request) : JsonResponse
|
||||||
|
{
|
||||||
|
$billPlz = $this->createsBillplzBill->execute($request->user()->name, $request->user()->email, $request->input('description'), 200, $request->input('bankName'));
|
||||||
|
|
||||||
|
if(!$billPlz) throw new MalformedRequestException('Unable to get correct response from billplz server.');
|
||||||
|
|
||||||
|
return $this->response(['data' => $billPlz]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Billplzs\DataTransferObjects;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Classes\General\Interfaces\DataTransferObject;
|
||||||
|
use function PHPSTORM_META\map;
|
||||||
|
|
||||||
|
class BillplzXSignatureObject implements DataTransferObject
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $billPlzId;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $status;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
private $billPlzConstructArray;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $billPlzConstructString;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $billPlzComputedXSignature;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $type;
|
||||||
|
|
||||||
|
/** @var Request */
|
||||||
|
private $request;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $requestXSignature;
|
||||||
|
|
||||||
|
public function __construct(Request $request)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->type = $request->exists('billplz') ? 'redirect' : 'callback';
|
||||||
|
|
||||||
|
$this->request = $this->type === 'redirect' ? $request->input('billplz') : $request;
|
||||||
|
|
||||||
|
$this->billPlzId = $this->request['id'];
|
||||||
|
|
||||||
|
$this->status = $this->request['transaction_status'];
|
||||||
|
|
||||||
|
$this->requestXSignature = $this->request['x_signature'];
|
||||||
|
|
||||||
|
$this->_constructBillplzArray()->_natSortBillplzArray()->_constructBillplzString()->_computeBillplzXSignature();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _constructBillplzArray(){
|
||||||
|
|
||||||
|
$this->billPlzConstructArray = collect($this->request)->forget('x_signature')->map(function($item, $key){
|
||||||
|
return $this->type === 'redirect' ? 'billplz'.$key.$item : $key.$item;
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _natCaseSortBillplzArray(){
|
||||||
|
natcasesort($this->billPlzConstructArray);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _natSortBillplzArray(){
|
||||||
|
natsort($this->billPlzConstructArray);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _constructBillplzString(){
|
||||||
|
$this->billPlzConstructString = implode('|', $this->billPlzConstructArray);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _computeBillplzXSignature(){
|
||||||
|
$this->billPlzComputedXSignature = hash_hmac('sha256', $this->billPlzConstructString, config('billplz.x_signature_key'));
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBillPlzId(): string
|
||||||
|
{
|
||||||
|
return $this->billPlzId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus(): string
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getBillPlzConstructArray(): array
|
||||||
|
{
|
||||||
|
return $this->billPlzConstructArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBillPlzConstructString(): string
|
||||||
|
{
|
||||||
|
return $this->billPlzConstructString;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBillPlzComputedXSignature(): string
|
||||||
|
{
|
||||||
|
return $this->billPlzComputedXSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValidSignature(): bool
|
||||||
|
{
|
||||||
|
return $this->billPlzComputedXSignature === $this->requestXSignature ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Billplzs\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use App\Classes\Exceptions\MalformedRequestException;
|
||||||
|
|
||||||
|
class CreatesBillplzBill
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param string $email
|
||||||
|
* @param string $description
|
||||||
|
* @param float $amount
|
||||||
|
* @param string $billNumber
|
||||||
|
* @param null|string $bankCode
|
||||||
|
* @param null|Boolean $wallet
|
||||||
|
* @return null|object
|
||||||
|
* @throws MalformedRequestException
|
||||||
|
*/
|
||||||
|
public function execute(string $name, string $email, string $description, float $amount, string $billNumber, ?string $bankCode = null, ?bool $wallet = null) {
|
||||||
|
try{
|
||||||
|
// config('billplz.maybank')
|
||||||
|
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->post(config('billplz.base_url').'/api/v3/bills', [
|
||||||
|
'collection_id' => $wallet ? config('billplz.wallet_collection_id') : config('billplz.collection_id'),
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
'description' => $description,
|
||||||
|
'amount' => $this->finalizeAmount($amount),
|
||||||
|
'redirect_url' => route('online_payment.redirect'),
|
||||||
|
'callback_url' => route('api.online_payment.callback'),
|
||||||
|
'reference_1_label' => 'Bank Code',
|
||||||
|
'reference_1' => $bankCode ? $bankCode : '',
|
||||||
|
'reference_2_label' => 'Bill Number',
|
||||||
|
'reference_2' => $billNumber
|
||||||
|
]);
|
||||||
|
|
||||||
|
if($response->successful()){
|
||||||
|
$data = $response->json();
|
||||||
|
|
||||||
|
$data['url'] = $data['url'].'?auto_submit=true';
|
||||||
|
|
||||||
|
return (object) $data;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}catch(\Exception $exception){
|
||||||
|
throw new MalformedRequestException('Unable to get correct response from billplz server' . $exception->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function finalizeAmount($amount){
|
||||||
|
$number = round($amount, 2) * 100;
|
||||||
|
return (string) $number;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Billplzs\Services;
|
||||||
|
|
||||||
|
use App\Classes\Exceptions\MalformedRequestException;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class GetBillplzBill
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $billPlzId
|
||||||
|
* @return null|object
|
||||||
|
* @throws MalformedRequestException
|
||||||
|
*/
|
||||||
|
public function execute(string $billPlzId) {
|
||||||
|
try{
|
||||||
|
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$billPlzId);
|
||||||
|
|
||||||
|
if($response->successful()){
|
||||||
|
$data = $response->json();
|
||||||
|
|
||||||
|
return (object) $data;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}catch(\Exception $exception){
|
||||||
|
throw new MalformedRequestException('Unable to get correct response from billplz server');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||||
|
|
||||||
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||||
|
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||||
|
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||||
|
use App\Classes\Modules\Transactions\Services\CreatesPaymentTransaction;
|
||||||
|
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
|
||||||
|
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||||
|
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
|
||||||
|
|
||||||
|
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||||
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||||
|
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||||
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
|
||||||
|
|
||||||
|
class CreatePaymentTransactionLogic extends AbstractControllerLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function notification():array {
|
||||||
|
return [
|
||||||
|
'title' => 'Create Payment Transactions',
|
||||||
|
'message' => 'You have successfully created currency supplier transactions'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var FetchesTransaction */
|
||||||
|
private $fetchesTransaction;
|
||||||
|
|
||||||
|
/** @var FetchesSegmentConstant */
|
||||||
|
private $fetchesSegmentConstant;
|
||||||
|
|
||||||
|
/** @var GeneratesTransactionBillNumber */
|
||||||
|
private $generatesTransactionBillNumber;
|
||||||
|
|
||||||
|
/** @var CreatesPaymentTransaction */
|
||||||
|
private $createsPaymentTransaction;
|
||||||
|
|
||||||
|
/** @var CreatesBillplzBill */
|
||||||
|
private $createsBillplzBill;
|
||||||
|
|
||||||
|
/** @var CreatesTransactionDetail */
|
||||||
|
private $createsTransactionDetail;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
FetchesTransaction $fetchesTransaction,
|
||||||
|
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||||
|
CreatesPaymentTransaction $createsPaymentTransaction,
|
||||||
|
CreatesTransactionDetail $createsTransactionDetail,
|
||||||
|
CreatesBillplzBill $createsBillplzBill
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->fetchesTransaction = $fetchesTransaction;
|
||||||
|
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||||
|
$this->createsPaymentTransaction = $createsPaymentTransaction;
|
||||||
|
$this->createsTransactionDetail = $createsTransactionDetail;
|
||||||
|
$this->createsBillplzBill = $createsBillplzBill;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logic(Request $request) : JsonResponse
|
||||||
|
{
|
||||||
|
$invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->input('transaction_id')]);
|
||||||
|
$amount = $request->input('amount');
|
||||||
|
$company_module = $invoice_transaction->owner()->first()->owner()->first()->companyModule()->first();
|
||||||
|
|
||||||
|
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
|
||||||
|
$payment_reference = null;
|
||||||
|
if ($request->input('payment_method') == 5) {
|
||||||
|
$payment_method = PaymentMethodType::PAYMENT_GATEWAY;
|
||||||
|
$billPlzBill = $this->createsBillplzBill->execute(
|
||||||
|
$company_module->name,
|
||||||
|
$company_module->employees()->first()->email,
|
||||||
|
'This payment is credit topup for company ref. ' . $company_module->reference, $amount, $billNumber,
|
||||||
|
$request->input('bank_code'), true
|
||||||
|
);
|
||||||
|
|
||||||
|
$payment_reference = $billPlzBill->id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$payment_method = PaymentMethodType::CASH;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new TransactionObject(
|
||||||
|
$billNumber,
|
||||||
|
TransactionType::PAYMENT,
|
||||||
|
$company_module->id,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
$payment_method,
|
||||||
|
$request->input('amount'),
|
||||||
|
$request->input('amount'),
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
ApprovalStatus::PENDING_SUBMISSION,
|
||||||
|
null,
|
||||||
|
$payment_reference
|
||||||
|
);
|
||||||
|
|
||||||
|
$payment_transaction = $this->createsPaymentTransaction->execute($invoice_transaction, $object);
|
||||||
|
|
||||||
|
return $this->response([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
-32
@@ -21,23 +21,10 @@ use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
|||||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||||
|
|
||||||
// use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
|
||||||
// use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
|
||||||
// use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
|
||||||
|
|
||||||
// use App\Models\Document;
|
|
||||||
// use App\Models\Transaction;
|
|
||||||
// use Barryvdh\DomPDF\PDF;
|
|
||||||
// use Carbon\Carbon;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
// use Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf;
|
|
||||||
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
|
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
|
||||||
|
|
||||||
class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||||
@@ -74,16 +61,6 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
|||||||
|
|
||||||
/** @var CreatesFiles */
|
/** @var CreatesFiles */
|
||||||
private $createsFile;
|
private $createsFile;
|
||||||
|
|
||||||
// /** @var FetchesTransaction */
|
|
||||||
// /** @var UpdatesTransactionStatus */
|
|
||||||
// private $updatesTransactionStatus;
|
|
||||||
// /** @var CreatesDocument */
|
|
||||||
// private $createsDocument;
|
|
||||||
// /** @var CreatesFiles */
|
|
||||||
// private $createsFile;
|
|
||||||
// /** @var PDF */
|
|
||||||
// private $pdf;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
FetchesPackingList $fetchesPackingList,
|
FetchesPackingList $fetchesPackingList,
|
||||||
@@ -93,10 +70,6 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
|||||||
CreatesTransactionDetail $createsTransactionDetail,
|
CreatesTransactionDetail $createsTransactionDetail,
|
||||||
CreatesDocument $createsDocument,
|
CreatesDocument $createsDocument,
|
||||||
CreatesFiles $createsFile
|
CreatesFiles $createsFile
|
||||||
|
|
||||||
// CreatesDocument $createsDocument,
|
|
||||||
// CreatesFiles $createsFile,
|
|
||||||
// PDF $pdf
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -107,11 +80,6 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
|||||||
$this->createsTransactionDetail = $createsTransactionDetail;
|
$this->createsTransactionDetail = $createsTransactionDetail;
|
||||||
$this->createsDocument = $createsDocument;
|
$this->createsDocument = $createsDocument;
|
||||||
$this->createsFile = $createsFile;
|
$this->createsFile = $createsFile;
|
||||||
|
|
||||||
// $this->updatesTransactionStatus = $updatesTransactionStatus;
|
|
||||||
// $this->createsDocument = $createsDocument;
|
|
||||||
// $this->createsFile = $createsFile;
|
|
||||||
// $this->pdf = $pdf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logic(Request $request) : JsonResponse
|
public function logic(Request $request) : JsonResponse
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ class TransactionObject implements DataTransferObject
|
|||||||
/** @var array|null */
|
/** @var array|null */
|
||||||
private $details;
|
private $details;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $paymentReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TransactionObject constructor.
|
* TransactionObject constructor.
|
||||||
* @param string $billNo
|
* @param string $billNo
|
||||||
@@ -92,7 +95,8 @@ class TransactionObject implements DataTransferObject
|
|||||||
float $serviceCharge,
|
float $serviceCharge,
|
||||||
?Carbon $expiresOn,
|
?Carbon $expiresOn,
|
||||||
?int $status = ApprovalStatus::PENDING_SUBMISSION,
|
?int $status = ApprovalStatus::PENDING_SUBMISSION,
|
||||||
?array $details = []
|
?array $details = [],
|
||||||
|
?string $paymentReference = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->billNo = $billNo;
|
$this->billNo = $billNo;
|
||||||
@@ -111,6 +115,7 @@ class TransactionObject implements DataTransferObject
|
|||||||
$this->expiresOn = $expiresOn;
|
$this->expiresOn = $expiresOn;
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
$this->details = $details;
|
$this->details = $details;
|
||||||
|
$this->paymentReference = $paymentReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,7 +248,11 @@ class TransactionObject implements DataTransferObject
|
|||||||
}, $this->details);
|
}, $this->details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getPaymentReference(): ?string
|
||||||
|
{
|
||||||
|
return $this->paymentReference;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Transactions\Services;
|
||||||
|
|
||||||
|
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||||
|
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||||
|
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
|
||||||
|
class CreatesPaymentTransaction extends AbstractUpdateRelationshipRecord
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param TransactionObject $object
|
||||||
|
* @return \Illuminate\Database\Eloquent\Model
|
||||||
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||||
|
*/
|
||||||
|
public function execute(Transaction $transaction, TransactionObject $object) {
|
||||||
|
$model = new Transaction();
|
||||||
|
$model->bill_no = $object->getBillNo();
|
||||||
|
$model->type = $object->getTransactionType();
|
||||||
|
$model->issuer = $object->getIssuer();
|
||||||
|
$model->receiver = $object->getReceiver();
|
||||||
|
$model->recipient_bank_account_id = $object->getRecipientBankAccountId();
|
||||||
|
$model->payment_method = $object->getPaymentMethod();
|
||||||
|
$model->amount = $object->getAmount();
|
||||||
|
$model->original_amount = $object->getOriginalAmount();
|
||||||
|
$model->currency_id = $object->getCurrencyId();
|
||||||
|
$model->original_currency_id = $object->getOriginalCurrencyId();
|
||||||
|
$model->currency_rate = $object->getCurrencyRate();
|
||||||
|
$model->tax = $object->getTax();
|
||||||
|
$model->service_charge = $object->getServiceCharge();
|
||||||
|
$model->expires_on = $object->getExpiresOn();
|
||||||
|
$model->status = $object->getStatus();
|
||||||
|
|
||||||
|
return $this->handler($transaction->transactions(), $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,10 @@ final class TransactionType {
|
|||||||
|
|
||||||
public const SHIPPING_INVOICE = 1;
|
public const SHIPPING_INVOICE = 1;
|
||||||
|
|
||||||
|
public const PAYMENT = 2;
|
||||||
|
|
||||||
// public const PAYMENT_ATTEMPT = 0;
|
// public const PAYMENT_ATTEMPT = 0;
|
||||||
|
|
||||||
// public const PAYMENT = 1;
|
|
||||||
|
|
||||||
// public const INVOICE = 2;
|
// public const INVOICE = 2;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Billplz;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Billplzs\ControllersLogic\CallbackBillplzLogic;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CallbackBillplzController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param CallbackBillplzLogic $logic
|
||||||
|
* @return bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||||
|
* @throws \App\Classes\Exceptions\ResourceNotFoundException
|
||||||
|
*/
|
||||||
|
public function callback(Request $request, CallbackBillplzLogic $logic) {
|
||||||
|
return $logic->execute($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Billplz;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Billplzs\ControllersLogic\CreateBillplzBillLogic;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CreateBillplzBillController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param CreateBillplzBillLogic $logic
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function create(Request $request, CreateBillplzBillLogic $logic): JsonResponse {
|
||||||
|
return $logic->execute($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Transactions;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Classes\Modules\Transactions\ControllersLogic\CreatePaymentTransactionLogic;
|
||||||
|
|
||||||
|
class CreatePaymentTransactionController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param CreatePaymentTransactionLogic $logic
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function create(Request $request, CreatePaymentTransactionLogic $logic) : JsonResponse {
|
||||||
|
return $logic->execute($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -139,7 +139,7 @@ class CompanyModule extends AbstractModel implements Addressable, Documentable,
|
|||||||
*/
|
*/
|
||||||
public function banks(): HasMany
|
public function banks(): HasMany
|
||||||
{
|
{
|
||||||
return $this->HasMany(Bank::class, 'company_id');
|
return $this->HasMany(BankAccount::class, 'company_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Classes\General\Interfaces\Documentable;
|
use App\Classes\General\Interfaces\Documentable;
|
||||||
|
use App\Classes\General\Interfaces\Transactionable;
|
||||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@@ -12,7 +13,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
|
||||||
class Transaction extends AbstractModel implements Documentable
|
class Transaction extends AbstractModel implements Documentable, Transactionable
|
||||||
{
|
{
|
||||||
protected $table = 'transactions';
|
protected $table = 'transactions';
|
||||||
|
|
||||||
@@ -29,6 +30,14 @@ class Transaction extends AbstractModel implements Documentable
|
|||||||
return $this->morphMany(Order::class, 'owner');
|
return $this->morphMany(Order::class, 'owner');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return MorphMany
|
||||||
|
*/
|
||||||
|
public function transactions(): MorphMany
|
||||||
|
{
|
||||||
|
return $this->MorphMany(Transaction::class, 'owner');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return MorphMany
|
* @return MorphMany
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'base_url' => env('BILLPLZ_BASE_URL', 'https://www.billplz.com'),
|
||||||
|
'api_key' => env('BILLPLZ_API_KEY', '0fa4c710-761b-4a7a-a501-c2c2d02643d5'),
|
||||||
|
'x_signature_key' => env('BILLPLZ_X_SIGNATURE_KEY', 'S-pbNVthVRsvnPfZlgLwqqOg'),
|
||||||
|
'collection_id' => env('BILLPLZ_COLLECTION_ID', 'hev2wdjy'),
|
||||||
|
'wallet_collection_id' => env('BILLPLZ_WALLET_COLLECTION_ID', 'hev2wdjy'),
|
||||||
|
'redirect_url' => env('BILLPLZ_REDIRECT_URL', 'localhost'),
|
||||||
|
'callback_url' => env('BILLPLZ_CALLBACK_URL', 'localhost'),
|
||||||
|
'maybank' => 'MB2U0227',
|
||||||
|
'cimb' => 'BCBB0235'
|
||||||
|
];
|
||||||
@@ -26,6 +26,8 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
|
|||||||
|
|
||||||
Route::get('/storage/{fileName}/fetch', 'Documents\RenderDocumentController@fileStorageServe')->where(['fileName' => '.*'])->name('storage.document.file');
|
Route::get('/storage/{fileName}/fetch', 'Documents\RenderDocumentController@fileStorageServe')->where(['fileName' => '.*'])->name('storage.document.file');
|
||||||
|
|
||||||
|
Route::post('online_payment/callback', 'Billplz\CallbackBillplzController@callback')->name('online_payment.callback');
|
||||||
|
|
||||||
require __DIR__ . '/company.php';
|
require __DIR__ . '/company.php';
|
||||||
|
|
||||||
require __DIR__ . '/document.php';
|
require __DIR__ . '/document.php';
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' =>
|
|||||||
Route::get('/list', 'ListTransactionsController@list')->name('list');
|
Route::get('/list', 'ListTransactionsController@list')->name('list');
|
||||||
// Route::delete('/suspend/{id}', 'SuspendTransactionController@suspend')->name('suspend');
|
// Route::delete('/suspend/{id}', 'SuspendTransactionController@suspend')->name('suspend');
|
||||||
|
|
||||||
|
route::post('/payment/create', 'CreatePaymentTransactionController@create')->name('payment.create');
|
||||||
route::post('/shipping-invoice/create', 'CreateShippingInvoiceTransactionController@create')->name('supplier.create');
|
route::post('/shipping-invoice/create', 'CreateShippingInvoiceTransactionController@create')->name('supplier.create');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -260,4 +260,6 @@ Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{ina
|
|||||||
echo $key + 1 .'. <a href="'.\route('customer.profile', $marking).'" target="_blank">'.$marking.'</a><br><br>';
|
echo $key + 1 .'. <a href="'.\route('customer.profile', $marking).'" target="_blank">'.$marking.'</a><br><br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::get('/online_payment/redirect', 'Billplz\CallbackBillplzController@callback')->name('online_payment.redirect');
|
||||||
Reference in New Issue
Block a user