sarga theme
This commit is contained in:
parent
3c206eea73
commit
433934a702
|
|
@ -3,28 +3,16 @@
|
|||
namespace Sarga\Payment\Http\Controllers;
|
||||
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use Sarga\Payment\Methods\AltynAsyr;
|
||||
use Webkul\Checkout\Facades\Cart;
|
||||
use Sarga\Payment\CardPayment\AltynAsyr;
|
||||
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
|
||||
class AltynAsyrController extends Controller
|
||||
{
|
||||
/**
|
||||
* OrderRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $orderRepository;
|
||||
|
||||
/**
|
||||
* @var AltynAsyr object
|
||||
*/
|
||||
protected $altynAsyr;
|
||||
|
||||
public function __construct(OrderRepository $orderRepository, AltynAsyr $altynAsyr)
|
||||
public function __construct(protected OrderRepository $orderRepository, protected AltynAsyr $altynAsyr)
|
||||
{
|
||||
$this->orderRepository = $orderRepository;
|
||||
$this->altynAsyr = $altynAsyr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -32,25 +20,15 @@ class AltynAsyrController extends Controller
|
|||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function redirect(){
|
||||
// register order to payment gateway
|
||||
try{
|
||||
$result = $this->altynAsyr->registerOrder();
|
||||
if($result['errorCode'] == 0){
|
||||
// dd($result);
|
||||
$this->altynAsyr->registerOrderId($result['orderId']);
|
||||
return redirect($result['formUrl']);
|
||||
}
|
||||
else{//if already registered or otkazana w dostupe
|
||||
//todo log
|
||||
session()->flash('error', $result['errorMessage']);
|
||||
}
|
||||
$result = $this->altynAsyr->registerOrder();
|
||||
|
||||
}catch (\Exception $exception){
|
||||
//todo Check exception if not connection excepion redirect to login ore somewhere if session expired
|
||||
session()->flash('error', $exception->getMessage());
|
||||
if($result['success']){
|
||||
return redirect($result['url']);
|
||||
}
|
||||
|
||||
return redirect()->route('shop.checkout.cart.index');
|
||||
session()->flash('error', $result['message']);
|
||||
|
||||
return redirect()->route('shop.checkout.onepage.index');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -58,34 +36,26 @@ class AltynAsyrController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function success(){
|
||||
try {
|
||||
$result = $this->altynAsyr->getOrderStatus();
|
||||
|
||||
if ($result['ErrorCode'] == 0) {
|
||||
if ($result['OrderStatus'] == 2) {
|
||||
$order = $this->orderRepository->create(Cart::prepareDataForOrder());
|
||||
//todo save card details to cart->payment
|
||||
Cart::deActivateCart();
|
||||
|
||||
session()->flash('order', $order);
|
||||
|
||||
return redirect()->route('shop.checkout.success');
|
||||
} else {
|
||||
return view('payment::order-status')->with('cart', $this->altynAsyr->getCart());
|
||||
}
|
||||
|
||||
} else {
|
||||
session()->flash('error', trans('payment.unsuccessfull'));
|
||||
}
|
||||
public function success(CartRepository $cartRepository, $cart_id){
|
||||
if(!auth()->guard()->check() && !session()->has('cart')){
|
||||
Cart::setCart($cartRepository->find($cart_id));
|
||||
}
|
||||
catch (ConnectException $connectException){
|
||||
session()->flash('error',trans('payment::messages.connection_failed'));
|
||||
|
||||
$result = $this->altynAsyr->getOrderStatus();
|
||||
|
||||
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');
|
||||
}
|
||||
catch (\Exception $exception){
|
||||
session()->flash('error',trans('payment::messages.session_expired'));
|
||||
}
|
||||
return redirect()->route('shop.checkout.cart.index');
|
||||
|
||||
return view('shop::checkout.retry',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue