diff --git a/Api/PixConfigurationInterface.php b/Api/PixConfigurationInterface.php index 66851055..5496f81d 100644 --- a/Api/PixConfigurationInterface.php +++ b/Api/PixConfigurationInterface.php @@ -8,10 +8,19 @@ 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/Helper/PixConfiguration.php b/Helper/PixConfiguration.php index 329f007a..af79dad1 100644 --- a/Helper/PixConfiguration.php +++ b/Helper/PixConfiguration.php @@ -10,6 +10,14 @@ 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/Payment/Customer.php b/Model/Payment/Customer.php index 21260a28..677eeb2a 100644 --- a/Model/Payment/Customer.php +++ b/Model/Payment/Customer.php @@ -2,19 +2,38 @@ namespace Vindi\Payment\Model\Payment; + +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\Message\ManagerInterface; +use Magento\Sales\Model\Order; +use Vindi\Payment\Helper\Api; + class Customer { + + /** + * @param CustomerRepositoryInterface $customerRepository + * @param Api $api + * @param ManagerInterface $messageManager + */ public function __construct( - \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, - \Vindi\Payment\Helper\Api $api, - \Magento\Framework\Message\ManagerInterface $messageManager + CustomerRepositoryInterface $customerRepository, + Api $api, + ManagerInterface $messageManager ) { $this->customerRepository = $customerRepository; $this->api = $api; $this->messageManager = $messageManager; } - public function findOrCreate($order) + /** + * @param Order $order + * + * @return array|bool|mixed + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function findOrCreate(Order $order) { $billing = $order->getBillingAddress(); $customer = null; @@ -43,7 +62,7 @@ public function findOrCreate($order) $customerVindi = [ 'name' => $billing->getFirstname() . ' ' . $billing->getLastname(), 'email' => $billing->getEmail(), - 'registry_code' => $order->getData('customer_taxvat') ?: '', + 'registry_code' => $this->getDocumentGuest($order), 'code' => $customer ? $customer->getId() : '', 'phones' => $this->formatPhone($billing->getTelephone()), 'address' => $address @@ -95,6 +114,11 @@ public function findVindiCustomer($query) return false; } + /** + * @param $phone + * + * @return string|null + */ public function formatPhone($phone) { $digits = strlen('55' . preg_replace('/^0|\D+/', '', $phone)); @@ -105,4 +129,18 @@ public function formatPhone($phone) return array_key_exists($digits, $phone_types) ? $phone_types[$digits] : null; } + + /** + * @param \Magento\Sales\Model\Order $order + * + * @return mixed|string + */ + protected function getDocumentGuest(Order $order) + { + if($document = $order->getData('customer_taxvat')) { + return $document; + } + + return $order->getPayment()->getAdditionalInformation('document') ?: ''; + } } diff --git a/Model/Pix/ConfigProvider.php b/Model/Pix/ConfigProvider.php index f28e32dc..57957ae7 100644 --- a/Model/Pix/ConfigProvider.php +++ b/Model/Pix/ConfigProvider.php @@ -36,6 +36,7 @@ public function getConfig() return [ 'payment' => [ 'vindi_pix' => [ + 'enabledDocument' => $this->pixConfiguration->isEnabledDocument(), 'info_message' => $this->pixConfiguration->getInfoMessage(), ] ] diff --git a/Observer/DataAssignObserver.php b/Observer/DataAssignObserver.php index 711246f4..41dc9b52 100644 --- a/Observer/DataAssignObserver.php +++ b/Observer/DataAssignObserver.php @@ -1,6 +1,7 @@ + + + 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. + diff --git a/etc/config.xml b/etc/config.xml index 6163b745..e509a5a5 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -24,6 +24,7 @@ 0 Vindi\Payment\Model\Payment\Pix Vindi - Pix + 0 0 authorize offline diff --git a/etc/events.xml b/etc/events.xml index 214d82b4..f0849e44 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -1,8 +1,10 @@ - - + + + - \ No newline at end of file + diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 94162e3c..f3c6ede3 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -127,3 +127,5 @@ "Copy QR Code key","Copiar chave QR Code" "Message if the qr code is not resized.","Mensagem se o QR Code não for redimensionado." "Pay up: %s","Pague até: %s" +"Enabled document","Ativar documento" +"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.","Quando habilitado, só será possível finalizar o pedido com o documento informado ao selecionar o método de pagamento. Quando desabilitado, não será solicitado ao cliente o documento, porém ainda será necessário o envio do documento ao criar o pedido na VINDI, caso contrário será rejeitado pela API." diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js new file mode 100644 index 00000000..d4b42ba6 --- /dev/null +++ b/view/frontend/requirejs-config.js @@ -0,0 +1,5 @@ +const config = { + paths: { + 'jQueryMask': 'Vindi_Payment/js/libs/jquery.mask.min' + }, +} diff --git a/view/frontend/web/js/libs/jquery.mask.min.js b/view/frontend/web/js/libs/jquery.mask.min.js new file mode 100644 index 00000000..986b8391 --- /dev/null +++ b/view/frontend/web/js/libs/jquery.mask.min.js @@ -0,0 +1,19 @@ +// jQuery Mask Plugin v1.14.15 +// github.com/igorescobar/jQuery-Mask-Plugin +var $jscomp={scope:{},findInternal:function(a,l,d){a instanceof String&&(a=String(a));for(var p=a.length,h=0;hd?g=10*e:f>=g&&f!==d?c.maskDigitPosMapOld[g]||(f=g,g=g-(l-h)-a,c.maskDigitPosMap[g]&&(g=f)):g>f&& + (g=g+(h-l)+m)}return g},behaviour:function(f){f=f||window.event;c.invalid=[];var e=b.data("mask-keycode");if(-1===a.inArray(e,m.byPassKeys)){var e=c.getMasked(),g=c.getCaret();setTimeout(function(){c.setCaret(c.calculateCaretPosition())},a.jMaskGlobals.keyStrokeCompensation);c.val(e);c.setCaret(g);return c.callbacks(f)}},getMasked:function(a,b){var g=[],d=void 0===b?c.val():b+"",n=0,h=e.length,q=0,l=d.length,k=1,r="push",p=-1,t=0,y=[],v,z;f.reverse?(r="unshift",k=-1,v=0,n=h-1,q=l-1,z=function(){return-1< + n&&-1 +
+ + +
+
+ +
+ + +
+
+
+
+ + + +
+
+
+
+
+
+
+ +
+