zapper-deeplinking - Version 1.0.1

Version Notes

N/A

Download this release

Release Info

Developer Zapper
Extension zapper-deeplinking
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

app/code/community/Zapper/.DS_Store ADDED
Binary file
app/code/community/Zapper/DeepLinking/.DS_Store ADDED
Binary file
app/code/community/Zapper/DeepLinking/Block/Form/DeepLinking.php ADDED
@@ -0,0 +1,16 @@
1
+ <?php
2
+ class Zapper_DeepLinking_Block_Form_DeepLinking extends Mage_Payment_Block_Form
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate( 'zapper_deeplinking/form/deeplinking.phtml' );
8
+ }
9
+
10
+ public function getOrder() {
11
+ $order = Mage::getModel('sales/order');
12
+ $session = Mage::getSingleton('checkout/session');
13
+ $order->loadByIncrementId($session->getLastRealOrderId());
14
+ return $order;
15
+ }
16
+ }
app/code/community/Zapper/DeepLinking/Block/Info/DeepLinking.php ADDED
@@ -0,0 +1,16 @@
1
+ <?php
2
+ class Zapper_DeepLinking_Block_Info_DeepLinking extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _prepareSpecificInformation($transport = null)
5
+ {
6
+ if (null !== $this->_paymentSpecificInformation) {
7
+ return $this->_paymentSpecificInformation;
8
+ }
9
+
10
+ $data = array();
11
+
12
+ $transport = parent::_prepareSpecificInformation($transport);
13
+
14
+ return $transport->setData(array_merge($data, $transport->getData()));
15
+ }
16
+ }
app/code/community/Zapper/DeepLinking/Helper/Data.php ADDED
@@ -0,0 +1,3 @@
1
+ <?php
2
+ class Zapper_DeepLinking_Helper_Data extends Mage_Payment_Helper_Data {
3
+ }
app/code/community/Zapper/DeepLinking/Model/DeepLinking.php ADDED
@@ -0,0 +1,60 @@
1
+ <?php
2
+ class Zapper_DeepLinking_Model_DeepLinking extends Mage_Payment_Model_Method_Abstract
3
+ {
4
+ protected $_code = 'zapperdeeplinking';
5
+ protected $_formBlockType = 'deeplinking/form_deepLinking';
6
+ protected $_canCapture = true;
7
+
8
+ public function getOrderPlaceRedirectUrl()
9
+ {
10
+ return Mage::getUrl('zapperdeeplinking/processing/redirect', array('_secure' => false));
11
+ }
12
+
13
+ public function getMerchantID() {
14
+ return Mage::getStoreConfig('payment/zapperdeeplinking/merchant_id');
15
+ }
16
+
17
+ public function getSiteID() {
18
+ return Mage::getStoreConfig('payment/zapperdeeplinking/site_id');
19
+ }
20
+
21
+ public function getPosKey() {
22
+ return Mage::getStoreConfig('payment/zapperdeeplinking/pos_key');
23
+ }
24
+
25
+ public function getPosSecret() {
26
+ return Mage::getStoreConfig('payment/zapperdeeplinking/pos_secret');
27
+ }
28
+
29
+ public function getAppName() {
30
+ return Mage::getStoreConfig('payment/zapperdeeplinking/app_name');
31
+ }
32
+
33
+ public function getOrderStatus() {
34
+ return $this->getConfigData('order_status');
35
+ }
36
+
37
+ public function getOrderPlacedEmail() {
38
+ return $this->getConfigData('order_placed_email');
39
+ }
40
+
41
+ public function getOrderSuccessfulEmail() {
42
+ return $this->getConfigData('order_successful_email');
43
+ }
44
+
45
+ public function getOrderFailedEmail() {
46
+ return $this->getConfigData('order_failed_email');
47
+ }
48
+
49
+ public function getZapperUrl() {
50
+ // return "https://zapapi.zapzap.mobi/ecommerce/api/v2/";
51
+ return "https://zapqa.zapzapadmin.com/qa-zapperpointofsale/api/v2/";
52
+ }
53
+
54
+ public function getOrder() {
55
+ $order = Mage::getModel('sales/order');
56
+ $session = Mage::getSingleton('checkout/session');
57
+ $order->loadByIncrementId($session->getLastRealOrderId());
58
+ return $order;
59
+ }
60
+ }
app/code/community/Zapper/DeepLinking/controllers/ProcessingController.php ADDED
@@ -0,0 +1,118 @@
1
+ <?php
2
+ class Zapper_DeepLinking_ProcessingController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function testAction() {
5
+ $deeplinking = Mage::getModel('deeplinking/deeplinking');
6
+
7
+ $order = $deeplinking->getOrder();
8
+
9
+ $fields['merchantId'] = $deeplinking->getMerchantID();
10
+ $fields['siteId'] = $deeplinking->getSiteID();
11
+ $fields['amount'] = number_format($order->getGrandTotal(),2,'','');
12
+ $fields['amountType'] = 11; // read only
13
+ $fields['tip'] = 0; // not built into STQ yet
14
+ $fields['merchantReference'] = $order->getRealOrderId();
15
+ $fields['shortMerchantName'] = Mage::app()->getStore()->getName();
16
+ $fields['currencyISOCode'] = Mage::app()->getStore()->getBaseCurrencyCode(); // ZAR
17
+
18
+ $urlParams = urlencode("http://2.zap.pe?t=6&");
19
+ $urlParams .= "i=" . urlencode($fields['merchantId'] .":" . $fields['siteId'] . ":7[34|" . $fields['amount'] . "|" . $fields['amountType'] . ",66|" . $fields['merchantReference'] . "|10,60|1:10[38|" . $fields['shortMerchantName'] . ",39|" . $fields['currencyISOCode']);
20
+ $urlParams .= "&appName=" . urlencode($fields['appName']);
21
+ $urlParams .= "&successCallbackURL=" . urlencode(Mage::getBaseUrl() . "zapperdeeplinking/processing/success/");
22
+ $urlParams .= "&failureCallbackURL=" . urlencode(Mage::getBaseUrl() . "zapperdeeplinking/processing/failure/");
23
+
24
+ echo $urlParams;
25
+ }
26
+
27
+ public function setZapperIdAction() {
28
+ $zapperId = $this->getRequest()->getParam('id');
29
+ Mage::getSingleton('core/session')->setZapperId($zapperId);
30
+ echo Mage::getSingleton('core/session')->getZapperId();
31
+ }
32
+
33
+ public function redirectAction()
34
+ {
35
+ $deeplinking = Mage::getModel('deeplinking/deepLinking');
36
+ $order = $deeplinking->getOrder();
37
+
38
+ //Get Zapper payment Id
39
+ $zapperPaymentId = Mage::getSingleton('core/session')->getZapperId();
40
+ Mage::getSingleton('core/session')->setZapperId(0);
41
+ if ($zapperPaymentId == "") {
42
+ $this->_redirectUrl(Mage::getBaseUrl() . "zapperdeeplinking/processing/failure/");
43
+ }
44
+
45
+ $merchantId = $deeplinking->getMerchantID();
46
+ $siteId = $deeplinking->getSiteID();
47
+ $posKey = $deeplinking->getPosKey();
48
+ $posSecret = $deeplinking->getPosSecret();
49
+ $signature = $this->createSignature($posKey, $posSecret);
50
+
51
+ $url = $deeplinking->getZapperUrl() . '/merchants/' . $merchantId . '/sites/' . $siteId . '/payments/' . $zapperPaymentId;
52
+
53
+ $opts = array(
54
+ 'http'=>array(
55
+ 'method'=>"GET",
56
+ 'header'=>"SiteId: " . $siteId ."\r\n" .
57
+ "PosKey: " . $posKey . "\r\n" .
58
+ "Signature: " . $signature . "\r\n"
59
+ )
60
+ );
61
+
62
+ $context = stream_context_create($opts);
63
+
64
+ // Open the file using the HTTP headers set above
65
+ $file = file_get_contents($url, false, $context);
66
+
67
+ $zapperOrder = json_decode($file);
68
+
69
+ if ($zapperOrder->data == null || count($zapperOrder->data) == 0) {
70
+ // echo "failure";
71
+ $this->_redirectUrl(Mage::getBaseUrl() . "zapperdeeplinking/processing/failure/");
72
+ }
73
+
74
+ $zapperPayment = $zapperOrder->data[0];
75
+ $lastOrder = $deeplinking->getOrder();
76
+
77
+ if ($zapperPayment->ReceiptStatus == 2) {
78
+ $this->_redirectUrl(Mage::getBaseUrl() . "zapperdeeplinking/processing/success");
79
+ } else {
80
+ $this->_redirectUrl(Mage::getBaseUrl() . "zapperdeeplinking/processing/failure");
81
+ }
82
+ }
83
+
84
+ public function successAction()
85
+ {
86
+ $deeplinking = Mage::getModel('deeplinking/deepLinking');
87
+ $order = $deeplinking->getOrder();
88
+
89
+ $invoice = $order->prepareInvoice();
90
+ $invoice->register()->capture();
91
+ $order->addRelatedObject($invoice);
92
+ $email = ($deeplinking->getOrderSuccessfulEmail() ? true : false);
93
+ $order->addStatusToHistory(Mage_Sales_Model_Order::STATE_PROCESSING,'The user completed payment with the Zapper App',$email);
94
+ if ($email)
95
+ $deeplinking->sendPaymentSuccessfulEmail($order);
96
+
97
+ $order->save();
98
+
99
+ $this->_redirect('checkout/onepage/success', array('_secure'=> false));
100
+ }
101
+
102
+ public function failureAction()
103
+ {
104
+ $deeplinking = Mage::getModel('deeplinking/deepLinking');
105
+ $order = $deeplinking->getOrder();
106
+ $email = ($deeplinking->getOrderFailedEmail() ? true : false);
107
+ $order->addStatusToHistory(Mage_Sales_Model_Order::STATE_CANCELED,'The user failed to make payment with the Zapper App.',$email);
108
+ if ($email)
109
+ $deeplinking->sendPaymentFailedEmail($order);
110
+
111
+ $order->save();
112
+ $this->_redirect('checkout/onepage/failure', array('_secure'=> false));
113
+ }
114
+
115
+ private function createSignature($posKey, $posSecret) {
116
+ return hash('sha256', strtoupper($posSecret . '&' . $posKey));
117
+ }
118
+ }
app/code/community/Zapper/DeepLinking/etc/config.xml ADDED
@@ -0,0 +1,55 @@
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zapper_DeepLinking>
5
+ <version>0.0.1</version>
6
+ </Zapper_DeepLinking>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <deeplinking>
11
+ <class>Zapper_DeepLinking_Helper</class>
12
+ </deeplinking>
13
+ </helpers>
14
+ <blocks>
15
+ <deeplinking>
16
+ <class>Zapper_DeepLinking_Block</class>
17
+ </deeplinking>
18
+ </blocks>
19
+ <models>
20
+ <deeplinking>
21
+ <class>Zapper_DeepLinking_Model</class>
22
+ </deeplinking>
23
+ </models>
24
+ </global>
25
+ <frontend>
26
+ <layout>
27
+ <updates>
28
+ <deeplinking>
29
+ <file>zapper.xml</file>
30
+ </deeplinking>
31
+ </updates>
32
+ </layout>
33
+ <routers>
34
+ <deeplinking>
35
+ <use>standard</use>
36
+ <args>
37
+ <module>Zapper_DeepLinking</module>
38
+ <frontName>zapperdeeplinking</frontName>
39
+ </args>
40
+ </deeplinking>
41
+ </routers>
42
+ </frontend>
43
+ <default>
44
+ <payment>
45
+ <zapperdeeplinking>
46
+ <active>1</active>
47
+ <model>deeplinking/deepLinking</model>
48
+ <order_status>pending</order_status>
49
+ <title>Pay with Zapper</title>
50
+ <allowspecific>0</allowspecific>
51
+ <payment_action>sale</payment_action>
52
+ </zapperdeeplinking>
53
+ </payment>
54
+ </default>
55
+ </config>
app/code/community/Zapper/DeepLinking/etc/system.xml ADDED
@@ -0,0 +1,128 @@
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <zapperdeeplinking translate="label" module="deeplinking">
7
+ <label>Zapper Deep Linking</label>
8
+ <sort_order>650</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>1</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ </active>
22
+ <merchant_id translate="label">
23
+ <label>Merchant ID</label>
24
+ <frontend_type>text</frontend_type>
25
+ <validate>validate-number</validate>
26
+ <sort_order>10</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
+ <comment>Zapper Merchant ID. Ex: 1740</comment>
31
+ </merchant_id>
32
+ <site_id translate="label">
33
+ <label>Site ID</label>
34
+ <frontend_type>text</frontend_type>
35
+ <validate>validate-number</validate>
36
+ <sort_order>15</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <comment>Zapper Site ID. Ex: 1406</comment>
41
+ </site_id>
42
+ <pos_key translate="label">
43
+ <label>POS Key</label>
44
+ <frontend_type>text</frontend_type>
45
+ <sort_order>16</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>0</show_in_store>
49
+ <comment>Zapper POS Key. Ex: 12345678-1234-5678-1234-123456789012</comment>
50
+ </pos_key>
51
+ <pos_secret translate="label">
52
+ <label>POS Secret</label>
53
+ <frontend_type>text</frontend_type>
54
+ <sort_order>17</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ <comment>Zapper POS Secret. Ex: 12345678-1234-5678-1234-123456789012</comment>
59
+ </pos_secret>
60
+ <app_name translate="label">
61
+ <label>App Name</label>
62
+ <frontend_type>text</frontend_type>
63
+ <sort_order>18</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>1</show_in_store>
67
+ </app_name>
68
+ <sandbox translate="label">
69
+ <label>Sandbox</label>
70
+ <frontend_type>select</frontend_type>
71
+ <source_model>adminhtml/system_config_source_yesno</source_model>
72
+ <sort_order>20</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>0</show_in_store>
76
+ <comment>Put the system in Sandbox Mode.</comment>
77
+ </sandbox>
78
+ <title translate="label">
79
+ <label>Title</label>
80
+ <frontend_type>text</frontend_type>
81
+ <sort_order>25</sort_order>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>0</show_in_store>
85
+ <comment>The title of the payment method shown "Payment Information".</comment>
86
+ </title>
87
+ <order_status translate="label">
88
+ <label>New Order Status</label>
89
+ <frontend_type>select</frontend_type>
90
+ <source_model>adminhtml/system_config_source_order_status</source_model>
91
+ <sort_order>30</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>1</show_in_website>
94
+ <show_in_store>0</show_in_store>
95
+ </order_status>
96
+ <allowspecific translate="label">
97
+ <label>Payment from applicable countries</label>
98
+ <frontend_type>allowspecific</frontend_type>
99
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>1</show_in_website>
102
+ <show_in_store>1</show_in_store>
103
+ <sort_order>35</sort_order>
104
+ </allowspecific>
105
+ <specificcountry translate="label">
106
+ <label>Payment from Specific countries</label>
107
+ <frontend_type>multiselect</frontend_type>
108
+ <source_model>adminhtml/system_config_source_country</source_model>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>1</show_in_store>
112
+ <sort_order>40</sort_order>
113
+ </specificcountry>
114
+ <sort_order>
115
+ <label>Sort Order</label>
116
+ <frontend_type>text</frontend_type>
117
+ <validate>validate-number</validate>
118
+ <sort_order>50</sort_order>
119
+ <show_in_default>1</show_in_default>
120
+ <show_in_website>1</show_in_website>
121
+ <show_in_store>1</show_in_store>
122
+ </sort_order>
123
+ </fields>
124
+ </zapperdeeplinking>
125
+ </groups>
126
+ </payment>
127
+ </sections>
128
+ </config>
app/design/frontend/base/default/layout/zapper.xml ADDED
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+ <reference name="head">
5
+ <block type="core/text" name="zapper_script">
6
+ <action method="setText"><text><![CDATA[<script src="//qa-code.zapzapadmin.com/zapper.js"></script>]]></text></action>
7
+ </block>
8
+ </reference>
9
+ <reference name="head">
10
+ <action method="addJs">
11
+ <script>zapper_deeplinking/zapper-magento.js</script>
12
+ </action>
13
+ </reference>
14
+ </default>
15
+ </layout>
app/design/frontend/base/default/template/zapper_deeplinking/form/deeplinking.phtml ADDED
@@ -0,0 +1,17 @@
1
+ <div class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
2
+ <script type="text/javascript"></script>
3
+ <div id="zapper_magento_wrapper">
4
+ <?php echo $this->__('You will be redirected to the Zapper App when you place the order.') ?>
5
+ </div>
6
+ <?php
7
+ $lastOrderId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
8
+ // echo var_dump(Mage::getModel('sales/order')->loadByIncrementId($lastOrderId)->getId());
9
+ ?>
10
+ <input type="hidden" id="zapperMerchantId" value="<?php echo Mage::getStoreConfig('payment/zapperdeeplinking/merchant_id') ?>" />
11
+ <input type="hidden" id="zapperSiteId" value="<?php echo Mage::getStoreConfig('payment/zapperdeeplinking/site_id') ?>" />
12
+ <input type="hidden" id="zapperAmount" value="<?php echo Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() ?>" />
13
+ <input type="hidden" id="baseUrl" value="<?php echo Mage::getBaseUrl() ?>" />
14
+ </div>
15
+ <div>
16
+ <?php //echo $this->getMethod()->getConfigData('message');?>
17
+ </div>
app/etc/modules/Zapper_DeepLinking.xml ADDED
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zapper_DeepLinking>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+
8
+ <depends>
9
+ <Mage_Payment />
10
+ </depends>
11
+ </Zapper_DeepLinking>
12
+ </modules>
13
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Zapper</name>
4
+ <version>1.0.0</version>
5
+ <stability>beta</stability>
6
+ <license>MIT</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Allow customers to pay with Zapper on your website.</summary>
10
+ <description>Allow customers to pay with Zapper on your website.</description>
11
+ <notes>N/A</notes>
12
+ <authors><author><name>Zapper</name><user>Zapper</user><email>ecommercesupport@zapper.com</email></author></authors>
13
+ <date>2016-06-02</date>
14
+ <time>07:52:31</time>
15
+ <contents><target name="magecommunity"><dir name="Zapper"><dir name="DeepLinking"><dir name="Block"><dir name="Form"><file name="DeepLinking.php" hash="da6b5a26fce15c083e0f695f5d2bea7a"/></dir><dir name="Info"><file name="DeepLinking.php" hash="4ef983a2c691dace0a6cd7556acfbeb8"/></dir></dir><dir name="Helper"><file name="Data.php" hash="992d0c6f9fad5a36c786fe01b2c1f9a5"/></dir><dir name="Model"><file name="DeepLinking.php" hash="beedeb534c3e047b22bd53ccd31f9cf7"/></dir><dir name="controllers"><file name="ProcessingController.php" hash="8b2fd0c7a03d292f23ae976eefe001b6"/></dir><dir name="etc"><file name="config.xml" hash="91ca271e32c8bc5b16a51947bdf82361"/><file name="system.xml" hash="3285fbd8fb2a23dd1f9f2f94d55d4f92"/></dir><file name=".DS_Store" hash="4ec82e219c55ad9ad1a9b3f2c3763bf6"/></dir><file name=".DS_Store" hash="28727f5da84b0199c326d80fceb355bf"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="zapper.xml" hash="cdbb2eb5c2cb40b3e505b3a133944944"/></dir><dir name="template"><dir name="zapper_deeplinking"><dir name="form"><file name="deeplinking.phtml" hash="176d53097be7cd5863fe9155389c8223"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Zapper_DeepLinking.xml" hash="a9b0cafa2493148bd927f3081d0eec56"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>4.0.0</min><max>7.0.0</max></php></required></dependencies>
18
+ </package>