Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
v3.13.0 (#182)
Browse files Browse the repository at this point in the history
* feat(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* added payment places method

* comments removed

* refactored access token validation

* fixed ternary if structure

* fixed instantiation of access token

* 🐛 Fix the PR cover checker when there is no test (#189)

This fixes an issue that is workflow failure when the pull request does not contain tests and Added hotfix branch filter to check tests

* feat(PPWP-421): paycash front-end

* feat(PPWP-422): paycash admin

* fix(helper): 🐛 fixed float to int convertion

* feat(bin): ✨ new command sync with container

* improv: init tests

* improv: changing chmod command

* build: 📦 new patch version of mercardo pago for magento 2 v3.12.3

* getMercadoPagoPaymentMethods testing

* fix(ppwp-337): fixing exception testing

* testing config provider and api

* testing PaymentMethodsTicket

* feat(ppwp-377): testing custom config provider

* refactored constants

* refactored model test classes

* refactored helper test classes

* added annotation for Code Coverage Ignore

* fixed test variables

* fixed html structure of ticket

* feat(ppwp-377): adding metadata payment_option_id

* fixing data tests

* removed exception to access token

* hotfix(PLUG-1533): fixing refund error handling

* fixing pr coverage checker

* testing pr coverage checker

* fixing pr coverage checker

* hotfix: fixed js - undefined variable

* build: 📦 new minor version of mercardo pago for magento 2 v3.13.0

* build(v3.13.0): 📦 updated readme

Co-authored-by: Gustavo Brito <[email protected]>
Co-authored-by: sleaof <[email protected]>
Co-authored-by: Douglas <[email protected]>
  • Loading branch information
4 people authored Dec 2, 2021
1 parent b34ce87 commit db61907
Show file tree
Hide file tree
Showing 32 changed files with 2,289 additions and 486 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.13.0] - 2021-12-01

### Added
- Support to Paycash payment in Mexico
- Faster local builds

### Fixed
- Fixed Bank Transfer JS call
- Fixed refund rule observer

## [3.12.3] - 2021-11-16

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ COPY src magento2/app/code
COPY phpunit.xml phpunit.xml

# Fix permissions
RUN chmod 777 -Rf magento2
RUN cd magento2 && find var vendor generated pub/static pub/media app/etc -type f -print0 | xargs -0 chmod u+w
RUN cd magento2 && find var vendor generated pub/static pub/media app/etc -type d -print0 | xargs -0 chmod u+w
RUN chmod u+x magento2/bin/magento
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</a>
</p>

# Magento 2 - Mercado Pago Module (v3.12.3)
# Magento 2 - Mercado Pago Module (v3.13.0)

The Mercado Pago plugin for Magento 2 allows you to expand the functionalities of your online store and offer a unique payment experience for your customers.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"type": "magento2-module",
"version": "3.12.3",
"version": "3.13.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
151 changes: 37 additions & 114 deletions src/MercadoPago/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use MercadoPago\Core\Lib\RestClient;
use MercadoPago\Core\Logger\Logger;
use MercadoPago\Core\Model\Custom\Payment;
use MercadoPago\Core\Helper\PaymentPlaces;

/**
* Class Data
Expand Down Expand Up @@ -89,6 +90,11 @@ class Data extends \Magento\Payment\Helper\Data
*/
protected $_moduleResource;

/**
* @var Api $api
*/
protected $_api;

/**
* Data constructor.
* @param Message\MessageInterface $messageInterface
Expand All @@ -105,6 +111,7 @@ class Data extends \Magento\Payment\Helper\Data
* @param Switcher $switcher
* @param ComposerInformation $composerInformation
* @param ResourceInterface $moduleResource
* @param Api $api
*/
public function __construct(
Message\MessageInterface $messageInterface,
Expand All @@ -120,7 +127,8 @@ public function __construct(
OrderFactory $orderFactory,
Switcher $switcher,
ComposerInformation $composerInformation,
ResourceInterface $moduleResource
ResourceInterface $moduleResource,
Api $api
) {
parent::__construct($context, $layoutFactory, $paymentMethodFactory, $appEmulation, $paymentConfig, $initialConfig);
$this->_messageInterface = $messageInterface;
Expand All @@ -131,6 +139,7 @@ public function __construct(
$this->_switcher = $switcher;
$this->_composerInformation = $composerInformation;
$this->_moduleResource = $moduleResource;
$this->_api = $api;
}

/**
Expand Down Expand Up @@ -173,7 +182,9 @@ public function getApiInstance($accessToken = null)
throw new LocalizedException(__('The ACCESS_TOKEN has not been configured, without this credential the module will not work correctly.'));
}

$api = new Api($accessToken);
//$api = new Api($accessToken);
$api = $this->_api;
$api->set_access_token($accessToken);
$api->set_platform(self::PLATFORM_OPENPLATFORM);

$api->set_type(self::TYPE);
Expand Down Expand Up @@ -201,31 +212,13 @@ public function isValidAccessToken($accessToken)
return true;
}

$mp = $this->getApiInstance($accessToken);
$isValid = $mp->is_valid_access_token();

$this->_mpCache->saveCache($cacheKey, $isValid);
return $isValid;
}
$response = $this->getMercadoPagoPaymentMethods($accessToken);

/**
* ClientId and Secret valid?
*
* @param $clientId
* @param $clientSecret
*
* @return bool
* @throws LocalizedException
*/
public function isValidClientCredentials($clientId, $clientSecret)
{
$mp = $this->getApiInstance($clientId, $clientSecret);
try {
$mp->get_access_token();
} catch (Exception $e) {
if ((!$response) || (isset($response['status']) && ($response['status'] == 401 || $response['status'] == 400))) {
return false;
}

$this->_mpCache->saveCache($cacheKey, true);
return true;
}

Expand Down Expand Up @@ -269,53 +262,6 @@ public function setOrderSubtotals($data, $order)
$order->save();
}

/**
* Modify payment array adding specific fields
*
* @param $payment
*
* @return mixed
* @refactor
*/
public function setPayerInfo(&$payment)
{
$this->log("setPayerInfo", 'mercadopago-custom.log', $payment);

if ($payment['payment_method_id']) {
$payment["payment_method"] = $payment['payment_method_id'];
}

if ($payment['installments']) {
$payment["installments"] = $payment['installments'];
}
if ($payment['id']) {
$payment["payment_id_detail"] = $payment['id'];
}
if (isset($payment['trunc_card'])) {
$payment["trunc_card"] = $payment['trunc_card'];
} elseif (isset($payment['card']) && isset($payment['card']['last_four_digits'])) {
$payment["trunc_card"] = "xxxx xxxx xxxx " . $payment['card']["last_four_digits"];
}

if (isset($payment['card']["cardholder"]["name"])) {
$payment["cardholder_name"] = $payment['card']["cardholder"]["name"];
}

if (isset($payment['payer']['first_name'])) {
$payment['payer_first_name'] = $payment['payer']['first_name'];
}

if (isset($payment['payer']['last_name'])) {
$payment['payer_last_name'] = $payment['payer']['last_name'];
}

if (isset($payment['payer']['email'])) {
$payment['payer_email'] = $payment['payer']['email'];
}

return $payment;
}

/**
* Return sum of fields separated with |
*
Expand All @@ -342,26 +288,39 @@ protected function _getMultiCardValue($data, $field)
}

/**
* return the list of payment methods or null
* return the list of payment methods or false
*
* @param mixed|null $accessToken
*
* @return mixed
* @return array
*/
public function getMercadoPagoPaymentMethods($accessToken)
{

$this->log('GET /v1/payment_methods', 'mercadopago');

try {
$mp = $this->getApiInstance($accessToken);

$response = $mp->get("/v1/payment_methods");
if ($response['status'] == 401 || $response['status'] == 400) {
return false;
$payment_methods = $mp->get("/v1/payment_methods");

$treated_payments_methods = [];

foreach ($payment_methods['response'] as $payment_method) {
if (!isset($payment_method['payment_places'])) {
$payment_method['payment_places'] = PaymentPlaces::getPaymentPlaces($payment_method['id']);
}

array_push($treated_payments_methods, $payment_method);
}

$payment_methods['response'] = $treated_payments_methods;

return $payment_methods;

} catch (Exception $e) {
return false;
return [];
}

return $response['response'];
}

/**
Expand Down Expand Up @@ -411,42 +370,6 @@ public function getModuleVersion()
return $this->_moduleResource->getDbVersion('MercadoPago_Core');
}

/**
* Summary: Get client id from access token.
* Description: Get client id from access token.
*
* @param String $at
*
* @return String client id.
*/
public static function getClientIdFromAccessToken($at)
{
$t = explode('-', $at);

if (count($t) > 0) {
return $t[1];
}

return '';
}

/**
* @param $additionalInfo
* @return string|null
*/
public function getPaymentId($additionalInfo)
{
if (isset($additionalInfo['payment_id_detail']) && !empty($additionalInfo['payment_id_detail'])) {
return $additionalInfo['payment_id_detail'];
}

if (isset($additionalInfo['paymentResponse']) && !empty($additionalInfo['paymentResponse'])) {
return $additionalInfo['paymentResponse']['id'];
}

return null;
}

/**
* Get modal link
*
Expand Down
49 changes: 49 additions & 0 deletions src/MercadoPago/Core/Helper/PaymentPlaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace MercadoPago\Core\Helper;

class PaymentPlaces
{
/**
* @return array
*/
public static function getPaymentPlaces($paymentId)
{
$payment_places = [
"paycash" => [
[
"payment_option_id" => "7eleven",
"name" => "7 Eleven",
"status" => "active",
"thumbnail" => "https://http2.mlstatic.com/storage/logos-api-admin/417ddb90-34ab-11e9-b8b8-15cad73057aa-s.png"
],
[
"payment_option_id" => "circlek",
"name" => "Circle K",
"status" => "active",
"thumbnail" => "https://http2.mlstatic.com/storage/logos-api-admin/6f952c90-34ab-11e9-8357-f13e9b392369-s.png"
],
[
"payment_option_id" => "soriana",
"name" => "Soriana",
"status" => "active",
"thumbnail" => "https://http2.mlstatic.com/storage/logos-api-admin/dac0bf10-01eb-11ec-ad92-052532916206-s.png"
],
[
"payment_option_id" => "extra",
"name" => "Extra",
"status" => "active",
"thumbnail" => "https://http2.mlstatic.com/storage/logos-api-admin/9c8f26b0-34ab-11e9-b8b8-15cad73057aa-s.png"
],
[
"payment_option_id" => "calimax",
"name" => "Calimax",
"status" => "active",
"thumbnail" => "https://http2.mlstatic.com/storage/logos-api-admin/52efa730-01ec-11ec-ba6b-c5f27048193b-s.png"
]
],
];

return $payment_places[$paymentId] ?? [];
}
}
Loading

0 comments on commit db61907

Please sign in to comment.