diff --git a/Api/PixConfigurationInterface.php b/Api/PixConfigurationInterface.php index bbe4f3f7..06f4232a 100644 --- a/Api/PixConfigurationInterface.php +++ b/Api/PixConfigurationInterface.php @@ -7,20 +7,10 @@ interface PixConfigurationInterface { - - const PATH_ENABLED_DOCUMENT = 'payment/vindi_pix/enabled_document'; const PATH_INFO_MESSAGE = 'checkout/vindi_pix/info_message'; const PATH_INFO_MESSAGE_ONEPAGE_SUCCESS = 'checkout/vindi_pix/info_message_onepage_success'; const PATH_QR_CODE_WARNING_MESSAGE = 'checkout/vindi_pix/qr_code_warning_message'; - /** - * @param string $scopeType - * @param string|null $scopeCode - * - * @return bool - */ - public function isEnabledDocument(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null); - /** * @param string $scopeType * @param string|null $scopeCode diff --git a/Block/Info/BankSlipPix.php b/Block/Info/BankSlipPix.php index 07364c10..58d55d02 100644 --- a/Block/Info/BankSlipPix.php +++ b/Block/Info/BankSlipPix.php @@ -5,6 +5,7 @@ use Magento\Backend\Block\Template\Context; use Magento\Framework\Pricing\Helper\Data; use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Payment\Block\Info; use Vindi\Payment\Api\PixConfigurationInterface; use Vindi\Payment\Model\Payment\PaymentMethod; @@ -32,6 +33,9 @@ class BankSlipPix extends Info */ protected $pixConfiguration; + /** @var TimezoneInterface */ + protected $timezone; + /** * @var Json */ @@ -53,12 +57,14 @@ public function __construct( Context $context, PixConfigurationInterface $pixConfiguration, Json $json, + TimezoneInterface $timezone, array $data = [] ) { parent::__construct($context, $data); $this->paymentMethod = $paymentMethod; $this->currency = $currency; $this->pixConfiguration = $pixConfiguration; + $this->timezone = $timezone; $this->json = $json; } @@ -164,16 +170,16 @@ protected function isValidToPayment($timestampMaxDays) return false; } - return $timestampMaxDays >= strtotime("now"); + return $timestampMaxDays >= $this->timezone->scopeTimeStamp(); } /** - * @return mixed + * @return string * @throws \Magento\Framework\Exception\LocalizedException */ - protected function getMaxDaysToPayment() + protected function getMaxDaysToPayment(): string { - return $this->getOrder()->getPayment()->getAdditionalInformation('max_days_to_keep_waiting_payment'); + return (string) $this->getOrder()->getPayment()->getAdditionalInformation('max_days_to_keep_waiting_payment'); } public function getPrintUrl() diff --git a/Block/Info/Pix.php b/Block/Info/Pix.php index 93124b7f..fd279814 100644 --- a/Block/Info/Pix.php +++ b/Block/Info/Pix.php @@ -6,6 +6,7 @@ use Magento\Backend\Block\Template\Context; use Magento\Framework\Pricing\Helper\Data; use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Payment\Block\Info; use Vindi\Payment\Api\PixConfigurationInterface; use Vindi\Payment\Model\Payment\PaymentMethod; @@ -33,6 +34,9 @@ class Pix extends Info */ protected $pixConfiguration; + /** @var TimezoneInterface */ + protected $timezone; + /** * @var Json */ @@ -40,19 +44,12 @@ class Pix extends Info protected $paymentMethod; - /** - * @param PaymentMethod $paymentMethod - * @param Data $currency - * @param Context $context - * @param PixConfigurationInterface $pixConfiguration - * @param Json $json - * @param array $data - */ public function __construct( PaymentMethod $paymentMethod, Data $currency, Context $context, PixConfigurationInterface $pixConfiguration, + TimezoneInterface $timezone, Json $json, array $data = [] ) { @@ -60,6 +57,7 @@ public function __construct( $this->paymentMethod = $paymentMethod; $this->currency = $currency; $this->pixConfiguration = $pixConfiguration; + $this->timezone = $timezone; $this->json = $json; } @@ -167,15 +165,15 @@ protected function isValidToPayment($timestampMaxDays) return false; } - return $timestampMaxDays >= strtotime("now"); + return $timestampMaxDays >= $this->timezone->scopeTimeStamp(); } /** - * @return mixed + * @return string * @throws \Magento\Framework\Exception\LocalizedException */ - protected function getMaxDaysToPayment() + protected function getMaxDaysToPayment(): string { - return $this->getOrder()->getPayment()->getAdditionalInformation('max_days_to_keep_waiting_payment'); + return (string) $this->getOrder()->getPayment()->getAdditionalInformation('max_days_to_keep_waiting_payment'); } } diff --git a/Helper/Data.php b/Helper/Data.php index d8f36bab..c2f0c9f3 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -151,8 +151,8 @@ public static function sanitizeItemSku($code) "[^a-zA-Z0-9-]", "-", strtr( - utf8_decode(trim(preg_replace('/[ -]+/', '-', $code))), - utf8_decode("áàãâéêíóôõúüñçÁÀÃÂÉÊÍÓÔÕÚÜÑÇ"), + mb_convert_encoding(trim(preg_replace('/[ -]+/', '-', $code)), 'ISO-8859-1', 'UTF-8'), + mb_convert_encoding("áàãâéêíóôõúüñçÁÀÃÂÉÊÍÓÔÕÚÜÑÇ", 'ISO-8859-1', 'UTF-8'), "aaaaeeiooouuncAAAAEEIOOOUUNC-" ) )); diff --git a/Helper/PixConfiguration.php b/Helper/PixConfiguration.php index af79dad1..1c61d70a 100644 --- a/Helper/PixConfiguration.php +++ b/Helper/PixConfiguration.php @@ -9,15 +9,6 @@ class PixConfiguration extends AbstractHelper implements PixConfigurationInterface { - - /** - * @inheritDoc - */ - public function isEnabledDocument(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null) - { - return $this->scopeConfig->isSetFlag(static::PATH_ENABLED_DOCUMENT, $scopeType, $scopeCode); - } - /** * @inheritDoc */ diff --git a/Model/Bankslip/ConfigProvider.php b/Model/Bankslip/ConfigProvider.php new file mode 100644 index 00000000..403438a5 --- /dev/null +++ b/Model/Bankslip/ConfigProvider.php @@ -0,0 +1,49 @@ +customerSession = $customerSession; + } + + /** + * {@inheritdoc} + */ + public function getConfig() + { + $customerTaxvat = ''; + $customer = $this->customerSession->getCustomer(); + if ($customer && $customer->getTaxvat()) { + $customerTaxvat = $customer->getTaxvat(); + } + + return [ + 'payment' => [ + 'vindi_bankslip' => [ + 'enabledDocument' => true, + 'customer_taxvat' => $customerTaxvat + ] + ] + ]; + } +} diff --git a/Model/BankslipPix/ConfigProvider.php b/Model/BankslipPix/ConfigProvider.php index c12f3459..804d71b8 100644 --- a/Model/BankslipPix/ConfigProvider.php +++ b/Model/BankslipPix/ConfigProvider.php @@ -1,13 +1,11 @@ [ - 'vindi_pix' => [ - 'enabledDocument' => $this->pixConfiguration->isEnabledDocument(), + 'vindi_bankslippix' => [ + 'enabledDocument' => true, 'info_message' => $this->pixConfiguration->getInfoMessage(), 'customer_taxvat' => $customerTaxvat ] diff --git a/Model/ConfigProvider.php b/Model/ConfigProvider.php index 1c19e726..421be890 100644 --- a/Model/ConfigProvider.php +++ b/Model/ConfigProvider.php @@ -190,13 +190,22 @@ private function getAttributeValue(ProductInterface $product, $attribute = '') public function getPaymentProfiles(): array { + $paymentProfiles = []; if ($this->customerSession->isLoggedIn()) { $customerId = $this->customerSession->getCustomerId(); $this->paymentProfileCollection->addFieldToFilter('customer_id', $customerId); - return $this->paymentProfileCollection->getItems(); + $this->paymentProfileCollection->addFieldToFilter('cc_type', ['neq' => '']); + $this->paymentProfileCollection->addFieldToFilter('cc_type', ['neq' => null]); + foreach ($this->paymentProfileCollection as $paymentProfile) { + $paymentProfiles[] = [ + 'id' => $paymentProfile->getId(), + 'card_number' => (string) $paymentProfile->getCcLast4(), + 'card_type' => (string) $paymentProfile->getCcType() + ]; + } } - return []; + return $paymentProfiles; } /** diff --git a/Model/Payment/AbstractMethod.php b/Model/Payment/AbstractMethod.php index 8fdf72dd..11d35392 100644 --- a/Model/Payment/AbstractMethod.php +++ b/Model/Payment/AbstractMethod.php @@ -81,32 +81,32 @@ abstract class AbstractMethod extends OriginAbstractMethod /** * @var ProductManagementInterface */ - private $productManagement; + protected $productManagement; /** * @var \Vindi\Payment\Helper\Data */ - private $helperData; + protected $helperData; /** * @var PlanManagementInterface */ - private $planManagement; + protected $planManagement; /** * @var SubscriptionInterface */ - private $subscriptionRepository; + protected $subscriptionRepository; /** * @var PaymentProfileFactory */ - private $paymentProfileFactory; + protected $paymentProfileFactory; /** * @var PaymentProfileRepository */ - private $paymentProfileRepository; + protected $paymentProfileRepository; /** * @var ResourceConnection @@ -329,7 +329,9 @@ protected function processPayment(InfoInterface $payment, $amount) ]; if ($body['payment_method_code'] === PaymentMethod::CREDIT_CARD) { - $paymentProfile = $this->createPaymentProfile($order, $payment, $customerId); + $paymentProfile = ($payment->getAdditionalInformation('payment_profile')) + ? $this->getPaymentProfile((int) $payment->getAdditionalInformation('payment_profile')) + : $this->createPaymentProfile($order, $payment, $customerId); $body['payment_profile'] = ['id' => $paymentProfile->getData('payment_profile_id')]; } @@ -350,13 +352,18 @@ protected function processPayment(InfoInterface $payment, $amount) return $this->handleError($order); } + protected function getPaymentProfile(int $paymentProfileId): PaymentProfile + { + return $this->paymentProfileRepository->getById($paymentProfileId); + } + /** * @param InfoInterface $payment * @param OrderItemInterface $orderItem * @return mixed * @throws LocalizedException */ - private function handleSubscriptionOrder(InfoInterface $payment, OrderItemInterface $orderItem) + protected function handleSubscriptionOrder(InfoInterface $payment, OrderItemInterface $orderItem) { try { $order = $payment->getOrder(); @@ -436,7 +443,7 @@ private function handleSubscriptionOrder(InfoInterface $payment, OrderItemInterf * @return void * @throws \Exception */ - private function saveSubscriptionToDatabase(array $subscription, Order $order) + protected function saveSubscriptionToDatabase(array $subscription, Order $order) { $tableName = $this->resourceConnection->getTableName('vindi_subscription'); $startAt = new \DateTime($subscription['start_at']); @@ -466,7 +473,7 @@ private function saveSubscriptionToDatabase(array $subscription, Order $order) * @param Order $order * @return OrderItemInterface|bool */ - private function isSubscriptionOrder(Order $order) + protected function isSubscriptionOrder(Order $order) { foreach ($order->getItems() as $item) { try { @@ -490,7 +497,7 @@ private function isSubscriptionOrder(Order $order) * @param Order $order * @throws LocalizedException */ - private function handleError(Order $order) + protected function handleError(Order $order) { $this->psrLogger->error(__(sprintf('Error on order payment %d.', $order->getId()))); $message = __('There has been a payment confirmation error. Verify data and try again'); @@ -536,7 +543,7 @@ protected function handleBankSplitAdditionalInformation(InfoInterface $payment, * @param array $subscription * @return bool */ - private function successfullyPaid(array $body, $bill, array $subscription = []) + protected function successfullyPaid(array $body, $bill, array $subscription = []) { // nova validação para permitir pedidos com pagamento/fatura pendente if (!$bill) { diff --git a/Model/Payment/Customer.php b/Model/Payment/Customer.php index ba6a78ee..7f703ee2 100644 --- a/Model/Payment/Customer.php +++ b/Model/Payment/Customer.php @@ -101,7 +101,7 @@ public function findOrCreate(Order $order) $customerVindi = [ 'name' => $billing->getFirstname() . ' ' . $billing->getLastname(), 'email' => $billing->getEmail(), - 'registry_code' => $this->getDocumentGuest($order), + 'registry_code' => $this->getDocument($order), 'code' => $customer ? $customer->getId() : '', 'phones' => $this->formatPhone($billing->getTelephone()), 'address' => $address @@ -326,12 +326,12 @@ public function formatPhone($phone) * * @return mixed|string */ - protected function getDocumentGuest(Order $order) + protected function getDocument(Order $order) { - if($document = $order->getData('customer_taxvat')) { - return $document; + $document = (string) $order->getPayment()->getAdditionalInformation('document'); + if(!$document) { + $document = (string) $order->getData('customer_taxvat'); } - - return $order->getPayment()->getAdditionalInformation('document') ?: ''; + return $document; } } diff --git a/Model/Payment/Vindi.php b/Model/Payment/Vindi.php index c17b9b40..ba3cf1f7 100644 --- a/Model/Payment/Vindi.php +++ b/Model/Payment/Vindi.php @@ -5,6 +5,7 @@ use Magento\Framework\DataObject; use Magento\Quote\Api\Data\PaymentInterface; use Vindi\Payment\Block\Info\Cc; +use Vindi\Payment\Model\PaymentProfile; class Vindi extends \Vindi\Payment\Model\Payment\AbstractMethod { @@ -84,28 +85,36 @@ public function assignData(DataObject $data) $additionalData = new DataObject($additionalData ?: []); } - $info = $this->getInfoInstance(); + $ccType = $additionalData->getCcType(); + $ccOwner = $additionalData->getCcOwner(); + $ccLast4 = substr((string) $additionalData->getCcNumber(), -4); + $info = $this->getInfoInstance(); $info->setAdditionalInformation('installments', $additionalData->getCcInstallments()); + $paymentProfileId = (string) $additionalData->getData('payment_profile'); + if ($paymentProfileId) { + $info->setAdditionalInformation('payment_profile', $paymentProfileId); + $paymentProfile = $this->getPaymentProfile((int) $paymentProfileId); + $ccType = $paymentProfile->getCcType(); + $ccOwner = $paymentProfile->getCcName(); + $ccLast4 = $paymentProfile->getCcLast4(); + } - $info->addData( - [ - 'cc_type' => $additionalData->getCcType(), - 'cc_owner' => $additionalData->getCcOwner(), - 'cc_last_4' => substr((string) $additionalData->getCcNumber(), -4), - 'cc_number' => $additionalData->getCcNumber(), - 'cc_cid' => $additionalData->getCcCvv(), - 'cc_exp_month' => $additionalData->getCcExpMonth(), - 'cc_exp_year' => $additionalData->getCcExpYear(), - 'cc_ss_issue' => $additionalData->getCcSsIssue(), - 'cc_ss_start_month' => $additionalData->getCcSsStartMonth(), - 'cc_ss_start_year' => $additionalData->getCcSsStartYear() - ] - ); - - parent::assignData($data); - return $this; + $info->addData([ + 'cc_type' => $ccType, + 'cc_owner' => $ccOwner, + 'cc_last_4' => $ccLast4, + 'cc_number' => (string) $additionalData->getCcNumber(), + 'cc_cid' => (string) $additionalData->getCcCvv(), + 'cc_exp_month' => (string) $additionalData->getCcExpMonth(), + 'cc_exp_year' => (string) $additionalData->getCcExpYear(), + 'cc_ss_issue' => (string) $additionalData->getCcSsIssue(), + 'cc_ss_start_month' => (string) $additionalData->getCcSsStartMonth(), + 'cc_ss_start_year' => (string) $additionalData->getCcSsStartYear() + ]); + + return parent::assignData($data); } /** @@ -119,14 +128,20 @@ protected function getPaymentMethodCode() public function validate() { $info = $this->getInfoInstance(); - $ccNumber = $info->getCcNumber(); - // remove credit card non-numbers - $ccNumber = preg_replace('/\D/', '', $ccNumber); + $paymentProfile = $info->getAdditionalInformation('payment_profile'); + + if (!$paymentProfile) { + $ccNumber = $info->getCcNumber(); + if ($ccNumber) { + // remove credit card non-numbers + $ccNumber = preg_replace('/\D/', '', (string)$ccNumber); - $info->setCcNumber($ccNumber); + $info->setCcNumber($ccNumber); - if (!$this->paymentMethod->isCcTypeValid($info->getCcType())) { - throw new \Exception(__('Credit card type is not allowed for this payment method.')); + if (!$this->paymentMethod->isCcTypeValid($info->getCcType())) { + throw new \Exception(__('Credit card type is not allowed for this payment method.')); + } + } } return $this; diff --git a/Model/Pix/ConfigProvider.php b/Model/Pix/ConfigProvider.php index c12f3459..279afdc7 100644 --- a/Model/Pix/ConfigProvider.php +++ b/Model/Pix/ConfigProvider.php @@ -2,12 +2,10 @@ namespace Vindi\Payment\Model\Pix; - use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Customer\Model\Session as CustomerSession; use Vindi\Payment\Api\PixConfigurationInterface; - /** * Class ConfigProvider * @package Vindi\Payment\Model @@ -51,7 +49,7 @@ public function getConfig() return [ 'payment' => [ 'vindi_pix' => [ - 'enabledDocument' => $this->pixConfiguration->isEnabledDocument(), + 'enabledDocument' => true, 'info_message' => $this->pixConfiguration->getInfoMessage(), 'customer_taxvat' => $customerTaxvat ] diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index fcd82e99..7931baaf 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -107,14 +107,6 @@ payment/vindi_pix/title - - - Magento\Config\Model\Config\Source\Yesno - Vindi\Payment\Model\Config\Backend\ApiKeyValidator - When enabled, it will only be possible to finalize the order with the document informed when selecting the payment method. When disabled, the client will not be asked for the document, but it will still be necessary to send the document when creating the order in VINDI, otherwise it will be rejected by the API. - payment/vindi_pix/enabled_document - diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 539ed2d3..c6ddcfe8 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -6,6 +6,8 @@ Vindi\Payment\Model\ConfigProvider Vindi\Payment\Model\Pix\ConfigProvider + Vindi\Payment\Model\Bankslip\ConfigProvider + Vindi\Payment\Model\BankslipPix\ConfigProvider diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 6c534d2c..e242db05 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -278,3 +278,5 @@ "The number of installments cannot be greater than the number of installments of the plan.","A quantidade de parcelas não pode ser maior que a quantidade de parcelas do plano." "In cash","À vista" "Customer will choose in checkout","Cliente escolherá na finalização" +"Your saved cards","Seus cartões salvos" +"New Card.","Novo Cartão" diff --git a/view/frontend/web/js/view/payment/method-renderer/vindi-bankslip.js b/view/frontend/web/js/view/payment/method-renderer/vindi-bankslip.js index 806a1d10..82d849f5 100644 --- a/view/frontend/web/js/view/payment/method-renderer/vindi-bankslip.js +++ b/view/frontend/web/js/view/payment/method-renderer/vindi-bankslip.js @@ -4,13 +4,63 @@ define( 'Magento_Checkout/js/view/payment/default', 'mage/translate', 'jquery', - 'mageUtils' + 'mageUtils', + 'Vindi_Payment/js/model/taxvat', + 'Vindi_Payment/js/model/validate' ], - function (_, Component, $t, $, utils) { + function (_, Component, $t, $, utils, taxvat, documentValidate) { 'use strict'; return Component.extend({ defaults: { - template: 'Vindi_Payment/payment/vindi-bankslip' + template: 'Vindi_Payment/payment/vindi-bankslip', + taxvat: taxvat + }, + + initialize: function () { + this._super(); + this.taxvat.value(window?.checkoutConfig?.payment?.vindi_bankslip?.customer_taxvat); + }, + + isActiveDocument: function () { + return window?.checkoutConfig?.payment?.vindi_bankslip?.enabledDocument; + }, + + checkCpf: function (self, event) { + this.formatTaxvat(event.target) + const message = documentValidate.isValidTaxvat(this?.taxvat?.value()) ? '' : 'CPF/CNPJ inválido'; + $('#cpfResponseBankSlipPix').text(message); + }, + + formatTaxvat: function (target) { + taxvat.formatDocument(target) + }, + + validate: function () { + const self = this; + const documentValue = this?.taxvat?.value(); + + if (!this.isActiveDocument()) return true; + + if (!documentValue || documentValue === '') { + self.messageContainer.addErrorMessage({'message': ('CPF/CNPJ é obrigatório')}); + return false; + } + + if (!documentValidate.isValidTaxvat(documentValue)) { + self.messageContainer.addErrorMessage({'message': ('CPF/CNPJ não é válido')}); + return false; + } + + return true; + }, + + getData: function() { + return { + 'method': this?.item?.method, + 'additional_data': { + 'document': this?.taxvat?.value() + } + }; } }); } diff --git a/view/frontend/web/js/view/payment/method-renderer/vindi-bankslippix.js b/view/frontend/web/js/view/payment/method-renderer/vindi-bankslippix.js index 2fc450db..3997e308 100644 --- a/view/frontend/web/js/view/payment/method-renderer/vindi-bankslippix.js +++ b/view/frontend/web/js/view/payment/method-renderer/vindi-bankslippix.js @@ -17,18 +17,23 @@ define( taxvat: taxvat }, + initialize: function () { + this._super(); + this.taxvat.value(window?.checkoutConfig?.payment?.vindi_bankslippix?.customer_taxvat); + }, + getInfoMessage: function () { - return window?.checkoutConfig?.payment?.vindi_pix?.info_message; + return window?.checkoutConfig?.payment?.vindi_bankslippix?.info_message; }, isActiveDocument: function () { - return window?.checkoutConfig?.payment?.vindi_pix?.enabledDocument; + return window?.checkoutConfig?.payment?.vindi_bankslippix?.enabledDocument; }, checkCpf: function (self, event) { this.formatTaxvat(event.target) const message = documentValidate.isValidTaxvat(this?.taxvat?.value()) ? '' : 'CPF/CNPJ inválido'; - $('#cpfResponse').text(message); + $('#cpfResponseBankSlipPix').text(message); }, formatTaxvat: function (target) { diff --git a/view/frontend/web/js/view/payment/method-renderer/vindi-cc.js b/view/frontend/web/js/view/payment/method-renderer/vindi-cc.js index 9eef977a..1cfec0e3 100644 --- a/view/frontend/web/js/view/payment/method-renderer/vindi-cc.js +++ b/view/frontend/web/js/view/payment/method-renderer/vindi-cc.js @@ -80,6 +80,7 @@ define([ 'creditCardSsStartMonth', 'creditCardSsStartYear', 'selectedCardType', + 'selectedPaymentProfile', 'selectedInstallments' ]); return this; @@ -94,34 +95,38 @@ define([ }, validate: function () { - if (!this.selectedCardType() || this.selectedCardType() == '') { - this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Type.')}); - return false; - } - if (!this.creditCardExpYear() || this.creditCardExpYear() == '') { - this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Expiry Year.')}); - return false; - } + if (this.selectedPaymentProfile() == null || this.selectedPaymentProfile() == '') { - if (!this.creditCardExpMonth() || this.creditCardExpMonth() == '') { - this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Expiry Month.')}); - return false; - } + if (!this.selectedCardType() || this.selectedCardType() == '') { + this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Type.')}); + return false; + } - if (!this.creditCardNumber() || this.creditCardNumber() == '') { - this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Number.')}); - return false; - } + if (!this.creditCardExpYear() || this.creditCardExpYear() == '') { + this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Expiry Year.')}); + return false; + } - if (!this.creditCardOwner() || this.creditCardOwner() == '') { - this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Owner Name.')}); - return false; - } + if (!this.creditCardExpMonth() || this.creditCardExpMonth() == '') { + this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Expiry Month.')}); + return false; + } + + if (!this.creditCardNumber() || this.creditCardNumber() == '') { + this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Number.')}); + return false; + } - if (!this.creditCardVerificationNumber() || this.creditCardVerificationNumber() == '') { - this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card CVV.')}); - return false; + if (!this.creditCardOwner() || this.creditCardOwner() == '') { + this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card Owner Name.')}); + return false; + } + + if (!this.creditCardVerificationNumber() || this.creditCardVerificationNumber() == '') { + this.messageContainer.addErrorMessage({'message': $t('Please enter the Credit Card CVV.')}); + return false; + } } if (this.installmentsAllowed()) { @@ -145,7 +150,6 @@ define([ //Set credit card number to credit card data object this.creditCardNumber.subscribe(function (value) { var result; - self.selectedCardType(null); if (value == '' || value == null) { return false; @@ -285,6 +289,26 @@ define([ }, getFormattedPrice: function (price) { return priceUtils.formatPrice(price, quote.getPriceFormat()); + }, + + getPaymentProfiles: function () { + let paymentProfiles = []; + const savedCards = window.checkoutConfig.payment?.vindi_cc?.saved_cards; + + if (savedCards) { + savedCards.forEach(function (card) { + paymentProfiles.push({ + 'value': card.id, + 'text': `${card.card_type.toUpperCase()} xxxx-${card.card_number}` + }); + }); + } + + return paymentProfiles; + }, + + hasPaymentProfiles: function () { + return this.getPaymentProfiles().length > 0; } }); } diff --git a/view/frontend/web/js/view/payment/method-renderer/vindi-pix.js b/view/frontend/web/js/view/payment/method-renderer/vindi-pix.js index 05108be1..19f25cfa 100644 --- a/view/frontend/web/js/view/payment/method-renderer/vindi-pix.js +++ b/view/frontend/web/js/view/payment/method-renderer/vindi-pix.js @@ -17,6 +17,11 @@ define( taxvat: taxvat }, + initialize: function () { + this._super(); + this.taxvat.value(window?.checkoutConfig?.payment?.vindi_pix?.customer_taxvat); + }, + getInfoMessage: function () { return window?.checkoutConfig?.payment?.vindi_pix?.info_message; }, diff --git a/view/frontend/web/template/payment/cc-form.html b/view/frontend/web/template/payment/cc-form.html index 29d5b426..f6565314 100644 --- a/view/frontend/web/template/payment/cc-form.html +++ b/view/frontend/web/template/payment/cc-form.html @@ -4,42 +4,27 @@
-
- -
- -
-
+ +
-
+ -
+
@@ -65,7 +50,43 @@
-
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
@@ -106,7 +127,7 @@
-
+
@@ -135,7 +156,7 @@ -
+
diff --git a/view/frontend/web/template/payment/vindi-bankslip.html b/view/frontend/web/template/payment/vindi-bankslip.html index 65c9f5f4..6488a181 100644 --- a/view/frontend/web/template/payment/vindi-bankslip.html +++ b/view/frontend/web/template/payment/vindi-bankslip.html @@ -1,9 +1,3 @@ -
+ + + +
+
+ +
+ + +
+
+
+
+ + + +
+
+
+
+
+
+
+ +
diff --git a/view/frontend/web/template/payment/vindi-bankslippix.html b/view/frontend/web/template/payment/vindi-bankslippix.html index b878159f..e0dbea1c 100644 --- a/view/frontend/web/template/payment/vindi-bankslippix.html +++ b/view/frontend/web/template/payment/vindi-bankslippix.html @@ -1,9 +1,3 @@ -
- +
diff --git a/view/frontend/web/template/payment/vindi-pix.html b/view/frontend/web/template/payment/vindi-pix.html index 5a7a1e4c..e292c314 100644 --- a/view/frontend/web/template/payment/vindi-pix.html +++ b/view/frontend/web/template/payment/vindi-pix.html @@ -1,9 +1,3 @@ -