stan errros
This commit is contained in:
@@ -186,11 +186,12 @@ class OnlinePaymentRepository
|
||||
/**
|
||||
* Check payment
|
||||
*
|
||||
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
||||
* @return array<string, string|bool|int>
|
||||
*/
|
||||
public function checkPayment(string $orderId): array
|
||||
{
|
||||
/** @var \App\Modules\OnlinePayment\Models\OnlinePayment Find payment order from history */
|
||||
// Find payment order from history
|
||||
/** @var \App\Modules\OnlinePayment\Models\OnlinePayment */
|
||||
$paymentHistory = OnlinePayment::where('orderId', $orderId)->first();
|
||||
|
||||
// Resolve related resource model dynamically
|
||||
@@ -209,12 +210,12 @@ class OnlinePaymentRepository
|
||||
return $this->paymentFailed('(RESOURCE NOT FOUND)');
|
||||
}
|
||||
|
||||
$relatedResource->load('branch');
|
||||
$relatedResource->loadMissing('branch');
|
||||
|
||||
/** @var \App\Modules\Branch\Models\Branch */
|
||||
$bankBranch = $relatedResource->branch;
|
||||
|
||||
if (! $bankBranch) {
|
||||
if (! $bankBranch || is_null($bankBranch->billing_username) || is_null($bankBranch->billing_password)) { // @phpstan-ignore-line
|
||||
return $this->paymentFailed('(BRANCH NOT FOUND)');
|
||||
}
|
||||
|
||||
@@ -226,17 +227,17 @@ class OnlinePaymentRepository
|
||||
return $this->paymentFailed('(REQUEST FAILURE)');
|
||||
}
|
||||
|
||||
return $response['paymentAmountInfo']['depositedAmount'] > 0
|
||||
? $this->paymentSuccessful($relatedResource, $paymentHistory, $bankBranch)
|
||||
: $this->paymentFailed(__('Payment has failed'), $paymentHistory, $bankBranch);
|
||||
return $response['paymentAmountInfo']['depositedAmount'] > 0 // @phpstan-ignore-line
|
||||
? $this->paymentSuccessful($relatedResource, $paymentHistory, $bankBranch->name)
|
||||
: $this->paymentFailed(__('Payment has failed'), $paymentHistory, $bankBranch->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Successful payment
|
||||
*
|
||||
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
||||
* @return array<string, string|bool|int>
|
||||
*/
|
||||
public function paymentSuccessful($relatedResource, $paymentHistory, $bankBranch): array
|
||||
public function paymentSuccessful(Model $relatedResource, OnlinePayment $paymentHistory, string $branchName = ''): array
|
||||
{
|
||||
$relatedResource->update([
|
||||
'paid' => true,
|
||||
@@ -249,7 +250,7 @@ class OnlinePaymentRepository
|
||||
return $this->paymentCheckResponseTemplate(
|
||||
success: true,
|
||||
pnr: $paymentHistory->online_paymantable_id,
|
||||
branch_name: $bankBranch->name,
|
||||
branch_name: $branchName,
|
||||
price_amount: $paymentHistory->amount.' TMT'
|
||||
);
|
||||
}
|
||||
@@ -257,9 +258,9 @@ class OnlinePaymentRepository
|
||||
/**
|
||||
* Failed payment
|
||||
*
|
||||
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
||||
* @return array<string, string|bool|int>
|
||||
*/
|
||||
public function paymentFailed(string $title = '', $paymentHistory = null, $bankBranch = null): array
|
||||
public function paymentFailed(string $title = '', ?OnlinePayment $paymentHistory = null, string $branchName = ''): array
|
||||
{
|
||||
if ($paymentHistory) {
|
||||
$paymentHistory->update([
|
||||
@@ -269,7 +270,7 @@ class OnlinePaymentRepository
|
||||
return $this->paymentCheckResponseTemplate(
|
||||
success: false,
|
||||
pnr: $paymentHistory->online_paymantable_id,
|
||||
branch_name: $bankBranch->name,
|
||||
branch_name: $branchName,
|
||||
price_amount: $paymentHistory->amount.' TMT'
|
||||
);
|
||||
}
|
||||
@@ -280,14 +281,14 @@ class OnlinePaymentRepository
|
||||
/**
|
||||
* Check payment response
|
||||
*
|
||||
* @return array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string}
|
||||
* @return array<string, string|bool|int>
|
||||
*/
|
||||
public function paymentCheckResponseTemplate(
|
||||
bool $success,
|
||||
string $title = '',
|
||||
string $pnr = '',
|
||||
int|string $pnr = '',
|
||||
string $branch_name = '',
|
||||
string $price_amount = '',
|
||||
int|string $price_amount = '',
|
||||
string $return_url = ''
|
||||
): array {
|
||||
return [
|
||||
@@ -303,7 +304,7 @@ class OnlinePaymentRepository
|
||||
/**
|
||||
* Show payment status
|
||||
*
|
||||
* @param array{success: bool, title: string, pnr: string, branch_name: string, price_amount: string, return_url: string} $data
|
||||
* @param array<string, string|bool|int> $data
|
||||
*/
|
||||
public function paymentStatusView(array $data): View
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user