1 Commits

Author SHA1 Message Date
franknstayn
a2cddafa5f added shipping fee 2020-05-12 20:52:21 +08:00
7 changed files with 417 additions and 374 deletions

View File

@@ -6,7 +6,7 @@
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$public /$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.crewsportswear.com/beta/$1 [R,L]
#RewriteRule ^(.*)$ https://www.crewsportswear.com/beta/$1 [R,L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

View File

@@ -1,4 +1,6 @@
<?php namespace App\Http\Controllers\paypal;
<?php
namespace App\Http\Controllers\paypal;
use App\Http\Requests;
use App\Http\Controllers\Controller;
@@ -13,38 +15,37 @@ use Session;
use Redirect;
use Mail;
class PaypalController extends Controller {
class PaypalController extends Controller
{
private $_apiContext;
public function __construct()
{
$this->_apiContext = PayPal::ApiContext(
$this->_apiContext = Paypal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
config('services.paypal.secret')
);
/* $this->_apiContext->setConfig(array(
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
)); */
));
// live
$this->_apiContext->setConfig(array(
'mode' => 'live',
'service.EndPoint' => 'https://api.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
// $this->_apiContext->setConfig(array(
// 'mode' => 'live',
// 'service.EndPoint' => 'https://api.paypal.com',
// 'http.ConnectionTimeOut' => 30,
// 'log.LogEnabled' => true,
// 'log.FileName' => storage_path('logs/paypal.log'),
// 'log.LogLevel' => 'FINE'
// ));
}
@@ -80,7 +81,7 @@ class PaypalController extends Controller {
$getSubtotal = $m->getSubtotal($cartKey);
$grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey);
$store_array = $m->selectTeamStore('Id', $grouped_item[0]->StoreId);
$shipping_charges = 0;
foreach ($items as $item) {
if ($item->VoucherId != null) {
@@ -103,6 +104,8 @@ class PaypalController extends Controller {
);
}
}
$shipping_charges += $item->ShippingFee * $item->Quantity;
}
$order_items = array();
@@ -131,19 +134,20 @@ class PaypalController extends Controller {
// $order_items[$key]->setDescription($descriptions);
// $order_items[$key]->setTax(10);
$order_items[$key]->setPrice($item->Price);
}
$item_list = PayPal::ItemList();
$item_list->setItems($order_items);
$amount_details = PayPal::Details();
$amount_details->setSubtotal($order_grandtotal);
$amount_details->setTax($tax);
$amount_details->setShipping($shipping_charges);
$amount = PayPal::Amount();
$amount->setCurrency($store_array[0]->StoreCurrency);
$amount->setDetails($amount_details);
$amount->setTotal($order_grandtotal + $tax);
$amount->setTotal($order_grandtotal + $tax + $shipping_charges);
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
@@ -229,6 +233,13 @@ class PaypalController extends Controller {
$total = $obj->transactions[0]->amount->total;
$sub_total = $obj->transactions[0]->amount->details->subtotal;
$tax = $obj->transactions[0]->amount->details->tax;
$shipping_cost = $obj->transactions[0]->amount->details->shipping;
$relatedResources = $obj->transactions[0]->related_resources[0];
$saleId = $relatedResources->sale->id; // transaction_id
//
// $sale = $relatedResources[0]->getSale();
// echo $saleId = $sale->getId();
$currency = $obj->transactions[0]->amount->currency;
$invoice_number = $obj->transactions[0]->invoice_number;
@@ -263,7 +274,6 @@ class PaypalController extends Controller {
$getSubtotal = $m->getSubtotal($cartKey);
$payment_details = array(
'UserId' => $userId,
'CartKey' => $cartKey,
'PaymentId' => $id,
@@ -277,8 +287,9 @@ class PaypalController extends Controller {
'Payer_Email' => $email,
'Payer_Firstname' => $first_name,
'Payer_Lastname' => $last_name,
'PaymentMethod' =>$payment_method
'PaymentMethod' => $payment_method,
'ShippingCost' => $shipping_cost,
'TransactionId' => $saleId,
);
$p_id = $paypal_model->insertToPaypalDetails($payment_details);
@@ -330,7 +341,8 @@ class PaypalController extends Controller {
$email_cc = "orders@crewsportswear.com";
}
$explode_other_email = explode(",", $email_cc);
// $explode_other_email = explode(",", $email_cc);
$explode_other_email = "orders@crewsportswear.com"; // test_email
$data = array(
'order_item_array' => $order_item_array,
@@ -347,8 +359,9 @@ class PaypalController extends Controller {
$message->bcc($data['email_cc'], 'Orders From CREW Sportswear');
$message->to($data['receiver'])->subject($data['subject']);
});
// end email sending
// end email sending
$m->delete_cartTmp("CartKey", $cartKey);
$request->session()->forget('cartkey'); // clear session for cartkey
// redirect to thank you page.
@@ -389,5 +402,4 @@ class PaypalController extends Controller {
return redirect()->route('cart');
}
}

View File

@@ -1,4 +1,6 @@
<?php namespace App\Http\Controllers\teamstore;
<?php
namespace App\Http\Controllers\teamstore;
use App\Http\Requests;
use App\Http\Controllers\Controller;
@@ -11,7 +13,8 @@ use Mail;
use Analytics;
class TeamStoreController extends Controller {
class TeamStoreController extends Controller
{
public function index(Request $request, $teamStoreURL)
{
@@ -42,7 +45,6 @@ class TeamStoreController extends Controller {
return redirect()->back();
}
}
}
}
@@ -70,7 +72,6 @@ class TeamStoreController extends Controller {
'thumb' => $displayThumbnails
);
} else {
$thumbnails[] = array(
'folder' => $store_array[0]->ImageFolder,
@@ -135,7 +136,6 @@ class TeamStoreController extends Controller {
// sort only
$stores_array = $m->selectTeamstoreFilter($field, $sort_value);
}
} else {
$field = "StoreName";
$sort_value = "ASC";
@@ -158,11 +158,9 @@ class TeamStoreController extends Controller {
if ($store_array) {
$request->session()->put('teamstore_data_array', $store_array);
return redirect('teamstore/' . $store_array[0]->StoreUrl);
} else {
return redirect()->back()->with('errors', 'Invalid Password.');
}
}
private $teams_array;
@@ -185,7 +183,6 @@ class TeamStoreController extends Controller {
'ImageClass' => 'active'
);
$thumbnails_array[] = $data;
}
@@ -217,7 +214,6 @@ class TeamStoreController extends Controller {
->with('teams_array', $teams_array)
->with('sizes_array', $sizes_array)
->with('available_qty', $availableQty);
}
public function login(Request $request)
@@ -263,8 +259,6 @@ class TeamStoreController extends Controller {
->render();
return $handle_form;
}
public function addToCart(Request $request)
@@ -288,6 +282,7 @@ class TeamStoreController extends Controller {
$product_form = $product_array[0]->ProductForm;
$design_code = $product_array[0]->DesignCode;
$product_name = $product_array[0]->ProductName;
$shipping_fee = $product_array[0]->ShippingFee;
$teamstore_array = $m->selectTeamStore('Id', $TeamStoreId);
@@ -322,7 +317,8 @@ class TeamStoreController extends Controller {
'JerseySize' => $order_jersey_size[$key],
'ShortsSize' => $order_shorts_size[$key],
'Price' => $final_price,
'Quantity' => 1
'Quantity' => 1,
'ShippingFee' => $shipping_fee
);
}
} elseif ($product_form == "tshirt-form") {
@@ -338,7 +334,8 @@ class TeamStoreController extends Controller {
'ProductName' => $product_name,
'Size' => $post['uniformSize'],
'Price' => $ProductPrice,
'Quantity' => $post['quantity']
'Quantity' => $post['quantity'],
'ShippingFee' => $shipping_fee
);
} elseif ($product_form == "quantity-form") {
@@ -352,10 +349,9 @@ class TeamStoreController extends Controller {
'ProductURL' => $ProductURL,
'ProductName' => $product_name,
'Price' => $ProductPrice,
'Quantity' => $post['quantity']
'Quantity' => $post['quantity'],
'ShippingFee' => $shipping_fee
);
} elseif ($product_form == "name-number-form") {
$order_names = $post['order_names'];
@@ -374,7 +370,8 @@ class TeamStoreController extends Controller {
'Name' => $order_names[$key],
'Number' => $order_number[$key],
'Price' => $ProductPrice,
'Quantity' => 1
'Quantity' => 1,
'ShippingFee' => $shipping_fee
);
}
} elseif ($product_form == "name-number-size-form") {
@@ -397,10 +394,10 @@ class TeamStoreController extends Controller {
'Size' => $order_size[$key],
'Number' => $order_number[$key],
'Price' => $ProductPrice,
'Quantity' => 1
'Quantity' => 1,
'ShippingFee' => $shipping_fee
);
}
} elseif ($product_form == "number-form") {
$order_number = $post['order_number'];
@@ -417,7 +414,8 @@ class TeamStoreController extends Controller {
'ProductName' => $product_name,
'Number' => $order_number[$key],
'Price' => $ProductPrice,
'Quantity' => 1
'Quantity' => 1,
'ShippingFee' => $shipping_fee
);
}
} elseif ($product_form == "name-name2-size-form") {
@@ -440,7 +438,8 @@ class TeamStoreController extends Controller {
'Name2' => $order_names2[$key],
'Size' => $order_size[$key],
'Price' => $ProductPrice,
'Quantity' => 1
'Quantity' => 1,
'ShippingFee' => $shipping_fee
);
}
} elseif ($product_form == "name-size-form") {
@@ -461,7 +460,8 @@ class TeamStoreController extends Controller {
'Name' => $order_names[$key],
'Size' => $order_size[$key],
'Price' => $ProductPrice,
'Quantity' => 1
'Quantity' => 1,
'ShippingFee' => $shipping_fee
);
}
} elseif ($product_form == "jersey-and-shorts-quantity-form") {
@@ -491,10 +491,10 @@ class TeamStoreController extends Controller {
'JerseySize' => $order_jersey_size[$key],
'ShortsSize' => $order_shorts_size[$key],
'Price' => $final_price,
'Quantity' => $quantity[$key]
'Quantity' => $quantity[$key],
'ShippingFee' => $shipping_fee
);
}
}
} elseif ($product_form == "number-jersey-shorts-form") {
@@ -523,7 +523,8 @@ class TeamStoreController extends Controller {
'JerseySize' => $order_jersey_size[$key],
'ShortsSize' => $order_shorts_size[$key],
'Price' => $final_price,
'Quantity' => 1
'Quantity' => 1,
'ShippingFee' => $shipping_fee
);
}
}
@@ -543,7 +544,8 @@ class TeamStoreController extends Controller {
));
}
public function cart(Request $request){
public function cart(Request $request)
{
$m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey');
@@ -560,7 +562,7 @@ class TeamStoreController extends Controller {
$item_thumbs = $m->selectDisplayCartThumb();
$store_array = $m->selectTeamStore('Id', $defId);
$shipping_cost = 0;
if ($items) {
$voucherIds = array();
@@ -568,6 +570,8 @@ class TeamStoreController extends Controller {
if ($item->VoucherId != null) {
$voucherIds[] = $item->VoucherId;
}
$shipping_cost += $item->ShippingFee * $item->Quantity;
}
$vouchers = $m->selectVoucherWhereIn($voucherIds);
}
@@ -605,10 +609,12 @@ class TeamStoreController extends Controller {
->with('row', $items)
->with('img_thumb', $item_thumbs)
->with('getSubtotal', $finalSubTotal)
->with('store_array', $store_array);
->with('store_array', $store_array)
->with('shipping_cost', $shipping_cost);
}
public function addVoucher(Request $request){
public function addVoucher(Request $request)
{
$cartKey = $request->session()->get('cartkey');
if ($cartKey == "") {
@@ -665,7 +671,6 @@ class TeamStoreController extends Controller {
if ($item->VoucherId != null) {
$voucherIds[] = $item->VoucherId;
}
}
$vouchers = $TeamStoreModel->selectVoucherWhereIn($voucherIds);
@@ -723,9 +728,6 @@ class TeamStoreController extends Controller {
'message' => $message,
'subtotal' => $finalSubTotal
));
} else {
return response()->json(array(
@@ -755,7 +757,6 @@ class TeamStoreController extends Controller {
->with('row', $items)
->with('getSubtotal', $getSubtotal)
->with('array_address_book', $array_address_book);
}
public function mail()
@@ -771,13 +772,10 @@ class TeamStoreController extends Controller {
// dd('Mail Send Successfully');
Mail::raw('Text to e-mail', function($message)
{
Mail::raw('Text to e-mail', function ($message) {
$message->from('us@example.com', 'Laravel');
$message->to('frank.begornia@yahoo.com')->subject('sample email');
});
}
}

View File

@@ -219,4 +219,10 @@ class TeamStoreModel extends Model {
return $i;
}
function delete_cartTmp($field, $cartKey){
$i = DB::table('cart_tmp')
->where($field, $cartKey)
->delete();
return $i;
}
}

View File

@@ -35,15 +35,15 @@ return [
],
// sandbox
/* 'paypal' => [
'client_id' => 'AQuz-HKzQiL7FygkG8skSekaWf-RP6Rgj4f1XeX1Ghp86bUFj7tQXVT1xbpluu5_WCGRbQpOVGtlJKVB',
'secret' => 'EJAMKxQsl-mFkL_4J_90cvTamYfcsgswqgIxz9wQPiRAwJ6sy_wNsttMlmrXIpxI96JpYzdMXkLCHAPz'
], */
// live
'paypal' => [
'client_id' => 'AUqBUFW5lfyYmrlBtFZA3RNw45sttM3ltbvS_d4qCVBMrkcMG9rEeivGvtNFSy8XTiEp50YyQ6khKxbq',
'secret' => 'ELlnuiupoFKwGUSc2g5j-sD1EmsvKpdhth1gFV7njpfvyNtKsK8WwIKUMOS0ehJcRatV865eMhfgsnd_'
'client_id' => 'AR1FObcz7lD_p53BJpOw1Frf0hIJ1-VOArYoDnsNJXVvoxjYv6mOKBBvdvZBzQcpBPfB_AJnofdalO0t',
'secret' => 'EK0CB8Re802HTxLQawwjAYzOu-SxrFOwuVG7qZ_nSovwgkp77wVs6k4XelXj2v5Il5llCFzsWs_Eb4o-'
],
// live
// 'paypal' => [
// 'client_id' => 'AUqBUFW5lfyYmrlBtFZA3RNw45sttM3ltbvS_d4qCVBMrkcMG9rEeivGvtNFSy8XTiEp50YyQ6khKxbq',
// 'secret' => 'ELlnuiupoFKwGUSc2g5j-sD1EmsvKpdhth1gFV7njpfvyNtKsK8WwIKUMOS0ehJcRatV865eMhfgsnd_'
// ],
];

View File

@@ -387,6 +387,10 @@
<td class="col-md-3">Tax</td>
<td>{{ $array_payment_details[0]->Tax . ' ' . $array_payment_details[0]->Currency }}</td>
</tr>
<tr>
<td class="col-md-3">Shipping Fee</td>
<td>{{ $array_payment_details[0]->ShippingCost . ' ' . $array_payment_details[0]->Currency }}</td>
</tr>
<tr>
<td class="col-md-3">Total</td>
<td>{{ $array_payment_details[0]->Total . ' ' . $array_payment_details[0]->Currency }}</td>

View File

@@ -46,7 +46,30 @@
</div>
<div style="border: 1px solid #e2e2e2; padding: 10px; border-bottom: none;">
<h3>Subtotal: <span id="my_subtotal">{{ round($getSubtotal, 2) }}</span> <small>{{ $store_array[0]->StoreCurrency }}</small></h3>
{{-- <h3>Subtotal: <span id="my_subtotal">{{ round($getSubtotal, 2) }}</span> <small>{{ $store_array[0]->StoreCurrency }}</small></h3> --}}
<div class="alert alert-info">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<p>Free Shipping on orders with subtotal over 150.00 {{ $store_array[0]->StoreCurrency }}</p>
</div>
<table class="table table-bordered">
<tr>
<th>Subtotal</th>
<td>{{ round($getSubtotal, 2) }}</span> <small>{{ $store_array[0]->StoreCurrency }}</td>
</tr>
<tr>
<th>Tax</th>
<td>{{ round($getSubtotal, 2) * 0.10 }}</span> <small>{{ $store_array[0]->StoreCurrency }}</td>
</tr>
<tr>
<th>Shipping Fee</th>
<td>{{ round($shipping_cost, 2) }}</span> <small>{{ $store_array[0]->StoreCurrency }}</td>
</tr>
<tr>
<th><h5>Total<h5></th>
<td><h5>{{ round($getSubtotal + $shipping_cost + ($getSubtotal * 0.10), 2) }}</span> <small>{{ $store_array[0]->StoreCurrency }}</h5></td>
</tr>
</table>
<hr>
<div class="form-group" id="voucher_list">
@foreach($row as $item)