Commit 6ad4e588 authored by Alessio Zampatti's avatar Alessio Zampatti Committed by GitHub

Fix for showing only selected boleto types in checkout (#250)

* Fix for returning only selected boleto types in checkout

* Fix not showing boleto type field if only one field is configured

* Added validation of the Boleto Types field
parent b59d72f3
...@@ -38,11 +38,12 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface ...@@ -38,11 +38,12 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
*/ */
public function __construct(\Adyen\Payment\Helper\Data $adyenHelper) public function __construct(
{ \Adyen\Payment\Helper\Data $adyenHelper
) {
$this->adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
} }
/** /**
* @param array $buildSubject * @param array $buildSubject
* @return mixed * @return mixed
...@@ -59,7 +60,15 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface ...@@ -59,7 +60,15 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface
$request = []; $request = [];
$request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number"); $request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number");
$request['selectedBrand'] = $payment->getAdditionalInformation("boleto_type");
$boletoTypes = $this->adyenHelper->getAdyenBoletoConfigData('boletotypes');
$boletoTypes = explode(',', $boletoTypes);
if (count($boletoTypes) == 1) {
$request['selectedBrand'] = $boletoTypes[0];
} else {
$request['selectedBrand'] = $payment->getAdditionalInformation("boleto_type");
}
$shopperName = [ $shopperName = [
'firstName' => $payment->getAdditionalInformation("firstname"), 'firstName' => $payment->getAdditionalInformation("firstname"),
...@@ -68,7 +77,7 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface ...@@ -68,7 +77,7 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface
$request['shopperName'] = $shopperName; $request['shopperName'] = $shopperName;
$deliveryDays = (int) $this->adyenHelper->getAdyenBoletoConfigData("delivery_days", $storeId); $deliveryDays = (int)$this->adyenHelper->getAdyenBoletoConfigData("delivery_days", $storeId);
$deliveryDays = (!empty($deliveryDays)) ? $deliveryDays : 5; $deliveryDays = (!empty($deliveryDays)) ? $deliveryDays : 5;
$deliveryDate = date( $deliveryDate = date(
"Y-m-d\TH:i:s ", "Y-m-d\TH:i:s ",
...@@ -81,7 +90,7 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface ...@@ -81,7 +90,7 @@ class BoletoAuthorizationDataBuilder implements BuilderInterface
); );
$request['deliveryDate'] = $deliveryDate; $request['deliveryDate'] = $deliveryDate;
return $request; return $request;
} }
} }
\ No newline at end of file
...@@ -34,7 +34,7 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface ...@@ -34,7 +34,7 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface
* @var PaymentHelper * @var PaymentHelper
*/ */
protected $_paymentHelper; protected $_paymentHelper;
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Data
*/ */
...@@ -86,12 +86,32 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface ...@@ -86,12 +86,32 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface
'checkout/onepage/success/', ['_secure' => $this->_getRequest()->isSecure()]) 'checkout/onepage/success/', ['_secure' => $this->_getRequest()->isSecure()])
], ],
'adyenBoleto' => [ 'adyenBoleto' => [
'boletoTypes' => $this->_adyenHelper->getBoletoTypes() 'boletoTypes' => $this->getBoletoAvailableTypes()
] ]
] ]
]; ];
} }
/**
* @return array
*/
protected function getBoletoAvailableTypes()
{
$types = [];
$boletoTypes = $this->_adyenHelper->getBoletoTypes();
$availableTypes = $this->_adyenHelper->getAdyenBoletoConfigData('boletotypes');
if ($availableTypes) {
$availableTypes = explode(',', $availableTypes);
foreach ($boletoTypes as $boletoType) {
if (in_array($boletoType['value'], $availableTypes)) {
$types[] = $boletoType;
}
}
}
return $types;
}
/** /**
* Retrieve request object * Retrieve request object
* *
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
</field> </field>
<field id="cctypes" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0"> <field id="cctypes" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Boleto Types</label> <label>Boleto Types</label>
<depends><field id="active">1</field></depends>
<validate>validate-no-empty</validate>
<source_model>Adyen\Payment\Model\Config\Source\BoletoType</source_model> <source_model>Adyen\Payment\Model\Config\Source\BoletoType</source_model>
<config_path>payment/adyen_boleto/boletotypes</config_path> <config_path>payment/adyen_boleto/boletotypes</config_path>
</field> </field>
......
...@@ -84,6 +84,8 @@ ...@@ -84,6 +84,8 @@
</div> </div>
</div> </div>
<!-- ko if: getBoletoTypes().length > 1-->
<div class="field boleto_type type required"> <div class="field boleto_type type required">
<label data-bind="attr: {for: getCode() + '_boleto_type'}" class="label"> <label data-bind="attr: {for: getCode() + '_boleto_type'}" class="label">
<span><!-- ko text: $t('Boleto Card Type')--><!-- /ko --></span> <span><!-- ko text: $t('Boleto Card Type')--><!-- /ko --></span>
...@@ -103,7 +105,7 @@ ...@@ -103,7 +105,7 @@
</div> </div>
</div> </div>
<!--/ko-->
<div class="field firstname type required"> <div class="field firstname type required">
<label data-bind="attr: {for: getCode() + 'firstname'}" class="label"> <label data-bind="attr: {for: getCode() + 'firstname'}" class="label">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment