Skip to content

Commit

Permalink
Merge branch 'feature/mollie-components' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Jun 30, 2020
2 parents d1a6c0b + f068195 commit 9e10949
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php


class Mollie_Mpm_Block_Payment_Form_CreditcardComponents extends Mollie_Mpm_Block_Payment_Form
{
public function _construct()
{
parent::_construct();
$this->setTemplate('mollie/mpm/payment/form/creditcard-components.phtml');
}
}
4 changes: 4 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public function startTransaction(Mage_Sales_Model_Order $order)
$orderData['payment']['dueDate'] = $this->mollieHelper->getBanktransferDueDate($storeId);
}

if ($method == 'creditcard' && isset($additionalData['card_token'])) {
$orderData['payment']['cardToken'] = $additionalData['card_token'];
}

if (isset($additionalData['limited_methods'])) {
$orderData['method'] = $additionalData['limited_methods'];
}
Expand Down
4 changes: 4 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function startTransaction(Mage_Sales_Model_Order $order)
$paymentData['billingEmail'] = $order->getCustomerEmail();
}

if ($method == 'creditcard' && isset($additionalData['card_token'])) {
$paymentData['cardToken'] = $additionalData['card_token'];
}

if (!$order->getIsVirtual() && $order->hasData('shipping_address_id')) {
$paymentData['shippingAddress'] = $this->getAddressLine($order->getShippingAddress());
}
Expand Down
1 change: 1 addition & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function assignData($data)
{
parent::assignData($data);
$this->getInfoInstance()->setAdditionalInformation('selected_issuer', null);
$this->getInfoInstance()->setAdditionalInformation('card_token', null);
return $this;
}
}
22 changes: 22 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Method/Creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,26 @@ class Mollie_Mpm_Model_Method_Creditcard extends Mollie_Mpm_Model_Method_Abstrac
*/
protected $_paymentMethod = self::PAYMENT_METHOD;

/**
* Type of block that generates method form
*
* @var string
*/
protected $_formBlockType = 'mpm/payment_form_creditcardComponents';

/**
* @param mixed $data
*
* @return $this|Mage_Payment_Model_Info
* @throws Mage_Core_Exception
*/
public function assignData($data)
{
parent::assignData($data);

$cardToken = Mage::app()->getRequest()->getParam('cardToken');
$this->getInfoInstance()->setAdditionalInformation('card_token', $cardToken);

return $this;
}
}
24 changes: 24 additions & 0 deletions app/code/community/Mollie/Mpm/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,28 @@ public function restoreQuoteWhenReturningFromMollie(Varien_Event_Observer $obser
Mage::logException($e);
}
}

/**
* The Mollie javascript library conflicts with he ancient prototype.js library, that's why we load the library
* as soon as possible. When adding the script using xml it is always added to late. That's why we do it by
* manipulating the html.
*
* @param Varien_Event_Observer $observer
*/
public function injectMollieComponentsJs(Varien_Event_Observer $observer)
{
/** @var Mage_Core_Block_Template $block */
$block = $observer->getBlock();

if (!$block instanceof Mage_Page_Block_Html_Head) {
return;
}

/** @var \Varient_Object $transport */
$transport = $observer->getData('transport');
$html = $transport->getHtml();
$html = preg_replace('#</title>#', '</title>' . PHP_EOL . '<script type="text/javascript" src="https://js.mollie.com/v1/mollie.js"></script>', $html, 1);

$transport->setHtml($html);
}
}
20 changes: 18 additions & 2 deletions app/code/community/Mollie/Mpm/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function paymentAction()
}

