Skip to content

Commit ff63741

Browse files
authored
Merge pull request SummaSolutions#67 from imasson/develop_release
Develop release
2 parents 6f3bc8b + f7633c1 commit ff63741

File tree

14 files changed

+100
-68
lines changed

14 files changed

+100
-68
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,25 @@ This feature allows to setup and integrate with MercadoEnvios shipment method as
4343

4444
*Available for Argentina, Brazil and Mexico only with Standard Checkout*
4545

46+
<a name="composer_installation"></a>
47+
## Installation using composer:
48+
49+
1. Add repository to your Magento installation composer.json file
50+
51+
- "repositories": [
52+
{
53+
"type": "vcs",
54+
"url": "https://github.com/mercadopago/cart-magento2"
55+
}
56+
]
57+
58+
2. Execute composer command to download plugin package
59+
60+
- composer require mercadopago/magento2-plugin
61+
62+
4663
<a name="installation"></a>
47-
## Installation:
64+
## Installation copying files:
4865

4966
1. Copy the folder **app/code/MercadoPago** to the Magento root installation. Make sure to keep the Magento folders structure intact.
5067

app/code/MercadoPago/Core/Helper/Data.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function log($message, $name = "mercadopago", $array = null)
162162
/**
163163
* Return MercadoPago Api instance given AccessToken or ClientId and Secret
164164
*
165-
* @return \MercadoPago_Core_Lib_Api
165+
* @return \MercadoPago\Core\Lib\Api
166166
* @throws \Magento\Framework\Exception\LocalizedException
167167
*/
168168
public function getApiInstance()
@@ -172,10 +172,10 @@ public function getApiInstance()
172172
throw new \Magento\Framework\Exception\LocalizedException("Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN");
173173
}
174174
if ($params == 1) {
175-
$api = new \MercadoPago_Core_Lib_Api(func_get_arg(0));
175+
$api = new \MercadoPago\Core\Lib\Api(func_get_arg(0));
176176
$api->set_platform(self::PLATFORM_OPENPLATFORM);
177177
} else {
178-
$api = new \MercadoPago_Core_Lib_Api(func_get_arg(0), func_get_arg(1));
178+
$api = new \MercadoPago\Core\Lib\Api(func_get_arg(0), func_get_arg(1));
179179
$api->set_platform(self::PLATFORM_STD);
180180
}
181181
if ($this->scopeConfig->getValue('payment/mercadopago_standard/sandbox_mode')) {

app/code/MercadoPago/Core/Lib/Api.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
namespace MercadoPago\Core\Lib;
33
/**
44
* MercadoPago Integration Library
55
* Access MercadoPago for payments integration
@@ -9,7 +9,7 @@
99
*/
1010

1111

12-
class MercadoPago_Core_Lib_Api {
12+
class Api {
1313

1414
/**
1515
*
@@ -52,7 +52,7 @@ class MercadoPago_Core_Lib_Api {
5252

5353

5454
/**
55-
* MercadoPago_Core_Lib_Api constructor.
55+
* \MercadoPago\Core\Lib\Api constructor.
5656
*/
5757
public function __construct() {
5858
$i = func_num_args();
@@ -98,10 +98,10 @@ public function get_access_token() {
9898
'grant_type' => 'client_credentials'
9999
));
100100

101-
$access_data = MercadoPago_Core_Lib_RestClient::post("/oauth/token", $app_client_values, "application/x-www-form-urlencoded");
101+
$access_data = \MercadoPago\Core\Lib\RestClient::post("/oauth/token", $app_client_values, "application/x-www-form-urlencoded");
102102

103103
if ($access_data["status"] != 200) {
104-
throw new Exception ($access_data['response']['message'], $access_data['status']);
104+
throw new \Exception ($access_data['response']['message'], $access_data['status']);
105105
}
106106

107107
$this->access_data = $access_data['response'];
@@ -119,7 +119,7 @@ public function get_payment($id) {
119119

120120
$uri_prefix = $this->sandbox ? "/sandbox" : "";
121121

122-
$payment_info = MercadoPago_Core_Lib_RestClient::get($uri_prefix."/collections/notifications/" . $id . "?access_token=" . $access_token);
122+
$payment_info = \MercadoPago\Core\Lib\RestClient::get($uri_prefix."/collections/notifications/" . $id . "?access_token=" . $access_token);
123123
return $payment_info;
124124
}
125125

@@ -140,7 +140,7 @@ public function get_payment_info($id) {
140140
public function get_authorized_payment($id) {
141141
$access_token = $this->get_access_token();
142142

143-
$authorized_payment_info = MercadoPago_Core_Lib_RestClient::get("/authorized_payments/" . $id . "?access_token=" . $access_token);
143+
$authorized_payment_info = \MercadoPago\Core\Lib\RestClient::get("/authorized_payments/" . $id . "?access_token=" . $access_token);
144144
return $authorized_payment_info;
145145
}
146146

@@ -156,7 +156,7 @@ public function refund_payment($id) {
156156
"status" => "refunded"
157157
);
158158

159-
$response = MercadoPago_Core_Lib_RestClient::put("/collections/" . $id . "?access_token=" . $access_token, $refund_status);
159+
$response = \MercadoPago\Core\Lib\RestClient::put("/collections/" . $id . "?access_token=" . $access_token, $refund_status);
160160
return $response;
161161
}
162162

@@ -172,7 +172,7 @@ public function cancel_payment($id) {
172172
"status" => "cancelled"
173173
);
174174

175-
$response = MercadoPago_Core_Lib_RestClient::put("/collections/" . $id . "?access_token=" . $access_token, $cancel_status);
175+
$response = \MercadoPago\Core\Lib\RestClient::put("/collections/" . $id . "?access_token=" . $access_token, $cancel_status);
176176
return $response;
177177
}
178178

@@ -188,7 +188,7 @@ public function cancel_preapproval_payment($id) {
188188
"status" => "cancelled"
189189
);
190190

191-
$response = MercadoPago_Core_Lib_RestClient::put("/preapproval/" . $id . "?access_token=" . $access_token, $cancel_status);
191+
$response = \MercadoPago\Core\Lib\RestClient::put("/preapproval/" . $id . "?access_token=" . $access_token, $cancel_status);
192192
return $response;
193193
}
194194

@@ -209,7 +209,7 @@ public function search_payment($filters, $offset = 0, $limit = 0) {
209209

210210
$uri_prefix = $this->sandbox ? "/sandbox" : "";
211211

212-
$collection_result = MercadoPago_Core_Lib_RestClient::get($uri_prefix."/collections/search?" . $filters . "&access_token=" . $access_token);
212+
$collection_result = \MercadoPago\Core\Lib\RestClient::get($uri_prefix."/collections/search?" . $filters . "&access_token=" . $access_token);
213213
return $collection_result;
214214
}
215215

@@ -222,7 +222,7 @@ public function create_preference($preference) {
222222
$access_token = $this->get_access_token();
223223

224224
$extra_params = array('platform: ' . $this->_platform, 'so;', 'type: ' . $this->_type);
225-
$preference_result = MercadoPago_Core_Lib_RestClient::post("/checkout/preferences?access_token=" . $access_token, $preference, "application/json", $extra_params);
225+
$preference_result = \MercadoPago\Core\Lib\RestClient::post("/checkout/preferences?access_token=" . $access_token, $preference, "application/json", $extra_params);
226226
return $preference_result;
227227
}
228228

@@ -235,7 +235,7 @@ public function create_preference($preference) {
235235
public function update_preference($id, $preference) {
236236
$access_token = $this->get_access_token();
237237

238-
$preference_result = MercadoPago_Core_Lib_RestClient::put("/checkout/preferences/{$id}?access_token=" . $access_token, $preference);
238+
$preference_result = \MercadoPago\Core\Lib\RestClient::put("/checkout/preferences/{$id}?access_token=" . $access_token, $preference);
239239
return $preference_result;
240240
}
241241

@@ -247,7 +247,7 @@ public function update_preference($id, $preference) {
247247
public function get_preference($id) {
248248
$access_token = $this->get_access_token();
249249

250-
$preference_result = MercadoPago_Core_Lib_RestClient::get("/checkout/preferences/{$id}?access_token=" . $access_token);
250+
$preference_result = \MercadoPago\Core\Lib\RestClient::get("/checkout/preferences/{$id}?access_token=" . $access_token);
251251
return $preference_result;
252252
}
253253

@@ -259,7 +259,7 @@ public function get_preference($id) {
259259
public function create_preapproval_payment($preapproval_payment) {
260260
$access_token = $this->get_access_token();
261261

262-
$preapproval_payment_result = MercadoPago_Core_Lib_RestClient::post("/preapproval?access_token=" . $access_token, $preapproval_payment);
262+
$preapproval_payment_result = \MercadoPago\Core\Lib\RestClient::post("/preapproval?access_token=" . $access_token, $preapproval_payment);
263263
return $preapproval_payment_result;
264264
}
265265

@@ -271,7 +271,7 @@ public function create_preapproval_payment($preapproval_payment) {
271271
public function get_preapproval_payment($id) {
272272
$access_token = $this->get_access_token();
273273

274-
$preapproval_payment_result = MercadoPago_Core_Lib_RestClient::get("/preapproval/{$id}?access_token=" . $access_token);
274+
$preapproval_payment_result = \MercadoPago\Core\Lib\RestClient::get("/preapproval/{$id}?access_token=" . $access_token);
275275
return $preapproval_payment_result;
276276
}
277277

@@ -284,7 +284,7 @@ public function get_preapproval_payment($id) {
284284
public function update_preapproval_payment($id, $preapproval_payment) {
285285
$access_token = $this->get_access_token();
286286

287-
$preapproval_payment_result = MercadoPago_Core_Lib_RestClient::put("/preapproval/" . $id . "?access_token=" . $access_token, $preapproval_payment);
287+
$preapproval_payment_result = \MercadoPago\Core\Lib\RestClient::put("/preapproval/" . $id . "?access_token=" . $access_token, $preapproval_payment);
288288
return $preapproval_payment_result;
289289
}
290290

@@ -296,7 +296,7 @@ public function update_preapproval_payment($id, $preapproval_payment) {
296296
public function create_custon_payment($info) {
297297
$access_token = $this->get_access_token();
298298

299-
$preference_result = MercadoPago_Core_Lib_RestClient::post("/checkout/custom/create_payment?access_token=" . $access_token, $info);
299+
$preference_result = \MercadoPago\Core\Lib\RestClient::post("/checkout/custom/create_payment?access_token=" . $access_token, $info);
300300
return $preference_result;
301301
}
302302

@@ -322,7 +322,7 @@ public function get($uri, $params = null, $authenticate = true) {
322322
$uri .= $this->build_query($params);
323323
}
324324

325-
$result = MercadoPago_Core_Lib_RestClient::get($uri);
325+
$result = \MercadoPago\Core\Lib\RestClient::get($uri);
326326
return $result;
327327
}
328328

@@ -344,7 +344,7 @@ public function post($uri, $data, $params = null) {
344344
}
345345

346346
$extra_params = array('platform: ' . $this->_platform, 'so;', 'type: ' . $this->_type);
347-
$result = MercadoPago_Core_Lib_RestClient::post($uri, $data, "application/json", $extra_params);
347+
$result = \MercadoPago\Core\Lib\RestClient::post($uri, $data, "application/json", $extra_params);
348348
return $result;
349349
}
350350

@@ -365,7 +365,7 @@ public function put($uri, $data, $params = null) {
365365
$uri .= $this->build_query($params);
366366
}
367367

368-
$result = MercadoPago_Core_Lib_RestClient::put($uri, $data);
368+
$result = \MercadoPago\Core\Lib\RestClient::put($uri, $data);
369369
return $result;
370370
}
371371

@@ -386,7 +386,7 @@ public function delete($uri, $params = null) {
386386
$uri .= $this->build_query($params);
387387
}
388388

389-
$result = MercadoPago_Core_Lib_RestClient::delete($uri);
389+
$result = \MercadoPago\Core\Lib\RestClient::delete($uri);
390390
return $result;
391391
}
392392

app/code/MercadoPago/Core/Lib/RestClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
2-
2+
namespace MercadoPago\Core\Lib;
33
/**
44
* MercadoPago cURL RestClient
55
*/
66

77

8-
class MercadoPago_Core_Lib_RestClient {
8+
class RestClient {
99

1010
/**
1111
*API URL

app/code/MercadoPago/Core/Model/System/Config/Source/Category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function toOptionArray()
3939
{
4040
$this->coreHelper->log("Get Categories... ", 'mercadopago');
4141

42-
$response = \MercadoPago_Core_Lib_RestClient::get("/item_categories");
42+
$response = \MercadoPago\Core\Lib\RestClient::get("/item_categories");
4343
$this->coreHelper->log("API item_categories", 'mercadopago', $response);
4444

4545
$response = $response['response'];

app/code/MercadoPago/Core/Model/System/Config/Source/PaymentMethods.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function toOptionArray()
8686

8787
$meHelper->log("Get payment methods by country... ", 'mercadopago');
8888
$meHelper->log("API payment methods: " . "/v1/payment_methods?access_token=" . $accessToken, 'mercadopago');
89-
$response = \MercadoPago_Core_Lib_RestClient::get('/sites/'. strtoupper($country) .'/payment_methods?marketplace=NONE');
89+
$response = \MercadoPago\Core\Lib\RestClient::get('/sites/'. strtoupper($country) .'/payment_methods?marketplace=NONE');
9090

9191
$meHelper->log("API payment methods", 'mercadopago', $response);
9292

app/code/MercadoPago/Core/Observer/RefundObserverBeforeSave.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function creditMemoRefundBeforeSave($order, $creditMemo)
8181
$orderStatus = $order->getData('status');
8282
$orderPaymentStatus = $order->getPayment()->getData('additional_information')['status'];
8383
$payment = $order->getPayment();
84-
$paymentID = $order->getPayment()->getData('additional_information')['id'];
84+
8585
$paymentMethod = $order->getPayment()->getMethodInstance()->getCode();
8686
$orderStatusHistory = $order->getAllStatusHistory();
8787
$isCreditCardPayment = ($order->getPayment()->getData('additional_information')['installments'] != null ? true : false);
@@ -105,7 +105,7 @@ protected function creditMemoRefundBeforeSave($order, $creditMemo)
105105
$order);
106106

107107
if ($isValidBasicData && $isValidaData) {
108-
$this->sendRefundRequest($order, $creditMemo, $paymentMethod, $isTotalRefund, $paymentID);
108+
$this->sendRefundRequest($order, $creditMemo, $paymentMethod, $isTotalRefund);
109109
}
110110
}
111111

@@ -124,6 +124,7 @@ protected function checkRefundBasicData($paymentMethod, $paymentDate)
124124

125125
if (!$refundAvailable) {
126126
$this->_messageManager->addNoticeMessage(__('Mercado Pago refunds are disabled. The refund will be made through Magento'));
127+
127128
return false;
128129
}
129130

@@ -135,6 +136,7 @@ protected function checkRefundBasicData($paymentMethod, $paymentDate)
135136

136137
if (!($paymentMethod == 'mercadopago_standard' || $paymentMethod == 'mercadopago_custom')) {
137138
$this->_messageManager->addErrorMessage(__('Order payment wasn\'t made by Mercado Pago. The refund will be made through Magento'));
139+
138140
return false;
139141
}
140142

@@ -205,14 +207,16 @@ protected function checkRefundData($isCreditCardPayment,
205207
*
206208
* @throws \Magento\Framework\Exception\LocalizedException
207209
*/
208-
protected function sendRefundRequest($order, $creditMemo, $paymentMethod, $isTotalRefund, $paymentID)
210+
protected function sendRefundRequest($order, $creditMemo, $paymentMethod, $isTotalRefund)
209211
{
210-
$access_token = $this->_scopeConfig->getValue(self::XML_PATH_ACCESS_TOKEN);
211-
$mp = $this->_dataHelper->getApiInstance($access_token);
212212
$response = null;
213213
$amount = $creditMemo->getGrandTotal();
214214

215215
if ($paymentMethod == 'mercadopago_standard') {
216+
$paymentID = $order->getPayment()->getData('additional_information')['id'];
217+
$clientId = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_CLIENT_ID);
218+
$clientSecret = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_CLIENT_SECRET);
219+
$mp = $this->_dataHelper->getApiInstance($clientId, $clientSecret);
216220
if ($isTotalRefund) {
217221
$response = $mp->refund_payment($paymentID);
218222
$order->setMercadoPagoRefundType('total');
@@ -226,16 +230,19 @@ protected function sendRefundRequest($order, $creditMemo, $paymentMethod, $isTot
226230
"amount" => $amount,
227231
"metadata" => $metadata,
228232
];
229-
$response = $mp->post("/collections/$paymentID/refunds?access_token=$access_token", $params);
233+
$response = $mp->post('/collections/' . $paymentID . '/refunds?access_token=' . $mp->get_access_token(), $params);
230234
}
231235
} else {
236+
$paymentID = $order->getPayment()->getData('additional_information')['payment_method_id'];
237+
$accessToken = $this->_scopeConfig->getValue(self::XML_PATH_ACCESS_TOKEN);
238+
$mp = $this->_dataHelper->getApiInstance($accessToken, $accessToken);
232239
if ($isTotalRefund) {
233-
$response = $mp->post("/v1/payments/$paymentID/refunds?access_token=$access_token", null);
240+
$response = $mp->post("/v1/payments/$paymentID/refunds?access_token=$accessToken", null);
234241
} else {
235242
$params = [
236243
"amount" => $amount,
237244
];
238-
$response = $mp->post("/v1/payments/$paymentID/refunds?access_token=$access_token", $params);
245+
$response = $mp->post("/v1/payments/$paymentID/refunds?access_token=$accessToken", $params);
239246
}
240247
}
241248

app/code/MercadoPago/Core/Plugin/OrderCancelPlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,15 @@ protected function salesOrderBeforeCancel()
7676
$clientId = $this->dataHelper->getClientId();
7777
$clientSecret = $this->dataHelper->getClientSecret();
7878

79-
$mp = $this->dataHelper->getApiInstance($clientId, $clientSecret);
8079
$response = null;
8180

8281
$accessToken = $this->_scopeConfig->getValue(\MercadoPago\Core\Model\Core::XML_PATH_ACCESS_TOKEN);
8382

8483
if ($paymentMethod == 'mercadopago_standard') {
84+
$mp = $this->dataHelper->getApiInstance($clientId, $clientSecret);
8585
$response = $mp->cancel_payment($paymentID);
8686
} else {
87+
$mp = $this->dataHelper->getApiInstance($accessToken);
8788
$data = [
8889
"status" => 'cancelled',
8990
];

app/code/MercadoPago/Core/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="MercadoPago_Core" setup_version="1.1.0">
3+
<module name="MercadoPago_Core" setup_version="1.2.0">
44
<sequence>
55
<module name="Magento_Sales"/>
66
<module name="Magento_Payment"/>

app/code/MercadoPago/Core/view/frontend/web/css/style.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,17 @@
283283
max-width: 100%;
284284
max-height: 100%;
285285
}
286+
287+
.cft-info {
288+
color: #A0A0A0;
289+
font-weight: bold;
290+
font-size: 40px;
291+
padding: 5px;
292+
margin-bottom: 0px !important;
293+
}
294+
295+
.tea-info {
296+
color: #A0A0A0;
297+
padding: 5px;
298+
margin-bottom: -12px !important;
299+
}

0 commit comments

Comments
 (0)