Skip to content

Commit

Permalink
Merge pull request #204 from pagarme/feature/PAOPN-454/refactoring-cr…
Browse files Browse the repository at this point in the history
…edit-card-phtml-template

Feature/paopn 454/refactoring credit card phtml template
  • Loading branch information
mateus-picoloto authored Jul 19, 2023
2 parents 991ccac + 3194edf commit deb7806
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
62 changes: 53 additions & 9 deletions Block/Payment/Info/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,57 @@ class CreditCard extends Cc
{
const TEMPLATE = 'Pagarme_Pagarme::info/creditCard.phtml';

/**
* @return void
*/
public function _construct()
{
$this->setTemplate(self::TEMPLATE);
}

/**
* @return string
*/
public function getCcType()
{
return $this->getCcTypeName();
}

/**
* @return string
*/
public function getCardNumber()
{
return '**** **** **** ' . $this->getInfo()->getCcLast4();
}

/**
* @return string
*/
public function getCardLast4()
{
return '**** **** **** ' . $this->getInfo()->getAdditionalInformation('cc_last_4');
}

/**
* @return mixed
*/
public function getCcBrand()
{
return $this->getInfo()->getAdditionalInformation('cc_type');
}

/**
* @return mixed
*/
public function getTitle()
{
return $this->getInfo()->getAdditionalInformation('method_title');
}

/**
* @return mixed
*/
public function getInstallments()
{
return $this->getInfo()->getAdditionalInformation('cc_installments');
Expand All @@ -73,30 +94,53 @@ public function getTransactionInfo()
$orderService = new OrderService();

$orderEntityId = $this->getInfo()->getOrder()->getIncrementId();

$platformOrder = new Magento2PlatformOrderDecorator();
$platformOrder->loadByIncrementId($orderEntityId);
$platformOrder = $this->loadPlatformOrderByIncrementId($orderEntityId);

$orderPagarmeId = $platformOrder->getPagarmeId();
if ($orderPagarmeId === null) {
return [];
}

/**
* @var Order orderObject
*/
$orderObject = $orderService->getOrderByPagarmeId(new OrderId($orderPagarmeId));
$orderObject = $this->getOrderObjectByPagarmeId($orderService, $orderPagarmeId);

if ($orderObject === null) {
return [];
}

$charge = current($orderObject->getCharges());

return array_merge(
$orderObject->getCharges()[0]->getAcquirerTidCapturedAndAutorize(),
['tid' => $this->getTid($orderObject->getCharges()[0])]
$charge->getAcquirerTidCapturedAndAutorize(),
['tid' => $this->getTid($charge)]
);
}

/**
* @param mixed $incrementId
* @return Magento2PlatformOrderDecorator
*/
private function loadPlatformOrderByIncrementId($incrementId)
{
$platformOrder = new Magento2PlatformOrderDecorator();
$platformOrder->loadByIncrementId($incrementId);
return $platformOrder;
}

/**
* @param mixed $orderService
* @param mixed $pagarmeId
* @return mixed
*/
private function getOrderObjectByPagarmeId($orderService, $pagarmeId)
{
$orderId = new OrderId($pagarmeId);
return $orderService->getOrderByPagarmeId($orderId);
}

/**
* @param \Pagarme\Core\Kernel\Aggregates\Charge $charge
* @return string|null
*/
private function getTid(Charge $charge)
{
$transaction = $charge->getLastTransaction();
Expand Down
18 changes: 7 additions & 11 deletions view/frontend/templates/info/creditCard.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Class billet
* var Pagarme\Pagarme\Block\Payment\Info\CreditCard $this
*
* @author Open Source Team
* @copyright 2021 Pagar.me (https://pagar.me)
Expand All @@ -10,13 +10,9 @@
*/

?>
<?php if ($this->getCcType()): ?>
<span><?php echo __($this->getTitle()); ?></span>
<br/>
<br/>
<span><b><?php echo __('Brand'); ?>: </b><?php echo $this->getCcBrand(); ?></span>
<br/>
<span><b><?php echo __('Number'); ?>: </b><?php echo $this->getCardLast4(); ?></span>
<br/>
<span><b><?php echo __('Installments'); ?>: </b><?php echo $this->getInstallments(); ?></span>
<?php endif ?>
<p><?= __($this->getTitle()); ?></p>
<p>
<b><?= __('Brand'); ?>:</b> <?= ucfirst($this->getCcBrand()); ?><br/>
<b><?= __('Number'); ?>:</b> <?= $this->getCardLast4(); ?><br/>
<b><?= __('Installments'); ?>:</b> <?= $this->getInstallments(); ?>
</p>

0 comments on commit deb7806

Please sign in to comment.