Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when credit card data is empty #361

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 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,21 +63,9 @@ public function getTransactionInfo()
return [];
}

$charge = current($orderObject->getCharges());
$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
3 changes: 3 additions & 0 deletions view/adminhtml/templates/info/card.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @var \Pagarme\Core\Kernel\Aggregates\Transaction $info
*/
$info = $this->getTransactionInfo();
if(empty($info)) {
return;
}
?>
<span>
<?= __($this->getTitle()); ?>
Expand Down
3 changes: 3 additions & 0 deletions view/frontend/templates/info/card.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @var \Pagarme\Core\Kernel\Aggregates\Transaction $info
*/
$info = $this->getTransactionInfo();
if(empty($info)) {
return;
}
?>
<span>
<?= __($this->getTitle()); ?>
Expand Down
Loading