Routes Name Enhanced For Better Understanding
This commit is contained in:
parent
8e7c11b4c0
commit
b3bc0efa39
|
|
@ -53,11 +53,11 @@ class SmartButtonController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Success payment.
|
||||
* Paypal order creation for approval of client.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function details(OrdersCreateRequest $request)
|
||||
public function createOrder(OrdersCreateRequest $request)
|
||||
{
|
||||
$request->prefer('return=representation');
|
||||
$request->body = $this->buildRequestBody();
|
||||
|
|
@ -66,46 +66,17 @@ class SmartButtonController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Save order.
|
||||
* Capturing order.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function saveOrder()
|
||||
public function captureOrder()
|
||||
{
|
||||
$orderCreationData = request()->get('data');
|
||||
$request = new OrdersCaptureRequest($orderCreationData['orderID']);
|
||||
$request->prefer('return=representation');
|
||||
$this->smartButtonClient->execute($request);
|
||||
|
||||
if (Cart::hasError()) {
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
Cart::collectTotals();
|
||||
|
||||
$this->validateOrder();
|
||||
|
||||
$order = $this->orderRepository->create(Cart::prepareDataForOrder());
|
||||
|
||||
$this->orderRepository->update(['status' => 'processing'], $order->id);
|
||||
|
||||
if ($order->canInvoice()) {
|
||||
$this->invoiceRepository->create($this->prepareInvoiceData($order));
|
||||
}
|
||||
|
||||
Cart::deActivateCart();
|
||||
|
||||
session()->flash('order', $order);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('shop::app.common.error'));
|
||||
|
||||
throw $e;
|
||||
}
|
||||
return $this->saveOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -187,8 +158,6 @@ class SmartButtonController extends Controller
|
|||
];
|
||||
|
||||
if ($cart->haveStockableItems() && $cart->shipping_address) {
|
||||
$shippingAddressLines = $this->getAddressLines($cart->shipping_address->address1);
|
||||
|
||||
$data['purchase_units'][0] = array_merge($data['purchase_units'][0], [
|
||||
'shipping' => [
|
||||
'address' => [
|
||||
|
|
@ -253,6 +222,44 @@ class SmartButtonController extends Controller
|
|||
return $addressLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving order once captured and all formalities done.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function saveOrder()
|
||||
{
|
||||
if (Cart::hasError()) {
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
Cart::collectTotals();
|
||||
|
||||
$this->validateOrder();
|
||||
|
||||
$order = $this->orderRepository->create(Cart::prepareDataForOrder());
|
||||
|
||||
$this->orderRepository->update(['status' => 'processing'], $order->id);
|
||||
|
||||
if ($order->canInvoice()) {
|
||||
$this->invoiceRepository->create($this->prepareInvoiceData($order));
|
||||
}
|
||||
|
||||
Cart::deActivateCart();
|
||||
|
||||
session()->flash('order', $order);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('shop::app.common.error'));
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares order's invoice data for creation.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
Route::group(['middleware' => ['web']], function () {
|
||||
Route::prefix('paypal/standard')->group(function () {
|
||||
|
||||
Route::get('/redirect', 'Webkul\Paypal\Http\Controllers\StandardController@redirect')->name('paypal.standard.redirect');
|
||||
|
||||
Route::get('/success', 'Webkul\Paypal\Http\Controllers\StandardController@success')->name('paypal.standard.success');
|
||||
|
|
@ -11,9 +10,9 @@ Route::group(['middleware' => ['web']], function () {
|
|||
});
|
||||
|
||||
Route::prefix('paypal/smart-button')->group(function () {
|
||||
Route::get('/details', 'Webkul\Paypal\Http\Controllers\SmartButtonController@details')->name('paypal.smart_button.details');
|
||||
Route::get('/create-order', 'Webkul\Paypal\Http\Controllers\SmartButtonController@createOrder')->name('paypal.smart-button.create-order');
|
||||
|
||||
Route::post('/save-order', 'Webkul\Paypal\Http\Controllers\SmartButtonController@saveOrder')->name('paypal.smart_button.save_order');
|
||||
Route::post('/capture-order', 'Webkul\Paypal\Http\Controllers\SmartButtonController@captureOrder')->name('paypal.smart-button.capture-order');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
enableStandardCardFields: false,
|
||||
|
||||
createOrder: function(data, actions) {
|
||||
return window.axios.get("{{ route('paypal.smart_button.details') }}")
|
||||
return window.axios.get("{{ route('paypal.smart-button.create-order') }}")
|
||||
.then(function(response) {
|
||||
return response.data.result;
|
||||
})
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
onApprove: function(data, actions) {
|
||||
app.showLoader();
|
||||
|
||||
window.axios.post("{{ route('paypal.smart_button.save_order') }}", {
|
||||
window.axios.post("{{ route('paypal.smart-button.capture-order') }}", {
|
||||
'_token': "{{ csrf_token() }}",
|
||||
'data' : data
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue