stan errros
This commit is contained in:
1 parent
45fbde31c7
commit
7f394b90fa
4 files changed
+22
-20
No files matched your search
@@ -5,6 +5,7 @@
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $branch_id
|
||||
* @property \App\Modules\Branch\Models\Branch $branch
|
||||
*
|
||||
* @phpstan-require-extends \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $unique_code
|
||||
* @property array<string, string> $name
|
||||
* @property array<string, string>|null $address
|
||||
* @property string $name
|
||||
* @property string|null $address
|
||||
* @property string $region
|
||||
* @property int|null $province_id
|
||||
* @property array<string, string>|null $phone_numbers
|
||||
|
||||
@@ -100,7 +100,7 @@ public function checkPayment(string $orderId): Response
|
||||
return new Response(new GuzzleResponse(
|
||||
503,
|
||||
['Content-Type' => 'application/json'],
|
||||
sprintf('{"errorCode":"99","errorMessage":"FAILED_REQUEST"}', $e->getMessage())
|
||||
'{"errorCode":"99","errorMessage":"FAILED_REQUEST"}'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -186,11 +186,12 @@ public function createHistory(): void
|
||||
/**
|
||||
* 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 @@ public function checkPayment(string $orderId): array
|
||||
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 @@ public function checkPayment(string $orderId): array
|
||||
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 @@ public function paymentSuccessful($relatedResource, $paymentHistory, $bankBranch
|
||||
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 @@ public function paymentSuccessful($relatedResource, $paymentHistory, $bankBranch
|
||||
/**
|
||||
* 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 @@ public function paymentFailed(string $title = '', $paymentHistory = null, $bankB
|
||||
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 @@ public function paymentFailed(string $title = '', $paymentHistory = null, $bankB
|
||||
/**
|
||||
* 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 @@ public function paymentCheckResponseTemplate(
|
||||
/**
|
||||
* 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