Skip to content

Commit

Permalink
PagBank 😍 Magento
Browse files Browse the repository at this point in the history
- Adiciona salvamento de cartão utilizando a API de Zero Dollar.
  • Loading branch information
elisei committed Dec 4, 2024
1 parent cf8ee14 commit 4e55c75
Show file tree
Hide file tree
Showing 19 changed files with 1,214 additions and 5 deletions.
153 changes: 153 additions & 0 deletions Api/Data/PagBankVaultTokenInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?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 PagBank Vault Token.
*
* @api
*/
interface PagBankVaultTokenInterface
{
/**
* Constants for keys of data array.
*/
public const PAGBANK_TOKEN = 'pagbank_token';
public const PUBLIC_HASH = 'public_hash';
public const CARD_BRAND = 'card_brand';
public const LAST_DIGITS = 'last_digits';
public const EXPIRATION_DATE = 'expiration_date';
public const CREATED_AT = 'created_at';
public const IS_ACTIVE = 'is_active';
public const WEBSITE_ID = 'website_id';

/**
* Get PagBank Token.
*
* @return string|null
*/
public function getPagBankToken();

/**
* Set PagBank Token.
*
* @param string $token
* @return $this
*/
public function setPagBankToken($token);

/**
* Get Website Id.
*
* @return int|null
*/
public function getWebsiteId();

/**
* Set Website Id.
*
* @param int $websiteId
* @return $this
*/
public function setWebsiteId($websiteId);

/**
* Get public hash.
*
* @return string|null
*/
public function getPublicHash();

/**
* Set public hash.
*
* @param string $hash
* @return $this
*/
public function setPublicHash($hash);

/**
* Get card brand.
*
* @return string|null
*/
public function getCardBrand();

/**
* Set card brand.
*
* @param string $brand
* @return $this
*/
public function setCardBrand($brand);

/**
* Get last digits.
*
* @return string|null
*/
public function getLastDigits();

/**
* Set last digits.
*
* @param string $lastDigits
* @return $this
*/
public function setLastDigits($lastDigits);

/**
* Get expiration date.
*
* @return string|null
*/
public function getExpirationDate();

/**
* Set expiration date.
*
* @param string $expirationDate
* @return $this
*/
public function setExpirationDate($expirationDate);

/**
* Get created at.
*
* @return string|null
*/
public function getCreatedAt();

/**
* Set created at.
*
* @param string $createdAt
* @return $this
*/
public function setCreatedAt($createdAt);

/**
* Get is active.
*
* @return bool|null
*/
public function getIsActive();

/**
* Set is active.
*
* @param bool $isActive
* @return $this
*/
public function setIsActive($isActive);
}
33 changes: 33 additions & 0 deletions Api/PagBankVaultManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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;

/**
* Interface for creating token vault from zero dollar transaction.
*
* @api
*/
interface PagBankVaultManagementInterface
{
/**
* Criar token vault a partir de cartão criptografado.
*
* @param int $customerId
* @param string $encryptedCard
* @return \PagBank\PaymentMagento\Api\Data\PagBankVaultTokenInterface
*/
public function createVaultToken(
int $customerId,
string $encryptedCard
);
}
143 changes: 143 additions & 0 deletions Block/Customer/Vault/Cards/CreateForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?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\Customer\Vault\Cards;

use Magento\Framework\View\Element\Template;
use Magento\Payment\Model\CcConfig;
use PagBank\PaymentMagento\Gateway\Config\Config;
use PagBank\PaymentMagento\Gateway\Config\ConfigCc;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Asset\Source;

/**
* Class CreateForm - Block to handle credit card form.
*/
class CreateForm extends Template
{
/**
* @var Config
*/
private $config;

/**
* @var ConfigCc
*/
private $configCc;

/**
* @var CcConfig
*/
private $ccConfig;

/**
* @var Json
*/
private $serializer;

/**
* @var Source
*/
private $assetSource;

/**
* @param Template\Context $context
* @param Config $config
* @param ConfigCc $configCc
* @param CcConfig $ccConfig
* @param Json $serializer
* @param Source $assetSource
* @param array $data
*/
public function __construct(
Template\Context $context,
Config $config,
ConfigCc $configCc,
CcConfig $ccConfig,
Json $serializer,
Source $assetSource,
array $data = []
) {
parent::__construct($context, $data);
$this->config = $config;
$this->configCc = $configCc;
$this->ccConfig = $ccConfig;
$this->serializer = $serializer;
$this->assetSource = $assetSource;
}

/**
* Get credit card expiration months
*
* @return array
*/
public function getCcMonths()
{
return $this->ccConfig->getCcMonths();
}

/**
* Get credit card expiration years
*
* @return array
*/
public function getCcYears()
{
return $this->ccConfig->getCcYears();
}

/**
* Get CC Available Types
*
* @return array
*/
public function getCcAvailableTypes()
{
$storeId = $this->_storeManager->getStore()->getId();
$types = $this->configCc->getCcAvailableTypes($storeId);
$ccTypesMapper = $this->configCc->getCcTypesMapper($storeId);
$availableTypes = array_filter(explode(',', $types));

$result = [];
foreach ($availableTypes as $type) {
$code = trim($type);
if (isset($ccTypesMapper[$code])) {
$result[$code] = $ccTypesMapper[$code];
}
}

return $result;
}

/**
* Get Public Key
*
* @return string
*/
public function getPublicKey()
{
return $this->config->getMerchantGatewayPublicKey($this->_storeManager->getStore()->getId());
}

/**
* Get JS Form Config
*
* @return string
*/
public function getJsFormConfig()
{
$storeId = $this->_storeManager->getStore()->getId();
$config = [
'publicKey' => $this->getPublicKey(),
'ccTypesMapper' => $this->configCc->getCcTypesMapper($storeId)
];
return $this->serializer->serialize($config);
}
}
Loading

0 comments on commit 4e55c75

Please sign in to comment.