Version Notes
- Fix issue with multiple notifications
- Fix issue with approved tickets notifications
- Change logic for shipments calculation
- Add option include/exclude financing cost from the orders
- Fix other minor issues
Download this release
Release Info
Developer | MercadoPago |
Extension | MercadoPagoTransparent |
Version | 2.2.0 |
Comparing to | |
See all releases |
Code changes from version 0.0.4 to 2.2.0
- app/code/community/MercadoPago/Core/Block/AbstractForm.php +0 -0
- app/code/community/MercadoPago/Core/Block/AbstractSuccess.php +0 -0
- app/code/community/MercadoPago/Core/Block/Adminhtml/System/Config/Fieldset/Payment.php +3 -2
- app/code/community/MercadoPago/Core/Block/Custom/Form.php +0 -0
- app/code/community/MercadoPago/Core/Block/Custom/Info.php +0 -0
- app/code/community/MercadoPago/Core/Block/Custom/Success.php +0 -0
- app/code/community/MercadoPago/Core/Block/Customticket/Form.php +0 -0
- app/code/community/MercadoPago/Core/Block/Customticket/Info.php +0 -0
- app/code/community/MercadoPago/Core/Block/Customticket/Success.php +0 -0
- app/code/community/MercadoPago/Core/Block/Discount.php +0 -0
- app/code/community/MercadoPago/Core/Block/Sales/Order/Totals/Discount/Coupon.php +0 -0
- app/code/community/MercadoPago/Core/Block/Sales/Order/Totals/Finance/Cost.php +0 -0
- app/code/community/MercadoPago/Core/Block/Standard/Form.php +0 -0
- app/code/community/MercadoPago/Core/Block/Standard/Info.php +0 -0
- app/code/community/MercadoPago/Core/Block/Standard/Pay.php +0 -0
- app/code/community/MercadoPago/Core/Block/Standard/Success.php +0 -0
- app/code/community/MercadoPago/Core/Helper/Data.php +90 -27
- app/code/community/MercadoPago/Core/Helper/Message/Abstract.php +0 -0
- app/code/community/MercadoPago/Core/Helper/Response.php +0 -0
- app/code/community/MercadoPago/Core/Helper/StatusDetailMessage.php +0 -0
- app/code/community/MercadoPago/Core/Helper/StatusMessage.php +0 -0
- app/code/community/MercadoPago/Core/Helper/StatusOrderMessage.php +0 -0
- app/code/community/MercadoPago/Core/Model/Api/Exception.php +0 -0
- app/code/community/MercadoPago/Core/Model/Api/V0/Exception.php +0 -0
- app/code/community/MercadoPago/Core/Model/Api/V1/Exception.php +0 -0
- app/code/community/MercadoPago/Core/Model/Core.php +211 -184
- app/code/community/MercadoPago/Core/Model/Custom/Finance/Cost.php +0 -0
- app/code/community/MercadoPago/Core/Model/Custom/Finance/Cost/Creditmemo.php +0 -0
- app/code/community/MercadoPago/Core/Model/Custom/Finance/Cost/Invoice.php +0 -0
- app/code/community/MercadoPago/Core/Model/Custom/Payment.php +11 -17
- app/code/community/MercadoPago/Core/Model/CustomPayment.php +6 -0
- app/code/community/MercadoPago/Core/Model/CustomTicket/Payment.php +12 -27
- app/code/community/MercadoPago/Core/Model/Discount/Coupon.php +0 -0
- app/code/community/MercadoPago/Core/Model/Discount/Coupon/Creditmemo.php +0 -0
- app/code/community/MercadoPago/Core/Model/Discount/Coupon/Invoice.php +0 -0
- app/code/community/MercadoPago/Core/Model/Observer.php +39 -34
- app/code/community/MercadoPago/Core/Model/Source/CategoryId.php +0 -0
- app/code/community/MercadoPago/Core/Model/Source/Country.php +0 -0
- app/code/community/MercadoPago/Core/Model/Source/Installments.php +0 -0
- app/code/community/MercadoPago/Core/Model/Source/Order/Status.php +0 -0
- app/code/community/MercadoPago/Core/Model/Source/PaymentMethods.php +10 -8
- app/code/community/MercadoPago/Core/Model/Source/TypeCheckout.php +0 -0
- app/code/community/MercadoPago/Core/Model/Standard/Payment.php +45 -51
- app/code/community/MercadoPago/Core/controllers/ApiController.php +0 -0
- app/code/community/MercadoPago/Core/controllers/NotificationsController.php +154 -55
- app/code/community/MercadoPago/Core/controllers/PayController.php +0 -0
- app/code/community/MercadoPago/Core/controllers/SuccessController.php +10 -1
- app/code/community/MercadoPago/Core/etc/config.xml +3 -4
- app/code/community/MercadoPago/Core/etc/system.xml +17 -1
- app/code/community/MercadoPago/Core/sql/mercadopago_setup/install-2.1.0.php +0 -0
- app/code/community/MercadoPago/Core/sql/mercadopago_setup/upgrade-2.1.0-2.1.1.php +0 -0
- app/code/community/MercadoPago/Core/sql/mercadopago_setup/upgrade-2.1.1-2.1.2.php +0 -0
- app/code/community/MercadoPago/MercadoEnvios/Block/Adminhtml/System/Config/Fieldset/Carrier.php +0 -0
- app/code/community/MercadoPago/MercadoEnvios/Block/Adminhtml/System/Config/Fieldset/Mapping.php +0 -0
- app/code/community/MercadoPago/MercadoEnvios/Helper/CarrierData.php +120 -0
- app/code/community/MercadoPago/MercadoEnvios/Helper/Data.php +48 -85
- app/code/community/MercadoPago/MercadoEnvios/Helper/ItemData.php +0 -0
- app/code/community/MercadoPago/MercadoEnvios/Model/Adminhtml/Attribute/Validation/Mapping.php +0 -0
- app/code/community/MercadoPago/MercadoEnvios/Model/Adminhtml/Source/Shipping/FreeMethod.php +0 -0
- app/code/community/MercadoPago/MercadoEnvios/Model/Adminhtml/Source/Shipping/Method.php +9 -0
- app/code/community/MercadoPago/MercadoEnvios/Model/Adminhtml/Source/Shipping/Print/Mode.php +11 -0
- app/code/community/MercadoPago/MercadoEnvios/Model/Observer.php +26 -1
- app/code/community/MercadoPago/MercadoEnvios/Model/Shipping/Carrier/MercadoEnvios.php +20 -7
- app/code/community/MercadoPago/MercadoEnvios/etc/config.xml +13 -1
- app/code/community/MercadoPago/MercadoEnvios/etc/system.xml +9 -0
- app/code/community/MercadoPago/OneStepCheckout/Block/Custom/Form.php +0 -1
- app/code/community/MercadoPago/OneStepCheckout/Block/Customticket/Form.php +0 -0
- app/code/community/MercadoPago/OneStepCheckout/Helper/Data.php +0 -0
- app/code/community/MercadoPago/OneStepCheckout/Model/Observer.php +0 -0
- app/code/community/MercadoPago/OneStepCheckout/etc/config.xml +1 -1
- app/code/community/MercadoPago/OneStepCheckout/etc/system.xml +0 -0
- app/design/adminhtml/default/default/layout/mercadopago.xml +0 -0
- app/design/adminhtml/default/default/template/mercadopago/array_dropdown.phtml +0 -0
- app/design/adminhtml/default/default/template/mercadopago/custom/info.phtml +0 -0
- app/design/adminhtml/default/default/template/mercadopago/custom_ticket/info.phtml +0 -0
- app/design/adminhtml/default/default/template/mercadopago/standard/info.phtml +0 -0
- app/design/frontend/base/default/layout/mercadopago.xml +0 -0
- app/design/frontend/base/default/template/mercadopago/clean.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/custom/form.phtml +2 -3
- app/design/frontend/base/default/template/mercadopago/custom/info.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/custom/success.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/custom_ticket/form.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/custom_ticket/info.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/custom_ticket/success.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/discount.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/onestepcheckout/custom/form.phtml +1 -2
- app/design/frontend/base/default/template/mercadopago/standard/form.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/standard/info.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/standard/pay.phtml +0 -0
- app/design/frontend/base/default/template/mercadopago/standard/success.phtml +0 -0
- app/etc/modules/MercadoPago_Core.xml +0 -9
- app/etc/modules/MercadoPago_MercadoEnvios.xml +0 -12
- app/etc/modules/MercadoPago_OneStepCheckout.xml +0 -12
- app/locale/en_US/MercadoPago_Core.csv +13 -1
- app/locale/es_AR/MercadoPago_Core.csv +13 -1
- app/locale/es_CL/MercadoPago_Core.csv +13 -1
- app/locale/es_CO/MercadoPago_Core.csv +13 -1
- app/locale/es_ES/MercadoPago_Core.csv +13 -1
- app/locale/es_MX/MercadoPago_Core.csv +13 -1
- app/locale/es_VE/MercadoPago_Core.csv +13 -1
- app/locale/pt_BR/MercadoPago_Core.csv +12 -1
- js/mercadopago/jquery-1.11.0.min.js +0 -0
- js/mercadopago/mercadopago.js +54 -59
- js/mercadopago/mercadopago_osc.js +60 -63
- js/mercadopago/tiny.min.js +0 -0
- js/mercadopago/tinyJ.js +0 -0
- lib/MercadoPago/Lib/Api.php +0 -0
- lib/MercadoPago/Lib/RestClient.php +0 -0
- package.xml +165 -58
- skin/adminhtml/default/default/mercadopago/images/cards.jpg +0 -0
- skin/adminhtml/default/default/mercadopago/images/logo.png +0 -0
- skin/adminhtml/default/default/mercadopago/images/mercadoenvios.png +0 -0
- skin/adminhtml/default/default/mercadopago/styles.css +0 -0
- skin/frontend/base/default/mercadopago/css/style-success.css +0 -0
- skin/frontend/base/default/mercadopago/css/style.css +0 -0
- skin/frontend/base/default/mercadopago/images/loading.gif +0 -0
app/code/community/MercadoPago/Core/Block/AbstractForm.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/AbstractSuccess.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Adminhtml/System/Config/Fieldset/Payment.php
CHANGED
@@ -13,8 +13,9 @@ class MercadoPago_Core_Block_Adminhtml_System_Config_Fieldset_Payment
|
|
13 |
*/
|
14 |
protected function _getHeaderTitleHtml($element)
|
15 |
{
|
16 |
-
$
|
17 |
-
|
|
|
18 |
|
19 |
$html = '<div class="config-heading meli" ><div class="heading"><strong id="meli-logo">' . $element->getLegend();
|
20 |
$html .= '</strong></div>';
|
13 |
*/
|
14 |
protected function _getHeaderTitleHtml($element)
|
15 |
{
|
16 |
+
$website = Mage::helper('mercadopago')->getAdminSelectedWebsite();
|
17 |
+
|
18 |
+
$imageUrl = $website->getConfig('payment/mercadopago_standard/banner_checkout');
|
19 |
|
20 |
$html = '<div class="config-heading meli" ><div class="heading"><strong id="meli-logo">' . $element->getLegend();
|
21 |
$html .= '</strong></div>';
|
app/code/community/MercadoPago/Core/Block/Custom/Form.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Custom/Info.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Custom/Success.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Customticket/Form.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Customticket/Info.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Customticket/Success.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Discount.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Sales/Order/Totals/Discount/Coupon.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Sales/Order/Totals/Finance/Cost.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Standard/Form.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Standard/Info.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Standard/Pay.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Block/Standard/Success.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Helper/Data.php
CHANGED
@@ -27,6 +27,11 @@ class MercadoPago_Core_Helper_Data
|
|
27 |
const PLATFORM_DESKTOP = 'Desktop';
|
28 |
const TYPE = 'magento';
|
29 |
|
|
|
|
|
|
|
|
|
|
|
30 |
public function log($message, $file = "mercadopago.log", $array = null)
|
31 |
{
|
32 |
$actionLog = Mage::getStoreConfig('payment/mercadopago/logs');
|
@@ -40,27 +45,45 @@ class MercadoPago_Core_Helper_Data
|
|
40 |
}
|
41 |
}
|
42 |
|
43 |
-
public function
|
44 |
{
|
45 |
-
$
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
$
|
55 |
-
}
|
56 |
-
if (Mage::getStoreConfigFlag('payment/mercadopago_standard/sandbox_mode')) {
|
57 |
-
$api->sandbox_mode(true);
|
58 |
}
|
|
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
|
66 |
public function isValidAccessToken($accessToken)
|
@@ -160,12 +183,12 @@ class MercadoPago_Core_Helper_Data
|
|
160 |
|
161 |
public function setOrderSubtotals($data, $order)
|
162 |
{
|
163 |
-
if (isset($data['total_paid_amount
|
164 |
-
$balance = $this->_getMultiCardValue($data
|
165 |
} else {
|
166 |
$balance = $data['transaction_details']['total_paid_amount'];
|
167 |
}
|
168 |
-
$shippingCost = $this->_getMultiCardValue($data
|
169 |
|
170 |
$order->setGrandTotal($balance);
|
171 |
$order->setBaseGrandTotal($balance);
|
@@ -174,8 +197,8 @@ class MercadoPago_Core_Helper_Data
|
|
174 |
$order->setShippingAmount($shippingCost);
|
175 |
}
|
176 |
|
177 |
-
$couponAmount = $this->_getMultiCardValue($data
|
178 |
-
$transactionAmount = $this->_getMultiCardValue($data
|
179 |
|
180 |
if ($couponAmount) {
|
181 |
$order->setDiscountCouponAmount($couponAmount * -1);
|
@@ -185,7 +208,7 @@ class MercadoPago_Core_Helper_Data
|
|
185 |
$balance = $balance - $transactionAmount - $shippingCost;
|
186 |
}
|
187 |
|
188 |
-
if (Zend_Locale_Math::round($balance,4) > 0) {
|
189 |
$order->setFinanceCostAmount($balance);
|
190 |
$order->setBaseFinanceCostAmount($balance);
|
191 |
}
|
@@ -207,15 +230,55 @@ class MercadoPago_Core_Helper_Data
|
|
207 |
return $payment;
|
208 |
}
|
209 |
|
210 |
-
protected function _getMultiCardValue($
|
|
|
211 |
$finalValue = 0;
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
}
|
217 |
|
218 |
return $finalValue;
|
219 |
}
|
220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
}
|
27 |
const PLATFORM_DESKTOP = 'Desktop';
|
28 |
const TYPE = 'magento';
|
29 |
|
30 |
+
protected $_statusUpdatedFlag = false;
|
31 |
+
protected $_apiInstance;
|
32 |
+
|
33 |
+
protected $_website;
|
34 |
+
|
35 |
public function log($message, $file = "mercadopago.log", $array = null)
|
36 |
{
|
37 |
$actionLog = Mage::getStoreConfig('payment/mercadopago/logs');
|
45 |
}
|
46 |
}
|
47 |
|
48 |
+
public function isStatusUpdated()
|
49 |
{
|
50 |
+
return $this->_statusUpdatedFlag;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function setStatusUpdated($notificationData)
|
54 |
+
{
|
55 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($notificationData["external_reference"]);
|
56 |
+
$status = $notificationData['status'];
|
57 |
+
$currentStatus = $order->getPayment()->getAdditionalInformation('status');
|
58 |
+
if ($status == $currentStatus && $order->getState() === Mage_Sales_Model_Order::STATE_COMPLETE) {
|
59 |
+
$this->_statusUpdatedFlag = true;
|
|
|
|
|
|
|
60 |
}
|
61 |
+
}
|
62 |
|
63 |
+
public function getApiInstance()
|
64 |
+
{
|
65 |
+
if (empty($this->_apiInstance)) {
|
66 |
+
$params = func_num_args();
|
67 |
+
if ($params > 2 || $params < 1) {
|
68 |
+
Mage::throwException("Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN");
|
69 |
+
}
|
70 |
+
if ($params == 1) {
|
71 |
+
$api = new MercadoPago_Lib_Api(func_get_arg(0));
|
72 |
+
$api->set_platform(self::PLATFORM_V1_WHITELABEL);
|
73 |
+
} else {
|
74 |
+
$api = new MercadoPago_Lib_Api(func_get_arg(0), func_get_arg(1));
|
75 |
+
$api->set_platform(self::PLATFORM_DESKTOP);
|
76 |
+
}
|
77 |
+
if (Mage::getStoreConfigFlag('payment/mercadopago_standard/sandbox_mode')) {
|
78 |
+
$api->sandbox_mode(true);
|
79 |
+
}
|
80 |
|
81 |
+
$api->set_type(self::TYPE . ' ' . (string)Mage::getConfig()->getModuleConfig("MercadoPago_Core")->version);
|
82 |
|
83 |
+
$this->_apiInstance = $api;
|
84 |
+
}
|
85 |
+
|
86 |
+
return $this->_apiInstance;
|
87 |
}
|
88 |
|
89 |
public function isValidAccessToken($accessToken)
|
183 |
|
184 |
public function setOrderSubtotals($data, $order)
|
185 |
{
|
186 |
+
if (isset($data['total_paid_amount'])) {
|
187 |
+
$balance = $this->_getMultiCardValue($data, 'total_paid_amount');
|
188 |
} else {
|
189 |
$balance = $data['transaction_details']['total_paid_amount'];
|
190 |
}
|
191 |
+
$shippingCost = $this->_getMultiCardValue($data, 'shipping_cost');
|
192 |
|
193 |
$order->setGrandTotal($balance);
|
194 |
$order->setBaseGrandTotal($balance);
|
197 |
$order->setShippingAmount($shippingCost);
|
198 |
}
|
199 |
|
200 |
+
$couponAmount = $this->_getMultiCardValue($data, 'coupon_amount');
|
201 |
+
$transactionAmount = $this->_getMultiCardValue($data, 'transaction_amount');
|
202 |
|
203 |
if ($couponAmount) {
|
204 |
$order->setDiscountCouponAmount($couponAmount * -1);
|
208 |
$balance = $balance - $transactionAmount - $shippingCost;
|
209 |
}
|
210 |
|
211 |
+
if (Zend_Locale_Math::round($balance, 4) > 0) {
|
212 |
$order->setFinanceCostAmount($balance);
|
213 |
$order->setBaseFinanceCostAmount($balance);
|
214 |
}
|
230 |
return $payment;
|
231 |
}
|
232 |
|
233 |
+
protected function _getMultiCardValue($data, $field)
|
234 |
+
{
|
235 |
$finalValue = 0;
|
236 |
+
if (!isset($data[$field])) {
|
237 |
+
return $finalValue;
|
238 |
+
}
|
239 |
+
$amountValues = explode('|', $data[$field]);
|
240 |
+
$statusValues = explode('|', $data['status']);
|
241 |
+
foreach ($amountValues as $key => $value) {
|
242 |
+
$value = (float)str_replace(' ', '', $value);
|
243 |
+
if (str_replace(' ', '', $statusValues[$key]) == 'approved') {
|
244 |
+
$finalValue = $finalValue + $value;
|
245 |
+
}
|
246 |
}
|
247 |
|
248 |
return $finalValue;
|
249 |
}
|
250 |
|
251 |
+
public function getSuccessUrl()
|
252 |
+
{
|
253 |
+
if (Mage::getStoreConfig('payment/mercadopago/use_successpage_mp')) {
|
254 |
+
$url = 'mercadopago/success';
|
255 |
+
} else {
|
256 |
+
$url = 'checkout/onepage/success';
|
257 |
+
}
|
258 |
+
|
259 |
+
return $url;
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Return the website associated to admin combo select
|
264 |
+
*
|
265 |
+
* @return Mage_Core_Model_Website
|
266 |
+
*/
|
267 |
+
public function getAdminSelectedWebsite()
|
268 |
+
{
|
269 |
+
if (isset($this->_website)) {
|
270 |
+
return $this->_website;
|
271 |
+
}
|
272 |
+
|
273 |
+
$websiteId = Mage::getSingleton('adminhtml/config_data')->getWebsite();
|
274 |
+
|
275 |
+
if ($websiteId) {
|
276 |
+
$this->_website = Mage::app()->getWebsite($websiteId);
|
277 |
+
} else {
|
278 |
+
$this->_website = Mage::app()->getWebsite();
|
279 |
+
}
|
280 |
+
|
281 |
+
return $this->_website;
|
282 |
+
}
|
283 |
+
|
284 |
}
|
app/code/community/MercadoPago/Core/Helper/Message/Abstract.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Helper/Response.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Helper/StatusDetailMessage.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Helper/StatusMessage.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Helper/StatusOrderMessage.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Api/Exception.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Api/V0/Exception.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Api/V1/Exception.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Core.php
CHANGED
@@ -18,14 +18,13 @@ class MercadoPago_Core_Model_Core
|
|
18 |
extends Mage_Payment_Model_Method_Abstract
|
19 |
{
|
20 |
protected $_code = 'mercadopago';
|
|
|
|
|
|
|
21 |
|
22 |
protected $_isGateway = true;
|
23 |
protected $_canOrder = true;
|
24 |
-
protected $_canAuthorize = true;
|
25 |
-
protected $_canCapture = true;
|
26 |
-
protected $_canCapturePartial = true;
|
27 |
protected $_canRefund = true;
|
28 |
-
protected $_canRefundInvoicePartial = true;
|
29 |
protected $_canVoid = true;
|
30 |
protected $_canUseInternal = true;
|
31 |
protected $_canUseCheckout = true;
|
@@ -87,83 +86,83 @@ class MercadoPago_Core_Model_Core
|
|
87 |
return Mage::getModel('sales/order')->loadByIncrementId($incrementId);
|
88 |
}
|
89 |
|
90 |
-
public function getInfoPaymentByOrder($
|
91 |
{
|
92 |
-
$order = Mage::getModel('sales/order')->loadByIncrementId($
|
93 |
$payment = $order->getPayment();
|
94 |
-
$
|
95 |
-
$fields =
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
foreach ($fields as $field
|
109 |
-
if ($payment->getAdditionalInformation($field['field']) !=
|
110 |
$text = Mage::helper('mercadopago')->__($field['title'], $payment->getAdditionalInformation($field['field']));
|
111 |
-
$
|
112 |
"text" => $text,
|
113 |
"value" => $payment->getAdditionalInformation($field['field'])
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
-
return $
|
119 |
}
|
120 |
|
121 |
protected function validStatusTwoPayments($status)
|
122 |
{
|
123 |
-
$
|
124 |
-
$
|
125 |
-
$
|
126 |
-
foreach ($
|
127 |
|
128 |
-
if ($
|
129 |
-
$
|
130 |
} else {
|
131 |
-
if ($
|
132 |
-
$
|
133 |
}
|
134 |
}
|
135 |
endforeach;
|
136 |
|
137 |
-
if ($
|
138 |
-
$
|
139 |
}
|
140 |
|
141 |
-
return $
|
142 |
}
|
143 |
|
144 |
-
public function getMessageByStatus($status, $
|
145 |
{
|
146 |
$status = $this->validStatusTwoPayments($status);
|
147 |
-
$
|
148 |
|
149 |
-
$message =
|
150 |
"title" => "",
|
151 |
"message" => ""
|
152 |
-
|
153 |
|
154 |
$rawMessage = Mage::helper('mercadopago/statusMessage')->getMessage($status);
|
155 |
$message['title'] = Mage::helper('mercadopago')->__($rawMessage['title']);
|
156 |
|
157 |
if ($status == 'rejected') {
|
158 |
-
if ($
|
159 |
$message['message'] = Mage::helper('mercadopago')
|
160 |
-
->__(Mage::helper('mercadopago/statusDetailMessage')->getMessage($
|
161 |
-
} elseif ($
|
162 |
$message['message'] = Mage::helper('mercadopago')
|
163 |
-
->__(Mage::helper('mercadopago/statusDetailMessage')->getMessage($
|
164 |
} else {
|
165 |
$message['message'] = Mage::helper('mercadopago')
|
166 |
-
->__(Mage::helper('mercadopago/statusDetailMessage')->getMessage($
|
167 |
}
|
168 |
} else {
|
169 |
$message['message'] = Mage::helper('mercadopago')->__($rawMessage['message']);
|
@@ -179,27 +178,27 @@ class MercadoPago_Core_Model_Core
|
|
179 |
$email = $order['customer_email'];
|
180 |
}
|
181 |
|
182 |
-
$
|
183 |
-
if ($
|
184 |
-
$
|
185 |
}
|
186 |
|
187 |
-
$
|
188 |
-
if ($
|
189 |
-
$
|
190 |
}
|
191 |
|
192 |
-
return
|
193 |
}
|
194 |
|
195 |
protected function getItemsInfo($order)
|
196 |
{
|
197 |
-
$dataItems =
|
198 |
foreach ($order->getAllVisibleItems() as $item) {
|
199 |
$product = $item->getProduct();
|
200 |
$image = (string)Mage::helper('catalog/image')->init($product, 'image');
|
201 |
|
202 |
-
$dataItems[] =
|
203 |
"id" => $item->getSku(),
|
204 |
"title" => $product->getName(),
|
205 |
"description" => $product->getName(),
|
@@ -207,29 +206,29 @@ class MercadoPago_Core_Model_Core
|
|
207 |
"category_id" => Mage::getStoreConfig('payment/mercadopago/category_id'),
|
208 |
"quantity" => (int)number_format($item->getQtyOrdered(), 0, '.', ''),
|
209 |
"unit_price" => (float)number_format($product->getPrice(), 2, '.', '')
|
210 |
-
|
211 |
}
|
212 |
|
213 |
/* verify discount and add it like an item */
|
214 |
$discount = $this->getDiscount();
|
215 |
if ($discount != 0) {
|
216 |
-
$dataItems[] =
|
217 |
"title" => "Discount by the Store",
|
218 |
"description" => "Discount by the Store",
|
219 |
"quantity" => 1,
|
220 |
"unit_price" => (float)number_format($discount, 2, '.', '')
|
221 |
-
|
222 |
}
|
223 |
|
224 |
return $dataItems;
|
225 |
|
226 |
}
|
227 |
|
228 |
-
protected function getCouponInfo($coupon, $
|
229 |
{
|
230 |
-
$infoCoupon =
|
231 |
$infoCoupon['coupon_amount'] = (float)$coupon['response']['coupon_amount'];
|
232 |
-
$infoCoupon['coupon_code'] = $
|
233 |
$infoCoupon['campaign_id'] = $coupon['response']['id'];
|
234 |
if ($coupon['status'] == 200) {
|
235 |
Mage::helper('mercadopago')->log("Coupon applied. API response 200.", self::LOG_FILE);
|
@@ -240,78 +239,81 @@ class MercadoPago_Core_Model_Core
|
|
240 |
return $infoCoupon;
|
241 |
}
|
242 |
|
243 |
-
public function makeDefaultPreferencePaymentV1($
|
244 |
{
|
245 |
$quote = $this->_getQuote();
|
246 |
-
$
|
247 |
-
$order = $this->_getOrder($
|
248 |
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
249 |
|
250 |
-
$
|
251 |
$customerInfo = $this->getCustomerInfo($customer, $order);
|
252 |
|
253 |
/* INIT PREFERENCE */
|
254 |
-
$preference =
|
255 |
|
256 |
$preference['notification_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "mercadopago/notifications/custom";
|
257 |
-
|
258 |
$preference['transaction_amount'] = (float)$this->getAmount();
|
259 |
|
260 |
-
$preference['external_reference'] = $
|
261 |
$preference['payer']['email'] = $customerInfo['email'];
|
262 |
|
263 |
-
if (!empty($
|
264 |
-
$preference['payer']['identification']['type'] = $
|
265 |
-
$preference['payer']['identification']['number'] = $
|
266 |
}
|
267 |
$preference['additional_info']['items'] = $this->getItemsInfo($order);
|
268 |
|
269 |
$preference['additional_info']['payer']['first_name'] = $customerInfo['first_name'];
|
270 |
$preference['additional_info']['payer']['last_name'] = $customerInfo['last_name'];
|
271 |
|
272 |
-
$preference['additional_info']['payer']['address'] =
|
273 |
-
"zip_code" => $
|
274 |
-
"street_name" => $
|
275 |
"street_number" => ''
|
276 |
-
|
277 |
|
278 |
$preference['additional_info']['payer']['registration_date'] = date('Y-m-d', $customer->getCreatedAtTimestamp()) . "T" . date('H:i:s', $customer->getCreatedAtTimestamp());
|
279 |
|
280 |
-
|
|
|
|
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
|
289 |
-
|
|
|
290 |
|
291 |
-
$preference['additional_info']['payer']['phone'] =
|
292 |
"area_code" => "0",
|
293 |
-
"number" => $
|
294 |
-
|
295 |
|
296 |
-
if (!empty($
|
297 |
-
$
|
298 |
-
Mage::helper('mercadopago')->log("Validating coupon_code: " . $
|
299 |
|
300 |
-
$coupon = $this->validCoupon($
|
301 |
Mage::helper('mercadopago')->log("Response API Coupon: ", self::LOG_FILE, $coupon);
|
302 |
|
303 |
-
$couponInfo = $this->getCouponInfo($coupon, $
|
304 |
$preference['coupon_amount'] = $couponInfo['coupon_amount'];
|
305 |
-
$preference['coupon_code'] =
|
306 |
$preference['campaign_id'] = $couponInfo['campaign_id'];
|
307 |
|
308 |
}
|
309 |
|
310 |
-
$
|
311 |
-
Mage::helper('mercadopago')->log("Sponsor_id", 'mercadopago-standard.log', $
|
312 |
-
if (!empty($
|
313 |
-
Mage::helper('mercadopago')->log("Sponsor_id identificado", self::LOG_FILE, $
|
314 |
-
$preference['sponsor_id'] = (int)$
|
315 |
}
|
316 |
|
317 |
return $preference;
|
@@ -321,12 +323,13 @@ class MercadoPago_Core_Model_Core
|
|
321 |
public function postPaymentV1($preference)
|
322 |
{
|
323 |
|
324 |
-
|
325 |
-
|
326 |
-
|
|
|
327 |
|
328 |
-
//
|
329 |
-
$mp = Mage::helper('mercadopago')->getApiInstance($
|
330 |
$response = $mp->post("/v1/payments", $preference);
|
331 |
Mage::helper('mercadopago')->log("POST /v1/payments", self::LOG_FILE, $response);
|
332 |
|
@@ -353,35 +356,43 @@ class MercadoPago_Core_Model_Core
|
|
353 |
|
354 |
public function getPayment($payment_id)
|
355 |
{
|
356 |
-
|
357 |
-
|
358 |
-
|
|
|
|
|
359 |
|
360 |
return $mp->get_payment($payment_id);
|
361 |
}
|
362 |
|
363 |
public function getPaymentV1($payment_id)
|
364 |
{
|
365 |
-
|
366 |
-
|
|
|
|
|
367 |
|
368 |
return $mp->get("/v1/payments/" . $payment_id);
|
369 |
}
|
370 |
|
371 |
public function getMerchantOrder($merchant_order_id)
|
372 |
{
|
373 |
-
|
374 |
-
|
375 |
-
|
|
|
|
|
376 |
|
377 |
return $mp->get("/merchant_orders/" . $merchant_order_id);
|
378 |
}
|
379 |
|
380 |
public function getPaymentMethods()
|
381 |
{
|
382 |
-
|
|
|
|
|
383 |
|
384 |
-
$mp = Mage::helper('mercadopago')->getApiInstance($this->
|
385 |
|
386 |
$payment_methods = $mp->get("/v1/payment_methods");
|
387 |
|
@@ -413,9 +424,11 @@ class MercadoPago_Core_Model_Core
|
|
413 |
|
414 |
public function validCoupon($id)
|
415 |
{
|
416 |
-
|
|
|
|
|
417 |
|
418 |
-
$mp = Mage::helper('mercadopago')->getApiInstance($this->
|
419 |
|
420 |
$params = array(
|
421 |
"transaction_amount" => $this->getAmount(),
|
@@ -433,7 +446,22 @@ class MercadoPago_Core_Model_Core
|
|
433 |
return $details_discount;
|
434 |
}
|
435 |
|
436 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
437 |
{
|
438 |
$helper = Mage::helper('mercadopago');
|
439 |
$order = Mage::getModel('sales/order')->loadByIncrementId($payment["external_reference"]);
|
@@ -443,45 +471,29 @@ class MercadoPago_Core_Model_Core
|
|
443 |
$status = $payment['status_final'];
|
444 |
}
|
445 |
$message = $helper->getMessage($status, $payment);
|
|
|
|
|
|
|
446 |
|
447 |
try {
|
448 |
if ($status == 'approved') {
|
449 |
Mage::helper('mercadopago')->setOrderSubtotals($payment, $order);
|
450 |
-
|
451 |
-
if (!$order->hasInvoices()) {
|
452 |
-
$invoice = $order->prepareInvoice();
|
453 |
-
$invoice->register()->pay();
|
454 |
-
Mage::getModel('core/resource_transaction')
|
455 |
-
->addObject($invoice)
|
456 |
-
->addObject($invoice->getOrder())
|
457 |
-
->save();
|
458 |
-
|
459 |
-
$invoice->sendEmail(true, $message);
|
460 |
-
}
|
461 |
//Associate card to customer
|
462 |
$additionalInfo = $order->getPayment()->getAdditionalInformation();
|
463 |
if (isset($additionalInfo['token'])) {
|
464 |
Mage::getModel('mercadopago/custom_payment')->customerAndCards($additionalInfo['token'], $payment);
|
465 |
}
|
466 |
|
467 |
-
|
468 |
} elseif ($status == 'refunded' || $status == 'cancelled') {
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
$statusOrder = $helper->getStatusOrder($status);
|
473 |
-
if ($stateObject) {
|
474 |
-
$stateObject->setStatus($statusOrder);
|
475 |
-
$stateObject->setState($helper->_getAssignedState($statusOrder));
|
476 |
-
$stateObject->setIsNotified(true);
|
477 |
}
|
|
|
|
|
478 |
|
479 |
-
$order->
|
480 |
-
$
|
481 |
-
$order->sendOrderUpdateEmail(true, $message);
|
482 |
-
|
483 |
-
$status_save = $order->save();
|
484 |
-
$helper->log("Update order", 'mercadopago.log', $status_save->getData());
|
485 |
$helper->log($message, 'mercadopago.log');
|
486 |
|
487 |
return ['text' => $message, 'code' => MercadoPago_Core_Helper_Response::HTTP_OK];
|
@@ -492,60 +504,75 @@ class MercadoPago_Core_Model_Core
|
|
492 |
}
|
493 |
}
|
494 |
|
495 |
-
|
496 |
{
|
497 |
-
|
|
|
498 |
|
499 |
-
try {
|
500 |
-
$order = Mage::getModel('sales/order')->loadByIncrementId($data["external_reference"]);
|
501 |
|
502 |
-
$
|
|
|
|
|
|
|
|
|
503 |
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
|
|
|
|
513 |
|
514 |
-
|
515 |
|
516 |
-
|
517 |
-
|
518 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
}
|
520 |
-
}
|
521 |
-
|
522 |
-
if (isset($data['payment_method_id'])) {
|
523 |
-
$payment_order->setAdditionalInformation('payment_method', $data['payment_method_id']);
|
524 |
-
}
|
525 |
|
526 |
-
|
527 |
-
|
|
|
528 |
|
529 |
-
|
530 |
-
$
|
531 |
-
}
|
532 |
|
533 |
-
|
534 |
-
$
|
535 |
-
}
|
|
|
|
|
536 |
|
537 |
-
|
538 |
-
$order->setCustomerEmail($data['payer_email']);
|
539 |
}
|
540 |
-
|
541 |
-
|
542 |
-
$status_save = $order->save();
|
543 |
-
Mage::helper('mercadopago')->log("Update order", 'mercadopago.log', $status_save->getData());
|
544 |
-
} catch (Exception $e) {
|
545 |
-
Mage::helper('mercadopago')->log("error in update order status: " . $e, 'mercadopago.log');
|
546 |
-
$this->getResponse()->setBody($e);
|
547 |
-
|
548 |
-
$this->getResponse()->setHttpResponseCode(MercadoPago_Core_Helper_Response::HTTP_BAD_REQUEST);
|
549 |
}
|
550 |
}
|
551 |
|
18 |
extends Mage_Payment_Model_Method_Abstract
|
19 |
{
|
20 |
protected $_code = 'mercadopago';
|
21 |
+
protected $_accessToken;
|
22 |
+
protected $_clientId;
|
23 |
+
protected $_clientSecret;
|
24 |
|
25 |
protected $_isGateway = true;
|
26 |
protected $_canOrder = true;
|
|
|
|
|
|
|
27 |
protected $_canRefund = true;
|
|
|
28 |
protected $_canVoid = true;
|
29 |
protected $_canUseInternal = true;
|
30 |
protected $_canUseCheckout = true;
|
86 |
return Mage::getModel('sales/order')->loadByIncrementId($incrementId);
|
87 |
}
|
88 |
|
89 |
+
public function getInfoPaymentByOrder($orderId)
|
90 |
{
|
91 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
|
92 |
$payment = $order->getPayment();
|
93 |
+
$infoPayments = [];
|
94 |
+
$fields = [
|
95 |
+
["field" => "cardholderName", "title" => "Card Holder Name: %s"],
|
96 |
+
["field" => "trunc_card", "title" => "Card Number: %s"],
|
97 |
+
["field" => "payment_method", "title" => "Payment Method: %s"],
|
98 |
+
["field" => "expiration_date", "title" => "Expiration Date: %s"],
|
99 |
+
["field" => "installments", "title" => "Installments: %s"],
|
100 |
+
["field" => "statement_descriptor", "title" => "Statement Descriptor: %s"],
|
101 |
+
["field" => "payment_id", "title" => "Payment id (MercadoPago): %s"],
|
102 |
+
["field" => "status", "title" => "Payment Status: %s"],
|
103 |
+
["field" => "status_detail", "title" => "Payment Detail: %s"],
|
104 |
+
["field" => "activation_uri", "title" => "Generate Ticket"]
|
105 |
+
];
|
106 |
+
|
107 |
+
foreach ($fields as $field) {
|
108 |
+
if ($payment->getAdditionalInformation($field['field']) != "") {
|
109 |
$text = Mage::helper('mercadopago')->__($field['title'], $payment->getAdditionalInformation($field['field']));
|
110 |
+
$infoPayments[$field['field']] = [
|
111 |
"text" => $text,
|
112 |
"value" => $payment->getAdditionalInformation($field['field'])
|
113 |
+
];
|
114 |
+
}
|
115 |
+
}
|
116 |
|
117 |
+
return $infoPayments;
|
118 |
}
|
119 |
|
120 |
protected function validStatusTwoPayments($status)
|
121 |
{
|
122 |
+
$arrayStatus = explode(" | ", $status);
|
123 |
+
$statusVerif = true;
|
124 |
+
$statusFinal = "";
|
125 |
+
foreach ($arrayStatus as $status):
|
126 |
|
127 |
+
if ($statusFinal == "") {
|
128 |
+
$statusFinal = $status;
|
129 |
} else {
|
130 |
+
if ($statusFinal != $status) {
|
131 |
+
$statusVerif = false;
|
132 |
}
|
133 |
}
|
134 |
endforeach;
|
135 |
|
136 |
+
if ($statusVerif === false) {
|
137 |
+
$statusFinal = "other";
|
138 |
}
|
139 |
|
140 |
+
return $statusFinal;
|
141 |
}
|
142 |
|
143 |
+
public function getMessageByStatus($status, $statusDetail, $paymentMethod, $installment, $amount)
|
144 |
{
|
145 |
$status = $this->validStatusTwoPayments($status);
|
146 |
+
$statusDetail = $this->validStatusTwoPayments($statusDetail);
|
147 |
|
148 |
+
$message = [
|
149 |
"title" => "",
|
150 |
"message" => ""
|
151 |
+
];
|
152 |
|
153 |
$rawMessage = Mage::helper('mercadopago/statusMessage')->getMessage($status);
|
154 |
$message['title'] = Mage::helper('mercadopago')->__($rawMessage['title']);
|
155 |
|
156 |
if ($status == 'rejected') {
|
157 |
+
if ($statusDetail == 'cc_rejected_invalid_installments') {
|
158 |
$message['message'] = Mage::helper('mercadopago')
|
159 |
+
->__(Mage::helper('mercadopago/statusDetailMessage')->getMessage($statusDetail), strtoupper($paymentMethod), $installment);
|
160 |
+
} elseif ($statusDetail == 'cc_rejected_call_for_authorize') {
|
161 |
$message['message'] = Mage::helper('mercadopago')
|
162 |
+
->__(Mage::helper('mercadopago/statusDetailMessage')->getMessage($statusDetail), strtoupper($paymentMethod), $amount);
|
163 |
} else {
|
164 |
$message['message'] = Mage::helper('mercadopago')
|
165 |
+
->__(Mage::helper('mercadopago/statusDetailMessage')->getMessage($statusDetail), strtoupper($paymentMethod));
|
166 |
}
|
167 |
} else {
|
168 |
$message['message'] = Mage::helper('mercadopago')->__($rawMessage['message']);
|
178 |
$email = $order['customer_email'];
|
179 |
}
|
180 |
|
181 |
+
$firstName = htmlentities($customer->getFirstname());
|
182 |
+
if ($firstName == "") {
|
183 |
+
$firstName = $order->getBillingAddress()->getFirstname();
|
184 |
}
|
185 |
|
186 |
+
$lastName = htmlentities($customer->getLastname());
|
187 |
+
if ($lastName == "") {
|
188 |
+
$lastName = $order->getBillingAddress()->getLastname();
|
189 |
}
|
190 |
|
191 |
+
return ['email' => $email, 'first_name' => $firstName, 'last_name' => $lastName];
|
192 |
}
|
193 |
|
194 |
protected function getItemsInfo($order)
|
195 |
{
|
196 |
+
$dataItems = [];
|
197 |
foreach ($order->getAllVisibleItems() as $item) {
|
198 |
$product = $item->getProduct();
|
199 |
$image = (string)Mage::helper('catalog/image')->init($product, 'image');
|
200 |
|
201 |
+
$dataItems[] = [
|
202 |
"id" => $item->getSku(),
|
203 |
"title" => $product->getName(),
|
204 |
"description" => $product->getName(),
|
206 |
"category_id" => Mage::getStoreConfig('payment/mercadopago/category_id'),
|
207 |
"quantity" => (int)number_format($item->getQtyOrdered(), 0, '.', ''),
|
208 |
"unit_price" => (float)number_format($product->getPrice(), 2, '.', '')
|
209 |
+
];
|
210 |
}
|
211 |
|
212 |
/* verify discount and add it like an item */
|
213 |
$discount = $this->getDiscount();
|
214 |
if ($discount != 0) {
|
215 |
+
$dataItems[] = [
|
216 |
"title" => "Discount by the Store",
|
217 |
"description" => "Discount by the Store",
|
218 |
"quantity" => 1,
|
219 |
"unit_price" => (float)number_format($discount, 2, '.', '')
|
220 |
+
];
|
221 |
}
|
222 |
|
223 |
return $dataItems;
|
224 |
|
225 |
}
|
226 |
|
227 |
+
protected function getCouponInfo($coupon, $couponCode)
|
228 |
{
|
229 |
+
$infoCoupon = [];
|
230 |
$infoCoupon['coupon_amount'] = (float)$coupon['response']['coupon_amount'];
|
231 |
+
$infoCoupon['coupon_code'] = $couponCode;
|
232 |
$infoCoupon['campaign_id'] = $coupon['response']['id'];
|
233 |
if ($coupon['status'] == 200) {
|
234 |
Mage::helper('mercadopago')->log("Coupon applied. API response 200.", self::LOG_FILE);
|
239 |
return $infoCoupon;
|
240 |
}
|
241 |
|
242 |
+
public function makeDefaultPreferencePaymentV1($paymentInfo = [])
|
243 |
{
|
244 |
$quote = $this->_getQuote();
|
245 |
+
$orderId = $quote->getReservedOrderId();
|
246 |
+
$order = $this->_getOrder($orderId);
|
247 |
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
248 |
|
249 |
+
$billingAddress = $quote->getBillingAddress()->getData();
|
250 |
$customerInfo = $this->getCustomerInfo($customer, $order);
|
251 |
|
252 |
/* INIT PREFERENCE */
|
253 |
+
$preference = [];
|
254 |
|
255 |
$preference['notification_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "mercadopago/notifications/custom";
|
256 |
+
$preference['description'] = Mage::helper('mercadopago')->__("Order # %s in store %s", $orderId, Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true));
|
257 |
$preference['transaction_amount'] = (float)$this->getAmount();
|
258 |
|
259 |
+
$preference['external_reference'] = $orderId;
|
260 |
$preference['payer']['email'] = $customerInfo['email'];
|
261 |
|
262 |
+
if (!empty($paymentInfo['identification_type'])) {
|
263 |
+
$preference['payer']['identification']['type'] = $paymentInfo['identification_type'];
|
264 |
+
$preference['payer']['identification']['number'] = $paymentInfo['identification_number'];
|
265 |
}
|
266 |
$preference['additional_info']['items'] = $this->getItemsInfo($order);
|
267 |
|
268 |
$preference['additional_info']['payer']['first_name'] = $customerInfo['first_name'];
|
269 |
$preference['additional_info']['payer']['last_name'] = $customerInfo['last_name'];
|
270 |
|
271 |
+
$preference['additional_info']['payer']['address'] = [
|
272 |
+
"zip_code" => $billingAddress['postcode'],
|
273 |
+
"street_name" => $billingAddress['street'] . " - " . $billingAddress['city'] . " - " . $billingAddress['country_id'],
|
274 |
"street_number" => ''
|
275 |
+
];
|
276 |
|
277 |
$preference['additional_info']['payer']['registration_date'] = date('Y-m-d', $customer->getCreatedAtTimestamp()) . "T" . date('H:i:s', $customer->getCreatedAtTimestamp());
|
278 |
|
279 |
+
if ($order->canShip()) {
|
280 |
+
$shippingAddress = $order->getShippingAddress();
|
281 |
+
$shipping = $shippingAddress->getData();
|
282 |
|
283 |
+
$preference['additional_info']['shipments']['receiver_address'] = [
|
284 |
+
"zip_code" => $shipping['postcode'],
|
285 |
+
"street_name" => $shipping['street'] . " - " . $shipping['city'] . " - " . $shipping['country_id'],
|
286 |
+
"street_number" => '',
|
287 |
+
"floor" => "-",
|
288 |
+
"apartment" => "-",
|
289 |
|
290 |
+
];
|
291 |
+
}
|
292 |
|
293 |
+
$preference['additional_info']['payer']['phone'] = [
|
294 |
"area_code" => "0",
|
295 |
+
"number" => $billingAddress['telephone']
|
296 |
+
];
|
297 |
|
298 |
+
if (!empty($paymentInfo['coupon_code'])) {
|
299 |
+
$couponCode = $paymentInfo['coupon_code'];
|
300 |
+
Mage::helper('mercadopago')->log("Validating coupon_code: " . $couponCode, self::LOG_FILE);
|
301 |
|
302 |
+
$coupon = $this->validCoupon($couponCode);
|
303 |
Mage::helper('mercadopago')->log("Response API Coupon: ", self::LOG_FILE, $coupon);
|
304 |
|
305 |
+
$couponInfo = $this->getCouponInfo($coupon, $couponCode);
|
306 |
$preference['coupon_amount'] = $couponInfo['coupon_amount'];
|
307 |
+
$preference['coupon_code'] = strtoupper($couponInfo['coupon_code']);
|
308 |
$preference['campaign_id'] = $couponInfo['campaign_id'];
|
309 |
|
310 |
}
|
311 |
|
312 |
+
$sponsorId = Mage::getStoreConfig('payment/mercadopago/sponsor_id');
|
313 |
+
Mage::helper('mercadopago')->log("Sponsor_id", 'mercadopago-standard.log', $sponsorId);
|
314 |
+
if (!empty($sponsorId)) {
|
315 |
+
Mage::helper('mercadopago')->log("Sponsor_id identificado", self::LOG_FILE, $sponsorId);
|
316 |
+
$preference['sponsor_id'] = (int)$sponsorId;
|
317 |
}
|
318 |
|
319 |
return $preference;
|
323 |
public function postPaymentV1($preference)
|
324 |
{
|
325 |
|
326 |
+
if (!$this->_accessToken) {
|
327 |
+
$this->_accessToken = Mage::getStoreConfig(self::XML_PATH_ACCESS_TOKEN);
|
328 |
+
}
|
329 |
+
Mage::helper('mercadopago')->log("Access Token for Post", self::LOG_FILE, $this->_accessToken);
|
330 |
|
331 |
+
//set sdk php mercadopago
|
332 |
+
$mp = Mage::helper('mercadopago')->getApiInstance($this->_accessToken);
|
333 |
$response = $mp->post("/v1/payments", $preference);
|
334 |
Mage::helper('mercadopago')->log("POST /v1/payments", self::LOG_FILE, $response);
|
335 |
|
356 |
|
357 |
public function getPayment($payment_id)
|
358 |
{
|
359 |
+
if (!$this->_clientId || !$this->_clientSecret) {
|
360 |
+
$this->_clientId = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_ID);
|
361 |
+
$this->_clientSecret = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_SECRET);
|
362 |
+
}
|
363 |
+
$mp = Mage::helper('mercadopago')->getApiInstance($this->_clientId, $this->_clientSecret);
|
364 |
|
365 |
return $mp->get_payment($payment_id);
|
366 |
}
|
367 |
|
368 |
public function getPaymentV1($payment_id)
|
369 |
{
|
370 |
+
if (!$this->_accessToken) {
|
371 |
+
$this->_accessToken = Mage::getStoreConfig(self::XML_PATH_ACCESS_TOKEN);
|
372 |
+
}
|
373 |
+
$mp = Mage::helper('mercadopago')->getApiInstance($this->_accessToken);
|
374 |
|
375 |
return $mp->get("/v1/payments/" . $payment_id);
|
376 |
}
|
377 |
|
378 |
public function getMerchantOrder($merchant_order_id)
|
379 |
{
|
380 |
+
if (!$this->_clientId || !$this->_clientSecret) {
|
381 |
+
$this->_clientId = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_ID);
|
382 |
+
$this->_clientSecret = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_SECRET);
|
383 |
+
}
|
384 |
+
$mp = Mage::helper('mercadopago')->getApiInstance($this->_clientId, $this->_clientSecret);
|
385 |
|
386 |
return $mp->get("/merchant_orders/" . $merchant_order_id);
|
387 |
}
|
388 |
|
389 |
public function getPaymentMethods()
|
390 |
{
|
391 |
+
if (!$this->_accessToken) {
|
392 |
+
$this->_accessToken = Mage::getStoreConfig(self::XML_PATH_ACCESS_TOKEN);
|
393 |
+
}
|
394 |
|
395 |
+
$mp = Mage::helper('mercadopago')->getApiInstance($this->_accessToken);
|
396 |
|
397 |
$payment_methods = $mp->get("/v1/payment_methods");
|
398 |
|
424 |
|
425 |
public function validCoupon($id)
|
426 |
{
|
427 |
+
if (!$this->_accessToken) {
|
428 |
+
$this->_accessToken = Mage::getStoreConfig(self::XML_PATH_ACCESS_TOKEN);
|
429 |
+
}
|
430 |
|
431 |
+
$mp = Mage::helper('mercadopago')->getApiInstance($this->_accessToken);
|
432 |
|
433 |
$params = array(
|
434 |
"transaction_amount" => $this->getAmount(),
|
446 |
return $details_discount;
|
447 |
}
|
448 |
|
449 |
+
protected function _createInvoice($order, $message)
|
450 |
+
{
|
451 |
+
if (!$order->hasInvoices()) {
|
452 |
+
$invoice = $order->prepareInvoice();
|
453 |
+
$invoice->register();
|
454 |
+
$invoice->pay();
|
455 |
+
Mage::getModel('core/resource_transaction')
|
456 |
+
->addObject($invoice)
|
457 |
+
->addObject($invoice->getOrder())
|
458 |
+
->save();
|
459 |
+
|
460 |
+
$invoice->sendEmail(true, $message);
|
461 |
+
}
|
462 |
+
}
|
463 |
+
|
464 |
+
public function setStatusOrder($payment)
|
465 |
{
|
466 |
$helper = Mage::helper('mercadopago');
|
467 |
$order = Mage::getModel('sales/order')->loadByIncrementId($payment["external_reference"]);
|
471 |
$status = $payment['status_final'];
|
472 |
}
|
473 |
$message = $helper->getMessage($status, $payment);
|
474 |
+
if (Mage::helper('mercadopago')->isStatusUpdated()) {
|
475 |
+
return ['text' => $message, 'code' => MercadoPago_Core_Helper_Response::HTTP_OK];
|
476 |
+
}
|
477 |
|
478 |
try {
|
479 |
if ($status == 'approved') {
|
480 |
Mage::helper('mercadopago')->setOrderSubtotals($payment, $order);
|
481 |
+
$this->_createInvoice($order, $message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
482 |
//Associate card to customer
|
483 |
$additionalInfo = $order->getPayment()->getAdditionalInformation();
|
484 |
if (isset($additionalInfo['token'])) {
|
485 |
Mage::getModel('mercadopago/custom_payment')->customerAndCards($additionalInfo['token'], $payment);
|
486 |
}
|
487 |
|
|
|
488 |
} elseif ($status == 'refunded' || $status == 'cancelled') {
|
489 |
+
//generate credit memo and return items to stock according to setting
|
490 |
+
$this->_generateCreditMemo($order, $payment);
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
}
|
492 |
+
//if state is not complete updates according to setting
|
493 |
+
$this->_updateStatus($order, $helper, $status, $message);
|
494 |
|
495 |
+
$statusSave = $order->save();
|
496 |
+
$helper->log("Update order", 'mercadopago.log', $statusSave->getData());
|
|
|
|
|
|
|
|
|
497 |
$helper->log($message, 'mercadopago.log');
|
498 |
|
499 |
return ['text' => $message, 'code' => MercadoPago_Core_Helper_Response::HTTP_OK];
|
504 |
}
|
505 |
}
|
506 |
|
507 |
+
protected function _updateStatus($order, $helper, $status, $message)
|
508 |
{
|
509 |
+
if ($order->getState() !== Mage_Sales_Model_Order::STATE_COMPLETE) {
|
510 |
+
$statusOrder = $helper->getStatusOrder($status);
|
511 |
|
|
|
|
|
512 |
|
513 |
+
$order->setState($helper->_getAssignedState($statusOrder));
|
514 |
+
$order->addStatusToHistory($statusOrder, $message, true);
|
515 |
+
$order->sendOrderUpdateEmail(true, $message);
|
516 |
+
}
|
517 |
+
}
|
518 |
|
519 |
+
protected function _generateCreditMemo($order, $payment)
|
520 |
+
{
|
521 |
+
if (isset($payment['amount_refunded']) && $payment['amount_refunded'] > 0 && $payment['amount_refunded'] == $payment['total_paid_amount']) {
|
522 |
+
$order->getPayment()->registerRefundNotification($payment['amount_refunded']);
|
523 |
+
$creditMemo = array_pop($order->getCreditmemosCollection()->setPageSize(1)->setCurPage(1)->load()->getItems());
|
524 |
+
foreach ($creditMemo->getAllItems() as $creditMemoItem) {
|
525 |
+
$creditMemoItem->setBackToStock(Mage::helper('cataloginventory')->isAutoReturnEnabled());
|
526 |
+
}
|
527 |
+
$creditMemo->save();
|
528 |
+
$order->cancel();
|
529 |
+
}
|
530 |
|
531 |
+
}
|
532 |
|
533 |
+
public function updateOrder($data)
|
534 |
+
{
|
535 |
+
Mage::helper('mercadopago')->log("Update Order", 'mercadopago-notification.log');
|
536 |
+
if (!Mage::helper('mercadopago')->isStatusUpdated()) {
|
537 |
+
|
538 |
+
try {
|
539 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($data["external_reference"]);
|
540 |
+
|
541 |
+
$paymentOrder = $order->getPayment();
|
542 |
+
|
543 |
+
$additionalFields = [
|
544 |
+
'status',
|
545 |
+
'status_detail',
|
546 |
+
'payment_id',
|
547 |
+
'transaction_amount',
|
548 |
+
'cardholderName',
|
549 |
+
'installments',
|
550 |
+
'statement_descriptor',
|
551 |
+
'trunc_card',
|
552 |
+
'id'
|
553 |
+
];
|
554 |
+
|
555 |
+
foreach ($additionalFields as $field) {
|
556 |
+
if (isset($data[$field])) {
|
557 |
+
$paymentOrder->setAdditionalInformation($field, $data[$field]);
|
558 |
+
}
|
559 |
}
|
|
|
|
|
|
|
|
|
|
|
560 |
|
561 |
+
if (isset($data['payment_method_id'])) {
|
562 |
+
$paymentOrder->setAdditionalInformation('payment_method', $data['payment_method_id']);
|
563 |
+
}
|
564 |
|
565 |
+
$paymentStatus = $paymentOrder->save();
|
566 |
+
Mage::helper('mercadopago')->log("Update Payment", 'mercadopago.log', $paymentStatus->getData());
|
|
|
567 |
|
568 |
+
$statusSave = $order->save();
|
569 |
+
Mage::helper('mercadopago')->log("Update order", 'mercadopago.log', $statusSave->getData());
|
570 |
+
} catch (Exception $e) {
|
571 |
+
Mage::helper('mercadopago')->log("error in update order status: " . $e, 'mercadopago.log');
|
572 |
+
$this->getResponse()->setBody($e);
|
573 |
|
574 |
+
$this->getResponse()->setHttpResponseCode(MercadoPago_Core_Helper_Response::HTTP_BAD_REQUEST);
|
|
|
575 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
}
|
577 |
}
|
578 |
|
app/code/community/MercadoPago/Core/Model/Custom/Finance/Cost.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Custom/Finance/Cost/Creditmemo.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Custom/Finance/Cost/Invoice.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Custom/Payment.php
CHANGED
@@ -44,25 +44,18 @@ class MercadoPago_Core_Model_Custom_Payment
|
|
44 |
|
45 |
$response = $this->preparePostPayment();
|
46 |
|
47 |
-
if ($response
|
48 |
-
|
49 |
$payment = $response['response'];
|
50 |
//set status
|
51 |
$this->getInfoInstance()->setAdditionalInformation('status', $payment['status']);
|
52 |
$this->getInfoInstance()->setAdditionalInformation('status_detail', $payment['status_detail']);
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
$payment = Mage::helper('mercadopago')->setPayerInfo($payment);
|
58 |
-
$core = Mage::getModel('mercadopago/core');
|
59 |
-
Mage::helper('mercadopago')->log("Update Order", self::LOG_FILE);
|
60 |
-
$core->updateOrder($payment);
|
61 |
-
$core->setStatusOrder($payment, $stateObject);
|
62 |
-
}
|
63 |
|
64 |
return true;
|
65 |
-
|
66 |
|
67 |
return false;
|
68 |
}
|
@@ -187,7 +180,7 @@ class MercadoPago_Core_Model_Custom_Payment
|
|
187 |
|
188 |
public function getOrCreateCustomer($email)
|
189 |
{
|
190 |
-
if (empty($email
|
191 |
return false;
|
192 |
}
|
193 |
$access_token = Mage::getStoreConfig(self::XML_PATH_ACCESS_TOKEN);
|
@@ -240,10 +233,10 @@ class MercadoPago_Core_Model_Custom_Payment
|
|
240 |
}
|
241 |
}
|
242 |
$params = ["token" => $token];
|
243 |
-
if (isset($payment['issuer_id
|
244 |
$params['issuer_id'] = (int)$payment['issuer_id'];
|
245 |
}
|
246 |
-
if (isset($payment['payment_method_id
|
247 |
$params['payment_method_id'] = $payment['payment_method_id'];
|
248 |
}
|
249 |
$card = $mp->post("/v1/customers/" . $customer['id'] . "/cards", $params);
|
@@ -272,7 +265,8 @@ class MercadoPago_Core_Model_Custom_Payment
|
|
272 |
return Mage::getUrl('mercadopago/success', ['_secure' => true]);
|
273 |
}
|
274 |
|
275 |
-
public function getCode()
|
|
|
276 |
return $this->_code;
|
277 |
}
|
278 |
|
44 |
|
45 |
$response = $this->preparePostPayment();
|
46 |
|
47 |
+
if ($response) {
|
|
|
48 |
$payment = $response['response'];
|
49 |
//set status
|
50 |
$this->getInfoInstance()->setAdditionalInformation('status', $payment['status']);
|
51 |
$this->getInfoInstance()->setAdditionalInformation('status_detail', $payment['status_detail']);
|
52 |
+
$this->getInfoInstance()->setAdditionalInformation('payment_id_detail', $payment['id']);
|
53 |
+
$stateObject->setState(Mage::helper('mercadopago')->_getAssignedState('pending_payment'));
|
54 |
+
$stateObject->setStatus('pending_payment');
|
55 |
+
$stateObject->setIsNotified(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
return true;
|
58 |
+
}
|
59 |
|
60 |
return false;
|
61 |
}
|
180 |
|
181 |
public function getOrCreateCustomer($email)
|
182 |
{
|
183 |
+
if (empty($email)) {
|
184 |
return false;
|
185 |
}
|
186 |
$access_token = Mage::getStoreConfig(self::XML_PATH_ACCESS_TOKEN);
|
233 |
}
|
234 |
}
|
235 |
$params = ["token" => $token];
|
236 |
+
if (isset($payment['issuer_id'])) {
|
237 |
$params['issuer_id'] = (int)$payment['issuer_id'];
|
238 |
}
|
239 |
+
if (isset($payment['payment_method_id'])) {
|
240 |
$params['payment_method_id'] = $payment['payment_method_id'];
|
241 |
}
|
242 |
$card = $mp->post("/v1/customers/" . $customer['id'] . "/cards", $params);
|
265 |
return Mage::getUrl('mercadopago/success', ['_secure' => true]);
|
266 |
}
|
267 |
|
268 |
+
public function getCode()
|
269 |
+
{
|
270 |
return $this->_code;
|
271 |
}
|
272 |
|
app/code/community/MercadoPago/Core/Model/CustomPayment.php
CHANGED
@@ -39,6 +39,12 @@ abstract class MercadoPago_Core_Model_CustomPayment
|
|
39 |
return false;
|
40 |
}
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
return Mage::helper('mercadopago')->isValidAccessToken($accessToken);
|
43 |
}
|
44 |
|
39 |
return false;
|
40 |
}
|
41 |
|
42 |
+
$debugMode = Mage::getStoreConfig('payment/mercadopago/debug_mode');
|
43 |
+
$secure = Mage::app()->getFrontController()->getRequest()->isSecure();
|
44 |
+
if (!$secure && !$debugMode ) {
|
45 |
+
return false;
|
46 |
+
}
|
47 |
+
|
48 |
return Mage::helper('mercadopago')->isValidAccessToken($accessToken);
|
49 |
}
|
50 |
|
app/code/community/MercadoPago/Core/Model/CustomTicket/Payment.php
CHANGED
@@ -17,7 +17,6 @@
|
|
17 |
class MercadoPago_Core_Model_CustomTicket_Payment
|
18 |
extends MercadoPago_Core_Model_CustomPayment
|
19 |
{
|
20 |
-
//configura o lugar do arquivo para listar meios de pagamento
|
21 |
protected $_formBlockType = 'mercadopago/customticket_form';
|
22 |
protected $_infoBlockType = 'mercadopago/customticket_info';
|
23 |
|
@@ -46,23 +45,21 @@ class MercadoPago_Core_Model_CustomTicket_Payment
|
|
46 |
|
47 |
public function assignData($data)
|
48 |
{
|
49 |
-
|
50 |
// route /checkout/onepage/savePayment
|
51 |
if (!($data instanceof Varien_Object)) {
|
52 |
$data = new Varien_Object($data);
|
53 |
}
|
54 |
|
55 |
-
|
56 |
-
$
|
57 |
-
$info_form = $info_form['mercadopago_customticket'];
|
58 |
|
59 |
-
Mage::helper('mercadopago')->log("info form", 'mercadopago-custom.log', $
|
60 |
|
61 |
$info = $this->getInfoInstance();
|
62 |
-
$info->setAdditionalInformation('payment_method', $
|
63 |
|
64 |
-
if (isset($
|
65 |
-
$info->setAdditionalInformation('coupon_code', $
|
66 |
}
|
67 |
|
68 |
return $this;
|
@@ -73,23 +70,19 @@ class MercadoPago_Core_Model_CustomTicket_Payment
|
|
73 |
Mage::helper('mercadopago')->log("Ticket -> init prepare post payment", 'mercadopago-custom.log');
|
74 |
$core = Mage::getModel('mercadopago/core');
|
75 |
$quote = $this->_getQuote();
|
76 |
-
$
|
77 |
-
$order = $this->_getOrder($
|
78 |
|
79 |
-
//pega payment dentro da order para pegar as informacoes adicionadas pela funcao assignData()
|
80 |
$payment = $order->getPayment();
|
81 |
|
82 |
-
$
|
83 |
|
84 |
-
/* verifica se o pagamento possui coupon_code */
|
85 |
if ($payment->getAdditionalInformation("coupon_code") != "") {
|
86 |
-
$
|
87 |
}
|
88 |
|
89 |
-
|
90 |
-
$preference = $core->makeDefaultPreferencePaymentV1($payment_info);
|
91 |
|
92 |
-
/* adiciona informações sobre pagamento com ticket */
|
93 |
$preference['payment_method_id'] = $payment->getAdditionalInformation("payment_method");
|
94 |
|
95 |
Mage::helper('mercadopago')->log("Ticket -> PREFERENCE to POST /v1/payments", 'mercadopago-custom.log', $preference);
|
@@ -101,15 +94,7 @@ class MercadoPago_Core_Model_CustomTicket_Payment
|
|
101 |
|
102 |
public function getOrderPlaceRedirectUrl()
|
103 |
{
|
104 |
-
|
105 |
-
return Mage::getUrl('mercadopago/success', array('_secure' => true));
|
106 |
-
}
|
107 |
-
|
108 |
-
|
109 |
-
public function getSuccessBlockType()
|
110 |
-
{
|
111 |
-
return $this->_successBlockType;
|
112 |
}
|
113 |
|
114 |
-
|
115 |
}
|
17 |
class MercadoPago_Core_Model_CustomTicket_Payment
|
18 |
extends MercadoPago_Core_Model_CustomPayment
|
19 |
{
|
|
|
20 |
protected $_formBlockType = 'mercadopago/customticket_form';
|
21 |
protected $_infoBlockType = 'mercadopago/customticket_info';
|
22 |
|
45 |
|
46 |
public function assignData($data)
|
47 |
{
|
|
|
48 |
// route /checkout/onepage/savePayment
|
49 |
if (!($data instanceof Varien_Object)) {
|
50 |
$data = new Varien_Object($data);
|
51 |
}
|
52 |
|
53 |
+
$infoForm = $data->getData();
|
54 |
+
$infoForm = $infoForm['mercadopago_customticket'];
|
|
|
55 |
|
56 |
+
Mage::helper('mercadopago')->log("info form", 'mercadopago-custom.log', $infoForm);
|
57 |
|
58 |
$info = $this->getInfoInstance();
|
59 |
+
$info->setAdditionalInformation('payment_method', $infoForm['payment_method_ticket']);
|
60 |
|
61 |
+
if (isset($infoForm['coupon_code'])) {
|
62 |
+
$info->setAdditionalInformation('coupon_code', $infoForm['coupon_code']);
|
63 |
}
|
64 |
|
65 |
return $this;
|
70 |
Mage::helper('mercadopago')->log("Ticket -> init prepare post payment", 'mercadopago-custom.log');
|
71 |
$core = Mage::getModel('mercadopago/core');
|
72 |
$quote = $this->_getQuote();
|
73 |
+
$orderId = $quote->getReservedOrderId();
|
74 |
+
$order = $this->_getOrder($orderId);
|
75 |
|
|
|
76 |
$payment = $order->getPayment();
|
77 |
|
78 |
+
$paymentInfo = [];
|
79 |
|
|
|
80 |
if ($payment->getAdditionalInformation("coupon_code") != "") {
|
81 |
+
$paymentInfo['coupon_code'] = $payment->getAdditionalInformation("coupon_code");
|
82 |
}
|
83 |
|
84 |
+
$preference = $core->makeDefaultPreferencePaymentV1($paymentInfo);
|
|
|
85 |
|
|
|
86 |
$preference['payment_method_id'] = $payment->getAdditionalInformation("payment_method");
|
87 |
|
88 |
Mage::helper('mercadopago')->log("Ticket -> PREFERENCE to POST /v1/payments", 'mercadopago-custom.log', $preference);
|
94 |
|
95 |
public function getOrderPlaceRedirectUrl()
|
96 |
{
|
97 |
+
return Mage::getUrl('mercadopago/success', ['_secure' => true]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
}
|
99 |
|
|
|
100 |
}
|
app/code/community/MercadoPago/Core/Model/Discount/Coupon.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Discount/Coupon/Creditmemo.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Discount/Coupon/Invoice.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Observer.php
CHANGED
@@ -45,6 +45,7 @@ class MercadoPago_Core_Model_Observer
|
|
45 |
|
46 |
private $available_transparent_credit_cart = ['mla', 'mlb', 'mlm', 'mco', 'mlv', 'mlc'];
|
47 |
private $available_transparent_ticket = ['mla', 'mlb', 'mlm'];
|
|
|
48 |
|
49 |
const LOG_FILE = 'mercadopago.log';
|
50 |
|
@@ -55,6 +56,9 @@ class MercadoPago_Core_Model_Observer
|
|
55 |
*/
|
56 |
public function checkAndValidData($observer)
|
57 |
{
|
|
|
|
|
|
|
58 |
$this->validateAccessToken();
|
59 |
|
60 |
$this->validateClientCredentials();
|
@@ -71,41 +75,42 @@ class MercadoPago_Core_Model_Observer
|
|
71 |
|
72 |
public function availableCheckout()
|
73 |
{
|
74 |
-
//
|
|
|
75 |
|
76 |
-
$country =
|
77 |
|
78 |
if (!in_array($country, $this->available_transparent_credit_cart)) {
|
79 |
-
Mage::getConfig()->saveConfig('payment/mercadopago_custom/active', 0
|
80 |
}
|
81 |
|
82 |
if (!in_array($country, $this->available_transparent_ticket)) {
|
83 |
-
Mage::getConfig()->saveConfig('payment/mercadopago_customticket/active', 0
|
84 |
}
|
85 |
}
|
86 |
|
87 |
-
public function checkBanner($
|
88 |
{
|
89 |
//get country
|
90 |
-
$country =
|
91 |
-
if (!isset($this->banners[$
|
92 |
return;
|
93 |
}
|
94 |
-
$
|
95 |
|
96 |
-
$
|
97 |
|
98 |
-
Mage::helper('mercadopago')->log("Type Checkout Path: " . $
|
99 |
-
Mage::helper('mercadopago')->log("Current Banner: " . $
|
100 |
-
Mage::helper('mercadopago')->log("Default Banner: " . $
|
101 |
|
102 |
-
if (in_array($
|
103 |
Mage::helper('mercadopago')->log("Banner default need update...", self::LOG_FILE);
|
104 |
|
105 |
-
if ($
|
106 |
-
Mage::getConfig()->saveConfig('payment/' . $
|
107 |
|
108 |
-
Mage::helper('mercadopago')->log('payment/' . $
|
109 |
}
|
110 |
}
|
111 |
}
|
@@ -113,15 +118,15 @@ class MercadoPago_Core_Model_Observer
|
|
113 |
|
114 |
public function setSponsor()
|
115 |
{
|
116 |
-
Mage::helper('mercadopago')->log("Sponsor_id: " .
|
117 |
|
118 |
-
$
|
119 |
Mage::helper('mercadopago')->log("Valid user test", self::LOG_FILE);
|
120 |
|
121 |
-
$
|
122 |
-
Mage::helper('mercadopago')->log("Get access_token: " . $
|
123 |
|
124 |
-
$mp = Mage::helper('mercadopago')->getApiInstance($
|
125 |
$user = $mp->get("/users/me");
|
126 |
Mage::helper('mercadopago')->log("API Users response", self::LOG_FILE, $user);
|
127 |
|
@@ -129,38 +134,38 @@ class MercadoPago_Core_Model_Observer
|
|
129 |
|
130 |
switch ($user['response']['site_id']) {
|
131 |
case 'MLA':
|
132 |
-
$
|
133 |
break;
|
134 |
case 'MLB':
|
135 |
-
$
|
136 |
break;
|
137 |
case 'MLM':
|
138 |
-
$
|
139 |
break;
|
140 |
case 'MCO':
|
141 |
-
$
|
142 |
break;
|
143 |
case 'MLC':
|
144 |
-
$
|
145 |
break;
|
146 |
case 'MLV':
|
147 |
-
$
|
148 |
break;
|
149 |
default:
|
150 |
-
$
|
151 |
break;
|
152 |
}
|
153 |
|
154 |
-
Mage::helper('mercadopago')->log("Sponsor id setted", self::LOG_FILE, $
|
155 |
}
|
156 |
|
157 |
-
Mage::getConfig()->saveConfig('payment/mercadopago/sponsor_id', $
|
158 |
-
Mage::helper('mercadopago')->log("Sponsor saved", self::LOG_FILE, $
|
159 |
}
|
160 |
|
161 |
protected function validateAccessToken()
|
162 |
{
|
163 |
-
$accessToken =
|
164 |
if (!empty($accessToken)) {
|
165 |
if (!Mage::helper('mercadopago')->isValidAccessToken($accessToken)) {
|
166 |
Mage::throwException(Mage::helper('mercadopago')->__('Mercado Pago - Custom Checkout: Invalid access token'));
|
@@ -170,8 +175,8 @@ class MercadoPago_Core_Model_Observer
|
|
170 |
|
171 |
protected function validateClientCredentials()
|
172 |
{
|
173 |
-
$clientId =
|
174 |
-
$clientSecret =
|
175 |
if (!empty($clientId) && !empty($clientSecret)) {
|
176 |
if (!Mage::helper('mercadopago')->isValidClientCredentials($clientId, $clientSecret)) {
|
177 |
Mage::throwException(Mage::helper('mercadopago')->__('Mercado Pago - Classic Checkout: Invalid client id or client secret'));
|
45 |
|
46 |
private $available_transparent_credit_cart = ['mla', 'mlb', 'mlm', 'mco', 'mlv', 'mlc'];
|
47 |
private $available_transparent_ticket = ['mla', 'mlb', 'mlm'];
|
48 |
+
private $_website;
|
49 |
|
50 |
const LOG_FILE = 'mercadopago.log';
|
51 |
|
56 |
*/
|
57 |
public function checkAndValidData($observer)
|
58 |
{
|
59 |
+
|
60 |
+
$this->_website = Mage::helper('mercadopago')->getAdminSelectedWebsite();
|
61 |
+
|
62 |
$this->validateAccessToken();
|
63 |
|
64 |
$this->validateClientCredentials();
|
75 |
|
76 |
public function availableCheckout()
|
77 |
{
|
78 |
+
//check if country is available for transparent checkout
|
79 |
+
//and disables method if it is not
|
80 |
|
81 |
+
$country = $this->_website->getConfig('payment/mercadopago/country');
|
82 |
|
83 |
if (!in_array($country, $this->available_transparent_credit_cart)) {
|
84 |
+
Mage::getConfig()->saveConfig('payment/mercadopago_custom/active', 0, 'websites', $this->_website->getId());
|
85 |
}
|
86 |
|
87 |
if (!in_array($country, $this->available_transparent_ticket)) {
|
88 |
+
Mage::getConfig()->saveConfig('payment/mercadopago_customticket/active', 0, 'websites', $this->_website->getId());
|
89 |
}
|
90 |
}
|
91 |
|
92 |
+
public function checkBanner($typeCheckout)
|
93 |
{
|
94 |
//get country
|
95 |
+
$country = $this->_website->getConfig('payment/mercadopago/country');
|
96 |
+
if (!isset($this->banners[$typeCheckout][$country])) {
|
97 |
return;
|
98 |
}
|
99 |
+
$defaultBanner = $this->banners[$typeCheckout][$country];
|
100 |
|
101 |
+
$currentBanner = $this->_website->getConfig('payment/' . $typeCheckout . '/banner_checkout');
|
102 |
|
103 |
+
Mage::helper('mercadopago')->log("Type Checkout Path: " . $typeCheckout, self::LOG_FILE);
|
104 |
+
Mage::helper('mercadopago')->log("Current Banner: " . $currentBanner, self::LOG_FILE);
|
105 |
+
Mage::helper('mercadopago')->log("Default Banner: " . $defaultBanner, self::LOG_FILE);
|
106 |
|
107 |
+
if (in_array($currentBanner, $this->banners[$typeCheckout])) {
|
108 |
Mage::helper('mercadopago')->log("Banner default need update...", self::LOG_FILE);
|
109 |
|
110 |
+
if ($defaultBanner != $currentBanner) {
|
111 |
+
Mage::getConfig()->saveConfig('payment/' . $typeCheckout . '/banner_checkout', $defaultBanner, 'websites', $this->_website->getId());
|
112 |
|
113 |
+
Mage::helper('mercadopago')->log('payment/' . $typeCheckout . '/banner_checkout setted ' . $defaultBanner, self::LOG_FILE);
|
114 |
}
|
115 |
}
|
116 |
}
|
118 |
|
119 |
public function setSponsor()
|
120 |
{
|
121 |
+
Mage::helper('mercadopago')->log("Sponsor_id: " . $this->_website->getConfig('payment/mercadopago/sponsor_id'), self::LOG_FILE);
|
122 |
|
123 |
+
$sponsorId = "";
|
124 |
Mage::helper('mercadopago')->log("Valid user test", self::LOG_FILE);
|
125 |
|
126 |
+
$accessToken = $this->_website->getConfig(MercadoPago_Core_Helper_Data::XML_PATH_ACCESS_TOKEN);
|
127 |
+
Mage::helper('mercadopago')->log("Get access_token: " . $accessToken, self::LOG_FILE);
|
128 |
|
129 |
+
$mp = Mage::helper('mercadopago')->getApiInstance($accessToken);
|
130 |
$user = $mp->get("/users/me");
|
131 |
Mage::helper('mercadopago')->log("API Users response", self::LOG_FILE, $user);
|
132 |
|
134 |
|
135 |
switch ($user['response']['site_id']) {
|
136 |
case 'MLA':
|
137 |
+
$sponsorId = 186172525;
|
138 |
break;
|
139 |
case 'MLB':
|
140 |
+
$sponsorId = 186175129;
|
141 |
break;
|
142 |
case 'MLM':
|
143 |
+
$sponsorId = 186175064;
|
144 |
break;
|
145 |
case 'MCO':
|
146 |
+
$sponsorId = 206959966;
|
147 |
break;
|
148 |
case 'MLC':
|
149 |
+
$sponsorId = 206959756;
|
150 |
break;
|
151 |
case 'MLV':
|
152 |
+
$sponsorId = 206960619;
|
153 |
break;
|
154 |
default:
|
155 |
+
$sponsorId = "";
|
156 |
break;
|
157 |
}
|
158 |
|
159 |
+
Mage::helper('mercadopago')->log("Sponsor id setted", self::LOG_FILE, $sponsorId);
|
160 |
}
|
161 |
|
162 |
+
Mage::getConfig()->saveConfig('payment/mercadopago/sponsor_id', $sponsorId, $this->_website->getId());
|
163 |
+
Mage::helper('mercadopago')->log("Sponsor saved", self::LOG_FILE, $sponsorId);
|
164 |
}
|
165 |
|
166 |
protected function validateAccessToken()
|
167 |
{
|
168 |
+
$accessToken = $this->_website->getConfig(MercadoPago_Core_Helper_Data::XML_PATH_ACCESS_TOKEN);
|
169 |
if (!empty($accessToken)) {
|
170 |
if (!Mage::helper('mercadopago')->isValidAccessToken($accessToken)) {
|
171 |
Mage::throwException(Mage::helper('mercadopago')->__('Mercado Pago - Custom Checkout: Invalid access token'));
|
175 |
|
176 |
protected function validateClientCredentials()
|
177 |
{
|
178 |
+
$clientId = $this->_website->getConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_ID);
|
179 |
+
$clientSecret = $this->_website->getConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_SECRET);
|
180 |
if (!empty($clientId) && !empty($clientSecret)) {
|
181 |
if (!Mage::helper('mercadopago')->isValidClientCredentials($clientId, $clientSecret)) {
|
182 |
Mage::throwException(Mage::helper('mercadopago')->__('Mercado Pago - Classic Checkout: Invalid client id or client secret'));
|
app/code/community/MercadoPago/Core/Model/Source/CategoryId.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Source/Country.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Source/Installments.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Source/Order/Status.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Source/PaymentMethods.php
CHANGED
@@ -24,12 +24,14 @@ class MercadoPago_Core_Model_Source_PaymentMethods
|
|
24 |
$methods = array();
|
25 |
$helper = Mage::helper('mercadopago');
|
26 |
|
27 |
-
//
|
28 |
-
$methods[] =
|
29 |
|
30 |
-
$
|
31 |
-
|
32 |
-
$
|
|
|
|
|
33 |
if (empty($accessToken) && !$helper->isValidClientCredentials($clientId, $clientSecret)) {
|
34 |
return $methods;
|
35 |
}
|
@@ -39,9 +41,9 @@ class MercadoPago_Core_Model_Source_PaymentMethods
|
|
39 |
$accessToken = $helper->getAccessToken();
|
40 |
}
|
41 |
|
42 |
-
$helper->log
|
43 |
-
$helper->log
|
44 |
-
$response = MercadoPago_Lib_RestClient::get
|
45 |
|
46 |
$helper->log("API payment methods", 'mercadopago.log', $response);
|
47 |
|
24 |
$methods = array();
|
25 |
$helper = Mage::helper('mercadopago');
|
26 |
|
27 |
+
//empty value, to include all methods
|
28 |
+
$methods[] = ['value' => '', 'label' => ''];
|
29 |
|
30 |
+
$website = $helper->getAdminSelectedWebsite();
|
31 |
+
|
32 |
+
$accessToken = $website->getConfig(self::XML_PATH_ACCESS_TOKEN);
|
33 |
+
$clientId = $website->getConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_ID);
|
34 |
+
$clientSecret = $website->getConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_SECRET);
|
35 |
if (empty($accessToken) && !$helper->isValidClientCredentials($clientId, $clientSecret)) {
|
36 |
return $methods;
|
37 |
}
|
41 |
$accessToken = $helper->getAccessToken();
|
42 |
}
|
43 |
|
44 |
+
$helper->log('Get payment methods by country... ', 'mercadopago.log');
|
45 |
+
$helper->log('API payment methods: ' . '/v1/payment_methods?access_token=' . $accessToken, 'mercadopago.log');
|
46 |
+
$response = MercadoPago_Lib_RestClient::get('/sites/'. strtoupper($website->getConfig('payment/mercadopago/country')) .'/payment_methods?marketplace=NONE');
|
47 |
|
48 |
$helper->log("API payment methods", 'mercadopago.log', $response);
|
49 |
|
app/code/community/MercadoPago/Core/Model/Source/TypeCheckout.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/Model/Standard/Payment.php
CHANGED
@@ -38,21 +38,19 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
38 |
|
39 |
public function postPago()
|
40 |
{
|
41 |
-
//
|
42 |
$client_id = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_ID);
|
43 |
$client_secret = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_SECRET);
|
44 |
$mp = Mage::helper('mercadopago')->getApiInstance($client_id, $client_secret);
|
45 |
|
46 |
-
//
|
47 |
$pref = $this->makePreference();
|
48 |
Mage::helper('mercadopago')->log("make array", self::LOG_FILE, $pref);
|
49 |
|
50 |
-
//
|
51 |
$response = $mp->create_preference($pref);
|
52 |
Mage::helper('mercadopago')->log("create preference result", self::LOG_FILE, $response);
|
53 |
|
54 |
-
$array_assign = [];
|
55 |
-
|
56 |
if ($response['status'] == 200 || $response['status'] == 201) {
|
57 |
$payment = $response['response'];
|
58 |
if (Mage::getStoreConfigFlag('payment/mercadopago_standard/sandbox_mode')) {
|
@@ -61,7 +59,7 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
61 |
$init_point = $payment['init_point'];
|
62 |
}
|
63 |
|
64 |
-
$
|
65 |
"init_point" => $init_point,
|
66 |
"type_checkout" => $this->getConfigData('type_checkout'),
|
67 |
"iframe_width" => $this->getConfigData('iframe_width'),
|
@@ -72,7 +70,7 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
72 |
|
73 |
Mage::helper('mercadopago')->log("Array preference ok", self::LOG_FILE);
|
74 |
} else {
|
75 |
-
$
|
76 |
"message" => Mage::helper('mercadopago')->__('An error has occurred. Please refresh the page.'),
|
77 |
"json" => json_encode($response),
|
78 |
"status" => 400
|
@@ -81,12 +79,11 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
81 |
Mage::helper('mercadopago')->log("Array preference error", self::LOG_FILE);
|
82 |
}
|
83 |
|
84 |
-
return $
|
85 |
}
|
86 |
|
87 |
public function getOrderPlaceRedirectUrl()
|
88 |
{
|
89 |
-
// requisicao vem da pagina de finalizacao de pedido
|
90 |
return Mage::getUrl('mercadopago/pay', ['_secure' => true]);
|
91 |
}
|
92 |
|
@@ -136,10 +133,10 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
136 |
protected function getExcludedPaymentsMethods()
|
137 |
{
|
138 |
$excludedMethods = [];
|
139 |
-
$
|
140 |
-
$
|
141 |
-
if (count($
|
142 |
-
foreach ($
|
143 |
$excludedMethods[] = ["id" => $m];
|
144 |
}
|
145 |
}
|
@@ -164,37 +161,37 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
164 |
|
165 |
$this->_calculateDiscountAmount($arr['items'], $order);
|
166 |
$this->_calculateBaseTaxAmount($arr['items'], $order);
|
167 |
-
$
|
168 |
-
$
|
169 |
-
$
|
170 |
-
if (!$
|
171 |
-
$
|
172 |
}
|
173 |
-
if ($
|
174 |
-
$
|
175 |
$arr['items'][] = [
|
176 |
"title" => "Difference amount of the items with a total",
|
177 |
"description" => "Difference amount of the items with a total",
|
178 |
"category_id" => Mage::getStoreConfig('payment/mercadopago/category_id'),
|
179 |
"quantity" => 1,
|
180 |
-
"unit_price" => (float)$
|
181 |
];
|
182 |
-
Mage::helper('mercadopago')->log("Total itens: " . $
|
183 |
-
Mage::helper('mercadopago')->log("Total order: " . $
|
184 |
-
Mage::helper('mercadopago')->log("Difference add itens: " . $
|
185 |
}
|
|
|
|
|
|
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
"area_code" => "-",
|
192 |
-
"number" => $shipping['telephone']
|
193 |
-
];
|
194 |
-
|
195 |
-
$arr['shipments'] = $this->_getParamShipment($paramsShipment,$order,$shippingAddress);
|
196 |
|
197 |
-
|
|
|
|
|
198 |
|
199 |
$arr['payer']['date_created'] = date('Y-m-d', $customer->getCreatedAtTimestamp()) . "T" . date('H:i:s', $customer->getCreatedAtTimestamp());
|
200 |
$arr['payer']['email'] = htmlentities($customer->getEmail());
|
@@ -209,14 +206,15 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
209 |
}
|
210 |
|
211 |
$arr['payer']['address'] = [
|
212 |
-
"zip_code" => $
|
213 |
-
"street_name" => $
|
214 |
"street_number" => ""
|
215 |
];
|
216 |
|
|
|
217 |
$arr['back_urls'] = [
|
218 |
-
"success" => Mage::getUrl
|
219 |
-
"pending" => Mage::getUrl
|
220 |
"failure" => Mage::getUrl('checkout/onepage/failure')
|
221 |
];
|
222 |
|
@@ -226,16 +224,16 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
226 |
$installments = $this->getConfigData('installments');
|
227 |
$arr['payment_methods']['installments'] = (int)$installments;
|
228 |
|
229 |
-
$
|
230 |
-
if ($
|
231 |
$arr['auto_return'] = "approved";
|
232 |
}
|
233 |
|
234 |
-
$
|
235 |
-
Mage::helper('mercadopago')->log("Sponsor_id", self::LOG_FILE, $
|
236 |
-
if (!empty($
|
237 |
-
Mage::helper('mercadopago')->log("Sponsor_id identificado", self::LOG_FILE, $
|
238 |
-
$arr['sponsor_id'] = (int)$
|
239 |
}
|
240 |
|
241 |
return $arr;
|
@@ -252,21 +250,17 @@ class MercadoPago_Core_Model_Standard_Payment
|
|
252 |
];
|
253 |
}
|
254 |
|
255 |
-
protected function _getParamShipment($params
|
256 |
$paramsShipment = $params->getValues();
|
257 |
if (empty($paramsShipment)) {
|
258 |
$paramsShipment = $params->getData();
|
259 |
$paramsShipment['cost'] = (float)$order->getBaseShippingAmount();
|
|
|
260 |
}
|
261 |
$paramsShipment['receiver_address'] = $this->getReceiverAddress($shippingAddress);
|
262 |
return $paramsShipment;
|
263 |
}
|
264 |
|
265 |
-
public function getSuccessBlockType()
|
266 |
-
{
|
267 |
-
return $this->_successBlockType;
|
268 |
-
}
|
269 |
-
|
270 |
/**
|
271 |
* Check whether payment method can be used
|
272 |
*
|
38 |
|
39 |
public function postPago()
|
40 |
{
|
41 |
+
//get mercadopago api instance
|
42 |
$client_id = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_ID);
|
43 |
$client_secret = Mage::getStoreConfig(MercadoPago_Core_Helper_Data::XML_PATH_CLIENT_SECRET);
|
44 |
$mp = Mage::helper('mercadopago')->getApiInstance($client_id, $client_secret);
|
45 |
|
46 |
+
//create preference
|
47 |
$pref = $this->makePreference();
|
48 |
Mage::helper('mercadopago')->log("make array", self::LOG_FILE, $pref);
|
49 |
|
50 |
+
//make payment request
|
51 |
$response = $mp->create_preference($pref);
|
52 |
Mage::helper('mercadopago')->log("create preference result", self::LOG_FILE, $response);
|
53 |
|
|
|
|
|
54 |
if ($response['status'] == 200 || $response['status'] == 201) {
|
55 |
$payment = $response['response'];
|
56 |
if (Mage::getStoreConfigFlag('payment/mercadopago_standard/sandbox_mode')) {
|
59 |
$init_point = $payment['init_point'];
|
60 |
}
|
61 |
|
62 |
+
$arrayAssign = [
|
63 |
"init_point" => $init_point,
|
64 |
"type_checkout" => $this->getConfigData('type_checkout'),
|
65 |
"iframe_width" => $this->getConfigData('iframe_width'),
|
70 |
|
71 |
Mage::helper('mercadopago')->log("Array preference ok", self::LOG_FILE);
|
72 |
} else {
|
73 |
+
$arrayAssign = [
|
74 |
"message" => Mage::helper('mercadopago')->__('An error has occurred. Please refresh the page.'),
|
75 |
"json" => json_encode($response),
|
76 |
"status" => 400
|
79 |
Mage::helper('mercadopago')->log("Array preference error", self::LOG_FILE);
|
80 |
}
|
81 |
|
82 |
+
return $arrayAssign;
|
83 |
}
|
84 |
|
85 |
public function getOrderPlaceRedirectUrl()
|
86 |
{
|
|
|
87 |
return Mage::getUrl('mercadopago/pay', ['_secure' => true]);
|
88 |
}
|
89 |
|
133 |
protected function getExcludedPaymentsMethods()
|
134 |
{
|
135 |
$excludedMethods = [];
|
136 |
+
$excludedPaymentMethods = $this->getConfigData('excluded_payment_methods');
|
137 |
+
$arrEpm = explode(",", $excludedPaymentMethods);
|
138 |
+
if (count($arrEpm) > 0) {
|
139 |
+
foreach ($arrEpm as $m) {
|
140 |
$excludedMethods[] = ["id" => $m];
|
141 |
}
|
142 |
}
|
161 |
|
162 |
$this->_calculateDiscountAmount($arr['items'], $order);
|
163 |
$this->_calculateBaseTaxAmount($arr['items'], $order);
|
164 |
+
$totalItem = $this->getTotalItems($arr['items']);
|
165 |
+
$totalItem += (float)$order->getBaseShippingAmount();
|
166 |
+
$orderAmount = (float)$order->getBaseGrandTotal();
|
167 |
+
if (!$orderAmount) {
|
168 |
+
$orderAmount = (float)$order->getBasePrice() + $order->getBaseShippingAmount();
|
169 |
}
|
170 |
+
if ($totalItem > $orderAmount || $totalItem < $orderAmount) {
|
171 |
+
$diffPrice = $orderAmount - $totalItem;
|
172 |
$arr['items'][] = [
|
173 |
"title" => "Difference amount of the items with a total",
|
174 |
"description" => "Difference amount of the items with a total",
|
175 |
"category_id" => Mage::getStoreConfig('payment/mercadopago/category_id'),
|
176 |
"quantity" => 1,
|
177 |
+
"unit_price" => (float)$diffPrice
|
178 |
];
|
179 |
+
Mage::helper('mercadopago')->log("Total itens: " . $totalItem, self::LOG_FILE);
|
180 |
+
Mage::helper('mercadopago')->log("Total order: " . $orderAmount, self::LOG_FILE);
|
181 |
+
Mage::helper('mercadopago')->log("Difference add itens: " . $diffPrice, self::LOG_FILE);
|
182 |
}
|
183 |
+
if ($order->canShip()) {
|
184 |
+
$shippingAddress = $order->getShippingAddress();
|
185 |
+
$shipping = $shippingAddress->getData();
|
186 |
|
187 |
+
$arr['payer']['phone'] = [
|
188 |
+
"area_code" => "-",
|
189 |
+
"number" => $shipping['telephone']
|
190 |
+
];
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
+
$arr['shipments'] = $this->_getParamShipment($paramsShipment, $order, $shippingAddress);
|
193 |
+
}
|
194 |
+
$billingAddress = $order->getBillingAddress()->getData();
|
195 |
|
196 |
$arr['payer']['date_created'] = date('Y-m-d', $customer->getCreatedAtTimestamp()) . "T" . date('H:i:s', $customer->getCreatedAtTimestamp());
|
197 |
$arr['payer']['email'] = htmlentities($customer->getEmail());
|
206 |
}
|
207 |
|
208 |
$arr['payer']['address'] = [
|
209 |
+
"zip_code" => $billingAddress['postcode'],
|
210 |
+
"street_name" => $billingAddress['street'] . " - " . $billingAddress['city'] . " - " . $billingAddress['country_id'],
|
211 |
"street_number" => ""
|
212 |
];
|
213 |
|
214 |
+
$url = 'mercadopago/success';
|
215 |
$arr['back_urls'] = [
|
216 |
+
"success" => Mage::getUrl($url),
|
217 |
+
"pending" => Mage::getUrl($url),
|
218 |
"failure" => Mage::getUrl('checkout/onepage/failure')
|
219 |
];
|
220 |
|
224 |
$installments = $this->getConfigData('installments');
|
225 |
$arr['payment_methods']['installments'] = (int)$installments;
|
226 |
|
227 |
+
$autoReturn = $this->getConfigData('auto_return');
|
228 |
+
if ($autoReturn == 1) {
|
229 |
$arr['auto_return'] = "approved";
|
230 |
}
|
231 |
|
232 |
+
$sponsorId = Mage::getStoreConfig('payment/mercadopago/sponsor_id');
|
233 |
+
Mage::helper('mercadopago')->log("Sponsor_id", self::LOG_FILE, $sponsorId);
|
234 |
+
if (!empty($sponsorId)) {
|
235 |
+
Mage::helper('mercadopago')->log("Sponsor_id identificado", self::LOG_FILE, $sponsorId);
|
236 |
+
$arr['sponsor_id'] = (int)$sponsorId;
|
237 |
}
|
238 |
|
239 |
return $arr;
|
250 |
];
|
251 |
}
|
252 |
|
253 |
+
protected function _getParamShipment($params, $order, $shippingAddress) {
|
254 |
$paramsShipment = $params->getValues();
|
255 |
if (empty($paramsShipment)) {
|
256 |
$paramsShipment = $params->getData();
|
257 |
$paramsShipment['cost'] = (float)$order->getBaseShippingAmount();
|
258 |
+
$paramsShipment['mode'] = 'custom';
|
259 |
}
|
260 |
$paramsShipment['receiver_address'] = $this->getReceiverAddress($shippingAddress);
|
261 |
return $paramsShipment;
|
262 |
}
|
263 |
|
|
|
|
|
|
|
|
|
|
|
264 |
/**
|
265 |
* Check whether payment method can be used
|
266 |
*
|
app/code/community/MercadoPago/Core/controllers/ApiController.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/controllers/NotificationsController.php
CHANGED
@@ -23,97 +23,193 @@ class MercadoPago_Core_NotificationsController
|
|
23 |
protected $_mpcartid = null;
|
24 |
protected $_sendemail = false;
|
25 |
protected $_hash = null;
|
|
|
|
|
26 |
|
27 |
const LOG_FILE = 'mercadopago-notification.log';
|
28 |
|
29 |
protected function _getDataPayments($merchantOrder)
|
30 |
{
|
31 |
-
$data = array();
|
32 |
$core = Mage::getModel('mercadopago/core');
|
|
|
33 |
foreach ($merchantOrder['payments'] as $payment) {
|
34 |
-
$
|
35 |
-
$payment = $response['response']['collection'];
|
36 |
-
$data = $this->formatArrayPayment($data, $payment);
|
37 |
}
|
38 |
|
39 |
return $data;
|
40 |
}
|
41 |
|
42 |
-
protected function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
{
|
44 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
$statuses = explode('|', $dataStatus);
|
46 |
foreach ($statuses as $status) {
|
47 |
$status = str_replace(' ', '', $status);
|
48 |
-
if ($
|
49 |
-
$
|
50 |
-
|
51 |
-
|
52 |
-
$status_final = false;
|
53 |
-
}
|
54 |
}
|
55 |
}
|
56 |
|
57 |
-
|
|
|
|
|
58 |
}
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
public function standardAction()
|
62 |
{
|
63 |
$request = $this->getRequest();
|
64 |
//notification received
|
65 |
-
Mage::helper('mercadopago
|
66 |
-
|
|
|
|
|
67 |
$core = Mage::getModel('mercadopago/core');
|
68 |
|
69 |
$id = $request->getParam('id');
|
70 |
$topic = $request->getParam('topic');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
if
|
73 |
$response = $core->getMerchantOrder($id);
|
74 |
-
|
75 |
-
if ($response
|
76 |
-
$
|
77 |
-
|
78 |
-
|
79 |
-
$data = $this->_getDataPayments($merchant_order);
|
80 |
-
$status_final = $this->getStatusFinal($data['status']);
|
81 |
-
$shipmentData = (isset($merchant_order['shipments'][0])) ? $merchant_order['shipments'][0] : [];
|
82 |
-
Mage::helper('mercadopago')->log("Update Order", self::LOG_FILE);
|
83 |
-
$core->updateOrder($data);
|
84 |
-
if(!empty($shipmentData)) {
|
85 |
-
Mage::dispatchEvent('mercadopago_standard_notification_before_set_status',
|
86 |
-
array('shipmentData' => $shipmentData,
|
87 |
-
'orderId' => $merchant_order['external_reference'])
|
88 |
-
);
|
89 |
-
}
|
90 |
-
if ($status_final != false) {
|
91 |
-
$data['status_final'] = $status_final;
|
92 |
-
Mage::helper('mercadopago')->log("Received Payment data", self::LOG_FILE, $data);
|
93 |
-
$setStatusResponse = $core->setStatusOrder($data);
|
94 |
-
$this->getResponse()->setBody($setStatusResponse['text']);
|
95 |
-
$this->getResponse()->setHttpResponseCode($setStatusResponse['code']);
|
96 |
-
} else {
|
97 |
-
$this->getResponse()->setBody("Status not final");
|
98 |
-
$this->getResponse()->setHttpResponseCode(MercadoPago_Core_Helper_Response::HTTP_OK);
|
99 |
-
}
|
100 |
-
|
101 |
-
Mage::dispatchEvent('mercadopago_standard_notification_received',
|
102 |
-
array('payment' => $data,
|
103 |
-
'merchant_order' => $merchant_order)
|
104 |
-
);
|
105 |
-
|
106 |
-
Mage::helper('mercadopago')->log("Http code", self::LOG_FILE, $this->getResponse()->getHttpResponseCode());
|
107 |
-
return;
|
108 |
-
}
|
109 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
} else {
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
}
|
115 |
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
}
|
118 |
|
119 |
public function customAction()
|
@@ -135,11 +231,13 @@ class MercadoPago_Core_NotificationsController
|
|
135 |
$payment = Mage::helper('mercadopago')->setPayerInfo($payment);
|
136 |
|
137 |
Mage::helper('mercadopago')->log("Update Order", self::LOG_FILE);
|
|
|
138 |
$core->updateOrder($payment);
|
139 |
$setStatusResponse = $core->setStatusOrder($payment);
|
140 |
$this->getResponse()->setBody($setStatusResponse['text']);
|
141 |
$this->getResponse()->setHttpResponseCode($setStatusResponse['code']);
|
142 |
Mage::helper('mercadopago')->log("Http code", self::LOG_FILE, $this->getResponse()->getHttpResponseCode());
|
|
|
143 |
return;
|
144 |
}
|
145 |
}
|
@@ -164,6 +262,7 @@ class MercadoPago_Core_NotificationsController
|
|
164 |
"coupon_amount",
|
165 |
"installments",
|
166 |
"shipping_cost",
|
|
|
167 |
);
|
168 |
|
169 |
foreach ($fields as $field) {
|
23 |
protected $_mpcartid = null;
|
24 |
protected $_sendemail = false;
|
25 |
protected $_hash = null;
|
26 |
+
protected $_finalStatus = ['rejected', 'cancelled', 'refunded', 'charge_back'];
|
27 |
+
protected $_notFinalStatus = ['authorized', 'process', 'in_mediation'];
|
28 |
|
29 |
const LOG_FILE = 'mercadopago-notification.log';
|
30 |
|
31 |
protected function _getDataPayments($merchantOrder)
|
32 |
{
|
|
|
33 |
$core = Mage::getModel('mercadopago/core');
|
34 |
+
$data = array();
|
35 |
foreach ($merchantOrder['payments'] as $payment) {
|
36 |
+
$data = $this->_getFormattedPaymentData($payment['id'], $core, $data);
|
|
|
|
|
37 |
}
|
38 |
|
39 |
return $data;
|
40 |
}
|
41 |
|
42 |
+
protected function _getFormattedPaymentData($paymentId, $core, $data = [])
|
43 |
+
{
|
44 |
+
$response = $core->getPayment($paymentId);
|
45 |
+
$payment = $response['response']['collection'];
|
46 |
+
|
47 |
+
return $this->formatArrayPayment($data, $payment);
|
48 |
+
}
|
49 |
+
|
50 |
+
protected function _dateCompare($a, $b)
|
51 |
+
{
|
52 |
+
$t1 = strtotime($a['value']);
|
53 |
+
$t2 = strtotime($b['value']);
|
54 |
+
|
55 |
+
return $t2 - $t1;
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* @param $payments
|
60 |
+
* @param $status
|
61 |
+
*
|
62 |
+
* @return int
|
63 |
+
*/
|
64 |
+
protected function _getLastPaymentIndex($payments, $status)
|
65 |
{
|
66 |
+
$dates = [];
|
67 |
+
foreach ($payments as $key => $payment) {
|
68 |
+
if (in_array($payment['status'], $status)) {
|
69 |
+
$dates[] = ['key' => $key, 'value' => $payment['last_modified']];
|
70 |
+
}
|
71 |
+
}
|
72 |
+
usort($dates, array(get_class($this), "_dateCompare"));
|
73 |
+
if ($dates) {
|
74 |
+
$lastModified = array_pop($dates);
|
75 |
+
|
76 |
+
return $lastModified['key'];
|
77 |
+
}
|
78 |
+
|
79 |
+
return 0;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Returns status that must be set to order, if a not final status exists
|
84 |
+
* then the last of this statuses is returned. Else the last of final statuses
|
85 |
+
* is returned
|
86 |
+
*
|
87 |
+
* @param $dataStatus
|
88 |
+
* @param $merchantOrder
|
89 |
+
*
|
90 |
+
* @return string
|
91 |
+
*/
|
92 |
+
protected function getStatusFinal($dataStatus, $merchantOrder)
|
93 |
+
{
|
94 |
+
if ($merchantOrder['total_amount'] == $merchantOrder['paid_amount']) {
|
95 |
+
return 'approved';
|
96 |
+
}
|
97 |
+
$payments = $merchantOrder['payments'];
|
98 |
$statuses = explode('|', $dataStatus);
|
99 |
foreach ($statuses as $status) {
|
100 |
$status = str_replace(' ', '', $status);
|
101 |
+
if (in_array($status, $this->_notFinalStatus)) {
|
102 |
+
$lastPaymentIndex = $this->_getLastPaymentIndex($payments, $this->_notFinalStatus);
|
103 |
+
|
104 |
+
return $payments[$lastPaymentIndex]['status'];
|
|
|
|
|
105 |
}
|
106 |
}
|
107 |
|
108 |
+
$lastPaymentIndex = $this->_getLastPaymentIndex($payments, $this->_finalStatus);
|
109 |
+
|
110 |
+
return $payments[$lastPaymentIndex]['status'];
|
111 |
}
|
112 |
|
113 |
+
protected function _responseLog($helper)
|
114 |
+
{
|
115 |
+
$helper->log("Http code", self::LOG_FILE, $this->getResponse()->getHttpResponseCode());
|
116 |
+
}
|
117 |
+
|
118 |
+
protected function _shipmentExists($shipmentData, $merchantOrder)
|
119 |
+
{
|
120 |
+
return (!empty($shipmentData) && !empty($merchantOrder));
|
121 |
+
}
|
122 |
+
|
123 |
+
protected function _getShipmentsArray($merchantOrder)
|
124 |
+
{
|
125 |
+
return (isset($merchantOrder['shipments'][0])) ? $merchantOrder['shipments'][0] : [];
|
126 |
+
}
|
127 |
+
|
128 |
+
protected function _isValidResponse($response)
|
129 |
+
{
|
130 |
+
return ($response['status'] == 200 || $response['status'] == 201);
|
131 |
+
}
|
132 |
+
|
133 |
+
protected function _emptyParams($p1, $p2)
|
134 |
+
{
|
135 |
+
return (empty($p1) || empty($p2));
|
136 |
+
}
|
137 |
|
138 |
public function standardAction()
|
139 |
{
|
140 |
$request = $this->getRequest();
|
141 |
//notification received
|
142 |
+
$helper = Mage::helper('mercadopago');
|
143 |
+
$shipmentData = '';
|
144 |
+
$merchantOrder = '';
|
145 |
+
$helper->log("Standard Received notification", self::LOG_FILE, $request->getParams());
|
146 |
$core = Mage::getModel('mercadopago/core');
|
147 |
|
148 |
$id = $request->getParam('id');
|
149 |
$topic = $request->getParam('topic');
|
150 |
+
if ($this->_emptyParams($id, $topic)) {
|
151 |
+
$helper->log("Merchant Order not found", self::LOG_FILE, $request->getParams());
|
152 |
+
$this->getResponse()->setBody("Merchant Order not found");
|
153 |
+
$this->getResponse()->setHttpResponseCode(MercadoPago_Core_Helper_Response::HTTP_NOT_FOUND);
|
154 |
+
|
155 |
+
return;
|
156 |
+
}
|
157 |
|
158 |
+
if ($topic == 'merchant_order') {
|
159 |
$response = $core->getMerchantOrder($id);
|
160 |
+
$helper->log("Return merchant_order", self::LOG_FILE, $response);
|
161 |
+
if (!$this->_isValidResponse($response)) {
|
162 |
+
$this->_responseLog($helper);
|
163 |
+
|
164 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
}
|
166 |
+
$merchantOrder = $response['response'];
|
167 |
+
if (count($merchantOrder['payments']) == 0) {
|
168 |
+
$this->_responseLog($helper);
|
169 |
+
|
170 |
+
return;
|
171 |
+
}
|
172 |
+
$data = $this->_getDataPayments($merchantOrder);
|
173 |
+
$statusFinal = $this->getStatusFinal($data['status'], $merchantOrder);
|
174 |
+
$shipmentData = $this->_getShipmentsArray($merchantOrder);
|
175 |
+
} elseif ($topic == 'payment') {
|
176 |
+
$data = $this->_getFormattedPaymentData($id, $core);
|
177 |
+
$statusFinal = $data['status'];
|
178 |
} else {
|
179 |
+
$this->_responseLog($helper);
|
180 |
+
|
181 |
+
return;
|
182 |
}
|
183 |
|
184 |
+
$helper->log("Update Order", self::LOG_FILE);
|
185 |
+
$helper->setStatusUpdated($data);
|
186 |
+
$core->updateOrder($data);
|
187 |
+
if ($this->_shipmentExists($shipmentData, $merchantOrder)) {
|
188 |
+
Mage::dispatchEvent('mercadopago_standard_notification_before_set_status',
|
189 |
+
array('shipmentData' => $shipmentData,
|
190 |
+
'orderId' => $merchantOrder['external_reference'])
|
191 |
+
);
|
192 |
+
}
|
193 |
+
if ($statusFinal != false) {
|
194 |
+
$data['status_final'] = $statusFinal;
|
195 |
+
$helper->log("Received Payment data", self::LOG_FILE, $data);
|
196 |
+
$setStatusResponse = $core->setStatusOrder($data);
|
197 |
+
$this->getResponse()->setBody($setStatusResponse['text']);
|
198 |
+
$this->getResponse()->setHttpResponseCode($setStatusResponse['code']);
|
199 |
+
} else {
|
200 |
+
$this->getResponse()->setBody("Status not final");
|
201 |
+
$this->getResponse()->setHttpResponseCode(MercadoPago_Core_Helper_Response::HTTP_OK);
|
202 |
+
}
|
203 |
+
|
204 |
+
if ($this->_shipmentExists($shipmentData, $merchantOrder)) {
|
205 |
+
Mage::dispatchEvent('mercadopago_standard_notification_received',
|
206 |
+
array('payment' => $data,
|
207 |
+
'merchant_order' => $merchantOrder)
|
208 |
+
);
|
209 |
+
}
|
210 |
+
|
211 |
+
|
212 |
+
$this->_responseLog($helper);
|
213 |
}
|
214 |
|
215 |
public function customAction()
|
231 |
$payment = Mage::helper('mercadopago')->setPayerInfo($payment);
|
232 |
|
233 |
Mage::helper('mercadopago')->log("Update Order", self::LOG_FILE);
|
234 |
+
Mage::helper('mercadopago')->setStatusUpdated($payment);
|
235 |
$core->updateOrder($payment);
|
236 |
$setStatusResponse = $core->setStatusOrder($payment);
|
237 |
$this->getResponse()->setBody($setStatusResponse['text']);
|
238 |
$this->getResponse()->setHttpResponseCode($setStatusResponse['code']);
|
239 |
Mage::helper('mercadopago')->log("Http code", self::LOG_FILE, $this->getResponse()->getHttpResponseCode());
|
240 |
+
|
241 |
return;
|
242 |
}
|
243 |
}
|
262 |
"coupon_amount",
|
263 |
"installments",
|
264 |
"shipping_cost",
|
265 |
+
"amount_refunded",
|
266 |
);
|
267 |
|
268 |
foreach ($fields as $field) {
|
app/code/community/MercadoPago/Core/controllers/PayController.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/controllers/SuccessController.php
CHANGED
@@ -25,13 +25,17 @@ class MercadoPago_Core_SuccessController
|
|
25 |
return $this->_order;
|
26 |
}
|
27 |
|
|
|
|
|
|
|
|
|
28 |
/**
|
29 |
* Send email of new order
|
30 |
*/
|
31 |
protected function sendNewOrderMail()
|
32 |
{
|
33 |
$order = $this->getOrder();
|
34 |
-
if ($order->getCanSendNewEmailFlag()) {
|
35 |
try {
|
36 |
$order->sendNewOrderEmail();
|
37 |
} catch (Exception $e) {
|
@@ -57,6 +61,11 @@ class MercadoPago_Core_SuccessController
|
|
57 |
public function indexAction()
|
58 |
{
|
59 |
$this->sendNewOrderMail();
|
|
|
|
|
|
|
|
|
|
|
60 |
$checkoutTypeHandle = $this->getCheckoutHandle();
|
61 |
$this->loadLayout(['default', $checkoutTypeHandle]);
|
62 |
|
25 |
return $this->_order;
|
26 |
}
|
27 |
|
28 |
+
protected function _getQuoteId() {
|
29 |
+
return Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastQuoteId();
|
30 |
+
}
|
31 |
+
|
32 |
/**
|
33 |
* Send email of new order
|
34 |
*/
|
35 |
protected function sendNewOrderMail()
|
36 |
{
|
37 |
$order = $this->getOrder();
|
38 |
+
if ($order->getCanSendNewEmailFlag() && !$order->getEmailSent()) {
|
39 |
try {
|
40 |
$order->sendNewOrderEmail();
|
41 |
} catch (Exception $e) {
|
61 |
public function indexAction()
|
62 |
{
|
63 |
$this->sendNewOrderMail();
|
64 |
+
if (!Mage::getStoreConfig('payment/mercadopago/use_successpage_mp')) {
|
65 |
+
Mage::getSingleton('checkout/type_onepage')->getCheckout()->setLastSuccessQuoteId($this->_getQuoteId());
|
66 |
+
$this->_redirect('checkout/onepage/success',$this->_request->getParams());
|
67 |
+
return;
|
68 |
+
}
|
69 |
$checkoutTypeHandle = $this->getCheckoutHandle();
|
70 |
$this->loadLayout(['default', $checkoutTypeHandle]);
|
71 |
|
app/code/community/MercadoPago/Core/etc/config.xml
CHANGED
@@ -18,7 +18,7 @@
|
|
18 |
<config>
|
19 |
<modules>
|
20 |
<MercadoPago_Core>
|
21 |
-
<version>2.
|
22 |
</MercadoPago_Core>
|
23 |
</modules>
|
24 |
|
@@ -154,9 +154,7 @@
|
|
154 |
</updates>
|
155 |
</layout>
|
156 |
</adminhtml>
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
<default>
|
161 |
<payment>
|
162 |
<mercadopago>
|
@@ -168,6 +166,7 @@
|
|
168 |
<order_status_rejected>pending</order_status_rejected>
|
169 |
<order_status_cancelled>pending</order_status_cancelled>
|
170 |
<order_status_chargeback>pending</order_status_chargeback>
|
|
|
171 |
<logs>0</logs>
|
172 |
<debug_mode>0</debug_mode>
|
173 |
</mercadopago>
|
18 |
<config>
|
19 |
<modules>
|
20 |
<MercadoPago_Core>
|
21 |
+
<version>2.2.0</version>
|
22 |
</MercadoPago_Core>
|
23 |
</modules>
|
24 |
|
154 |
</updates>
|
155 |
</layout>
|
156 |
</adminhtml>
|
157 |
+
|
|
|
|
|
158 |
<default>
|
159 |
<payment>
|
160 |
<mercadopago>
|
166 |
<order_status_rejected>pending</order_status_rejected>
|
167 |
<order_status_cancelled>pending</order_status_cancelled>
|
168 |
<order_status_chargeback>pending</order_status_chargeback>
|
169 |
+
<use_successpage_mp>1</use_successpage_mp>
|
170 |
<logs>0</logs>
|
171 |
<debug_mode>0</debug_mode>
|
172 |
</mercadopago>
|
app/code/community/MercadoPago/Core/etc/system.xml
CHANGED
@@ -116,6 +116,16 @@
|
|
116 |
<show_in_website>1</show_in_website>
|
117 |
<show_in_store>1</show_in_store>
|
118 |
</order_status_chargeback>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
<logs translate="label">
|
120 |
<label>Logs</label>
|
121 |
<frontend_type>select</frontend_type>
|
@@ -181,7 +191,7 @@
|
|
181 |
<show_in_store>1</show_in_store>
|
182 |
<sort_order>20</sort_order>
|
183 |
<fields>
|
184 |
-
<active translate="label">
|
185 |
<label>Enabled</label>
|
186 |
<frontend_type>select</frontend_type>
|
187 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
@@ -189,6 +199,12 @@
|
|
189 |
<show_in_default>1</show_in_default>
|
190 |
<show_in_website>1</show_in_website>
|
191 |
<show_in_store>0</show_in_store>
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
</active>
|
193 |
<title translate="label">
|
194 |
<label>Payment Title</label>
|
116 |
<show_in_website>1</show_in_website>
|
117 |
<show_in_store>1</show_in_store>
|
118 |
</order_status_chargeback>
|
119 |
+
<use_successpage_mp translate="label comment">
|
120 |
+
<label>Use Mercado Pago success page</label>
|
121 |
+
<frontend_type>select</frontend_type>
|
122 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
123 |
+
<sort_order>135</sort_order>
|
124 |
+
<show_in_default>1</show_in_default>
|
125 |
+
<show_in_website>1</show_in_website>
|
126 |
+
<show_in_store>0</show_in_store>
|
127 |
+
<comment>If set this config with NO, magento success page will be used</comment>
|
128 |
+
</use_successpage_mp>
|
129 |
<logs translate="label">
|
130 |
<label>Logs</label>
|
131 |
<frontend_type>select</frontend_type>
|
191 |
<show_in_store>1</show_in_store>
|
192 |
<sort_order>20</sort_order>
|
193 |
<fields>
|
194 |
+
<active translate="label comment">
|
195 |
<label>Enabled</label>
|
196 |
<frontend_type>select</frontend_type>
|
197 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
199 |
<show_in_default>1</show_in_default>
|
200 |
<show_in_website>1</show_in_website>
|
201 |
<show_in_store>0</show_in_store>
|
202 |
+
<comment>
|
203 |
+
<![CDATA[It is a requirement that you have a SSL certificate, and the payment form to be provided under an HTTPS page.
|
204 |
+
During the sandbox mode tests, you can operate over HTTP,
|
205 |
+
but for homologation you'll need to acquire the certificate in case you don't have it.
|
206 |
+
<a href="https://www.mercadopago.com.ar/developers/solutions/payments/custom-checkout/appliance-requirements/" target="_blank">Learn More</a>]]>
|
207 |
+
</comment>
|
208 |
</active>
|
209 |
<title translate="label">
|
210 |
<label>Payment Title</label>
|
app/code/community/MercadoPago/Core/sql/mercadopago_setup/install-2.1.0.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/sql/mercadopago_setup/upgrade-2.1.0-2.1.1.php
CHANGED
File without changes
|
app/code/community/MercadoPago/Core/sql/mercadopago_setup/upgrade-2.1.1-2.1.2.php
CHANGED
File without changes
|
app/code/community/MercadoPago/MercadoEnvios/Block/Adminhtml/System/Config/Fieldset/Carrier.php
CHANGED
File without changes
|
app/code/community/MercadoPago/MercadoEnvios/Block/Adminhtml/System/Config/Fieldset/Mapping.php
CHANGED
File without changes
|