41 removals
27 additions
1.<?php1.<?php
2.2.
3.class Platnosci_Cashbill_CashbillController extends Mage_Core_Controller_Front_Action {3.class Platnosci_Cashbill_CashbillController extends Mage_Core_Controller_Front_Action {
4.4.
5. public function redirectAction() {5. public function redirectAction() {
6. $session = Mage::getSingleton('checkout/session');6. $session = Mage::getSingleton('checkout/session');
7. 7.
8. $session->setCashbillQuoteId($session->getQuoteId());8. $session->setCashbillQuoteId($session->getQuoteId());
9.9.
10. $this->getResponse()->setBody($this->getLayout()->createBlock('cashbill/payment_cashbill_redirect')->toHtml());10. $this->getResponse()->setBody($this->getLayout()->createBlock('cashbill/payment_cashbill_redirect')->toHtml());
11. $session->unsQuoteId();11. $session->unsQuoteId();
12. }12. }
13.
14.13.
15.
16.
17. public function returnAction() {14. public function returnAction() {
18. // Dane punktu otrzymane po zakonczeniu procesu rejestracji15. // Dane punktu otrzymane po zakonczeniu procesu rejestracji
19. $service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');16. $service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');
20. $key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');17. $key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');
21. // Funkcja sprawdzajaca poprawnosc sygnatury18. // Funkcja sprawdzajaca poprawnosc sygnatury
22. $data = $_GET;19. $data = $_GET;
23. 20.
24. if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_GET['sign'] )21. if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_GET['sign'] )
25. {$test = 1;}else{$test = 2;}22. {
23. $test = 1;
24. }else{
25. $test = 2;
26. }
26.27.
27. $params = array('n' => $data['userdata'], 'amount' => $data['amount']);28. $params = array('n' => $data['userdata'], 'amount' => $data['amount']);
28. if( $test == 1 && $_GET['service'] == $service)29. if( $test == 1 && $_GET['service'] == $service)
29. {30. {
30. // prawidlowa sygnatura, w zaleznosci od statusu odpowiednia informacja dla klienta31. // prawidlowa sygnatura, w zaleznosci od statusu odpowiednia informacja dla klienta
31. if( strtoupper($_GET['status']) == 'OK' ) {32. if( strtoupper($_GET['status']) == 'OK' ) {
32. $this->_redirect('cashbill/cashbill/success/', $params);33. $this->success($data['userdata'],$data['amount']);
33. }else {34. }else {
34. $this->_redirect('cashbill/cashbill/failure', $params);35. $this->failure($data['userdata'],$data['amount']);
35. }36. }
36. }else {37. }else {
37. $session = Mage::getSingleton('checkout/session');38. $session = Mage::getSingleton('checkout/session');
38. $session->setQuoteId($session->getCashbillQuoteId(true));39. $session->setQuoteId($session->getCashbillQuoteId(true));
39. $session->addError("wystąpił inny błąd. zgłoś to administratora sklepu.");40. $session->addError("wystąpił inny błąd. zgłoś to administratora sklepu.");
40. $this->_redirect('checkout/cart');41. $this->_redirect('checkout/cart');
41. }42. }
42. }43. }
43. 44.
44.
45. public function serwerAction() {45. public function serwerAction() {
46. // Dane punktu otrzymane po zakonczeniu procesu rejestracji46. // Dane punktu otrzymane po zakonczeniu procesu rejestracji
47. $service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');47. $service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');
48. $key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');48. $key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');
49. // Funkcja sprawdzajaca poprawnosc sygnatury49. // Funkcja sprawdzajaca poprawnosc sygnatury
50. $data = $_POST;50. $data = $_POST;
51. 51.
52. if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_POST['sign'] )52. if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_POST['sign'] )
53. {$test = 1;}else{$test = 2;}53. {$test = 1;}else{$test = 2;}
54. 54.
55. $params = array( 'n' => $data['userdata'],'amount'=>$data['amount']);55. $params = array( 'n' => $data['userdata'],'amount'=>$data['amount']);
56. if( $test == 1 && $_POST['service'] == $service)56. if( $test == 1 && $_POST['service'] == $service)
57. {57. {
58. if( strtoupper($_POST['status']) == 'OK' ) {58. if( strtoupper($_POST['status']) == 'OK' ) {
59. $this->_redirect('cashbill/cashbill/hsuccess/', $params);59. $this->hsuccess($data['userdata'],$data['amount']);
60. }60. }
61. else {61. else {
62. $this->_redirect('cashbill/cashbill/herror/', $params);62. $this->herror($data['userdata'],$data['amount']);
63. }63. }
64. }64. }
65. else {65. else {
66. echo 'BLAD SYGNATURY';66. echo 'BLAD SYGNATURY';
67. }67. }
68. }68. }
69. 69.
70. 70. private function hsuccess($order_id,$amount) {
71.
72. public function hsuccessAction() {
73. $order_id = $this->getRequest()->getParam('n');
74.
75. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);71. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
76. 72.
77. if($order->canInvoice()) {73. if($order->canInvoice()) {
78. $order->sendNewOrderEmail();74. $order->sendNewOrderEmail();
79. $order->addStatusHistoryComment ("Płatność w kwocie ".$this->getRequest()->getParam('amount')." zł została przyjęta przez CashBill.pl", Mage::getStoreConfig('payment/platnosci_cashbill/complete_order_status'));75. $order->addStatusHistoryComment ("Płatność w kwocie ".$amount." zł została przyjęta przez CashBill.pl", Mage::getStoreConfig('payment/platnosci_cashbill/complete_order_status'));
80. $order->save();76. $order->save();
81. }77. }
82. 78.
83. $session = Mage::getSingleton('checkout/session');79. $session = Mage::getSingleton('checkout/session');
84. $session->setQuoteId($session->getCashbillQuoteId(true));80. $session->setQuoteId($session->getCashbillQuoteId(true));
85.81.
86. Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();82. Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
87. 83.
88. echo 'OK';84. echo 'OK';
89. }85. }
90. 86.
91. public function herrorAction()87. private function herror($order_id,$amount) {
92. {
93. $order_id = $this->getRequest()->getParam('n');
94. 88.
95. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);89. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
96. 90.
97. if(!$order->getId()) { return FALSE; }91. if(!$order->getId()) { return FALSE; }
98. 92.
99. $order->cancel();93. $order->cancel();
100. $order->save();94. $order->save();
101. 95.
102. echo 'OK';96. echo 'OK';
103. }97. }
104. 98.
105.99. private function success($order_id,$amount) {
106.
107.
108.
109. public function successAction() {
110. $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
111. //$order_id = $this->getRequest()->getParam('n');
112.
113. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);100. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
114. if($order->canInvoice()) {101. if($order->canInvoice()) {
115. $order->sendNewOrderEmail();102. $order->sendNewOrderEmail();
116. $order->addStatusHistoryComment ("Płatność w kwocie ".$this->getRequest()->getParam('amount')." zł została przyjęta przez CashBill.pl", Mage::getStoreConfig('payment/platnosci_cashbill/complete_order_status'));103. $order->addStatusHistoryComment ("Płatność w kwocie ".$amount." zł została przyjęta przez CashBill.pl", Mage::getStoreConfig('payment/platnosci_cashbill/complete_order_status'));
117. $order->save();104. $order->save();
118. }105. }
119. 106.
120. $session = Mage::getSingleton('checkout/session');107. $session = Mage::getSingleton('checkout/session');
121. $session->setQuoteId($session->getCashbillQuoteId(true));108. $session->setQuoteId($session->getCashbillQuoteId(true));
122.109.
123. Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();110. Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
124. 111.
125. $this->_redirect('checkout/onepage/success');112. $this->_redirect('checkout/onepage/success');
126. }113. }
127. 114.
128. public function failureAction() {115. private function failure($order_id,$amount) {
129. //$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();116. //$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
130. $order_id = $this->getRequest()->getParam('n');
131.
132. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);117. $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
133. 118.
134. if(!$order->getId()) { return FALSE; }119. if(!$order->getId()) { return FALSE; }
135. 120.
136. $order->cancel();121. $order->cancel();
137. $order->save();122. $order->save();
138. 123.
139. $session = Mage::getSingleton('checkout/session');124. $session = Mage::getSingleton('checkout/session');
140. $session->setQuoteId($session->getCashbillQuoteId(true));125. $session->setQuoteId($session->getCashbillQuoteId(true));
141. $session->addError("Płatność za pomocą serwisu Cashbill została zakończona niepowodzeniem.");126. $session->addError("Płatność za pomocą serwisu Cashbill została zakończona niepowodzeniem.");
142. 127.
143. $this->_redirect('checkout/cart');128. $this->_redirect('checkout/cart');
144. }129. }
130.
145.}131.}
original text
changed text