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
cd9c580b
Commit
cd9c580b
authored
May 23, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finaliza transaccion paypal
parent
c9d38589
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
16 deletions
+65
-16
CartController.php
src/controllers/CartController.php
+57
-16
layout.blade.php
src/views/public/layout.blade.php
+8
-0
No files found.
src/controllers/CartController.php
View file @
cd9c580b
...
@@ -25,6 +25,7 @@ use PayPal\Api\Amount;
...
@@ -25,6 +25,7 @@ use PayPal\Api\Amount;
use
PayPal\Api\Transaction
;
use
PayPal\Api\Transaction
;
use
PayPal\Api\RedirectUrls
;
use
PayPal\Api\RedirectUrls
;
use
PayPal\Api\Payment
;
use
PayPal\Api\Payment
;
use
PayPal\Api\PaymentExecution
;
use
PayPal\Exception\PayPalConnectionException
;
use
PayPal\Exception\PayPalConnectionException
;
use
PayPal\Api\Item
as
PaypalItem
;
use
PayPal\Api\Item
as
PaypalItem
;
use
PayPal\Api\ItemList
;
use
PayPal\Api\ItemList
;
...
@@ -403,9 +404,10 @@ class CartController extends Controller
...
@@ -403,9 +404,10 @@ class CartController extends Controller
return
$total
;
return
$total
;
}
}
public
function
successPaypal
()
public
function
successPaypal
(
Request
$request
)
{
{
if
(
!
\Session
::
has
(
'client'
))
{
if
(
!
\Session
::
has
(
'client'
))
{
return
redirect
()
->
route
(
'cart.shipping'
);
return
redirect
()
->
route
(
'cart.shipping'
);
}
}
...
@@ -413,24 +415,63 @@ class CartController extends Controller
...
@@ -413,24 +415,63 @@ class CartController extends Controller
return
redirect
()
->
route
(
'cart.shipping'
);
return
redirect
()
->
route
(
'cart.shipping'
);
}
}
$sale
=
Sale
::
find
(
\Session
::
get
(
'sale'
)
->
id
);
$apiContext
=
new
ApiContext
(
$client
=
$sale
->
client
;
new
OAuthTokenCredential
(
$items
=
$sale
->
items
;
env
(
'CLIENT_ID_PAYPAL'
),
$addres
=
$client
->
shipping
;
env
(
'SECRET_PAYPAL'
)
)
);
$sale
->
status
=
2
;
$apiContext
->
setConfig
(
$sale
->
save
();
array
(
'log.LogEnabled'
=>
true
,
'log.FileName'
=>
base_path
()
.
'/Paypal.log'
,
'log.LogLevel'
=>
'DEBUG'
,
'mode'
=>
env
(
'PAYPAL_MODE'
),
)
);
$user
=
\App\User
::
first
();
$user
->
notify
(
new
PaymentClientCard
(
$client
,
'Paypal'
,
'Pagado'
));
\Session
::
forget
(
'client'
);
$paymentId
=
$request
->
paymentId
;
\Session
::
forget
(
'cart'
);
$payment
=
Payment
::
get
(
$paymentId
,
$apiContext
);
\Session
::
forget
(
'sale'
);
$execution
=
new
PaymentExecution
();
$execution
->
setPayerId
(
$request
->
PayerID
);
try
{
$result
=
$payment
->
execute
(
$execution
,
$apiContext
);
if
(
$result
->
state
==
'approved'
)
{
$sale
=
Sale
::
find
(
\Session
::
get
(
'sale'
)
->
id
);
$client
=
$sale
->
client
;
$items
=
$sale
->
items
;
$addres
=
$client
->
shipping
;
$sale
->
status
=
2
;
$sale
->
save
();
$user
=
\App\User
::
first
();
$user
->
notify
(
new
PaymentClientCard
(
$client
,
'Paypal'
,
'Pagado'
));
\Session
::
forget
(
'client'
);
\Session
::
forget
(
'cart'
);
\Session
::
forget
(
'sale'
);
return
redirect
()
->
route
(
'main.shop'
)
->
with
(
'payment_approved'
,
'payment_approved'
);
}
else
{
return
redirect
()
->
route
(
'cart.finish'
)
->
with
(
'paypal_fail'
,
$result
->
state
);
}
}
catch
(
\PayPal\Exception\PayPalConnectionException
$ex
)
{
return
$ex
->
getData
();
}
return
redirect
()
->
route
(
'main.shop'
)
->
with
(
'payment_approved'
,
'payment_approved'
);
}
}
...
...
src/views/public/layout.blade.php
View file @
cd9c580b
...
@@ -41,6 +41,14 @@
...
@@ -41,6 +41,14 @@
</script>
</script>
@endif
@endif
@if(Session::has('paypal_fail'))
<script
type=
"text/javascript"
>
swal
(
"Pago rechazado"
,
"Tuvimos problemas para procesar tu pago, verifica tus datos : {{Session::get('paypal_fail')}}"
,
"error"
)
</script>
@endif
@if(Session::has('payment_pending'))
@if(Session::has('payment_pending'))
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
swal
(
"Pago pendiente"
,
"Estamos procesando tu pago, te notificaremos por correo el estatus"
,
"warning"
)
swal
(
"Pago pendiente"
,
"Estamos procesando tu pago, te notificaremos por correo el estatus"
,
"warning"
)
...
...
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