diff --git a/Block/Sales/Form/DeepLink.php b/Block/Sales/Form/DeepLink.php new file mode 100644 index 0000000..78c6dd1 --- /dev/null +++ b/Block/Sales/Form/DeepLink.php @@ -0,0 +1,78 @@ + + * @license See LICENSE for license details. + */ + +namespace PagBank\PaymentMagento\Block\Sales\Form; + +use Magento\Framework\View\Element\Template\Context; +use PagBank\PaymentMagento\Gateway\Config\ConfigDeepLink; + +/** + * Class DeepLink - Form for payment by DeepLink. + */ +class DeepLink extends \Magento\Payment\Block\Form +{ + /** + * DeepLink Form template. + */ + public const TEMPLATE = 'PagBank_PaymentMagento::form/deep-link.phtml'; + + /** + * Get relevant path to template. + * + * @return string + */ + public function getTemplate() + { + return self::TEMPLATE; + } + + /** + * @var ConfigDeepLink + */ + protected $configDeepLink; + + /** + * @param Context $context + * @param ConfigDeepLink $configDeepLink + */ + public function __construct( + Context $context, + ConfigDeepLink $configDeepLink + ) { + parent::__construct($context); + $this->configDeepLink = $configDeepLink; + } + + /** + * Title - DeepLink. + * + * @return string + */ + public function getTitle() + { + return $this->configDeepLink->getTitle(); + } + + /** + * Get Instruction. + * + * @param int|null $storeId + * + * @return Phrase + */ + public function getInstruction() + { + $text = $this->configDeepLink->getInstructionCheckout(); + + $replaceText = __($text); + + return $replaceText; + } +} diff --git a/Block/Sales/Info/DeepLink.php b/Block/Sales/Info/DeepLink.php new file mode 100644 index 0000000..6d5c2fb --- /dev/null +++ b/Block/Sales/Info/DeepLink.php @@ -0,0 +1,64 @@ + + * @license See LICENSE for license details. + */ + +namespace PagBank\PaymentMagento\Block\Sales\Info; + +use Magento\Framework\Phrase; +use Magento\Payment\Block\ConfigurableInfo; + +/** + * Class DeepLink - DeepLink payment information. + */ +class DeepLink extends ConfigurableInfo +{ + /** + * DeepLink Info template. + */ + public const TEMPLATE = 'PagBank_PaymentMagento::info/deep-link/instructions.phtml'; + + /** + * Get relevant path to template. + * + * @return string + */ + public function getTemplate() + { + return self::TEMPLATE; + } + + /** + * Returns value view. + * + * @param string $field + * @param string $value + * + * @return string | Phrase + */ + protected function getValueView($field, $value) + { + if ($field === 'qr_code_url_image') { + return $this->getImageQrCode($value); + } + + return parent::getValueView($field, $value); + } + + /** + * Get Url to Image Qr Code. + * + * @param string $qrCode + * + * @return string + */ + public function getImageQrCode($qrCode) + { + return $this->_urlBuilder->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]).$qrCode; + } +} diff --git a/Block/Sales/Order/Success.php b/Block/Sales/Order/Success.php index a9a1cae..8ed9fe7 100644 --- a/Block/Sales/Order/Success.php +++ b/Block/Sales/Order/Success.php @@ -30,6 +30,11 @@ class Success extends Template */ public const TEMPLATE_PIX = 'PagBank_PaymentMagento::sales/order/success/pix.phtml'; + /** + * Template Pix. + */ + public const TEMPLATE_DEEP_LINK = 'PagBank_PaymentMagento::sales/order/success/deep-link.phtml'; + /** * @var Session */ @@ -67,8 +72,9 @@ public function getTemplate() $paymentType = $this->getMethodCode(); $templates = [ - 'pagbank_paymentmagento_boleto' => self::TEMPLATE_BOLETO, - 'pagbank_paymentmagento_pix' => self::TEMPLATE_PIX, + 'pagbank_paymentmagento_boleto' => self::TEMPLATE_BOLETO, + 'pagbank_paymentmagento_pix' => self::TEMPLATE_PIX, + 'pagbank_paymentmagento_deep_link' => self::TEMPLATE_DEEP_LINK, ]; if (isset($templates[$paymentType])) { diff --git a/Cron/GetStatusUpdate.php b/Cron/GetStatusUpdate.php index cd66814..c5e05d5 100644 --- a/Cron/GetStatusUpdate.php +++ b/Cron/GetStatusUpdate.php @@ -37,6 +37,11 @@ class GetStatusUpdate */ public const PAYMENT_METHOD_PIX = 'pagbank_paymentmagento_pix'; + /** + * Payment Method Deep Link. + */ + public const PAYMENT_METHOD_DEEP_LINK = 'pagbank_paymentmagento_deep_link'; + /** * Payment Method Boleto. */ @@ -145,6 +150,27 @@ public function findPix() } } + /** + * Find Deep Link. + * + * @return void + */ + public function findDeepLink() + { + $orders = $this->getFilterdOrders(self::PAYMENT_METHOD_DEEP_LINK); + + foreach ($orders as $order) { + $incrementId = $order->getIncrementId(); + + try { + $this->update->getUpdate($incrementId); + } catch (\Throwable $th) { + $this->errorNotificationManager($order); + continue; + } + } + } + /** * Find Boleto. * diff --git a/Gateway/Config/Config.php b/Gateway/Config/Config.php index f3899f1..6dd3e64 100644 --- a/Gateway/Config/Config.php +++ b/Gateway/Config/Config.php @@ -467,9 +467,9 @@ public function createFile(WriteInterface $writeDirectory, $filePath, $fileToCop */ public function hasPathDir($type): bool { - $pixPath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('/pagbank/'.$type); + $path = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('/pagbank/'.$type); - return $this->fileIo->checkAndCreateFolder($pixPath); + return $this->fileIo->checkAndCreateFolder($path); } /** diff --git a/Gateway/Config/ConfigDeepLink.php b/Gateway/Config/ConfigDeepLink.php new file mode 100644 index 0000000..78fe663 --- /dev/null +++ b/Gateway/Config/ConfigDeepLink.php @@ -0,0 +1,193 @@ + + * @license See LICENSE for license details. + */ + +declare(strict_types=1); + +namespace PagBank\PaymentMagento\Gateway\Config; + +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Phrase; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Payment\Gateway\Config\Config as PaymentConfig; +use Magento\Store\Model\ScopeInterface; + +/** + * Class Config DeepLink - Returns form of payment configuration properties for DeepLink. + */ +class ConfigDeepLink extends PaymentConfig +{ + /** + * @const string + */ + public const METHOD = 'pagbank_paymentmagento_deep_link'; + + /** + * @const string + */ + public const ACTIVE = 'active'; + + /** + * @const string + */ + public const TITLE = 'title'; + + /** + * @const string + */ + public const INSTRUCTION_CHECKOUT = 'instruction_checkout'; + + /** + * @const string + */ + public const GET_TAX_ID = 'get_tax_id'; + + /** + * @const string + */ + public const GET_NAME = 'get_name'; + + /** + * @const string + */ + public const GET_PHONE = 'get_phone'; + + /** + * @var ScopeConfigInterface + */ + protected $scopeConfig; + + /** + * @var DateTime + */ + protected $date; + + /** + * @param ScopeConfigInterface $scopeConfig + * @param DateTime $date + * @param string $methodCode + */ + public function __construct( + ScopeConfigInterface $scopeConfig, + DateTime $date, + $methodCode = self::METHOD + ) { + parent::__construct($scopeConfig, $methodCode); + $this->scopeConfig = $scopeConfig; + $this->date = $date; + } + + /** + * Get Payment configuration status. + * + * @param int|null $storeId + * + * @return bool + */ + public function isActive($storeId = null): bool + { + $pathPattern = 'payment/%s/%s'; + + return (bool) $this->scopeConfig->getValue( + sprintf($pathPattern, self::METHOD, self::ACTIVE), + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + + /** + * Get title of payment. + * + * @param int|null $storeId + * + * @return string|null + */ + public function getTitle($storeId = null): ?string + { + $pathPattern = 'payment/%s/%s'; + + return $this->scopeConfig->getValue( + sprintf($pathPattern, self::METHOD, self::TITLE), + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + + /** + * Get Instruction - Checkoout. + * + * @param int|null $storeId + * + * @return string|null + */ + public function getInstructionCheckout($storeId = null): ?string + { + $pathPattern = 'payment/%s/%s'; + + return $this->scopeConfig->getValue( + sprintf($pathPattern, self::METHOD, self::INSTRUCTION_CHECKOUT), + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + + /** + * Get if tax id capture on the form. + * + * @param int|null $storeId + * + * @return bool + */ + public function hasTaxIdCapture($storeId = null): bool + { + $pathPattern = 'payment/%s/%s'; + + return (bool) $this->scopeConfig->getValue( + sprintf($pathPattern, self::METHOD, self::GET_TAX_ID), + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + + /** + * Get if name capture on the form. + * + * @param int|null $storeId + * + * @return bool + */ + public function hasNameCapture($storeId = null): bool + { + $pathPattern = 'payment/%s/%s'; + + return (bool) $this->scopeConfig->getValue( + sprintf($pathPattern, self::METHOD, self::GET_NAME), + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + + /** + * Get if phone capture on the form. + * + * @param int|null $storeId + * + * @return bool + */ + public function hasPhoneCapture($storeId = null): bool + { + $pathPattern = 'payment/%s/%s'; + + return (bool) $this->scopeConfig->getValue( + sprintf($pathPattern, self::METHOD, self::GET_PHONE), + ScopeInterface::SCOPE_STORE, + $storeId + ); + } +} diff --git a/Gateway/Http/Client/CreateOrderPaymentDeepLinkClient.php b/Gateway/Http/Client/CreateOrderPaymentDeepLinkClient.php new file mode 100644 index 0000000..a42c0db --- /dev/null +++ b/Gateway/Http/Client/CreateOrderPaymentDeepLinkClient.php @@ -0,0 +1,82 @@ + + * @license See LICENSE for license details. + */ + +declare(strict_types=1); + +namespace PagBank\PaymentMagento\Gateway\Http\Client; + +use Magento\Payment\Gateway\Http\ClientInterface; +use Magento\Payment\Gateway\Http\TransferInterface; + +/** + * Class Create Order Payment DeepLink Client - create order for payment for DeepLink. + */ +class CreateOrderPaymentDeepLinkClient implements ClientInterface +{ + /** + * Result Code - Block name. + */ + public const RESULT_CODE = 'RESULT_CODE'; + + /** + * External Order Id - Block name. + */ + public const EXT_ORD_ID = 'id'; + + /** + * Reponse Pay Status - Block Name. + */ + public const STATUS = 'status'; + + /** + * @var ApiClient + */ + protected $api; + + /** + * @param ApiClient $api + */ + public function __construct( + ApiClient $api + ) { + $this->api = $api; + } + + /** + * Places request to gateway. + * + * @param TransferInterface $transferObject + * + * @return array + */ + public function placeRequest(TransferInterface $transferObject) + { + $response = []; + + $request = $transferObject->getBody(); + + $path = 'orders'; + + $data = $this->api->sendPostRequest($transferObject, $path, $request); + + $status = isset($data[self::EXT_ORD_ID]) ?: 0; + + if (is_array($data)) { + $response = array_merge( + [ + self::RESULT_CODE => ($status) ? 1 : 0, + ], + $data + ); + } + + return $response; + } +} diff --git a/Gateway/Request/DeepLink/DeepLinkDataRequest.php b/Gateway/Request/DeepLink/DeepLinkDataRequest.php new file mode 100644 index 0000000..55225de --- /dev/null +++ b/Gateway/Request/DeepLink/DeepLinkDataRequest.php @@ -0,0 +1,88 @@ + + * @license See LICENSE for license details. + */ + +namespace PagBank\PaymentMagento\Gateway\Request\DeepLink; + +use Magento\Payment\Gateway\Data\PaymentDataObject; +use Magento\Payment\Gateway\Helper\SubjectReader; +use Magento\Payment\Gateway\Request\BuilderInterface; +use PagBank\PaymentMagento\Gateway\Config\Config; +use PagBank\PaymentMagento\Gateway\Config\ConfigDeepLink; + +/** + * Class Deep Link Data Request - Structure for QRCode information in orders. + */ +class DeepLinkDataRequest implements BuilderInterface +{ + /** + * Deep Link block name. + */ + public const DEEP_LINK = 'deep_links'; + + /** + * Amount block name. + */ + public const AMOUNT = 'amount'; + + /** + * Amount Value block name. + */ + public const AMOUNT_VALUE = 'value'; + + /** + * @var Config + */ + protected $config; + + /** + * @var ConfigDeepLink + */ + protected $configDeepLink; + + /** + * @param Config $config + * @param ConfigDeepLink $configDeepLink + */ + public function __construct( + Config $config, + ConfigDeepLink $configDeepLink + ) { + $this->config = $config; + $this->configDeepLink = $configDeepLink; + } + + /** + * Build. + * + * @param array $buildSubject + * + * @SuppressWarnings(PHPMD.StaticAccess) + */ + public function build(array $buildSubject) + { + $result = []; + + /** @var PaymentDataObject $paymentDO * */ + $paymentDO = SubjectReader::readPayment($buildSubject); + + /** @var \Magento\Sales\Model\Order $order */ + $order = $paymentDO->getOrder(); + + $grandTotal = $order->getGrandTotalAmount(); + + $result[self::DEEP_LINK][] = [ + self::AMOUNT => [ + self::AMOUNT_VALUE => $this->config->formatPrice($grandTotal), + ] + ]; + + return $result; + } +} diff --git a/Gateway/Request/DeepLink/QrCodeDataRequest.php b/Gateway/Request/DeepLink/QrCodeDataRequest.php new file mode 100644 index 0000000..318dc17 --- /dev/null +++ b/Gateway/Request/DeepLink/QrCodeDataRequest.php @@ -0,0 +1,87 @@ + + * @license See LICENSE for license details. + */ + +namespace PagBank\PaymentMagento\Gateway\Request\DeepLink; + +use Magento\Payment\Gateway\Data\PaymentDataObject; +use Magento\Payment\Gateway\Helper\SubjectReader; +use Magento\Payment\Gateway\Request\BuilderInterface; +use PagBank\PaymentMagento\Gateway\Config\Config; + +/** + * Class Qr Code Data Request - Structure for QRCode information in orders. + */ +class QrCodeDataRequest implements BuilderInterface +{ + /** + * Qr Code block name. + */ + public const QR_CODES = 'qr_codes'; + + /** + * Arrangements block name. + */ + public const ARRANGEMENTS = 'arrangements'; + + /** + * Amount block name. + */ + public const AMOUNT = 'amount'; + + /** + * Amount Value block name. + */ + public const AMOUNT_VALUE = 'value'; + + /** + * @var Config + */ + protected $config; + + /** + * @param Config $config + */ + public function __construct( + Config $config + ) { + $this->config = $config; + } + + /** + * Build. + * + * @param array $buildSubject + * + * @SuppressWarnings(PHPMD.StaticAccess) + */ + public function build(array $buildSubject) + { + $result = []; + + /** @var PaymentDataObject $paymentDO * */ + $paymentDO = SubjectReader::readPayment($buildSubject); + + /** @var \Magento\Sales\Model\Order $order */ + $order = $paymentDO->getOrder(); + + $grandTotal = $order->getGrandTotalAmount(); + + $result[self::QR_CODES][] = [ + self::AMOUNT => [ + self::AMOUNT_VALUE => $this->config->formatPrice($grandTotal), + ], + self::ARRANGEMENTS => [ + "PAGBANK" + ] + ]; + + return $result; + } +} diff --git a/Gateway/Response/FetchPaymentHandler.php b/Gateway/Response/FetchPaymentHandler.php index 91a3d75..1ae2c2e 100644 --- a/Gateway/Response/FetchPaymentHandler.php +++ b/Gateway/Response/FetchPaymentHandler.php @@ -68,6 +68,11 @@ class FetchPaymentHandler implements HandlerInterface */ public const RESPONSE_STATUS_CANCELED = 'CANCELED'; + /** + * Response Pay Status Waiting - Value. + */ + public const RESPONSE_STATUS_WAITING = 'WAITING'; + /** * Response Pay Authorized - Block name. */ @@ -98,6 +103,7 @@ public function __construct( * * @param array $handlingSubject * @param array $response + * @SuppressWarnings(PHPMD.CyclomaticComplexity) * * @return void */ @@ -141,6 +147,10 @@ public function handle(array $handlingSubject, array $response) $this->setPaymentDeny($payment, $paymentParentId, $pagbankPayId, $amount); $order->isPaymentReview(0); } + + if ($this->finalStatus === 'WAITING') { + $this->setPaymentWaiting($payment); + } } } } @@ -159,6 +169,10 @@ public function findForPaymentStatus($response, $charges) foreach ($charges as $charge) { switch ($charge[self::RESPONSE_STATUS]) { + case self::RESPONSE_STATUS_WAITING: + $this->finalStatus = 'WAITING'; + break; + case self::RESPONSE_AUTHORIZED: $this->finalStatus = 'AUTH'; break; @@ -181,6 +195,26 @@ public function findForPaymentStatus($response, $charges) } } + /** + * Set Payment Auth. + * + * @param InfoInterface $payment + * + * @return void + */ + public function setPaymentWaiting($payment) + { + $order = $payment->getOrder(); + $payment->setIsTransactionApproved(false); + $payment->setIsTransactionDenied(false); + $payment->setIsTransactionPending(true); + $payment->setIsInProcess(false); + $payment->setIsTransactionClosed(false); + $comment = __('Awaiting payment.'); + $order->addStatusHistoryComment($comment, $payment->getOrder()->getStatus()); + $order->save(); + } + /** * Set Payment Auth. * diff --git a/Gateway/Response/TxnDataDeepLinkHandler.php b/Gateway/Response/TxnDataDeepLinkHandler.php new file mode 100644 index 0000000..b480e27 --- /dev/null +++ b/Gateway/Response/TxnDataDeepLinkHandler.php @@ -0,0 +1,180 @@ + + * @license See LICENSE for license details. + */ + +namespace PagBank\PaymentMagento\Gateway\Response; + +use InvalidArgumentException; +use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; +use Magento\Payment\Gateway\Response\HandlerInterface; +use Magento\Payment\Model\InfoInterface; +use PagBank\PaymentMagento\Gateway\Config\Config; + +/** + * Txn Data DeepLink Handler - Reply Flow for DeepLink data. + */ +class TxnDataDeepLinkHandler implements HandlerInterface +{ + + /** + * Creation Date Qrcode - Payment Addtional Information. + */ + public const PAYMENT_INFO_CREATION_DATE_QRCODE = 'creation_date_qrcode'; + + /** + * Expiration Date - Payment Addtional Information. + */ + public const PAYMENT_INFO_EXPIRATION_DATE = 'expiration_date'; + + /** + * Qr Code Image - Payment Addtional Information. + */ + public const PAYMENT_INFO_QR_CODE_URL_IMAGE = 'qr_code_url_image'; + + /** + * Deep Link Url - Payment Addtional Information. + */ + public const PAYMENT_INFO_DEEP_LINK_URL = 'deep_link_url'; + + /** + * Response Pay PagBank Id - Block name. + */ + public const REPONSE_PAGBANK_ID = 'id'; + + /** + * Response Pay Qr Codes - Block name. + */ + public const RESPONSE_QR_CODES = 'qr_codes'; + + /** + * Response Pay Deep Link - Block name. + */ + public const RESPONSE_DEEP_LINK = 'deep_links'; + + /** + * Response Pay Deep Link Url - Block name. + */ + public const RESPONSE_DEEP_LINK_URL = 'url'; + + /** + * Response Pay Qr Codes - Block name. + */ + public const RESPONSE_QR_CODES_ID = 'id'; + + /** + * Response Pay Qr Codes Expiration Date - Block name. + */ + public const RESPONSE_QR_CODES_EXPIRATION_DATE = 'expiration_date'; + + /** + * Response Pay Qr Codes Text - Block name. + */ + public const RESPONSE_QR_CODES_TEXT = 'text'; + + /** + * Response Pay Charges Links - Block name. + */ + public const RESPONSE_QR_CODES_LINKS = 'links'; + + /** + * Response Pay Charges Links Href - Block name. + */ + public const RESPONSE_QR_CODES_LINKS_HREF = 'href'; + + /** + * Response Pay Charges Links Media - Block name. + */ + public const RESPONSE_QR_CODES_LINKS_MEDIA = 'media'; + + /** + * Response Pay Charges Links Media for Image PNG - Block name. + */ + public const RESPONSE_QR_CODES_LINKS_MEDIA_FOR_IMAGE = 'image/png'; + + /** + * @var Config + */ + protected $configBase; + + /** + * @param Config $configBase + */ + public function __construct( + Config $configBase + ) { + $this->configBase = $configBase; + } + + /** + * Handles. + * + * @param array $handlingSubject + * @param array $response + * + * @return void + */ + public function handle(array $handlingSubject, array $response) + { + if (!isset($handlingSubject['payment']) + || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface + ) { + throw new InvalidArgumentException('Payment data object should be provided'); + } + + $paymentDO = $handlingSubject['payment']; + + $payment = $paymentDO->getPayment(); + + $qrCodes = $response[self::RESPONSE_QR_CODES][0]; + + $pagbankPayId = $qrCodes[self::RESPONSE_QR_CODES_ID]; + + /** Popule Additional Info */ + $this->setAdditionalInfo($payment, $response, $pagbankPayId); + } + + /** + * Set Additional Info. + * + * @param InfoInterface $payment + * @param array $response + * @param string $pagbankPayId + * + * @return void + */ + public function setAdditionalInfo( + $payment, + $response, + $pagbankPayId + ) { + $qrCodes = $response[self::RESPONSE_QR_CODES][0]; + $deepLink = $response[self::RESPONSE_DEEP_LINK][0]; + + if (isset($deepLink[self::RESPONSE_DEEP_LINK_URL])) { + $linkToImage = 'https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl='. + urlencode($deepLink[self::RESPONSE_DEEP_LINK_URL]); + + $qrCodeImage = $this->configBase->copyFile('deep_link', $linkToImage, $pagbankPayId); + $payment->setAdditionalInformation( + self::PAYMENT_INFO_QR_CODE_URL_IMAGE, + $qrCodeImage + ); + } + + $payment->setAdditionalInformation( + self::PAYMENT_INFO_EXPIRATION_DATE, + $qrCodes[self::RESPONSE_QR_CODES_EXPIRATION_DATE] + ); + + $payment->setAdditionalInformation( + self::PAYMENT_INFO_DEEP_LINK_URL, + $deepLink[self::RESPONSE_DEEP_LINK_URL] + ); + } +} diff --git a/Model/Console/Command/Orders/Update.php b/Model/Console/Command/Orders/Update.php index 22ca78c..99ac26b 100644 --- a/Model/Console/Command/Orders/Update.php +++ b/Model/Console/Command/Orders/Update.php @@ -35,6 +35,11 @@ class Update extends AbstractModel */ public const TIME_DUE_PIX = 5; + /** + * Time due for Deep Link. + */ + public const TIME_DUE_DEEP_LINK = 5; + /** * Time due for Boleto. */ @@ -197,6 +202,10 @@ public function hasExpired($payment) $due = self::TIME_DUE_BOLETO * -1; } + if ($method === 'pagbank_paymentmagento_deep_link') { + $due = self::TIME_DUE_DEEP_LINK * -1; + } + $initDateNow = $this->date->gmtDate('Y-m-d\TH:i:s.uP', strtotime("{$due} minutes")); $dateNow = $this->localeDate->date($initDateNow)->format('Y-m-d H:i:s'); diff --git a/Model/Ui/ConfigProviderBase.php b/Model/Ui/ConfigProviderBase.php index a3e5298..eb7c09b 100644 --- a/Model/Ui/ConfigProviderBase.php +++ b/Model/Ui/ConfigProviderBase.php @@ -40,6 +40,11 @@ class ConfigProviderBase implements ConfigProviderInterface */ public const METHOD_CODE_BOLETO = 'pagbank_paymentmagento_boleto'; + /* + * @var METHOD CODE Deep Link + */ + public const METHOD_CODE_DEEP_LINK = 'pagbank_paymentmagento_deep_link'; + /** * @var Config */ diff --git a/Model/Ui/ConfigProviderDeepLink.php b/Model/Ui/ConfigProviderDeepLink.php new file mode 100644 index 0000000..849cdd2 --- /dev/null +++ b/Model/Ui/ConfigProviderDeepLink.php @@ -0,0 +1,139 @@ + + * @license See LICENSE for license details. + */ + +namespace PagBank\PaymentMagento\Model\Ui; + +use Magento\Checkout\Model\ConfigProviderInterface; +use Magento\Framework\Escaper; +use Magento\Framework\Phrase; +use Magento\Framework\View\Asset\Source; +use Magento\Payment\Model\CcConfig; +use Magento\Quote\Api\Data\CartInterface; +use PagBank\PaymentMagento\Gateway\Config\ConfigDeepLink; + +/** + * Class Config Provider DeepLink - Defines properties of the payment form.. + */ +class ConfigProviderDeepLink implements ConfigProviderInterface +{ + /* + * @const string + */ + public const CODE = 'pagbank_paymentmagento_deep_link'; + + /** + * @var ConfigDeepLink + */ + protected $config; + + /** + * @var CartInterface + */ + protected $cart; + + /** + * @var CcConfig + */ + protected $ccConfig; + + /** + * @var Escaper + */ + protected $escaper; + + /** + * @var Source + */ + protected $assetSource; + + /** + * @param ConfigDeepLink $config + * @param CartInterface $cart + * @param CcConfig $ccConfig + * @param Escaper $escaper + * @param Source $assetSource + */ + public function __construct( + ConfigDeepLink $config, + CartInterface $cart, + CcConfig $ccConfig, + Escaper $escaper, + Source $assetSource + ) { + $this->config = $config; + $this->cart = $cart; + $this->escaper = $escaper; + $this->ccConfig = $ccConfig; + $this->assetSource = $assetSource; + } + + /** + * Retrieve assoc array of checkout configuration. + * + * @return array + */ + public function getConfig() + { + $storeId = $this->cart->getStoreId(); + + return [ + 'payment' => [ + self::CODE => [ + 'isActive' => $this->config->isActive($storeId), + 'title' => $this->config->getTitle($storeId), + 'name_capture' => $this->config->hasNameCapture($storeId), + 'tax_id_capture' => $this->config->hasTaxIdCapture($storeId), + 'phone_capture' => $this->config->hasPhoneCapture($storeId), + 'instruction_checkout' => nl2br($this->getInstruction($storeId)), + 'logo' => $this->getLogo(), + ], + ], + ]; + } + + /** + * Get Instruction. + * + * @param int|null $storeId + * + * @return Phrase + */ + public function getInstruction($storeId) + { + $text = $this->config->getInstructionCheckout($storeId); + + return $this->escaper->escapeHtml( + $text, + ['b', 'a', 'h3', 'target'] + ); + } + + /** + * Get icons for available payment methods. + * + * @return array + */ + public function getLogo() + { + $logo = []; + $asset = $this->ccConfig->createAsset('PagBank_PaymentMagento::images/deep-link/logo.svg'); + $placeholder = $this->assetSource->findSource($asset); + if ($placeholder) { + $logo = [ + 'url' => $asset->getUrl(), + 'width' => '48px', + 'height' => '32px', + 'title' => __('`Pay in PagBank'), + ]; + } + + return $logo; + } +} diff --git a/Plugin/SalesOrderViewButtonPlugin.php b/Plugin/SalesOrderViewButtonPlugin.php index af59016..c13eb09 100644 --- a/Plugin/SalesOrderViewButtonPlugin.php +++ b/Plugin/SalesOrderViewButtonPlugin.php @@ -71,7 +71,8 @@ public function aroundAddButton( $method = (string) $payment->getMethod(); if ($method === 'pagbank_paymentmagento_pix' - || $method === 'pagbank_paymentmagento_boleto') { + || $method === 'pagbank_paymentmagento_boleto' + || $method === 'pagbank_paymentmagento_deep_link') { if ($buttonId === 'accept_payment') { $message = __('This decision will not change the status in PagBank.'); $data = [ diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index 571c37d..d6fdc20 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -31,5 +31,12 @@ + + + + 0 + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index b23cbe1..c2f9653 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -21,6 +21,7 @@ + diff --git a/etc/adminhtml/system/deep_link.xml b/etc/adminhtml/system/deep_link.xml new file mode 100644 index 0000000..16e5f11 --- /dev/null +++ b/etc/adminhtml/system/deep_link.xml @@ -0,0 +1,84 @@ + + + + + + O botão de pagamento que deixa você um passo à frente da concorrência! + + + Magento\Config\Model\Config\Source\Yesno + payment/pagbank_paymentmagento_deep_link/active + + + + payment/pagbank_paymentmagento_deep_link/title + + + + Information displayed at checkout. + payment/pagbank_paymentmagento_deep_link/instruction_checkout + + + + PagBank\PaymentMagento\Model\Adminhtml\Source\PaymentActionBoleto + payment/pagbank_paymentmagento_deep_link/payment_action + + + + Basic configuration of payment methods. + + + validate-number validate-zero-or-greater + payment/pagbank_paymentmagento_deep_link/min_order_total + + + + validate-number validate-zero-or-greater + payment/pagbank_paymentmagento_deep_link/max_order_total + + + + Magento\Payment\Model\Config\Source\Allspecificcountries + payment/pagbank_paymentmagento_deep_link/allowspecific + + + + Magento\Directory\Model\Config\Source\Country + payment/pagbank_paymentmagento_deep_link/specificcountry + + + + validate-number + payment/pagbank_paymentmagento_deep_link/sort_order + + + + + Define the payment form data capture. + + + Magento\Config\Model\Config\Source\Yesno + payment/pagbank_paymentmagento_deep_link/get_name + + + + Magento\Config\Model\Config\Source\Yesno + payment/pagbank_paymentmagento_deep_link/get_tax_id + + + + Magento\Config\Model\Config\Source\Yesno + payment/pagbank_paymentmagento_deep_link/get_phone + + + + \ No newline at end of file diff --git a/etc/config.xml b/etc/config.xml index 27cd38c..08afe42 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -184,6 +184,40 @@ A confirmação do seu pagamento é automática, em até 5 minutos.]]>BR 12 + + pagbank_group + PagBankDeepLinkFacade + order + pending + BRL + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + qr_code_url_image,deep_link_url,expiration_date,payer_name,payer_phone,payer_tax_id + 1 + Pagar com PagBank + + 0 + 0 + 0 + 1 + 200000 + 1 + BR + 11 + diff --git a/etc/crontab.xml b/etc/crontab.xml index 1cdad3f..005c8ce 100644 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -23,6 +23,9 @@ */30 * * * * + + 0 */1 * * * + 0 7 * * 1-5 diff --git a/etc/di.xml b/etc/di.xml index 6fcbff1..a899cf8 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -118,6 +118,17 @@ + + + PagBank\PaymentMagento\Model\Ui\ConfigProviderDeepLink::CODE + PagBank\PaymentMagento\Block\Sales\Form\DeepLink + PagBank\PaymentMagento\Block\Sales\Info\DeepLink + PagBankDeepLinkValueHandlerPool + PagBankDeepLinkValidatorPool + PagBankDeepLinkCommandPool + + + @@ -126,6 +137,7 @@ PagBankCcCommandManager PagBankBoletoCommandManager PagBankPixCommandManager + PagBankDeepLinkCommandManager @@ -162,6 +174,12 @@ + + + \PagBank\PaymentMagento\Model\Ui\ConfigProviderDeepLink::CODE + + + @@ -181,6 +199,12 @@ + + + PagBankDeepLinkConfig + + + @@ -330,6 +354,81 @@ + + + + + + + PagBankDeepLinkOrderCommand + PagBankRefundCommand + PagBankBaseFetchCommand + + + + + + + + PagBankDeepLinkCommandPool + PagBankDeepLinkOrderRequest + PagBankDeepLinkOrderResponseHandlerComposite + PagBank\PaymentMagento\Gateway\Http\TransferFactory + PagBank\PaymentMagento\Gateway\Http\Client\CreateOrderPaymentDeepLinkClient + PagBankTransactionValidator + PagBankVirtualErrorMessageMapper + + + + + + + + PagBank\PaymentMagento\Gateway\Request\MetadataRequest + PagBank\PaymentMagento\Gateway\Request\ReferenceIdRequest + PagBank\PaymentMagento\Gateway\Request\DescriptionDataRequest + PagBank\PaymentMagento\Gateway\Request\AmountDataRequest + PagBank\PaymentMagento\Gateway\Request\CustomerDataRequest + PagBank\PaymentMagento\Gateway\Request\ItemsDataRequest + PagBank\PaymentMagento\Gateway\Request\ShippingsDataRequest + PagBank\PaymentMagento\Gateway\Request\BillingAddressDataRequest + PagBank\PaymentMagento\Gateway\Request\NotificationUrlDataRequest + + PagBank\PaymentMagento\Gateway\Request\DeepLink\QrCodeDataRequest + PagBank\PaymentMagento\Gateway\Request\DeepLink\DeepLinkDataRequest + + + + + + + + + PagBank\PaymentMagento\Gateway\Response\ExtOrdIdHandler + PagBank\PaymentMagento\Gateway\Response\TxnOrderedHandler + PagBank\PaymentMagento\Gateway\Response\TxnDataDeepLinkHandler + + + + + + + + + PagBankDeepLinkCountryValidator + + + + + + + + PagBank\PaymentMagento\Gateway\Config\ConfigDeepLink + + + + + @@ -415,7 +514,6 @@ - @@ -432,6 +530,8 @@ + + @@ -727,6 +827,26 @@ + + + PagBankDeepLinkCommandPool + + + + + + + PagBankDeepLinkConfigValueHandler + + + + + + + PagBankDeepLinkConfig + + + diff --git a/etc/events.xml b/etc/events.xml index bdec8d1..d14d3ca 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -25,4 +25,7 @@ + + + diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 9e32c7f..179923f 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -18,6 +18,7 @@ PagBank\PaymentMagento\Model\Ui\Vault\ConfigProvider PagBank\PaymentMagento\Model\Ui\ConfigProviderBoleto PagBank\PaymentMagento\Model\Ui\ConfigProviderPix + PagBank\PaymentMagento\Model\Ui\ConfigProviderDeepLink @@ -42,6 +43,13 @@ + + + + 1 + + + diff --git a/etc/payment.xml b/etc/payment.xml index 6e7a95d..046e1a9 100644 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -26,5 +26,8 @@ 0 + + 0 + diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 101788a..4e8a228 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -23,8 +23,8 @@ Production,Production "%1 minutes","%1 minutes" "Pay for Order #%1","Pay for Order #%1" "Order Canceled.","Order Canceled." -"Awaiting payment review.","Awaiting payment review." "Awaiting payment.","Awaiting payment." +"Awaiting payment review.","Awaiting payment review." "Gateway rejected the transaction.","Gateway rejected the transaction." "Sandbox - Environment for tests","Sandbox - Environment for tests" "1 installment","1 installment" @@ -75,6 +75,7 @@ Finished,Finished "Update not available because the initial state is incompatible: %1","Update not available because the initial state is incompatible: %1" "Boleto Bancário - PagBank","Boleto Bancário - PagBank" "Cartão de Crédito - PagBank","Cartão de Crédito - PagBank" +"`Pay in PagBank","`Pay in PagBank" "Pix - PagBank","Pix - PagBank" "Get Payment Update","Get Payment Update" "This decision will not change the status in PagBank.","This decision will not change the status in PagBank." @@ -89,12 +90,20 @@ Link,Link "Line Code","Line Code" "Payer Name","Payer Name" "Payer Tax Id","Payer Tax Id" +"Pay by Compute","Pay by Compute" +"Pay by Mobile","Pay by Mobile" +"Payer Phone","Payer Phone" "Pix Qr Code","Pix Qr Code" "Pix Copy and Paste","Pix Copy and Paste" -"Payer Phone","Payer Phone" "The Boleto barcode is","The Boleto barcode is" Copy,Copy Copied,Copied +"To make the payment:","To make the payment:" +"Access your PagBank account by clicking on the link:","Access your PagBank account by clicking on the link:" +"You must be redirected to PagBank to complete the payment.","You must be redirected to PagBank to complete the payment." +"Use the camera on your mobile device to scan the QR Code:","Use the camera on your mobile device to scan the QR Code:" +"Pay in PagBank","Pay in PagBank" +"You must click the link indicated by the camera.","You must click the link indicated by the camera." "To pay, read the Qr Code","To pay, read the Qr Code" "Or if you prefer, copy and paste the code","Or if you prefer, copy and paste the code" "Boleto Information","Boleto Information" @@ -112,6 +121,7 @@ Waiting...,Waiting... "A 3-digit number in italics on the back of your credit card.","A 3-digit number in italics on the back of your credit card." Month,Month Year,Year +"Information for paying with PagBank","Information for paying with PagBank" "Payer Information","Payer Information" "Payer Tax id","Payer Tax id" "Payer Full Name","Payer Full Name" @@ -171,12 +181,6 @@ Title,Title "You can run charges to a credit card using national currency and to top it off with rates that fit your pocket.","You can run charges to a credit card using national currency and to top it off with rates that fit your pocket." "Enabled Vault","Enabled Vault" "Credit Card Types","Credit Card Types" -"3D Secure","3D Secure" -"3D Secure configuration.","3D Secure configuration." -"Authorization is required to use this service. Please get in touch with PagBank for further assistance.","Authorization is required to use this service. Please get in touch with PagBank for further assistance." -"Reject payment not authenticated","Reject payment not authenticated" -"Instruction before challenge","Instruction before challenge" -"%1 and %2 are two variables, they will be replaced by the card's flag and the issuer bank's name, respectively.","%1 and %2 are two variables, they will be replaced by the card's flag and the issuer bank's name, respectively." "Capture phone in the payment form?","Capture phone in the payment form?" "Installment and interest","Installment and interest" "Maximum number of installment","Maximum number of installment" @@ -185,6 +189,8 @@ Title,Title "Number of installments you want to accept without applying interest","Number of installments you want to accept without applying interest" "The minimum installment price","The minimum installment price" "It is the minimum value that the installment can have","It is the minimum value that the installment can have" +"Pague com PagBank","Pague com PagBank" +"O botão de pagamento que deixa você um passo à frente da concorrência!","O botão de pagamento que deixa você um passo à frente da concorrência!" Developers,Developers "Meet our Wiki.","Meet our Wiki." Debug,Debug diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 6bd900b..e259ffd 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -89,12 +89,20 @@ Link,Link "Line Code","Linha digitável" "Payer Name","Nome do Pagador" "Payer Tax Id","CPF/CNPJ do Pagador" +"Pay by Compute","Pagar pelo Computador" +"Pay by Mobile","Pagar pelo Celular" "Pix Qr Code","Pix Qr Code" "Pix Copy and Paste","Pix Cópia e Cola" "Payer Phone","Telefone do Pagador" "The Boleto barcode is","O código de barras do boleto é" Copy,Copiar Copied,Copiado +"To make the payment:","Para realizar o pagamento:" +"Access your PagBank account by clicking on the link:","Acesse sua conta PagBank clicando no link:" +"You must be redirected to PagBank to complete the payment.","Você deve será redirecionado ao PagBank para concluir o pagamento." +"Use the camera on your mobile device to scan the QR Code:","Use a câmera do seu celular para escanear o Qr Code:" +"Pay in PagBank","Pagar com PagBank" +"You must click the link indicated by the camera.","Você deve clicar no link indicado pela câmera para concluir o pagamento diretamente sua conta PagBank." "To pay, read the Qr Code","Para o pagamento, faço a leitura do Qr Code" "Or if you prefer, copy and paste the code","Ou se preferir, copie e cole o código" "Boleto Information","Informações do Boleto" diff --git a/view/adminhtml/templates/form/deep-link.phtml b/view/adminhtml/templates/form/deep-link.phtml new file mode 100644 index 0000000..58e8627 --- /dev/null +++ b/view/adminhtml/templates/form/deep-link.phtml @@ -0,0 +1,29 @@ + + * @license See LICENSE for license details. + */ + +/** + * @var \PagBank\PaymentMagento\Block\Sales\Form\DeepLink $block + * @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer + */ +$code = $block->escapeHtml($block->getMethodCode()); +?> +
+
+ +
+ escapeHtml($block->getInstruction(), ['b', 'a', 'h3', 'target'])) ?> +
+
+
+ +renderStyleAsTag( + "display:none", + 'fieldset#payment_form_' . $block->escapeJs($block->getMethodCode()) +) ?> diff --git a/view/adminhtml/templates/info/deep-link/instructions.phtml b/view/adminhtml/templates/info/deep-link/instructions.phtml new file mode 100644 index 0000000..a65a874 --- /dev/null +++ b/view/adminhtml/templates/info/deep-link/instructions.phtml @@ -0,0 +1,105 @@ + + * @license See LICENSE for license details. + */ + +/** + * @var \PagBank\PaymentMagento\Block\Sales\Form\DeepLink $block + * @see \PagBank\PaymentMagento\Block\Sales\Form\DeepLink + */ +$specificInfo = $block->getSpecificInformation(); +$title = $block->escapeHtml($block->getMethod()->getTitle()); +$deepLink = isset($specificInfo['deep_link_url']) ? $specificInfo['deep_link_url']: null; +$qrCodeImage = isset($specificInfo['qr_code_url_image']) ? $specificInfo['qr_code_url_image'] : null; +$expirationDate = isset($specificInfo['expiration_date']) ? $specificInfo['expiration_date'] : null; +$payerName = isset($specificInfo['payer_name']) ? $specificInfo['payer_name'] : null; +$payerPhone = isset($specificInfo['payer_phone']) ? $specificInfo['payer_phone'] : null; +$payerTaxId = isset($specificInfo['payer_tax_id']) ? $specificInfo['payer_tax_id'] : null; +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
escapeHtml(__('Expiration')); ?> + formatDate( + $expirationDate, + \IntlDateFormatter::LONG, + true + ) ?> +
+ escapeHtml(__('Pay by Compute')); ?> + + <?= /* @noEscape */ $title ?> + +
+ escapeHtml(__('Pay by Mobile')); ?> + + + + +
+ escapeHtml(__('Payer Name')); ?> + + escapeHtml($payerName) ?> +
+ escapeHtml(__('Payer Phone')); ?> + + escapeHtml($payerPhone) ?> +
+ escapeHtml(__('Payer Tax Id')); ?> + + escapeHtml($payerTaxId) ?> +
+ \ No newline at end of file diff --git a/view/base/web/images/deep-link/btn.svg b/view/base/web/images/deep-link/btn.svg new file mode 100644 index 0000000..5d8443e --- /dev/null +++ b/view/base/web/images/deep-link/btn.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/view/base/web/images/deep-link/logo.svg b/view/base/web/images/deep-link/logo.svg new file mode 100644 index 0000000..19bac09 --- /dev/null +++ b/view/base/web/images/deep-link/logo.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index a53873c..0c4f6bc 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -45,6 +45,9 @@ true + + true + diff --git a/view/frontend/templates/info/deep-link/instructions.phtml b/view/frontend/templates/info/deep-link/instructions.phtml new file mode 100644 index 0000000..8b6c74b --- /dev/null +++ b/view/frontend/templates/info/deep-link/instructions.phtml @@ -0,0 +1,99 @@ + + * @license See LICENSE for license details. + */ + +/** + * @var \PagBank\PaymentMagento\Block\Sales\Form\DeepLink $block + * @see \PagBank\PaymentMagento\Block\Sales\Form\DeepLink + */ +$specificInfo = $block->getSpecificInformation(); +$title = $block->escapeHtml($block->getMethod()->getTitle()); +$deepLink = isset($specificInfo['deep_link_url']) ? $specificInfo['deep_link_url']: null; +$qrCodeImage = isset($specificInfo['qr_code_url_image']) ? $specificInfo['qr_code_url_image'] : null; +$expirationDate = isset($specificInfo['expiration_date']) ? $specificInfo['expiration_date'] : null; +$payerName = isset($specificInfo['payer_name']) ? $specificInfo['payer_name'] : null; +$payerTaxId = isset($specificInfo['payer_tax_id']) ? $specificInfo['payer_tax_id'] : null; +?> + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
escapeHtml(__('Expiration')); ?> + formatDate( + $expirationDate, + \IntlDateFormatter::MEDIUM, + true + ) ?> +
+ escapeHtml(__('Pay by Mobile')); ?> + + + + +
+ escapeHtml(__('Pay by Compute')); ?> + + <?= /* @noEscape */ $title ?> + +
+ escapeHtml(__('Payer Name')); ?> + + escapeHtml($payerName) ?> +
+ escapeHtml(__('Payer Tax Id')); ?> + + escapeHtml($payerTaxId) ?> +
+
+
+ \ No newline at end of file diff --git a/view/frontend/templates/sales/order/success/deep-link.phtml b/view/frontend/templates/sales/order/success/deep-link.phtml new file mode 100644 index 0000000..b1ac86e --- /dev/null +++ b/view/frontend/templates/sales/order/success/deep-link.phtml @@ -0,0 +1,63 @@ + + + * @license See LICENSE for license details. + */ + +/** + * @var PagBank\PaymentMagento\Block\Sales\Order\Success $block + * @see PagBank\PaymentMagento\Block\Order\Success + */ +$deepLink = $block->getInfo('deep_link_url'); +$qrCodeImage = $block->getInfo('qr_code_url_image'); +?> +
+

+ escapeHtml( + __('To make the payment:') + ) ?> +

+ + +
\ No newline at end of file diff --git a/view/frontend/web/css/source/_module.less b/view/frontend/web/css/source/_module.less index 90b677f..afe17a0 100644 --- a/view/frontend/web/css/source/_module.less +++ b/view/frontend/web/css/source/_module.less @@ -234,6 +234,7 @@ .pagbank-payment { &-boleto-copy, + &-deep-link-copy, &-pix-copy { margin-bottom: @indent__s; max-width: 500px; @@ -250,7 +251,8 @@ } } - &-pix-image { + &-pix-image, + &-deep-link-image { margin-bottom: @indent__s; max-width: 500px; @@ -258,6 +260,10 @@ max-width: 250px; } } + + &-deep-link-image { + .lib-visually-hidden() + } } } @@ -283,4 +289,18 @@ } } } + + .pagbank-payment-success-details { + + .pagbank-payment { + + &-deep-link-image { + .lib-visually-hidden-reset() + } + + &-deep-link-url { + .lib-visually-hidden() + } + } + } } diff --git a/view/frontend/web/js/view/payment/method-renderer/deep-link.js b/view/frontend/web/js/view/payment/method-renderer/deep-link.js new file mode 100644 index 0000000..eaf3808 --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/deep-link.js @@ -0,0 +1,110 @@ +/** + * PagBank Payment Magento Module. + * + * Copyright © 2023 PagBank. All rights reserved. + * + * @author Bruno Elisei + * @license See LICENSE for license details. + */ + +define([ + 'jquery', + 'Magento_Checkout/js/view/payment/default', + 'PagBank_PaymentMagento/js/view/payment/payer-form', + 'PagBank_PaymentMagento/js/view/payment/base-data-for-payment-form' +], function ( + $, + Component, + PayerFormData, + BaseDataForPaymentForm +) { + 'use strict'; + + return Component.extend({ + defaults: { + active: false, + template: 'PagBank_PaymentMagento/payment/deep-link', + deepLinkForm: 'PagBank_PaymentMagento/payment/deep-link-form', + payerForm: 'PagBank_PaymentMagento/payment/payer-form' + }, + + /** + * Initializes model instance. + * + * @returns {Object} + */ + initObservable() { + this._super().observe(['active']); + return this; + }, + + /** + * Get code + * @returns {String} + */ + getCode() { + return 'pagbank_paymentmagento_deep_link'; + }, + + /** + * Init component + */ + initialize() { + var self = this; + + self._super(); + + self.payerFormData = new PayerFormData(); + self.payerFormData.setPaymentCode(self.getCode()); + + self.baseDataForPaymentForm = new BaseDataForPaymentForm(); + self.baseDataForPaymentForm.setPaymentCode(self.getCode()); + }, + + /** + * Is Active + * @returns {Boolean} + */ + isActive() { + var active = this.getCode() === this.isChecked(); + + this.active(active); + return active; + }, + + /** + * Init Form Element + * @returns {void} + */ + initFormElement(element) { + this.formElement = element; + $(this.formElement).validation(); + }, + + /** + * Before Place Order + * @returns {void} + */ + beforePlaceOrder() { + if (!$(this.formElement).valid()) { + return; + } + this.placeOrder(); + }, + + /** + * Get data + * @returns {Object} + */ + getData() { + return { + method: this.getCode(), + 'additional_data': { + 'payer_name': this.payerFormData.payerName(), + 'payer_tax_id': this.payerFormData.payerTaxId(), + 'payer_phone': this.payerFormData.payerPhone() + } + }; + } + }); +}); diff --git a/view/frontend/web/js/view/payment/pagbank.js b/view/frontend/web/js/view/payment/pagbank.js index 565f1f0..bcb5ae4 100644 --- a/view/frontend/web/js/view/payment/pagbank.js +++ b/view/frontend/web/js/view/payment/pagbank.js @@ -20,7 +20,8 @@ define( var config = window.checkoutConfig.payment, methodBoleto = 'pagbank_paymentmagento_boleto', methodCc = 'pagbank_paymentmagento_cc', - methodPix = 'pagbank_paymentmagento_pix'; + methodPix = 'pagbank_paymentmagento_pix', + methodDeepLink = 'pagbank_paymentmagento_deep_link'; if (config[methodBoleto].isActive) { rendererList.push( @@ -49,6 +50,15 @@ define( ); } + if (config[methodDeepLink].isActive) { + rendererList.push( + { + type: methodDeepLink, + component: 'PagBank_PaymentMagento/js/view/payment/method-renderer/deep-link' + } + ); + } + return Component.extend({}); } ); diff --git a/view/frontend/web/template/payment/deep-link-form.html b/view/frontend/web/template/payment/deep-link-form.html new file mode 100644 index 0000000..f92f9f2 --- /dev/null +++ b/view/frontend/web/template/payment/deep-link-form.html @@ -0,0 +1,31 @@ + + +
+ + + + + +
+

+
+
+ +
+
+
+ +
+
+ +
+
diff --git a/view/frontend/web/template/payment/deep-link.html b/view/frontend/web/template/payment/deep-link.html new file mode 100644 index 0000000..7b60efd --- /dev/null +++ b/view/frontend/web/template/payment/deep-link.html @@ -0,0 +1,59 @@ + +
+
+ + + +
+
+ +
+ +
+
+ + + +
+
+ +
+
+
+ +
+
+
+