Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
onestartup-shop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Angel Martin
onestartup-shop
Commits
01858f47
Commit
01858f47
authored
Jun 19, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reembolso paypal y pago con tarjeta
parent
98b5f493
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
1 deletions
+125
-1
AdminProductController.php
src/controllers/AdminProductController.php
+96
-0
OrderDataTable.php
src/lib/OrderDataTable.php
+3
-0
routes.php
src/routes.php
+8
-0
orden.blade.php
src/views/clients/orden.blade.php
+18
-1
No files found.
src/controllers/AdminProductController.php
View file @
01858f47
...
...
@@ -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
);
}
}
}
src/lib/OrderDataTable.php
View file @
01858f47
...
...
@@ -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
{
...
...
src/routes.php
View file @
01858f47
...
...
@@ -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'
);
});
...
...
src/views/clients/orden.blade.php
View file @
01858f47
...
...
@@ -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']) !!}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment