diff --git a/app/Http/Controllers/Shop/Auth/ConfirmPasswordController.php b/app/Http/Controllers/Admin/Auth/ConfirmPasswordController.php similarity index 91% rename from app/Http/Controllers/Shop/Auth/ConfirmPasswordController.php rename to app/Http/Controllers/Admin/Auth/ConfirmPasswordController.php index 038cbf3b..cafe9ff2 100644 --- a/app/Http/Controllers/Shop/Auth/ConfirmPasswordController.php +++ b/app/Http/Controllers/Admin/Auth/ConfirmPasswordController.php @@ -1,6 +1,6 @@ middleware('guest'); + } + + public function showLinkRequestForm() + { + $data = \App\Repositories\Config::init(); + return view('auth.passwords.email', $data); + } +} diff --git a/app/Http/Controllers/Admin/Auth/LoginController.php b/app/Http/Controllers/Admin/Auth/LoginController.php new file mode 100644 index 00000000..60019db4 --- /dev/null +++ b/app/Http/Controllers/Admin/Auth/LoginController.php @@ -0,0 +1,35 @@ +middleware('guest')->except('logout'); + $this->middleware('guest:web')->except('logout'); + } + + public function showLoginForm() + { + return view('auth.login'); + } + + public function authenticated(Request $request, $user) + { + return redirect()->intended($this->redirectPath()); + } + + public function username() + { + return 'username'; + } +} diff --git a/app/Http/Controllers/Auth/PasswordSecurityController.php b/app/Http/Controllers/Admin/Auth/PasswordSecurityController.php similarity index 98% rename from app/Http/Controllers/Auth/PasswordSecurityController.php rename to app/Http/Controllers/Admin/Auth/PasswordSecurityController.php index 6c873ccc..08203fa1 100644 --- a/app/Http/Controllers/Auth/PasswordSecurityController.php +++ b/app/Http/Controllers/Admin/Auth/PasswordSecurityController.php @@ -1,6 +1,6 @@ middleware('auth'); + } + + /** + * Get a validator for an incoming registration request. + * + * @param array $data + * @return \Illuminate\Contracts\Validation\Validator + */ + protected function validator(array $data) + { + return Validator::make( + $data, [ + 'name' => 'required|string|max:255', + 'email' => 'required|string|email|max:255|unique:users', + 'password' => 'required|string|min:6|confirmed', + ] + ); + } + + /** + * Create a new user instance after a valid registration. + * + * @param array $data + * @return \App\User + */ + protected function create(array $data) + { + return User::create( + [ + 'name' => $data['name'], + 'email' => $data['email'], + 'password' => Hash::make($data['password']), + ] + ); + } +} diff --git a/app/Http/Controllers/Admin/Auth/ResetPasswordController.php b/app/Http/Controllers/Admin/Auth/ResetPasswordController.php new file mode 100644 index 00000000..a8805215 --- /dev/null +++ b/app/Http/Controllers/Admin/Auth/ResetPasswordController.php @@ -0,0 +1,47 @@ +middleware('guest'); + } + + public function showResetForm(Request $request, $token = null) + { + $data['token'] = $token; + $data['email'] = $request->email; + return view('auth.passwords.reset', $data); + } +} diff --git a/app/Http/Controllers/Shop/Auth/VerificationController.php b/app/Http/Controllers/Admin/Auth/VerificationController.php similarity index 92% rename from app/Http/Controllers/Shop/Auth/VerificationController.php rename to app/Http/Controllers/Admin/Auth/VerificationController.php index a7ac017e..c99e296d 100644 --- a/app/Http/Controllers/Shop/Auth/VerificationController.php +++ b/app/Http/Controllers/Admin/Auth/VerificationController.php @@ -1,6 +1,6 @@ all()); - return redirect()->route('Admin.Shop.Orders.index'); - } - public function show($id) { $data = Orders::get($id); @@ -34,14 +28,20 @@ class OrderController extends Controller public function edit($id) { - $data['order'] = Orders::get($id, ['customer', 'detail'])->toArray(); - dump($data['order']); - exit; + $data['order'] = Orders::edit($id)->toArray(); + // dump($data); + // exit; return view('Admin.Shop.Orders.edit', $data); } + public function store(Request $request) + { + $ret = Orders::store($request->all()); + return redirect()->route('Admin.Shop.Orders.index'); + } + public function delete($id) { - return Orders::destroy($id); + return Orders::delete($id); } } diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index c39194c8..aee17b0c 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -3,36 +3,27 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; + use Illuminate\Foundation\Auth\SendsPasswordResetEmails; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Password; class ForgotPasswordController extends Controller { - /* - |-------------------------------------------------------------------------- - | Password Reset Controller - |-------------------------------------------------------------------------- - | - | This controller is responsible for handling password reset emails and - | includes a trait which assists in sending these notifications from - | your application to your users. Feel free to explore this trait. - | - */ - use SendsPasswordResetEmails; - /** - * Create a new controller instance. - * - * @return void - */ - public function __construct() + protected function guard() { - $this->middleware('guest'); + return Auth::guard('customer'); + } + + public function broker() + { + return Password::broker('customers'); } public function showLinkRequestForm() { - $data = \App\Repositories\Config::init(); - return view('auth.passwords.email', $data); + return view('Shop.auth.passwords.email'); } } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 7d6dd79a..63a36910 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -10,26 +10,48 @@ use Illuminate\Http\Request; class LoginController extends Controller { use AuthenticatesUsers; + protected $redirectTo = '/'; public function __construct() { - $this->middleware('guest')->except('logout'); - $this->middleware('guest:web')->except('logout'); + // $this->middleware('guest')->except('logout'); + } + + protected function guard() + { + return Auth::guard('customer'); } public function showLoginForm() { - return view('auth.login', $data ?? []); + return view('Shop.auth.login'); } - public function authenticated(Request $request, $user) + public function login(Request $request) { - return redirect()->intended($this->redirectPath()); + $credentials = $request->validate([ + 'email' => 'required|email', + 'password' => 'required|min:8', + ]); + + if ($this->guard()->attempt($credentials, $request->get('remember'))) { + $request->session()->regenerate(); + return (back()->getTargetUrl() == route('Shop.login')) ? redirect()->intended(route('home')) : back(); + } + return back()->withInput($request->only('email', 'remember')); + } + + public function logout(Request $request) + { + $sessionKey = $this->guard()->getName(); + $this->guard()->logout(); + $request->session()->forget($sessionKey); + return redirect()->route('home'); } public function username() { - return 'username'; + return 'email'; } } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 14e82aa3..ea683363 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -2,75 +2,84 @@ namespace App\Http\Controllers\Auth; -use App\User; use App\Http\Controllers\Controller; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Validator; +use Carbon\Carbon; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; +use Illuminate\Foundation\Auth\EmailVerificationRequest; use Illuminate\Foundation\Auth\RegistersUsers; +use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Validator; +use Sebastienheyd\Boilerplate\Rules\Password; + +use App\Models\Shop\Customer; class RegisterController extends Controller { - /* - |-------------------------------------------------------------------------- - | Register Controller - |-------------------------------------------------------------------------- - | - | This controller handles the registration of new users as well as their - | validation and creation. By default this controller uses a trait to - | provide this functionality without requiring any additional code. - | - */ - use RegistersUsers; - /** - * Where to redirect users after registration. - * - * @var string - */ - protected $redirectTo = '/home'; + protected $redirectTo; - /** - * Create a new controller instance. - * - * @return void - */ - public function __construct() + protected function guard() { - $this->middleware('auth'); + return Auth::guard('customer'); + } + + protected function redirectTo() + { + return route(config('boilerplate.app.redirectTo', 'boilerplate.dashboard')); } - /** - * Get a validator for an incoming registration request. - * - * @param array $data - * @return \Illuminate\Contracts\Validation\Validator - */ protected function validator(array $data) { - return Validator::make( - $data, [ - 'name' => 'required|string|max:255', - 'email' => 'required|string|email|max:255|unique:users', - 'password' => 'required|string|min:6|confirmed', - ] - ); + return Validator::make($data, [ + 'last_name' => 'required|max:255', + 'first_name' => 'required|max:255', + 'email' => 'required|email|max:255|unique:shop_customers,email,NULL,id,deleted_at,NULL', + 'password' => ['required', 'confirmed', new Password()], + ]); + } + + public function showRegistrationForm() + { + return view('Shop.auth.register', $data ?? []); } - /** - * Create a new user instance after a valid registration. - * - * @param array $data - * @return \App\User - */ protected function create(array $data) { - return User::create( - [ - 'name' => $data['name'], - 'email' => $data['email'], - 'password' => Hash::make($data['password']), - ] - ); + $user = Customer::withTrashed()->updateOrCreate(['email' => $data['email']], [ + 'active' => true, + 'first_name' => $data['first_name'], + 'last_name' => $data['last_name'], + 'email' => $data['email'], + 'password' => bcrypt($data['password']), + ]); + + return $user; + } + + public function emailVerify() + { + if (Auth::user()->hasVerifiedEmail()) { + return redirect(route(config('boilerplate.app.redirectTo', 'boilerplate.dashboard'))); + } + + return view('boilerplate::auth.verify-email'); + } + + public function emailVerifyRequest(EmailVerificationRequest $request) + { + $request->fulfill(); + return redirect(route(config('boilerplate.app.redirectTo', 'boilerplate.dashboard'))); + } + + public function emailSendVerification(Request $request) + { + $request->user()->sendEmailVerificationNotification(); + return back()->with('message', 'Verification link sent!'); } } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 15358f32..c00c135d 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -2,37 +2,19 @@ namespace App\Http\Controllers\Auth; -use Illuminate\Http\Request; use App\Http\Controllers\Controller; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Password; use Illuminate\Foundation\Auth\ResetsPasswords; +use App\Rules\Password as PasswordRules; class ResetPasswordController extends Controller { - /* - |-------------------------------------------------------------------------- - | Password Reset Controller - |-------------------------------------------------------------------------- - | - | This controller is responsible for handling password reset requests - | and uses a simple trait to include this behavior. You're free to - | explore this trait and override any methods you wish to tweak. - | - */ - use ResetsPasswords; - /** - * Where to redirect users after resetting their password. - * - * @var string - */ - protected $redirectTo = '/home'; + protected $redirectTo = '/'; - /** - * Create a new controller instance. - * - * @return void - */ public function __construct() { $this->middleware('guest'); @@ -40,8 +22,29 @@ class ResetPasswordController extends Controller public function showResetForm(Request $request, $token = null) { - $data['token'] = $token; - $data['email'] = $request->email; - return view('auth.passwords.reset', $data); + $token = $request->route()->parameter('token'); + + return view('Shop.auth.passwords.reset')->with( + ['token' => $token, 'email' => $request->email] + ); + } + + protected function rules() + { + return [ + 'token' => 'required', + 'email' => 'required|email', + 'password' => ['required', 'confirmed', new PasswordRules()], + ]; + } + + public function broker() + { + return Password::broker('customers'); + } + + protected function guard() + { + return Auth::guard('customer'); } } diff --git a/app/Http/Controllers/Auth/VerificationController.php b/app/Http/Controllers/Auth/VerificationController.php index 23a43a84..22aaf006 100644 --- a/app/Http/Controllers/Auth/VerificationController.php +++ b/app/Http/Controllers/Auth/VerificationController.php @@ -25,7 +25,7 @@ class VerificationController extends Controller * * @var string */ - protected $redirectTo = '/home'; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Shop/ArticleController.php b/app/Http/Controllers/Shop/ArticleController.php index 61a34d27..f0788485 100644 --- a/app/Http/Controllers/Shop/ArticleController.php +++ b/app/Http/Controllers/Shop/ArticleController.php @@ -9,7 +9,6 @@ use App\Repositories\Shop\Articles; class ArticleController extends Controller { - public function show($id) { $data['article'] = Articles::getArticleToSell($id); diff --git a/app/Http/Controllers/Shop/Auth/ForgotPasswordController.php b/app/Http/Controllers/Shop/Auth/ForgotPasswordController.php deleted file mode 100644 index e348a1d7..00000000 --- a/app/Http/Controllers/Shop/Auth/ForgotPasswordController.php +++ /dev/null @@ -1,29 +0,0 @@ -middleware('guest')->except('logout'); - } - - protected function guard() - { - return Auth::guard('customer'); - } - - public function showLoginForm() - { - return view('Shop.auth.login'); - } - - public function login(Request $request) - { - $credentials = $request->validate([ - 'email' => 'required|email', - 'password' => 'required|min:8', - ]); - - if ($this->guard()->attempt($credentials, $request->get('remember'))) { - $request->session()->regenerate(); - return (back()->getTargetUrl() == route('Shop.login')) ? redirect()->intended(route('home')) : back(); - } - return back()->withInput($request->only('email', 'remember')); - } - - public function logout(Request $request) - { - $sessionKey = $this->guard()->getName(); - $this->guard()->logout(); - $request->session()->forget($sessionKey); - return redirect()->route('home'); - } - - public function username() - { - return 'email'; - } -} diff --git a/app/Http/Controllers/Shop/Auth/RegisterController.php b/app/Http/Controllers/Shop/Auth/RegisterController.php deleted file mode 100644 index 7a40a159..00000000 --- a/app/Http/Controllers/Shop/Auth/RegisterController.php +++ /dev/null @@ -1,85 +0,0 @@ - 'required|max:255', - 'first_name' => 'required|max:255', - 'email' => 'required|email|max:255|unique:shop_customers,email,NULL,id,deleted_at,NULL', - 'password' => ['required', 'confirmed', new Password()], - ]); - } - - public function showRegistrationForm() - { - return view('Shop.auth.register', $data ?? []); - } - - protected function create(array $data) - { - $user = Customer::withTrashed()->updateOrCreate(['email' => $data['email']], [ - 'active' => true, - 'first_name' => $data['first_name'], - 'last_name' => $data['last_name'], - 'email' => $data['email'], - 'password' => bcrypt($data['password']), - ]); - - return $user; - } - - public function emailVerify() - { - if (Auth::user()->hasVerifiedEmail()) { - return redirect(route(config('boilerplate.app.redirectTo', 'boilerplate.dashboard'))); - } - - return view('boilerplate::auth.verify-email'); - } - - public function emailVerifyRequest(EmailVerificationRequest $request) - { - $request->fulfill(); - return redirect(route(config('boilerplate.app.redirectTo', 'boilerplate.dashboard'))); - } - - public function emailSendVerification(Request $request) - { - $request->user()->sendEmailVerificationNotification(); - return back()->with('message', 'Verification link sent!'); - } -} diff --git a/app/Http/Controllers/Shop/Auth/ResetPasswordController.php b/app/Http/Controllers/Shop/Auth/ResetPasswordController.php deleted file mode 100644 index 2a3803c9..00000000 --- a/app/Http/Controllers/Shop/Auth/ResetPasswordController.php +++ /dev/null @@ -1,50 +0,0 @@ -middleware('guest'); - } - - public function showResetForm(Request $request, $token = null) - { - $token = $request->route()->parameter('token'); - - return view('Shop.auth.passwords.reset')->with( - ['token' => $token, 'email' => $request->email] - ); - } - - protected function rules() - { - return [ - 'token' => 'required', - 'email' => 'required|email', - 'password' => ['required', 'confirmed', new PasswordRules()], - ]; - } - - public function broker() - { - return Password::broker('customers'); - } - - protected function guard() - { - return Auth::guard('customer'); - } -} diff --git a/app/Http/Controllers/Shop/CustomerController.php b/app/Http/Controllers/Shop/CustomerController.php index fd838ab0..66228d84 100644 --- a/app/Http/Controllers/Shop/CustomerController.php +++ b/app/Http/Controllers/Shop/CustomerController.php @@ -11,6 +11,7 @@ class CustomerController extends Controller { public function profile($id = false) { - return view('Shop.Customers.profile'); + $data = Customers::editProfile($id); + return view('Shop.Customers.profile', $data); } } diff --git a/app/Http/Controllers/Shop/OrderController.php b/app/Http/Controllers/Shop/OrderController.php index 3c0fb146..fc0faff5 100644 --- a/app/Http/Controllers/Shop/OrderController.php +++ b/app/Http/Controllers/Shop/OrderController.php @@ -9,6 +9,7 @@ use App\Repositories\Core\User\ShopCart; use App\Repositories\Shop\Customers; use App\Repositories\Shop\Deliveries; use App\Repositories\Shop\Orders; +use App\Repositories\Shop\Paybox; use App\Repositories\Shop\Baskets; use App\Repositories\Shop\SaleChannels; @@ -30,13 +31,13 @@ class OrderController extends Controller { $data = $request->all(); $data['customer_id'] = Customers::getId(); - $data['basket'] = Baskets::getBasketSummary(); - dump($data); - exit; + $data['sale_channel_id'] = $data['sale_channel_id'] ?? SaleChannels::getDefaultID(); + $data['basket'] = Baskets::getBasketSummary($data['sale_channel_id']); $order = Orders::saveOrder($data); if ($order) { - if ($data['payment'] == '1') { - return redirect()->route('Shop.Payments.online'); + if ($data['payment_type'] == '1') { + return Paybox::makeAuthorizationRequest($data['basket']['total_shipped']); + // return redirect()->route('Shop.Payments.online'); } else { return redirect()->route('Shop.Orders.confirmed'); } @@ -47,6 +48,7 @@ class OrderController extends Controller public function confirmed() { + ShopCart::clear(); return view('Shop.Orders.confirmed'); } } diff --git a/app/Http/Controllers/Shop/OrderPaymentController.php b/app/Http/Controllers/Shop/OrderPaymentController.php new file mode 100644 index 00000000..440232ba --- /dev/null +++ b/app/Http/Controllers/Shop/OrderPaymentController.php @@ -0,0 +1,18 @@ + $homepage], $id); } + + public static function getNumericHash($id) + { + return hexdec(self::getHash($id)); + } + + public static function getHash($id) + { + $name = self::get($id)->name ?? false; + return $name ? hash('crc32c', Str::slug($name)) : false; + } } diff --git a/app/Repositories/Shop/Baskets.php b/app/Repositories/Shop/Baskets.php index 38b6b8b2..4001f0db 100644 --- a/app/Repositories/Shop/Baskets.php +++ b/app/Repositories/Shop/Baskets.php @@ -16,39 +16,44 @@ class Baskets return $data ? ShopCart::add($data, $update) : false; } - public static function getBasketSummary() + public static function getBasketSummary($sale_channel_id = false) { $basket = ShopCart::getContent(); $offers = Offer::with('variation')->whereIn('id', ShopCart::keys())->get(); $total = 0; $total_taxed = 0; + $shipping = 5; foreach ($basket as $item) { $offer = $offers->where('id', $item->id)->first(); + $prices = Offers::getPrice($item->id, $item->quantity, $sale_channel_id); $detail[] = [ - 'id' => (int) $item->id, + 'offer_id' => (int) $item->id, 'name' => $offer->article->name . ' (' . $offer->variation->name . ')', 'quantity' => (int) $item->quantity, - 'price' => $item->price, - 'tax' => '', - 'price_taxed' => $item->price, - 'total' => self::getTotal($item->quantity, $item->price), - 'total_taxed' => self::getTotal($item->quantity, $item->price), + 'price' => (float) $prices->price, + 'tax' => $prices->price_taxed - $prices->price, + 'price_taxed' => (float) $prices->price_taxed, + 'total' => self::getTotal($item->quantity, $prices->price), + 'total_tax' => self::getTotal($item->quantity, $prices->price_taxed - $prices->price), + 'total_taxed' => self::getTotal($item->quantity, $prices->price_taxed), ]; - $total += self::getTotal($item->quantity, $item->price); - $total_taxed += self::getTotal($item->quantity, $item->price); + $total += self::getTotal($item->quantity, $prices->price); + $total_taxed += self::getTotal($item->quantity, $prices->price_taxed); } $data = [ 'detail' => $detail, 'total' => $total, 'taxes' => $total_taxed - $total, 'total_taxed' => $total_taxed, + 'shipping' => $shipping, + 'total_shipped' => $total_taxed + $shipping, ]; return $data ?? false; } public static function getTotal($quantity, $price) { - return (int) $quantity * $price; + return $quantity * $price; } public static function getBasket($sale_channel_id = false) diff --git a/app/Repositories/Shop/CustomerStats.php b/app/Repositories/Shop/CustomerStats.php index 47e1e4c3..11ecb119 100644 --- a/app/Repositories/Shop/CustomerStats.php +++ b/app/Repositories/Shop/CustomerStats.php @@ -4,9 +4,10 @@ namespace App\Repositories\Shop; use Spatie\Stats\BaseStats; -class CustomerStats extends BaseStats {} +class CustomerStats extends BaseStats { - public function getName() : string{ + public function getName() : string + { return 'customers'; } } diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php index c3de97ac..b5fefe1b 100644 --- a/app/Repositories/Shop/Customers.php +++ b/app/Repositories/Shop/Customers.php @@ -12,6 +12,16 @@ use App\Models\Shop\Customer; class Customers { + public static function editProfile($id = false) + { + $id = $id ? $id : self::getId(); + $data = [ + 'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(), + 'deliveries' => Deliveries::getAll('sale_channel')->toArray(), + ]; + dump($data); + return $data; + } public static function getAvatar($id = false) { diff --git a/app/Repositories/Shop/Deliveries.php b/app/Repositories/Shop/Deliveries.php index 2e6042f5..efba3df3 100644 --- a/app/Repositories/Shop/Deliveries.php +++ b/app/Repositories/Shop/Deliveries.php @@ -11,9 +11,10 @@ class Deliveries return Delivery::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray(); } - public static function getAll() + public static function getAll($relations = false) { - return Delivery::orderBy('name', 'asc')->get(); + $model = $relations ? Delivery::with($relations) : Delivery::query(); + return $model->orderBy('name', 'asc')->get(); } public static function getAllWithSaleChannel() diff --git a/app/Repositories/Shop/InvoiceStats.php b/app/Repositories/Shop/InvoiceStats.php index cf71ae0e..1679d0cb 100644 --- a/app/Repositories/Shop/InvoiceStats.php +++ b/app/Repositories/Shop/InvoiceStats.php @@ -4,9 +4,10 @@ namespace App\Repositories\Shop; use Spatie\Stats\BaseStats; -class InvoiceStats extends BaseStats {} +class InvoiceStats extends BaseStats { - public function getName() : string{ + public function getName() : string + { return 'invoices'; } } diff --git a/app/Repositories/Shop/Invoices.php b/app/Repositories/Shop/Invoices.php index 660281f8..cc1db812 100644 --- a/app/Repositories/Shop/Invoices.php +++ b/app/Repositories/Shop/Invoices.php @@ -8,12 +8,9 @@ use App\Models\Shop\Invoice; class Invoices { - public static function saveInvoice($order_id, $data) { $data['order_id'] = $order_id; - dump($data); - exit; return self::store($data); } @@ -29,6 +26,7 @@ class Invoices public static function create($data) { + InvoiceStats::increase($data['total_taxed']); $data['uuid'] = Str::uuid()->toString(); $data['ref'] = self::getNewRef(); return Invoice::create($data); @@ -44,6 +42,8 @@ class Invoices public static function delete($id) { + $invoice = self::get($id); + InvoiceStats::decrease($invoice->total_priced); return Invoice::destroy($id); } @@ -51,6 +51,6 @@ class Invoices { $ref = date('ym') . '00000'; $last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first(); - return $last_ref ? $last_ref + 1 : $ref + 1; + return $last_ref ? $last_ref->ref + 1 : $ref + 1; } } diff --git a/app/Repositories/Shop/OrderDetails.php b/app/Repositories/Shop/OrderDetails.php index 41b37304..61e37604 100644 --- a/app/Repositories/Shop/OrderDetails.php +++ b/app/Repositories/Shop/OrderDetails.php @@ -9,12 +9,8 @@ class OrderDetails public static function saveBasket($order_id, $data) { foreach ($data as $item) { - $detail = self::store([ - 'order_id' => $order_id, - 'offer_id' => $item['id'], - 'quantity' => $item['quantity'], - 'price_taxed' => $item['price'], - ]); + $item['order_id'] = $order_id; + $detail = self::store($item); } return true; } diff --git a/app/Repositories/Shop/OrderStats.php b/app/Repositories/Shop/OrderStats.php new file mode 100644 index 00000000..b27cab25 --- /dev/null +++ b/app/Repositories/Shop/OrderStats.php @@ -0,0 +1,13 @@ +id, $data); - return $order ? OrderDetails::saveBasket($order->id, $basket) : false; + $detail = OrderDetails::saveBasket($order->id, $basket['detail']); + unset($data['comment']); + unset($data['agree']); + unset($data['customer_id']); + unset($data['delivery_id']); + unset($data['detail']); + unset($data['payment_type']); + unset($data['sale_channel_id']); + return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false; + } + + public static function edit($id) + { + return Orders::get($id, ['customer', 'address', 'delivery', 'detail']); } public static function get($id, $relations = false) @@ -30,6 +41,7 @@ class Orders public static function create($data) { + OrderStats::increase(); return Order::create($data); } diff --git a/app/Repositories/Shop/Paybox.php b/app/Repositories/Shop/Paybox.php new file mode 100644 index 00000000..fa110120 --- /dev/null +++ b/app/Repositories/Shop/Paybox.php @@ -0,0 +1,53 @@ +setAmount($amount)->setCustomerEmail($customer_email) + ->setPaymentNumber(1)->send('paybox.send'); + } + + public static function verifyPayment($invoice_id) + { + $invoice = Invoices::get($invoice_id); + $payboxVerify = App::make(Verify::class); + try { + $success = $payboxVerify->isSuccess($invoice->total_shipped); + if ($success) { + // process order here after making sure it was real payment + } + echo "OK"; + } + catch (InvalidSignature $e) { + Log::alert('Invalid payment signature detected'); + } + } + + public static function getPreviousAuthorizedRequest() + { + $payment = PaymentModel::find($idOfAuthorizedPayment); + $captureRequest = App::make(Capture::class); + $response = $captureRequest->setAmount($payment->amount) + ->setPayboxCallNumber($payment->call_number) + ->setPayboxTransactionNumber($payment->transaction_number) + ->setDayRequestNumber(2) + ->send(); + + if ($response->isSuccess()) { + // process order here + } + } + +} diff --git a/composer.json b/composer.json index d52bcb2b..f2633822 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "arcanedev/log-viewer": "^8.1", "arrilot/laravel-widgets": "^3.13", "awobaz/compoships": "^2.1", + "balping/laravel-hashslug": "^2.2", "barryvdh/laravel-dompdf": "^0.9", "barryvdh/laravel-snappy": "^0.4.7", "box/spout": "^3.3", @@ -21,7 +22,6 @@ "cesargb/laravel-cascade-delete": "^1.2", "coduo/php-humanizer": "^4.0", "composer/composer": "^2.0.13", - "consoletvs/charts": "^7.2", "cornford/googlmapper": "^3.3", "darryldecode/cart": "^4.1", "datatables/datatables": "^1.10", @@ -63,6 +63,7 @@ "mpdf/mpdf": "^8.0", "mpociot/teamwork": "^6.1", "nicmart/tree": "^0.3", + "nicolaslopezj/searchable": "^1.13", "orangehill/iseed": "^3.0", "php-console/php-console": "^3.1", "proengsoft/laravel-jsvalidation": "^4.5", @@ -84,6 +85,7 @@ "spatie/image-optimizer": "^1.4", "spatie/laravel-activitylog": "^3.6", "spatie/laravel-backup": "^7.0", + "spatie/laravel-collection-macros": "^7.12", "spatie/laravel-cookie-consent": "^3.2", "spatie/laravel-mail-preview": "^4.0", "spatie/laravel-medialibrary": "^9.6", diff --git a/config/app.php b/config/app.php index 94044f34..5cb0062d 100644 --- a/config/app.php +++ b/config/app.php @@ -166,6 +166,7 @@ return [ * Package Service Providers... */ Darryldecode\Cart\CartServiceProvider::class, + Devpark\PayboxGateway\Providers\PayboxServiceProvider::class, /* * Application Service Providers... diff --git a/config/boilerplate/app.php b/config/boilerplate/app.php index 2db442aa..a251cf51 100644 --- a/config/boilerplate/app.php +++ b/config/boilerplate/app.php @@ -8,10 +8,14 @@ return [ 'domain' => '', // Redirect to this route after login - 'redirectTo' => 'home', + 'redirectTo' => 'Admin.home', // Backend locale 'locale' => config('app.locale'), 'logs' => true, + + // When set to true, allows admins to view the site as a user of their choice + 'allowImpersonate' => false, + ]; diff --git a/config/boilerplate/auth.php b/config/boilerplate/auth.php index dab66843..0e71e6e7 100644 --- a/config/boilerplate/auth.php +++ b/config/boilerplate/auth.php @@ -12,6 +12,6 @@ return [ ], 'throttle' => [ 'maxAttempts' => 3, // Maximum number of login attempts to allow - 'decayMinutes' => 1, // Number of minutes to wait before login will be available again + 'decayMinutes' => 5, // Number of minutes to wait before login will be available again ], ]; diff --git a/config/paybox.php b/config/paybox.php new file mode 100644 index 00000000..ab3e1d16 --- /dev/null +++ b/config/paybox.php @@ -0,0 +1,118 @@ + env('PAYBOX_TEST', false), + + /* + * Site number (provided by Paybox) + */ + 'site' => env('PAYBOX_SITE', ''), + + /* + * Rank number (provided by Paybox) + */ + 'rank' => env('PAYBOX_RANK', ''), + + /* + * Internal identifier (provided by Paybox) + */ + 'id' => env('PAYBOX_ID', ''), + + /* + * Password for Paybox back-office (It's required for Paybox direct - when you use + * capturing, otherwise it won't be used) + */ + 'back_office_password' => env('PAYBOX_BACK_OFFICE_PASSWORD', ''), + + /* + * HMAC authentication key - it should be generated in Paybox merchant panel + */ + 'hmac_key' => env('PAYBOX_HMAC_KEY', ''), + + /* + * Paybox public key location - you can get it from + * http://www1.paybox.com/wp-content/uploads/2014/03/pubkey.pem + */ + 'public_key' => storage_path('paybox/pubkey.pem'), + + /* + * Default return fields when going back from Paybox. You can change here keys as you want, + * you can add also more values from ResponseField class + */ + 'return_fields' => [ + 'amount' => \Devpark\PayboxGateway\ResponseField::AMOUNT, + 'authorization_number' => \Devpark\PayboxGateway\ResponseField::AUTHORIZATION_NUMBER, + 'order_number' => \Devpark\PayboxGateway\ResponseField::ORDER_NUMBER, + 'response_code' => \Devpark\PayboxGateway\ResponseField::RESPONSE_CODE, + 'payment_type' => \Devpark\PayboxGateway\ResponseField::PAYMENT_TYPE, + 'call_number' => \Devpark\PayboxGateway\ResponseField::PAYBOX_CALL_NUMBER, + 'transaction_number' => \Devpark\PayboxGateway\ResponseField::TRANSACTION_NUMBER, + // signature should be always last return field + 'signature' => \Devpark\PayboxGateway\ResponseField::SIGNATURE, + ], + + /* + * Those are routes names (not urls) where customer will be redirected after payment. If you + * want to use custom route with params in url you should set them dynamically when creating + * authorization data. You shouldn't change keys here. Those urls will be later launched using + * GET HTTP request + */ + 'customer_return_routes_names' => [ + 'accepted' => 'paybox.accepted', + 'refused' => 'paybox.refused', + 'aborted' => 'paybox.aborted', + 'waiting' => 'paybox.waiting', + ], + + /* + * This is route name (not url) where Paybox will send transaction status. This url is + * independent from customer urls and it's the only url that should be used to track current + * payment status for real. If you want to use custom route with params in url you should set it + * dynamically when creating authorization data. This url will be later launched using GET HTTP + * request + */ + 'transaction_verify_route_name' => 'paybox.process', + + /* + * Access urls for Paybox for production environment + */ + 'production_urls' => [ + /* + * Paybox System urls + */ + 'paybox' => [ + 'https://tpeweb.e-transactions.fr/cgi/MYchoix_pagepaiement.cgi', + 'https://tpeweb1.e-transactions.fr/cgi/MYchoix_pagepaiement.cgi', + ], + + /* + * Paybox Direct urls + */ + 'paybox_direct' => [ + 'https://ppps.e-transactions.fr/PPPS.php', + 'https://ppps1.e-transactions.fr/PPPS.php', + ], + ], + + /* + * Access urls for Paybox for test environment + */ + 'test_urls' => [ + /* + * Paybox System urls + */ + 'paybox' => [ + 'https://preprod-tpeweb.e-transactions.fr/cgi/MYchoix_pagepaiement.cgi', + ], + + /* + * Paybox Direct urls + */ + 'paybox_direct' => [ + 'https://preprod-ppps.e-transactions.fr/PPPS.php', + ], + ], +]; diff --git a/resources/views/Admin/Shop/Orders/edit.blade.php b/resources/views/Admin/Shop/Orders/edit.blade.php index f3a2cc03..5eefd822 100644 --- a/resources/views/Admin/Shop/Orders/edit.blade.php +++ b/resources/views/Admin/Shop/Orders/edit.blade.php @@ -5,45 +5,48 @@ ]) @section('content') - {{ Form::open(['route' => 'Admin.Shop.Orders.update', 'id' => 'order-form', 'autocomplete' => 'off']) }} - + -
| {{ $detail['quantity'] }} | -{{ $detail['name'] }} | -{{ $detail['price'] }} | -{{ $detail['total'] }} | -
| Quantité | +Nom | +Prix | +Total | + + + @foreach ($order['detail'] as $detail) +
|---|---|---|---|
| {{ $detail['quantity'] }} | +{{ $detail['name'] }} | +{{ $detail['price'] }} | +{{ $detail['total'] }} | +
-
+ :message
') !!}:message
') !!}{{ __('boilerplate::auth.password.intro') }}
+ @if (session('status')) +:message
') !!} +{{ __('boilerplate::auth.password_reset.intro') }}
- {!! Form::open(['route' => 'Shop.password.update', 'method' => 'post', 'autocomplete'=> 'off']) !!} + {!! Form::open(['route' => 'Shop.password.reset.post', 'method' => 'post', 'autocomplete'=> 'off']) !!} {!! Form::hidden('token', $token) !!}{{ __('boilerplate::auth.register.intro') }}
+ {!! Form::open(['route' => 'boilerplate.register', 'method' => 'post', 'autocomplete'=> 'off']) !!} +:message
') !!} +:message
') !!} +:message
') !!} +:message
') !!} +:message
') !!} +{{ $delivery['description'] }}
+- Vous n'avez pas encore de compte ? - {{ __('Inscrivez-vous') }} -
-@endsection diff --git a/resources/views/Shop/auth/passwords/email.blade.php b/resources/views/Shop/auth/passwords/email.blade.php deleted file mode 100644 index 6103e523..00000000 --- a/resources/views/Shop/auth/passwords/email.blade.php +++ /dev/null @@ -1,13 +0,0 @@ -@extends('Shop.auth.layout', ['title' => __('boilerplate::auth.password.title'), 'bodyClass' => 'hold-transition login-page']) - -@section('content') - -{{ __('boilerplate::auth.password.intro') }}
- @if (session('status')) -
+
- + Vous n'avez pas encore de compte ? + {{ __('Inscrivez-vous') }} +
@endsection diff --git a/resources/views/auth/partials/login.blade.php b/resources/views/auth/partials/login.blade.php index 0d255f62..4515e3fb 100644 --- a/resources/views/auth/partials/login.blade.php +++ b/resources/views/auth/partials/login.blade.php @@ -1,35 +1,42 @@ -{!! Form::open(['route' => 'boilerplate.login', 'method' => 'post', 'autocomplete'=> 'off']) !!} +{!! Form::open(['route' => 'login.post', 'method' => 'post', 'autocomplete'=> 'off']) !!}:message
') !!}:message
') !!}:message
') !!} @@ -13,4 +13,4 @@:message
') !!}{{ __('boilerplate::auth.password.intro') }}
- @if (session('status')) -:message
') !!} -{{ __('boilerplate::auth.password.intro') }}
+ @if (session('status')) +{{ __('boilerplate::auth.password_reset.intro') }}
- {!! Form::open(['route' => 'Shop.password.reset.post', 'method' => 'post', 'autocomplete'=> 'off']) !!} + {!! Form::open(['route' => 'Shop.password.update', 'method' => 'post', 'autocomplete'=> 'off']) !!} {!! Form::hidden('token', $token) !!}{{ __('boilerplate::auth.register.intro') }}
- {!! Form::open(['route' => 'boilerplate.register', 'method' => 'post', 'autocomplete'=> 'off']) !!} -:message
') !!} -:message
') !!} -:message
') !!} -:message
') !!} -:message
') !!} -