Skip to content

Commit

Permalink
Merge pull request #176 from avored/dev
Browse files Browse the repository at this point in the history
merging dev to master
  • Loading branch information
indpurvesh authored Jul 7, 2018
2 parents ade803b + e53b470 commit d231667
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 39 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(ConfigurationInterface $rep)
public function place(PlaceOrderRequest $request)
{
$orderProductData = Cart::all();

$user = $this->_getUser($request);
$billingAddress = $this->_getBillingAddress($request);
$shippingAddress = $this->_getShippingAddress($request);
Expand Down
32 changes: 15 additions & 17 deletions app/Http/Requests/PlaceOrderRequest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest as Request;
Expand All @@ -23,12 +24,11 @@ public function authorize()
*/
public function rules()
{

$validation['billing.first_name'] = 'required|max:255';
$validation['billing.last_name'] = 'required|max:255';
$validation['billing.phone'] = 'required|max:255';


//dd($this->request->all());

if (!Auth::check()) {
//$validation['user.email'] = 'required|email|max:255|unique:users';
Expand All @@ -37,32 +37,30 @@ public function rules()
//$validation['user.password'] = 'required|min:6|confirmed';
}


$billingData = $this->request->get('billing');

if (isset($billingData) && null === array_get($billingData,'id')) {
$validation['billing.address1'] = 'required|max:255';
$validation['billing.address2'] = 'max:255';
$validation['billing.country_id'] = 'required|max:255';
$validation['billing.state'] = 'required|max:255';
$validation['billing.city'] = 'required|max:255';
$validation['billing.postcode'] = 'required|max:255';
if (isset($billingData) && null === array_get($billingData, 'id')) {
$validation['billing.address1'] = 'required|max:255';
$validation['billing.address2'] = 'max:255';
$validation['billing.country_id'] = 'required|max:255';
$validation['billing.state'] = 'required|max:255';
$validation['billing.city'] = 'required|max:255';
$validation['billing.postcode'] = 'required|max:255';
}

if (null !== $this->request->get('use_different_shipping_address')) {
$validation['shipping.address1'] = 'required|max:255';
$validation['shipping.address2'] = 'max:255';
$validation['shipping.country_id'] = 'required|max:255';
$validation['shipping.state'] = 'required|max:255';
$validation['shipping.city'] = 'required|max:255';
$validation['shipping.postcode'] = 'required|max:255';
$validation['shipping.address1'] = 'required|max:255';
$validation['shipping.address2'] = 'max:255';
$validation['shipping.country_id'] = 'required|max:255';
$validation['shipping.state'] = 'required|max:255';
$validation['shipping.city'] = 'required|max:255';
$validation['shipping.postcode'] = 'required|max:255';
}

$validation['shipping_option'] = 'required';
$validation['payment_option'] = 'required';
$validation['agree'] = 'required';

return $validation;

}
}
10 changes: 10 additions & 0 deletions modules/avored/ecommerce/resources/lang/en/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'module-list' => 'Module List',
'module-upload' => 'Upload Module',
'module-upload-file' => 'Upload Module File',

'activate' => 'Activate',
'deactivate' => 'Deactivate',
];
51 changes: 51 additions & 0 deletions modules/avored/ecommerce/resources/views/module/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@extends('avored-ecommerce::layouts.app')

@section('content')
<div class="row mt-3">

<div class="col-12">
<div class="h1 float-left">
{{ __('avored-ecommerce::module.module-list') }}
</div>

<div class="float-right">
<a href="{{ route('admin.module.create') }}"
class="btn btn-primary">
{{ __('avored-ecommerce::module.module-upload') }}
</a>
</div>
</div>
</div>
<div class="row">
@if(count($modules) <= 0)
<p>Sorry No Modules Found</p>
@else
@foreach($modules as $module)
<div class="col-3 mt-3">
<div class="card">
<img class="card-img-top" src="http://placehold.it/250x250" alt="Card image cap">

<div class="card-body">
<div class="h5">{{ $module->name() }}</div>
<p>{{ $module->description() }}</p>
<button
class="btn btn-primary" disabled>

@if("enabled" == strtolower($module->status()))
Enabled
@else
Disabled
@endif
</button>
</div>

</div>
</div>
@endforeach

