<commit_before><?php

/**
 * Adyen Payment Module
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category	Adyen
 * @package	Adyen_Payment
 * @copyright	Copyright (c) 2011 Adyen (http://www.adyen.com)
 * @license	http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
/**
 * @category   Payment Gateway
 * @package    Adyen_Payment
 * @author     Adyen
 * @property   Adyen B.V
 * @copyright  Copyright (c) 2014 Adyen BV (http://www.adyen.com)
 */
class Adyen_Payment_Model_Sales_Quote_Address_Total_PaymentInstallmentFee extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    protected $_code = 'payment_installment_fee';

    /*
     *  keep in mind that collect is running twice if you save payment method.
     * First time before the payment step save and second time after payment step change
     */
    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);

        $quote = $address->getQuote();

        if ($address->getAllItems()) {
            $currentAmount = $address->getPaymentInstallmentFeeAmount();
            $payment = $quote->getPayment();

            if($payment && !empty($payment)) {

                $paymentMethod = $quote->getPayment()->getMethod() ;

                if($paymentMethod == "adyen_cc" || substr($paymentMethod, 0, 14) == 'adyen_oneclick') {

                    $info = $payment->getMethodInstance();

                    $instance = $info->getInfoInstance();
                    $numberOfInstallments = $instance->getAdditionalInformation('number_of_installments');

                    if($numberOfInstallments > 0)
                    {
                        // get the Interest Rate of this installment

                        // get cc type
                        $ccType = $instance->getCcType();

                        // get installment for this specific card type
                        $ccTypeInstallments = "installments_".$ccType;

                        $all_installments = Mage::helper('adyen/installments')->getInstallments(null, $ccTypeInstallments);
                        if(empty($all_installments)) {
                            // use default installments
                            $all_installments = Mage::helper('adyen/installments')->getInstallments();
                        }

                        $installmentKey = $numberOfInstallments - 1;

                        Mage::log("installment key:" . $ccTypeInstallments, Zend_Log::DEBUG, "adyen_installments.log", true);
//                        echo $installmentKey;
//print_r($all_installments[$installmentKey]);
//                        die();

                        $installment = $all_installments[$installmentKey];

                        if($installment != null && is_array($installment)) {

                            // check if interest rate is filled in
                            if(isset($installment[3]) && $installment[3] > 0) {

                                $this->_setAmount(0);
                                $this->_setBaseAmount(0);

                                $interestRate = $installment[3];
                                $grandTotal = $address->getGrandTotal();<commit_msg>remove test logging<commit_after><?php

/**
 * Adyen Payment Module
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category	Adyen
 * @package	Adyen_Payment
 * @copyright	Copyright (c) 2011 Adyen (http://www.adyen.com)
 * @license	http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
/**
 * @category   Payment Gateway
 * @package    Adyen_Payment
 * @author     Adyen
 * @property   Adyen B.V
 * @copyright  Copyright (c) 2014 Adyen BV (http://www.adyen.com)
 */
class Adyen_Payment_Model_Sales_Quote_Address_Total_PaymentInstallmentFee extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    protected $_code = 'payment_installment_fee';

    /*
     *  keep in mind that collect is running twice if you save payment method.
     * First time before the payment step save and second time after payment step change
     */
    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);

        $quote = $address->getQuote();
        nstallmentKey = $numberOfInstallments - 1;

        if ($address->getAllItems()) {
            $currentAmount = $address->getPaymentInstallmentFeeAmount();
            $payment = $quote->getPayment();

            if($payment && !empty($payment)) {

                $paymentMethod = $quote->getPayment()->getMethod() ;

                if($paymentMethod == "adyen_cc" || substr($paymentMethod, 0, 14) == 'adyen_oneclick') {

                    $info = $payment->getMethodInstance();

                    $instance = $info->getInfoInstance();
                    $numberOfInstallments = $instance->getAdditionalInformation('number_of_installments');

                    if($numberOfInstallments > 0)
                    {
                        // get the Interest Rate of this installment

                        // get cc type
                        $ccType = $instance->getCcType();

                        // get installment for this specific card type
                        $ccTypeInstallments = "installments_".$ccType;

                        $all_installments = Mage::helper('adyen/installments')->getInstallments(null, $ccTypeInstallments);
                        if(empty($all_installments)) {
                            // use default installments
                            $all_installments = Mage::helper('adyen/installments')->getInstallments();
                        }

                        $installmentKey = $numberOfInstallments - 1;
                        $installment = $all_installments[$installmentKey];

                        if($installment != null && is_array($installment)) {

                            // check if interest rate is filled in
                            if(isset($installment[3]) && $installment[3] > 0) {

                                $this->_setAmount(0);
                                $this->_setBaseAmount(0);

                                $interestRate = $installment[3];
                                $grandTotal = $address->getGrandTotal();
{'fraction_non_alphanumeric': 0.10475787095863334, 'fraction_numerical': 0.0077650712974728225, 'mean_word_length': 1.944305901911887, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4377903', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1778, 'n_words': 466}