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
d86936e5
Commit
d86936e5
authored
May 21, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
paypal payment
parent
01de6697
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
184 additions
and
8 deletions
+184
-8
composer.json
composer.json
+3
-1
CartController.php
src/controllers/CartController.php
+157
-0
routes.php
src/routes.php
+3
-7
finish.blade.php
src/views/public/cart/finish.blade.php
+4
-0
form-paypal.blade.php
src/views/public/forms/form-paypal.blade.php
+9
-0
layout.blade.php
src/views/public/layout.blade.php
+8
-0
No files found.
composer.json
View file @
d86936e5
...
...
@@ -12,6 +12,8 @@
"minimum-stability"
:
"dev"
,
"require"
:
{},
"autoload"
:
{
"psr-4"
:
{
"Onestartup
\\
Shop
\\
"
:
"src"
}
"psr-4"
:
{
"Onestartup
\\
Shop
\\
"
:
"src"
}
}
}
src/controllers/CartController.php
View file @
d86936e5
...
...
@@ -18,6 +18,18 @@ use Onestartup\Shop\Payment\MP;
use
Onestartup\Shop\Notifications\PaymentClient
;
use
Onestartup\Shop\Notifications\PaymentClientCard
;
use
PayPal\Rest\ApiContext
;
use
PayPal\Auth\OAuthTokenCredential
;
use
PayPal\Api\Payer
;
use
PayPal\Api\Amount
;
use
PayPal\Api\Transaction
;
use
PayPal\Api\RedirectUrls
;
use
PayPal\Api\Payment
;
use
PayPal\Exception\PayPalConnectionException
;
use
PayPal\Api\Item
as
PaypalItem
;
use
PayPal\Api\ItemList
;
use
PayPal\Api\Details
;
class
CartController
extends
Controller
{
public
function
__construct
()
...
...
@@ -391,5 +403,150 @@ class CartController extends Controller
return
$total
;
}
public
function
successPaypal
()
{
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
;
$sale
->
status
=
2
;
$sale
->
save
();
\Session
::
forget
(
'client'
);
\Session
::
forget
(
'cart'
);
\Session
::
forget
(
'sale'
);
return
redirect
()
->
route
(
'main.shop'
)
->
with
(
'payment_approved'
,
'payment_approved'
);
}
public
function
cancelPaypal
()
{
return
redirect
()
->
route
(
'cart.show'
)
->
with
(
'paypal_cancel'
,
'paypal_cancel'
);
}
public
function
paymentPaypal
(
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
=
''
;
$apiContext
=
new
ApiContext
(
new
OAuthTokenCredential
(
'AaeMLQGFFuvYBfOT1bWcLUo0-r_V81AqRXi6pJ2j_FNtsqdO0qeoj6CHed8Gzdhzr5wiKUvFF0gYfTf3'
,
'EOCbTEZffxOx3GXG3j0eAJSpeWlPLAhiY34uqWE71ljERbakYkjwqGTYkHp1qdms6O_FxXtdL5jwbfIA'
)
);
$apiContext
->
setConfig
(
array
(
'log.LogEnabled'
=>
true
,
'log.FileName'
=>
base_path
()
.
'/Paypal.log'
,
'log.LogLevel'
=>
'DEBUG'
,
'mode'
=>
'sandbox'
,
)
);
$payer
=
new
\PayPal\Api\Payer
();
$payer
->
setPaymentMethod
(
'paypal'
);
$items
=
array
();
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
);
$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
);
array_push
(
$items
,
$item2
);
$itemList
=
new
ItemList
();
$itemList
->
setItems
(
$items
);
$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
);
$transaction
=
new
\PayPal\Api\Transaction
();
$transaction
->
setAmount
(
$amount
)
->
setItemList
(
$itemList
)
->
setDescription
(
"Compra en Onestartup"
)
->
setInvoiceNumber
(
uniqid
());
$redirectUrls
=
new
\PayPal\Api\RedirectUrls
();
$redirectUrls
->
setReturnUrl
(
route
(
'cart.successPaypal'
))
->
setCancelUrl
(
route
(
'cart.cancelPaypal'
));
$payment
=
new
\PayPal\Api\Payment
();
$payment
->
setIntent
(
'sale'
)
->
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
();
}
}
}
src/routes.php
View file @
d86936e5
...
...
@@ -71,11 +71,7 @@ Route::group(['middleware' => ['web']], function(){
Route
::
get
(
'shop'
,
'Onestartup\Shop\Controller\ProductController@index'
)
->
name
(
'main.shop'
);
//Route::get('cart/{product_id}')
Route
::
get
(
'test/payments'
,
function
()
{
$mp
=
new
Onestartup\Shop\Payment\MP
(
"TEST-7957752184054483-101318-9bbc7ef53f975318d2521f05257cb66a__LB_LC__-60150825"
);
$payment_methods
=
$mp
->
get
(
"/v1/payment_methods"
);
dd
(
$payment_methods
);
});
Route
::
post
(
'cart/paymentPaypal'
,
'Onestartup\Shop\Controller\CartController@paymentPaypal'
)
->
name
(
'cart.paymentPaypal'
);
Route
::
get
(
'cart/successPaypal'
,
'Onestartup\Shop\Controller\CartController@successPaypal'
)
->
name
(
'cart.successPaypal'
);
Route
::
get
(
'cart/cancelPaypal'
,
'Onestartup\Shop\Controller\CartController@cancelPaypal'
)
->
name
(
'cart.cancelPaypal'
);
});
src/views/public/cart/finish.blade.php
View file @
d86936e5
...
...
@@ -63,6 +63,10 @@ setlocale(LC_MONETARY, 'en_US');
@include('shop-public::forms.fields-payment-cash')
<br>
@include('shop-public::forms.form-paypal')
<br>
</section>
...
...
src/views/public/forms/form-paypal.blade.php
0 → 100644
View file @
d86936e5
<form
action=
"{{route('cart.paymentPaypal')}}"
method=
"POST"
>
{{ csrf_field() }}
<button>
Pagar con paypal {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
</button>
</form>
\ No newline at end of file
src/views/public/layout.blade.php
View file @
d86936e5
...
...
@@ -46,6 +46,14 @@
swal
(
"Pago pendiente"
,
"Estamos procesando tu pago, te notificaremos por correo el estatus"
,
"warning"
)
</script>
@endif
@if(Session::has('paypal_cancel'))
<script
type=
"text/javascript"
>
swal
(
"Operación cancelada"
,
"Se cancelo el proceso de pago"
,
"warning"
)
</script>
@endif
@if(Session::has('url_ficha'))
<script>
...
...
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