2022-02-28 09:19:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Sarga\Payment\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use GuzzleHttp\Exception\ConnectException;
|
2023-02-24 11:35:11 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2023-02-24 11:08:19 +00:00
|
|
|
use Sarga\Payment\Methods\Rysgal;
|
2022-02-28 09:19:57 +00:00
|
|
|
use Webkul\Checkout\Facades\Cart;
|
2023-02-24 10:38:15 +00:00
|
|
|
|
|
|
|
|
use Webkul\Checkout\Repositories\CartRepository;
|
2022-02-28 09:19:57 +00:00
|
|
|
use Webkul\Sales\Repositories\OrderRepository;
|
|
|
|
|
|
2023-02-24 11:08:19 +00:00
|
|
|
class RysgalController extends Controller
|
2022-02-28 09:19:57 +00:00
|
|
|
{
|
2023-02-24 11:08:19 +00:00
|
|
|
public function __construct(protected OrderRepository $orderRepository, protected Rysgal $altynAsyr)
|
2022-02-28 09:19:57 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Redirects to payment gateway
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
|
*/
|
|
|
|
|
public function redirect(){
|
2023-02-24 10:38:15 +00:00
|
|
|
$result = $this->altynAsyr->registerOrder();
|
|
|
|
|
|
|
|
|
|
if($result['success']){
|
|
|
|
|
return redirect($result['url']);
|
2022-02-28 09:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-24 10:38:15 +00:00
|
|
|
session()->flash('error', $result['message']);
|
|
|
|
|
|
|
|
|
|
return redirect()->route('shop.checkout.onepage.index');
|
2022-02-28 09:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Success payment
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
2023-02-24 10:38:15 +00:00
|
|
|
public function success(CartRepository $cartRepository, $cart_id){
|
|
|
|
|
if(!auth()->guard()->check() && !session()->has('cart')){
|
|
|
|
|
Cart::setCart($cartRepository->find($cart_id));
|
2022-02-28 09:19:57 +00:00
|
|
|
}
|
2023-02-24 10:38:15 +00:00
|
|
|
|
|
|
|
|
$result = $this->altynAsyr->getOrderStatus();
|
|
|
|
|
|
2023-02-24 11:35:11 +00:00
|
|
|
Log::info($result);
|
|
|
|
|
|
2023-02-24 10:38:15 +00:00
|
|
|
if ($result['success'] ) {
|
|
|
|
|
$order = $this->orderRepository->create(Cart::prepareDataForOrder());
|
|
|
|
|
|
|
|
|
|
Cart::deActivateCart();
|
|
|
|
|
|
|
|
|
|
session()->flash('order', $order);
|
|
|
|
|
|
|
|
|
|
// return view('shop::checkout.retry',$result);
|
|
|
|
|
|
|
|
|
|
return redirect()->route('shop.checkout.success');
|
2022-02-28 09:19:57 +00:00
|
|
|
}
|
2023-02-24 10:38:15 +00:00
|
|
|
|
|
|
|
|
return view('shop::checkout.retry',$result);
|
2022-02-28 09:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|