updated checkout flow

This commit is contained in:
franknstayn
2021-10-09 20:25:36 +08:00
parent eea777b544
commit f8b87ea787
9 changed files with 135 additions and 85 deletions

View File

@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
use App\Traits\CaptchaTrait;
use App\User;
use Illuminate\Support\Facades\Validator;
use App\Models\user\UserModel;
use Illuminate\Http\Request;
@@ -72,6 +73,7 @@ class CustomAuthController extends Controller
public function postRegister(Request $request)
{
$post = $request->all();
$userModel = new UserModel;
$post['captcha'] = $this->captchaCheck();
@@ -87,6 +89,12 @@ class CustomAuthController extends Controller
'g-recaptcha-response.required' => 'Captcha is required',
'captcha.min' => 'Wrong captcha, please try again.'
]
// $post,
// [
// 'username' => 'unique:user_logins',
// 'email' => 'unique:user_logins',
// ]
);
@@ -115,7 +123,7 @@ class CustomAuthController extends Controller
));
}
User::create([
$user = User::create([
'name' => $post['name'],
'username' => $post['username'],
'email' => $post['email'],
@@ -123,10 +131,19 @@ class CustomAuthController extends Controller
'role' => 'user'
]);
$country = explode("_", $post['country']);
$data = array(
'UserId' => $user->id,
'CountryCode' => $country[0],
'Country' => $country[1]
);
$userModel->insertAddressBook($data);
Auth::attempt(['email' => $post['email'], 'password' => $post['password']]);
return response()->json(array(
'success' => true
'success' => true,
'redirect' => $post['redirect']
));
}
}

View File