$methodInstance = $order->getPayment()->getMethodInstance();
$redirectUrl = $methodInstance->startTransaction($order);
if (!empty($redirectUrl)) {
$redirectUrl = $this->getRedirectUrl($methodInstance, $order);
if ($redirectUrl) {
$this->_redirectUrl($redirectUrl);
return;
} else {
Expand Down Expand Up @@ -239,4 +239,20 @@ public function redirectAction()
$this->loadLayout();
$this->renderLayout();
}

/**
* @param Mage_Payment_Model_Method_Abstract $methodInstance
* @param Mage_Sales_Model_Order $order
* @return string|null
*/
private function getRedirectUrl(Mage_Payment_Model_Method_Abstract $methodInstance, Mage_Sales_Model_Order $order)
{
$redirectUrl = $methodInstance->startTransaction($order);

if (!$redirectUrl && $methodInstance instanceof Mollie_Mpm_Model_Method_Creditcard) {
$redirectUrl = Mage::getUrl('checkout/onepage/success');
}

return $redirectUrl;
}
}
9 changes: 9 additions & 0 deletions app/code/community/Mollie/Mpm/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@
</mollie_controller_action_predispatch_onestepcheckout_index_index>
</observers>
</controller_action_predispatch_checkout_onepage_index>
<core_block_abstract_to_html_after>
<observers>
<mollie_core_layout_block_create_after>
<type>singleton</type>
<class>Mollie_Mpm_Model_Observer</class>
<method>injectMollieComponentsJs</method>
</mollie_core_layout_block_create_after>
</observers>
</core_block_abstract_to_html_after>
</events>
<sales>
<quote>
Expand Down
59 changes: 41 additions & 18 deletions app/code/community/Mollie/Mpm/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,20 @@
<active>1</active>
</depends>
</type>
<profile_id translate="label tooltip">
<label>Profile ID</label>
<sort_order>12</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<active>1</active>
</depends>
</profile_id>
<apikey_test translate="label tooltip">
<label>Test API Key</label>
<frontend_type>text</frontend_type>
<sort_order>12</sort_order>
<sort_order>13</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -107,7 +117,7 @@
<apikey_live translate="label tooltip">
<label>Live API Key</label>
<frontend_type>text</frontend_type>
<sort_order>12</sort_order>
<sort_order>14</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -119,7 +129,7 @@
<label>Api Test</label>
<frontend_type>button</frontend_type>
<frontend_model>mpm/adminhtml_system_config_form_apitest_button</frontend_model>
<sort_order>13</sort_order>
<sort_order>15</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -131,7 +141,7 @@
<label></label>
<frontend_type>button</frontend_type>
<frontend_model>mpm/adminhtml_system_config_form_apitest_result</frontend_model>
<sort_order>14</sort_order>
<sort_order>16</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down Expand Up @@ -168,7 +178,7 @@
<label>Show Icons</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>22</sort_order>
<sort_order>23</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -181,7 +191,7 @@
<label>Status Pending</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status_new</source_model>
<sort_order>23</sort_order>
<sort_order>24</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -194,7 +204,7 @@
<label>Status Processing</label>
<frontend_type>select</frontend_type>
<source_model>mpm/adminhtml_system_config_source_processing</source_model>
<sort_order>24</sort_order>
<sort_order>25</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -207,7 +217,7 @@
<label>Send Invoice Email</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>25</sort_order>
<sort_order>26</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -220,7 +230,7 @@
<label>Language Payment Page</label>
<frontend_type>select</frontend_type>
<source_model>mpm/adminhtml_system_config_source_locale</source_model>
<sort_order>26</sort_order>
<sort_order>27</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -233,7 +243,7 @@
<label>Use Base Currency</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>27</sort_order>
<sort_order>28</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -246,7 +256,7 @@
<label>Show Transaction Details</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>27</sort_order>
<sort_order>29</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -259,7 +269,7 @@
<label>Cancel the order when the connection fails</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>28</sort_order>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down Expand Up @@ -764,10 +774,23 @@
<active>1</active>
</depends>
</method>
<use_components translate="label tooltip">
<label>Use Mollie Components</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>5</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[With Components the customer can enter their credit card details within your webshop.<br><strong>Note:</strong> You need to enter your Profile ID in the general section of this extension configuration to use Mollie Components.]]></comment>
<depends>
<active>1</active>
</depends>
</use_components>
<payment_description translate="label">
<label>Description</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<sort_order>6</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -786,7 +809,7 @@
<allowspecific translate="label">
<label>Payment from Applicable Countries</label>
<frontend_type>allowspecific</frontend_type>
<sort_order>5</sort_order>
<sort_order>7</sort_order>
<source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand All @@ -798,7 +821,7 @@
<specificcountry translate="label">
<label>Payment from Specific Countries</label>
<frontend_type>multiselect</frontend_type>
<sort_order>6</sort_order>
<sort_order>8</sort_order>
<source_model>adminhtml/system_config_source_country</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand All @@ -811,7 +834,7 @@
<min_order_total translate="label">
<label>Minimum Order Total</label>
<frontend_type>text</frontend_type>
<sort_order>7</sort_order>
<sort_order>9</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -822,7 +845,7 @@
<max_order_total translate="label">
<label>Maximum Order Total</label>
<frontend_type>text</frontend_type>
<sort_order>8</sort_order>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -833,7 +856,7 @@
<sort_order translate="label">
<label>Sort Order</label>
<frontend_type>text</frontend_type>
<sort_order>9</sort_order>
<sort_order>11</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down
16 changes: 16 additions & 0 deletions app/design/frontend/base/default/layout/mollie_mpm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,20 @@
<block type="mpm/adminhtml_sales_creditmemo_paymentFee" before="tax" name="mollie_mpm_payment_fee" />
</reference>
</sales_email_order_creditmemo_items>

<checkout_onepage_index>
<reference name="head">
<action method="addItem">
<type>skin_js</type>
<name>js/mollie/mpm/creditcard-components.js</name>
</action>
<action method="addCss" ifconfig="payment/mollie/active">
<stylesheet>mollie/mpm/style.css</stylesheet>
</action>
</reference>

<reference name="after_body_start">
<block type="core/template" name="mollie_components_initialize" template="mollie/mpm/payment/after_body_start.phtml" />
</reference>
</checkout_onepage_index>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
if (!Mage::getStoreConfigFlag('payment/mollie_creditcard/use_components')) {
return;
}
?>

<script>
var mollieComponentsInstance = new MollieComponents(
'<?php echo Mage::getStoreConfig('payment/mollie/profile_id'); ?>',
<?php echo Mage::helper('mpm')->getModus() == 'test' ? 'true' : 'false'; ?>,
'<?php echo Mage::app()->getLocale()->getLocaleCode(); ?>'
);
</script>
Loading

0 comments on commit 9e10949

Please sign in to comment.