crewsportswear update as of 3_18_19

This commit is contained in:
Frank John Begornia
2019-03-18 13:48:37 +08:00
parent 562f03488a
commit a2d88bc52e
71 changed files with 5443 additions and 85 deletions

View File

@@ -6,10 +6,13 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Paypal;
use App\Models\teamstore\TeamStoreModel;
use App\Models\user\UserModel;
use App\Models\paypal\PayPalModel;
use Auth;
use Session;
use Redirect;
use Mail;
class PaypalController extends Controller {
@@ -66,7 +69,10 @@ class PaypalController extends Controller {
$m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey');
$paypal_model = new PayPalModel;
$last_id = $paypal_model->getLastIdPaymentDetails();
$invoice_num = str_pad($last_id[0]->Id, 4,'0',STR_PAD_LEFT);
$cartKey = $request->session()->get('cartkey');
$items = $m->myCart($cartKey);
$getSubtotal = $m->getSubtotal($cartKey);
@@ -76,6 +82,8 @@ class PaypalController extends Controller {
$order_subtotal = $getSubtotal[0]->Subtotal;
$order_grandtotal = $getSubtotal[0]->Subtotal;
$tax = $order_grandtotal * 0.10;
$order_items = array();
foreach($items as $key => $item){
@@ -98,25 +106,30 @@ class PaypalController extends Controller {
$order_items[$key]->setCurrency('USD');
$order_items[$key]->setQuantity($item->Quantity);
// $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_subtotal);
$amount_details->setTax($tax);
$amount = PayPal::Amount();
$amount->setCurrency('USD');
$amount->setDetails($amount_details);
$amount->setTotal($order_grandtotal);
$amount->setTotal($order_grandtotal + $tax);
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($item_list);
$transaction->setDescription('Your transaction description');
$transaction->setInvoiceNumber(date('Y') . '-' . uniqid());
// $transaction->setDescription('Your transaction description');
$transaction->setInvoiceNumber(date('Ymd') . '-' . $invoice_num);
$redirectUrls = PayPal:: RedirectUrls();
$redirectUrls->setReturnUrl(route('getDone'));
@@ -188,22 +201,48 @@ class PaypalController extends Controller {
// }
$obj = json_decode($executePayment);
$line2 = null;
//details
$total = $obj->transactions[0]->amount->total;
$sub_total = $obj->transactions[0]->amount->details->subtotal;
$tax = $obj->transactions[0]->amount->details->tax;
$currency = $obj->transactions[0]->amount->currency;
$invoice_number = $obj->transactions[0]->invoice_number;
// var_dump($obj->transactions[0]->amount);
//shipping address details
$recipient_name = $obj->transactions[0]->item_list->shipping_address->recipient_name;
$line1 = $obj->transactions[0]->item_list->shipping_address->line1;
if(isset($obj->transactions[0]->item_list->shipping_address->line2)){
$line2 = $obj->transactions[0]->item_list->shipping_address->line2;
}
$city = $obj->transactions[0]->item_list->shipping_address->city;
$state = $obj->transactions[0]->item_list->shipping_address->state;
$postal_code = $obj->transactions[0]->item_list->shipping_address->postal_code;
$country_code = $obj->transactions[0]->item_list->shipping_address->country_code;
// payer info
$payment_method = $obj->payer->payment_method;
$email = $obj->payer->payer_info->email;
$first_name = $obj->payer->payer_info->first_name;
$last_name = $obj->payer->payer_info->last_name;
$_payer_id = $obj->payer->payer_info->payer_id;
/// end paypal codes
$paypal_model = new PayPalModel;
$m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey');
$userId = Auth::user()->id;
$user_email = Auth::user()->email;
$items = $m->myCart($cartKey); // item from cart_tmp
$getSubtotal = $m->getSubtotal($cartKey);
$payment_details = array(
'UserId' => $userId,
'CartKey' => $cartKey,
'PaymentId' => $id,
@@ -211,39 +250,66 @@ class PaypalController extends Controller {
'PayerId' => $payer_id,
'InvoiceNumber' => $invoice_number,
'Currency' => $currency,
'Total' => $total
'Total' => $total,
'SubTotal' => $sub_total,
'Tax' => $tax,
'Payer_Email' => $email,
'Payer_Firstname' => $first_name,
'Payer_Lastname' => $last_name,
'PaymentMethod' =>$payment_method
);
$i = $paypal_model->insertToPaypalDetails($payment_details);
// var_dump($i);
// foreach($items as $key => $val){
// $orders[] = array(
// 'Order' => $val->Order,
// 'ProductId' => $val->ProductId,
// 'CartKey' => $val->CartKey,
// 'ProductURL' => $val->ProductURL,
// 'TeamName' => $val->TeamName,
// 'Name' => $val->Name,
// 'Number' => $val->Number,
// 'Size' => $val->Size,
// 'Price' => $val->Price,
// 'Quantity' => $val->Quantity,
// );
// }
$p_id = $paypal_model->insertToPaypalDetails($payment_details);
$shipping_address = array(
'PaymentDetail_Id' => $p_id,
'recipient_name' => $recipient_name,
'line1' => $line1,
'line2' => $line2,
'city' => $city,
'state' => $state,
'postal_code' => $postal_code,
'country_code' => $country_code,
);
// iinsert shipping address
$paypal_model->insertShippingAddress($shipping_address);
// insert order from cart_tmp to orders table
$l = $paypal_model->insertToOrders($cartKey); // insert to orders table
//email sending
$newUserModel = new UserModel;
$order_item_array = $newUserModel->selectOrderItem($cartKey);
$item_goup_array = $newUserModel->itemGroup($cartKey);
$item_thumbs = $newUserModel->selectDisplayItemThumb();
$array_payment_details = $newUserModel->selectPaymentDetails('CartKey', $cartKey);
var_dump($items);
$data = array(
'order_item_array' => $order_item_array,
'item_goup_array' => $item_goup_array,
'img_thumb' => $item_thumbs,
'array_payment_details' => $array_payment_details,
'receiver' => $user_email,
'subject' => 'Order Details',
);
Mail::send('emails.orders', $data, function($message) use ($data) {
$message->from('no-reply@crewsportswear.com', 'CREW Sportswear');
$message->cc('orders@crewsportswear.com', 'Orders From CREW Sportswear');
$message->to($data['receiver'])->subject('Order Details');
// $paypal_model->insertToOrders($items); // insert to orders table
});
// end email sending
$request->session()->forget('cartkey'); // clear session for cartkey
// $request->session()->forget('cartkey'); // clear session for cartkey
// return view('paypal.get_done')
// ->with('currency', $currency)
// ->with('total', $total);
// redirect to thank you page.
return view('paypal.get_done')
->with('currency', $currency)
->with('total', $total);
}