@@ -79,16 +79,25 @@ class PaypalController extends Controller
{
$UserModel = new UserModel;
if (Auth::guest()) {
$message = 'Please <a href="' . url('auth/login') . '">Sign in</a> to your account to proceed.';
Session::flash('msg', $message);
return Redirect::back();
}
// if (Auth::guest()) {
// $message = 'Please <a href="' . url('auth/login') . '">Sign in</a> to your account to proceed.';
// Session::flash('msg', $message);
// return Redirect::back();
// }
$userId = Auth::user()->id;
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
if (count($array_address_book) <= 0) {
$message = 'Please add Shipping address.';
if (
count($array_address_book) <= 0 ||
$array_address_book[0]->Fullname == null ||
$array_address_book[0]->ContactNumber == null ||
$array_address_book[0]->Address == null ||
$array_address_book[0]->State == null ||
$array_address_book[0]->City == null ||
$array_address_book[0]->ZipCode == null
) {
$message = 'Please complete your <a href="'.url('user/address-book').'"><u>shipping address</u></a>.';
Session::flash('cartkeyError', $message);
return Redirect::back();
}
@@ -115,14 +124,14 @@ class PaypalController extends Controller
$payer = PayPal::Payer();
$payer->setPaymentMethod('paypal');
$inputFields = Paypal::InputFields();
$inputFields->setAllowNote(true)
->setNoShipping(1)
->setAddressOverride(0);
$webProfile = Paypal::WebProfile();
$webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
// ->setPresentation($presentation)
->setInputFields($inputFields);
// $inputFields = Paypal::InputFields();
// $inputFields->setAllowNote(true)
// ->setNoShipping(1)
// ->setAddressOverride(0);
// $webProfile = Paypal::WebProfile();
// $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
// // ->setPresentation($presentation)
// ->setInputFields($inputFields);
// $shipping = PayPal::ShippingAddress();
// $shipping->setRecipientName($array_address_book[0]->Fullname);
@@ -422,7 +431,7 @@ class PaypalController extends Controller
$currency = $obj->transactions[0]->amount->currency;
$invoice_number = $obj->transactions[0]->invoice_number;
// var_dump( $obj->transactions[0]->item_list->phone);
//shipping address details
$recipient_name = $obj->transactions[0]->item_list->shipping_address->recipient_name;
$line1 = $obj->transactions[0]->item_list->shipping_address->line1;

View File

@@ -1,9 +1,13 @@
<?php namespace App\Http\Middleware;
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Support\Facades\URL;
class Authenticate {
class Authenticate
{
/**
* The Guard implementation.
@@ -32,19 +36,19 @@ class Authenticate {
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest())
{
if ($request->ajax())
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
$prev = URL::previous();
if (str_contains($prev, ['cart'])) {
return redirect()->guest('auth/register?redirectUrl='. $prev);
}
else
{
return redirect()->guest('auth/login');
}
}
return $next($request);
}
}

View File

@@ -1,5 +1,6 @@
<?php
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Route;
// use Spatie\LaravelAnalytics\LaravelAnalytics;
/*
@@ -150,6 +151,7 @@ Route::group(['middleware' => 'normaluser'], function () {
Route::group(['middleware' => 'auth'], function () {
// PAYPAL ROUTES
Route::get('payPremium', ['as' => 'payPremium', 'uses' => 'paypal\PaypalController@payPremium']);
Route::get('getCheckout', ['as' => 'getCheckout', 'uses' => 'paypal\PaypalController@getCheckout']);
Route::get('getDone', ['as' => 'getDone', 'uses' => 'paypal\PaypalController@getDone']);

View File

@@ -22,6 +22,7 @@
<div class="col col-lg-5">
<div id="register-response-msg"></div>
<form role="form" id="frm-register">
<input type="hidden" name="redirect" value="{{ Request::get('redirectUrl') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="mb-3">
<label class="control-label">Fullname</label>
@@ -48,6 +49,14 @@
<input type="password" class="form-control" name="password_confirmation" placeholder="Confirm Password" data-rule-equalTo="#password" required>
</div>
<div class="mb-3">
<label class="control-label">Select Country</label>
<select name="country" id="country" class="form-control">
<option value="US_United States">United States</option>
<option value="CA_Canada">Canada</option>
</select>
</div>
<div class="mb-3">
<div class="g-recaptcha text-center" data-sitekey="{{ env('CAPTCHA_SITE_KEY') }}"></div>
</div>

View File

@@ -322,9 +322,12 @@
@endif
<h3>Order Summary</h3>
</div>
@if (!Auth::guest())
<div style="border: 1px solid #e2e2e2; padding: 10px; border-bottom: none;">
<p><strong>Ship to:</strong></p>
@if ($address_book === null)
<a href="{{ url('user/address-book') }}">[ Add ]</a>
@else
@@ -332,18 +335,27 @@
<div>{{ $address_book[0]->ContactNumber }}</div>
<div>
{{ $address_book[0]->Address . ', ' . $address_book[0]->State . ', ' . $address_book[0]->City . ', ' . $address_book[0]->Country . ', ' . $address_book[0]->CountryCode . ' ' . $address_book[0]->ZipCode }}
<a href="{{ url('user/address-book') }}">[ Edit ]</a> </div>
<a href="{{ url('user/address-book') }}">[ Edit ]</a>
</div>
@endif
</div>
@endif
<div style="border: 1px solid #e2e2e2; padding: 10px; border-bottom: none;">
<h5>Subtotal: <small>{{ number_format($tax['order_grandtotal'] , 2) . ' ' . $store_array[0]->StoreCurrency }}</small> </h5>
<h5>Shipping Fee: <small>{{ number_format($shipping_fee , 2) . ' ' . $store_array[0]->StoreCurrency }}</small> </h5>
<h5>Tax: <small>{{ number_format($tax['tax'] , 2) . ' ' . $store_array[0]->StoreCurrency }}</small> </h5>
<h5>Subtotal:
<small>{{ number_format($tax['order_grandtotal'], 2) . ' ' . $store_array[0]->StoreCurrency }}</small>
</h5>
<h5>Shipping Fee:
<small>{{ number_format($shipping_fee, 2) . ' ' . $store_array[0]->StoreCurrency }}</small>
</h5>
<h5>Tax:
<small>{{ number_format($tax['tax'], 2) . ' ' . $store_array[0]->StoreCurrency }}</small>
</h5>
<hr>
<h3>Total: <span id="my_subtotal">{{ number_format($tax['order_grandtotal'] + $shipping_fee + $tax['tax'], 2) }}</span>
<small>{{ $store_array[0]->StoreCurrency }}</small></h3>
<h3>Total: <span
id="my_subtotal">{{ number_format($tax['order_grandtotal'] + $shipping_fee + $tax['tax'], 2) }}</span>
<small>{{ $store_array[0]->StoreCurrency }}</small>
</h3>
{{-- {{ var_dump($tax) }}
{{ var_dump($shipping_fee) }} --}}
@@ -386,10 +398,8 @@
</div>
<div style="border: 1px solid #e2e2e2; padding: 10px;">
<a @if ($getSubtotal <= 0) disabled @endif href="{{ url('getCheckout') }}" class="btn btn-primary w-100"
style="background-color: #ffc300; border-color: #e2ad00; text-align: -webkit-center;"><img
src="{{ asset('/public/images/paypal1.png') }}" class="img img-responsive"
style="height:30px;"></a><br>
<a @if ($getSubtotal <= 0) disabled @endif href="{{ url('getCheckout') }}" class="btn w-100"
style="background-color: #ffc300; border-color: #e2ad00; text-align: -webkit-center;">Checkout</a><br>
<!-- <div class="my-2">
<button class="btn btn-lg btn-info w-100">Checkout with Voucher</button>
</div> -->

View File

@@ -7,14 +7,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="csrf_token" content="{{ csrf_token() }}" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Merchbay</title>
<link rel="icon" href="{{ asset('public/favicon.ico') }}">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;400;500;600;700;800;900&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;400;500;600;700;800;900&display=swap" rel="stylesheet">
<link href="{{ asset('public/assets/css/merchbay/styles.css') }}" rel="stylesheet">
<!-- <link href="{{ asset('public/assets/login/css/style.css') }}" rel="stylesheet">
@@ -48,7 +46,8 @@
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js = d.createElement(s);
js.id = id;
js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
@@ -59,10 +58,7 @@
@yield('main-content')
<!-- Your Chat Plugin code -->
<div class="fb-customerchat"
attribution="install_email"
attribution_version="biz_inbox"
page_id="107414144973415">
<div class="fb-customerchat" attribution="install_email" attribution_version="biz_inbox" page_id="107414144973415">
</div>
</div>
@include('merchbay.footer')
@@ -73,8 +69,7 @@
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script>
@@ -239,7 +234,11 @@
$("#register-response-msg").fadeIn(1000, function() {
if (response.success) {
if (response.redirect != "") {
window.location = response.redirect;
} else {
location.reload();
}
} else {
$("#register-response-msg").html(response.message);
}

View File

@@ -49,7 +49,7 @@
<label>Country</label>
<select class="form-control" name="countryCode" id="select_country" onchange="selectCountry(this)">
<option value="">Select Country</option>
<option value="US">United State</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
</select>
</div>

View File

@@ -49,7 +49,7 @@
<label>Country</label>
<select class="form-control" name="countryCode" id="select_country" onchange="selectCountry(this)" data-selected="{{ $array_address_book[0]->CountryCode }}">
<option value="">Select Country</option>
<option value="US">United State</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
</select>
</div>