Skip to content

Commit

Permalink
Release 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiano-mallmann authored Jun 13, 2024
2 parents 989bc47 + 098ed18 commit eed765b
Show file tree
Hide file tree
Showing 96 changed files with 4,483 additions and 1,082 deletions.
37 changes: 37 additions & 0 deletions Api/GooglePayRequestDataProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Class CreateCreditCardDataProviderInterface
*
*
* @author Open Source Team
* @copyright 2021 Pagar.me (https://pagar.me)
* @license https://pagar.me Copyright
*
* @link https://pagar.me
*/

namespace Pagarme\Pagarme\Api;


interface GooglePayRequestDataProviderInterface extends BaseRequestDataProviderInterface
{
/**
* @return string
*/
public function getCustomerAddressStreet($shipping);

/**
* @return string
*/
public function getCustomerAddressNumber($shipping);

/**
* @return string
*/
public function getCustomerAddressComplement($shipping);

/**
* @return string
*/
public function getCustomerAddressDistrict($shipping);
}
31 changes: 31 additions & 0 deletions Api/KycLinkResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Pagarme\Pagarme\Api;

interface KycLinkResponseInterface
{
const DATA_URL = 'url';
const DATA_QR_CODE = 'qrCode';

/**
* @return string
*/
public function getUrl();

/**
* @return string
*/
public function getQrCode();

/**
* @param string $url
* @return $this
*/
public function setUrl(string $url);

/**
* @param string $qrCode
* @return $this
*/
public function setQrCode(string $qrCode);
}
6 changes: 6 additions & 0 deletions Api/RecipientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ public function saveFormData();
* @return string
*/
public function searchRecipient(): string;

/**
* @param string $id
* @return KycLinkResponseInterface
*/
public function createKycLink(string $id);
}
105 changes: 95 additions & 10 deletions Block/Adminhtml/Marketplace/Recipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

namespace Pagarme\Pagarme\Block\Adminhtml\Marketplace;

use Exception;
use Magento\Customer\Model\ResourceModel\Customer\Collection;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Magento\Directory\Model\Country;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Pagarme\Core\Marketplace\Repositories\RecipientRepository;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use stdClass;
use Pagarme\Core\Marketplace\Interfaces\RecipientInterface as CoreRecipientInterface;

class Recipient extends Template
{

/**
* @var Collection
*/
private $customerCollection;

/**
Expand All @@ -25,7 +31,6 @@ class Recipient extends Template
*/
private $coreRegistry;


/**
* @var array
*/
Expand All @@ -36,28 +41,48 @@ class Recipient extends Template
*/
private $recipient = null;

/**
* @var Country
*/
private $country;


/**
* Link constructor.
* @param Context $context
* @param Registry $registry
* @param CustomerCollectionFactory $customerCollectionFactory
* @param Country $country
* @throws Exception
*/
public function __construct(
Context $context,
Registry $registry,
CustomerCollectionFactory $customerCollectionFactory
) {
Context $context,
Registry $registry,
CustomerCollectionFactory $customerCollectionFactory,
Country $country,
RecipientRepository $recipientRepository
)
{
$this->coreRegistry = $registry;
$this->customerCollection = $customerCollectionFactory->create();
$this->recipientRepository = new RecipientRepository();
$this->recipientRepository = $recipientRepository;
$this->country = $country;

Magento2CoreSetup::bootstrap();
$this->init();
parent::__construct($context, []);
}

protected function init()
{
$recipientData = $this->coreRegistry->registry('recipient_data');
if (!empty($recipientData)) {
$this->recipient = json_decode($recipientData);
$this->recipient->recipient->externalId = $this->recipient->externalId;
$this->recipient->recipient->localId = $this->recipient->localId;
$this->recipient->recipient->status = $this->recipient->status;
$this->recipient->recipient->statusUpdated = $this->recipient->statusUpdated;
$this->recipient->recipient->statusLabel = $this->buildStatusLabel($this->recipient->recipient->status);
$this->recipient = $this->recipient->recipient;
}

Expand Down Expand Up @@ -127,4 +152,64 @@ public function getSellers()

return $this->sellers;
}
}

/**
* @param string $countryCode
* @return array
*/
public function getAllRegionsOfCountry($countryCode = 'BR')
{
return $this->country->loadByCode($countryCode)->getRegions()->getData();
}

