Skip to content

Commit

Permalink
Version 4.0.8
Browse files Browse the repository at this point in the history
+ Makes payment methods visible for internal use
+ Solves a problem with currency conversion and credit memos
+ Corrects webhooks for multi-store setups with store codes in URL
  • Loading branch information
jesse-mollie committed Mar 11, 2014
1 parent cf994ac commit 7fa379c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
11 changes: 9 additions & 2 deletions app/code/community/Mollie/Mpm/Helper/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

class Mollie_Mpm_Helper_Api
{
const PLUGIN_VERSION = '4.0.7';
const PLUGIN_VERSION = '4.0.8';

protected $api_key = null;
protected $amount = 0;
Expand Down Expand Up @@ -292,6 +292,13 @@ public function getErrorMessage()
return $this->error_message;
}

public function getWebhookURL()
{
$store_code = Mage::app()->getRequest()->getParam('store');
$store_url_part = empty($store_code) ? '/' : '/' . $store_code . '/';
return str_replace('/admin/', $store_url_part, Mage::getUrl('mpm/api/webhook'));
}

public function getPaymentMethods()
{
try
Expand Down Expand Up @@ -348,7 +355,7 @@ public function getPaymentMethods()
}
catch (Mollie_API_Exception $e)
{
Mage::log(__CLASS__ . '::' . __FUNCTION__ . '() failed to fetch available payment methods. API said: ' . $e->getMessage() . ' (' . $e->getCode() . ') ' );
Mage::log(__METHOD__ . '() failed to fetch available payment methods. API said: ' . $e->getMessage() . ' (' . $e->getCode() . ') ' );

if (strpos($e->getMessage(), "Unable to communicate with Mollie") === 0)
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Mollie/Mpm/Model/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Mollie_Mpm_Model_Api extends Mage_Payment_Model_Method_Abstract
protected $_isGateway = TRUE;
protected $_canAuthorize = TRUE;
protected $_canUseCheckout = TRUE;
protected $_canUseInternal = FALSE;
protected $_canUseInternal = TRUE;
protected $_canUseForMultishipping = FALSE; // wouldn't work without event capturing anyway
protected $_canRefund = FALSE;
protected $_canCapture = FALSE;
Expand Down
64 changes: 40 additions & 24 deletions app/code/community/Mollie/Mpm/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ protected function _showException ($e = '', $order_id = NULL)
$this->loadLayout();

$block = $this->getLayout()
->createBlock('Mage_Core_Block_Template')
->setTemplate('mollie/page/exception.phtml')
->setData('exception', $e)
->setData('orderId', $order_id);
->createBlock('Mage_Core_Block_Template')
->setTemplate('mollie/page/exception.phtml')
->setData('exception', $e)
->setData('orderId', $order_id);

$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
Expand Down Expand Up @@ -102,8 +102,8 @@ protected function getAmount (Mage_Sales_Model_Order $order)
}
else
{
Mage::log(__CLASS__ . '::' . __METHOD__ . ' said: Neither Base nor Order currency is in Euros.');
Mage::throwException(__CLASS__ . '::' . __METHOD__ . ' said: Neither Base nor Order currency is in Euros.');
Mage::log(__METHOD__ . ' said: Neither Base nor Order currency is in Euros.');
Mage::throwException(__METHOD__ . ' said: Neither Base nor Order currency is in Euros.');
}

if (is_string($grand_total))
Expand Down Expand Up @@ -184,9 +184,9 @@ public function paymentAction ()
// Creates transaction
/** @var $payment Mage_Sales_Model_Order_Payment */
$payment = Mage::getModel('sales/order_payment')
->setMethod('Mollie')
->setTransactionId($this->_api->getTransactionId())
->setIsTransactionClosed(false);
->setMethod('Mollie')
->setTransactionId($this->_api->getTransactionId())
->setIsTransactionClosed(false);


$order->setPayment($payment);
Expand Down Expand Up @@ -245,19 +245,14 @@ public function webhookAction ()
// Maakt een Order transactie aan
/** @var $payment Mage_Sales_Model_Order_Payment */
$payment = Mage::getModel('sales/order_payment')
->setMethod('Mollie')
->setTransactionId($transactionId)
->setIsTransactionClosed(TRUE);
->setMethod('Mollie')
->setTransactionId($transactionId)
->setIsTransactionClosed(TRUE);

$order->setPayment($payment);

