wip
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Repos\Payment\OnlinePaymentRepo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OnlinePaymentController extends Controller
|
||||
{
|
||||
@@ -13,25 +17,59 @@ class OnlinePaymentController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
return $request->all();
|
||||
// Validate the order id
|
||||
$request->validate(['orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId']]);
|
||||
|
||||
// $response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
// 'language' => 'ru',
|
||||
// 'orderId' => $request->orderId,
|
||||
// 'userName' => 301161000067,
|
||||
// 'password' => 'E3vb2SR3dgTPdff'
|
||||
// ]);
|
||||
// Find order from history
|
||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
|
||||
// if ($response['depositAmount'] > 0) {
|
||||
// $payment_history = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
// Find related resource
|
||||
$resource = (new $paymentHistory->online_paymantable_type)->find(id: $paymentHistory->online_paymantable_id);
|
||||
|
||||
// $booking = Booking::where('id', $payment_history->online_paymantable_id)->update([
|
||||
// 'status' => Settings::PAID
|
||||
// ]);
|
||||
if (! $resource) {
|
||||
Log::channel('halkbank_payment_check_error')
|
||||
->error('Related resource not found', [
|
||||
'orderId' => $request->orderId,
|
||||
'onlinePaymentHistory_id' => $paymentHistory->id,
|
||||
'related_resource' => [
|
||||
'type' => $paymentHistory->online_paymantable_type,
|
||||
'id' => $paymentHistory->online_paymantable_id,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// $payment_history->update([
|
||||
// 'paymentStatus' => Settings::PAID
|
||||
// ]);
|
||||
// }
|
||||
$resource->load('branch');
|
||||
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $resource->branch->billing_username,
|
||||
'password' => $resource->branch->billing_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['depositAmount'] > 0;
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
'paid' => true,
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
} else {
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
}
|
||||
|
||||
return view(OnlinePaymentRepo::statusView(), [
|
||||
'status' => $payment_status,
|
||||
'title' => $payment_status ? __('Payment is successful') : __('Payment has failed'),
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $resource->branch->name,
|
||||
'price_amount' => $paymentHistory->amount,
|
||||
'return_url' => $resource->panelUrl(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,14 @@ class CardOrder extends Model
|
||||
return 1;
|
||||
// return floatval($this->cardType->price);
|
||||
}
|
||||
|
||||
/**
|
||||
* Panel url
|
||||
*/
|
||||
public function panelUrl(string $type = 'index'): string
|
||||
{
|
||||
return match ($type) {
|
||||
'index' => sprintf('resources/card-orders'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,26 @@ namespace App\Repos\Payment;
|
||||
|
||||
use App\Models\Payment\ApiKeyHalkbank;
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OnlinePaymentRepo
|
||||
{
|
||||
/**
|
||||
* Pending orders are brand new orders that have not been processed yet.
|
||||
*/
|
||||
public const PENDING = 'pending';
|
||||
|
||||
/**
|
||||
* Failed orders are existing orders that could be paid
|
||||
*/
|
||||
public const FAILED = 'failed';
|
||||
|
||||
/**
|
||||
* Paid orders are existing order that could be paid successfully
|
||||
*/
|
||||
public const PAID = 'paid';
|
||||
|
||||
/**
|
||||
* Pay card order
|
||||
*
|
||||
@@ -58,7 +71,7 @@ class OnlinePaymentRepo
|
||||
'errorUrl' => route('online-payment-store'),
|
||||
'api_client' => config('app.url'),
|
||||
'username' => $resource->branch->billing_username,
|
||||
'paymentStatus' => OrderRepo::PENDING,
|
||||
'paymentStatus' => self::PENDING,
|
||||
]);
|
||||
|
||||
return [
|
||||
@@ -74,4 +87,12 @@ class OnlinePaymentRepo
|
||||
{
|
||||
return ApiKeyHalkbank::generateOrderNumber($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Status view
|
||||
*/
|
||||
public static function statusView(): string
|
||||
{
|
||||
return 'orders.cards.online-payment.status';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user