Faturah_Payment - Version 0.0.2

Version Notes

Faturah Payment Gateway first release 0.0.1

Download this release

Release Info

Developer Moe
Extension Faturah_Payment
Version 0.0.2
Comparing to
See all releases


Version 0.0.2

app/code/community/Faturah/Pay/Adminhtml/Model/System/Config/Source/Currencyoptions.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Faturah_Pay_Adminhtml_Model_System_Config_Source_Currencyoptions {
4
+ /* * */
5
+
6
+ /**
7
+ * Options getter
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray() {
12
+ return array(
13
+ array('value' => 'usd', 'label' => Mage::helper('adminhtml')->__('USD')),
14
+ array('value' => 'aed', 'label' => Mage::helper('adminhtml')->__('AED')),
15
+ array('value' => 'eur', 'label' => Mage::helper('adminhtml')->__('EUR')),
16
+ array('value' => 'egp', 'label' => Mage::helper('adminhtml')->__('EGP')),
17
+ array('value' => 'sar', 'label' => Mage::helper('adminhtml')->__('SAR')),
18
+ array('value' => 'kwd', 'label' => Mage::helper('adminhtml')->__('KWD')),
19
+ array('value' => 'syp', 'label' => Mage::helper('adminhtml')->__('SYP')),
20
+ );
21
+ }
22
+
23
+ }
app/code/community/Faturah/Pay/Adminhtml/Model/System/Config/Source/Languageoptions.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Faturah_Pay_Adminhtml_Model_System_Config_Source_Languageoptions {
4
+ /* * */
5
+
6
+ /**
7
+ * Options getter
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray() {
12
+ return array(
13
+ array('value' => 'en', 'label' => Mage::helper('adminhtml')->__('en')),
14
+ array('value' => 'ar', 'label' => Mage::helper('adminhtml')->__('ar')),
15
+ );
16
+ }
17
+
18
+ }
app/code/community/Faturah/Pay/Helper/Data.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Faturah_Pay_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ public function deleteallCartItems() {
6
+ $cartHelper = Mage::helper('checkout/cart');
7
+ $items = $cartHelper->getCart()->getItems();
8
+ foreach ($items as $item) {
9
+ $itemId = $item->getItemId();
10
+ $cartHelper->getCart()->removeItem($itemId)->save();
11
+ }
12
+ }
13
+
14
+ /**
15
+ * Translates the response code into a more meaningful description.
16
+ * Response code descriptions are taken directly from the MIGS documentation.
17
+ */
18
+ function getResponseCodeDescription($responseCode) {
19
+ switch ($responseCode) {
20
+ case "?" : $result = "Response Unknown";
21
+ break;
22
+ case "0" : $result = "Transaction Successful";
23
+ break;
24
+ case "1" : $result = "Transaction Declined - Bank Error";
25
+ break;
26
+ case "2" : $result = "Bank Declined Transaction";
27
+ break;
28
+ case "3" : $result = "Transaction Declined - No Reply from Bank";
29
+ break;
30
+ case "4" : $result = "Transaction Declined - Expired Card";
31
+ break;
32
+ case "5" : $result = "Transaction Declined - Insufficient funds";
33
+ break;
34
+ case "6" : $result = "Transaction Declined - Error Communicating with Bank";
35
+ break;
36
+ case "7" : $result = "Payment Server Processing Error - Typically caused by invalid input data such as an in valid credit card number. Processing errors can also occur";
37
+ break;
38
+ case "8" : $result = "Transaction Declined - Transaction Type Not Supported";
39
+ break;
40
+ case "9" : $result = "Bank Declined Transaction (Do not contact Bank)";
41
+ break;
42
+ case "A" : $result = "Transaction Aborted";
43
+ break;
44
+ case "B" : $result = "Transaction Declined - Contact the Bank";
45
+ break;
46
+ case "C" : $result = "Transaction Cancelled";
47
+ break;
48
+ case "D" : $result = "Deferred Transaction";
49
+ break;
50
+ case "E" : $result = "Issuer Returned a Referral Response";
51
+ break;
52
+ case "F" : $result = "3D Secure Authentication failed";
53
+ break;
54
+ case "I" : $result = "Card Security Code Failed";
55
+ break;
56
+ case "L" : $result = "Shopping Transaction Locked (This indicates that there is another transaction taking place using the same shopping transaction number) ";
57
+ break;
58
+ case "N" : $result = "Cardholder is not enrolled in 3D Secure (Authentication Only)";
59
+ break;
60
+ case "P" : $result = "Transaction is Pending";
61
+ break;
62
+ case "R" : $result = "Retry Limits Exceeded, Transaction Not Processed";
63
+ break;
64
+ case "S" : $result = "Duplicate OrderInfo used. (This is only relevant for Payment Servers that enforce the uniqueness of this field)";
65
+ break;
66
+ case "U" : $result = "Card Security Code Failed";
67
+ break;
68
+ default : $result = "Response Unknown";
69
+ }
70
+
71
+ return $result;
72
+ }
73
+
74
+ }
app/code/community/Faturah/Pay/Model/Pay.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Faturah_Pay_Model_Pay extends Mage_Payment_Model_Method_Abstract {
4
+
5
+ protected $_code = 'faturah';
6
+ protected $_isInitializeNeeded = true;
7
+ protected $_canUseInternal = true;
8
+ protected $_canUseForMultishipping = false;
9
+
10
+ public function getOrderPlaceRedirectUrl() {
11
+ return Mage::getUrl('faturah/payment', array('_secure' => true));
12
+ }
13
+
14
+ }
app/code/community/Faturah/Pay/Model/Service/Quote.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Faturah_Pay_Model_Service_Quote extends Mage_Sales_Model_Service_Quote {
4
+
5
+ public function submitOrder() {
6
+ $order = parent::submitOrder();
7
+
8
+ // Prevent the cart to be emptied before payment response
9
+ //$this->_quote->setIsActive(true);
10
+
11
+ return $order;
12
+ }
13
+
14
+ }
app/code/community/Faturah/Pay/controllers/PaymentController.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Faturah_Pay_PaymentController extends Mage_Core_Controller_Front_Action {
4
+
5
+ public function indexAction() {
6
+
7
+ $is_active = Mage::getStoreConfig('payment/faturah/active');
8
+ $merchant_code = Mage::getStoreConfig('payment/faturah/merchant_code');
9
+ $test_mode = Mage::getStoreConfig('payment/faturah/sandbox_mode');
10
+
11
+ $action_gateway = '';
12
+
13
+ //Post url
14
+ //https://Gateway.faturah.com/TransactionRequestHandler_Post.aspx
15
+
16
+ if (!$test_mode) {
17
+ //https://gateway.faturah.com/TransactionRequestHandler.aspx
18
+ $action_gateway = 'https://gateway.faturah.com/TransactionRequestHandler_Post.aspx';
19
+ } else {
20
+ //https://gatewaytest.faturah.com/TransactionRequestHandler.aspx
21
+ $action_gateway = 'https://gatewaytest.faturah.com/TransactionRequestHandler_Post.aspx';
22
+ }
23
+
24
+
25
+ //var_dump($merchant_code);
26
+
27
+ $client = new SoapClient('https://Services.faturah.com/TokenGeneratorWS.asmx?wsdl');
28
+
29
+ $faturahParams = array('GenerateNewMerchantToken' => array("merchantCode" => $merchant_code));
30
+
31
+ $result = $client->__soapCall('GenerateNewMerchantToken', $faturahParams);
32
+
33
+ $tokenGUID = $result->GenerateNewMerchantTokenResult;
34
+
35
+ //Loading current layout
36
+ $this->loadLayout();
37
+ //Creating a new block
38
+ $block = $this->getLayout()->createBlock(
39
+ 'Mage_Core_Block_Template', 'test_block_name', array('template' => 'faturah/pay/redirect.phtml')
40
+ )
41
+ ->setData('merchant_code', $merchant_code)
42
+ ->setData('tokenGUID', $tokenGUID)
43
+ ->setData('action_gateway', $action_gateway);
44
+
45
+ $this->getLayout()->getBlock('content')->append($block);
46
+
47
+ //Now showing it with rendering of layout
48
+ $this->renderLayout();
49
+ }
50
+
51
+ // The redirect action is triggered when someone places an order
52
+ public function payAction() {
53
+
54
+ $data = array();
55
+ if (!$this->getRequest()->isPost()) {
56
+
57
+ $data['error'] = 'method not allowed';
58
+ print json_encode($data);
59
+ return;
60
+ }
61
+ }
62
+
63
+ public function responseAction() {
64
+
65
+ /*
66
+ * $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
67
+ * $order->getGrandTotal();
68
+ *
69
+ * */
70
+
71
+ $error = false;
72
+ $status = "";
73
+
74
+
75
+
76
+
77
+ //$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
78
+ //$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
79
+
80
+ /*if (!$this->getRequest()->getParam('token')) {
81
+ $token = $this->getRequest()->getParam('token');
82
+ }*/
83
+
84
+ $token = $this->getRequest()->getParam('token');
85
+
86
+ $order = '';
87
+
88
+ $orders = Mage::getModel('sales/order')->getCollection()->load();
89
+ foreach($orders as $order) {
90
+ //var_dump($order->getPayment()->getAdditionalData());
91
+ //var_dump($order->getIncrementId());
92
+ if($order->getPayment()->getAdditionalData() === $token) {
93
+ $order = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());
94
+ break;
95
+ }
96
+ }
97
+
98
+ if(empty($token) || empty($order)) {
99
+
100
+
101
+ $response_text = 'Token or Order: not found';
102
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','faturah_payment_block',array('template' => 'faturah/pay/response.phtml'))->setData('response_text', $response_text);
103
+ //$this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
104
+ $this->loadLayout()->getLayout()->getBlock('content')->append($block);
105
+ $this->renderLayout();
106
+ return;
107
+
108
+
109
+ }
110
+
111
+ if ($this->getRequest()->getParam('Response') == "1")
112
+ {
113
+ if($this->getRequest()->getParam('ignore') == "0"){
114
+ switch($this->getRequest()->getParam("status"))
115
+ {
116
+ case '15': //**** Transaction is accepted by bank
117
+ case '30': //**** Transaction is approved/accepted by Faturah Team
118
+ $status = "approved";
119
+ $error = false;
120
+ /** trying to create invoice **/
121
+ try {
122
+ if(!$order->canInvoice()):
123
+ //Mage::throwException(Mage::helper('core')->__('cannot create invoice !'));
124
+ Mage::throwException(Mage::helper('core')->__('cannot create an invoice !'));
125
+ else:
126
+ /** create invoice **/
127
+ //$invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getIncremenetId(), array());
128
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
129
+
130
+ if(!$invoice->getTotalQty()):
131
+ Mage::throwException(Mage::helper('core')->__('cannot create an invoice without products !'));
132
+ endif;
133
+
134
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
135
+ $invoice->register();
136
+ $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
137
+ $transactionSave->save();
138
+
139
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Faturah Gateway has authorized the payment.');
140
+ /** load invoice **/
141
+ //$invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId);
142
+ /** pay invoice **/
143
+ //$invoice->capture()->save();
144
+ endif;
145
+ }
146
+ catch(Mage_Core_Exception $e){
147
+ Mage::throwException(Mage::helper('core')->__('cannot create an invoice !'));
148
+ }
149
+
150
+ $order->sendNewOrderEmail();
151
+ $order->setEmailSent(true);
152
+ $order->save();
153
+ break;
154
+ case '1': //**** Transaction is pending on bank processing
155
+ case '18': //**** Transaction is pending on Faturah Team for approval/acceptance
156
+ $error = false;
157
+ $status = "pending";
158
+ //die('Transaction Pending');
159
+ $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true, 'Transaction is pending on Faturah Team for approval/acceptance');
160
+ $order->sendNewOrderEmail();
161
+ $order->save();
162
+ break;
163
+ case '22': //**** Transaction is rejected
164
+ case '6': //**** Transaction is NOT approved/accepted by Faturah Team
165
+ $error = true;
166
+ $status = "rejected";
167
+ //$this->delete_order($order_id);
168
+ //die('Transaction Rejected -> order deleted');
169
+ // There is a problem in the response we got
170
+ $this->cancelAction($order);
171
+ break;
172
+ default:
173
+ die('Wrong Status');
174
+ break;
175
+ }
176
+
177
+ //if(in_array($this->request->get["status"], array(15, 30, 1, 18)))
178
+ /*if(in_array($this->getRequest()->getParam("status"), array(15, 30, 1, 18, 22, 6)))
179
+ {
180
+
181
+ }*/
182
+ //die();
183
+ }
184
+ else if($this->getRequest()->getParam('ignore') == "1"){
185
+ if(in_array($this->getRequest()->getParam("status"), array(15, 30, 1, 18)))
186
+ {
187
+
188
+ // transaction is under review
189
+ if(in_array($this->getRequest()->getParam("status"), array(1, 18))) {
190
+
191
+ // frontend transaction is under review
192
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','faturah_payment_block',array('template' => 'faturah/pay/response.phtml'))->setData('response_text', 'Your transaction is under review');
193
+ $this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
194
+ $this->loadLayout()->getLayout()->getBlock('content')->append($block);
195
+ $this->renderLayout();
196
+
197
+
198
+
199
+ } else {
200
+
201
+ // frontend success
202
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','faturah_payment_block',array('template' => 'faturah/pay/success.phtml'))->setData('order', $orderId);
203
+ $this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
204
+ $this->loadLayout()->getLayout()->getBlock('content')->append($block);
205
+ $this->renderLayout();
206
+
207
+
208
+ }
209
+
210
+
211
+ }
212
+ else
213
+ {
214
+ // frontend failure
215
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','faturah_payment_block',array('template' => 'faturah/pay/response.phtml'))->setData('response_text', 'Transaction is rejected');
216
+ $this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
217
+ $this->loadLayout()->getLayout()->getBlock('content')->append($block);
218
+ $this->renderLayout();
219
+ }
220
+
221
+
222
+ }
223
+
224
+ }
225
+ elseif($this->getRequest()->getParam('Response') == "0") {
226
+
227
+ $response_text = $this->getRequest()->getParam('ResponseText');
228
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','faturah_payment_block',array('template' => 'faturah/pay/response.phtml'))->setData('response_text', $response_text);
229
+ //$this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
230
+ $this->loadLayout()->getLayout()->getBlock('content')->append($block);
231
+ $this->renderLayout();
232
+ return;
233
+
234
+
235
+ }
236
+
237
+ else // error occured
238
+ {
239
+ // There is a problem in the response we got
240
+ $this->cancelAction();
241
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
242
+ }
243
+ }
244
+
245
+
246
+
247
+
248
+ // The cancel action is triggered when an order is to be cancelled
249
+ public function cancelAction($order) {
250
+ //if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
251
+ //if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
252
+ //$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
253
+ if ($order->getId()) {
254
+ // Flag the order as 'cancelled' and save it
255
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Gateway has declined the payment.')->save();
256
+ }
257
+ //}
258
+ }
259
+
260
+ public function successAction() {
261
+ /**/
262
+ }
263
+
264
+ public function testAction() {
265
+
266
+ /*$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
267
+ $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
268
+ var_dump($orderId);*/
269
+
270
+ /*
271
+ $orders = Mage::getModel('sales/order')->getCollection()->load();
272
+ foreach($orders as $order) {
273
+ var_dump($order->getPayment()->getAdditionalData());
274
+ var_dump($order->getIncrementId());
275
+ }
276
+ */
277
+ }
278
+
279
+ }
app/code/community/Faturah/Pay/etc/config.xml ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Faturah_Pay>
5
+ <version>0.0.2</version>
6
+ </Faturah_Pay>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <faturah>
11
+ <class>Faturah_Pay_Block</class>
12
+ </faturah>
13
+ </blocks>
14
+ <helpers>
15
+ <faturah>
16
+ <class>Faturah_Pay_Helper</class>
17
+ </faturah>
18
+ </helpers>
19
+ <models>
20
+ <faturah>
21
+ <class>Faturah_Pay_Model</class>
22
+ </faturah>
23
+ <faturah_adminhtml>
24
+ <class>Faturah_Pay_Adminhtml_Model</class>
25
+ </faturah_adminhtml>
26
+ <sales>
27
+ <rewrite>
28
+ <service_quote>Faturah_Pay_Model_Service_Quote</service_quote>
29
+ </rewrite>
30
+ </sales>
31
+ </models>
32
+ <resources>
33
+ <faturah_setup>
34
+ <setup>
35
+ <module>Faturah_Pay</module>
36
+ </setup>
37
+ <connection>
38
+ <use>core_setup</use>
39
+ </connection>
40
+ </faturah_setup>
41
+ <faturah_write>
42
+ <connection>
43
+ <use>core_write</use>
44
+ </connection>
45
+ </faturah_write>
46
+ <faturah_read>
47
+ <connection>
48
+ <use>core_read</use>
49
+ </connection>
50
+ </faturah_read>
51
+ </resources>
52
+ </global>
53
+ <default>
54
+ <payment>
55
+ <faturah>
56
+ <active>1</active>
57
+ <order_status>pending</order_status>
58
+ <model>faturah/pay</model>
59
+ <title>PayFaturah Payment Method</title>
60
+ <payment_action>sale</payment_action>
61
+ <allowspecific>0</allowspecific>
62
+ <sort_order>1</sort_order>
63
+ </faturah>
64
+ </payment>
65
+ </default>
66
+ <frontend>
67
+ <secure_url>
68
+ <pay>/faturah</pay>
69
+ </secure_url>
70
+ <routers>
71
+ <faturah>
72
+ <use>standard</use>
73
+ <args>
74
+ <module>Faturah_Pay</module>
75
+ <frontName>faturah</frontName>
76
+ </args>
77
+ </faturah>
78
+ </routers>
79
+ <layout>
80
+ <updates>
81
+ <faturah>
82
+ <file>faturah/faturah.xml</file>
83
+ </faturah>
84
+ </updates>
85
+ </layout>
86
+ </frontend>
87
+ </config>
app/code/community/Faturah/Pay/etc/system.xml ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <faturah translate="label" module="paygate">
7
+ <label>Faturah Payment Method</label>
8
+ <sort_order>670</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
+ <title translate="label">
23
+ <label>Title</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>2</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>0</show_in_store>
29
+ </title>
30
+
31
+ <!-- <currency translate="label">
32
+ <label>Currency</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>faturah_adminhtml/system_config_source_currencyoptions</source_model>
35
+ <sort_order>4</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
+ </currency> -->
40
+ <!-- <language translate="label">
41
+ <label>Language</label>
42
+ <frontend_type>select</frontend_type>
43
+ <source_model>faturah_adminhtml/system_config_source_languageoptions</source_model>
44
+ <sort_order>5</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>0</show_in_store>
48
+ </language> -->
49
+ <!--<display_text translate="label">
50
+ <label>Transaction Description</label>
51
+ <frontend_type>textarea</frontend_type>
52
+ <sort_order>6</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>0</show_in_store>
56
+ </display_text>-->
57
+
58
+ <merchant_code translate="label">
59
+ <label>Faturah merchant code</label>
60
+ <frontend_type>text</frontend_type>
61
+ <sort_order>8</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>0</show_in_store>
65
+ </merchant_code>
66
+
67
+ <sandbox_mode translate="label">
68
+ <label>Sandbox mode</label>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>adminhtml/system_config_source_yesno</source_model>
71
+ <sort_order>100</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>0</show_in_store>
75
+ </sandbox_mode>
76
+
77
+ <!--<return_url>
78
+ <label>Note : you need to specify your Return URL http://example.com/faturah/payment/response</label>
79
+ <frontend_type>label</frontend_type>
80
+ <sort_order>9</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>0</show_in_store>
84
+ </return_url>-->
85
+ </fields>
86
+ </faturah>
87
+ </groups>
88
+ </payment>
89
+ </sections>
90
+ </config>
app/design/frontend/base/default/template/faturah/pay/redirect.phtml ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $merchant_code = $this->getData('merchant_code');
3
+ $tokenGUID = $this->getData('tokenGUID');
4
+ $action_gateway = $this->getData('action_gateway');
5
+
6
+ // Retrieve order
7
+ $_order = Mage::getModel('sales/order');
8
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
9
+ $_order->loadByIncrementId($orderId);
10
+
11
+ // save generated token to the current order
12
+ $payment = $_order->getPayment();
13
+ $payment->setAdditionalData($tokenGUID)
14
+ ->save();
15
+
16
+ $_order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true, 'Order token: ' . $tokenGUID);
17
+
18
+ // $total = round($_order->getBaseGrandTotal(), 2);
19
+ // $shipping_amount = $_order->getShippingAmount();
20
+
21
+
22
+ // Convert currency to SAR
23
+ //$total = round(Mage::helper('directory')->currencyConvert($total, 'USD', 'SAR'), 2);
24
+ $shipping_amount = round(Mage::helper('directory')->currencyConvert($_order->getBaseShippingAmount(), 'USD', 'SAR'), 2);
25
+
26
+ //$baseSubtotal = $_order->getBaseGrandTotal() - $_order->getBaseShippingAmount();
27
+ $subtotal = round(Mage::helper('directory')->currencyConvert($_order->getBaseSubtotal(), 'USD', 'SAR'), 2);
28
+
29
+ // var_dump($_order->getBaseSubtotal());
30
+ // exit();
31
+
32
+ // testing amount
33
+ $test_mode = Mage::getStoreConfig('payment/faturah/sandbox_mode');
34
+ /*if($test_mode) {
35
+ $total = 1.00;
36
+ $shipping_amount = 0.00;
37
+ } else {
38
+ // Convert currency to SAR
39
+ $total = round(Mage::helper('directory')->currencyConvert($total, 'USD', 'SAR'), 2);
40
+ $shipping_amount = round(Mage::helper('directory')->currencyConvert($_order->getShippingAmount(), 'USD', 'SAR'), 2);
41
+ }*/
42
+
43
+
44
+ $items_name = array();
45
+ $items_description = array();
46
+ $items_qty = array();
47
+ $items_price = array();
48
+ $items_id = array();
49
+
50
+ $items = $_order->getAllItems();
51
+
52
+ foreach ($items as $item) {
53
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
54
+ $items_name[] = $product->getName();
55
+ $items_description[] = substr(htmlentities($product->getDescription()), 0, 50);
56
+ $items_qty[] = $item->getQtyOrdered();
57
+ /*if($test_mode) {
58
+ $items_price[] = round(1, 2);
59
+ } else {
60
+ $items_price[] = round(Mage::helper('directory')->currencyConvert(round($item->getPrice(), 2), 'USD', 'SAR'), 2);
61
+ }*/
62
+ // var_dump(round($item->getBasePrice()));
63
+ // exit();
64
+
65
+ $items_price[] = round(Mage::helper('directory')->currencyConvert(round($item->getBasePrice()), 'USD', 'SAR'), 2) . ' SR';
66
+ $items_id[] = $item->getProductId();
67
+ }
68
+
69
+ ?>
70
+
71
+
72
+ <form name="faturahpaymentform" action="<?php echo $action_gateway ?>" method="post">
73
+ <input type="hidden" name="mc" value="<?php echo $merchant_code ?>" />
74
+ <input type="hidden" name="mt" value="<?php echo $tokenGUID ?>" />
75
+ <input type="hidden" name="dt" value="<?php echo date('m/d/Y h:i:s A') ?>" />
76
+ <input type="hidden" name="a" value="<?php echo $subtotal ?>" />
77
+ <!--
78
+ <input type="hidden" name="DeliveryCharge" value="<?php echo $shipping_amount ?>" />
79
+ -->
80
+ <input type="hidden" name="DeliveryCharge" value="<?php echo $shipping_amount ?>" />
81
+ <input type="hidden" name="ProductID" value="<?php echo implode("|", $items_id) ?>" />
82
+ <input type="hidden" name="ProductName" value="<?php echo implode("|", $items_name) ?>" />
83
+ <input type="hidden" name="ProductQuantity" value="<?php echo implode("|", $items_qty) ?>" />
84
+ <input type="hidden" name="ProductDescription" value="<?php echo implode("|", $items_description) ?>" />
85
+ <input type="hidden" name="ProductPrice" value="<?php echo implode("|", $items_price) ?>" />
86
+ <input type="hidden" name="EMail" value="<?php echo $_order->getCustomerEmail() ?>" />
87
+ <input type="hidden" name="lang" value="en" />
88
+ </form>
89
+ <script type="text/javascript">
90
+ document.faturahpaymentform.submit();
91
+ </script>
92
+
app/design/frontend/base/default/template/faturah/pay/response.phtml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ $_order = new Mage_Sales_Model_Order();
4
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
5
+ $_order->loadByIncrementId($orderId);
6
+ */
7
+ //$orderId = $this->getOrder();
8
+
9
+ $response_text = $this->getData('response_text');
10
+
11
+ $home_url = Mage::helper('core/url')->getHomeUrl();
12
+
13
+ //$checkout_order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
14
+ //$current_order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
15
+
16
+ ?>
17
+ <?php if($this->helper('customer')->isLoggedIn()): ?>
18
+ <div class="col-main">
19
+ <div class="page-title">
20
+ <h1><?php echo $response_text ?></h1>
21
+ </div>
22
+ <h2 class="sub-title"><?php echo $response_text ?>!</h2>
23
+
24
+ </div>
25
+ <?php else: ?>
26
+ <div class="col-main">
27
+ <div class="page-title">
28
+ <h1><?php echo $response_text ?></h1>
29
+ </div>
30
+ <h2 class="sub-title"><?php echo $response_text ?>!</h2>
31
+ </div>
32
+ <?php endif; ?>
app/design/frontend/base/default/template/faturah/pay/success.phtml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ $_order = new Mage_Sales_Model_Order();
4
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
5
+ $_order->loadByIncrementId($orderId);
6
+ */
7
+ $orderId = $this->getOrder();
8
+ $home_url = Mage::helper('core/url')->getHomeUrl();
9
+
10
+ //$checkout_order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
11
+ $current_order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
12
+
13
+ ?>
14
+ <?php if($this->helper('customer')->isLoggedIn()): ?>
15
+ <div class="col-main">
16
+ <div class="page-title">
17
+ <h1>Your order has been received.</h1>
18
+ </div>
19
+ <h2 class="sub-title">Thank you for your purchase!</h2>
20
+ <p>Your order # is: <a href="<?php echo $home_url;?>sales/order/view/order_id/<?php echo $current_order->getId();?>"><?php echo $orderId;?></a>.</p>
21
+ <p>You will receive an order confirmation email with details of your order and a link to track its progress.</p>
22
+ <p>Click <a href="<?php echo $home_url;?>sales/order/print/order_id/<?php echo $current_order->getId();?>" onclick="this.target='_blank'">here to print</a> a copy of your order confirmation. </p>
23
+ <div class="buttons-set">
24
+ <button type="button" class="button" title="Continue Shopping" onclick="window.location='<?php echo $home_url;?>'"><span><span>Continue Shopping</span></span></button>
25
+ </div>
26
+ </div>
27
+ <?php else: ?>
28
+ <div class="col-main">
29
+ <div class="page-title">
30
+ <h1>Your order has been received.</h1>
31
+ </div>
32
+ <h2 class="sub-title">Thank you for your purchase!</h2>
33
+ <p>Your order # is: <?php echo $orderId;?>.</p>
34
+ <p>You will receive an order confirmation email with details of your order and a link to track its progress.</p>
35
+ <div class="buttons-set">
36
+ <button type="button" class="button" title="Continue Shopping" onclick="window.location='<?php echo $home_url;?>'"><span><span>Continue Shopping</span></span></button>
37
+ </div>
38
+ </div>
39
+ <?php endif; ?>
40
+
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Faturah_Payment</name>
4
+ <version>0.0.2</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension will allow your customers to use Faturah payment gateway.</summary>
10
+ <description>This extension adds (Faturah Payment Gateway) option to your store payment methods. Upon adding this extension to your store, your customers will be able to complete payment through Faturah Gateway. This extension is customizable as you can configure it to meet your needs. Additionally, it allows you to add the requirements settings for your Faturah merchant account.</description>
11
+ <notes>Faturah Payment Gateway first release 0.0.1 </notes>
12
+ <authors><author><name>Moe</name><user>Ghashim</user><email>moe@shopgo.me</email></author></authors>
13
+ <date>2013-12-17</date>
14
+ <time>09:01:11</time>
15
+ <contents><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="faturah"><dir name="pay"><file name="redirect.phtml" hash="deb26ac3190d5d8d3c78ef35ea462dfa"/><file name="response.phtml" hash="640ef81196fbb2497eb8eb76291cc49c"/><file name="success.phtml" hash="75d285b7fb8b9e84dbd517ac431de774"/></dir></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir name="Faturah"><dir name="Pay"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="Currencyoptions.php" hash="1f58ccf3f16e5a2938e60f8fdc872cec"/><file name="Languageoptions.php" hash="e2f2e44a0a6ea8bbf238a31546d64e13"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="PaymentController.php" hash="bd854027d56a066179e74674d59cfb08"/></dir><dir name="etc"><file name="config.xml" hash="ab5fb212f858c8b956fce4c9efc6d67d"/><file name="system.xml" hash="eddf406f2fbcb7b8b3398754143732cf"/></dir><dir name="Helper"><file name="Data.php" hash="7a515365e2c1405b2cc24a5ddff4ddd9"/></dir><dir name="Model"><file name="Pay.php" hash="261b4dd0e0bc462f35709751d9546d50"/><dir name="Service"><file name="Quote.php" hash="bb70e67729a46fd5cc432f1ed87b44ef"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>