InfiniteTouch_Ontopay - Version 1.0.0

Version Notes

A payment module for connection to the OntoPay payment gateway.

Download this release

Release Info

Developer Andrew Dunn
Extension InfiniteTouch_Ontopay
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/InfiniteTouch/Ontopay/Block/Form/Ontopay.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class InfiniteTouch_Ontopay_Block_Form_Ontopay extends Mage_Payment_Block_Form
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $mark = Mage::getConfig()->getBlockClassName('core/template');
8
+ $mark = new $mark;
9
+ $mark->setTemplate('infinitetouch/ontopay/form/ontopay.phtml');
10
+ $this->setTemplate('infinitetouch/ontopay/form/redirect.phtml')
11
+ ->setRedirectMessage(
12
+ Mage::helper('infinitetouch_ontopay')->__('You will be redirected to the OntoPay website.')
13
+ )
14
+ ->setMethodTitle('') // Output PayPal mark, omit title
15
+ ->setMethodLabelAfterHtml($mark->toHtml())
16
+ ;
17
+ return parent::_construct();
18
+ }
19
+ }
app/code/community/InfiniteTouch/Ontopay/Helper/Data.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class InfiniteTouch_Ontopay_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ protected $_xmlPathModulePrefix = 'payment/infinitetouch_ontopay/';
6
+ const ONTOPAY_DEV_VALIDATION_URL = 'https://dev-api.ontopay.com/transaction/validate/';
7
+ const ONTOPAY_VALIDATION_URL = 'https://api.ontopay.com/transaction/validate/';
8
+ const ORDER_STATUS_AFTER_PAYMENT = 'processing';
9
+ const LOG_PATH = 'ontopay.log';
10
+
11
+ /**
12
+ * Return module config
13
+ * @param string $path without module prefix
14
+ * @return mixed
15
+ */
16
+ public function getStoreConfig($path)
17
+ {
18
+ $xmlPath = $this->_xmlPathModulePrefix . $path;
19
+ return Mage::getStoreConfig($xmlPath);
20
+ }
21
+
22
+ public function logEnabled()
23
+ {
24
+ return $this->getStoreConfig('enable_logging');
25
+ }
26
+
27
+ public function checkIsPaid($order)
28
+ {
29
+ $fields_string = '';
30
+ $url = $this->getStoreConfig('test_mode') ? self::ONTOPAY_DEV_VALIDATION_URL : self::ONTOPAY_VALIDATION_URL;
31
+ $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
32
+ $fields = array(
33
+ "api_key" => $this->getStoreConfig('api_key'),
34
+ "transaction_id" => $order->getOntopayTransactionId(),
35
+ "amount" => $order->getBaseGrandTotal(),
36
+ "currency" => $currency
37
+ );
38
+ foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
39
+ rtrim($fields_string, '&');
40
+
41
+ $url .= '?' . $fields_string;
42
+ if ($this->logEnabled()) Mage::Log("Request: " . $url, null, self::LOG_PATH);
43
+ $ch = curl_init($url);
44
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
45
+ $content = curl_exec($ch);
46
+ if ($this->logEnabled()) Mage::Log("Response: " . $content, null, self::LOG_PATH);
47
+ $json = json_decode($content);
48
+ if ($json->status == "ok") { return true; }
49
+
50
+ return false;
51
+ }
52
+
53
+ public function validateOrderPayment($order)
54
+ {
55
+ if ($this->checkIsPaid($order)) {
56
+ $invoice = $order->prepareInvoice();
57
+ $invoice->register()->capture();
58
+ $order->addRelatedObject($invoice);
59
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Gateway has authorized the payment.');
60
+ $order->setStatus(self::ORDER_STATUS_AFTER_PAYMENT);
61
+ $order->save();
62
+ $order->sendNewOrderEmail();
63
+ return true;
64
+ }
65
+ else {
66
+ $order->registerCancellation('Gateway hasn\'t authorized the payment.');
67
+ $order->save();
68
+ }
69
+ return false;
70
+ }
71
+
72
+ }
app/code/community/InfiniteTouch/Ontopay/Model/Ontopay.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class InfiniteTouch_Ontopay_Model_Ontopay extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ const LOG_PATH = 'ontopay.log';
6
+ const SUBMIT_URL = 'https://www.ontopay.com/checkout/';
7
+ const DEV_SUBMIT_URL = 'https://www.ontopay.com/checkout-dev/';
8
+
9
+ protected $_code = 'infinitetouch_ontopay';
10
+ protected $_formBlockType = 'infinitetouch_ontopay/form_ontopay';
11
+
12
+ protected $_isGateway = true;
13
+ protected $_canAuthorize = true;
14
+ protected $_canCapture = true;
15
+ protected $_canUseInternal = true;
16
+ protected $_canUseCheckout = true;
17
+
18
+ public function authorize(Varien_Object $payment, $amount)
19
+ {
20
+ $helper = Mage::helper('infinitetouch_ontopay');
21
+ /** @var $order Mage_Sales_Model_Order */
22
+ $order = $payment->getOrder();
23
+ $orderId = $order->getIncrementId();
24
+ $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
25
+
26
+ $redirectUrl = ($helper->getStoreConfig('test_mode') ? self::DEV_SUBMIT_URL : self::SUBMIT_URL)
27
+ . "?to=" . $helper->getStoreConfig('merchant_id')
28
+ . "&amount=" . $amount
29
+ . "&currency=" . $currency
30
+ . "&order_id=" . $orderId;
31
+ Mage::getSingleton('core/session')->setRedirectUrl($redirectUrl);
32
+ }
33
+
34
+ public function getOrderPlaceRedirectUrl()
35
+ {
36
+ return (string)Mage::getSingleton('core/session')->getRedirectUrl();
37
+ }
38
+
39
+ public function capture(Varien_Object $payment, $amount)
40
+ {
41
+ $payment->setStatus(self::STATUS_APPROVED);
42
+ return $this;
43
+ }
44
+
45
+
46
+ }
47
+
app/code/community/InfiniteTouch/Ontopay/controllers/TransactionController.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class InfiniteTouch_Ontopay_TransactionController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ const ORDER_STATUS_AFTER_PAYMENT = 'processing';
6
+
7
+ public function saveAction()
8
+ {
9
+ $arrParams = $_GET;
10
+ $orderId = $arrParams['order_id'];
11
+ $transactionId = $arrParams['transaction_id'];
12
+
13
+ try{
14
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
15
+ $order->setOntopayTransactionId($transactionId);
16
+ $order->save();
17
+ // print "Transaction #{$transactionId} was saved into order #{$orderId}";
18
+ $resultUrl = Mage::helper('infinitetouch_ontopay')->validateOrderPayment($order) ? 'checkout/onepage/success' : 'checkout/onepage/failure';
19
+ $this->_redirect($resultUrl);
20
+ } catch (Exception $e){
21
+ echo $e->getMessage();
22
+ }
23
+ }
24
+
25
+ public function checkAction() {
26
+ $arrParams = $_GET;
27
+ $orderId = $arrParams['order_id'];
28
+
29
+ try {
30
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
31
+ Mage::helper('infinitetouch_ontopay')->validateOrderPayment($order);
32
+ } catch (Exception $e){
33
+ echo $e->getMessage();
34
+ }
35
+ }
36
+
37
+ }
app/code/community/InfiniteTouch/Ontopay/etc/config.xml ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <InfiniteTouch_Ontopay>
5
+ <version>1.0.0</version>
6
+ </InfiniteTouch_Ontopay>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <infinitetouch_ontopay>
11
+ <class>InfiniteTouch_Ontopay_Block</class>
12
+ </infinitetouch_ontopay>
13
+ </blocks>
14
+ <models>
15
+ <infinitetouch_ontopay>
16
+ <class>InfiniteTouch_Ontopay_Model</class>
17
+ </infinitetouch_ontopay>
18
+ </models>
19
+ <helpers>
20
+ <infinitetouch_ontopay>
21
+ <class>InfiniteTouch_Ontopay_Helper</class>
22
+ </infinitetouch_ontopay>
23
+ </helpers>
24
+ <resources>
25
+ <infinitetouch_ontopay_setup>
26
+ <setup>
27
+ <module>InfiniteTouch_Ontopay</module>
28
+ </setup>
29
+ <connection>
30
+ <use>core_setup</use>
31
+ </connection>
32
+ </infinitetouch_ontopay_setup>
33
+ <infinitetouch_ontopay_write>
34
+ <connection>
35
+ <use>core_write</use>
36
+ </connection>
37
+ </infinitetouch_ontopay_write>
38
+ <infinitetouch_ontopay_read>
39
+ <connection>
40
+ <use>core_read</use>
41
+ </connection>
42
+ </infinitetouch_ontopay_read>
43
+ </resources>
44
+ </global>
45
+
46
+ <frontend>
47
+ <routers>
48
+ <infinitetouch_ontopay>
49
+ <use>standard</use>
50
+ <args>
51
+ <module>InfiniteTouch_Ontopay</module>
52
+ <frontName>ontopay</frontName>
53
+ </args>
54
+ </infinitetouch_ontopay>
55
+ </routers>
56
+ </frontend>
57
+
58
+ <default>
59
+ <payment>
60
+ <infinitetouch_ontopay>
61
+ <active>1</active>
62
+ <model>infinitetouch_ontopay/ontopay</model>
63
+ <order_status>pending</order_status>
64
+ <title>OntoPay</title>
65
+ <merchant_id>Insert your phone number from the OntoPay account</merchant_id>
66
+ <payment_action>authorize</payment_action>
67
+ <allowspecific>0</allowspecific>
68
+ <sort_order>1</sort_order>
69
+ <test_mode>1</test_mode>
70
+ <enable_logging>1</enable_logging>
71
+ </infinitetouch_ontopay>
72
+ </payment>
73
+ </default>
74
+
75
+ </config>
app/code/community/InfiniteTouch/Ontopay/etc/system.xml ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <infinitetouch_ontopay translate="label" module="infinitetouch_ontopay">
7
+ <label>OntoPay Payment Module</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>100</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>10</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>0</show_in_store>
22
+ </active>
23
+ <title translate="label">
24
+ <label>Title</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>20</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </title>
31
+ <order_status translate="label">
32
+ <label>New order status</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>adminhtml/system_config_source_order_status_new</source_model>
35
+ <sort_order>50</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ </order_status>
40
+ <merchant_id>
41
+ <label>OntoPay Account Phone Number</label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>55</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>0</show_in_store>
47
+ </merchant_id>
48
+ <api_key>
49
+ <label>OntoPay API Key</label>
50
+ <frontend_type>text</frontend_type>
51
+ <sort_order>57</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>0</show_in_store>
55
+ </api_key>
56
+ <allowspecific translate="label">
57
+ <label>Payment Applicable From</label>
58
+ <frontend_type>select</frontend_type>
59
+ <sort_order>60</sort_order>
60
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>0</show_in_store>
64
+ </allowspecific>
65
+ <specificcountry translate="label">
66
+ <label>Countries Payment Applicable From</label>
67
+ <frontend_type>multiselect</frontend_type>
68
+ <sort_order>70</sort_order>
69
+ <source_model>adminhtml/system_config_source_country</source_model>
70
+ <show_in_default>1</show_in_default>
71
+ <show_in_website>1</show_in_website>
72
+ <show_in_store>0</show_in_store>
73
+ <depends><allowspecific>1</allowspecific></depends>
74
+ </specificcountry>
75
+ <sort_order translate="label">
76
+ <label>Sort Order</label>
77
+ <frontend_type>text</frontend_type>
78
+ <sort_order>100</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </sort_order>
83
+ <test_mode translate="label">
84
+ <label>Test Mode</label>
85
+ <frontend_type>select</frontend_type>
86
+ <source_model>adminhtml/system_config_source_yesno</source_model>
87
+ <sort_order>200</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>0</show_in_store>
91
+ </test_mode>
92
+ <enable_logging translate="label">
93
+ <label>Enable logging</label>
94
+ <frontend_type>select</frontend_type>
95
+ <source_model>adminhtml/system_config_source_yesno</source_model>
96
+ <sort_order>300</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>0</show_in_store>
100
+ </enable_logging>
101
+ </fields>
102
+ </infinitetouch_ontopay>
103
+ </groups>
104
+ </payment>
105
+ </sections>
106
+ </config>
app/code/community/InfiniteTouch/Ontopay/sql/infinitetouch_ontopay_setup/install-1.0.0.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: stepantsevich_m
5
+ * Date: 01.07.13
6
+ * Time: 10:38
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+ /* @var $installer Mage_Sales_Model_Mysql4_Setup */
10
+ $installer = $this;
11
+
12
+
13
+ $installer->startSetup();
14
+
15
+ $installer->addAttribute(
16
+ 'order',
17
+ 'ontopay_transaction_id',
18
+ array(
19
+ 'type' => 'varchar'
20
+ )
21
+ );
22
+
23
+ $installer->endSetup();
app/design/frontend/base/default/template/infinitetouch/ontopay/form/ontopay.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <img src="<?php echo $this->getSkinUrl('images/ontopay/ontopay-now-small.png') ?>" alt="<?php echo $this->__('Pay now with OntoPay'); ?>" class="v-middle"/>
2
+ <a href="http://ontopay.com/solution/consumers/"
3
+ target="_blank">
4
+ <?php echo $this->__('What is OntoPay?')?>
5
+ </a>
app/design/frontend/base/default/template/infinitetouch/ontopay/form/redirect.phtml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ /**
29
+ * @see Mage_PayPal_Block_Express_Form
30
+ * @see Mage_PayPal_Block_Standard_Form
31
+ */
32
+ ?>
33
+ <ul class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
34
+ <li class="form-alt"><?php echo $this->getRedirectMessage() ?></li>
35
+ </ul>
app/etc/modules/InfiniteTouch_Ontopay.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <InfiniteTouch_Ontopay>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Payment/>
9
+ </depends>
10
+ </InfiniteTouch_Ontopay>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>InfiniteTouch_Ontopay</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>A payment module for connection to the OntoPay payment gateway.</summary>
10
+ <description>A payment module for connection to the OntoPay payment gateway.</description>
11
+ <notes>A payment module for connection to the OntoPay payment gateway.</notes>
12
+ <authors><author><name>Andrew Dunn</name><user>AndyDunn</user><email>andy@infinitetouch.ie</email></author><author><name>Ruslan Mukhatov</name><user>Ruslan</user><email>ruslan.mukhatov@gmail.com</email></author></authors>
13
+ <date>2015-06-17</date>
14
+ <time>15:12:07</time>
15
+ <contents><target name="magecommunity"><dir name="InfiniteTouch"><dir name="Ontopay"><dir name="Block"><dir name="Form"><file name="Ontopay.php" hash="f9ec9dc6a383078d1a143cd1f5eff7e6"/></dir></dir><dir name="Helper"><file name="Data.php" hash="6961f208b0a2fb7fbe3c6a59313218da"/></dir><dir name="Model"><file name="Ontopay.php" hash="ed082d6cbac75f0aa8708fc20c18c01e"/></dir><dir name="controllers"><file name="TransactionController.php" hash="c39ecf8e51a8aa0e00d410bb29a89fc1"/></dir><dir name="etc"><file name="config.xml" hash="219991bef716af0aa012a63f93bfc9a3"/><file name="system.xml" hash="169ac06d3dcc7bb2c16d609d2c6e15d0"/></dir><dir name="sql"><dir name="infinitetouch_ontopay_setup"><file name="install-1.0.0.php" hash="801c03b92787979789fc5c1c0da71603"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="infinitetouch"><dir name="ontopay"><dir name="form"><file name="ontopay.phtml" hash="252946eefae054b797b3e48e032c91e9"/><file name="redirect.phtml" hash="b229f926255f9af7d9937552033960c4"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="InfiniteTouch_Ontopay.xml" hash="705975e1d25ad69756c92665323ba8b9"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="ontopay"><file name="ontopay-now-small.png" hash="4269b4c32da0935bbadb10d35f730f29"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/images/ontopay/ontopay-now-small.png ADDED
Binary file