Skip to content

Commit

Permalink
Release 2.4.1
Browse files Browse the repository at this point in the history
Release 2.4.1
  • Loading branch information
fabiano-mallmann authored Mar 7, 2024
2 parents f3932ae + 2482d64 commit 72cf07a
Show file tree
Hide file tree
Showing 27 changed files with 164 additions and 242 deletions.
3 changes: 2 additions & 1 deletion Block/Payment/Billet.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected function getPayment()
public function getBilletUrl()
{
$billetHelper = new BilletHelper();
return $billetHelper->getBilletUrl($this->getPayment());
$pagarmeTransaction = $this->checkoutSession->getPixOrBilletTransaction();
return $billetHelper->getBilletUrl($this->getPayment(), $pagarmeTransaction);
}
}
38 changes: 32 additions & 6 deletions Block/Payment/Pix.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Class Billet
* Class Pix
*
* @author Open Source Team
* @copyright 2021 Pagar.me (https://pagar.me)
Expand All @@ -11,9 +11,12 @@

namespace Pagarme\Pagarme\Block\Payment;

use Exception;
use Magento\Framework\Phrase;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\View\Asset\Repository;
use Magento\Sales\Api\Data\OrderInterface as Order;
use Magento\Sales\Api\Data\OrderPaymentInterface as Payment;
use Pagarme\Pagarme\Helper\Payment\Pix as PixHelper;
Expand All @@ -36,14 +39,27 @@ class Pix extends Template
private $pixHelper;

/**
* Link constructor.
* @var Repository
*/
private $assetRepository;

/**
* Pix constructor
*
* @param Context $context
* @param CheckoutSession $checkoutSession
* @param PixHelper $pixHelper
* @param Repository $assetRepository
*/
public function __construct(Context $context, CheckoutSession $checkoutSession, PixHelper $pixHelper)
{
public function __construct(
Context $context,
CheckoutSession $checkoutSession,
PixHelper $pixHelper,
Repository $assetRepository
) {
$this->checkoutSession = $checkoutSession;
$this->pixHelper = $pixHelper;
$this->assetRepository = $assetRepository;
parent::__construct($context, []);
}

Expand Down Expand Up @@ -85,6 +101,14 @@ public function showPixInformation()
return !empty($this->getPixInfo());
}

/**
* @return string
*/
public function getLogoSrc()
{
return $this->assetRepository->getUrl(PixHelper::LOGO_URL);
}

/**
* @return string
*/
Expand All @@ -94,7 +118,7 @@ public function getErrorCopyMessage()
}

