Skip to content

Commit b65acc8

Browse files
Merge pull request #5 from epayco/release/v2.7.0
Release/v2.7.0
2 parents 805ea36 + 6430d96 commit b65acc8

File tree

8 files changed

+161
-47
lines changed

8 files changed

+161
-47
lines changed

Pago/Paycoagregador/Controller/PaymentController.php

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ public function confirmAction()
126126

127127
}
128128

129-
public function getQuoteIncrementId(){
130-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
131-
$last_order_increment_id = $objectManager->create('\Magento\Sales\Model\Order')->getCollection()->getLastItem()->getIncrementId();
132-
return $last_order_increment_id+1;
133-
}
129+
public function getQuoteIncrementId(){
130+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
131+
$last_order_increment_id = $objectManager->create('\Magento\Sales\Model\Order')->getCollection()->getLastItem()->getIncrementId();
132+
return $last_order_increment_id+1;
133+
}
134134

135135
public function getOrderIncrementId(){
136136
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
@@ -157,19 +157,40 @@ public function getQuoteData(){
157157
return $orderId;
158158
}
159159

160-
public function getStoreData(){
161-
$orderId=$this->checkoutSession->getQuote()->getStoredData();
162-
return $orderId;
163-
}
160+
public function getStoreData(){
161+
$orderId=$this->checkoutSession->getQuote()->getStoredData();
162+
return $orderId;
163+
}
164164

165165
public function getOrderId(){
166166
$carrito = $this->checkoutSession->getQuote()->getId();
167167
return $carrito;
168168
}
169169

170-
public function getQuoteIdData(){
171-
$order = $this->checkoutSession->getQuoteId();
172-
return $order;
173-
}
170+
public function getQuoteIdData(){
171+
$order = $this->checkoutSession->getQuoteId();
172+
return $order;
173+
}
174+
175+
public function getCustomerIp(){
176+
$ipaddress = '';
177+
if (isset($_SERVER['HTTP_CLIENT_IP']))
178+
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
179+
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
180+
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
181+
else if(isset($_SERVER['HTTP_X_FORWARDED']))
182+
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
183+
else if(isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
184+
$ipaddress = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
185+
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
186+
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
187+
else if(isset($_SERVER['HTTP_FORWARDED']))
188+
$ipaddress = $_SERVER['HTTP_FORWARDED'];
189+
else if(isset($_SERVER['REMOTE_ADDR']))
190+
$ipaddress = $_SERVER['REMOTE_ADDR'];
191+
else
192+
$ipaddress = 'UNKNOWN';
193+
return $ipaddress;
194+
}
174195

175196
}

Pago/Paycoagregador/Model/CustomConfigProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function getConfig() {
4545
'payco_merchant'=> $this->_scopeConfig->getValue('payment/epaycoagregador/payco_merchant',$storeScope),
4646
'payco_key'=> $this->_scopeConfig->getValue('payment/epayco/epaycoagregador',$storeScope),
4747
'payco_public_key'=> $this->_scopeConfig->getValue('payment/epaycoagregador/payco_public_key',$storeScope),
48+
'payco_private_key'=> $this->_scopeConfig->getValue('payment/epaycoagregador/payco_private_key',$storeScope),
4849
'payco_callback'=> $this->_scopeConfig->getValue('payment/epaycoagregador/payco_callback',$storeScope),
4950

5051
'payco_test'=> $this->_scopeConfig->getValue('payment/epaycoagregador/payco_test',$storeScope),
@@ -56,6 +57,7 @@ public function getConfig() {
5657
'getOrderIncrementId'=>$this->epayco->getOrderIncrementId(),
5758
'getQuoteIncrementId'=>$this->epayco->getQuoteIncrementId(),
5859
'getQuoteIdData'=>$this->epayco->getQuoteIdData(),
60+
'getCustomerIp'=>$this->epayco->getCustomerIp(),
5961
'language'=>$this->getLanguage()
6062
]
6163
]

Pago/Paycoagregador/etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<label>Public_KEY</label>
3232
<comment>LLave para autenticar y consumir los servicios de ePayco, Proporcionado en su panel de clientes en la opción configuración.</comment>
3333
</field>
34+
<field id="payco_private_key" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="0">
35+
<label>Private_KEY</label>
36+
<comment>LLave para autenticar y consumir los servicios de ePayco, Proporcionado en su panel de clientes en la opción configuración.</comment>
37+
</field>
3438
<field id="payco_callback" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="0">
3539
<label>URL De Respuesta</label>
3640
<comment>Url de respuesta para confirmar los pagos desde ePayco.</comment>

Pago/Paycoagregador/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<p_cust_id_cliente>P_CUST_ID_CLIENTE</p_cust_id_cliente>
1717
<p_key>P_KEY</p_key>
1818
<public_key>Public_KEY</public_key>
19+
<private_key>Private_KEY</private_key>
1920
<url_de_respuesta>URL De Respuesta</url_de_respuesta>
2021
<url_de_confirmacion>URL de confirmación</url_de_confirmacion>
2122
<modo_pruebas>Modo Pruebas</modo_pruebas>

Pago/Paycoagregador/readme.md

100644100755
File mode changed.

Pago/Paycoagregador/view/frontend/web/js/view/payment/method-renderer/epaycoagregador-method.js

Lines changed: 115 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ define(
1515
'Magento_Checkout/js/model/url-builder',
1616
'Magento_Customer/js/model/customer',
1717
'Magento_Checkout/js/model/place-order',
18-
'https://checkout.epayco.co/checkout.js'
18+
'https://checkout.epayco.co/checkout.js',
19+
'Magento_Checkout/js/model/full-screen-loader',
20+
'Magento_Ui/js/modal/alert',
1921
],
20-
function ($,Component,url,quote,checkoutData,messageContainer, urlBuilder, customer, placeOrderService) {
22+
function ($,Component,url,quote,checkoutData,messageContainer, urlBuilder, customer, placeOrderService, ePayco, fullScreenLoader, alert) {
2123
'use strict';
2224
return Component.extend({
2325
defaults: {
2426
self:this,
2527
template: 'Pago_Paycoagregador/payment/epaycoagregador'
2628
},
2729
redirectAfterPlaceOrder: false,
28-
renderCheckout: async function() {
30+
renderCheckout: function() {
31+
fullScreenLoader.startLoader();
32+
//$('#loader-agregador').trigger('processStart');
2933
var button0 = document.getElementsByClassName('action primary checkout')[0];
3034
var button1 = document.getElementsByClassName('action primary checkout')[1];
3135
button0.style.disabled = true;
@@ -43,20 +47,40 @@ define(
4347
billingAddress: quote.billingAddress(),
4448
paymentMethod: paymentData
4549
};
50+
var docType='';
51+
var mobile = '';
52+
var doc= '';
53+
var country = '';
54+
var email = '';
55+
var name_billing = '';
56+
var address_billing = '';
4657

4758
if (customer.isLoggedIn()) {
4859
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
49-
} else {
60+
email = customer.customerData.email;
61+
//mobile = customer.customerData.addresses[0].telephone;
62+
mobile = '';
63+
name_billing = customer.customerData.firstname + ' ' + customer.customerData.lastname;
64+
//address_billing = customer.customerData.addresses[0].street[0];
65+
//country = customer.customerData.addresses[0].country_id;
66+
} else {
5067
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
5168
quoteId: quote.getQuoteId()
5269
});
5370
payload.email = quote.guestEmail;
71+
email = quote.guestEmail;
72+
mobile = '';
73+
name_billing = quote.billingAddress().firstname + ' '+ quote.billingAddress().lastname;
74+
address_billing = quote.billingAddress().street[0];
75+
country = quote.billingAddress().countryId;
5476
}
55-
placeOrderService(serviceUrl, payload, messageContainer);
77+
// placeOrderService(serviceUrl, payload, messageContainer);
5678
var orderId = this.getOrderId();
5779
var getQuoteIncrement = this.getQuoteIncrementId();
5880
var totals = quote.getTotals();
5981
var quoteIdData = this.getQuoteIdData();
82+
var ip = this.getCustomerIp();
83+
var _this = this;
6084
var invoice;
6185
var settings = {
6286
"url": url.build("responseAgregador/paymentagregador/index"),
@@ -71,7 +95,7 @@ define(
7195
"order_id": quoteIdData
7296
}
7397
}
74-
await $.ajax({
98+
$.ajax({
7599
url: url.build("responseAgregador/paymentagregador/index"),
76100
headers: {
77101
'X-Requested-With': 'XMLHttpRequest',
@@ -103,7 +127,7 @@ define(
103127
window.checkoutConfig.payment.epaycoagregador.payco_test = "false";
104128
var test2 = false;
105129
}
106-
var handler = ePayco.checkout.configure({
130+
var handler = window.ePayco.checkout.configure({
107131
key: window.checkoutConfig.payment.epaycoagregador.payco_public_key,
108132
test:test2
109133
})
@@ -116,44 +140,42 @@ define(
116140
}
117141

118142
}
119-
var docType='';
120-
var mobile = '';
121-
var doc= '';
122-
var country = '';
143+
123144
// fin calcular base iva
124145
if(!window.checkoutConfig.isCustomerLoggedIn){
125146
if(customerData){
126-
var name_billing = customerData.firstname + ' ' + customerData.lastname;
127-
var address_billing = customerData.street[0]+ ' ' + customerData.street[1];
147+
name_billing = customerData.firstname + ' ' + customerData.lastname;
148+
address_billing = customerData.street[0]+ ' ' + customerData.street[1];
128149
country = customerData.country_id;
129150
}else{
130151
country = 'CO';
131152
}
132153
} else {
133-
var name_billing = window.checkoutConfig.customerData.firstname + ' '+ window.checkoutConfig.customerData.lastname;
154+
name_billing = window.checkoutConfig.customerData.firstname + ' '+ window.checkoutConfig.customerData.lastname;
134155
mobile = countryBllg.telephone;
135-
var address_billing = countryBllg.street[0];
156+
address_billing = countryBllg.street[0];
136157
country = countryBllg.countryId;
137158
}
138159
var lang = '';
139160
var temp = window.checkoutConfig.payment.epaycoagregador.language.split("_");
140161
lang = temp[0];
141-
162+
142163
var amount = 0;
143164
amount = totals._latestValue.base_grand_total;
144165
var taxes = 0;
145166
taxes = totals._latestValue.base_tax_amount;
146167
var tax_base = 0;
147168
tax_base = amount - taxes;
169+
parseFloat(tax_base);
148170
var data={
149171
//Parametros compra (obligatorio)
150172
name: items,
151173
description: items,
152174
invoice: invoice,
153175
currency: window.checkoutConfig.quoteData.store_currency_code,
154-
amount: amount,
155-
tax_base: tax_base.replace('.',','),
156-
tax: taxes.replace('.',','),
176+
amount: amount.toString(),
177+
tax_base: tax_base.toString(),
178+
tax: taxes.toString(),
157179
country: country,
158180
lang: lang,
159181
//Onpage='false' - Standard='true'
@@ -163,22 +185,50 @@ define(
163185
extra2: invoice,
164186
confirmation:url.build("confirmationAgregador/epaycoagregador/index"),
165187
response: url.build("confirmationAgregador/epaycoagregador/index"),
166-
//Atributos cliente
188+
//Atributos clienteng:
189+
email_billing:email,
167190
name_billing: name_billing,
168191
address_billing: address_billing,
169192
type_doc_billing: docType,
170193
mobilephone_billing: mobile,
171-
number_doc_billing: doc
194+
number_doc_billing: doc,
195+
autoclick: "true",
196+
//ip: ip,
197+
//test: test2.toString()
172198
};
199+
173200
button0.disabled = false;
174201
button1.disabled = false;
175202
button0.style.disabled = false;
176203
button1.style.disabled = false;
177-
handler.open(data);
204+
const apiKey = window.checkoutConfig.payment.epaycoagregador.payco_public_key;
205+
const privateKey = window.checkoutConfig.payment.epaycoagregador.payco_private_key;
206+
var handler = ePayco.checkout.configure({
207+
key: apiKey,
208+
test:test2
209+
})
210+
fullScreenLoader.stopLoader();
211+
handler.open(data);
212+
/*if(localStorage.getItem("invoicePayment") == null){
213+
localStorage.setItem("invoicePayment", invoice);
214+
_this.makePayment(privateKey,apiKey,data, data.external == 'true'?true:false)
215+
}else{
216+
if(localStorage.getItem("invoicePayment") != invoice){
217+
localStorage.removeItem("invoicePayment");
218+
localStorage.setItem("invoicePayment", invoice);
219+
_this.makePayment(privateKey,apiKey,data, data.external == 'true'?true:false)
220+
}else{
221+
_this.makePayment(privateKey,apiKey,data, data.external == 'true'?true:false)
222+
}
223+
}*/
178224
}
179225
},
180226
error :function(error){
181-
227+
//$('body').trigger('processStop');
228+
fullScreenLoader.stopLoader();
229+
alert({
230+
content: $.mage.__('Sorry, something went wrong. Please try again later.')
231+
});
182232
console.log('error: '+error);
183233
}
184234
});
@@ -214,6 +264,48 @@ define(
214264
responseAction: function(){
215265
return window.checkoutConfig.payment.epaycoagregador.responseAction;
216266
},
267+
getCustomerIp: function(){
268+
return window.checkoutConfig.payment.epaycoagregador.getCustomerIp;
269+
},
270+
afterPlaceOrder: function () {
271+
this.renderCheckout();
272+
},
273+
makePayment: function (privatekey, apikey, info, external) {
274+
const headers = { 'Content-Type': 'application/json' } ;
275+
headers['privatekey'] = privatekey;
276+
headers['apikey'] = apikey;
277+
var payment = function (){
278+
return fetch("https://cms.epayco.io/checkout/payment/session", {
279+
method: 'POST',
280+
body: JSON.stringify(info),
281+
headers
282+
})
283+
.then(res => res.json())
284+
.catch(err => err);
285+
}
286+
payment()
287+
.then(session => {
288+
if(session.data.sessionId != undefined){
289+
localStorage.removeItem("sessionPayment");
290+
localStorage.setItem("sessionPayment", session.data.sessionId);
291+
const handlerNew = window.ePayco.checkout.configure({
292+
sessionId: session.data.sessionId,
293+
external: external,
294+
});
295+
//$('body').trigger('processStop');
296+
//$('#loader-agregador').trigger('processStop');
297+
fullScreenLoader.stopLoader();
298+
handlerNew.openNew()
299+
}
300+
})
301+
.catch(error => {
302+
fullScreenLoader.stopLoader();
303+
alert({
304+
content: $.mage.__('Sorry, something went wrong. Please try again later.')
305+
});
306+
error.message;
307+
});
308+
}
217309
});
218310
}
219311
);

Pago/Paycoagregador/view/frontend/web/template/payment/epaycoagregador.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
1+
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}" id="loader-agregador" data-mage-init='{"loader": { "icon": "{store_url}/static/{static_version}/frontend/Magento/luma/en_US/images/loader-2.gif"}}'>
22
<div class="payment-method-title field choice">
33
<input type="radio"
44
name="payment[method]"
@@ -22,25 +22,18 @@
2222
</div>
2323
<div class="actions-toolbar">
2424
<div class="primary">
25-
26-
<!--<input type="image" id="imagen" src="https://369969691f476073508a-60bf0867add971908d4f26a64519c2aa.ssl.cf5.rackcdn.com/btns/btn4.png" data-bind="
27-
click: renderCheckout
28-
"/> -->
2925
<button class="action primary checkout"
3026
type="submit"
3127
data-bind="
32-
click: renderCheckout,
28+
click: placeOrder,
3329
attr: {title: $t('Place Order')},
3430
css: {disabled: !isPlaceOrderActionAllowed()},
3531
enable: (getCode() == isChecked())
3632
"
3733
disabled>
3834
<span data-bind="i18n: 'Place Order'"></span>
3935
</button>
40-
<!-- <button class="action primary checkout"
41-
type="button" onclick="renderCheckout()">
42-
<span data-bind="i18n: 'Place Order'"></span>
43-
</button>-->
36+
4437
</div>
4538
</div>
4639
</div>

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Este plugin permite integrar ePayco como medio de pago para sus diferentes tiend
55
**Si usted tiene alguna pregunta o problema, no dude en ponerse en contacto con nuestro soporte técnico: desarrollo@payco.co.**
66

77
## Versiones
8-
* [ePayco plugin Magento multi tienda v2.0.x](https://github.com/epayco/plugin_epayco_magento_agregador/releases/tag/v2.0.0).
8+
* [ePayco plugin Magento agregador v2.0.x](https://github.com/epayco/plugin_epayco_magento_agregador/releases/tag/v2.0.0).
9+
* [ePayco plugin Magento agregador v2.7.0](https://github.com/epayco/plugin_epayco_magento_agregador/releases/tag/v2.7.0).
910

1011

1112
## Iniciando

0 commit comments

Comments
 (0)