Untitled diff

Created Diff never expires
43 removals
145 lines
28 additions
131 lines
<?php
<?php


class Platnosci_Cashbill_CashbillController extends Mage_Core_Controller_Front_Action {
class Platnosci_Cashbill_CashbillController extends Mage_Core_Controller_Front_Action {


public function redirectAction() {
public function redirectAction() {
$session = Mage::getSingleton('checkout/session');
$session = Mage::getSingleton('checkout/session');
$session->setCashbillQuoteId($session->getQuoteId());
$session->setCashbillQuoteId($session->getQuoteId());


$this->getResponse()->setBody($this->getLayout()->createBlock('cashbill/payment_cashbill_redirect')->toHtml());
$this->getResponse()->setBody($this->getLayout()->createBlock('cashbill/payment_cashbill_redirect')->toHtml());
$session->unsQuoteId();
$session->unsQuoteId();
}
}


public function returnAction() {
public function returnAction() {
// Dane punktu otrzymane po zakonczeniu procesu rejestracji
// Dane punktu otrzymane po zakonczeniu procesu rejestracji
$service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');
$service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');
$key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');
$key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');
// Funkcja sprawdzajaca poprawnosc sygnatury
// Funkcja sprawdzajaca poprawnosc sygnatury
$data = $_GET;
$data = $_GET;
if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_GET['sign'] )
if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_GET['sign'] )
{$test = 1;}else{$test = 2;}
{
$test = 1;
}else{
$test = 2;
}


$params = array('n' => $data['userdata'], 'amount' => $data['amount']);
$params = array('n' => $data['userdata'], 'amount' => $data['amount']);
if( $test == 1 && $_GET['service'] == $service)
if( $test == 1 && $_GET['service'] == $service)
{
{
// prawidlowa sygnatura, w zaleznosci od statusu odpowiednia informacja dla klienta
// prawidlowa sygnatura, w zaleznosci od statusu odpowiednia informacja dla klienta
if( strtoupper($_GET['status']) == 'OK' ) {
if( strtoupper($_GET['status']) == 'OK' ) {
$this->_redirect('cashbill/cashbill/success/', $params);
$this->success($data['userdata'],$data['amount']);
}else {
}else {
$this->_redirect('cashbill/cashbill/failure', $params);
$this->failure($data['userdata'],$data['amount']);
}
}
}else {
}else {
$session = Mage::getSingleton('checkout/session');
$session = Mage::getSingleton('checkout/session');
$session->setQuoteId($session->getCashbillQuoteId(true));
$session->setQuoteId($session->getCashbillQuoteId(true));
$session->addError("wystąpił inny błąd. zgłoś to administratora sklepu.");
$session->addError("wystąpił inny błąd. zgłoś to administratora sklepu.");
$this->_redirect('checkout/cart');
$this->_redirect('checkout/cart');
}
}
}
}

public function serwerAction() {
public function serwerAction() {
// Dane punktu otrzymane po zakonczeniu procesu rejestracji
// Dane punktu otrzymane po zakonczeniu procesu rejestracji
$service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');
$service = Mage::getStoreConfig('payment/platnosci_cashbill/shopid');
$key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');
$key = Mage::getStoreConfig('payment/platnosci_cashbill/shopkey');
// Funkcja sprawdzajaca poprawnosc sygnatury
// Funkcja sprawdzajaca poprawnosc sygnatury
$data = $_POST;
$data = $_POST;
if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_POST['sign'] )
if( md5($data['service'].$data['orderid'].$data['amount'].$data['userdata'].$data['status'].$key) == $_POST['sign'] )
{$test = 1;}else{$test = 2;}
{$test = 1;}else{$test = 2;}
$params = array( 'n' => $data['userdata'],'amount'=>$data['amount']);
$params = array( 'n' => $data['userdata'],'amount'=>$data['amount']);
if( $test == 1 && $_POST['service'] == $service)
if( $test == 1 && $_POST['service'] == $service)
{
{
if( strtoupper($_POST['status']) == 'OK' ) {
if( strtoupper($_POST['status']) == 'OK' ) {
$this->_redirect('cashbill/cashbill/hsuccess/', $params);
$this->hsuccess($data['userdata'],$data['amount']);
}
}
else {
else {
$this->_redirect('cashbill/cashbill/herror/', $params);
$this->herror($data['userdata'],$data['amount']);
}
}
}
}
else {
else {
echo 'BLAD SYGNATURY';
echo 'BLAD SYGNATURY';
}
}
}
}
private function hsuccess($order_id,$amount) {
public function hsuccessAction() {
$order_id = $this->getRequest()->getParam('n');
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
if($order->canInvoice()) {
if($order->canInvoice()) {
$order->sendNewOrderEmail();
$order->sendNewOrderEmail();
$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'));
$order->addStatusHistoryComment ("Płatność w kwocie ".$amount." zł została przyjęta przez CashBill.pl", Mage::getStoreConfig('payment/platnosci_cashbill/complete_order_status'));
$order->save();
$order->save();
}
}
$session = Mage::getSingleton('checkout/session');
$session = Mage::getSingleton('checkout/session');
$session->setQuoteId($session->getCashbillQuoteId(true));
$session->setQuoteId($session->getCashbillQuoteId(true));


Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
echo 'OK';
echo 'OK';
}
}
public function herrorAction()
private function herror($order_id,$amount) {
{
$order_id = $this->getRequest()->getParam('n');
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
if(!$order->getId()) { return FALSE; }
if(!$order->getId()) { return FALSE; }
$order->cancel();
$order->cancel();
$order->save();
$order->save();
echo 'OK';
echo 'OK';
}
}

private function success($order_id,$amount) {

public function successAction() {
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
//$order_id = $this->getRequest()->getParam('n');
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
if($order->canInvoice()) {
if($order->canInvoice()) {
$order->sendNewOrderEmail();
$order->sendNewOrderEmail();
$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'));
$order->addStatusHistoryComment ("Płatność w kwocie ".$amount." zł została przyjęta przez CashBill.pl", Mage::getStoreConfig('payment/platnosci_cashbill/complete_order_status'));
$order->save();
$order->save();
}
}
$session = Mage::getSingleton('checkout/session');
$session = Mage::getSingleton('checkout/session');
$session->setQuoteId($session->getCashbillQuoteId(true));
$session->setQuoteId($session->getCashbillQuoteId(true));


Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
$this->_redirect('checkout/onepage/success');
$this->_redirect('checkout/onepage/success');
}
}
public function failureAction() {
private function failure($order_id,$amount) {
//$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
//$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order_id = $this->getRequest()->getParam('n');
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
if(!$order->getId()) { return FALSE; }
if(!$order->getId()) { return FALSE; }
$order->cancel();
$order->cancel();
$order->save();
$order->save();
$session = Mage::getSingleton('checkout/session');
$session = Mage::getSingleton('checkout/session');
$session->setQuoteId($session->getCashbillQuoteId(true));
$session->setQuoteId($session->getCashbillQuoteId(true));
$session->addError("Płatność za pomocą serwisu Cashbill została zakończona niepowodzeniem.");
$session->addError("Płatność za pomocą serwisu Cashbill została zakończona niepowodzeniem.");
$this->_redirect('checkout/cart');
$this->_redirect('checkout/cart');
}
}

}
}