-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add kyc validation to recipient dashboard
- Loading branch information
1 parent
aaf6153
commit b78b861
Showing
8 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* @author Open Source Team | ||
* @copyright 2024 Pagar.me (https://pagar.me) | ||
* @license https://pagar.me Copyright | ||
* | ||
* @link https://pagar.me | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Pagarme\Pagarme\Block\Customer\Marketplace; | ||
|
||
use Magento\Customer\Model\Session; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Pagarme\Pagarme\Model\ResourceModel\Recipients\CollectionFactory; | ||
|
||
class Kyc extends Template | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
protected $customerSession; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
protected $collectionFactory; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Session $customerSession | ||
* @param CollectionFactory $collectionFactory | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
Session $customerSession, | ||
CollectionFactory $collectionFactory, | ||
array $data = []) | ||
{ | ||
$this->customerSession = $customerSession; | ||
$this->collectionFactory = $collectionFactory; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
public function getRecipient() | ||
{ | ||
return $this->collectionFactory->create()->addFieldToFilter( | ||
'external_id', | ||
['eq' => $this->getCustomerId()] | ||
)->getFirstItem(); | ||
} | ||
|
||
/** | ||
* Get customerid | ||
* | ||
* @return int | ||
*/ | ||
public function getCustomerId() | ||
{ | ||
return $this->customerSession->getCustomerId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* @author Open Source Team | ||
* @copyright 2024 Pagar.me (https://pagar.me) | ||
* @license https://pagar.me Copyright | ||
* | ||
* @link https://pagar.me | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<head> | ||
<css src="Pagarme_Pagarme/css/pagarme_kyc.css" /> | ||
</head> | ||
<body> | ||
<referenceContainer name="content"> | ||
<block class="Pagarme\Pagarme\Block\Customer\Marketplace\Kyc" name="pagarme_marketplace_kyc" template="customer/marketplace/kyc.phtml" before="marketplace_account_dashboard" cacheable="false"/> | ||
</referenceContainer> | ||
</body> | ||
</page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* @var $block Kyc | ||
*/ | ||
|
||
use Pagarme\Pagarme\Block\Customer\Marketplace\Kyc; | ||
|
||
$recipientId = $block->getRecipient()->getId(); | ||
|
||
if (empty($recipientId)) { | ||
return; | ||
} | ||
|
||
?> | ||
|
||
<div class="wk-mp-design"> | ||
<div class="mp-widgets pagarme-kyc"> | ||
<div class="container"> | ||
<div class="pagarme-kyc-box"> | ||
<div class="pagarme-kyc-box-title"> | ||
<div class="p-5"><?= __('Pagar.me Recipient') ?></div> | ||
</div> | ||
<div class="pagarme-kyc-box-content"> | ||
<div class="p-5"> | ||
<p><?= __('You can now sell, but you must successfully complete our <b>security ' | ||
. 'validation</b> to release your sales amounts.') ?></p> | ||
<button class="button" id="pagarme-kyc-start-validation"> | ||
<span><?= __('Start validation') ?></span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div id="modal-content"> | ||
<div class="modal-inner-content pagarme-kyc-modal"> | ||
<p><?= __('Point the smartphone camera to read the QRCode.') ?></p> | ||
<p><img src="" alt="QRCode" id="pagarme-kyc-qrcode" /></p> | ||
<p><?= sprintf(__('Or use this %slink%s.'), '<a id="pagarme-kyc-link" target="_blank" rel="noreferrer">', '</a>') ?></p> | ||
</div> | ||
</div> | ||
|
||
<script type="text/x-magento-init"> | ||
{ | ||
"#pagarme-kyc-start-validation": { | ||
"kyc": {"id": "<?= $recipientId ?>"} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.wk-mp-design .mp-widgets.pagarme-kyc { | ||
width: 100%; | ||
} | ||
|
||
.pagarme-kyc .container { | ||
padding-bottom: 15px; | ||
} | ||
|
||
.pagarme-kyc-box { | ||
border:1px solid #ccc; | ||
} | ||
|
||
.pagarme-kyc-box-title { | ||
border-bottom: 1px solid #ccc; | ||
display: inline-block; | ||
width: 100%; | ||
} | ||
|
||
.pagarme-kyc-box-content { | ||
padding:5px; | ||
} | ||
|
||
.pagarme-kyc-box-content > div { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.pagarme-kyc-box-content > div button { | ||
margin: 2.5rem; | ||
} | ||
|
||
.pagarme-kyc-modal { | ||
display: none; | ||
padding-top: 3rem; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
define([ | ||
'Magento_Ui/js/modal/modal', | ||
"mage/url", | ||
'jquery', | ||
'mage/translate', | ||
'loader' | ||
], function (modal, mageUrl, $) { | ||
return function (config) { | ||
|
||
$('#pagarme-kyc-start-validation').on('click', async function (){ | ||
const body = $('body'); | ||
try { | ||
body.loader('show'); | ||
const url = mageUrl.build(`rest/V1/pagarme/marketplace/recipient/kyc/link/${config.id}`); | ||
const response = await $.get(mageUrl.build(url)); | ||
body.loader('hide'); | ||
if (response) { | ||
$('#pagarme-kyc-qrcode').attr('src', response.qr_code); | ||
$('#pagarme-kyc-link').attr('href', response.url); | ||
$('.pagarme-kyc-modal').show(); | ||
|
||
const options = { | ||
responsive: true, | ||
innerScroll: true, | ||
// @todo: Using portuguese title for the translation did't work. | ||
title: $.mage.__('Iniciar validação'), | ||
buttons: [{ | ||
text: $.mage.__('Close'), | ||
click: function () { | ||
this.closeModal(); | ||
} | ||
}] | ||
}; | ||
|
||
const popup = modal(options, $('#modal-content')); | ||
$('#modal-content').modal('openModal'); | ||
} | ||
} catch (exception) { | ||
body.loader('hide'); | ||
// this.mageAlert(exception?.responseJSON?.message, $.mage.__('Error!')); | ||
} | ||
}); | ||
}; | ||
}); |