Skip to content

Commit

Permalink
Initial public release
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Peters committed Oct 5, 2017
1 parent 2c83719 commit 9aa3e42
Show file tree
Hide file tree
Showing 68 changed files with 7,629 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Magento 1.x PSP extension
=========================

This is the official Magento 1.x extension to enable CM Payments payment methods in Magento

## Installation

To install this extension, simply place the files in this repository in the root of your Magento installation

## Submitting bugs and feature requests

Bugs and feature request are tracked on [GitHub](https://github.com/cmpayments/magento1-psp-extension/issues)

## Copyright and license

The cmpayment/magento1-psp-extension is copyright © [CM Payments](https://github.com/cmpayments/) and licensed for use under the MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* Block to insert additional fees into order totals (Magento backend)
*
* @category Comaxx
* @package Comaxx_CmPayments
* @author Development <development@comaxx.nl>
*/
class Comaxx_CmPayments_Block_Adminhtml_Sales_Totals_Creditmemo extends Mage_Adminhtml_Block_Sales_Order_Creditmemo_Totals
{
/**
* Initialize order totals array
*
* @return Mage_Sales_Block_Order_Totals
*/
protected function _initTotals()
{
parent::_initTotals();

$order = $this->getSource()->getOrder();
$amount = $order->getCmpaymentsFeeAmount();
$method = $order->getPayment()->getMethodInstance();

$tax = $order->getCmpaymentsFeeTaxAmount();

if ($amount && $amount > 0) {
$label = ($method instanceof Comaxx_CmPayments_Model_Method_Abstract) ? $method->getPmName() . ' ' . $this->helper('cmpayments')
->__('payment fee') : 'Payment fee';

$this->addTotalBefore(
new Varien_Object(
array(
'code' => 'cmpayments_payment_fee',
'value' => $amount,
'base_value' => $amount,
'label' => $label,
), array('tax')
)
);

//update totals for creditmemo since Magento does not use order/invoice grand totals
$creditmemo = $this->getCreditMemo();
//set tax
$creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $tax);
$creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $tax);
//set grand total
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $amount + $tax);
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $amount + $tax);

//set creditmemo values on total overview
$grandTotal = $this->getTotal('grand_total');
$grandTotal->setBaseValue($creditmemo->getBaseGrandTotal());
$grandTotal->setValue($creditmemo->getGrandTotal());
}