@endif

</div>

@endsection

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
card.mount('#card-element');
jQuery('.avored-payment-option').change(function (e) {
jQuery('#stripe').bind('paymentOptionChange', function (e) {
if (jQuery(this).prop('id') != "stripe") {
Expand All @@ -90,7 +90,7 @@
});
jQuery('#stripe').bind('paymentProcessStart', function (e) {
stripe.createToken(card).then(function (result) {
if (result.error) {
// Inform the customer that there was an error.
Expand All @@ -103,6 +103,7 @@
// Send the token to your server.
stripeTokenHandler(result.token);
jQuery("#place-order-button").trigger('paymentProcessEnd');
}
Expand All @@ -113,11 +114,19 @@
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var formWrapper = document.getElementById('stripe-card-form-wrapper');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
formWrapper.appendChild(hiddenInput);
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'payment_option');
hiddenInput.setAttribute('value', 'stripe');
formWrapper.appendChild(hiddenInput);
}
</script>
Expand Down
7 changes: 6 additions & 1 deletion modules/avored/ecommerce/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
Route::get('configuration', 'ConfigurationController@index')->name('configuration');
Route::post('configuration', 'ConfigurationController@store')->name('configuration.store');

/** -------- Modules ROUTES -------- **/
Route::get('module', 'ModuleController@index')->name('module.index');
Route::get('module/create', 'ModuleController@create')->name('module.create');
Route::get('module/{module}', 'ModuleController@show')->name('module.show');

Route::get('themes', 'ThemeController@index')->name('theme.index');
Route::get('themes/create', 'ThemeController@create')->name('theme.create');
Route::post('themes', 'ThemeController@store')->name('theme.store');
Expand All @@ -74,7 +79,7 @@
Route::delete('themes/{name}', 'ThemeController@destroy')->name('theme.destroy');

//Route::resource('order-status', 'OrderStatusController');

Route::get('order', 'OrderController@index')->name('order.index');

Route::post('get-property-element', 'PropertyController@getElementHtml')->name('property.element');
Expand Down
21 changes: 21 additions & 0 deletions modules/avored/ecommerce/src/Http/Controllers/ModuleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace AvoRed\Ecommerce\Http\Controllers;

use AvoRed\Framework\Modules\Facade as Module;

class ModuleController extends Controller
{
/**
* Display a listing of the modules.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$modules = Module::all();

return view('avored-ecommerce::module.index')
->with('modules', $modules);
}
}
23 changes: 17 additions & 6 deletions modules/avored/ecommerce/src/Payment/Stripe/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use AvoRed\Framework\Models\Database\Configuration;
use AvoRed\Framework\Payment\Payment as PaymentEcommerce;
use AvoRed\Framework\Payment\Contracts\Payment as PaymentContracts;
use AvoRed\Ecommerce\Models\Database\User;

class Payment extends PaymentEcommerce implements PaymentContracts
{
const CONFIG_KEY = 'payment_stripe_enabled';
const CONFIG_KEY = 'payment_stripe_enabled';

const CONFIG_PUBLISHABLE_KEY = 'payment_stripe_publishable_key';
const CONFIG_PUBLISHABLE_KEY = 'payment_stripe_publishable_key';

const CONFIG_SECRET_KEY = 'payment_stripe_secret_key';
const CONFIG_SECRET_KEY = 'avored_stripe_secret_key';
/**
* Payment Option Identifier.
*
Expand Down Expand Up @@ -80,8 +81,8 @@ public function process($orderData, $cartProducts, $request)
$taxTotal = 0;

foreach ($cartProducts as $product) {
$subTotal += $product['price'] * $product['qty'];
$taxTotal += $product['tax_amount'] * $product['qty'];
$subTotal += $product->price() * $product->qty();
$taxTotal += $product->tax() * $product->qty();
}

$total = (round($subTotal, 2) + round($taxTotal, 2)) * 100;
Expand All @@ -90,12 +91,22 @@ public function process($orderData, $cartProducts, $request)
$apiKey = Configuration::getConfiguration(self::CONFIG_SECRET_KEY);

Stripe::setApiKey($apiKey);
//dd($orderData);
//$user = User::find($orderData['user_id']);
//$customer = \Stripe\Customer::create([
// 'email' => $user->email,
// 'description' => 'Customer for One of Charge ' . $user->id,
// 'source' => $request->get('stripeToken')
// ]);

//dd($request->all());
//dd($request->get('stripeToken'));

$response = Charge::create([
'amount' => $totalCents,
'currency' => 'nzd',
'source' => $request->get('stripeToken'), // obtained with Stripe.js
'description' => 'AvoRed E commerce',
'description' => 'AvoRed E commerce Payment',
]);

return $response;
Expand Down
20 changes: 15 additions & 5 deletions modules/avored/ecommerce/src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function registerPassportResources()
*/
protected function registerAdminMenu()
{
AdminMenuFacade::add('shop', function(AdminMenu $shopMenu) {
AdminMenuFacade::add('shop', function (AdminMenu $shopMenu) {
$shopMenu->label('Shop')
->route('#')
->icon('fas fa-cart-plus');
Expand Down Expand Up @@ -214,10 +214,10 @@ protected function registerAdminMenu()
->icon('fas fa-dollar-sign');
$shopMenu->subMenu('order', $orderMenu);

AdminMenuFacade::add('cms',function(AdminMenu $cmsMenu) {
AdminMenuFacade::add('cms', function (AdminMenu $cmsMenu) {
$cmsMenu->label('CMS')
->route('#')
->icon('fas fa-building');
->icon('fas fa-building');
});

$cmsMenu = AdminMenuFacade::get('cms');
Expand All @@ -235,12 +235,12 @@ protected function registerAdminMenu()
->icon('fas fa-leaf');
$cmsMenu->subMenu('menu', $frontMenu);

AdminMenuFacade::add('system', function(AdminMenu $systemMenu) {
AdminMenuFacade::add('system', function (AdminMenu $systemMenu) {
$systemMenu->label('System')
->route('#')
->icon('fas fa-cogs');
});

$systemMenu = AdminMenuFacade::get('system');

$configurationMenu = new AdminMenu();
Expand Down Expand Up @@ -277,6 +277,16 @@ protected function registerAdminMenu()
->route('admin.theme.index')
->icon('fas fa-adjust');
$systemMenu->subMenu('themes', $themeMenu);

//$moduleMenu = new AdminMenu();

$systemMenu->subMenu('module', function (AdminMenu $moduleMenu) {
//dd($moduleMenu);
$moduleMenu->key('module')
->label('Module')
->route('admin.module.index')
->icon('fas fa-adjust');
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

<div class="form-check">

<input class="avored-payment-option form-check-input {{ $errors->has('payment_option') ? ' is-invalid' : '' }}"
type="radio" name="payment_option"
id="{{ $paymentOption->identifier() }}"
value="{{ $paymentOption->identifier() }}">
<input
type="radio" name="payment_option"
id="{{ $paymentOption->identifier() }}"
value="{{ $paymentOption->identifier() }}"
@if($errors->has('payment_option'))
class="is-invalid avored-payment-option form-check-input"
@else
class="avored-payment-option form-check-input"
@endif

/>

<label for="{{ $paymentOption->identifier() }}"
class="form-check-label">
Expand Down
16 changes: 12 additions & 4 deletions themes/avored/default/views/checkout/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,37 @@ function checkIfUserExist(data) {
jQuery('.avored-payment-option').change(function (e) {
e.preventDefault();
jQuery(this).trigger('paymentOptionChange');
});
jQuery('#place-order-button').click(function (e) {
e.preventDefault();
if(jQuery('.payment-radio-options input:radio').length <= 0) {
//if(jQuery('.payment-radio-options input:radio').length <= 0) {
jQuery('.payment-radio-options input:radio').each(function (i, el) {
if (jQuery(el).is(':checked')) {
jQuery(this).prop('disabled', true);
jQuery(el).trigger('paymentProcessStart');
}
});
} else {
jQuery('#place-order-form').submit();
}
//} else {
//jQuery('#place-order-form').submit();
//}
});
jQuery("#place-order-button").bind('paymentProcessEnd', function (e) {
e.preventDefault();
//alert('working');
//return true;
jQuery(this).prop('disabled',false);
jQuery('#place-order-form').submit();
});
Expand Down

0 comments on commit d231667

Please sign in to comment.