diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9defb5e4..15c452ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,19 +58,91 @@ jobs: - name: Check PHP sintax run: find . -name \*.php -exec php -l "{}" \; + phpunit: + name: PHP Unit + runs-on: ubuntu-latest + steps: + - name: Create Folder + run: ls -la && mkdir magento && cd magento && ls -la + + - name: Install Magento + uses: php-actions/composer@v6 + with: + php_version: 8.1 + command: "create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:2.4.5 ." + args: "--ignore-platform-reqs" + working_dir: /app/magento + env: + COMPOSER_AUTH: '{"http-basic": { "repo.magento.com": { "username": "${{ secrets.MAGENTO_KEY }}", "password": "${{secrets.MAGENTO_SECRET}}"}}}' + + - name: Change minimum stable to Dev + uses: php-actions/composer@v6 + with: + php_version: 8.1 + command: "config minimum-stability dev" + working_dir: /app/magento + + - name: Download Module + uses: php-actions/composer@v6 + with: + php_version: 8.1 + command: require pagarme/pagarme-magento2-module:dev-${{ github.head_ref }} + args: "--ignore-platform-reqs" + working_dir: /app/magento + env: + COMPOSER_AUTH: '{"http-basic": { "repo.magento.com": { "username": "${{ secrets.MAGENTO_KEY }}", "password": "${{secrets.MAGENTO_SECRET}}"}}}' + + - name: Download Mockery + uses: php-actions/composer@v6 + with: + php_version: 8.1 + command: require mockery/mockery + args: "--ignore-platform-reqs" + working_dir: /app/magento + env: + COMPOSER_AUTH: '{"http-basic": { "repo.magento.com": { "username": "${{ secrets.MAGENTO_KEY }}", "password": "${{secrets.MAGENTO_SECRET}}"}}}' + + - name: Run PHP Unit Tests + uses: php-actions/phpunit@v3 + env: + XDEBUG_MODE: coverage + with: + bootstrap: "/app/magento/vendor/autoload.php" + configuration: "/app/magento/vendor/pagarme/pagarme-magento2-module/phpunit.xml" + version: 9.5.28 + php_version : 8.1 + php_extensions: "xdebug" + + - name: Upload coverage artifact + uses: actions/upload-artifact@master + with: + name: mage-coverage-${{ github.sha }} + path: magento/vendor/pagarme/pagarme-magento2-module/clover.xml sonar: name: SonarCloud runs-on: ubuntu-latest + needs: phpunit steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 + - + name: Download coverage artifact + uses: actions/download-artifact@master + with: + name: mage-coverage-${{ github.sha }} + path: coverage - name: Run Sonar uses: sonarsource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + - name: Delete coverage artifact + uses: geekyeggo/delete-artifact@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + name: mage-coverage-${{ github.sha }} diff --git a/Api/TdsTokenInterface.php b/Api/TdsTokenInterface.php new file mode 100644 index 00000000..810b0c55 --- /dev/null +++ b/Api/TdsTokenInterface.php @@ -0,0 +1,11 @@ +account = $account; } diff --git a/Block/Adminhtml/Form/Field/GatewayField.php b/Block/Adminhtml/Form/Field/GatewayField.php index fbdcb808..d8fb185d 100644 --- a/Block/Adminhtml/Form/Field/GatewayField.php +++ b/Block/Adminhtml/Form/Field/GatewayField.php @@ -5,7 +5,6 @@ use Magento\Backend\Block\Template\Context; use Magento\Config\Block\System\Config\Form\Field; use Magento\Framework\Data\Form\Element\AbstractElement; -use Magento\Framework\View\Helper\SecureHtmlRenderer; use Pagarme\Pagarme\Model\Account; class GatewayField extends Field @@ -25,16 +24,14 @@ class GatewayField extends Field * @param Account $account * @param string $paymentMethodName * @param array $data - * @param SecureHtmlRenderer|null $secureRenderer */ public function __construct( Context $context, Account $account, string $paymentMethodName = '', - array $data = [], - ?SecureHtmlRenderer $secureRenderer = null + array $data = [] ) { - parent::__construct($context, $data, $secureRenderer); + parent::__construct($context, $data); $this->account = $account; $this->paymentMethodName = $paymentMethodName; } diff --git a/Block/Adminhtml/Form/Field/InstallmentsNumber.php b/Block/Adminhtml/Form/Field/InstallmentsNumber.php index 3a88a5f9..9fd93db0 100644 --- a/Block/Adminhtml/Form/Field/InstallmentsNumber.php +++ b/Block/Adminhtml/Form/Field/InstallmentsNumber.php @@ -6,7 +6,6 @@ use Magento\Config\Block\System\Config\Form\Field; use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory; use Magento\Framework\Data\Form\Element\AbstractElement; -use Magento\Framework\View\Helper\SecureHtmlRenderer; use Pagarme\Pagarme\Model\Account; use Pagarme\Pagarme\Model\PagarmeConfigProvider; @@ -22,16 +21,14 @@ class InstallmentsNumber extends Field * @param CollectionFactory $configCollectionFactory * @param Account $account * @param array $data - * @param SecureHtmlRenderer|null $secureRenderer */ public function __construct( Context $context, CollectionFactory $configCollectionFactory, Account $account, - array $data = [], - ?SecureHtmlRenderer $secureRenderer = null + array $data = [] ) { - parent::__construct($context, $data, $secureRenderer); + parent::__construct($context, $data); $this->configCollectionFactory = $configCollectionFactory; $this->account = $account; } diff --git a/Block/Adminhtml/Form/Field/SoftDescriptor.php b/Block/Adminhtml/Form/Field/SoftDescriptor.php index cf52e3d4..aeefd603 100644 --- a/Block/Adminhtml/Form/Field/SoftDescriptor.php +++ b/Block/Adminhtml/Form/Field/SoftDescriptor.php @@ -5,7 +5,6 @@ use Magento\Backend\Block\Template\Context; use Magento\Config\Block\System\Config\Form\Field; use Magento\Framework\Data\Form\Element\AbstractElement; -use Magento\Framework\View\Helper\SecureHtmlRenderer; use Pagarme\Pagarme\Model\Account; class SoftDescriptor extends Field @@ -25,16 +24,14 @@ class SoftDescriptor extends Field * @param Account $account * @param string $paymentMethodName * @param array $data - * @param SecureHtmlRenderer|null $secureRenderer */ public function __construct( Context $context, Account $account, string $paymentMethodName = '', - array $data = [], - ?SecureHtmlRenderer $secureRenderer = null + array $data = [] ) { - parent::__construct($context, $data, $secureRenderer); + parent::__construct($context, $data); $this->account = $account; $this->paymentMethodName = $paymentMethodName; } diff --git a/Block/Adminhtml/Form/Fieldset/CreditCardGatewayFieldset.php b/Block/Adminhtml/Form/Fieldset/CreditCardGatewayFieldset.php index 01395772..441499b5 100644 --- a/Block/Adminhtml/Form/Fieldset/CreditCardGatewayFieldset.php +++ b/Block/Adminhtml/Form/Fieldset/CreditCardGatewayFieldset.php @@ -7,7 +7,6 @@ use Magento\Config\Block\System\Config\Form\Fieldset; use Magento\Framework\Data\Form\Element\AbstractElement; use Magento\Framework\View\Helper\Js; -use Magento\Framework\View\Helper\SecureHtmlRenderer; use Pagarme\Pagarme\Model\Account; use Pagarme\Pagarme\Model\PagarmeConfigProvider; @@ -24,17 +23,15 @@ class CreditCardGatewayFieldset extends Fieldset * @param Js $jsHelper * @param Account $account * @param array $data - * @param SecureHtmlRenderer|null $secureRenderer */ public function __construct( Context $context, Session $authSession, Js $jsHelper, Account $account, - array $data = [], - ?SecureHtmlRenderer $secureRenderer = null + array $data = [] ) { - parent::__construct($context, $authSession, $jsHelper, $data, $secureRenderer); + parent::__construct($context, $authSession, $jsHelper, $data); $this->account = $account; } diff --git a/Block/Adminhtml/Form/Fieldset/CustomPaymentFieldset.php b/Block/Adminhtml/Form/Fieldset/CustomPaymentFieldset.php index c0453484..43e64d75 100644 --- a/Block/Adminhtml/Form/Fieldset/CustomPaymentFieldset.php +++ b/Block/Adminhtml/Form/Fieldset/CustomPaymentFieldset.php @@ -7,7 +7,6 @@ use Magento\Config\Block\System\Config\Form\Fieldset; use Magento\Framework\Data\Form\Element\AbstractElement; use Magento\Framework\View\Helper\Js; -use Magento\Framework\View\Helper\SecureHtmlRenderer; use Pagarme\Pagarme\Model\Account; class CustomPaymentFieldset extends Fieldset @@ -29,7 +28,6 @@ class CustomPaymentFieldset extends Fieldset * @param Account $account * @param string $paymentMethodName * @param array $data - * @param SecureHtmlRenderer|null $secureRenderer */ public function __construct( Context $context, @@ -37,10 +35,9 @@ public function __construct( Js $jsHelper, Account $account, string $paymentMethodName = '', - array $data = [], - ?SecureHtmlRenderer $secureRenderer = null + array $data = [] ) { - parent::__construct($context, $authSession, $jsHelper, $data, $secureRenderer); + parent::__construct($context, $authSession, $jsHelper, $data); $this->account = $account; $this->paymentMethodName = $paymentMethodName; } diff --git a/Block/Adminhtml/System/Config/Form/Field/HubIntegration.php b/Block/Adminhtml/System/Config/Form/Field/HubIntegration.php index a2e0e9fc..c7fa226a 100644 --- a/Block/Adminhtml/System/Config/Form/Field/HubIntegration.php +++ b/Block/Adminhtml/System/Config/Form/Field/HubIntegration.php @@ -7,7 +7,6 @@ use Magento\Config\Block\System\Config\Form\Field; use Magento\Framework\Data\Form\Element\AbstractElement; use Magento\Framework\Phrase; -use Magento\Framework\View\Helper\SecureHtmlRenderer; use Pagarme\Core\Hub\Services\HubIntegrationService; use Pagarme\Pagarme\Concrete\Magento2CoreSetup; use Pagarme\Pagarme\Model\Account; @@ -22,11 +21,10 @@ class HubIntegration extends Field public function __construct( Account $account, Context $context, - array $data = [], - ?SecureHtmlRenderer $secureRenderer = null + array $data = [] ) { $this->account = $account; - parent::__construct($context, $data, $secureRenderer); + parent::__construct($context, $data); } /** diff --git a/Block/Payment/Info/CreditCard.php b/Block/Payment/Info/CreditCard.php index 9d15ecbe..8a79027e 100644 --- a/Block/Payment/Info/CreditCard.php +++ b/Block/Payment/Info/CreditCard.php @@ -15,10 +15,10 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Payment\Block\Info\Cc; use Pagarme\Core\Kernel\Aggregates\Charge; -use Pagarme\Core\Kernel\Aggregates\Order; use Pagarme\Core\Kernel\Exceptions\InvalidParamException; use Pagarme\Core\Kernel\Services\OrderService; use Pagarme\Core\Kernel\ValueObjects\Id\OrderId; +use Pagarme\Core\Payment\Aggregates\Payments\Authentication\AuthenticationStatusEnum; use Pagarme\Pagarme\Concrete\Magento2CoreSetup; use Pagarme\Pagarme\Concrete\Magento2PlatformOrderDecorator; @@ -42,14 +42,6 @@ public function getCcType() return $this->getCcTypeName(); } - /** - * @return string - */ - public function getCardNumber() - { - return '**** **** **** ' . $this->getInfo()->getCcLast4(); - } - /** * @return string */ @@ -82,6 +74,19 @@ public function getInstallments() return $this->getInfo()->getAdditionalInformation('cc_installments'); } + public function getThreeDSStatus() + { + $authenticationAdditionalInformation = $this->getInfo()->getAdditionalInformation('authentication'); + if (empty($authenticationAdditionalInformation)) { + return ''; + } + + $authentication = json_decode($authenticationAdditionalInformation, true); + return AuthenticationStatusEnum::statusMessage( + $authentication['trans_status'] ?? '' + ); + } + /** * @return array * @throws InvalidParamException @@ -109,7 +114,7 @@ public function getTransactionInfo() } $charge = current($orderObject->getCharges()); - + return array_merge( $charge->getAcquirerTidCapturedAndAutorize(), ['tid' => $this->getTid($charge)] diff --git a/Block/Payment/Info/Debit.php b/Block/Payment/Info/Debit.php index 7a5da5f9..81b52f39 100644 --- a/Block/Payment/Info/Debit.php +++ b/Block/Payment/Info/Debit.php @@ -2,9 +2,7 @@ namespace Pagarme\Pagarme\Block\Payment\Info; -use Magento\Payment\Block\Info\Cc; - -class Debit extends Cc +class Debit extends CreditCard { } diff --git a/Block/Payment/Tds.php b/Block/Payment/Tds.php new file mode 100644 index 00000000..3aed99ee --- /dev/null +++ b/Block/Payment/Tds.php @@ -0,0 +1,68 @@ +config = $config; + $this->creditCardConfig = $creditCardConfig; + $this->pagarmeConfig = $pagarmeConfig; + parent::__construct($context, $data); + } + + + public function getSdkUrl() + { + $url = 'https://3ds2.pagar.me/v1/3ds2.min.js'; + if ($this->pagarmeConfig->isSandboxMode()) { + $url = 'https://3ds2-sdx.pagar.me/v1/3ds2.min.js'; + } + return $url; + } + + public function canInitTds() + { + return $this->creditCardConfig->getTdsActive(); + } +} diff --git a/Concrete/Magento2PlatformCustomerDecorator.php b/Concrete/Magento2PlatformCustomerDecorator.php index c2fdaa6f..11465797 100644 --- a/Concrete/Magento2PlatformCustomerDecorator.php +++ b/Concrete/Magento2PlatformCustomerDecorator.php @@ -41,10 +41,13 @@ public function getPagarmeId() return $this->pagarmeId; } - /** @var $mpIdLegado deprecated */ - $mpIdLegado = $this->platformCustomer->getCustomAttribute('customer_id_pagarme'); - if (!empty($mpIdLegado->getValue())) { - $this->pagarmeId = $mpIdLegado; + /** @var $pagarmeIdLegacy deprecated */ + $pagarmeIdLegacy = $this->platformCustomer->getCustomAttribute('customer_id_pagarme'); + $isPagarmeIdLegacyValid = !empty($pagarmeIdLegacy) + && is_object($pagarmeIdLegacy) + && !empty($pagarmeIdLegacy->getValue()); + if ($isPagarmeIdLegacyValid) { + $this->pagarmeId = $pagarmeIdLegacy; return $this->pagarmeId; } @@ -88,7 +91,7 @@ public function getAddress() public function getPhones() { $customerToArray = $this->platformCustomer->__toArray(); - return $customerToArray["phones"]; + return $customerToArray["phones"]; } } diff --git a/Concrete/Magento2PlatformOrderDecorator.php b/Concrete/Magento2PlatformOrderDecorator.php index 323452e1..e32b537b 100644 --- a/Concrete/Magento2PlatformOrderDecorator.php +++ b/Concrete/Magento2PlatformOrderDecorator.php @@ -50,6 +50,7 @@ use Pagarme\Pagarme\Helper\Marketplace\WebkulHelper; use Pagarme\Pagarme\Model\PagarmeConfigProvider; use Pagarme\Pagarme\Model\Source\Bank; +use stdClass; class Magento2PlatformOrderDecorator extends AbstractPlatformOrderDecorator { @@ -903,7 +904,7 @@ private function extractBasePaymentData($additionalInformation) $customerId = $card->getCardId(); } - $newPaymentData = new \stdClass(); + $newPaymentData = new stdClass(); $newPaymentData->customerId = $customerId; $newPaymentData->brand = $brand; $newPaymentData->identifier = $identifier; @@ -916,6 +917,20 @@ private function extractBasePaymentData($additionalInformation) $newPaymentData->cvvCard = $additionalInformation['cc_cvv_card']; } + if (!empty($additionalInformation['authentication'])) { + $additionalInformation['authentication'] = json_decode($additionalInformation['authentication'], true); + $authentication = new stdClass(); + $authentication->type = 'threed_secure'; + $authentication->status = $additionalInformation['authentication']['trans_status']; + + $threeDSecure = new stdClass(); + $threeDSecure->mpi = 'pagarme'; + $threeDSecure->transactionId = $additionalInformation['authentication']['tds_server_trans_id']; + + $authentication->threeDSecure = $threeDSecure; + $newPaymentData->authentication = $authentication; + } + $amount = $this->getGrandTotal() - $this->getBaseTaxAmount(); $amount = number_format($amount, 2, '.', ''); $amount = str_replace('.', '', $amount ?? ''); @@ -967,7 +982,7 @@ private function extractPaymentDataFromPagarmeTwoCreditCard($additionalInformati $customerId = $card->getCardId(); } - $newPaymentData = new \stdClass(); + $newPaymentData = new stdClass(); $newPaymentData->customerId = $customerId; $newPaymentData->identifier = $identifier; $newPaymentData->brand = $brand; @@ -1024,7 +1039,7 @@ private function extractMultibuyerData( "{$prefix}_buyer_mobile_phone{$index}" => "mobilePhone" ]; - $multibuyer = new \stdClass(); + $multibuyer = new stdClass(); foreach ($fields as $key => $attribute) { $value = $additionalInformation[$key]; @@ -1078,7 +1093,7 @@ private function extractPaymentDataFromPagarmeBilletCreditcard( $customerId = $card->getCardId(); } - $newPaymentData = new \stdClass(); + $newPaymentData = new stdClass(); $newPaymentData->identifier = $identifier; $newPaymentData->customerId = $customerId; $newPaymentData->brand = $brand; @@ -1109,7 +1124,7 @@ private function extractPaymentDataFromPagarmeBilletCreditcard( //boleto - $newPaymentData = new \stdClass(); + $newPaymentData = new stdClass(); $amount = str_replace( ['.', ','], @@ -1138,7 +1153,7 @@ private function extractPaymentDataFromPagarmeBillet( &$paymentData, $payment ) { - $newPaymentData = new \stdClass(); + $newPaymentData = new stdClass(); $newPaymentData->amount = $this->moneyService->floatToCents($this->platformOrder->getGrandTotal()); $moduleConfiguration = MPSetup::getModuleConfiguration(); @@ -1175,7 +1190,7 @@ private function extractPaymentDataFromPagarmePix( &$paymentData, $payment ) { - $newPaymentData = new \stdClass(); + $newPaymentData = new stdClass(); $newPaymentData->amount = $this->moneyService->floatToCents($this->platformOrder->getGrandTotal()); diff --git a/Gateway/Transaction/Base/Command/InitializeCommand.php b/Gateway/Transaction/Base/Command/InitializeCommand.php index 107f7027..4b540498 100755 --- a/Gateway/Transaction/Base/Command/InitializeCommand.php +++ b/Gateway/Transaction/Base/Command/InitializeCommand.php @@ -22,18 +22,33 @@ use Pagarme\Core\Kernel\Interfaces\PlatformOrderInterface; use Pagarme\Core\Kernel\Services\OrderLogService; use Pagarme\Core\Kernel\Services\OrderService; -use Pagarme\Core\Recurrence\Services\RecurrenceService; use Pagarme\Core\Recurrence\Services\SubscriptionService; use Pagarme\Pagarme\Concrete\Magento2CoreSetup; -use Pagarme\Pagarme\Concrete\Magento2PlatformPaymentMethodDecorator; -use Pagarme\Pagarme\Model\Ui\CreditCard\ConfigProvider; +use Pagarme\Pagarme\Model\Ui\CreditCard\ConfigProvider as CreditConfigProvider; use Pagarme\Pagarme\Model\Ui\TwoCreditCard\ConfigProvider as TwoCreditCardConfigProvider; use Magento\Framework\Phrase; use Magento\Framework\Webapi\Exception as M2WebApiException; use Pagarme\Pagarme\Helper\RecurrenceProductHelper; +use Pagarme\Pagarme\Gateway\Transaction\Base\Config\Config; +use Pagarme\Pagarme\Service\Transaction\ThreeDSService; class InitializeCommand implements CommandInterface { + + protected $config; + /** + * @var ThreeDSService + */ + protected $threeDSService; + + public function __construct( + Config $config, + ThreeDSService $threeDSService + ){ + $this->config = $config; + $this->threeDSService = $threeDSService; + } + /** * @param array $commandSubject * @return $this @@ -76,12 +91,14 @@ public function execute(array $commandSubject) $stateObject->setData(OrderInterface::STATE, Order::STATE_PENDING_PAYMENT); - if ($payment->getMethod() === ConfigProvider::CODE || $payment->getMethod() === TwoCreditCardConfigProvider::CODE) { + if ($payment->getMethod() === CreditConfigProvider::CODE + || $payment->getMethod() === TwoCreditCardConfigProvider::CODE + ) { $stateObject->setData(OrderInterface::STATE, $customStatus->getData('state')); $stateObject->setData(OrderInterface::STATUS, $customStatus->getData('status')); } - if ($payment->getMethod() != ConfigProvider::CODE) { + if ($payment->getMethod() !== CreditConfigProvider::CODE) { $stateObject->setData(OrderInterface::STATUS, $payment->getMethodInstance()->getConfigData('order_status')); } @@ -94,7 +111,9 @@ public function execute(array $commandSubject) private function doCoreDetour($payment) { $order = $payment->getOrder(); - + if($this->config->getAlwaysCreateOrder()){ + $order->save(); + } $log = new OrderLogService(); Magento2CoreSetup::bootstrap(); @@ -139,6 +158,10 @@ private function doCoreDetour($payment) $subscriptionService = new SubscriptionService(); $isSubscription = $subscriptionService->isSubscription($orderDecorator); + if ($this->threeDSService->hasThreeDSAuthorization($payment)) { + $this->threeDSService->processDeclinedThreeDsTransaction($payment, $orderDecorator); + } + if ($isSubscription) { $subscriptionService->createSubscriptionAtPagarme($orderDecorator); } diff --git a/Gateway/Transaction/Base/Config/AbstractConfig.php b/Gateway/Transaction/Base/Config/AbstractConfig.php index 3d0732cb..9713c947 100755 --- a/Gateway/Transaction/Base/Config/AbstractConfig.php +++ b/Gateway/Transaction/Base/Config/AbstractConfig.php @@ -15,7 +15,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; -abstract class AbstractConfig +abstract class AbstractConfig implements CustomerConfigInterface { protected $storeConfig; @@ -60,4 +60,36 @@ protected function setStoreConfig(ScopeConfigInterface $storeConfig) $this->storeConfig = $storeConfig; return $this; } + + /** + * @return string + */ + public function getCustomerStreetAttribute() + { + return $this->getConfig(static::PATH_CUSTOMER_STREET); + } + + /** + * @return string + */ + public function getCustomerAddressNumber() + { + return $this->getConfig(static::PATH_CUSTOMER_NUMBER); + } + + /** + * @return string + */ + public function getCustomerAddressComplement() + { + return $this->getConfig(static::PATH_CUSTOMER_COMPLEMENT); + } + + /** + * @return string + */ + public function getCustomerAddressDistrict() + { + return $this->getConfig(static::PATH_CUSTOMER_DISTRICT); + } } diff --git a/Gateway/Transaction/Base/Config/Config.php b/Gateway/Transaction/Base/Config/Config.php index 949abfb0..5f1ec188 100755 --- a/Gateway/Transaction/Base/Config/Config.php +++ b/Gateway/Transaction/Base/Config/Config.php @@ -45,7 +45,14 @@ public function getPublicKey() return $this->getConfig(static::PATH_PUBLIC_KEY); } - + /** + * @return string + */ + public function getAlwaysCreateOrder() + { + return $this->getConfig('pagarme_pagarme/global/create_order'); + } + /** * @return bool */ @@ -139,4 +146,17 @@ public function getPagarmeCustomerConfigs() 'streetLinesNumber' => $this->getConfig(static::PATH_CUSTOMER_ADDRESS_LINES) ?? '', ]; } + + /** + * @return array + */ + public function getPagarmeCustomerAddressConfigs() + { + return [ + 'street' => $this->getConfig(static::PATH_CUSTOMER_ADDRESS_STREET) ?? '', + 'number' => $this->getConfig(static::PATH_CUSTOMER_ADDRESS_NUMBER) ?? '', + 'complement' => $this->getConfig(static::PATH_CUSTOMER_ADDRESS_COMPLEMENT) ?? '', + 'neighborhood' => $this->getConfig(static::PATH_CUSTOMER_ADDRESS_NEIGHBOURHOOD) ?? '', + ]; + } } diff --git a/Gateway/Transaction/Base/Config/ConfigInterface.php b/Gateway/Transaction/Base/Config/ConfigInterface.php index c2319c23..423e956f 100755 --- a/Gateway/Transaction/Base/Config/ConfigInterface.php +++ b/Gateway/Transaction/Base/Config/ConfigInterface.php @@ -33,17 +33,17 @@ interface ConfigInterface const PATH_SEND_EMAIL = 'pagarme_pagarme/global/sendmail'; - const PATH_CUSTOMER_STREET = 'payment/pagarme_customer_address/street_attribute'; + const PATH_CUSTOMER_VAT_NUMBER = 'customer/create_account/vat_frontend_visibility'; - const PATH_CUSTOMER_NUMBER = 'payment/pagarme_customer_address/number_attribute'; + const PATH_CUSTOMER_ADDRESS_LINES = 'customer/address/street_lines'; - const PATH_CUSTOMER_COMPLEMENT = 'payment/pagarme_customer_address/complement_attribute'; + const PATH_CUSTOMER_ADDRESS_STREET = 'payment/pagarme_customer_address/street_attribute'; - const PATH_CUSTOMER_DISTRICT = 'payment/pagarme_customer_address/district_attribute'; + const PATH_CUSTOMER_ADDRESS_NUMBER = 'payment/pagarme_customer_address/number_attribute'; - const PATH_CUSTOMER_VAT_NUMBER = 'customer/create_account/vat_frontend_visibility'; + const PATH_CUSTOMER_ADDRESS_COMPLEMENT = 'payment/pagarme_customer_address/complement_attribute'; - const PATH_CUSTOMER_ADDRESS_LINES = 'customer/address/street_lines'; + const PATH_CUSTOMER_ADDRESS_NEIGHBOURHOOD = 'payment/pagarme_customer_address/district_attribute'; const HUB_SANDBOX_ENVIRONMENT = 'Sandbox'; @@ -77,31 +77,15 @@ public function isHubEnabled(); */ public function getTestMode(); - /** - * @return string - */ - public function getCustomerStreetAttribute(); - - /** - * @return string - */ - public function getCustomerAddressNumber(); - - /** - * @return string - */ - public function getCustomerAddressComplement(); - - /** - * @return string + * @return array */ - public function getCustomerAddressDistrict(); + public function getPagarmeCustomerConfigs(); /** * @return array */ - public function getPagarmeCustomerConfigs(); + public function getPagarmeCustomerAddressConfigs(); /** * @return bool diff --git a/Gateway/Transaction/Base/Config/CustomerConfigInterface.php b/Gateway/Transaction/Base/Config/CustomerConfigInterface.php new file mode 100644 index 00000000..dc77fb02 --- /dev/null +++ b/Gateway/Transaction/Base/Config/CustomerConfigInterface.php @@ -0,0 +1,31 @@ +getConfig(static::PATH_EXPIRATION_DAYS); } - /** - * @return string - */ - public function getCustomerStreetAttribute() - { - return $this->getConfig(static::PATH_CUSTOMER_STREET); - } - - /** - * @return string - */ - public function getCustomerAddressNumber() - { - return $this->getConfig(static::PATH_CUSTOMER_NUMBER); - } - - /** - * @return string - */ - public function getCustomerAddressComplement() - { - return $this->getConfig(static::PATH_CUSTOMER_COMPLEMENT); - } - - /** - * @return string - */ - public function getCustomerAddressDistrict() - { - return $this->getConfig(static::PATH_CUSTOMER_DISTRICT); - } - /** * @return string */ diff --git a/Gateway/Transaction/Billet/Config/ConfigInterface.php b/Gateway/Transaction/Billet/Config/ConfigInterface.php index 0e68ccc4..981067d9 100755 --- a/Gateway/Transaction/Billet/Config/ConfigInterface.php +++ b/Gateway/Transaction/Billet/Config/ConfigInterface.php @@ -18,10 +18,6 @@ interface ConfigInterface const PATH_TEXT = 'payment/pagarme_billet/text'; const PATH_TYPE_BANK = 'payment/pagarme_billet/types'; const PATH_EXPIRATION_DAYS = 'payment/pagarme_billet/expiration_days'; - const PATH_CUSTOMER_STREET = 'payment/pagarme_customer_address/street_attribute'; - const PATH_CUSTOMER_NUMBER = 'payment/pagarme_customer_address/number_attribute'; - const PATH_CUSTOMER_COMPLEMENT = 'payment/pagarme_customer_address/complement_attribute'; - const PATH_CUSTOMER_DISTRICT = 'payment/pagarme_customer_address/district_attribute'; const PATH_TITLE = 'payment/pagarme_billet/title'; /** diff --git a/Gateway/Transaction/BilletCreditCard/Config/Config.php b/Gateway/Transaction/BilletCreditCard/Config/Config.php index f423eb79..f0b845e7 100644 --- a/Gateway/Transaction/BilletCreditCard/Config/Config.php +++ b/Gateway/Transaction/BilletCreditCard/Config/Config.php @@ -56,39 +56,6 @@ public function getAntifraudMinAmount() return $this->getConfig(static::PATH_ANTIFRAUD_MIN_AMOUNT); } - - /** - * @return string - */ - public function getCustomerStreetAttribute() - { - return $this->getConfig(static::PATH_CUSTOMER_STREET); - } - - /** - * @return string - */ - public function getCustomerAddressNumber() - { - return $this->getConfig(static::PATH_CUSTOMER_NUMBER); - } - - /** - * @return string - */ - public function getCustomerAddressComplement() - { - return $this->getConfig(static::PATH_CUSTOMER_COMPLEMENT); - } - - /** - * @return string - */ - public function getCustomerAddressDistrict() - { - return $this->getConfig(static::PATH_CUSTOMER_DISTRICT); - } - /** * @return string */ diff --git a/Gateway/Transaction/BilletCreditCard/Config/ConfigInterface.php b/Gateway/Transaction/BilletCreditCard/Config/ConfigInterface.php index 39460ce5..77b32d7a 100644 --- a/Gateway/Transaction/BilletCreditCard/Config/ConfigInterface.php +++ b/Gateway/Transaction/BilletCreditCard/Config/ConfigInterface.php @@ -19,10 +19,6 @@ interface ConfigInterface const PATH_PAYMENT_ACTION = 'payment/pagarme_billet_creditcard/payment_action'; const PATH_ANTIFRAUD_ACTIVE = 'payment/pagarme_billet_creditcard/antifraud_active'; const PATH_ANTIFRAUD_MIN_AMOUNT = 'payment/pagarme_billet_creditcard/antifraud_min_amount'; - const PATH_CUSTOMER_STREET = 'payment/pagarme_customer_address/street_attribute'; - const PATH_CUSTOMER_NUMBER = 'payment/pagarme_customer_address/number_attribute'; - const PATH_CUSTOMER_COMPLEMENT = 'payment/pagarme_customer_address/complement_attribute'; - const PATH_CUSTOMER_DISTRICT = 'payment/pagarme_customer_address/district_attribute'; const PATH_TITLE = 'payment/pagarme_billet_creditcard/title'; /** @@ -50,26 +46,6 @@ public function getAntifraudActive(); */ public function getAntifraudMinAmount(); - /** - * @return string - */ - public function getCustomerStreetAttribute(); - - /** - * @return string - */ - public function getCustomerAddressNumber(); - - /** - * @return string - */ - public function getCustomerAddressComplement(); - - /** - * @return string - */ - public function getCustomerAddressDistrict(); - /** * @return string */ diff --git a/Gateway/Transaction/CreditCard/Config/Config.php b/Gateway/Transaction/CreditCard/Config/Config.php index 547f1fc6..cd9a9982 100755 --- a/Gateway/Transaction/CreditCard/Config/Config.php +++ b/Gateway/Transaction/CreditCard/Config/Config.php @@ -11,10 +11,10 @@ namespace Pagarme\Pagarme\Gateway\Transaction\CreditCard\Config; - +use Pagarme\Pagarme\Gateway\Transaction\Base\Config\TdsConfigInterface; use Pagarme\Pagarme\Gateway\Transaction\Base\Config\AbstractConfig; -class Config extends AbstractConfig implements ConfigInterface +class Config extends AbstractConfig implements ConfigInterface, TdsConfigInterface { /** * {@inheritdoc} @@ -49,64 +49,57 @@ public function getTitle() /** * {@inheritdoc} */ - public function getPaymentAction() + public function getTdsActive() { - return $this->getConfig(static::PATH_PAYMENT_ACTION); + return (bool) $this->getConfig(static::PATH_TDS_ACTIVE); } /** - * @return bool + * {@inheritdoc} */ - public function getAntifraudActive() + public function getOrderWithTdsRefused() { - return $this->getConfig(static::PATH_ANTIFRAUD_ACTIVE); + return (bool) $this->getConfig(static::PATH_ORDER_WITH_TDS_REFUSED); } /** * @return string */ - public function getAntifraudMinAmount() + public function getTdsMinAmount() { - return $this->getConfig(static::PATH_ANTIFRAUD_MIN_AMOUNT); + return $this->getConfig(static::PATH_TDS_MIN_AMOUNT); } /** - * @return string + * {@inheritdoc} */ - public function getSoftDescription() + public function getPaymentAction() { - return $this->getConfig(static::PATH_SOFT_DESCRIPTION); + return $this->getConfig(static::PATH_PAYMENT_ACTION); } /** - * @return string + * @return bool */ - public function getCustomerStreetAttribute() + public function getAntifraudActive() { - return $this->getConfig(static::PATH_CUSTOMER_STREET); + return $this->getConfig(static::PATH_ANTIFRAUD_ACTIVE); } /** * @return string */ - public function getCustomerAddressNumber() + public function getAntifraudMinAmount() { - return $this->getConfig(static::PATH_CUSTOMER_NUMBER); + return $this->getConfig(static::PATH_ANTIFRAUD_MIN_AMOUNT); } /** * @return string */ - public function getCustomerAddressComplement() + public function getSoftDescription() { - return $this->getConfig(static::PATH_CUSTOMER_COMPLEMENT); + return $this->getConfig(static::PATH_SOFT_DESCRIPTION); } - /** - * @return string - */ - public function getCustomerAddressDistrict() - { - return $this->getConfig(static::PATH_CUSTOMER_DISTRICT); - } } diff --git a/Gateway/Transaction/CreditCard/Config/ConfigInterface.php b/Gateway/Transaction/CreditCard/Config/ConfigInterface.php index 6671ec74..9721a136 100755 --- a/Gateway/Transaction/CreditCard/Config/ConfigInterface.php +++ b/Gateway/Transaction/CreditCard/Config/ConfigInterface.php @@ -16,14 +16,13 @@ interface ConfigInterface { const PATH_ACTIVE = 'payment/pagarme_creditcard/active'; const PATH_ENABLED_SAVED_CARDS = 'payment/pagarme_creditcard/enabled_saved_cards'; + const PATH_TDS_ACTIVE = 'payment/pagarme_creditcard/tds_active'; + const PATH_ORDER_WITH_TDS_REFUSED = 'payment/pagarme_creditcard/order_with_tds_refused'; + const PATH_TDS_MIN_AMOUNT = 'payment/pagarme_creditcard/tds_min_amount'; const PATH_PAYMENT_ACTION = 'payment/pagarme_creditcard/payment_action'; const PATH_ANTIFRAUD_ACTIVE = 'payment/pagarme_creditcard/antifraud_active'; const PATH_ANTIFRAUD_MIN_AMOUNT = 'payment/pagarme_creditcard/antifraud_min_amount'; const PATH_SOFT_DESCRIPTION = 'payment/pagarme_creditcard/soft_description'; - const PATH_CUSTOMER_STREET = 'payment/pagarme_customer_address/street_attribute'; - const PATH_CUSTOMER_NUMBER = 'payment/pagarme_customer_address/number_attribute'; - const PATH_CUSTOMER_COMPLEMENT = 'payment/pagarme_customer_address/complement_attribute'; - const PATH_CUSTOMER_DISTRICT = 'payment/pagarme_customer_address/district_attribute'; const PATH_TITLE = 'payment/pagarme_creditcard/title'; /** @@ -56,26 +55,6 @@ public function getAntifraudMinAmount(); */ public function getSoftDescription(); - /** - * @return string - */ - public function getCustomerStreetAttribute(); - - /** - * @return string - */ - public function getCustomerAddressNumber(); - - /** - * @return string - */ - public function getCustomerAddressComplement(); - - /** - * @return string - */ - public function getCustomerAddressDistrict(); - /** * @return string */ diff --git a/Gateway/Transaction/DebitCard/Config/Config.php b/Gateway/Transaction/DebitCard/Config/Config.php new file mode 100755 index 00000000..75101004 --- /dev/null +++ b/Gateway/Transaction/DebitCard/Config/Config.php @@ -0,0 +1,55 @@ +getConfig(static::PATH_ACTIVE); + } + + /** + * {@inheritdoc} + */ + public function getEnabledSavedCards() + { + return (bool) $this->getConfig(static::PATH_ENABLED_SAVED_CARDS); + } + /** + * @return string + */ + public function getTitle() + { + $title = $this->getConfig(static::PATH_TITLE); + + if(empty($title)){ + return __('Pagar.me Credit Card'); + } + + return $title; + } + + /** + * {@inheritdoc} + */ + public function getPaymentAction() + { + return $this->getConfig(static::PATH_PAYMENT_ACTION); + } +} diff --git a/Gateway/Transaction/DebitCard/Config/ConfigInterface.php b/Gateway/Transaction/DebitCard/Config/ConfigInterface.php new file mode 100755 index 00000000..2f90ae51 --- /dev/null +++ b/Gateway/Transaction/DebitCard/Config/ConfigInterface.php @@ -0,0 +1,44 @@ +getConfig(static::PATH_SOFT_DESCRIPTION); } - - /** - * @return string - */ - public function getCustomerStreetAttribute() - { - return $this->getConfig(static::PATH_CUSTOMER_STREET); - } - - /** - * @return string - */ - public function getCustomerAddressNumber() - { - return $this->getConfig(static::PATH_CUSTOMER_NUMBER); - } - - /** - * @return string - */ - public function getCustomerAddressComplement() - { - return $this->getConfig(static::PATH_CUSTOMER_COMPLEMENT); - } - - /** - * @return string - */ - public function getCustomerAddressDistrict() - { - return $this->getConfig(static::PATH_CUSTOMER_DISTRICT); - } - /** * @return string */ diff --git a/Gateway/Transaction/TwoCreditCard/Config/ConfigInterface.php b/Gateway/Transaction/TwoCreditCard/Config/ConfigInterface.php index 1c01ed7a..6a01e4e0 100644 --- a/Gateway/Transaction/TwoCreditCard/Config/ConfigInterface.php +++ b/Gateway/Transaction/TwoCreditCard/Config/ConfigInterface.php @@ -19,10 +19,6 @@ interface ConfigInterface const PATH_ANTIFRAUD_ACTIVE = 'payment/pagarme_two_creditcard/antifraud_active'; const PATH_ANTIFRAUD_MIN_AMOUNT = 'payment/pagarme_two_creditcard/antifraud_min_amount'; const PATH_SOFT_DESCRIPTION = 'payment/pagarme_creditcard/soft_description'; - const PATH_CUSTOMER_STREET = 'payment/pagarme_customer_address/street_attribute'; - const PATH_CUSTOMER_NUMBER = 'payment/pagarme_customer_address/number_attribute'; - const PATH_CUSTOMER_COMPLEMENT = 'payment/pagarme_customer_address/complement_attribute'; - const PATH_CUSTOMER_DISTRICT = 'payment/pagarme_customer_address/district_attribute'; const PATH_TITLE = 'payment/pagarme_two_creditcard/title'; /** diff --git a/Model/Graphql/PixDataProvider.php b/Model/Graphql/PixDataProvider.php index b02926fe..55d87a0f 100644 --- a/Model/Graphql/PixDataProvider.php +++ b/Model/Graphql/PixDataProvider.php @@ -3,6 +3,13 @@ namespace Pagarme\Pagarme\Model\Graphql; +if (!class_exists('\Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface')) { + class PixDataProvider { + + } + return; +} + use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface; /** diff --git a/Model/PagarmeConfigProvider.php b/Model/PagarmeConfigProvider.php index 2917e363..3e177702 100644 --- a/Model/PagarmeConfigProvider.php +++ b/Model/PagarmeConfigProvider.php @@ -411,6 +411,7 @@ public function getConfig(): array 'pagarme_is_sandbox_mode' => $this->pagarmeConfig->isSandboxMode(), 'pagarme_is_hub_enabled' => $this->pagarmeConfig->isHubEnabled(), 'pagarme_customer_configs' => $this->pagarmeConfig->getPagarmeCustomerConfigs(), + 'pagarme_customer_address_configs' => $this->pagarmeConfig->getPagarmeCustomerAddressConfigs() ] ; } diff --git a/Model/TdsToken.php b/Model/TdsToken.php new file mode 100644 index 00000000..ea9f37bb --- /dev/null +++ b/Model/TdsToken.php @@ -0,0 +1,37 @@ +pagarmeConfig = $pagarmeConfig; + $this->tdsTokenService = $tdsTokenService; + } + public function getToken() + { + $accountId = $this->pagarmeConfig->getAccountId(); + if (empty($accountId)) { + return []; + } + return $this->tdsTokenService->getTdsToken($accountId); + } +} diff --git a/Model/Ui/CreditCard/ConfigProvider.php b/Model/Ui/CreditCard/ConfigProvider.php index b90c8f8a..5ad7c6b1 100755 --- a/Model/Ui/CreditCard/ConfigProvider.php +++ b/Model/Ui/CreditCard/ConfigProvider.php @@ -98,8 +98,10 @@ public function getConfig() 'active' => $this->getCreditCardConfig()->getActive(), 'title' => $this->getCreditCardConfig()->getTitle(), 'is_saved_card' => $is_saved_card, - 'enabled_saved_cards' => $this->getCreditCardConfig() - ->getEnabledSavedCards(), + 'enabled_saved_cards' => $this->getCreditCardConfig()->getEnabledSavedCards(), + 'tds_active' => $this->getCreditCardConfig()->getTdsActive(), + 'order_with_tds_refused' => $this->getCreditCardConfig()->getOrderWithTdsRefused(), + 'tds_min_amount' => $this->getCreditCardConfig()->getTdsMinAmount(), 'cards' => $cards, 'selected_card' => $selectedCard, 'size_credit_card' => '18', diff --git a/Model/Ui/Debit/ConfigProvider.php b/Model/Ui/Debit/ConfigProvider.php index 6d8af6a0..6985ee71 100644 --- a/Model/Ui/Debit/ConfigProvider.php +++ b/Model/Ui/Debit/ConfigProvider.php @@ -7,7 +7,7 @@ use Pagarme\Core\Kernel\ValueObjects\Configuration\DebitConfig; use Pagarme\Core\Payment\Repositories\CustomerRepository; use Pagarme\Core\Payment\Repositories\SavedCardRepository; -use Pagarme\Pagarme\Concrete\Magento2CoreSetup as MPSetup; +use Pagarme\Pagarme\Gateway\Transaction\DebitCard\Config\ConfigInterface; final class ConfigProvider implements ConfigProviderInterface { @@ -25,14 +25,11 @@ final class ConfigProvider implements ConfigProviderInterface * @throws \Exception */ public function __construct( - Session $customerSession + Session $customerSession, + ConfigInterface $debitConfig ) { - MPSetup::bootstrap(); - $moduleConfig = MPSetup::getModuleConfiguration(); - if (!empty($moduleConfig->getDebitConfig())) { - $this->setDebitConfig($moduleConfig->getDebitConfig()); - } + $this->setDebitConfig($debitConfig); $this->setCustomerSession($customerSession); } @@ -84,12 +81,12 @@ public function getConfig() return [ 'payment' => [ self::CODE =>[ - 'active' => $this->getDebitConfig()->isEnabled(), + 'active' => $this->getDebitConfig()->getActive(), 'title' => $this->getDebitConfig()->getTitle(), 'size_credit_card' => '18', 'number_credit_card' => 'null', 'data_credit_card' => '', - 'enabled_saved_cards' => $this->getDebitConfig()->isSaveCards(), + 'enabled_saved_cards' => $this->getDebitConfig()->getEnabledSavedCards(), 'is_saved_card' => $isSavedCard, 'cards' => $cards, 'selected_card' => $selectedCard, @@ -107,10 +104,10 @@ protected function getDebitConfig() } /** - * @param DebitConfig $debitConfig + * @param ConfigInterface $debitConfig * @return $this */ - protected function setDebitConfig(DebitConfig $debitConfig) + protected function setDebitConfig(ConfigInterface $debitConfig) { $this->debitConfig = $debitConfig; return $this; diff --git a/Observer/CreditCardDataAssignObserver.php b/Observer/CreditCardDataAssignObserver.php index 1768b872..2429f9b0 100644 --- a/Observer/CreditCardDataAssignObserver.php +++ b/Observer/CreditCardDataAssignObserver.php @@ -56,7 +56,7 @@ public function execute(Observer $observer) $multiBuyerDataAssign = new MultiBuyerDataAssign(); $multiBuyerDataAssign->setCcMultiBuyer($info, $additionalData); - + $info->setAdditionalInformation('cc_installments', 1); if ($additionalData->getCcInstallments()) { @@ -113,6 +113,7 @@ private function fillNotSavedCardData($info, DataObject $additionalData) { $info->setAdditionalInformation('cc_saved_card', $additionalData->getCcSavedCard()); $info->setAdditionalInformation('cc_type', $additionalData->getCcType()); + $info->setAdditionalInformation('authentication', $additionalData->getAuthentication()); if ($additionalData->getCcLast4()) { $info->setAdditionalInformation( 'cc_last_4', diff --git a/Observer/CustomerAddressSaveBefore.php b/Observer/CustomerAddressSaveBefore.php index 48f7c330..4c93948e 100644 --- a/Observer/CustomerAddressSaveBefore.php +++ b/Observer/CustomerAddressSaveBefore.php @@ -62,7 +62,7 @@ public function addressValidation($customerAddress) throw new InputException(__("Please check your address. Country is required.")); } - if (empty($customerAddress->getName()) || strlen($customerAddress->getName()) > 65) { + if (empty($customerAddress->getName()) || mb_strlen($customerAddress->getName()) > 65) { throw new InputException(__("Please check your address. Name and firstname are required.")); } diff --git a/Observer/DebitDataAssignObserver.php b/Observer/DebitDataAssignObserver.php index cab3eb97..466a5508 100644 --- a/Observer/DebitDataAssignObserver.php +++ b/Observer/DebitDataAssignObserver.php @@ -47,7 +47,7 @@ public function execute(Observer $observer) $info->setAdditionalInformation('cc_saved_card', '0'); $info->setAdditionalInformation('cc_installments', 1); - + $multiBuyerDataAssign = new MultiBuyerDataAssign(); $multiBuyerDataAssign->setCcMultiBuyer($info, $additionalData); @@ -64,6 +64,7 @@ protected function setNewCardAdditionalData($info, $additionalData) { $info->setAdditionalInformation('cc_saved_card', $additionalData->getCcSavedCard()); $info->setAdditionalInformation('cc_type', $additionalData->getCcType()); + $info->setAdditionalInformation('authentication', $additionalData->getAuthentication()); if ($additionalData->getCcLast4()) { $info->setAdditionalInformation('cc_last_4', substr($additionalData->getCcLast4(),-4)); } diff --git a/Service/Transaction/TdsTokenService.php b/Service/Transaction/TdsTokenService.php new file mode 100644 index 00000000..a30a167e --- /dev/null +++ b/Service/Transaction/TdsTokenService.php @@ -0,0 +1,37 @@ +coreAuth = new CoreAuth(''); + $this->config = $config; + } + + public function getTdsToken($accountId) + { + $tdsTokenProxy = new TdsTokenProxy($this->coreAuth); + $environment = 'live'; + if ($this->config->isSandboxMode()) { + $environment = 'test'; + } + return $tdsTokenProxy->getTdsToken($environment, $accountId)->tdsToken; + } +} diff --git a/Service/Transaction/ThreeDSService.php b/Service/Transaction/ThreeDSService.php new file mode 100644 index 00000000..f83423b9 --- /dev/null +++ b/Service/Transaction/ThreeDSService.php @@ -0,0 +1,133 @@ +creditCardConfig = $creditCardConfig; + } + + /** + * @param Payment $payment + * @return bool + */ + public function hasThreeDSAuthorization(Payment $payment) + { + return $payment->getAdditionalInformation()['authentication'] ?? false; + } + + /** + * @param Payment $payment + * @param PlatformOrderInterface $orderDecorator + * @return void + * @throws PaymentException + */ + public function processDeclinedThreeDsTransaction(Payment $payment, PlatformOrderInterface $orderDecorator) + { + if ($this->isNotThreeDsPayment($payment) || $this->isAuthorizedThreeDsTransaction($payment)) { + return; + } + + if ($this->isOrderWithTdsRefusedDisabled($payment)) { + $forceCreateOrder = MPSetup::getModuleConfiguration()->isCreateOrderEnabled(); + if ($forceCreateOrder) { + $orderDecorator->setStatus(OrderStatus::canceled()); + $orderDecorator->setState(OrderState::canceled()); + $orderDecorator->save(); + + $errorMessage = "Can't create payment. Please review the information and try again."; + $logService = new OrderLogService(); + $logService->orderInfo( + $orderDecorator->getCode(), + $errorMessage + ); + $logService->orderInfo( + $orderDecorator->getCode(), + "Failed to create order at Pagarme!" + ); + + $errorMessage = __( + "Order # %1 : %2", + $orderDecorator->getCode(), + __($errorMessage) + ); + + throw new PaymentException(__($errorMessage), null, 400); + } + + + throw new PaymentException(__("Order declined, do not try again."), null, 400); + } + } + + /** + * @param Payment $payment + * @return bool + */ + private function isNotThreeDsPayment(Payment $payment) + { + $status = $this->getThreeDsTransaction($payment); + return ($payment->getMethod() !== CreditConfigProvider::CODE) + || empty($status); + } + + /** + * @param Payment $payment + * @return bool + */ + private function isAuthorizedThreeDsTransaction(Payment $payment) + { + $status = $this->getThreeDsTransaction($payment); + $additionalInformation = $payment->getAdditionalInformation(); + $ccBrand = $additionalInformation['cc_type'] ?? ''; + $ccBrand = ucfirst(strtolower($ccBrand)); + return in_array($status, AuthenticationStatusEnum::doesNotNeedToUseAntifraudStatuses()) + && ($ccBrand === CreditCardBrandEnum::VISA + || $ccBrand === CreditCardBrandEnum::MASTERCARD); + } + + /** + * @param Payment $payment + * @return bool + */ + private function isOrderWithTdsRefusedDisabled(Payment $payment) + { + return $payment->getMethod() === CreditConfigProvider::CODE + && !$this->creditCardConfig->getOrderWithTdsRefused(); + } + + /** + * @param Payment $payment + * @return string + */ + private function getThreeDsTransaction(Payment $payment) + { + $additionalInformation = $payment->getAdditionalInformation(); + $authentication = json_decode($additionalInformation['authentication'], true); + return $authentication['trans_status'] ?? ''; + } +} diff --git a/Test/Unit/BaseTest.php b/Test/Unit/BaseTest.php new file mode 100644 index 00000000..fcda9065 --- /dev/null +++ b/Test/Unit/BaseTest.php @@ -0,0 +1,14 @@ +paymentMock = Mockery::mock('Magento\Sales\Model\Order\Payment'); + $this->creditConfigMock = Mockery::mock('Pagarme\Pagarme\Gateway\Transaction\CreditCard\Config\Config'); + $this->mpSetupMock = Mockery::mock('alias:Pagarme\Core\Kernel\Abstractions\AbstractModuleCoreSetup'); + $this->platformOrderMock = Mockery::mock('Pagarme\Pagarme\Concrete\Magento2PlatformOrderDecorator'); + } + + public function testIfHasThreeDSAuthorization() + { + $tdsService = new ThreeDSService($this->creditConfigMock); + $paymentMock = $this->paymentMock; + $paymentMock->shouldReceive('getAdditionalInformation')->andReturn(['authentication' => '{"trans_status":"N", "cc_type":"visa"}']); + $hasAuth = $tdsService->hasThreeDSAuthorization($paymentMock); + $this->assertNotFalse($hasAuth); + } + + public function testIfNotHaveThreeDSAuthorization() + { + $tdsService = new ThreeDSService($this->creditConfigMock); + $paymentMock = $this->paymentMock; + $paymentMock->shouldReceive('getAdditionalInformation')->andReturn(true); + $hasAuth = $tdsService->hasThreeDSAuthorization($paymentMock); + $this->assertFalse($hasAuth); + } + + + public function testProcessDeclinedThreeDsTransaction() + { + $this->expectException('Magento\Framework\Exception\PaymentException'); + + $platformOrderMock = $this->platformOrderMock; + $platformOrderMock->shouldReceive('getCode')->andReturn('007'); + $platformOrderMock->shouldReceive('setStatus')->once()->andReturnSelf(); + $platformOrderMock->shouldReceive('setState')->once()->andReturnSelf(); + $platformOrderMock->shouldReceive('save')->once()->andReturnSelf(); + + $mpSetupMock = $this->mpSetupMock; + $mpSetupMock->shouldReceive('getLogPath')->andReturn("./temp/"); + $mpSetupMock->shouldReceive('getModuleConfiguration')->andReturnSelf(); + $mpSetupMock->shouldReceive('isCreateOrderEnabled')->andReturn(true); + + $paymentMock = $this->paymentMock; + $paymentMock->shouldReceive('getStatus')->andReturn('N'); + $paymentMock->shouldReceive('getMethod')->andReturn(CreditCardConfigProvider::CODE); + $paymentMock->shouldReceive('getAdditionalInformation')->andReturn(['authentication' => '{"trans_status":"N", "cc_type":"visa"}']); + + $this->creditConfigMock->shouldReceive('getOrderWithTdsRefused')->andReturn(false); + + $tdsService = new ThreeDSService($this->creditConfigMock); + $tdsService->processDeclinedThreeDsTransaction($paymentMock, $platformOrderMock); + } + + public function testProcessDeclinedThreeDsTransactionButIsNotTdsPayment() + { + $platformOrderMock = $this->platformOrderMock; + + $paymentMock = $this->paymentMock; + $paymentMock->shouldReceive('getMethod')->andReturn(CreditCardConfigProvider::CODE); + $paymentMock->shouldReceive('getAdditionalInformation')->andReturn(['authentication' => ""]); + + $this->creditConfigMock->shouldReceive('getOrderWithTdsRefused')->andReturn(false); + + $tdsService = new ThreeDSService($this->creditConfigMock); + $emptyReturn = $tdsService->processDeclinedThreeDsTransaction($paymentMock, $platformOrderMock); + $this->assertEmpty($emptyReturn); + } + + public function testProcessDeclinedThreeDsTransactionWithRefusedDisabled() + { + $this->expectException('Magento\Framework\Exception\PaymentException'); + + $mpSetupMock = $this->mpSetupMock; + $mpSetupMock->shouldReceive('getModuleConfiguration')->andReturnSelf(); + $mpSetupMock->shouldReceive('isCreateOrderEnabled')->andReturn(false); + + $platformOrderMock = Mockery::mock('\Pagarme\Pagarme\Concrete\Magento2PlatformOrderDecorator'); + + $paymentMock = $this->paymentMock; + $paymentMock->shouldReceive('getStatus')->andReturn('Y'); + $paymentMock->shouldReceive('getMethod')->andReturn(CreditCardConfigProvider::CODE); + $paymentMock->shouldReceive('getAdditionalInformation')->andReturn(['authentication' => '{"trans_status":"Y", "cc_type":"visa"}']); + + $this->creditConfigMock->shouldReceive('getOrderWithTdsRefused')->andReturn(false); + + $tdsService = new ThreeDSService($this->creditConfigMock); + $tdsService->processDeclinedThreeDsTransaction($paymentMock, $platformOrderMock); + } +} diff --git a/Test/Unit/bootstrap.php b/Test/Unit/bootstrap.php deleted file mode 100755 index 3115dbed..00000000 --- a/Test/Unit/bootstrap.php +++ /dev/null @@ -1,24 +0,0 @@ -=7.1", - "pagarme/ecommerce-module-core": "2.3.*" + "pagarme/ecommerce-module-core": "2.4.*" }, "require-dev": { - "phpunit/phpunit": "4.1.0", + "phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9", "squizlabs/php_codesniffer": "2.8.1", "phpmd/phpmd": "@stable", "pdepend/pdepend": "2.2.2", @@ -21,7 +21,8 @@ "satooshi/php-coveralls": "^1.0", "phpdocumentor/phpdocumentor": "^2.8", "magento-ecg/coding-standard":"dev-master", - "rregeer/phpunit-coverage-check": "^0.1.3" + "rregeer/phpunit-coverage-check": "^0.1.3", + "mockery/mockery": "1.3.x-dev" }, "authors":[ { diff --git a/etc/adminhtml/system/transaction/creditcard.xml b/etc/adminhtml/system/transaction/creditcard.xml index 9471620b..2bb06c41 100644 --- a/etc/adminhtml/system/transaction/creditcard.xml +++ b/etc/adminhtml/system/transaction/creditcard.xml @@ -83,5 +83,6 @@ + diff --git a/etc/adminhtml/system/transaction/creditcard/tds.xml b/etc/adminhtml/system/transaction/creditcard/tds.xml new file mode 100644 index 00000000..ee50a935 --- /dev/null +++ b/etc/adminhtml/system/transaction/creditcard/tds.xml @@ -0,0 +1,41 @@ + + + + + + Pagarme\Pagarme\Block\Adminhtml\Form\Fieldset\CreditCardGatewayFieldset + + + Magento\Config\Model\Config\Source\Yesno + payment/pagarme_creditcard/tds_active + + + + + Magento\Config\Model\Config\Source\Yesno + payment/pagarme_creditcard/order_with_tds_refused + If the Issuing Bank rejects 3DS authentication, you may receive a fraud chargeback + + 1 + + + + Pagarme\Pagarme\Model\Validation\GenericValidation + + + payment/pagarme_creditcard/tds_min_amount + validate-currency-dollar + + 1 + + + + 1 + + + diff --git a/etc/config.xml b/etc/config.xml index 26fad8bc..7e7867cc 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -113,6 +113,8 @@ 1 1 0 + 1 + 0.00 diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index 768d77b4..b48ccb32 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -15,5 +15,95 @@ api.pagar.me + + + 3ds2.pagar.me + 3ds2-sdx.pagar.me + + + + + *.pagar.me + *.netsgroup.com + *.sibs.pt + *.seglan.com + *.secureacs.com + *.secureacs.com + *.rsa3dsauth.com + *.apata.io + *.cardinalcommerce.com + *.santander.com.br + *.bradesco.com.br + *.bradesco + *.stone.com.br + *.nubank.com.br + *.itau.com.br + *.bb.com.br + *.caixa.gov.br + *.inter.co + *.bancointer.com.br + *.c6bank.com.br + *.bancobmg.com.br + *.safra.com.br + *.sicoob.com.br + *.banrisul.com.br + *.banrisul.b.br + *.banorte.com + *.xpi.com.br + *.btgpactual.com + *.btgpactualdigital.com + *.mercadopago.com.br + *.mercadopago.com + *.picpay.com + *.amedigital.com + *.neon.tech + *.neon.com.br + *.wise.com + *.revolut.com + *.sandbox.3dsecure.io + + + + + *.pagar.me + *.netsgroup.com + *.sibs.pt + *.seglan.com + *.secureacs.com + *.secureacs.com + *.rsa3dsauth.com + *.apata.io + *.cardinalcommerce.com + *.santander.com.br + *.bradesco.com.br + *.bradesco + *.stone.com.br + *.nubank.com.br + *.itau.com.br + *.bb.com.br + *.caixa.gov.br + *.inter.co + *.bancointer.com.br + *.c6bank.com.br + *.bancobmg.com.br + *.safra.com.br + *.sicoob.com.br + *.banrisul.com.br + *.banrisul.b.br + *.banorte.com + *.xpi.com.br + *.btgpactual.com + *.btgpactualdigital.com + *.mercadopago.com.br + *.mercadopago.com + *.picpay.com + *.amedigital.com + *.neon.tech + *.neon.com.br + *.wise.com + *.revolut.com + *.sandbox.3dsecure.io + + diff --git a/etc/di.xml b/etc/di.xml index 740078f9..58f903e4 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -18,6 +18,7 @@ + @@ -27,6 +28,7 @@ + diff --git a/etc/module.xml b/etc/module.xml index b8794923..cf6ccf1d 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -9,7 +9,7 @@ */ --> - + diff --git a/etc/webapi.xml b/etc/webapi.xml index 5b3f68ff..89224aed 100755 --- a/etc/webapi.xml +++ b/etc/webapi.xml @@ -36,6 +36,15 @@ + + + + + + + Test/Unit - - - - Test - vendor - - - + + + ./* + + + ./Test/ + + + + + diff --git a/sonar-project.properties b/sonar-project.properties index 5d6f1777..8ff289a4 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,3 +5,6 @@ sonar.projectVersion=1.0 sonar.sources=. sonar.sourceEncoding=UTF-8 sonar.exclusions=**/Test/**, **/.circleci/**, **/.github/** +sonar.php.coverage.reportPaths=coverage/clover.xml +sonar.coverage.exclusions=Test/* +sonar.tests=Test/Unit \ No newline at end of file diff --git a/view/adminhtml/templates/info/creditCard.phtml b/view/adminhtml/templates/info/creditCard.phtml index 52010931..c0b2d9b1 100644 --- a/view/adminhtml/templates/info/creditCard.phtml +++ b/view/adminhtml/templates/info/creditCard.phtml @@ -6,25 +6,31 @@ * @var \Pagarme\Core\Kernel\Aggregates\Transaction $lastTransaction */ $lastTransaction = $this->getTransactionInfo(); + $threeDSStatus = $this->getThreeDSStatus(); ?> - getTitle()); ?> + getTitle()); ?>

- : getCcBrand(); ?> + : getCcBrand(); ?>
- : getCardLast4(); ?> + : getCardLast4(); ?>
- : getInstallments(); ?> - + : getInstallments(); ?> +
- : - + : +
- - : +
- - - : - + : + + +
+ : + + +
+ : + diff --git a/view/adminhtml/templates/info/debit.phtml b/view/adminhtml/templates/info/debit.phtml new file mode 100644 index 00000000..8fcdf3f8 --- /dev/null +++ b/view/adminhtml/templates/info/debit.phtml @@ -0,0 +1,15 @@ +getThreeDSStatus(); +?> +getCardBrand()): ?> + getTitle()); ?> +
+
+ : getCcBrand(); ?> +
+ : getCardLast4(); ?> + +
+ : + + diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index f994fde5..b53a522d 100755 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -11,6 +11,7 @@ + @@ -69,5 +70,12 @@ + + + diff --git a/view/frontend/templates/payment/tds.phtml b/view/frontend/templates/payment/tds.phtml new file mode 100644 index 00000000..c849cb40 --- /dev/null +++ b/view/frontend/templates/payment/tds.phtml @@ -0,0 +1,18 @@ +canInitTds()) { + return; + } +?> +
+ +
+ diff --git a/view/frontend/web/css/pagarme_tds.css b/view/frontend/web/css/pagarme_tds.css new file mode 100644 index 00000000..a33856ec --- /dev/null +++ b/view/frontend/web/css/pagarme_tds.css @@ -0,0 +1,28 @@ +.challengeIframeElement { + display: none; + position: fixed; + z-index: 99999; + padding-top: 100px; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgb(0, 0, 0); + background-color: rgba(0, 0, 0, 0.4); +} + +.modal-content { + background-color: #fefefe; + margin: auto; + padding: 20px; + border: 1px solid #888; + max-width: fit-content; +} + +#challengeIframe { + display: none; + width: 500px; + height: 600px; + border: 0; +} \ No newline at end of file diff --git a/view/frontend/web/js/core/checkout/Tds.js b/view/frontend/web/js/core/checkout/Tds.js new file mode 100644 index 00000000..d6d611a6 --- /dev/null +++ b/view/frontend/web/js/core/checkout/Tds.js @@ -0,0 +1,128 @@ +define([ + "Magento_Checkout/js/model/url-builder", + "mage/url", + 'Magento_Checkout/js/model/quote' +], ( + urlBuilder, + mageUrl, + quote +) => { + return class Tds { + constructor(formObject) { + this.formObject = formObject; + } + + getToken() { + const url = urlBuilder.createUrl("/pagarme/tdstoken", {}); + return jQuery.ajax({ + type: "GET", + dataType: "json", + url: mageUrl.build(url), + async: false, + cache: false, + }); + } + + callTdsFunction(tdsToken, tdsData, callbackTds) { + const challengeWindowSize = '03' + Script3ds.init3ds(tdsToken, tdsData, callbackTds, challengeWindowSize); + } + + showErrors(errors, parentObject) { + if(errors.error?.email) { + parentObject.addErrors("Ocorreu um problema ao encontrar o e-mail."); + } + if(errors.error?.bill_addr) { + parentObject.addErrors("Ocorreu um problema ao encontrar os endereços."); + } + if(errors.error?.card_expiry_date) { + parentObject.addErrors("Ocorreu um problema ao montar o dado de expiração do cartão."); + } + if(errors.error?.purchase) { + parentObject.addErrors("Ocorreu um problema ao montar o dado de compra."); + } + } + + addTdsAttributeData() { + const cardForm = this.formObject; + jQuery(cardForm.containerSelector).attr("data-pagarmecheckout-form", "") + cardForm.creditCardHolderName.attr("data-pagarmecheckout-element", "holder_name") + cardForm.creditCardNumber.attr("data-pagarmecheckout-element", "number") + cardForm.creditCardBrand.attr("data-pagarmecheckout-element", "brand") + cardForm.creditCardExpMonth.attr("data-pagarmecheckout-element", "exp_month") + cardForm.creditCardExpYear.attr("data-pagarmecheckout-element", "exp_year") + cardForm.creditCardCvv.attr("data-pagarmecheckout-element", "cvv") + } + + removeTdsAttributeData() { + const cardForm = this.formObject; + jQuery(cardForm.containerSelector).removeAttr("data-pagarmecheckout-form") + cardForm.creditCardHolderName.removeAttr("data-pagarmecheckout-element") + cardForm.creditCardNumber.removeAttr("data-pagarmecheckout-element") + cardForm.creditCardBrand.removeAttr("data-pagarmecheckout-element") + cardForm.creditCardExpMonth.removeAttr("data-pagarmecheckout-element") + cardForm.creditCardExpYear.removeAttr("data-pagarmecheckout-element") + cardForm.creditCardCvv.removeAttr("data-pagarmecheckout-element") + } + + getTdsData(acctType, cardExpiryDate) { + const billingAddress = quote.billingAddress(); + const [ + billingAddressStreet, + billingAddressNumber, + billingAddressComplement + ] = billingAddress.street; + + const shippingAddress = quote.shippingAddress(); + const [ + shippingAddressStreet, + shippingAddressNumber, + shippingAddressComplement + ] = shippingAddress.street; + + let customerEmail = window.checkoutConfig.customerData?.email; + if(quote.guestEmail) { + customerEmail = quote.guestEmail + } + + const customerPhones = + [{ + country_code : '55', + subscriber : shippingAddress.telephone, + phone_type : 'mobile' + }]; + + return { + bill_addr : { + street : billingAddressStreet, + number : billingAddressNumber, + complement : billingAddressComplement, + city : billingAddress.city, + state : billingAddress.regionCode, + country : 'BRA', + post_code : billingAddress.postcode + }, + ship_addr : { + street : shippingAddressStreet, + number : shippingAddressNumber, + complement : shippingAddressComplement, + city : shippingAddress.city, + state : shippingAddress.regionCode, + country : 'BRA', + post_code : shippingAddress.postcode + }, + email : customerEmail, + phones : customerPhones, + card_expiry_date : cardExpiryDate, + purchase : { + amount : quote.totals().grand_total * 100, + date : + new Date().toISOString() + , + instal_data : 2, + }, + acct_type : acctType + } + } + }; +}); diff --git a/view/frontend/web/js/core/models/CreditCardModel.js b/view/frontend/web/js/core/models/CreditCardModel.js index 6de6d852..593e757c 100644 --- a/view/frontend/web/js/core/models/CreditCardModel.js +++ b/view/frontend/web/js/core/models/CreditCardModel.js @@ -2,7 +2,9 @@ define([ 'Pagarme_Pagarme/js/core/validators/CreditCardValidator', 'Pagarme_Pagarme/js/core/validators/MultibuyerValidator', 'Pagarme_Pagarme/js/core/checkout/CreditCardToken', -], (CreditCardValidator, MultibuyerValidator, CreditCardToken) => { + 'Pagarme_Pagarme/js/core/checkout/Tds', + 'Magento_Checkout/js/model/quote', +], (CreditCardValidator, MultibuyerValidator, CreditCardToken, Tds, quote) => { return class CreditCardModel { constructor(formObject, publicKey) { this.formObject = formObject; @@ -23,6 +25,22 @@ define([ return; } + if(this.canTdsRun()) { + const tds = new Tds(this.formObject) + tds.addTdsAttributeData(); + jQuery('body').trigger('processStart'); + this.getCreditCardTdsToken( + function (tdsToken) { + _self.initTds(tdsToken) + }, + function(error) { + jQuery('body').trigger('processStop'); + _self.addErrors("Falha ao gerar Token para 3ds, tente novamente."); + } + ) + + return; + } this.getCreditCardToken( function (data) { _self.formObject.creditCardToken.val(data.id); @@ -58,6 +76,58 @@ define([ .done(success) .fail(error); } + getCreditCardTdsToken(success, error) { + const modelTdsToken = new Tds(this.formObject); + modelTdsToken.getToken() + .done(success) + .fail(error); + } + canTdsRun() { + const configCard = window.checkoutConfig.payment.pagarme_creditcard; + + return configCard['tds_active'] === true + && quote.totals().grand_total * 100 >= configCard['tds_min_amount'] * 100 + && this.brandIsVisaOrMaster() + } + brandIsVisaOrMaster() { + return this.formObject.creditCardBrand.val() === "visa" + || this.formObject.creditCardBrand.val() === "mastercard" + } + initTds(tdsToken) { + const modelTds = new Tds(this.formObject) + const expYear = this.formObject.creditCardExpYear.val() + const expMonth = this.formObject.creditCardExpMonth.val().padStart(2, '0') + const cardExpiryDate = `${expYear}-${expMonth}` + const tdsData = modelTds.getTdsData('02', cardExpiryDate); + modelTds.callTdsFunction(tdsToken, tdsData, this.callbackTds.bind(this)); + } + + callbackTds(data) { + const _self = this; + const tds = new Tds(this.formObject); + jQuery('body').trigger('processStop'); + if(data?.error !== undefined) { + tds.showErrors(data, _self); + return; + } + if(data?.trans_status === '' || data?.trans_status === undefined){ + return; + } + + this.formObject.authentication = JSON.stringify(data); + this.getCreditCardToken( + function (data) { + _self.formObject.creditCardToken.val(data.id); + _self.placeOrderObject.placeOrder(); + }, + function (error) { + tds.removeTdsAttributeData() + _self.addErrors("Cartão inválido. Por favor, verifique os dados digitados e tente novamente"); + } + ); + return true; + } + getData() { this.saveThiscard = 0; const formObject = this.formObject; @@ -93,7 +163,8 @@ define([ 'cc_saved_card': formObject.savedCreditCardSelect.val(), 'cc_installments': formObject.creditCardInstallments.val(), 'cc_token_credit_card': formObject.creditCardToken.val(), - 'cc_card_tax_amount' : formObject.creditCardInstallments.find(':selected').attr('interest') + 'cc_card_tax_amount' : formObject.creditCardInstallments.find(':selected').attr('interest'), + 'authentication': formObject.authentication } }; } diff --git a/view/frontend/web/js/core/models/DebitModel.js b/view/frontend/web/js/core/models/DebitModel.js index e0456ac2..316a5cf0 100644 --- a/view/frontend/web/js/core/models/DebitModel.js +++ b/view/frontend/web/js/core/models/DebitModel.js @@ -2,7 +2,8 @@ define([ 'Pagarme_Pagarme/js/core/validators/CreditCardValidator', 'Pagarme_Pagarme/js/core/validators/MultibuyerValidator', 'Pagarme_Pagarme/js/core/checkout/CreditCardToken', -], (CreditCardValidator, MultibuyerValidator, CreditCardToken) => { + 'Pagarme_Pagarme/js/core/checkout/Tds', +], (CreditCardValidator, MultibuyerValidator, CreditCardToken, Tds) => { return class DebitModel { constructor(formObject, publicKey) { this.formObject = formObject; @@ -38,6 +39,7 @@ define([ message: error }) } + validate() { const creditCardValidator = new CreditCardValidator(this.formObject); @@ -58,6 +60,7 @@ define([ .done(success) .fail(error); } + getData() { this.saveThiscard = 0; const formObject = this.formObject; diff --git a/view/frontend/web/template/payment/creditcard-form.html b/view/frontend/web/template/payment/creditcard-form.html index 346a9df0..e71d49b3 100644 --- a/view/frontend/web/template/payment/creditcard-form.html +++ b/view/frontend/web/template/payment/creditcard-form.html @@ -121,7 +121,7 @@ class="input-text cvv cc_cid" name="payment[cc_cid]" value="" - onKeyPress="if(this.value.length==4) return false;" + oninput="this.value = this.value.replace(/[^0-9]/g, ''); if (this.value.length > 4) this.value = this.value.slice(0, 4);" min="0" />