Skip to content

Commit

Permalink
PagBank 😍 Magento
Browse files Browse the repository at this point in the history
- Implementa autenticação 3DS
- Implementa pagamento por Cartão de Débito
  • Loading branch information
elisei committed Oct 21, 2024
1 parent e244f45 commit 61d5241
Show file tree
Hide file tree
Showing 41 changed files with 1,078 additions and 137 deletions.
44 changes: 44 additions & 0 deletions Api/Data/CardTypeTransactionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* PagBank Payment Magento Module.
*
* Copyright © 2023 PagBank. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* @license See LICENSE for license details.
*/

declare(strict_types=1);

namespace PagBank\PaymentMagento\Api\Data;

/**
* Interface Card Type Transaction - Data Card Type Transaction.
*
* @api
*
* @since 100.0.1
*/
interface CardTypeTransactionInterface
{
/**
* @const string
*/
public const PAGBANK_CARD_TYPE_TRANSACTION = 'card_type_transaction';

/**
* Get Card Type Transaction.
*
* @return string
*/
public function getCardTypeTransaction();

/**
* Set Card Type Transaction.
*
* @param string $cardTypeTransaction
*
* @return void
*/
public function setCardTypeTransaction($cardTypeTransaction);
}
8 changes: 5 additions & 3 deletions Api/GuestListInstallmentsManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ interface GuestListInstallmentsManagementInterface
/**
* Generate the list installments by credit card.
*
* @param string $cartId
* @param \PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin
* @param string $cartId
* @param \PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin
* @param \PagBank\PaymentMagento\Api\Data\CardTypeTransactionInterface $cardTypeTransaction
*
* @return mixed
*/
public function generateListInstallments(
$cartId,
\PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin
\PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin,
\PagBank\PaymentMagento\Api\Data\CardTypeTransactionInterface $cardTypeTransaction = null
);
}
8 changes: 5 additions & 3 deletions Api/ListInstallmentsManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ interface ListInstallmentsManagementInterface
/**
* Generate the list installments by credit card number.
*
* @param int $cartId
* @param \PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin
* @param int $cartId
* @param \PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin
* @param \PagBank\PaymentMagento\Api\Data\CardTypeTransactionInterface $cardTypeTransaction
*
* @return mixed
*/
public function generateListInstallments(
$cartId,
\PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin
\PagBank\PaymentMagento\Api\Data\CreditCardBinInterface $creditCardBin,
\PagBank\PaymentMagento\Api\Data\CardTypeTransactionInterface $cardTypeTransaction = null
);
}
67 changes: 67 additions & 0 deletions Block/Adminhtml/System/Config/Apps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* PagBank Payment Magento Module.
*
* Copyright © 2023 PagBank. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* @license See LICENSE for license details.
*/

namespace PagBank\PaymentMagento\Block\Adminhtml\System\Config;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;

