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
d3a2de64
Commit
d3a2de64
authored
Jan 18, 2019
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
open pay integration
parent
535db319
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
220 additions
and
0 deletions
+220
-0
CartController.php
src/controllers/CartController.php
+94
-0
PaymentOpenPay.php
src/lib/PaymentOpenPay.php
+79
-0
2019_01_17_220117_add_interesteds_to_sale_table.php
...tions/2019_01_17_220117_add_interesteds_to_sale_table.php
+34
-0
routes.php
src/routes.php
+1
-0
orden.blade.php
src/views/clients/orden.blade.php
+9
-0
order.blade.php
src/views/mail/resumen/order.blade.php
+3
-0
form-openpay.blade.php
src/views/public/forms/form-openpay.blade.php
+0
-0
No files found.
src/controllers/CartController.php
View file @
d3a2de64
...
...
@@ -37,6 +37,7 @@ use PayPal\Api\ItemList;
use
PayPal\Api\Details
;
use
Onestartup\Shop\Libs\Util
;
use
Onestartup\Shop\Libs\PaymentOpenPay
;
use
Onestartup\Shop\Model\VariableExtra
as
Variable
;
use
Onestartup\Shop\Model\ExtraSaleInfo
;
...
...
@@ -833,6 +834,99 @@ public function shipping()
->
with
(
'acordar'
,
'acordar'
);
}
public
function
openpay
()
{
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
;
$products
=
$sale
->
products
;
$items
=
$sale
->
items
;
$addres
=
$client
->
shipping
!=
null
?
$client
->
shipping
:
null
;
$total
=
$sale
->
total
;
if
(
request
()
->
coupon
!=
null
)
{
$data
=
$this
->
getDiscount
(
$sale
,
request
()
->
coupon
);
if
(
$data
[
'valid'
])
{
$total
=
$data
[
'total_unformated'
];
$sale
->
coupon
=
request
()
->
coupon
;
}
}
$openpay
=
new
PaymentOpenPay
();
$customer
=
[
'name'
=>
$client
->
name
,
'phone_number'
=>
$client
->
phone
,
'email'
=>
$client
->
email
];
$total_with_interesteds
=
$openpay
->
totalWithPorcent
(
$total
,
request
()
->
months
);
$total_interesteds
=
$total_with_interesteds
-
$total
;
$payment_detail
=
[
'method'
=>
'card'
,
'source_id'
=>
request
()
->
token_id
,
'amount'
=>
$total_with_interesteds
,
'description'
=>
'Pago orden #'
.
$sale
->
id
.
', Meses '
.
request
()
->
months
,
'device_session_id'
=>
request
()
->
deviceIdHiddenFieldName
,
'customer'
=>
$customer
,
];
$response
=
$openpay
->
sendPayment
(
$payment_detail
,
request
()
->
months
);
if
(
$response
[
'status'
]
===
'ok'
)
{
$sale
->
status
=
3
;
$status
=
'process'
;
if
(
$response
[
'status_payment'
]
===
'completed'
)
{
$sale
->
status
=
2
;
$status
=
'approved'
;
}
if
(
request
()
->
months
>
1
)
{
$sale
->
months
=
request
()
->
months
;
$sale
->
interests
=
$total_interesteds
;
}
$sale
->
total
=
$total_with_interesteds
;
$sale
->
transaction_id
=
null
;
$sale
->
payment_type
=
'Open Pay'
;
$sale
->
save
();
\Session
::
forget
(
'client'
);
\Session
::
forget
(
'cart'
);
\Session
::
forget
(
'sale'
);
$user
=
\App\User
::
first
();
//$user->notify(new PaymentAcordarClient('Acordar con el vendedor', $client));
$user
->
notify
(
new
ResumenOrder
(
$sale
,
$products
,
$client
,
$addres
));
$client
->
notify
(
new
ResumenOrder
(
$sale
,
$products
,
$client
,
$addres
));
return
redirect
()
->
route
(
'main.shop'
)
->
with
(
'payment_approved'
,
'payment_approved'
);
}
else
{
return
redirect
()
->
route
(
'cart.finish'
)
->
with
(
'paypal_fail'
,
$response
[
'message'
]);
}
}
public
function
testmail
()
{
/*$sale = Sale::find(10);
...
...
src/lib/PaymentOpenPay.php
0 → 100644
View file @
d3a2de64
<?php
namespace
Onestartup\Shop\Libs
;
use
Openpay
;
class
PaymentOpenPay
{
public
function
sendPayment
(
$payment_data
,
$months
=
1
)
{
try
{
$openpay
=
Openpay
::
getInstance
(
env
(
'OPENPAY_ID'
),
env
(
'OPENPAY_SK'
));
$charge
=
array
();
$plan
=
array
(
'payments'
=>
$months
);
if
(
$months
>=
3
)
{
$payment_data
[
'payment_plan'
]
=
$plan
;
}
if
(
$charge
=
$openpay
->
charges
->
create
(
$payment_data
)){
return
[
'status'
=>
'ok'
,
'status_payment'
=>
$charge
->
status
,
'message'
=>
'Pago completado'
];
}
else
{
return
[
'status'
=>
'error'
,
'status_payment'
=>
'fail'
,
'message'
=>
'No se realizo el cargo'
];
}
}
catch
(
\OpenpayApiTransactionError
$e
)
{
return
[
'status'
=>
'error'
,
'status_payment'
=>
'fail_transaction'
,
'message'
=>
$e
->
getMessage
()];
}
catch
(
\OpenpayApiRequestError
$e
)
{
return
[
'status'
=>
'error'
,
'status_payment'
=>
'fail_request'
,
'message'
=>
$e
->
getMessage
()];
}
catch
(
\OpenpayApiConnectionError
$e
)
{
return
[
'status'
=>
'error'
,
'status_payment'
=>
'fail_connection'
,
'message'
=>
$e
->
getMessage
()];
}
catch
(
\OpenpayApiAuthError
$e
)
{
return
response
()
->
json
([
'status'
=>
'error'
,
'status_payment'
=>
'fail_auth'
,
'message'
=>
$e
->
getMessage
()]);
}
catch
(
\OpenpayApiError
$e
)
{
return
[
'status'
=>
'error'
,
'status_payment'
=>
'fail_api'
,
'message'
=>
$e
->
getMessage
()];
}
catch
(
Exception
$e
)
{
return
[
'status'
=>
'error'
,
'status_payment'
=>
'fail_script'
,
'message'
=>
$e
->
getMessage
()];
}
}
public
function
totalWithPorcent
(
$total
,
$months
)
{
$total_with_porcents
=
$total
;
switch
(
$months
)
{
case
1
:
$total_with_porcents
=
$total
;
break
;
case
3
:
$total_with_porcents
=
(
env
(
'TASA_3'
)
/
100
)
*
$total
+
$total
;
break
;
case
6
:
$total_with_porcents
=
(
env
(
'TASA_6'
)
/
100
)
*
$total
+
$total
;
break
;
case
9
:
$total_with_porcents
=
(
env
(
'TASA_9'
)
/
100
)
*
$total
+
$total
;
break
;
case
12
:
$total_with_porcents
=
(
env
(
'TASA_12'
)
/
100
)
*
$total
+
$total
;
break
;
default
:
$total_with_porcents
=
$total
;
}
return
$total_with_porcents
;
}
}
\ No newline at end of file
src/migrations/2019_01_17_220117_add_interesteds_to_sale_table.php
0 → 100644
View file @
d3a2de64
<?php
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
AddInterestedsToSaleTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'sale_shops'
,
function
(
Blueprint
$table
)
{
$table
->
integer
(
'months'
)
->
nullable
();
$table
->
float
(
'interests'
)
->
nullable
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
table
(
'sale_shops'
,
function
(
Blueprint
$table
)
{
$table
->
dropColumn
(
'months'
);
$table
->
dropColumn
(
'interests'
);
});
}
}
src/routes.php
View file @
d3a2de64
...
...
@@ -141,6 +141,7 @@ Route::group(['middleware' => ['web']], function(){
Route
::
post
(
'cart/payment/installments'
,
'Onestartup\Shop\Controller\CartController@paymentInstallments'
)
->
name
(
'cart.payment-installments'
);
Route
::
post
(
'cart/paymentCash'
,
'Onestartup\Shop\Controller\CartController@paymentCash'
)
->
name
(
'cart.paymentCash'
);
Route
::
post
(
'cart/acordar'
,
'Onestartup\Shop\Controller\CartController@acordar'
)
->
name
(
'cart.acordar'
);
Route
::
post
(
'cart/openpay'
,
'Onestartup\Shop\Controller\CartController@openpay'
)
->
name
(
'cart.openpay'
);
Route
::
get
(
'cart/update/{product_slug}/{quantity}'
,
'Onestartup\Shop\Controller\CartController@update'
)
->
where
(
'quantity'
,
'[0-9]+'
)
...
...
src/views/clients/orden.blade.php
View file @
d3a2de64
...
...
@@ -188,6 +188,15 @@ setlocale(LC_MONETARY, 'en_US');
</tr>
@endif
<tfoot>
@if(
$sale->months
!= null)
<tr>
<td colspan="
3
" align="
right
">Meses sin intereses:</td>
<td align="
right
">
{{money_format('%(#10n',
$sale->interests
)}}
</td>
</tr>
@endif
<tr>
<td></td>
<td></td>
...
...
src/views/mail/resumen/order.blade.php
View file @
d3a2de64
...
...
@@ -27,6 +27,9 @@ setlocale(LC_MONETARY, 'en_US');
@
if
(
$promo
!=
null
)
|
-
|
1
|
Descuento
***
{{
$order
->
coupon
}}
***
|
{{
" - "
.
$promo
[
'amount'
]}}
|
{{
" - "
.
$promo
[
'amount'
]}}
|
@
endif
@
if
(
$sale
->
months
!=
null
)
|
-
|
-
|
-
|
Meses
sin
intereses
:
|
{{
money_format
(
'%(#10n'
,
$sale
->
interests
)}}
|
@
endif
|
-
|
-
|
-
|
Total
:
|
{{
money_format
(
'%(#10n'
,
$order
->
total
)}}
|
@
endcomponent
...
...
src/views/public/forms/form-openpay.blade.php
0 → 100644
View file @
d3a2de64
This diff is collapsed.
Click to expand it.
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