Commit 01de6697 by Angel MAS

Notificaciones de pagos

parent a0774dcc
...@@ -15,6 +15,9 @@ use Onestartup\Shop\Model\SaleShop as Sale; ...@@ -15,6 +15,9 @@ use Onestartup\Shop\Model\SaleShop as Sale;
use Onestartup\Shop\Model\DetailShop as Item; use Onestartup\Shop\Model\DetailShop as Item;
use Onestartup\Shop\Payment\MP; use Onestartup\Shop\Payment\MP;
use Onestartup\Shop\Notifications\PaymentClient;
use Onestartup\Shop\Notifications\PaymentClientCard;
class CartController extends Controller class CartController extends Controller
{ {
public function __construct() public function __construct()
...@@ -234,6 +237,8 @@ class CartController extends Controller ...@@ -234,6 +237,8 @@ class CartController extends Controller
$items = $sale->items; $items = $sale->items;
$addres = $client->shipping; $addres = $client->shipping;
$detail = ''; $detail = '';
$status = '';
$user = \App\User::first();
foreach ($sale->items as $item) { foreach ($sale->items as $item) {
...@@ -262,11 +267,14 @@ class CartController extends Controller ...@@ -262,11 +267,14 @@ class CartController extends Controller
$sale->status = 2; $sale->status = 2;
$sale->transaction_id = $payment['response']['id']; $sale->transaction_id = $payment['response']['id'];
$sale->save(); $sale->save();
$status = 'Aprobado';
\Session::forget('client'); \Session::forget('client');
\Session::forget('cart'); \Session::forget('cart');
\Session::forget('sale'); \Session::forget('sale');
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
return redirect() return redirect()
->route('main.shop') ->route('main.shop')
->with('payment_approved', 'payment_approved'); ->with('payment_approved', 'payment_approved');
...@@ -276,17 +284,23 @@ class CartController extends Controller ...@@ -276,17 +284,23 @@ class CartController extends Controller
$sale->status = 3; $sale->status = 3;
$sale->transaction_id = $payment['response']['id']; $sale->transaction_id = $payment['response']['id'];
$sale->save(); $sale->save();
$status = 'En proceso';
\Session::forget('client'); \Session::forget('client');
\Session::forget('cart'); \Session::forget('cart');
\Session::forget('sale'); \Session::forget('sale');
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
return redirect() return redirect()
->route('main.shop') ->route('main.shop')
->with('payment_pending', 'payment_pending'); ->with('payment_pending', 'payment_pending');
} else { } else {
$status = 'Rechazado';
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
return redirect() return redirect()
->back() ->back()
->with('payment_reject', 'payment_reject'); ->with('payment_reject', 'payment_reject');
...@@ -294,6 +308,9 @@ class CartController extends Controller ...@@ -294,6 +308,9 @@ class CartController extends Controller
} }
//dd($payment); //dd($payment);
...@@ -351,6 +368,9 @@ class CartController extends Controller ...@@ -351,6 +368,9 @@ class CartController extends Controller
\Session::forget('cart'); \Session::forget('cart');
\Session::forget('sale'); \Session::forget('sale');
$user = \App\User::first();
$user->notify(new PaymentClient($request->payment_id, $client));
return redirect() return redirect()
->route('main.shop') ->route('main.shop')
......
<?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 PaymentClient 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('Ficha pago en efectivo en '.env('APP_NAME'))
//->replyTo($this->interested->email, $this->interested->name)
->line('Se ha generado una ficha de deposito en efectivo')
->line('Tipo de ficha: '.$this->tipo )
->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 [
//
];
}
}
<?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 PaymentClientCard extends Notification
{
use Queueable;
protected $tipo;
protected $client;
protected $status;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Client $client, $tipo, $status)
{
$this->tipo = $tipo;
$this->client = $client;
$this->status = $status;
}
/**
* 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('Pago con tarjeta en '.env('APP_NAME'))
//->replyTo($this->interested->email, $this->interested->name)
->line('Se ha generado un pago con tarjeta')
->line('Tipo de tarjeta: '.$this->tipo )
->line('Estatus de la transacción: '.$this->status )
->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 [
//
];
}
}
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