Skip to content

Commit 4442dd9

Browse files
author
Luis Felipe Vicente
committed
v1.9.3
1 parent d61e706 commit 4442dd9

File tree

11 files changed

+227
-42
lines changed

11 files changed

+227
-42
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.9.3] - 2025-04-10
9+
### Fixed
10+
- Adjustments to the Pix QR code sent by email
11+
- Adjustments to the address fields for Boleto
12+
- Adjustments to the total amount in payments with ChoPro
13+
814
## [1.9.2] - 2025-03-26
915
### Changed
1016
- Adjustments on payments without postcode
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* Copyright © MercadoPago. All rights reserved.
5+
*
6+
* @author Mercado Pago
7+
* @license See LICENSE for license details.
8+
*/
9+
10+
namespace MercadoPago\AdbPayment\Controller\Index;
11+
12+
use Magento\Framework\App\Action\Action;
13+
use Magento\Framework\App\Action\Context;
14+
use Psr\Log\LoggerInterface;
15+
16+
class GenerateQrCode extends Action
17+
{
18+
protected LoggerInterface $logger;
19+
20+
public function __construct(
21+
Context $context,
22+
LoggerInterface $logger
23+
) {
24+
parent::__construct($context);
25+
$this->logger = $logger;
26+
}
27+
28+
public function execute()
29+
{
30+
try {
31+
$qrCodeBase64 = $this->getRequest()->getParam('data');
32+
33+
if (!$qrCodeBase64) {
34+
throw new \InvalidArgumentException("'data' parameter not provided.");
35+
}
36+
37+
$imageData = base64_decode($qrCodeBase64);
38+
39+
if (!$imageData) {
40+
throw new \RuntimeException("Error decoding image.");
41+
}
42+
43+
$image = imagecreatefromstring($imageData);
44+
45+
if (!$image) {
46+
throw new \RuntimeException("Error creating image.");
47+
}
48+
49+
$image = imagescale($image, 447);
50+
51+
$this->getResponse()
52+
->setHeader('Content-Type', 'image/png')
53+
->setBody($this->generatePngOutput($image));
54+
55+
imagedestroy($image);
56+
} catch (\Exception $e) {
57+
$this->logger->debug(json_encode(['error' => $e->getMessage()]));
58+
$this->getResponse()
59+
->setHttpResponseCode(500)
60+
->setBody('Error processing QR Code.');
61+
}
62+
63+
return $this->getResponse();
64+
}
65+
66+
private function generatePngOutput($image)
67+
{
68+
ob_start();
69+
imagepng($image);
70+
return ob_get_clean();
71+
}
72+
}

Gateway/Config/Config.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -491,21 +491,18 @@ public function getValueForAddress($adress, $field): ?string
491491
{
492492
$value = (int) $this->getAddtionalValue($field);
493493

494-
if ($value === 0) {
495-
return $adress->getStreetLine1();
496-
} elseif ($value === 1) {
497-
return $adress->getStreetLine2();
498-
} elseif ($value === 2) {
499-
if ($adress->getStreetLine3()) {
500-
return $adress->getStreetLine3();
501-
}
502-
} elseif ($value === 3) {
503-
if ($adress->getStreetLine4()) {
504-
return $adress->getStreetLine4();
505-
}
494+
switch ($value) {
495+
case 0:
496+
return $adress->getStreetLine1();
497+
case 1:
498+
return $adress->getStreetLine2();
499+
case 2:
500+
return $adress->getStreetLine3() ?: '';
501+
case 3:
502+
return $adress->getStreetLine4() ?: '';
503+
default:
504+
return '';
506505
}
507-
508-
return '';
509506
}
510507

511508
/**

Gateway/Http/Client/CreateOrderPaymentCheckoutProClient.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public function placeRequest(TransferInterface $transferObject)
8080
$storeId = $request[self::STORE_ID];
8181

8282
try {
83+
$request['items'] = $this->calculateDiscountAmount($request['items'], $request['transaction_amount']);
84+
8385
$sdk = $this->config->getSdkInstance($storeId);
8486
$preferenceInstance = $sdk->getPreferenceInstance();
8587
unset($request[self::STORE_ID]);
@@ -128,4 +130,29 @@ public function placeRequest(TransferInterface $transferObject)
128130

129131
return $response;
130132
}
133+
134+
/**
135+
* Calculate the discount generated by a coupon or store credit.
136+
*
137+
* @param array $items
138+
* @param float $transactionAmount
139+
*
140+
* @return array
141+
*/
142+
protected function calculateDiscountAmount(array $items, float $transactionAmount): array {
143+
$total = 0;
144+
145+
foreach ($items as $item) {
146+
$total += $item['unit_price'];
147+
}
148+
149+
if ($total !== $transactionAmount) {
150+
$items[] = [
151+
'id' => 'store_discount',
152+
'unit_price' => $transactionAmount - $total
153+
];
154+
}
155+
156+
return $items;
157+
}
131158
}

