Skip to content

Commit

Permalink
Merge pull request #363 from pagarme/stg
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
fabiano-mallmann authored Sep 11, 2024
2 parents eed765b + 6293e3f commit 157c5b6
Show file tree
Hide file tree
Showing 33 changed files with 655 additions and 402 deletions.
2 changes: 1 addition & 1 deletion Api/RecipientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function searchRecipient(): string;

/**
* @param string $id
* @return KycLinkResponseInterface
* @return Pagarme\Pagarme\Api\KycLinkResponseInterface
*/
public function createKycLink(string $id);
}
77 changes: 47 additions & 30 deletions Block/Adminhtml/System/Config/Form/Field/HubIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Phrase;
use Pagarme\Core\Hub\Services\HubIntegrationService;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use Pagarme\Pagarme\Model\Account;
Expand All @@ -18,12 +18,16 @@ class HubIntegration extends Field
*/
private $account;

protected $scopeConfig;

public function __construct(
Account $account,
ScopeConfigInterface $scopeConfig,
Context $context,
array $data = []
) {
$this->account = $account;
$this->scopeConfig = $scopeConfig;
parent::__construct($context, $data);
}

Expand All @@ -32,31 +36,46 @@ public function __construct(
* @return string
* @throws Exception
*/
protected function _renderValue(AbstractElement $element)
protected function _renderValue(AbstractElement $element): string
{
Magento2CoreSetup::bootstrap();

$installId = Magento2CoreSetup::getModuleConfiguration()
->getHubInstallId();

$hubUrl = $this->getHubUrl($installId);
$buttonText = $this->getButtonText($installId);
$installId = Magento2CoreSetup::getModuleConfiguration()->getHubInstallId();
$installIdValue = !empty($installId) ? $installId->getValue() : '';
$defaultInstallId = $this->scopeConfig->getValue(
'pagarme_pagarme/hub/install_id',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
$defaultInstallId = $defaultInstallId ?? '';

$html = '<td class="value">';
$html = sprintf(
'<td class="value" data-pagarme-integration-scope="%s">',
$installIdValue === $defaultInstallId ? 'default' : 'scope'
);
$html .= $this->_getElementHtml($element);

$hidden = ' hidden';

$html .= sprintf(
'<a id="pagarme-hub-button" href="%s">%s</a>',
$hubUrl,
$buttonText
'<a href="%s" id="pagarme-integrate-button" class="pagarme-integration-button%s">%s</a>',
$this->getBaseIntegrateUrl(),
$installId ? $hidden : '',
__("Integrate With Pagar.me")
);

$html .= sprintf(
'<a href="%s" id="pagarme-view-integration-button" class="pagarme-integration-button%s">%s</a>',
$this->getHubUrl($installId),
$installId ? '' : $hidden,
__("View Integration")
);

if ($this->account->hasMerchantAndAccountIds()) {
$dashUrl = $this->account->getDashUrl();
$html .= sprintf(
'<a id="pagarme-dash-button" href="%s" target="_blank">%s</a>',
$dashUrl,
'<a href="%s" target="_blank" id="pagarme-dash-button" class="pagarme-integration-button%s">%s</a>',
$this->account->getDashUrl(),
$installId ? '' : $hidden,
__('Access Pagar.me Dash')
);
}
Expand All @@ -66,16 +85,6 @@ protected function _renderValue(AbstractElement $element)
return $html;
}

/**
* @param $installId
* @return Phrase
*/
private function getButtonText($installId): Phrase
{
return $installId
? __("View Integration") : __("Integrate With Pagar.me");
}

/**
* @param $installId
* @return string
Expand All @@ -97,12 +106,20 @@ private function getBaseIntegrateUrl(): string
$this->getPublicAppKey()
);

$params = sprintf(
'?redirect=%swebsite/%s/&install_token/%s',
$this->getRedirectUrl(),
Magento2CoreSetup::getCurrentStoreId(),
$this->getInstallToken()
);
if($this->getRequest()->getParam('website') !== null) {
$params = sprintf(
'?redirect=%swebsite/%s/&install_token/%s',
$this->getRedirectUrl(),
Magento2CoreSetup::getCurrentStoreId(),
$this->getInstallToken()
);
} else {
$params = sprintf(
'?redirect=%s&install_token/%s',
$this->getRedirectUrl(),
$this->getInstallToken()
);
}

return $baseUrl . $params;
}
Expand Down
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
Loading

0 comments on commit 157c5b6

Please sign in to comment.