Skip to content

Commit

Permalink
refact: split in two functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiano-mallmann committed Sep 5, 2024
1 parent c204af3 commit 4f06cea
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions Block/Payment/Info/BaseCardInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,34 @@ abstract class BaseCardInfo extends Cc

/**
* @return array
*/
public function getTransactionInfo()
{
$charge = $this->getLastCharge();
if ($charge->getLastTransaction()->getCardData() == null) {
return [];
}
$lastFourDigitsWithDots = sprintf(
"**** **** **** %s",
$charge->getLastTransaction()->getCardData()->getLastFourDigits()->getValue()
);
return array_merge(
$charge->getAcquirerTidCapturedAndAuthorize(),
['tid' => $charge->getLastTransaction()->getAcquirerTid() ?? ""],
['cardBrand' => $charge->getLastTransaction()->getCardData()->getBrand()->getName() ?? ""],
['installments' => $this->getInfo()->getAdditionalInformation('cc_installments') ?? ""],
['lastFour' => $lastFourDigitsWithDots],
['acquirerMessage' => $charge->getLastTransaction()->getAcquirerMessage() ?? ""]
);
}

/**
* @return mixed|array|Charge
* @throws InvalidParamException
* @throws LocalizedException
* @throws Exception
*/
public function getTransactionInfo()
private function getLastCharge()
{
Magento2CoreSetup::bootstrap();
$orderService = new OrderService();
Expand All @@ -40,24 +63,9 @@ public function getTransactionInfo()
return [];
}

$charge = current($orderObject->getCharges());
if ($charge->getLastTransaction()->getCardData() == null) {
return [];
}
$lastFourDigitsWithDots = sprintf(
"**** **** **** %s",
$charge->getLastTransaction()->getCardData()->getLastFourDigits()->getValue()
);
return array_merge(
$charge->getAcquirerTidCapturedAndAuthorize(),
['tid' => $charge->getLastTransaction()->getAcquirerTid() ?? ""],
['cardBrand' => $charge->getLastTransaction()->getCardData()->getBrand()->getName() ?? ""],
['installments' => $this->getInfo()->getAdditionalInformation('cc_installments') ?? ""],
['lastFour' => $lastFourDigitsWithDots],
['acquirerMessage' => $charge->getLastTransaction()->getAcquirerMessage() ?? ""]
);
return current($orderObject->getCharges());
}

/**
* @param mixed $orderService
* @param mixed $pagarmeId
Expand Down

0 comments on commit 4f06cea

Please sign in to comment.