Gateway/Request/BillingAddressDataRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BillingAddressDataRequest implements BuilderInterface
3838
/**
3939
* The street complement block name.
4040
*/
41-
public const STREET_COMPLEMENT = 'street_complement';
41+
public const STREET_COMPLEMENT = 'complement';
4242

4343
/**
4444
* The Street Neighborhood address block name.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace MercadoPago\AdbPayment\Test\Unit\Controller\Index;
4+
5+
use Magento\Framework\App\Request\Http as Request;
6+
use Magento\Framework\App\Response\Http as Response;
7+
use Magento\Framework\App\Action\Context;
8+
use MercadoPago\AdbPayment\Controller\Index\GenerateQrCode;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class GenerateQrCodeTest extends TestCase
12+
{
13+
private $controller;
14+
private $requestMock;
15+
private $responseMock;
16+
private $contextMock;
17+
private $loggerMock;
18+
private $responseBody;
19+
20+
protected function setUp(): void
21+
{
22+
$this->requestMock = $this->createMock(Request::class);
23+
$this->responseMock = $this->createMock(Response::class);
24+
$this->contextMock = $this->createMock(Context::class);
25+
$this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
26+
27+
$this->contextMock->method('getRequest')->willReturn($this->requestMock);
28+
$this->contextMock->method('getResponse')->willReturn($this->responseMock);
29+
30+
$this->responseMock->method('setHeader')->willReturnSelf();
31+
$this->responseMock->method('setHttpResponseCode')->willReturnSelf();
32+
$this->responseMock->method('setBody')->willReturnCallback(function ($body) {
33+
$this->responseBody = $body;
34+
return $this->responseMock;
35+
});
36+
37+
$this->controller = new GenerateQrCode($this->contextMock, $this->loggerMock);
38+
}
39+
40+
public function testExecuteWithoutDataParam()
41+
{
42+
$this->requestMock->method('getParam')->with('data')->willReturn(null);
43+
44+
$this->loggerMock
45+
->expects($this->once())
46+
->method('debug')
47+
->with(json_encode(['error' => "'data' parameter not provided."]));
48+
49+
$this->controller->execute();
50+
}
51+
52+
public function testExecuteWithInvalidBase64()
53+
{
54+
$this->requestMock->method('getParam')->with('data')->willReturn('invalid_base64');
55+
56+
$this->loggerMock
57+
->expects($this->once())
58+
->method('debug')
59+
->with(json_encode(['error' => "imagecreatefromstring(): Data is not in a recognized format"]));
60+
61+
$this->controller->execute();
62+
}
63+
64+
public function testExecuteWithValidBase64()
65+
{
66+
$image = imagecreatetruecolor(100, 100);
67+
ob_start();
68+
imagepng($image);
69+
$imageData = ob_get_clean();
70+
imagedestroy($image);
71+
72+
$base64Image = base64_encode($imageData);
73+
74+
$this->requestMock->method('getParam')->with('data')->willReturn($base64Image);
75+
76+
$this->controller->execute();
77+
78+
$this->assertNotEmpty($this->responseBody);
79+
$this->assertStringContainsString("\x89PNG", $this->responseBody);
80+
}
81+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mercadopago/adb-payment",
33
"description": "MercadoPago - Payment for Adobe Commerce",
4-
"version": "1.9.2",
4+
"version": "1.9.3",
55
"require": {
66
"php": "~7.3.0||~7.4.0||~8.1.0||~8.2.0||~8.3.0",
77
"ext-json": "*",

0 commit comments

Comments
 (0)