if ($this->_api->getPaidStatus())
{
/*
* Update the total amount paid
*/
$order->setTotalPaid($this->_api->getAmount());

// Als de vorige betaling was mislukt, zijn de producten 'Canceled'... Undo that
foreach ($order->getAllItems() as $item) {
/** @var $item Mage_Sales_Model_Order_Item */
Expand All @@ -267,8 +262,6 @@ public function webhookAction ()

$this->_model->updatePayment($transactionId, $this->_api->getBankStatus(), $customer);

$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING, $this->__(Mollie_Mpm_Model_Api::PAYMENT_FLAG_PROCESSED), TRUE)->save();

/*
* Send an email to the customer.
*/
Expand All @@ -277,11 +270,33 @@ public function webhookAction ()
$order->sendNewOrderEmail()->setEmailSent(TRUE);
}

if (!Mage::Helper('mpm/data')->getConfig('mollie', 'skip_invoice'))
if (Mage::Helper('mpm/data')->getConfig('mollie', 'skip_invoice'))
{
/*
* Update the total amount paid
*/
try {
$amount = $this->_api->getAmount(); // Amount in EUROs

$curr_base = Mage::app()->getStore()->getBaseCurrencyCode();
$curr_store = Mage::app()->getStore()->getCurrentCurrencyCode();

$amount_base = Mage::helper('directory')->currencyConvert($amount, 'EUR', $curr_base);
$amount_store = Mage::helper('directory')->currencyConvert($amount, 'EUR', $curr_store);

$order->setBaseTotalPaid($amount_base);
$order->setTotalPaid($amount_store);
} catch (Exception $e) {
Mage::log(__METHOD__ . '() said: Could not convert currencies. Details: ' . $e->getMessage());
}
}
else
{
$this->_savePaidInvoice($order);
}

$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING, $this->__(Mollie_Mpm_Model_Api::PAYMENT_FLAG_PROCESSED), TRUE);

if ($transaction = $payment->getTransaction($transactionId))
{
$transaction->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
Expand All @@ -290,8 +305,9 @@ public function webhookAction ()
}
else
{
Mage::log(__CLASS__ . '::' . __METHOD__ . ' said: Could not find a transaction with id ' . $transactionId . ' for order ' . $orderId);
Mage::log(__METHOD__ . ' said: Could not find a transaction with id ' . $transactionId . ' for order ' . $orderId);
}
$order->save();
}
else
{
Expand Down Expand Up @@ -324,9 +340,9 @@ protected function _savePaidInvoice(Mage_Sales_Model_Order $order)
return FALSE;
}

$invoice = $order->prepareInvoice();
$invoice->register();
$invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_PAID);
$invoice = $order->prepareInvoice()
->register()
->pay();

Mage::getModel('core/resource_transaction')
->addObject($invoice)
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Mollie/Mpm/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<config>
<modules>
<Mollie_Mpm>
<version>4.0.7</version>
<version>4.0.8</version>
</Mollie_Mpm>
</modules>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ foreach ($methods as $method)

<b><?php echo $core->__('Webhook'); ?></b><br />
<?php echo $core->__('Your webhook URL is:'); ?><br />
<input id="webhook" value="<?php echo $this->escapeHtml(Mage::getUrl('mpm/api/webhook')); ?>" readonly onclick="this.select();" /><br />
<input id="webhook" value="<?php echo $this->escapeHtml(Mage::helper('mpm/api')->getWebhookURL()); ?>" readonly onclick="this.select();" /><br />
<script type="text/javascript">
var el = document.getElementById('webhook');
el.size = el.value.length + 20;
Expand Down
2 changes: 1 addition & 1 deletion app/etc/modules/Mollie_Mpm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<depends>
<Mage_Payment />
</depends>
<version>4.0.7</version>
<version>4.0.8</version>
</Mollie_Mpm>
</modules>
</config>
5 changes: 5 additions & 0 deletions changelog.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# Changelog #

## Wijzigingen in versie 4.0.8 ##
+ Maakt betaalmethoden zichtbaar bij intern aangemaakte orders
+ Lost een probleem met valutaconversie en creditmemos op
+ Geeft gecorrigeerde webhook weer bij URL's met store code

## Wijzigingen in versie 4.0.7 ##
+ Voegt een optie toe om automatisch mailen na een order uit te zetten
+ Voegt een probleemoplossend upgrade script toe
Expand Down

0 comments on commit 7fa379c

Please sign in to comment.