/**
* Class Apps - Type apps.
*
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
*/
class Apps extends Field
{
/**
* Template oAuth.
*/
public const TEMPLATE = 'PagBank_PaymentMagento::system/config/apps.phtml';

/**
* @param Context $context
*/
public function __construct(
Context $context
) {
parent::__construct($context);
$this->setTemplate(self::TEMPLATE);
}

/**
* Override render method to remove label and td elements
*
* @param AbstractElement $element
*/
public function render(AbstractElement $element)
{
$html = '<tr id="row_' . $element->getHtmlId() . '">';
$html .= '<td colspan="2">';
$html .= $this->_getElementHtml($element);
$html .= '</td>';
$html .= '</tr>';
return $html;
}

/**
* Render the field HTML
*
* @param AbstractElement $element
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->toHtml();
}
}
14 changes: 14 additions & 0 deletions Block/Adminhtml/System/Config/Oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ public function getUrlToConnect()
$appId = Config::APP_ID_SANDBOX;
}

if ($this->config->getTypeApp($storeId) === 'd14') {
$appId = Config::APP_ID_FOURTEEN_PRODUCTION;
if ($this->config->getEnvironmentMode($storeId) === Config::ENVIRONMENT_SANDBOX) {
$appId = Config::APP_ID_FOURTEEN_SANDBOX;
}
}

if ($this->config->getTypeApp($storeId) === 'd30') {
$appId = Config::APP_ID_THIRTY_PRODUCTION;
if ($this->config->getEnvironmentMode($storeId) === Config::ENVIRONMENT_SANDBOX) {
$appId = Config::APP_ID_THIRTY_SANDBOX;
}
}

$params = [
'response_type' => $responseType,
'client_id' => $appId,
Expand Down
74 changes: 74 additions & 0 deletions Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Config extends PaymentConfig
*/
public const ENDPOINT_PRODUCTION = 'https://api.pagseguro.com/';

/**
* @const string
*/
public const ENDPOINT_SDK_PRODUCTION = 'https://sdk.pagseguro.com/';

/**
* @const string
*/
Expand All @@ -54,6 +59,15 @@ class Config extends PaymentConfig
*/
public const APP_ID_PRODUCTION = '1782a592-5eea-442c-8e67-c940d020dc53';

/**
* @const string
*/
public const APP_ID_THIRTY_PRODUCTION = '4875151e-9caa-4019-b6b7-d29852efe7ee';

/**
* @const string
*/
public const APP_ID_FOURTEEN_PRODUCTION = 'fd0305da-da00-42b6-a9f4-dac498bc05e4';
/**
* @const string
*/
Expand All @@ -64,11 +78,26 @@ class Config extends PaymentConfig
*/
public const ENDPOINT_SANDBOX = 'https://sandbox.api.pagseguro.com/';

/**
* @const string
*/
public const ENDPOINT_SDK_SANDBOX = 'https://sandbox.sdk.pagseguro.com/';

/**
* @const string
*/
public const APP_ID_SANDBOX = '16670d56-c0cb-4a45-a7c7-616868c2c94d';

/**
* @const string
*/
public const APP_ID_THIRTY_SANDBOX = '38a3acd5-b628-4bab-8364-079343cce978';

/**
* @const string
*/
public const APP_ID_FOURTEEN_SANDBOX = 'ebde0a80-a80c-4e81-b375-9d1e8b8671d3';

/**
* @const string
*/
Expand Down Expand Up @@ -185,6 +214,24 @@ public function getApiUrl($storeId = null): ?string
return self::ENDPOINT_PRODUCTION;
}

/**
* Gets the API endpoint URL.
*
* @param int|null $storeId
*
* @return string|null
*/
public function getApiSDKUrl($storeId = null): ?string
{
$environment = $this->getEnvironmentMode($storeId);

if ($environment === 'sandbox') {
return self::ENDPOINT_SDK_SANDBOX;
}

return self::ENDPOINT_SDK_PRODUCTION;
}

/**
* Gets the Environment Mode.
*
Expand All @@ -203,6 +250,18 @@ public function getEnvironmentMode($storeId = null): ?string
return self::ENVIRONMENT_PRODUCTION;
}

/**
* Get Type App.
*
* @param int|null $storeId
*
* @return string|null
*/
public function getTypeApp($storeId = null): ?string
{
return $this->getAddtionalValue('type_app', $storeId);
}

/**
* Get Api Headers.
*
Expand Down Expand Up @@ -245,11 +304,26 @@ public function getPubHeader($storeId = null)
{
$environment = $this->getAddtionalValue('environment', $storeId);
$pub = $this->getAddtionalValue('cipher_text_production', $storeId);
$app = $this->getTypeApp($storeId);

if ($environment === 'sandbox') {
$pub = $this->getAddtionalValue('cipher_text_sandbox');
}

if ($app === 'd14') {
$pub = $this->getAddtionalValue('d14_cipher_text_production', $storeId);
if ($environment === 'sandbox') {
$pub = $this->getAddtionalValue('d14_cipher_text_sandbox');
}
}

if ($app === 'd30') {
$pub = $this->getAddtionalValue('d30_cipher_text_production', $storeId);
if ($environment === 'sandbox') {
$pub = $this->getAddtionalValue('d30_cipher_text_sandbox');
}
}

return [
'Content-Type' => 'application/json',
'Authorization' => 'Pub '.$pub,
Expand Down
Loading

0 comments on commit 61d5241

Please sign in to comment.