/**
* @return string
* @return Phrase
*/
public function getSuccessMessage()
{
Expand All @@ -103,11 +127,13 @@ public function getSuccessMessage()

/**
* @return PixHelper
* @throws Exception
*/
public function getPixInfo()
{
$pagarmeTransaction = $this->checkoutSession->getPixOrBilletTransaction();
if (empty($this->pixInfo)) {
$this->pixInfo = $this->pixHelper->getInfo($this->getPayment());
$this->pixInfo = $this->pixHelper->getInfo($this->getPayment(), $pagarmeTransaction);
}

return $this->pixInfo;
Expand Down
37 changes: 11 additions & 26 deletions Concrete/Magento2PlatformOrderDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1122,30 +1122,11 @@ private function extractPaymentDataFromPagarmeBilletCreditcard(

$paymentData[$creditCardDataIndex][] = $newPaymentData;

//boleto

$newPaymentData = new stdClass();

$amount = str_replace(
['.', ','],
"",
$additionalInformation["cc_billet_amount"] ?? ''
$this->extractPaymentDataFromPagarmeBillet(
$additionalInformation,
$paymentData,
$payment
);

$newPaymentData->amount =
$this->moneyService->floatToCents($amount / 100);

$boletoDataIndex = BoletoPayment::getBaseCode();
if (!isset($paymentData[$boletoDataIndex])) {
$paymentData[$boletoDataIndex] = [];
}

$newPaymentData->customer = $this->extractMultibuyerData(
'billet',
$additionalInformation
);

$paymentData[$boletoDataIndex][] = $newPaymentData;
}

private function extractPaymentDataFromPagarmeBillet(
Expand All @@ -1154,17 +1135,21 @@ private function extractPaymentDataFromPagarmeBillet(
$payment
) {
$newPaymentData = new stdClass();
$amount = $this->platformOrder->getGrandTotal();
if (isset($additionalInformation["cc_billet_amount"])) {
$amount = $this->moneyService->removeSeparators($additionalInformation["cc_billet_amount"]) / 100;
}
$newPaymentData->amount =
$this->moneyService->floatToCents($this->platformOrder->getGrandTotal());
$this->moneyService->floatToCents($amount);
$moduleConfiguration = MPSetup::getModuleConfiguration();
$newPaymentData->instructions = $moduleConfiguration->getBoletoInstructions();
$bankConfig = new Bank();
$bankNumber = $bankConfig->getBankNumber(MPSetup::getModuleConfiguration()->getBoletoBankCode());
$bankNumber = $bankConfig->getBankNumber($moduleConfiguration->getBoletoBankCode());
if ($bankNumber) {
$newPaymentData->bank = $bankNumber;
}
$expirationDate = new \DateTime();
$days = MPSetup::getModuleConfiguration()->getBoletoDueDays();
$days = $moduleConfiguration->getBoletoDueDays();
if ($days) {
$expirationDate->modify("+{$days} day");
}
Expand Down
28 changes: 16 additions & 12 deletions Gateway/Transaction/Base/Command/InitializeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Pagarme\Pagarme\Gateway\Transaction\Base\Command;

use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Sales\Model\Order;
use Magento\Sales\Api\Data\OrderInterface;
Expand All @@ -28,25 +29,27 @@
use Pagarme\Pagarme\Model\Ui\TwoCreditCard\ConfigProvider as TwoCreditCardConfigProvider;
use Magento\Framework\Phrase;
use Magento\Framework\Webapi\Exception as M2WebApiException;
use Pagarme\Pagarme\Helper\RecurrenceProductHelper;
use Pagarme\Pagarme\Gateway\Transaction\Base\Config\Config;
use Pagarme\Pagarme\Service\Transaction\ThreeDSService;

class InitializeCommand implements CommandInterface
{

protected $config;
/**
* @var ThreeDSService
*/
protected $threeDSService;
/**
* @var CheckoutSession
*/
protected $checkoutSession;

public function __construct(
Config $config,
ThreeDSService $threeDSService
){
$this->config = $config;
ThreeDSService $threeDSService,
CheckoutSession $checkoutSession
)
{
$this->threeDSService = $threeDSService;
$this->checkoutSession = $checkoutSession;
}

/**
Expand Down Expand Up @@ -110,10 +113,7 @@ public function execute(array $commandSubject)
/** @return AbstractPlatformOrderDecorator */
private function doCoreDetour($payment)
{
$order = $payment->getOrder();
if($this->config->getAlwaysCreateOrder()){
$order->save();
}
$order = $payment->getOrder();
$log = new OrderLogService();

Magento2CoreSetup::bootstrap();
Expand Down Expand Up @@ -168,7 +168,11 @@ private function doCoreDetour($payment)

if (!$isSubscription) {
$orderService = new OrderService();
$orderService->createOrderAtPagarme($orderDecorator);
$pagarmeOrder = current($orderService->createOrderAtPagarme($orderDecorator));
$transaction = $pagarmeOrder->getPixOrBilletTransaction();
if (!is_null($transaction)) {
$this->checkoutSession->setPixOrBilletTransaction($transaction);
}
}

$orderDecorator->save();
Expand Down
18 changes: 11 additions & 7 deletions Helper/Payment/Billet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,36 @@
use Pagarme\Core\Recurrence\Repositories\SubscriptionRepository;

class Billet {
public function getBilletUrl($info)

public function getBilletUrl($info, $transaction = null)
{
$method = $info->getMethod();
if (strpos($method, "pagarme_billet") === false) {
return;
}

Magento2CoreSetup::bootstrap();
$boletoUrl = $this->getBoletoLinkFromOrder($info);
$boletoUrl = $this->getBoletoLinkFromOrder($info, $transaction);

if (!$boletoUrl) {
$boletoUrl = $this->getBoletoLinkFromSubscription($info);
}

return $boletoUrl;
}

private function getBoletoLinkFromOrder($info)
private function getBoletoLinkFromOrder($info, $transaction = null)
{
$lastTransId = $info->getLastTransId();
$orderId = null;
if ($lastTransId) {
$orderId = substr($lastTransId, 0, 19);
}

if (!$orderId && !is_null($transaction)) {
return $transaction->getBoletoUrl();
}

if (!$orderId) {
return null;
}
Expand Down Expand Up @@ -79,4 +83,4 @@ private function getBoletoLinkFromSubscription($info)

return null;
}
}
}
12 changes: 11 additions & 1 deletion Helper/Payment/Pix.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

namespace Pagarme\Pagarme\Helper\Payment;

use Exception;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use Pagarme\Core\Kernel\ValueObjects\Id\OrderId;
use Pagarme\Core\Payment\Services\OrderService;

class Pix
{
const LOGO_URL = "Pagarme_Pagarme::images/logo-pix.svg";

private $qrCodeUrl;
private $qrCode;

/**
* @return $this
* @throws Exception
*/
public function getInfo($info)
public function getInfo($info, $transaction = null)
{
$orderId = null;
$method = $info->getMethod();
Expand All @@ -27,6 +31,12 @@ public function getInfo($info)
$orderId = substr($lastTransId, 0, 19);
}

if (!$orderId && !is_null($transaction)) {
$this->setQrCode($transaction->getPostData()->qr_code);
$this->setQrCodeUrl($transaction->getPostData()->qr_code_url);
return $this;
}

Magento2CoreSetup::bootstrap();
$orderService = new OrderService();
$qrCodeData = $orderService->getPixQrCodeInfoFromOrder(new OrderId($orderId));
Expand Down
2 changes: 1 addition & 1 deletion Model/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private function addDashSettingsMessages()
CoreAccount::DOMAIN_INCORRECT => sprintf(
__('The registered <b>domain</b> is different from the URL of your website. Please correct the '
. 'domain configured on the <b>%s</b> to be able to process payment in your store.'),
$this->buildDashLink($linkLabel, $linkAccount),
$this->buildDashLink($linkLabel, $linkAccount)
),
CoreAccount::WEBHOOK_INCORRECT => sprintf(
__('The URL for receiving <b>webhooks</b> registered in Pagar.me Dash is different from the URL of '
Expand Down
11 changes: 10 additions & 1 deletion Model/Ui/Pix/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Pagarme\Pagarme\Model\Ui\Pix;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\View\Asset\Repository;
use Pagarme\Core\Kernel\ValueObjects\Configuration\PixConfig;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup as MPSetup;
use Pagarme\Pagarme\Helper\Payment\Pix as PixHelper;

final class ConfigProvider implements ConfigProviderInterface
{
Expand All @@ -15,10 +17,16 @@ final class ConfigProvider implements ConfigProviderInterface
*/
private $pixConfig;

public function __construct()
/**
* @var Repository
*/
private $assetRepository;

public function __construct(Repository $assetRepository)
{
MPSetup::bootstrap();
$moduleConfig = MPSetup::getModuleConfiguration();
$this->assetRepository = $assetRepository;
if (!empty($moduleConfig->getPixConfig())) {
$this->pixConfig = $moduleConfig->getPixConfig();
}
Expand All @@ -31,6 +39,7 @@ public function getConfig()
self::CODE => [
'active' => $this->pixConfig->isEnabled(),
'title' => $this->pixConfig->getTitle(),
'logo' => $this->assetRepository->getUrl(PixHelper::LOGO_URL)
]
]
];
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "pagarme/pagarme-magento2-module",
"license": "MIT",
"version": "2.4.0",
"version": "2.4.1",
"type": "magento2-module",
"description": "Magento 2 Module Pagar.me",
"require": {
"php": ">=7.1",
"pagarme/ecommerce-module-core": "2.4.*"
"pagarme/ecommerce-module-core": "~2.4.1"
},
"require-dev": {
"phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Pagarme_Pagarme" setup_version="2.4.0">
<module name="Pagarme_Pagarme" setup_version="2.4.1">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down
Loading

0 comments on commit 72cf07a

Please sign in to comment.