Version Notes
Allows store owner to accept payments via Egopay.com.
Instant Callback to magento store.
Download this release
Release Info
Developer | Magento Core Team |
Extension | egopay |
Version | 1.0.0.0 |
Comparing to | |
See all releases |
Version 1.0.0.0
- app/code/community/Egopay/Egopay/Block/Form.php +11 -0
- app/code/community/Egopay/Egopay/Block/Info.php +9 -0
- app/code/community/Egopay/Egopay/Block/Redirect.php +31 -0
- app/code/community/Egopay/Egopay/Helper/Data.php +8 -0
- app/code/community/Egopay/Egopay/Lib/EgoPaySci.php +186 -0
- app/code/community/Egopay/Egopay/Model/Checkout.php +74 -0
- app/code/community/Egopay/Egopay/Model/Ipn.php +129 -0
- app/code/community/Egopay/Egopay/controllers/IpnController.php +19 -0
- app/code/community/Egopay/Egopay/controllers/RedirectController.php +44 -0
- app/code/community/Egopay/Egopay/etc/config.xml +99 -0
- app/code/community/Egopay/Egopay/etc/system.xml +71 -0
- app/design/adminhtml/default/default/template/egopay/form.phtml +3 -0
- app/design/adminhtml/default/default/template/egopay/info.phtml +5 -0
- app/design/frontend/default/default/template/egopay/form.phtml +3 -0
- app/design/frontend/default/default/template/egopay/info.phtml +5 -0
- app/etc/modules/Egopay_Egopay.xml +14 -0
- app/locale/en_US/Egopay_Egopay.csv +7 -0
- package.xml +32 -0
app/code/community/Egopay/Egopay/Block/Form.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Egopay_Egopay_Block_Form extends Mage_Payment_Block_Form
|
5 |
+
{
|
6 |
+
protected function _construct()
|
7 |
+
{
|
8 |
+
parent::_construct();
|
9 |
+
$this->setTemplate('egopay/form.phtml');
|
10 |
+
}
|
11 |
+
}
|
app/code/community/Egopay/Egopay/Block/Info.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Egopay_Egopay_Block_Info extends Mage_Payment_Block_Info {
|
4 |
+
|
5 |
+
protected function _construct() {
|
6 |
+
parent::_construct();
|
7 |
+
$this->setTemplate('egopay/info.phtml');
|
8 |
+
}
|
9 |
+
}
|
app/code/community/Egopay/Egopay/Block/Redirect.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Egopay_Egopay_Block_Redirect extends Mage_Core_Block_Abstract
|
5 |
+
{
|
6 |
+
protected function _toHtml()
|
7 |
+
{
|
8 |
+
$egopay = Mage::getModel('egopay/checkout');
|
9 |
+
|
10 |
+
$form = new Varien_Data_Form();
|
11 |
+
$form->setAction($egopay->getEgopayUrl())
|
12 |
+
->setId('pay')
|
13 |
+
->setName('pay')
|
14 |
+
->setMethod('POST')
|
15 |
+
->setUseContainer(true);
|
16 |
+
foreach ($egopay->getEgopayCheckoutFormFields() as $field=>$value) {
|
17 |
+
// echo $field.' - '.$value.'<br>';
|
18 |
+
$form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value));
|
19 |
+
}
|
20 |
+
|
21 |
+
$html = '<html><body>';
|
22 |
+
$html.= $this->__('Redirect to Egopay.com ...');
|
23 |
+
$html.= '<hr>';
|
24 |
+
$html.= $form->toHtml();
|
25 |
+
$html.= '<script type="text/javascript">document.getElementById("pay").submit();</script>';
|
26 |
+
$html.= '</body></html>';
|
27 |
+
|
28 |
+
|
29 |
+
return $html;
|
30 |
+
}
|
31 |
+
}
|
app/code/community/Egopay/Egopay/Helper/Data.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Egopay_Egopay_Helper_Data extends Mage_Core_Helper_Abstract
|
5 |
+
{
|
6 |
+
|
7 |
+
|
8 |
+
}
|
app/code/community/Egopay/Egopay/Lib/EgoPaySci.php
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* EgoPay Sci Class
|
5 |
+
*/
|
6 |
+
class EgoPaySci {
|
7 |
+
//User payment url
|
8 |
+
|
9 |
+
const EGOPAY_PAYMENT_URL = "https//www.egopay.com/api/pay";
|
10 |
+
|
11 |
+
//EgoPay Store ID
|
12 |
+
protected $store_id;
|
13 |
+
//EgoPay Store password
|
14 |
+
protected $store_password;
|
15 |
+
// Set these urls if you don't want use the ones you have in the website
|
16 |
+
//User gets redirected after success payment
|
17 |
+
protected $success_url;
|
18 |
+
//User gets redirected then he goes back without paying
|
19 |
+
protected $fail_url;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Constructor
|
23 |
+
* @param mixed $aParams - parametersthat initiate API object
|
24 |
+
* The available parameters are:
|
25 |
+
* Required:
|
26 |
+
* store_id - id of the store
|
27 |
+
* store_password - unique generated password for the store
|
28 |
+
* Optional:
|
29 |
+
* success_url - success callback url
|
30 |
+
* fail_url - failed callback url
|
31 |
+
*/
|
32 |
+
function __construct($aParams) {
|
33 |
+
//Required parameters
|
34 |
+
$aRequired = array('store_id', 'store_password');
|
35 |
+
$aOptional = array('success_url', 'fail_url');
|
36 |
+
|
37 |
+
foreach ($aRequired as $required)
|
38 |
+
if (!array_key_exists($required, $aParams) || !$aParams[$required])
|
39 |
+
throw new EgoPayException("This param is required - '$required'");
|
40 |
+
|
41 |
+
$aBoth = array_merge($aRequired, $aOptional);
|
42 |
+
foreach ($aBoth as $key)
|
43 |
+
if (array_key_exists($key, $aParams) && $aParams[$key])
|
44 |
+
$this->{$key} = $aParams[$key];
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Creates confirmation url
|
49 |
+
* @param type $aData - data that will be sent
|
50 |
+
* @return string - confirmation url
|
51 |
+
*/
|
52 |
+
public function getConfirmationUrl($aData) {
|
53 |
+
$sHash = $this->createHash($aData);
|
54 |
+
return self::EGOPAY_PAYMENT_URL . '/?hash=' . urlencode($sHash);
|
55 |
+
}
|
56 |
+
|
57 |
+
public function sendRequest($aData) {
|
58 |
+
$sUrl = $this->getConfirmationUrl($aData);
|
59 |
+
header('Location: ' . $sUrl);
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Creates encoded data hash
|
64 |
+
* @param type $aData
|
65 |
+
* @return type
|
66 |
+
*/
|
67 |
+
public function createHash($aData) {
|
68 |
+
$aRequired = array('amount', 'currency');
|
69 |
+
|
70 |
+
foreach ($aRequired as $required)
|
71 |
+
if (!array_key_exists($required, $aData) || !$aData[$required])
|
72 |
+
throw new EgoPayException("This param is required - '$required'");
|
73 |
+
|
74 |
+
if ($this->success_url)
|
75 |
+
$aData['success_url'] = $this->success_url;
|
76 |
+
if ($this->fail_url)
|
77 |
+
$aData['fail_url'] = $this->fail_url;
|
78 |
+
|
79 |
+
$sData = serialize($aData);
|
80 |
+
$sResult = $this->store_id . $this->encode($sData);
|
81 |
+
return $sResult;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Required for encoding
|
86 |
+
* @param type $string
|
87 |
+
* @return type
|
88 |
+
*/
|
89 |
+
protected function safe_b64encode($string) {
|
90 |
+
$data = base64_encode($string);
|
91 |
+
$data = str_replace(array('+', '/', '='), array('-', '_', ''), $data);
|
92 |
+
return $data;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Encodes given value
|
97 |
+
* @param type $value
|
98 |
+
* @return type
|
99 |
+
*/
|
100 |
+
protected function encode($data) {
|
101 |
+
if (!$data) {
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
|
105 |
+
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
|
106 |
+
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->store_password, $data, MCRYPT_MODE_ECB, $iv);
|
107 |
+
return trim($this->safe_b64encode($crypttext));
|
108 |
+
}
|
109 |
+
|
110 |
+
}
|
111 |
+
|
112 |
+
class EgoPaySciCallback {
|
113 |
+
|
114 |
+
//EgoPay Store ID
|
115 |
+
protected $store_id;
|
116 |
+
//EgoPay Store password
|
117 |
+
protected $store_password;
|
118 |
+
|
119 |
+
//Payment details url
|
120 |
+
|
121 |
+
const EGOPAY_REQUEST_URL = "https://www.egopay.com/api/request";
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Constructor
|
125 |
+
* @param mixed $aParams - parameters that initiate API object
|
126 |
+
* The available parameters are:
|
127 |
+
* Required:
|
128 |
+
* store_id - id of the store
|
129 |
+
* store_password - unique generated password for the store
|
130 |
+
*/
|
131 |
+
function __construct($aParams) {
|
132 |
+
//Required parameters
|
133 |
+
$aRequired = array('store_id', 'store_password');
|
134 |
+
|
135 |
+
foreach ($aRequired as $required)
|
136 |
+
if (!array_key_exists($required, $aParams) || !$aParams[$required])
|
137 |
+
throw new EgoPayException("This param is required - '$required'");
|
138 |
+
|
139 |
+
foreach ($aRequired as $key)
|
140 |
+
if (array_key_exists($key, $aParams) && $aParams[$key])
|
141 |
+
$this->{$key} = $aParams[$key];
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Sends response to the EgoPay server with data that was sent from EgoPay
|
146 |
+
* server
|
147 |
+
* @param type $aParams
|
148 |
+
* @return string response
|
149 |
+
*/
|
150 |
+
public function getResponse($aParams) {
|
151 |
+
if (!isset($aParams['product_id']))
|
152 |
+
throw new EgoPayException("This param is required - 'product_id'");
|
153 |
+
|
154 |
+
$ch = curl_init();
|
155 |
+
|
156 |
+
curl_setopt($ch, CURLOPT_URL, self::EGOPAY_REQUEST_URL);
|
157 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
158 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, "product_id=" . urlencode($aParams['product_id'])
|
159 |
+
. "&security_password=" . urlencode($this->store_password)
|
160 |
+
. "&store_id=" . urlencode($this->store_id)
|
161 |
+
);
|
162 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
163 |
+
curl_setopt($ch, CURLOPT_HEADER, false);
|
164 |
+
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
165 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
166 |
+
|
167 |
+
$response = curl_exec($ch);
|
168 |
+
|
169 |
+
curl_close($ch);
|
170 |
+
|
171 |
+
if ($response == 'INVALID')
|
172 |
+
throw new EgoPayException('Invalid Request To EgoPay');
|
173 |
+
|
174 |
+
$aResponse = array();
|
175 |
+
parse_str($response, $aResponse);
|
176 |
+
return $aResponse;
|
177 |
+
}
|
178 |
+
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* EgoPay Api Exception class
|
183 |
+
*/
|
184 |
+
class EgoPayException extends Exception {
|
185 |
+
|
186 |
+
}
|
app/code/community/Egopay/Egopay/Model/Checkout.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$ExternalLibPath = Mage::getModuleDir('', 'Egopay_Egopay') . DS . 'Lib' . DS . 'EgoPaySci.php';
|
4 |
+
require_once($ExternalLibPath);
|
5 |
+
|
6 |
+
class Egopay_Egopay_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
|
7 |
+
|
8 |
+
protected $_code = 'egopay';
|
9 |
+
protected $_formBlockType = 'egopay/form';
|
10 |
+
protected $_infoBlockType = 'egopay/info';
|
11 |
+
protected $_order;
|
12 |
+
|
13 |
+
const STORE_ID = 'payment/egopay/egopay_storeid';
|
14 |
+
const STORE_PASSWORD = 'payment/egopay/egopay_storepassword';
|
15 |
+
|
16 |
+
public function getCheckout() {
|
17 |
+
return Mage::getSingleton('checkout/session');
|
18 |
+
}
|
19 |
+
|
20 |
+
public function getOrderPlaceRedirectUrl() {
|
21 |
+
return Mage::getUrl('egopay/redirect', array('_secure' => true));
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getEgopayUrl() {
|
25 |
+
$url = 'https://www.egopay.com/api/pay';
|
26 |
+
return $url;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getLocale() {
|
30 |
+
return Mage::app()->getLocale()->getLocaleCode();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getEgopayCheckoutFormFields() {
|
34 |
+
|
35 |
+
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
|
36 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
|
37 |
+
if ($order->getBillingAddress()->getEmail()) {
|
38 |
+
$email = $order->getBillingAddress()->getEmail();
|
39 |
+
} else {
|
40 |
+
$email = $order->getCustomerEmail();
|
41 |
+
}
|
42 |
+
|
43 |
+
try {
|
44 |
+
$oEgopay = new EgoPaySci(array(
|
45 |
+
'store_id' => Mage::getStoreConfig(Egopay_Egopay_Model_Checkout::STORE_ID),
|
46 |
+
'store_password' => Mage::getStoreConfig(Egopay_Egopay_Model_Checkout::STORE_PASSWORD)
|
47 |
+
));
|
48 |
+
$aParams = $oEgopay->createHash(array(
|
49 |
+
'amount' => trim(round($order->getGrandTotal(), 2)),
|
50 |
+
'currency' => $order->getOrderCurrencyCode(),
|
51 |
+
'description' => 'Order id:' . $order_id,
|
52 |
+
'success_url' => Mage::getUrl('egopay/redirect/success', array('transaction_id' => $order_id)),
|
53 |
+
'fail_url' => Mage::getUrl('egopay/redirect/cancel', array('transaction_id' => $order_id)),
|
54 |
+
'callback_url' => Mage::getUrl('egopay/ipn'),
|
55 |
+
'cf_1' => $order_id
|
56 |
+
));
|
57 |
+
} catch (EgoPayException $e) {
|
58 |
+
die($e->getMessage());
|
59 |
+
}
|
60 |
+
|
61 |
+
$params = array(
|
62 |
+
'hash' => $aParams
|
63 |
+
);
|
64 |
+
return $params;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function initialize($paymentAction, $stateObject) {
|
68 |
+
$state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
|
69 |
+
$stateObject->setState($state);
|
70 |
+
$stateObject->setStatus('pending_payment');
|
71 |
+
$stateObject->setIsNotified(false);
|
72 |
+
}
|
73 |
+
|
74 |
+
}
|
app/code/community/Egopay/Egopay/Model/Ipn.php
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$ExternalLibPath = Mage::getModuleDir('', 'Egopay_Egopay') . DS . 'Lib' . DS . 'EgoPaySci.php';
|
4 |
+
require_once($ExternalLibPath);
|
5 |
+
|
6 |
+
class Egopay_Egopay_Model_Ipn {
|
7 |
+
|
8 |
+
const STORE_ID = 'payment/egopay/egopay_storeid';
|
9 |
+
const STORE_PASSWORD = 'payment/egopay/egopay_storepassword';
|
10 |
+
|
11 |
+
protected $_response = array();
|
12 |
+
protected $_error = array();
|
13 |
+
protected $_order = null;
|
14 |
+
|
15 |
+
public function getRequestData($key = null) {
|
16 |
+
if (null === $key) {
|
17 |
+
return $this->_response;
|
18 |
+
}
|
19 |
+
return isset($this->_response[$key]) ? $this->_response[$key] : null;
|
20 |
+
}
|
21 |
+
|
22 |
+
//checks if order exists and puts order into $_order
|
23 |
+
protected function _getOrder() {
|
24 |
+
$this->_order = Mage::getModel('sales/order')->loadByIncrementId($this->_response['cf_1']);
|
25 |
+
if (!empty($this->_order)) {
|
26 |
+
return true;
|
27 |
+
} else {
|
28 |
+
return false;
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
//checks if order details (currency and amount) are correct
|
33 |
+
protected function _verifyOrder() {
|
34 |
+
$OrderAmount = $this->_order->getGrandTotal();
|
35 |
+
$OrderCurrency = $this->_order->getOrderCurrencyCode();
|
36 |
+
if ($OrderAmount == $this->_response['fAmount']) {
|
37 |
+
if ($OrderCurrency == $this->_response['sCurrency']) {
|
38 |
+
return true;
|
39 |
+
} else {
|
40 |
+
return false;
|
41 |
+
}
|
42 |
+
} else {
|
43 |
+
return false;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
protected function _registerPaymentCanceled()
|
48 |
+
{
|
49 |
+
$comment = 'Payment has been canceled';
|
50 |
+
$this->_order->addStatusHistoryComment($comment, 'Canceled');
|
51 |
+
$this->_order->save();
|
52 |
+
}
|
53 |
+
|
54 |
+
protected function _registerPaymentPending()
|
55 |
+
{
|
56 |
+
$comment = 'Payment is pending';
|
57 |
+
$this->_order->addStatusHistoryComment($comment, 'Pending');
|
58 |
+
$this->_order->save();
|
59 |
+
}
|
60 |
+
|
61 |
+
protected function _registerPaymentOnHold()
|
62 |
+
{
|
63 |
+
$comment = 'Payment has been holded';
|
64 |
+
$this->_order->addStatusHistoryComment($comment, 'On Hold');
|
65 |
+
$this->_order->save();
|
66 |
+
}
|
67 |
+
|
68 |
+
//Checks if payment is completed (or test) or canceled
|
69 |
+
protected function _processOrder() {
|
70 |
+
$this->_order = null;
|
71 |
+
$this->_getOrder();
|
72 |
+
|
73 |
+
$paymentStatus = $this->_response['sStatus'];
|
74 |
+
switch ($paymentStatus) {
|
75 |
+
case 'Completed':
|
76 |
+
case 'TEST SUCCESS':
|
77 |
+
$this->_processOrderStatus();
|
78 |
+
break;
|
79 |
+
|
80 |
+
case 'Canceled':
|
81 |
+
$this->_registerPaymentCanceled();
|
82 |
+
break;
|
83 |
+
case 'On Hold':
|
84 |
+
$this->_registerPaymentOnHold();
|
85 |
+
break;
|
86 |
+
case 'Pending':
|
87 |
+
$this->_registerPaymentPending();
|
88 |
+
break;
|
89 |
+
|
90 |
+
default:
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
private function _processOrderStatus() {
|
95 |
+
$statusMessage = '';
|
96 |
+
$payment = $this->_order->getPayment();
|
97 |
+
$payment->setTransactionId($this->getRequestData('sId'))
|
98 |
+
->setPreparedMessage('Payment ' . $this->getRequestData('sId') . $this->getRequestData('sId'))
|
99 |
+
->setIsTransactionClosed(true)
|
100 |
+
->registerCaptureNotification($this->getRequestData('fAmount'));
|
101 |
+
$this->_order->save();
|
102 |
+
|
103 |
+
// notify customer
|
104 |
+
$invoice = $payment->getCreatedInvoice();
|
105 |
+
if ($invoice && !$this->_order->getEmailSent()) {
|
106 |
+
$this->_order->sendNewOrderEmail()->addStatusHistoryComment('Payment for order: ' . $this->getRequestData('cf_1') . 'received')
|
107 |
+
->setIsCustomerNotified(true)
|
108 |
+
->save();
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
public function processIpnRequest() {
|
113 |
+
try {
|
114 |
+
$EgoPay = new EgoPaySciCallback(array(
|
115 |
+
'store_id' => Mage::getStoreConfig(Egopay_Egopay_Model_Checkout::STORE_ID),
|
116 |
+
'store_password' => Mage::getStoreConfig(Egopay_Egopay_Model_Checkout::STORE_PASSWORD)
|
117 |
+
));
|
118 |
+
$this->_response = $EgoPay->getResponse($_POST);
|
119 |
+
} catch (EgoPayException $e) {
|
120 |
+
die($e->getMessage());
|
121 |
+
}
|
122 |
+
if ($this->_getOrder()) {
|
123 |
+
if ($this->_verifyOrder()) {
|
124 |
+
$this->_processOrder();
|
125 |
+
}
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
}
|
app/code/community/Egopay/Egopay/controllers/IpnController.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Egopay_Egopay_IpnController extends Mage_Core_Controller_Front_Action
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Instantiate IPN model and pass IPN request to it
|
7 |
+
*/
|
8 |
+
public function indexAction()
|
9 |
+
{
|
10 |
+
if (!$this->getRequest()->isPost()) {
|
11 |
+
return;
|
12 |
+
}
|
13 |
+
try {
|
14 |
+
Mage::getModel('egopay/ipn')->processIpnRequest();
|
15 |
+
} catch (Exception $e) {
|
16 |
+
Mage::logException($e);
|
17 |
+
}
|
18 |
+
}
|
19 |
+
}
|
app/code/community/Egopay/Egopay/controllers/RedirectController.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Egopay_Egopay_RedirectController extends Mage_Core_Controller_Front_Action {
|
4 |
+
|
5 |
+
protected $_order;
|
6 |
+
|
7 |
+
protected function _expireAjax() {
|
8 |
+
if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) {
|
9 |
+
$this->getResponse()->setHeader('HTTP/1.1', '403 Session Expired');
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
protected function _getCheckout() {
|
15 |
+
return Mage::getSingleton('checkout/session');
|
16 |
+
}
|
17 |
+
|
18 |
+
public function indexAction() {
|
19 |
+
$this->getResponse()
|
20 |
+
->setHeader('Content-type', 'text/html; charset=utf8')
|
21 |
+
->setBody($this->getLayout()
|
22 |
+
->createBlock('egopay/redirect')
|
23 |
+
->toHtml());
|
24 |
+
}
|
25 |
+
|
26 |
+
public function successAction() {
|
27 |
+
$event = $this->getRequest()->getParams();
|
28 |
+
$transaction_id = $event['transaction_id'];
|
29 |
+
$session = Mage::getSingleton('checkout/session');
|
30 |
+
$session->setQuoteId($transaction_id);
|
31 |
+
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
|
32 |
+
$this->_redirect('checkout/onepage/success', array('_secure' => true));
|
33 |
+
}
|
34 |
+
|
35 |
+
public function cancelAction() {
|
36 |
+
$event = $this->getRequest()->getParams();
|
37 |
+
$transaction_id = $event['transaction_id'];
|
38 |
+
$this->_getCheckout()->addError(Mage::helper('egopay')->__('The order has been canceled. Order #') . $transaction_id);
|
39 |
+
$this->_redirect('checkout/cart');
|
40 |
+
}
|
41 |
+
|
42 |
+
}
|
43 |
+
|
44 |
+
?>
|
app/code/community/Egopay/Egopay/etc/config.xml
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<modules>
|
5 |
+
<Egopay_Egopay>
|
6 |
+
<version>0.0.1</version>
|
7 |
+
</Egopay_Egopay>
|
8 |
+
</modules>
|
9 |
+
|
10 |
+
<global>
|
11 |
+
|
12 |
+
<models>
|
13 |
+
<egopay>
|
14 |
+
<class>Egopay_Egopay_Model</class>
|
15 |
+
</egopay>
|
16 |
+
</models>
|
17 |
+
|
18 |
+
<blocks>
|
19 |
+
<egopay>
|
20 |
+
<class>Egopay_Egopay_Block</class>
|
21 |
+
</egopay>
|
22 |
+
</blocks>
|
23 |
+
|
24 |
+
<resources>
|
25 |
+
<egopay_setup>
|
26 |
+
<setup>
|
27 |
+
<module>Egopay_Egopay</module>
|
28 |
+
</setup>
|
29 |
+
<connection>
|
30 |
+
<use>core_setup</use>
|
31 |
+
</connection>
|
32 |
+
</egopay_setup>
|
33 |
+
<egopay_write>
|
34 |
+
<connection>
|
35 |
+
<use>core_write</use>
|
36 |
+
</connection>
|
37 |
+
</egopay_write>
|
38 |
+
<egopay_read>
|
39 |
+
<connection>
|
40 |
+
<use>core_read</use>
|
41 |
+
</connection>
|
42 |
+
</egopay_read>
|
43 |
+
</resources>
|
44 |
+
<helpers>
|
45 |
+
<egopay>
|
46 |
+
<class>Egopay_Egopay_Helper</class>
|
47 |
+
</egopay>
|
48 |
+
</helpers>
|
49 |
+
</global>
|
50 |
+
|
51 |
+
|
52 |
+
<frontend>
|
53 |
+
<secure_url>
|
54 |
+
<egopay_redirect>/egopay/redirect/00</egopay_redirect>
|
55 |
+
</secure_url>
|
56 |
+
<routers>
|
57 |
+
<egopay>
|
58 |
+
<use>standard</use>
|
59 |
+
<args>
|
60 |
+
<module>Egopay_Egopay</module>
|
61 |
+
<frontName>egopay</frontName>
|
62 |
+
</args>
|
63 |
+
</egopay>
|
64 |
+
</routers>
|
65 |
+
<translate>
|
66 |
+
<modules>
|
67 |
+
<Egopay_Egopay>
|
68 |
+
<files>
|
69 |
+
<default>Egopay_Egopay.csv</default>
|
70 |
+
</files>
|
71 |
+
</Egopay_Egopay>
|
72 |
+
</modules>
|
73 |
+
</translate>
|
74 |
+
</frontend>
|
75 |
+
|
76 |
+
|
77 |
+
<adminhtml>
|
78 |
+
<translate>
|
79 |
+
<modules>
|
80 |
+
<Egopay_Egopay>
|
81 |
+
<files>
|
82 |
+
<default>Egopay_Egopay.csv</default>
|
83 |
+
</files>
|
84 |
+
</Egopay_Egopay>
|
85 |
+
</modules>
|
86 |
+
</translate>
|
87 |
+
</adminhtml>
|
88 |
+
|
89 |
+
<default>
|
90 |
+
<payment>
|
91 |
+
<egopay>
|
92 |
+
<active>0</active>
|
93 |
+
<model>egopay/checkout</model>
|
94 |
+
<title>Egopay.com</title>
|
95 |
+
<egopay_storeid>OK########</egopay_storeid>
|
96 |
+
</egopay>
|
97 |
+
</payment>
|
98 |
+
</default>
|
99 |
+
</config>
|
app/code/community/Egopay/Egopay/etc/system.xml
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<payment>
|
5 |
+
<groups>
|
6 |
+
<egopay translate="label" module="paygate">
|
7 |
+
<label>Egopay.com</label>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>1</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>1</show_in_website>
|
12 |
+
<show_in_store>0</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>1</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>2</sort_order>
|
27 |
+
<show_in_default>1</show_in_default>
|
28 |
+
<show_in_website>1</show_in_website>
|
29 |
+
<show_in_store>0</show_in_store>
|
30 |
+
</title>
|
31 |
+
<egopay_storeid translate="label,comment">
|
32 |
+
<label>Store ID</label>
|
33 |
+
<comment><![CDATA[ <a href="https://www.egopay.com" target="_blank"> Egopay.com </a>]]></comment>
|
34 |
+
<frontend_type>text</frontend_type>
|
35 |
+
<sort_order>3</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
<show_in_website>1</show_in_website>
|
38 |
+
<show_in_store>1</show_in_store>
|
39 |
+
</egopay_storeid>
|
40 |
+
<egopay_storepassword translate="label">
|
41 |
+
<label>Store PASSWORD</label>
|
42 |
+
<frontend_type>password</frontend_type>
|
43 |
+
<sort_order>4</sort_order>
|
44 |
+
<show_in_default>1</show_in_default>
|
45 |
+
<show_in_website>1</show_in_website>
|
46 |
+
<show_in_store>1</show_in_store>
|
47 |
+
</egopay_storepassword>
|
48 |
+
<allowspecific translate="label">
|
49 |
+
<label>Payment from applicable countries</label>
|
50 |
+
<frontend_type>allowspecific</frontend_type>
|
51 |
+
<sort_order>50</sort_order>
|
52 |
+
<source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
|
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 |
+
</allowspecific>
|
57 |
+
<specificcountry translate="label">
|
58 |
+
<label>Payment from Specific countries</label>
|
59 |
+
<frontend_type>multiselect</frontend_type>
|
60 |
+
<sort_order>51</sort_order>
|
61 |
+
<source_model>adminhtml/system_config_source_country</source_model>
|
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 |
+
</specificcountry>
|
66 |
+
</fields>
|
67 |
+
</egopay>
|
68 |
+
</groups>
|
69 |
+
</payment>
|
70 |
+
</sections>
|
71 |
+
</config>
|
app/design/adminhtml/default/default/template/egopay/form.phtml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo $this->__('When you place an order you will be redirected to').' <a href="https://www.egopay.com" target="_blank"> Egopay.com </a>'
|
3 |
+
?>
|
app/design/adminhtml/default/default/template/egopay/info.phtml
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo '<a href="https://www.egopay.com" target="_blank"> Egopay.com </a>';
|
3 |
+
?>
|
4 |
+
|
5 |
+
|
app/design/frontend/default/default/template/egopay/form.phtml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo $this->__('When you place an order you will be redirected to').' <a href="https://www.egopay.com" target="_blank"> Egopay.com </a>'
|
3 |
+
?>
|
app/design/frontend/default/default/template/egopay/info.phtml
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo '<a href="https://www.egopay.com" target="_blank"> Egopay.com </a>';
|
3 |
+
?>
|
4 |
+
|
5 |
+
|
app/etc/modules/Egopay_Egopay.xml
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Egopay_Egopay>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<depends>
|
8 |
+
<Mage_Paygate/>
|
9 |
+
<Mage_Checkout/>
|
10 |
+
<Mage_Sales/>
|
11 |
+
</depends>
|
12 |
+
</Egopay_Egopay>
|
13 |
+
</modules>
|
14 |
+
</config>
|
app/locale/en_US/Egopay_Egopay.csv
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Payment for order #","Payment for order #"
|
2 |
+
"The order has been canceled. Order #",The order has been canceled. Order #"
|
3 |
+
"Redirect to Egopay.com ...","Redirect to Egopay.com ..."
|
4 |
+
"Store Id","Store Id"
|
5 |
+
"Store Password","Store Password"
|
6 |
+
"payments","payments"
|
7 |
+
"When you place an order you will be redirected to","When you place an order you will be redirected to"
|
package.xml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>egopay</name>
|
4 |
+
<version>1.0.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Accepts payments via Egopay.com</summary>
|
10 |
+
<description>Egopay FREE payments module
|
11 |
+

|
12 |
+
Flexible depositing and withdrawal options
|
13 |
+
Transfer money to any Egopay.com user using their email
|
14 |
+
Easily exchange different e-currencies
|
15 |
+
Make regular payments over the Internet
|
16 |
+
Accepts USD, EUR currencies
|
17 |
+

|
18 |
+
Main features:
|
19 |
+
Easily receive payments to Your Egopay.com wallet (merchant's only)
|
20 |
+
Customers can pay from their Egopay.com accounts
|
21 |
+
Instant notification to your callback url when a payment is made
|
22 |
+
Adds order history and updates order status if payment has been cancelled, suspended or on hold
|
23 |
+
Customers will be redirected to Egopay.com if they choose to pay via Egopay.com</description>
|
24 |
+
<notes>Allows store owner to accept payments via Egopay.com.
|
25 |
+
Instant Callback to magento store.</notes>
|
26 |
+
<authors><author><name>Egopay</name><user>auto-converted</user><email>info@egopay.com</email></author></authors>
|
27 |
+
<date>2012-12-17</date>
|
28 |
+
<time>09:50:40</time>
|
29 |
+
<contents><target name="magecommunity"><dir name="Egopay"><dir name="Egopay"><dir name="Block"><file name="Form.php" hash="97e6eecf58006d788be3f293e74ec5ee"/><file name="Info.php" hash="149fa8700234afef00e75a7e0cfbe379"/><file name="Redirect.php" hash="58c04dd146829fb64e79f29d2d98b08e"/></dir><dir name="Helper"><file name="Data.php" hash="8d39231d593a14bcba2636a5cff26e7e"/></dir><dir name="Lib"><file name="EgoPaySci.php" hash="0496ecdbc6242338df22c44c465b15be"/></dir><dir name="Model"><file name="Checkout.php" hash="83b07df97d6dc9d06e4f2db26f36a054"/><file name="Ipn.php" hash="d345ab6ff3298cc46717dba18955b452"/></dir><dir name="controllers"><file name="IpnController.php" hash="3e20a69a3876b548fa95194297c2b880"/><file name="RedirectController.php" hash="29734c13228bcf65cb53fd2fb26a7495"/></dir><dir name="etc"><file name="config.xml" hash="7b4c396814d6a397a7c45edd37e1f05b"/><file name="system.xml" hash="6e982b6f0332b2d15e8efbd38e152369"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="egopay"><file name="form.phtml" hash="5992a4794316970180f69e69215f852c"/><file name="info.phtml" hash="f66f2d697305aa268f0bd7103731f9ae"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="egopay"><file name="form.phtml" hash="5992a4794316970180f69e69215f852c"/><file name="info.phtml" hash="f66f2d697305aa268f0bd7103731f9ae"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Egopay_Egopay.csv" hash="0342d15b57bd718598ec7800b41d831d"/></dir></target><target name="mageetc"><dir name="modules"><file name="Egopay_Egopay.xml" hash="030e5f7e6b78e2fa424a01f3d51370bc"/></dir></target></contents>
|
30 |
+
<compatible/>
|
31 |
+
<dependencies><required><package><name>Mage_core_modules</name><channel>community</channel><min>1.4.0.0</min><max>1.7</max></package></required></dependencies>
|
32 |
+
</package>
|