Commit 01858f47 by Angel MAS

reembolso paypal y pago con tarjeta

parent 98b5f493
......@@ -20,6 +20,16 @@ use Onestartup\Shop\Model\SaleShop as Sale;
use Onestartup\Shop\Model\OrderTracking as Tracking;
use Onestartup\Shop\Libs\Util;
use Onestartup\Shop\Payment\MP;
use PayPal\Api\Amount;
use PayPal\Api\Refund;
use PayPal\Api\Sale as SalePaypal;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
class AdminProductController extends Controller
{
protected $util;
......@@ -311,6 +321,10 @@ class AdminProductController extends Controller
$estado = "En proceso";
}
if ($sale->status == 4) {
$estado = "Cancelado/Reembolsado";
}
return view('shop::clients.orden')
->with('sale', $sale)
->with('client', $client)
......@@ -355,4 +369,86 @@ class AdminProductController extends Controller
->with('message_success', 'Información agregada correctamente');
}
/**
* Reembolsa pagos hechos con tarjeta
* @param [type] $sale_id [description]
* @return [type] [description]
*/
public function refund($sale_id)
{
//$paymentInfo = $mp->get_payment ("3799582572");
//$result = $mp->refund_payment("3799582572");
//$paymentInfo = $mp->get_payment ($sale->transaction_id);
$sale = Sale::find($sale_id);
$mp = new MP(env('AC_MERCADO_PAGO'));
$result = $mp->refund_payment($sale->transaction_id);
$old = $sale->status;
$sale->status = 4;
$sale->save();
$this->util->stock_change($sale, $old);
dd($result);
return redirect()->back()->with('message_success', 'Se realizo el reembolso correctamente');
}
public function refundPaypal($sale_id)
{
$saleLocal = Sale::find($sale_id);
$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'),
)
);
$payment = Payment::get($saleLocal->transaction_id, $apiContext);
//dd($payment->transactions[0]->related_resources[0]->sale->id);
$amt = new Amount();
$amt->setTotal($saleLocal->total)
->setCurrency('MXN');
$refund = new Refund();
$refund->setAmount($amt);
$sale = new SalePaypal();
$sale->setId($payment->transactions[0]->related_resources[0]->sale->id);
try {
$refundedSale = $sale->refund($refund, $apiContext);
$old = $saleLocal->status;
$saleLocal->status = 4;
$saleLocal->save();
$this->util->stock_change($saleLocal, $old);
return redirect()->back()->with('message_success', 'Se realizo el reembolso correctamente');
//dd($refundedSale);
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}
}
}
......@@ -39,6 +39,9 @@ class OrderDataTable extends DataTable
if ($sale->status == 3) {
$estado = "<span class='label primary'>En proceso</span>";
}
if ($sale->status == 4) {
$estado = "<span class='label danger'>Reembolsado</span>";
}
if ($sale->client->shipping != null) {
$html = "Estado: <b>$estado</b><br>Tipo: <b>$sale->payment_type</b> <br>Transaccion:<br><b>$sale->transaction_id</b><br>Envio: <b>".$sale->client->shipping->shipping_price->name."</b>";
} else {
......
......@@ -70,6 +70,14 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
'Onestartup\Shop\Controller\AdminProductController@stock')
->name('admin-shop-client.stock');
Route::put('admin/shop/refund/{sale_id}',
'Onestartup\Shop\Controller\AdminProductController@refund')
->name('admin-shop-client.refund');
Route::put('admin/shop/refundPaypal/{sale_id}',
'Onestartup\Shop\Controller\AdminProductController@refundPaypal')
->name('admin-shop-client.refundPaypal');
});
......
......@@ -182,6 +182,23 @@ setlocale(LC_MONETARY, 'en_US');
</tfoot>
</tbody>
</table>
@if($sale->status == 2)
@if($sale->payment_type == 'Tarjeta')
{!! Form::model($sale,['route'=> ['admin-shop-client.refund', $sale->id],"method"=>"PUT", "onsubmit"=>"if(!confirm('¿Estas seguro de devolver el dinero?')){return false;}"]) !!}
{!! Form::submit('Reembolsar efectivo a tarjeta', ['class'=>'btn btn-warning']) !!}
{!! Form::close() !!}
@endif
@if($sale->payment_type == 'Pay Pal')
{!! Form::model($sale,['route'=> ['admin-shop-client.refundPaypal', $sale->id],"method"=>"PUT", "onsubmit"=>"if(!confirm('¿Estas seguro de devolver el dinero?')){return false;}"]) !!}
{!! Form::submit('Reembolsar efectivo a cuenta de paypal', ['class'=>'btn btn-warning']) !!}
{!! Form::close() !!}
@endif
@endif
</div>
</div>
</div>
......@@ -289,7 +306,7 @@ setlocale(LC_MONETARY, 'en_US');
<div class="form-group">
{!! Form::label('status', 'Estatus del envio', ['class'=>'form-control-label']) !!}
{!! Form::select('status', [0=>'Cancelado',1=>'Pendiente',2=>'Pagado',3=>'En proceso'], null, ['class' => 'form-control select2', 'required'=>'required']) !!}
{!! Form::select('status', [0=>'Cancelado',1=>'Pendiente',2=>'Pagado',3=>'En proceso',4=>'Cancelado/Reembolsado'], null, ['class' => 'form-control select2', 'required'=>'required']) !!}
</div>
<br>
{!! Form::submit('Actualizar', ['class'=>'btn btn-danger btn-block']) !!}
......
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