wip
This commit is contained in:
@@ -150,44 +150,6 @@ class OnlinePaymentRepository
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check payment
|
|
||||||
*/
|
|
||||||
public function checkPayment(string $orderId): array
|
|
||||||
{
|
|
||||||
/** @var \App\Modules\OnlinePayment\Models\OnlinePayment Find payment order from history */
|
|
||||||
$paymentHistory = OnlinePayment::where('orderId', $orderId)->first();
|
|
||||||
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Model Find related resource */
|
|
||||||
$relatedResource = (new $paymentHistory->online_paymantable_type)->find(id: $paymentHistory->online_paymantable_id);
|
|
||||||
|
|
||||||
// Check if resource could not be found or does not exist
|
|
||||||
if (! $relatedResource) {
|
|
||||||
return $this->paymentFailed('(RESOURCE NOT FOUND)');
|
|
||||||
}
|
|
||||||
|
|
||||||
$relatedResource->load('branch');
|
|
||||||
|
|
||||||
/** @var \App\Modules\Branch\Models\Branch */
|
|
||||||
$bankBranch = $relatedResource->branch;
|
|
||||||
|
|
||||||
if (! $bankBranch) {
|
|
||||||
return $this->paymentFailed('(BRANCH NOT FOUND)');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->provider->setUsername($bankBranch->billing_username);
|
|
||||||
$this->provider->setPassword($bankBranch->billing_password);
|
|
||||||
$response = $this->provider->checkPayment($orderId);
|
|
||||||
|
|
||||||
if ($response['ErrorCode'] == '99') {
|
|
||||||
return $this->paymentFailed('(REQUEST FAILURE)');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response['ErrorCode'] == '0'
|
|
||||||
? $this->paymentSuccessful($relatedResource, $paymentHistory, $bankBranch)
|
|
||||||
: $this->paymentFailed(__('Payment has failed'), $paymentHistory, $bankBranch);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment link
|
* Payment link
|
||||||
*/
|
*/
|
||||||
@@ -221,6 +183,59 @@ class OnlinePaymentRepository
|
|||||||
OnlinePayment::create($data);
|
OnlinePayment::create($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check payment
|
||||||
|
*
|
||||||
|
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
||||||
|
*/
|
||||||
|
public function checkPayment(string $orderId): array
|
||||||
|
{
|
||||||
|
/** @var \App\Modules\OnlinePayment\Models\OnlinePayment Find payment order from history */
|
||||||
|
$paymentHistory = OnlinePayment::where('orderId', $orderId)->first();
|
||||||
|
|
||||||
|
// Resolve related resource model dynamically
|
||||||
|
$modelClass = $paymentHistory->online_paymantable_type;
|
||||||
|
$modelId = $paymentHistory->online_paymantable_id;
|
||||||
|
|
||||||
|
if (! class_exists($modelClass)) {
|
||||||
|
return $this->paymentFailed('(INVALID RESOURCE TYPE)');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Illuminate\Database\Eloquent\Model Find related resource */
|
||||||
|
$relatedResource = $modelClass::find($modelId);
|
||||||
|
|
||||||
|
// Check if resource could not be found or does not exist
|
||||||
|
if (! $relatedResource) {
|
||||||
|
return $this->paymentFailed('(RESOURCE NOT FOUND)');
|
||||||
|
}
|
||||||
|
|
||||||
|
$relatedResource->load('branch');
|
||||||
|
|
||||||
|
/** @var \App\Modules\Branch\Models\Branch */
|
||||||
|
$bankBranch = $relatedResource->branch;
|
||||||
|
|
||||||
|
if (! $bankBranch) {
|
||||||
|
return $this->paymentFailed('(BRANCH NOT FOUND)');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->provider->setUsername($bankBranch->billing_username);
|
||||||
|
$this->provider->setPassword($bankBranch->billing_password);
|
||||||
|
$response = $this->provider->checkPayment($orderId);
|
||||||
|
|
||||||
|
if ($response['ErrorCode'] == '99') {
|
||||||
|
return $this->paymentFailed('(REQUEST FAILURE)');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response['ErrorCode'] == '0'
|
||||||
|
? $this->paymentSuccessful($relatedResource, $paymentHistory, $bankBranch)
|
||||||
|
: $this->paymentFailed(__('Payment has failed'), $paymentHistory, $bankBranch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Successful payment
|
||||||
|
*
|
||||||
|
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
||||||
|
*/
|
||||||
public function paymentSuccessful($relatedResource, $paymentHistory, $bankBranch): array
|
public function paymentSuccessful($relatedResource, $paymentHistory, $bankBranch): array
|
||||||
{
|
{
|
||||||
$relatedResource->update([
|
$relatedResource->update([
|
||||||
@@ -241,6 +256,8 @@ class OnlinePaymentRepository
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Failed payment
|
* Failed payment
|
||||||
|
*
|
||||||
|
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
||||||
*/
|
*/
|
||||||
public function paymentFailed(string $title = '', $paymentHistory = null, $bankBranch = null): array
|
public function paymentFailed(string $title = '', $paymentHistory = null, $bankBranch = null): array
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user