return $this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* Block to insert additional fees into invoice totals (Magento backend)
*
* @category Comaxx
* @package Comaxx_CmPayments
* @author Development <development@comaxx.nl>
*/
class Comaxx_CmPayments_Block_Adminhtml_Sales_Totals_Invoice extends Mage_Adminhtml_Block_Sales_Order_Invoice_Totals
{
/**
* Initialize order totals array
*
* @return Mage_Sales_Block_Order_Totals
*/
protected function _initTotals()
{
parent::_initTotals();

$invoice = $this->getSource();
$amount = $invoice->getCmpaymentsFeeAmount();
$method = $invoice->getOrder()->getPayment()->getMethodInstance();

if ($amount && $amount > 0) {
$label = ($method instanceof Comaxx_CmPayments_Model_Method_Abstract) ? $method->getPmName() . ' ' . $this->helper('cmpayments')
->__('payment fee') : 'Payment fee';

$this->addTotalBefore(
new Varien_Object(
array(
'code' => 'cmpayments_payment_fee',
'value' => $amount,
'base_value' => $amount,
'label' => $label,
), array('tax')
)
);
}

return $this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* Block to insert additional fees into order totals (Magento backend)
*
* @category Comaxx
* @package Comaxx_CmPayments
* @author Development <development@comaxx.nl>
*/
class Comaxx_CmPayments_Block_Adminhtml_Sales_Totals_Order extends Mage_Adminhtml_Block_Sales_Order_Totals
{
/**
* Initialize order totals array
*
* @return Mage_Sales_Block_Order_Totals
*/
protected function _initTotals()
{
parent::_initTotals();

$order = $this->getSource();
$amount = $order->getCmpaymentsFeeAmount();
$method = $order->getPayment()->getMethodInstance();

if ($amount && $amount > 0) {
$label = ($method instanceof Comaxx_CmPayments_Model_Method_Abstract) ? $method->getPmName() . ' ' . $this->helper('cmpayments')
->__('payment fee') : 'Payment fee';

$this->addTotalBefore(
new Varien_Object(
array(
'code' => 'cmpayments_payment_fee',
'value' => $amount,
'base_value' => $amount,
'label' => $label,
), array('tax')
)
);
}

return $this;
}

}
122 changes: 122 additions & 0 deletions app/code/community/Comaxx/CmPayments/Block/Checkout/Fee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

/**
* Block for displaying the additional fee in the checkout totals overview
*
* @category Comaxx
* @package Comaxx_CmPayments
* @author Development <development@comaxx.nl>
*/
class Comaxx_CmPayments_Block_Checkout_Fee extends Mage_Checkout_Block_Total_Default
{

protected $_template = 'comaxx_cmpayments/checkout/fee.phtml';
private $_tax_display;

const INCL_EXCL_TAX = '3', INCL_TAX = '2', EXCL_TAX = '1';

public function __construct()
{
$this->setTemplate($this->_template);
$this->_store = Mage::app()->getStore();
}

private function getTaxDisplay()
{
if (! $this->_tax_display) {
$payment = $this->getTotal()->getAddress()->getQuote()->getPayment();
if ($payment) {
$this->_tax_display = $this->helper('cmpayments/config')
->getPaymentMethodItem($payment->getMethod(), 'additional_fee_displaytax');
}
}

return $this->_tax_display;
}

/**
* Check if we need display afterpay costs include and exclude tax
*
* @return bool
*/
public function displayBoth()
{
return $this->getTaxDisplay() === self::INCL_EXCL_TAX;
}

/**
* Check if we need display shipping include tax
*
* @return bool
*/
public function displayIncludeTax()
{
return $this->getTaxDisplay() === self::INCL_TAX;
}

/**
* Check if we need display shipping exclude tax
*
* @return bool
*/
public function displayExcludeTax()
{
return $this->getTaxDisplay() === self::EXCL_TAX;
}

/**
* Get shipping amount include tax
*
* @return float
*/
public function getPaymentsFeeIncludeTax()
{
$address = $this->getTotal()->getAddress();
$quote = $address->getQuote();

return $quote->getCmpaymentsFeeAmount() + $quote->getCmpaymentsFeeTaxAmount();
}

/**
* Get shipping amount exclude tax
*
* @return float
*/
public function getPaymentsFeeExcludeTax()
{
$address = $this->getTotal()->getAddress();
$quote = $address->getQuote();

return $quote->getCmpaymentsFeeAmount();
}

public function getIncludeTaxLabel()
{
$address = $this->getTotal()->getAddress();
$quote = $address->getQuote();
$payment = $quote->getPayment();
$payment_name = '';

if ($payment->getMethod() !== null) {
$method = $payment->getMethodInstance();
$payment_name = $method->getPmName() . ' ';
}

return $payment_name . ' ' . $this->helper('cmpayments')->__('payment fee (Incl.VAT)');
}

public function getExcludeTaxLabel()
{
$address = $this->getTotal()->getAddress();
$quote = $address->getQuote();
$payment = $quote->getPayment();
$payment_name = '';

if ($payment->getMethod() !== null) {
$method = $payment->getMethodInstance();
$payment_name = $method->getPmName() . ' ';
}

return $payment_name . ' ' . $this->helper('cmpayments')->__('payment fee (Excl.VAT)');
}
}
17 changes: 17 additions & 0 deletions app/code/community/Comaxx/CmPayments/Block/Config/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* Block used for extracting plugin version on config page
*
* @category Comaxx
* @package Comaxx_CmPayments
* @author Development <development@comaxx.nl>
*/
class Comaxx_CmPayments_Block_Config_Version extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
//return version of plugin
return Mage::getConfig()->getModuleConfig("Comaxx_CmPayments")->version;
}
}
Loading

0 comments on commit 9aa3e42

Please sign in to comment.