diff --git a/app/Modules/Branch/Interfaces/BelongsToBranch.php b/app/Modules/Branch/Interfaces/BelongsToBranch.php index 708e3ee..287b279 100644 --- a/app/Modules/Branch/Interfaces/BelongsToBranch.php +++ b/app/Modules/Branch/Interfaces/BelongsToBranch.php @@ -5,6 +5,7 @@ namespace App\Modules\Branch\Interfaces; /** * @property int $id * @property int $branch_id + * @property \App\Modules\Branch\Models\Branch $branch * * @phpstan-require-extends \Illuminate\Database\Eloquent\Model */ diff --git a/app/Modules/Branch/Models/Branch.php b/app/Modules/Branch/Models/Branch.php index c6efae4..88150b3 100644 --- a/app/Modules/Branch/Models/Branch.php +++ b/app/Modules/Branch/Models/Branch.php @@ -12,8 +12,8 @@ use Spatie\Translatable\HasTranslations; /** * @property int $id * @property string $unique_code - * @property array $name - * @property array|null $address + * @property string $name + * @property string|null $address * @property string $region * @property int|null $province_id * @property array|null $phone_numbers diff --git a/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php b/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php index fefc17e..f45017a 100644 --- a/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php +++ b/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php @@ -100,7 +100,7 @@ class HalkbankOnlinePaymentRepository implements PaymentProviderContract return new Response(new GuzzleResponse( 503, ['Content-Type' => 'application/json'], - sprintf('{"errorCode":"99","errorMessage":"FAILED_REQUEST"}', $e->getMessage()) + '{"errorCode":"99","errorMessage":"FAILED_REQUEST"}' )); } diff --git a/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php b/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php index 50581ce..b2958c7 100644 --- a/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php +++ b/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php @@ -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 */ 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 */ - 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 */ - 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 */ 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 $data */ public function paymentStatusView(array $data): View {