Commit f68b67a4 by Angel MAS

medio acordar con el vendedor

parent 3e82a44a
......@@ -16,6 +16,7 @@ use Onestartup\Shop\Model\DetailShop as Item;
use Onestartup\Shop\Payment\MP;
use Onestartup\Shop\Notifications\PaymentClient;
use Onestartup\Shop\Notifications\PaymentAcordarClient;
use Onestartup\Shop\Notifications\PaymentClientCard;
use PayPal\Rest\ApiContext;
......@@ -42,99 +43,97 @@ class CartController extends Controller
public function show()
{
$total = $this->total();
$cart = \Session::get('cart');
$total = $this->total();
$cart = \Session::get('cart');
return view('shop-public::cart.show-cart')
->with('cart', $cart)
->with('total', $total);
}
return view('shop-public::cart.show-cart')
->with('cart', $cart)
->with('total', $total);
}
public function add(Product $product)
{
if (\Session::has('sale')) {
$sale = Sale::find(\Session::get('sale')->id);
$sale->status = 0;
$sale->save();
\Session::forget('sale');
}
$cart = \Session::get('cart');
$quantity = 1;
public function add(Product $product)
{
if (\Session::has('sale')) {
$sale = Sale::find(\Session::get('sale')->id);
$sale->status = 0;
$sale->save();
\Session::forget('sale');
}
$cart = \Session::get('cart');
$quantity = 1;
if (isset($cart[$product->slug])) {
$quantity = $cart[$product->slug]->quantity + 1;
}
$product->quantity = $quantity;
$cart[$product->slug] = $product;
if (isset($cart[$product->slug])) {
$quantity = $cart[$product->slug]->quantity + 1;
}
\Session::put('cart', $cart);
$product->quantity = $quantity;
$cart[$product->slug] = $product;
return redirect()->route('cart.show');
}
\Session::put('cart', $cart);
return redirect()->route('cart.show');
}
public function remove(Product $product)
{
$cart = \Session::get('cart');
if (!isset($cart[$product->slug])) {
return redirect()->route('cart.show');
}
public function remove(Product $product)
{
$cart = \Session::get('cart');
unset($cart[$product->slug]);
\Session::put('cart', $cart);
return redirect()->route('cart.show');
}
public function update(Product $product, $quantity)
{
if (\Session::has('sale')) {
$sale = Sale::find(\Session::get('sale')->id);
$sale->status = 0;
$sale->save();
\Session::forget('sale');
}
if ($quantity <= 0) {
return redirect()->back();
}
$cart = \Session::get('cart');
if (!isset($cart[$product->slug])) {
return redirect()->route('cart.show');
}
$cart[$product->slug]->quantity = $quantity;
\Session::put('cart', $cart);
if (!isset($cart[$product->slug])) {
return redirect()->route('cart.show');
}
public function trash()
{
if (\Session::has('sale')) {
$sale = Sale::find(\Session::get('sale')->id);
$sale->status = 0;
$sale->save();
}
unset($cart[$product->slug]);
\Session::put('cart', $cart);
return redirect()->route('cart.show');
}
\Session::forget('cart');
public function update(Product $product, $quantity)
{
if (\Session::has('sale')) {
$sale = Sale::find(\Session::get('sale')->id);
$sale->status = 0;
$sale->save();
\Session::forget('sale');
\Session::forget('client');
}
if ($quantity <= 0) {
return redirect()->back();
}
$cart = \Session::get('cart');
if (!isset($cart[$product->slug])) {
return redirect()->route('cart.show');
}
$cart[$product->slug]->quantity = $quantity;
\Session::put('cart', $cart);
return redirect()->route('cart.show');
}
public function shipping()
{
/*\Session::forget('client');
\Session::forget('cart');
\Session::forget('sale');*/
public function trash()
{
$client = new Client();
$addres = new Addres();
if (\Session::has('sale')) {
$sale = Sale::find(\Session::get('sale')->id);
$sale->status = 0;
$sale->save();
}
\Session::forget('cart');
\Session::forget('sale');
\Session::forget('client');
if(count(\Session::get('cart')) <= 0) {return redirect()->route('cart.show');}
return redirect()->route('cart.show');
}
public function shipping()
{
$client = new Client();
$addres = new Addres();
if(count(\Session::get('cart')) <= 0) {return redirect()->route('cart.show');}
if(\Session::has('client')) {
$client = \Session::get('client');
$addres = $client->shipping;
......@@ -144,15 +143,15 @@ class CartController extends Controller
$total = $this->total();
$shipping = Shipping::select(
\DB::raw("CONCAT(name,' $',cost) AS name"),'id')
->pluck('name', 'id');
->pluck('name', 'id');
return view('shop-public::cart.shipping')
->with('cart', $cart)
->with('total', $total)
->with('client', $client)
->with('addres', $addres)
->with('shipping', $shipping);
->with('cart', $cart)
->with('total', $total)
->with('client', $client)
->with('addres', $addres)
->with('shipping', $shipping);
}
public function storeClient(Request $request)
......@@ -168,7 +167,7 @@ class CartController extends Controller
$client = new Client();
$addres = new Addres();
}
}
/** Crea cliente ········· */
......@@ -181,14 +180,14 @@ class CartController extends Controller
if (!isset($addres->client_id)) {
$addres->client_id = $client->id;
}
$addres->save();
/** Guarda productos en tabla ······ */
$costoEnvio = $addres->shipping_price->cost;
if (!\Session::has('sale')) {
$sale = $client->sales()->save(new Sale(['status' => 1, 'total'=>($this->total() + $costoEnvio)]));
foreach ($cart as $product) {
......@@ -199,7 +198,7 @@ class CartController extends Controller
]);
}
} else {
$sale = Sale::find(\Session::get('sale')->id);
$sale->total = ($this->total() + $costoEnvio);
......@@ -226,13 +225,13 @@ class CartController extends Controller
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
return view('shop-public::cart.finish')
->with('sale', $sale)
->with('client', $client)
->with('items', $items)
->with('total', $this->total())
->with('addres', $addres);
->with('sale', $sale)
->with('client', $client)
->with('items', $items)
->with('total', $this->total())
->with('addres', $addres);
}
public function cancel()
......@@ -244,7 +243,7 @@ class CartController extends Controller
\Session::forget('sale');
return redirect()->route('cart.show');
}
public function payment(Request $request)
......@@ -303,8 +302,8 @@ class CartController extends Controller
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
return redirect()
->route('main.shop')
->with('payment_approved', 'payment_approved');
->route('main.shop')
->with('payment_approved', 'payment_approved');
} elseif ($payment['response']['status'] == 'in_process') {
......@@ -320,24 +319,24 @@ class CartController extends Controller
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
return redirect()
->route('main.shop')
->with('payment_pending', 'payment_pending');
->route('main.shop')
->with('payment_pending', 'payment_pending');
} else {
$status = 'Rechazado';
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
return redirect()
->back()
->with('payment_reject', 'payment_reject');
->back()
->with('payment_reject', 'payment_reject');
}
//dd($payment);
......@@ -373,9 +372,9 @@ class CartController extends Controller
$payment_data = array(
"transaction_amount" => $this->total() + $addres->shipping_price->cost,
"description" => $detail,
"payment_method_id" => $request->payment_id,
"payer" => array (
"email" => $client->email,
......@@ -401,11 +400,11 @@ class CartController extends Controller
return redirect()
->route('main.shop')
->with('url_ficha', $url_ficha);
->route('main.shop')
->with('url_ficha', $url_ficha);
}
......@@ -434,17 +433,17 @@ class CartController extends Controller
new OAuthTokenCredential(
env('CLIENT_ID_PAYPAL'),
env('SECRET_PAYPAL')
)
);
)
);
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => base_path().'/Paypal.log',
'log.LogLevel' => 'DEBUG',
'mode' => env('PAYPAL_MODE'),
)
);
array(
'log.LogEnabled' => true,
'log.FileName' => base_path().'/Paypal.log',
'log.LogLevel' => 'DEBUG',
'mode' => env('PAYPAL_MODE'),
)
);
$paymentId = $request->paymentId;
......@@ -457,7 +456,7 @@ class CartController extends Controller
$result = $payment->execute($execution, $apiContext);
if ($result->state == 'approved') {
$sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client;
$items = $sale->items;
......@@ -475,12 +474,12 @@ class CartController extends Controller
\Session::forget('sale');
return redirect()
->route('main.shop')
->with('payment_approved', 'payment_approved');
->route('main.shop')
->with('payment_approved', 'payment_approved');
} else {
return redirect()
->route('cart.finish')
->with('paypal_fail',$result->state);
->route('cart.finish')
->with('paypal_fail',$result->state);
}
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
......@@ -494,8 +493,8 @@ class CartController extends Controller
public function cancelPaypal()
{
return redirect()
->route('cart.finish')
->with('paypal_cancel', 'paypal_cancel');
->route('cart.finish')
->with('paypal_cancel', 'paypal_cancel');
}
public function paymentPaypal(Request $request)
......@@ -515,25 +514,25 @@ class CartController extends Controller
$addres = $client->shipping;
$detail = '';
$apiContext = new ApiContext(
new OAuthTokenCredential(
env('CLIENT_ID_PAYPAL'),
env('SECRET_PAYPAL')
)
);
)
);
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => base_path().'/Paypal.log',
'log.LogLevel' => 'DEBUG',
'mode' => env('PAYPAL_MODE'),
)
);
array(
'log.LogEnabled' => true,
'log.FileName' => base_path().'/Paypal.log',
'log.LogLevel' => 'DEBUG',
'mode' => env('PAYPAL_MODE'),
)
);
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
......@@ -542,26 +541,26 @@ class CartController extends Controller
foreach ($sale->items as $item) {
//$cost = $item->product->infoSale->sale_price * $item->quantity;
$item1 = new PaypalItem();
$item1->setName($item->product->name)
->setDescription($item->product->name)
->setCurrency('MXN')
->setQuantity($item->quantity)
->setPrice($item->product->infoSale->sale_price);
->setDescription($item->product->name)
->setCurrency('MXN')
->setQuantity($item->quantity)
->setPrice($item->product->infoSale->sale_price);
$items[]=$item1;
}
$item2 = new PaypalItem();
$item2->setName($addres->shipping_price->name)
->setDescription($addres->shipping_price->name)
->setCurrency('MXN')
->setQuantity(1)
->setPrice($addres->shipping_price->cost);
->setDescription($addres->shipping_price->name)
->setCurrency('MXN')
->setQuantity(1)
->setPrice($addres->shipping_price->cost);
array_push($items, $item2);
$itemList = new ItemList();
$itemList->setItems($items);
......@@ -569,44 +568,79 @@ class CartController extends Controller
$details = new Details();
$details->setSubtotal($this->total() + $addres->shipping_price->cost);
$amount = new \PayPal\Api\Amount();
$amount->setCurrency("MXN")
->setTotal($this->total() + $addres->shipping_price->cost)
->setDetails($details);
->setTotal($this->total() + $addres->shipping_price->cost)
->setDetails($details);
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Compra en Onestartup")
->setInvoiceNumber(uniqid());
->setItemList($itemList)
->setDescription("Compra en Onestartup")
->setInvoiceNumber(uniqid());
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl(route('cart.successPaypal'))
->setCancelUrl(route('cart.cancelPaypal'));
->setCancelUrl(route('cart.cancelPaypal'));
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try {
$payment->create($apiContext);
$sale->status = 3;
$sale->transaction_id = $payment->id;
$sale->save();
return redirect($payment->getApprovalLink());
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getData();
}
}
public function acordar(Request $request)
{
if (!\Session::has('client')) {
return redirect()->route('cart.shipping');
}
if (!\Session::has('sale')) {
return redirect()->route('cart.shipping');
}
$sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
$detail = '';
$sale->status = 3;
$sale->transaction_id = null;
$sale->payment_type = 'Acordar con vendedor';
$sale->save();
\Session::forget('client');
\Session::forget('cart');
\Session::forget('sale');
$user = \App\User::first();
$user->notify(new PaymentAcordarClient('Acordar con el vendedor', $client));
return redirect()
->route('main.shop')
->with('acordar', 'acordar');
}
}
<?php
namespace Onestartup\Shop\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Onestartup\Shop\Model\ClientShop as Client;
class PaymentAcordarClient extends Notification
{
use Queueable;
protected $tipo;
protected $client;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($tipo, Client $client)
{
$this->tipo = $tipo;
$this->client = $client;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->greeting('¡Hola!')
->subject('Orden: Acordar con el vendedor '.env('APP_NAME'))
//->replyTo($this->interested->email, $this->interested->name)
->line('Un cliente elijió la opcion de acordar con el vendedor')
->line('Datos del cliente:')
->line('Nombre: '.$this->client->name.' '.$this->client->lastname)
->line('Telefono: '.$this->client->phone)
->line('Correo: '.$this->client->email);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
......@@ -86,6 +86,7 @@ Route::group(['middleware' => ['web']], function(){
Route::post('cart/payment', 'Onestartup\Shop\Controller\CartController@payment')->name('cart.payment');
Route::post('cart/paymentCash', 'Onestartup\Shop\Controller\CartController@paymentCash')->name('cart.paymentCash');
Route::post('cart/acordar', 'Onestartup\Shop\Controller\CartController@acordar')->name('cart.acordar');
Route::get('cart/update/{product_slug}/{quantity}', 'Onestartup\Shop\Controller\CartController@update')
->where('quantity', '[0-9]+')
......
......@@ -67,6 +67,10 @@ setlocale(LC_MONETARY, 'en_US');
@include('shop-public::forms.form-paypal')
<br>
<br>
@include('shop-public::forms.form-acordar')
<br>
</section>
......
<form action="{{route('cart.acordar')}}" method="POST">
{{ csrf_field() }}
<button type="submit">
Acordar con el vendedor: {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
</button>
</form>
\ No newline at end of file
......@@ -64,6 +64,12 @@ $util = new Onestartup\Shop\Libs\Util();
</script>
@endif
@if(Session::has('acordar'))
<script type="text/javascript">
swal("Compra registrada", "Gracias! En breve nos comunicaremos contigo para cerrar la venta", "success")
</script>
@endif
@if(Session::has('url_ficha'))
<script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment