Gateway/Transaction/BilletCreditCard/ResourceGateway/Create/RequestDataProvider.php
<?php
/**
* Class RequestDataProvider
*
* @author MundiPagg Embeddables Team <embeddables@mundipagg.com>
* @copyright 2017 MundiPagg (http://www.mundipagg.com)
* @license http://www.mundipagg.com Copyright
*
* @link http://www.mundipagg.com
*/
namespace MundiPagg\MundiPagg\Gateway\Transaction\BilletCreditCard\ResourceGateway\Create;
use Magento\Checkout\Model\Session;
use Magento\Payment\Gateway\Data\OrderAdapterInterface;
use Magento\Payment\Model\InfoInterface;
use MundiPagg\MundiPagg\Api\BilletCreditCardRequestDataProviderInterface;
use MundiPagg\MundiPagg\Gateway\Transaction\Base\ResourceGateway\AbstractRequestDataProvider;
use MundiPagg\MundiPagg\Gateway\Transaction\CreditCard\Config\ConfigInterface;
use MundiPagg\MundiPagg\Helper\CustomerAddressInterface;
class RequestDataProvider
extends AbstractRequestDataProvider
implements BilletCreditCardRequestDataProviderInterface
{
protected $config;
public function __construct (
OrderAdapterInterface $orderAdapter,
InfoInterface $payment,
Session $session,
CustomerAddressInterface $customerAddressHelper,
ConfigInterface $config
)
{
parent::__construct($orderAdapter, $payment, $session, $customerAddressHelper);
$this->setConfig($config);
}
/**
* {@inheritdoc}
*/
public function getBankType()
{
return $this->getConfig()->getTypeBank();
}
/**
* {@inheritdoc}
*/
public function getInstallmentCount()
{
return $this->getPaymentData()->getAdditionalInformation('cc_installments');
}
/**
* {@inheritdoc}
*/
public function getCcTokenCreditCard()
{
return $this->getPaymentData()->getAdditionalInformation('cc_token_credit_card');
}
/**
* {@inheritdoc}
*/
public function getSaveCard()
{
return $this->getPaymentData()->getAdditionalInformation('cc_savecard');
}
/**
* {@inheritdoc}
*/
public function getBilletBuyerName()
{
return $this->getPaymentData()->getAdditionalInformation('billet_buyer_name');
}
/**
* {@inheritdoc}
*/
public function getBilletBuyerEmail()
{
return $this->getPaymentData()->getAdditionalInformation('billet_buyer_email');
}
/**
* {@inheritdoc}
*/
public function getCcBuyerName()
{
return $this->getPaymentData()->getAdditionalInformation('cc_buyer_name');
}
/**
* {@inheritdoc}
*/
public function getCcBuyerEmail()
{
return $this->getPaymentData()->getAdditionalInformation('cc_buyer_email');
}
/**
* {@inheritdoc}
*/
public function getBilletCreditCardOperation()
{
if ($this->getConfig()->getPaymentAction()) {
return \MundiPagg\MundiPagg\Model\Enum\CreditCardOperationEnum::AUTH_ONLY;
}
return \MundiPagg\MundiPagg\Model\Enum\CreditCardOperationEnum::AUTH_AND_CAPTURE;
}
/**
* {@inheritdoc}
*/
public function getBilletCreditCardBrand()
{
return $this->getPaymentData()->getCcType();
}
/**
* {@inheritdoc}
*/
public function getBilletCreditCardNumber()
{
return $this->getPaymentData()->getCcNumber();
}
/**
* {@inheritdoc}
*/
public function getExpMonth()
{
return $this->getPaymentData()->getCcExpMonth();
}
/**
* {@inheritdoc}
*/
public function getCcCcAmount()
{
return $this->getPaymentData()->getCcCcAmount();
}
/**
* {@inheritdoc}
*/
public function getCcBilletAmount()
{
return $this->getPaymentData()->getCcBilletAmount();
}
/**
* {@inheritdoc}
*/
public function getExpYear()
{
return $this->getPaymentData()->getCcExpYear();
}
/**
* {@inheritdoc}
*/
public function getHolderName()
{
return $this->getPaymentData()->getCcOwner();
}
/**
* {@inheritdoc}
*/
public function getSecurityCode()
{
return $this->getPaymentData()->getCcCid();
}
/**
* {@inheritdoc}
*/
public function getIsOneDollarAuthEnabled()
{
return $this->getConfig()->getIsOneDollarAuthEnabled();
}
/**
* @return ConfigInterface
*/
protected function getConfig()
{
return $this->config;
}
/**
* @param ConfigInterface $config
* @return $this
*/
protected function setConfig(ConfigInterface $config)
{
$this->config = $config;
return $this;
}
/**
* @return string
*/
public function getCustomerAddressStreet($shipping)
{
if ($shipping) {
return $this->getShippingAddressAttribute($this->getConfig()->getCustomerStreetAttribute());
}
return $this->getBillingAddressAttribute($this->getConfig()->getCustomerStreetAttribute());
}
/**
* @return string
*/
public function getCustomerAddressNumber($shipping)
{
if ($shipping) {
return $this->getShippingAddressAttribute($this->getConfig()->getCustomerAddressNumber());
}
return $this->getBillingAddressAttribute($this->getConfig()->getCustomerAddressNumber());
}
/**
* @return string
*/
public function getCustomerAddressComplement($shipping)
{
if ($shipping) {
$response = !$this->getShippingAddressAttribute($this->getConfig()->getCustomerAddressDistrict()) ? '' : $this->getShippingAddressAttribute($this->getConfig()->getCustomerAddressComplement());
}else{
$response = !$this->getBillingAddressAttribute($this->getConfig()->getCustomerAddressDistrict()) ? '' : $this->getShippingAddressAttribute($this->getConfig()->getCustomerAddressComplement());
}
return $response;
}
/**
* @return string
*/
public function getCustomerAddressDistrict($shipping)
{
if ($shipping) {
$streetLine = !$this->getShippingAddressAttribute($this->getConfig()->getCustomerAddressDistrict()) ? 'street_3' : $this->getConfig()->getCustomerAddressDistrict();
$response = $this->getShippingAddressAttribute($streetLine);
}else{
$streetLine = !$this->getBillingAddressAttribute($this->getConfig()->getCustomerAddressDistrict()) ? 'street_3' : $this->getConfig()->getCustomerAddressDistrict();
$response = $this->getBillingAddressAttribute($streetLine);
}
return $response;
}
}