<?php

/**
 * @var $installer Mage_Core_Model_Resource_Setup
 */
$installer = $this;
$installer->startSetup();
/** Remove Attributes */
$_attributesArray = array('catalog_product' => array('payperrentals_buyoutprice', 'payperrentals_enable_extend', 'payperrentals_enable_buyout', 'payperrentals_buyout_onproduct'));
$_attributeModel = new Mage_Sales_Model_Resource_Setup('sales_setup');
foreach ($_attributesArray as $_attributeType => $_attributeArray) {
    foreach ($_attributeArray as $_attributeCode) {
        try {
            $_attributeModel->removeAttribute($_attributeType, $_attributeCode);
        } catch (Exception $_e) {
            Mage::logException($_e);
        }
    }
}
$installer->endSetup();
$eav->addAttribute('quote', 'payexinvoice_payment_fee', array('type' => 'decimal'));
$eav->addAttribute('quote', 'base_payexinvoice_payment_fee', array('type' => 'decimal'));
$eav->addAttribute('order', 'payexinvoice_payment_fee', array('type' => 'decimal'));
$eav->addAttribute('order', 'base_payexinvoice_payment_fee', array('type' => 'decimal'));
// Clean up unnecessary data
try {
    $this->_conn->dropColumn($this->getTable('sales_flat_order'), 'px_invoice_fee');
    $this->_conn->dropColumn($this->getTable('sales_flat_order'), 'base_px_invoice_fee');
    $this->_conn->dropColumn($this->getTable('sales_flat_invoice'), 'px_invoice_fee');
    $this->_conn->dropColumn($this->getTable('sales_flat_invoice'), 'base_px_invoice_fee');
    $this->_conn->dropColumn($this->getTable('sales_flat_quote'), 'px_invoice_fee');
    $this->_conn->dropColumn($this->getTable('sales_flat_quote'), 'base_px_invoice_fee');
    $this->_conn->dropColumn($this->getTable('sales_flat_quote_address'), 'payexinvoice_payment_fee');
    $this->_conn->dropColumn($this->getTable('sales_flat_quote_address'), 'base_payexinvoice_payment_fee');
} catch (Exception $e) {
    Mage::logException($e);
}
try {
    $eav = new Mage_Sales_Model_Resource_Setup('sales_setup');
    $eav->removeAttribute('order', 'px_invoice_fee');
    $eav->removeAttribute('order', 'base_px_invoice_fee');
    $eav->removeAttribute('invoice', 'px_invoice_fee');
    $eav->removeAttribute('invoice', 'base_px_invoice_fee');
    $eav->removeAttribute('quote', 'px_invoice_fee');
    $eav->removeAttribute('quote', 'base_px_invoice_fee');
    $eav->removeAttribute('quote_address', 'px_invoice_fee');
    $eav->removeAttribute('quote_address', 'base_px_invoice_fee');
} catch (Exception $e) {
    Mage::logException($e);
}
$this->endSetup();