public function getLabel($key)
{
$labels = [
'no' => 'No',
'yes' => 'Yes',
'document_type' => 'Document type',
'document_number' => 'Document number',
'name' => 'Name',
'mother_name' => 'Mother name',
'email' => 'E-mail',
'birthdate' => 'Date of birth',
'monthly_income' => 'Monthly income',
'profession' => 'Profession',
'contact_type' => 'Contact type',
'contact_number' => 'Contact number',
'mobile_phone' => 'Mobile phone',
'street' => 'Street',
'number' => 'Number',
'complement' => 'Complement',
'neighborhood' => 'Neighborhood',
'reference_point' => 'Reference point',
'state' => 'State/Province',
'city' => 'City',
'zip' => 'Zip/Postal Code',
'select' => 'Select',
];

return __($labels[$key]);
}

/**
* @param string|null $status
* @return string|null
*/
private function buildStatusLabel($status)
{
if (!is_string($status)) {
return $status;
}

if ($status === CoreRecipientInterface::ACTIVE) {
$status = 'approved';
}

$statusWords = explode('_', $status);
$statusWords = array_map('ucfirst', $statusWords);
$statusLabel = implode(" ", $statusWords);
$statusLabel = trim($statusLabel);
return __($statusLabel);
}
}
69 changes: 69 additions & 0 deletions Block/Customer/Marketplace/Kyc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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 Pagarme\Pagarme\Model\Recipient;
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);
}


/**
* @return Recipient
*/
public function getRecipient()
{
return $this->collectionFactory->create()->addFieldToFilter(
'external_id',
['eq' => $this->getCustomerId()]
)->getFirstItem();
}

/**
* Get customerId
*
* @return int
*/
protected function getCustomerId()
{
return $this->customerSession->getCustomerId();
}
}
78 changes: 78 additions & 0 deletions Block/Payment/Info/BaseCardInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Pagarme\Pagarme\Block\Payment\Info;

use Exception;
use Magento\Payment\Block\Info\Cc;
use Pagarme\Core\Kernel\Services\OrderService;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use Pagarme\Core\Kernel\ValueObjects\Id\OrderId;
use Magento\Framework\Exception\LocalizedException;
use Pagarme\Core\Kernel\Exceptions\InvalidParamException;
use Pagarme\Pagarme\Concrete\Magento2PlatformOrderDecorator;

abstract class BaseCardInfo extends Cc
{

/**
* @return array
* @throws InvalidParamException
* @throws LocalizedException
* @throws Exception
*/
public function getTransactionInfo()
{
Magento2CoreSetup::bootstrap();
$orderService = new OrderService();

$orderEntityId = $this->getInfo()->getOrder()->getIncrementId();
$platformOrder = $this->loadPlatformOrderByIncrementId($orderEntityId);

$orderPagarmeId = $platformOrder->getPagarmeId();

if ($orderPagarmeId === null) {
return [];
}

$orderObject = $this->getOrderObjectByPagarmeId($orderService, $orderPagarmeId);

if ($orderObject === null || !is_object($orderObject)) {
return [];
}

$charge = current($orderObject->getCharges());
$lastFourDigitsWithDots = sprintf(
"**** **** **** %s",
$charge->getLastTransaction()->getCardData()->getLastFourDigits()->getValue()
);
return array_merge(
$charge->getAcquirerTidCapturedAndAuthorize(),
['tid' => $charge->getLastTransaction()->getAcquirerTid() ?? ""],
['cardBrand' => $charge->getLastTransaction()->getCardData()->getBrand()->getName() ?? ""],
['installments' => $this->getInfo()->getAdditionalInformation('cc_installments') ?? ""],
['lastFour' => $lastFourDigitsWithDots],
['acquirerMessage' => $charge->getLastTransaction()->getAcquirerMessage() ?? ""]
);
}

/**
* @param mixed $orderService
* @param mixed $pagarmeId
* @return mixed
*/
protected function getOrderObjectByPagarmeId($orderService, $pagarmeId)
{
$orderId = new OrderId($pagarmeId);
return $orderService->getOrderByPagarmeId($orderId);
}
/**
* @param mixed $incrementId
* @return Magento2PlatformOrderDecorator
*/
protected function loadPlatformOrderByIncrementId($incrementId)
{
$platformOrder = new Magento2PlatformOrderDecorator();
$platformOrder->loadByIncrementId($incrementId);
return $platformOrder;
}
}
2 changes: 1 addition & 1 deletion Block/Payment/Info/BilletCreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getTransactionInfo()
if ($item->getAcquirerNsu() != 0) {
$transactionList['creditCard'] =
array_merge(
$orderObject->getCharges()[0]->getAcquirerTidCapturedAndAutorize(),
$orderObject->getCharges()[0]->getAcquirerTidCapturedAndAuthorize(),
['tid' => $this->getTid($orderObject->getCharges()[0])]
);

Expand Down
Loading

0 comments on commit eed765b

Please sign in to comment.