Version Notes
- switch from SSL to TLS
Download this release
Release Info
Developer | ORBA |
Extension | Orba_Payupl |
Version | 0.3.0 |
Comparing to | |
See all releases |
Code changes from version 0.2.4 to 0.3.0
- app/code/community/Orba/Payupl/Helper/Data.php +42 -3
- app/code/community/Orba/Payupl/Model/Payment.php +177 -186
- app/code/community/Orba/Payupl/controllers/PaymentController.php +1 -1
- app/code/community/Orba/Payupl/etc/config.xml +1 -1
- app/code/community/Orba/Payupl/sql/payupl_setup/mysql4-install-0.3.0.php +26 -0
- app/code/community/Orba/Payupl/sql/payupl_setup/mysql4-upgrade-0.2.4-0.3.0.php +7 -0
- package.xml +5 -5
app/code/community/Orba/Payupl/Helper/Data.php
CHANGED
@@ -1,6 +1,45 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class Orba_Payupl_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
-
{
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
|
3 |
+
class Orba_Payupl_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
|
4 |
|
5 |
+
public function sendPost($url, $args = array()) {
|
6 |
+
return $this->sendRequest($url, $args, Zend_Http_Client::POST);
|
7 |
+
}
|
8 |
+
|
9 |
+
public function sendRequest($url, $args = array(), $method = Zend_Http_Client::GET) {
|
10 |
+
$client = new Zend_Http_Client($url);
|
11 |
+
$adapter = new Zend_Http_Client_Adapter_Curl();
|
12 |
+
$adapter->setConfig(array(
|
13 |
+
'curloptions' => array(
|
14 |
+
CURLOPT_SSLVERSION => 1,
|
15 |
+
CURLOPT_SSL_CIPHER_LIST => 'TLSv1',
|
16 |
+
CURLOPT_SSL_VERIFYHOST => 2,
|
17 |
+
CURLOPT_SSL_VERIFYPEER => false
|
18 |
+
)
|
19 |
+
));
|
20 |
+
$client->setAdapter($adapter);
|
21 |
+
if (!empty($args)) {
|
22 |
+
foreach ($args as $name => $value) {
|
23 |
+
$client->setParameterPost($name, $value);
|
24 |
+
}
|
25 |
+
}
|
26 |
+
try{
|
27 |
+
$response = $client->request($method);
|
28 |
+
if ($response->isSuccessful()) {
|
29 |
+
$headers = $response->getHeaders();
|
30 |
+
$gzipped = isset($headers['Content-encoding']) && $headers['Content-encoding'] === 'gzip';
|
31 |
+
return $gzipped ? $this->decodeGzip($response->getRawBody()) : $response->getRawBody();
|
32 |
+
} else {
|
33 |
+
Mage::log('Unable to send request to Payu: '.$response->getStatus(), null, 'payupl.log');
|
34 |
+
}
|
35 |
+
} catch (Exception $e) {
|
36 |
+
Mage::log('Unable to send request to Payu: '.$e->getMessage(), null, 'payupl.log');
|
37 |
+
}
|
38 |
+
return false;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function decodeGzip($data) {
|
42 |
+
return Zend_Http_Response::decodeGzip($data);
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
app/code/community/Orba/Payupl/Model/Payment.php
CHANGED
@@ -1,35 +1,31 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class Orba_Payupl_Model_Payment extends Mage_Payment_Model_Method_Abstract
|
4 |
-
|
5 |
-
|
6 |
-
protected $_code = 'payupl';
|
7 |
protected $_formBlockType = 'payupl/form';
|
8 |
-
protected $_isInitializeNeeded
|
9 |
-
protected $_canUseInternal
|
10 |
-
protected $_canUseForMultishipping
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
const
|
16 |
-
const
|
17 |
-
const
|
18 |
-
const
|
19 |
-
const
|
20 |
-
const
|
21 |
-
const
|
22 |
-
const PAYMENTSTATE_ERROR = '888';
|
23 |
-
|
24 |
const POLISH_ZLOTY_CODE = 'PLN';
|
25 |
-
|
26 |
-
|
27 |
* Get payupl session namespace
|
28 |
*
|
29 |
* @return Orba_Payupl_Model_Session
|
30 |
*/
|
31 |
-
public function getSession()
|
32 |
-
{
|
33 |
return Mage::getSingleton('payupl/session');
|
34 |
}
|
35 |
|
@@ -38,272 +34,267 @@ class Orba_Payupl_Model_Payment extends Mage_Payment_Model_Method_Abstract
|
|
38 |
*
|
39 |
* @return Mage_Checkout_Model_Session
|
40 |
*/
|
41 |
-
public function getCheckout()
|
42 |
-
{
|
43 |
return Mage::getSingleton('checkout/session');
|
44 |
}
|
45 |
-
|
46 |
-
public function getOrderPlaceRedirectUrl()
|
47 |
-
|
48 |
-
return Mage::getUrl('payupl/payment/new', array('_secure' => true));
|
49 |
}
|
50 |
-
|
51 |
/**
|
52 |
* Get current quote
|
53 |
*
|
54 |
* @return Mage_Sales_Model_Quote
|
55 |
*/
|
56 |
-
public function getQuote()
|
57 |
-
{
|
58 |
return $this->getCheckout()->getQuote();
|
59 |
}
|
60 |
-
|
61 |
-
public function getConfig()
|
62 |
-
|
63 |
-
return Mage::getModel('payupl/config');
|
64 |
}
|
65 |
-
|
66 |
private function getRedirectSig($data) {
|
67 |
$md5Key = $this->getConfig()->getMD5Key1();
|
68 |
$sig = md5(
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
);
|
86 |
return $sig;
|
87 |
}
|
88 |
-
|
89 |
-
public function getRedirectData($order)
|
90 |
-
|
91 |
-
$
|
92 |
-
$billing = $order->getBillingAddress();
|
93 |
$order_id = $order->getId();
|
94 |
$increment_order_id = $order->getRealOrderId();
|
95 |
$rData = array(
|
96 |
-
"pos_id"
|
97 |
"pos_auth_key" => $this->getConfig()->getPosAuthKey(),
|
98 |
-
"session_id"
|
99 |
-
"amount"
|
100 |
-
"desc"
|
101 |
-
"order_id"
|
102 |
-
"first_name"
|
103 |
-
"last_name"
|
104 |
-
"street"
|
105 |
-
"city"
|
106 |
-
"post_code"
|
107 |
-
"email"
|
108 |
-
"phone"
|
109 |
-
"client_ip"
|
110 |
-
"ts"
|
111 |
);
|
112 |
$rData['sig'] = $this->getRedirectSig($rData);
|
113 |
return $rData;
|
114 |
}
|
115 |
-
|
116 |
-
|
117 |
|
118 |
//process payment update
|
119 |
protected $_remotePaymentDataXML;
|
120 |
protected $_order;
|
121 |
|
122 |
-
public function processPaymentStateUpdate(array $request
|
123 |
try {
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
return false;
|
128 |
-
}
|
129 |
}
|
130 |
|
131 |
//remote payment info
|
132 |
-
$sessionId = (string)$this->_remotePaymentDataXML->trans[0]->session_id[0];
|
133 |
-
$remoteState = (string)$this->_remotePaymentDataXML->trans[0]->status[0];
|
134 |
-
$incrementOrderId = (string)$this->_remotePaymentDataXML->trans[0]->order_id[0];
|
135 |
|
136 |
//local payment and order infor
|
137 |
$this->_order = Mage::getModel('sales/order')->loadByIncrementId($incrementOrderId);
|
138 |
$lPayment = $this->_order->getPayment();
|
139 |
-
if($lPayment == null){
|
140 |
-
|
141 |
}
|
142 |
|
143 |
if (!($this->isOrderCompleted($this->_order))) {
|
144 |
$localState = $lPayment->getAdditionalInformation('payupl_state');
|
145 |
-
$this->_onPaymentStateChange($lPayment,(string)$remoteState, (string)$localState
|
146 |
}
|
147 |
return true;
|
148 |
} catch (Exception $e) {
|
149 |
Mage::logException($e);
|
150 |
-
}
|
151 |
return false;
|
152 |
}
|
153 |
-
|
154 |
/* get payment state */
|
155 |
-
protected function _postBack($data
|
156 |
-
{
|
157 |
if (is_array($data) && isset($data['pos_id']) && isset($data['session_id'])) {
|
158 |
-
$
|
159 |
-
|
|
|
|
|
|
|
160 |
$md5Key = $this->getConfig()->getMD5Key1();
|
161 |
-
$
|
162 |
-
$
|
163 |
-
|
164 |
-
$httpAdapter = new Zend_Http_Client($this->getConfig()->getGatewayUrl()."/UTF/Payment/get/xml");
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
$response = $httpAdapter->request('POST');
|
173 |
-
return simplexml_load_string ($response->getBody());
|
174 |
} catch (Exception $e) {
|
175 |
Mage::logException($e);
|
176 |
-
}
|
177 |
}
|
178 |
return false;
|
179 |
}
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
}
|
196 |
-
try{
|
197 |
$pmnt->setAdditionalInformation('payupl_state', $newState);
|
198 |
$pmnt->setAdditionalInformation('payupl_online', true);
|
199 |
$pmnt->save();
|
200 |
} catch (Exception $e) {
|
201 |
Mage::logException($e);
|
202 |
-
}
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
public function _processPaymentChangeNew($p) {
|
208 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
209 |
-
$t->setPreparedMessage('Nowa transakcja rozpoczęta. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_NEW.']')
|
210 |
-
|
211 |
}
|
212 |
-
|
213 |
public function _processPaymentChangeCanceled($p) {
|
214 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
215 |
|
216 |
-
$t->setPreparedMessage('Transakcja anulowana. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_CANCELED.']'
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
|
221 |
// notify customer
|
222 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja anulowana.', true)
|
223 |
-
|
224 |
-
|
225 |
}
|
226 |
-
|
227 |
public function _processPaymentChangeDenied($p) {
|
228 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
229 |
|
230 |
-
$t->setPreparedMessage('Transakcja odrzucona. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_DENIED.']'
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
|
236 |
// notify customer
|
237 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja odrzucona.', true)
|
238 |
-
|
239 |
-
|
240 |
}
|
241 |
-
|
242 |
public function _processPaymentChangeInProgress($p) {
|
243 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
244 |
|
245 |
-
$t->setPreparedMessage('Transakcja w trakcie realizacji. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_INPROGRSSS.']'
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
}
|
250 |
-
|
251 |
public function _processPaymentChangePending($p) {
|
252 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
253 |
|
254 |
-
$p->setPreparedMessage('Transakcja oczekuje na zatwierdzenie. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_PENDING.']'
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
}
|
259 |
-
|
260 |
public function _processPaymentChangeReversed($p) {
|
261 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
262 |
|
263 |
-
$t->setPreparedMessage('Transakcja zwrócona. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_REVERSED.']'
|
264 |
-
|
265 |
-
|
266 |
|
267 |
// notify customer
|
268 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja zwrócona.', true)
|
269 |
-
|
270 |
-
|
271 |
}
|
272 |
-
|
273 |
public function _processPaymentChangeCompleted($p) {
|
274 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
275 |
|
276 |
-
$t->setPreparedMessage('Transakcja zakończona pomyślnie. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_COMPLETED.']'
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
|
282 |
// notify customer
|
283 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Komunikat z Payu.pl: Transakcja zakończona pomyślnie.', true)
|
284 |
-
|
285 |
-
|
286 |
}
|
287 |
-
|
288 |
public function _processPaymentChangeError($p) {
|
289 |
-
$t = $p->setTransactionId((string)$this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
290 |
|
291 |
-
$p->setPreparedMessage('Transakcja błędna. ['.Orba_Payupl_Model_Payment::PAYMENTSTATE_ERROR.']'
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
|
296 |
// notify customer
|
297 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja błędna.')
|
298 |
-
|
299 |
-
|
300 |
}
|
301 |
-
|
302 |
public function isOrderCompleted($order) {
|
303 |
$status = $order->getStatus();
|
304 |
return in_array($status, array(Mage_Sales_Model_Order::STATE_CLOSED, Mage_Sales_Model_Order::STATE_CANCELED, Mage_Sales_Model_Order::STATE_COMPLETE));
|
305 |
}
|
306 |
-
|
307 |
protected function getOrderTotalInPolishCents($order) {
|
308 |
if ($order->getBaseCurrencyCode() == self::POLISH_ZLOTY_CODE) {
|
309 |
$total_pln = $order->getBaseGrandTotal();
|
@@ -315,5 +306,5 @@ class Orba_Payupl_Model_Payment extends Mage_Payment_Model_Method_Abstract
|
|
315 |
$rounded_pln = Mage::app()->getStore()->roundPrice($total_pln);
|
316 |
return $rounded_pln * 100;
|
317 |
}
|
318 |
-
|
319 |
}
|
1 |
<?php
|
2 |
|
3 |
+
class Orba_Payupl_Model_Payment extends Mage_Payment_Model_Method_Abstract {
|
4 |
+
|
5 |
+
protected $_code = 'payupl';
|
|
|
6 |
protected $_formBlockType = 'payupl/form';
|
7 |
+
protected $_isInitializeNeeded = true;
|
8 |
+
protected $_canUseInternal = false;
|
9 |
+
protected $_canUseForMultishipping = false;
|
10 |
+
|
11 |
+
/* payu.pl payment state */
|
12 |
+
|
13 |
+
const PAYMENTSTATE_NEW = '1';
|
14 |
+
const PAYMENTSTATE_CANCELED = '2';
|
15 |
+
const PAYMENTSTATE_DENIED = '3';
|
16 |
+
const PAYMENTSTATE_INPROGRSSS = '4';
|
17 |
+
const PAYMENTSTATE_PENDING = '5';
|
18 |
+
const PAYMENTSTATE_REVERSED = '7';
|
19 |
+
const PAYMENTSTATE_COMPLETED = '99';
|
20 |
+
const PAYMENTSTATE_ERROR = '888';
|
|
|
|
|
21 |
const POLISH_ZLOTY_CODE = 'PLN';
|
22 |
+
|
23 |
+
/**
|
24 |
* Get payupl session namespace
|
25 |
*
|
26 |
* @return Orba_Payupl_Model_Session
|
27 |
*/
|
28 |
+
public function getSession() {
|
|
|
29 |
return Mage::getSingleton('payupl/session');
|
30 |
}
|
31 |
|
34 |
*
|
35 |
* @return Mage_Checkout_Model_Session
|
36 |
*/
|
37 |
+
public function getCheckout() {
|
|
|
38 |
return Mage::getSingleton('checkout/session');
|
39 |
}
|
40 |
+
|
41 |
+
public function getOrderPlaceRedirectUrl() {
|
42 |
+
return Mage::getUrl('payupl/payment/new', array('_secure' => true));
|
|
|
43 |
}
|
44 |
+
|
45 |
/**
|
46 |
* Get current quote
|
47 |
*
|
48 |
* @return Mage_Sales_Model_Quote
|
49 |
*/
|
50 |
+
public function getQuote() {
|
|
|
51 |
return $this->getCheckout()->getQuote();
|
52 |
}
|
53 |
+
|
54 |
+
public function getConfig() {
|
55 |
+
return Mage::getModel('payupl/config');
|
|
|
56 |
}
|
57 |
+
|
58 |
private function getRedirectSig($data) {
|
59 |
$md5Key = $this->getConfig()->getMD5Key1();
|
60 |
$sig = md5(
|
61 |
+
$data['pos_id'] .
|
62 |
+
$data['session_id'] .
|
63 |
+
$data['pos_auth_key'] .
|
64 |
+
$data['amount'] .
|
65 |
+
$data['desc'] .
|
66 |
+
$data['order_id'] .
|
67 |
+
$data['first_name'] .
|
68 |
+
$data['last_name'] .
|
69 |
+
$data['street'] .
|
70 |
+
$data['city'] .
|
71 |
+
$data['post_code'] .
|
72 |
+
$data['email'] .
|
73 |
+
$data['phone'] .
|
74 |
+
$data['client_ip'] .
|
75 |
+
$data['ts'] .
|
76 |
+
$md5Key
|
77 |
);
|
78 |
return $sig;
|
79 |
}
|
80 |
+
|
81 |
+
public function getRedirectData($order) {
|
82 |
+
$payment = $order->getPayment();
|
83 |
+
$billing = $order->getBillingAddress();
|
|
|
84 |
$order_id = $order->getId();
|
85 |
$increment_order_id = $order->getRealOrderId();
|
86 |
$rData = array(
|
87 |
+
"pos_id" => $this->getConfig()->getPosId(),
|
88 |
"pos_auth_key" => $this->getConfig()->getPosAuthKey(),
|
89 |
+
"session_id" => $this->getSession()->getEncryptedSessionId() . '-' . $order_id,
|
90 |
+
"amount" => $this->getOrderTotalInPolishCents($order),
|
91 |
+
"desc" => Mage::helper('payupl')->__("Order no %s", $increment_order_id),
|
92 |
+
"order_id" => $increment_order_id,
|
93 |
+
"first_name" => $billing->getFirstname(),
|
94 |
+
"last_name" => $billing->getLastname(),
|
95 |
+
"street" => preg_replace("/\s/", " ", $billing->getStreetFull()),
|
96 |
+
"city" => $billing->getCity(),
|
97 |
+
"post_code" => $billing->getPostcode(),
|
98 |
+
"email" => $order->getCustomerEmail(),
|
99 |
+
"phone" => $billing->getTelephone(),
|
100 |
+
"client_ip" => $_SERVER['REMOTE_ADDR'],
|
101 |
+
"ts" => time() * rand(1, 10)
|
102 |
);
|
103 |
$rData['sig'] = $this->getRedirectSig($rData);
|
104 |
return $rData;
|
105 |
}
|
|
|
|
|
106 |
|
107 |
//process payment update
|
108 |
protected $_remotePaymentDataXML;
|
109 |
protected $_order;
|
110 |
|
111 |
+
public function processPaymentStateUpdate(array $request) {
|
112 |
try {
|
113 |
+
$this->_remotePaymentDataXML = $this->_postBack($request);
|
114 |
+
if (!$this->_remotePaymentDataXML) {
|
115 |
+
return false;
|
|
|
|
|
116 |
}
|
117 |
|
118 |
//remote payment info
|
119 |
+
$sessionId = (string) $this->_remotePaymentDataXML->trans[0]->session_id[0];
|
120 |
+
$remoteState = (string) $this->_remotePaymentDataXML->trans[0]->status[0];
|
121 |
+
$incrementOrderId = (string) $this->_remotePaymentDataXML->trans[0]->order_id[0];
|
122 |
|
123 |
//local payment and order infor
|
124 |
$this->_order = Mage::getModel('sales/order')->loadByIncrementId($incrementOrderId);
|
125 |
$lPayment = $this->_order->getPayment();
|
126 |
+
if ($lPayment == null) {
|
127 |
+
throw new Exception('No payment exists for given order. ' . $request['session_id']);
|
128 |
}
|
129 |
|
130 |
if (!($this->isOrderCompleted($this->_order))) {
|
131 |
$localState = $lPayment->getAdditionalInformation('payupl_state');
|
132 |
+
$this->_onPaymentStateChange($lPayment, (string) $remoteState, (string) $localState);
|
133 |
}
|
134 |
return true;
|
135 |
} catch (Exception $e) {
|
136 |
Mage::logException($e);
|
137 |
+
}
|
138 |
return false;
|
139 |
}
|
140 |
+
|
141 |
/* get payment state */
|
142 |
+
protected function _postBack($data) {
|
|
|
143 |
if (is_array($data) && isset($data['pos_id']) && isset($data['session_id'])) {
|
144 |
+
$args = array(
|
145 |
+
'pos_id' => $data['pos_id'],
|
146 |
+
'session_id' => $data['session_id'],
|
147 |
+
'ts' => now() * 1123
|
148 |
+
);
|
149 |
$md5Key = $this->getConfig()->getMD5Key1();
|
150 |
+
$args['sig'] = md5($args['pos_id'] . $args['session_id'] . $args['ts'] . $md5Key);
|
151 |
+
$url = $this->getConfig()->getGatewayUrl() . "/UTF/Payment/get/xml";
|
|
|
|
|
152 |
|
153 |
+
try {
|
154 |
+
$body = Mage::helper('payupl')->sendPost($url, $args);
|
155 |
+
if (!$body) {
|
156 |
+
throw new Exception('Cannot connect to ' . $url);
|
157 |
+
}
|
158 |
+
return new Varien_Simplexml_Element($body);
|
|
|
|
|
159 |
} catch (Exception $e) {
|
160 |
Mage::logException($e);
|
161 |
+
}
|
162 |
}
|
163 |
return false;
|
164 |
}
|
165 |
+
|
166 |
+
public function _onPaymentStateChange($pmnt, $newState, $oldState) {
|
167 |
+
if ($newState != $oldState) {
|
168 |
+
switch ($newState) {
|
169 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_NEW: $this->_processPaymentChangeNew($pmnt);
|
170 |
+
break;
|
171 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_CANCELED: $this->_processPaymentChangeCanceled($pmnt);
|
172 |
+
break;
|
173 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_DENIED: $this->_processPaymentChangeDenied($pmnt);
|
174 |
+
break;
|
175 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_INPROGRSSS: $this->_processPaymentChangeInProgress($pmnt);
|
176 |
+
break;
|
177 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_PENDING: $this->_processPaymentChangePending($pmnt);
|
178 |
+
break;
|
179 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_REVERSED: $this->_processPaymentChangeReversed($pmnt);
|
180 |
+
break;
|
181 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_COMPLETED: $this->_processPaymentChangeCompleted($pmnt);
|
182 |
+
break;
|
183 |
+
case Orba_Payupl_Model_Payment::PAYMENTSTATE_ERROR: $this->_processPaymenChangeError($pmnt);
|
184 |
+
break;
|
185 |
+
default: $this->_processPaymentChangeError($pmnt);
|
186 |
+
break;
|
187 |
}
|
188 |
+
try {
|
189 |
$pmnt->setAdditionalInformation('payupl_state', $newState);
|
190 |
$pmnt->setAdditionalInformation('payupl_online', true);
|
191 |
$pmnt->save();
|
192 |
} catch (Exception $e) {
|
193 |
Mage::logException($e);
|
194 |
+
}
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
|
|
198 |
public function _processPaymentChangeNew($p) {
|
199 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
200 |
+
$t->setPreparedMessage('Nowa transakcja rozpoczęta. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_NEW . ']')
|
201 |
+
->save();
|
202 |
}
|
203 |
+
|
204 |
public function _processPaymentChangeCanceled($p) {
|
205 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
206 |
|
207 |
+
$t->setPreparedMessage('Transakcja anulowana. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_CANCELED . ']')
|
208 |
+
->registerVoidNotification()
|
209 |
+
->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID)
|
210 |
+
->save();
|
211 |
|
212 |
// notify customer
|
213 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja anulowana.', true)
|
214 |
+
->sendOrderUpdateEmail()
|
215 |
+
->save();
|
216 |
}
|
217 |
+
|
218 |
public function _processPaymentChangeDenied($p) {
|
219 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
220 |
|
221 |
+
$t->setPreparedMessage('Transakcja odrzucona. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_DENIED . ']')
|
222 |
+
->setParentTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]) // this is the authorization transaction ID
|
223 |
+
->registerVoidNotification()
|
224 |
+
->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID)
|
225 |
+
->save();
|
226 |
|
227 |
// notify customer
|
228 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja odrzucona.', true)
|
229 |
+
->sendOrderUpdateEmail()
|
230 |
+
->save();
|
231 |
}
|
232 |
+
|
233 |
public function _processPaymentChangeInProgress($p) {
|
234 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
235 |
|
236 |
+
$t->setPreparedMessage('Transakcja w trakcie realizacji. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_INPROGRSSS . ']')
|
237 |
+
->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]) // this is the authorization transaction ID
|
238 |
+
->registerVoidNotification()
|
239 |
+
->save();
|
240 |
}
|
241 |
+
|
242 |
public function _processPaymentChangePending($p) {
|
243 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
244 |
|
245 |
+
$p->setPreparedMessage('Transakcja oczekuje na zatwierdzenie. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_PENDING . ']')
|
246 |
+
->setParentTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]) // this is the authorization transaction ID
|
247 |
+
->registerVoidNotification()
|
248 |
+
->save();
|
249 |
}
|
250 |
+
|
251 |
public function _processPaymentChangeReversed($p) {
|
252 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
253 |
|
254 |
+
$t->setPreparedMessage('Transakcja zwrócona. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_REVERSED . ']')
|
255 |
+
->registerVoidNotification()
|
256 |
+
->save();
|
257 |
|
258 |
// notify customer
|
259 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja zwrócona.', true)
|
260 |
+
->sendOrderUpdateEmail()
|
261 |
+
->save();
|
262 |
}
|
263 |
+
|
264 |
public function _processPaymentChangeCompleted($p) {
|
265 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
266 |
|
267 |
+
$t->setPreparedMessage('Transakcja zakończona pomyślnie. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_COMPLETED . ']')
|
268 |
+
->registerCaptureNotification($this->_remotePaymentDataXML->trans[0]->amount / 100)
|
269 |
+
->setIsTransactionApproved(true)
|
270 |
+
->setIsTransactionClosed(true)
|
271 |
+
->save();
|
272 |
|
273 |
// notify customer
|
274 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Komunikat z Payu.pl: Transakcja zakończona pomyślnie.', true)
|
275 |
+
->sendOrderUpdateEmail(true, 'Komunikat z Payu.pl: Transakcja zakończona pomyślnie.')
|
276 |
+
->save();
|
277 |
}
|
278 |
+
|
279 |
public function _processPaymentChangeError($p) {
|
280 |
+
$t = $p->setTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]);
|
281 |
|
282 |
+
$p->setPreparedMessage('Transakcja błędna. [' . Orba_Payupl_Model_Payment::PAYMENTSTATE_ERROR . ']')
|
283 |
+
->setParentTransactionId((string) $this->_remotePaymentDataXML->trans[0]->session_id[0]) // this is the authorization transaction ID
|
284 |
+
->registerVoidNotification()
|
285 |
+
->save();
|
286 |
|
287 |
// notify customer
|
288 |
$comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, 'Komunikat z Payu.pl: Transakcja błędna.')
|
289 |
+
->sendOrderUpdateEmail(true, 'Komunikat z Payu.pl: Transakcja błędna.')
|
290 |
+
->save();
|
291 |
}
|
292 |
+
|
293 |
public function isOrderCompleted($order) {
|
294 |
$status = $order->getStatus();
|
295 |
return in_array($status, array(Mage_Sales_Model_Order::STATE_CLOSED, Mage_Sales_Model_Order::STATE_CANCELED, Mage_Sales_Model_Order::STATE_COMPLETE));
|
296 |
}
|
297 |
+
|
298 |
protected function getOrderTotalInPolishCents($order) {
|
299 |
if ($order->getBaseCurrencyCode() == self::POLISH_ZLOTY_CODE) {
|
300 |
$total_pln = $order->getBaseGrandTotal();
|
306 |
$rounded_pln = Mage::app()->getStore()->roundPrice($total_pln);
|
307 |
return $rounded_pln * 100;
|
308 |
}
|
309 |
+
|
310 |
}
|
app/code/community/Orba/Payupl/controllers/PaymentController.php
CHANGED
@@ -62,7 +62,7 @@ class Orba_Payupl_PaymentController extends Mage_Core_Controller_Front_Action {
|
|
62 |
$this->loadLayout();
|
63 |
try {
|
64 |
$data = $this->getRequest()->getPost();
|
65 |
-
if (Mage::getModel('payupl/payment')->processPaymentStateUpdate($data
|
66 |
$this->getLayout()->getBlock('payupl_child')->setMessage('OK');
|
67 |
} else {
|
68 |
$error = true;
|
62 |
$this->loadLayout();
|
63 |
try {
|
64 |
$data = $this->getRequest()->getPost();
|
65 |
+
if (Mage::getModel('payupl/payment')->processPaymentStateUpdate($data)) {
|
66 |
$this->getLayout()->getBlock('payupl_child')->setMessage('OK');
|
67 |
} else {
|
68 |
$error = true;
|
app/code/community/Orba/Payupl/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Orba_Payupl>
|
5 |
-
<version>0.
|
6 |
</Orba_Payupl>
|
7 |
</modules>
|
8 |
<frontend>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Orba_Payupl>
|
5 |
+
<version>0.3.0</version>
|
6 |
</Orba_Payupl>
|
7 |
</modules>
|
8 |
<frontend>
|
app/code/community/Orba/Payupl/sql/payupl_setup/mysql4-install-0.3.0.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$this->startSetup();
|
4 |
+
|
5 |
+
$msg_title = "Moduł Orba Payu.pl został poprawnie zainstalowany! Ważne: Skonfiguruj system po stronie Payu.pl!";
|
6 |
+
$msg_desc = "Po stronie Payu.pl należy skonfigurować system w następujący sposób: <br />"
|
7 |
+
. "Adres powrotu błędnego: http://twojadomena.com/payupl/payment/error/sid/%sessionId%<br />"
|
8 |
+
. "Adres powrotu pozytywnego: http://twojadomena.com/payupl/payment/ok/sid/%sessionId%<br />"
|
9 |
+
. "Adres raportów: http://twojadomena.com/payupl/payment/online <br />"
|
10 |
+
. "Kodowanie przesyłanych danych: UTF-8 <br />"
|
11 |
+
. "W razie problemów prosimy o kontakt na adres e-mail magento@orba.pl.";
|
12 |
+
$url = "http://orba.pl/moduly-magento/payu-pl";
|
13 |
+
|
14 |
+
$message = Mage::getModel( 'adminnotification/inbox' );
|
15 |
+
$message->setDateAdded( date( "c", time() ) );
|
16 |
+
|
17 |
+
$message->setSeverity( Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE );
|
18 |
+
|
19 |
+
$message->setTitle( $msg_title );
|
20 |
+
$message->setDescription( $msg_desc );
|
21 |
+
$message->setUrl( $url );
|
22 |
+
$message->save();
|
23 |
+
|
24 |
+
@mail('magento@orba.pl', '[Instalacja] Payu.pl 0.3.0', "IP: ".$_SERVER['SERVER_ADDR']."\r\nHost: ".gethostbyaddr($_SERVER['SERVER_ADDR']), "From: ".(Mage::getStoreConfig('general/store_information/email_address') ? Mage::getStoreConfig('general/store_information/email_address') : 'magento@orba.pl'));
|
25 |
+
|
26 |
+
$this->endSetup();
|
app/code/community/Orba/Payupl/sql/payupl_setup/mysql4-upgrade-0.2.4-0.3.0.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$this->startSetup();
|
4 |
+
|
5 |
+
@mail('magento@orba.pl', '[Upgrade] Payu.pl 0.3.0', "IP: ".$_SERVER['SERVER_ADDR']."\r\nHost: ".gethostbyaddr($_SERVER['SERVER_ADDR']), "From: ".(Mage::getStoreConfig('general/store_information/email_address') ? Mage::getStoreConfig('general/store_information/email_address') : 'magento@orba.pl'));
|
6 |
+
|
7 |
+
$this->endSetup();
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Orba_Payupl</name>
|
4 |
-
<version>0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/academic.php">Academic Free License (AFL)</license>
|
7 |
<channel>community</channel>
|
@@ -14,11 +14,11 @@ If you are interested in the paid version of our extension with additional featu
|
|
14 |
Moduł dodaje do sklepu nowy sposób płatności, który daje klientom możliwość użycia serwisu Payu.pl do dokonania zapłaty za zakupy.
|
15 |
Istnieje możliwość integracji zarówno kont produkcyjnych jak i tych typu "sandbox".
|
16 |
Jeśli jesteś zainteresowany płatną wersją naszego modułu, który zawiera dodatkowe funkcjonalności oraz pomoc techniczą w cenie, wyślij do nas wiadomość e-mail na adres magento@orba.pl.</description>
|
17 |
-
<notes>-
|
18 |
<authors><author><name>ORBA</name><user>orba</user><email>magento@orba.pl</email></author></authors>
|
19 |
-
<date>
|
20 |
-
<time>
|
21 |
-
<contents><target name="magecommunity"><dir name="Orba"><dir name="Payupl"><dir name="Block"><file name="Form.php" hash="0dcab12715372a78f007a4abde209413"/><file name="Redirect.php" hash="1a1dfa1fdd2e4d7c22ea8a0c98772313"/></dir><dir name="Helper"><file name="Data.php" hash="
|
22 |
<compatible/>
|
23 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
24 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Orba_Payupl</name>
|
4 |
+
<version>0.3.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/academic.php">Academic Free License (AFL)</license>
|
7 |
<channel>community</channel>
|
14 |
Moduł dodaje do sklepu nowy sposób płatności, który daje klientom możliwość użycia serwisu Payu.pl do dokonania zapłaty za zakupy.
|
15 |
Istnieje możliwość integracji zarówno kont produkcyjnych jak i tych typu "sandbox".
|
16 |
Jeśli jesteś zainteresowany płatną wersją naszego modułu, który zawiera dodatkowe funkcjonalności oraz pomoc techniczą w cenie, wyślij do nas wiadomość e-mail na adres magento@orba.pl.</description>
|
17 |
+
<notes>- switch from SSL to TLS</notes>
|
18 |
<authors><author><name>ORBA</name><user>orba</user><email>magento@orba.pl</email></author></authors>
|
19 |
+
<date>2015-01-05</date>
|
20 |
+
<time>16:53:55</time>
|
21 |
+
<contents><target name="magecommunity"><dir name="Orba"><dir name="Payupl"><dir name="Block"><file name="Form.php" hash="0dcab12715372a78f007a4abde209413"/><file name="Redirect.php" hash="1a1dfa1fdd2e4d7c22ea8a0c98772313"/></dir><dir name="Helper"><file name="Data.php" hash="1b4c022fed446e5056098f061b5feb0c"/></dir><dir name="Model"><file name="Config.php" hash="3e933a833c5448bb641435a42a9aaa06"/><file name="Encoding.php" hash="54e9e22bd447dcf581c3b00c84f6d693"/><file name="Gateway.php" hash="10f12edec745c038a1d5b6d06180692c"/><file name="Payment.php" hash="85731d469d58c8962c2a9d979f2a6a07"/><file name="Session.php" hash="aad733c0d69beb14192e22415339343e"/></dir><dir name="controllers"><file name="IndexController.php" hash="2ee7e3bcd53c0eda0eb06f000cf23afb"/><file name="PaymentController.php" hash="6767eb564f270c20f364452aa3f87fb7"/></dir><dir name="etc"><file name="config.xml" hash="bf61cb8208c6ac32a44bc456de6e0760"/><file name="system.xml" hash="5f167eebe2529809465e654ffae869de"/></dir><dir name="sql"><dir name="payupl_setup"><file name="mysql4-install-0.1.0.php" hash="1c24d60e370bb07d601e02fcd1833c12"/><file name="mysql4-install-0.1.1.php" hash="8a734508ca8764fe397e8e98b2abda45"/><file name="mysql4-install-0.1.10.php" hash="59f3be8df67ac4eb1af1382b32f82d61"/><file name="mysql4-install-0.1.2.php" hash="212e958f7dcaca1209844703f1946b4e"/><file name="mysql4-install-0.1.3.php" hash="964592d00bb4cf8224ab5d2d73669d25"/><file name="mysql4-install-0.1.4.1.php" hash="0ad9b065639c15858c92dc443056d1c9"/><file name="mysql4-install-0.1.4.php" hash="0ad9b065639c15858c92dc443056d1c9"/><file name="mysql4-install-0.1.5.php" hash="af851501e249c0f711539724c129ef75"/><file name="mysql4-install-0.1.6.php" hash="86e34723c7192e7b3e63f9f6d6209140"/><file name="mysql4-install-0.1.7.php" hash="ef811c98a328f0c405435bb8d5baf2b3"/><file name="mysql4-install-0.1.8.php" hash="9f772cd5cbec3a46cd0b421ad482e965"/><file name="mysql4-install-0.1.9.php" hash="81a8706be704903850ed23ed63992b43"/><file name="mysql4-install-0.2.0.php" hash="008b767fc311dc1b4ac398a4fe3617da"/><file name="mysql4-install-0.2.1.php" hash="c84b836e0a171a74475c3e68419221c9"/><file name="mysql4-install-0.2.2.php" hash="acfff9b789376eeee001f1785def2156"/><file name="mysql4-install-0.3.0.php" hash="8383ea831bd6aac0393a709533b931b3"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="a5d9fc9d94f987f268c7b8246fcfd2b1"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="f1af4499aecb9280a23c73d98f860394"/><file name="mysql4-upgrade-0.1.10.1-0.2.0.php" hash="162f980728001e13b060b93d6b7007fd"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="6e517684413036f0420a48d8524a74e9"/><file name="mysql4-upgrade-0.1.3-0.1.4.1.php" hash="6a25a80a12e295abd83f4ce19a408c95"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="6a25a80a12e295abd83f4ce19a408c95"/><file name="mysql4-upgrade-0.1.4-0.1.5.php" hash="5a6e25ac859b99b1abbeeb8f71ca5acc"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="679f29891e5dfb59dff039926a58abf1"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="9673754430b1c8479b5f7472dfa85a0b"/><file name="mysql4-upgrade-0.1.7-0.1.8.php" hash="74939b2e76798c32b5c2893dccbbfa40"/><file name="mysql4-upgrade-0.1.8-0.1.9.php" hash="0d8819335f562e651c5b8ee4235a9cfb"/><file name="mysql4-upgrade-0.1.9-0.1.10.php" hash="24c14abbcaaeb35abee2535235d4c97d"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="47b9ce56d9cc39db3b17fa51033bce22"/><file name="mysql4-upgrade-0.2.1-0.2.2.php" hash="8ed509924a148aec16e761e352619d58"/><file name="mysql4-upgrade-0.2.2-0.2.3.php" hash="7344d966b7ebc86cef5dc94e715ef426"/><file name="mysql4-upgrade-0.2.3.1-0.2.4.php" hash="7a38b316c2745a076b0c870b648dddc6"/><file name="mysql4-upgrade-0.2.4-0.3.0.php" hash="e590f960ae315da9f18c0340bcec60d5"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="payupl.xml" hash="ee56ac84a7b72fdfaa0dbd4bc31a2fcc"/></dir><dir name="template"><dir name="payupl"><file name="empty.phtml" hash="ed465deabe832b50373acb983787dac7"/><file name="form.phtml" hash="1924fced96f1f107ce02d2636f4e3671"/><file name="online.phtml" hash="cf1636fb4cfeeec6bd6c17e7da07456e"/><file name="redirect.phtml" hash="e3c9e028dba4a49e410b5ed99cc3e0f0"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Orba_Payupl.xml" hash="59211173152eb267325c65e2498faa01"/></dir></target><target name="magelocale"><dir name="pl_PL"><file name="Orba_Payupl.csv" hash="1565e9dc326bdab05183454689f5a531"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="payupl"><file name="logo.jpg" hash="fc75365ea69655f8b9e3e66d75dc8362"/></dir></dir></dir></dir></dir></target></contents>
|
22 |
<compatible/>
|
23 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
24 |
</package>
|