Skip to content

Commit

Permalink
PagBank 😍 Magento
Browse files Browse the repository at this point in the history
  • Loading branch information
elisei committed Aug 2, 2023
1 parent a476d72 commit 9d5dd0a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
36 changes: 16 additions & 20 deletions Gateway/Config/ConfigCc.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,6 @@ class ConfigCc extends PaymentConfig
*/
public const GET_PHONE = 'get_phone';

/**
* @const string
*/
public const USE_FRAUD_MANAGER = 'fraud_manager';

/**
* @const string
*/
public const INSTALL_WITH_INTEREST = 'INSTALL_WITH_INTEREST';

/**
* @const string
*/
public const INSTALL_NO_INTEREST = 'INSTALL_NO_INTEREST';

/**
* @const string
*/
public const INSTALL_FULL = 'FULL';

/**
* @const string
*/
Expand Down Expand Up @@ -302,4 +282,20 @@ public function getInterestFree($storeId = null): int

return $free;
}

/**
* Get Min Value Installments.
*
* @param int|null $storeId
*
* @return int
*/
public function getMinValuelInstallment($storeId = null): int
{
return (int) $this->scopeConfig->getValue(
'payment/pagbank_paymentmagento_cc/min_value_installment',
ScopeInterface::SCOPE_STORE,
$storeId
);
}
}
32 changes: 28 additions & 4 deletions Model/Api/ConsultPSInstallments.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public function __construct(
/**
* Get PagBank Installments.
*
* @param int $storeId
* @param string $creditCardBin
* @param string $amount
* @param int|null $storeId
* @param string $creditCardBin
* @param string $amount
*
* @return array
*/
Expand Down Expand Up @@ -115,7 +115,9 @@ public function getPagBankInstallments($storeId, $creditCardBin, $amount)
$list = $brand;
}

$response = $list['installment_plans'];
$list = $this->getAvailableInstallments($list['installment_plans'], $storeId);

$response = $list;
}

if (!$client->request()->isSuccessful()) {
Expand All @@ -136,4 +138,26 @@ public function getPagBankInstallments($storeId, $creditCardBin, $amount)

return $response;
}

/**
* Get Available Installments.
*
* @param array $list
* @param int|null $storeId
* @return array
*/
public function getAvailableInstallments($list, $storeId)
{
$minInstallment = $this->configCc->getMinValuelInstallment($storeId) * 100;

foreach ($list as $key => $allInstallments) {
if ($key >= 1) {
if ($allInstallments['installment_value'] <= $minInstallment) {
unset($list[$key]);
}
}
}

return $list;
}
}
10 changes: 8 additions & 2 deletions etc/adminhtml/system/credit_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,26 @@
</group>
<group id="installment" translate="label" type="text" sortOrder="3000" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Installment and interest</label>
<field id="max_installment" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<field id="max_installment" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Maximum number of installment</label>
<source_model>PagBank\PaymentMagento\Model\Adminhtml\Source\Installments</source_model>
<comment>Maximum number of installments accepted</comment>
<validate>required-entry validate-number</validate>
<config_path>payment/pagbank_paymentmagento_cc/max_installment</config_path>
</field>
<field id="interest_free" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<field id="interest_free" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Number of interest-free installments</label>
<source_model>PagBank\PaymentMagento\Model\Adminhtml\Source\Installments</source_model>
<comment>Number of installments you want to accept without applying interest</comment>
<validate>required-entry validate-number</validate>
<config_path>payment/pagbank_paymentmagento_cc/interest_free</config_path>
</field>
<field id="min_value_installment" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>The minimum installment price</label>
<comment>It is the minimum value that the installment can have</comment>
<validate>required-entry validate-number validate-number-range validate-date-range number-range-5-9999</validate>
<config_path>payment/pagbank_paymentmagento_cc/min_value_installment</config_path>
</field>
</group>
</group>
</include>
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<cctypes>HC,ELO,AE,VI,MC,DN,AU</cctypes>
<max_installment>18</max_installment>
<interest_free>1</interest_free>
<min_value_installment>5.00</min_value_installment>
<get_tax_id>0</get_tax_id>
<get_phone>0</get_phone>
<min_order_total>1</min_order_total>
Expand Down
2 changes: 2 additions & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ Title,Title
"Maximum number of installments accepted","Maximum number of installments accepted"
"Number of interest-free installments","Number of interest-free installments"
"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"
Developers,Developers
"Meet our <a href='https://github.com/pagbank/payment-magento/wiki'>Wiki</a>.","Meet our <a href='https://github.com/pagbank/payment-magento/wiki'>Wiki</a>."
Debug,Debug
Expand Down
2 changes: 2 additions & 0 deletions i18n/pt_BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ Title,Título
"Maximum number of installments accepted","Número máximo de parcelas aceitas"
"Number of interest-free installments","Número de parcelas sem juros"
"Number of installments you want to accept without applying interest","Número de parcelas que pretende aceitar sem aplicar juros"
"The minimum installment price","O preço mínimo da parcela"
"It is the minimum value that the installment can have","É o valor mínimo que a parcela pode ter"
Developers,Desenvolvedores
"Meet our <a href='https://github.com/pagbank/payment-magento/wiki'>Wiki</a>.","Conheça a nossa <a href='https://github.com/pagbank/payment-magento/wiki'>Wiki</a>."
Debug,Debug
Expand Down

0 comments on commit 9d5dd0a

Please sign in to comment.