diff --git a/app/code/community/Quickpay/Payment/Helper/Data.php b/app/code/community/Quickpay/Payment/Helper/Data.php index 4d698db..7031134 100644 --- a/app/code/community/Quickpay/Payment/Helper/Data.php +++ b/app/code/community/Quickpay/Payment/Helper/Data.php @@ -8,7 +8,12 @@ class Quickpay_Payment_Helper_Data extends Mage_Core_Helper_Abstract protected $format = "application/json"; /** - * Send a request to Quickpay. + * Perform a POST request + * + * @param $resource + * @param array $postdata + * @param string $synchronized + * @return string */ protected function request($resource, $postdata = array(), $synchronized = "?synchronized") { @@ -39,6 +44,13 @@ protected function request($resource, $postdata = array(), $synchronized = "?syn return $request->getBody(); } + /** + * Perform a PUT request + * + * @param $resource + * @param array $postdata + * @return string + */ protected function put($resource, $postdata = array()) { $client = new Zend_Http_Client(); @@ -69,7 +81,10 @@ protected function put($resource, $postdata = array()) } /** - * Create a payment at the quickpay gateway + * Create a Payment + * + * @param Mage_Sales_Model_Order $order + * @return mixed|string */ public function qpCreatePayment(Mage_Sales_Model_Order $order) { @@ -129,8 +144,12 @@ public function qpCreatePayment(Mage_Sales_Model_Order $order) } /** - * Create a payment link at the quickpay gateway - */ + * Create a Payment Link + * + * @param $id + * @param $array + * @return mixed|string + */ function qpCreatePaymentLink($id, $array) { $storeId = Mage::app()->getStore()->getStoreId(); @@ -141,7 +160,12 @@ function qpCreatePaymentLink($id, $array) } /** - * Capture a payment at the quickpay gateway + * Capture Payment + * + * @param $id + * @param $amount + * @param null $extras + * @return mixed|string */ function qpCapture($id, $amount, $extras = null) { @@ -158,7 +182,12 @@ function qpCapture($id, $amount, $extras = null) } /** - * Refund a payment at the quickpay gateway + * Refund Payment + * + * @param $id + * @param $amount + * @param null $extras + * @return mixed|string */ function qpRefund($id, $amount, $extras = null) { @@ -175,7 +204,10 @@ function qpRefund($id, $amount, $extras = null) } /** - * Cancel a payment at the quickpay gateway + * Cancel Payment + * + * @param $id + * @return mixed|string */ function qpCancel($id) { @@ -187,6 +219,12 @@ function qpCancel($id) return $result; } + /** + * Capture Payment + * + * @param $payment + * @param $amount + */ public function capture($payment, $amount) { Mage::log('start capture', null, 'qp_capture.log'); @@ -261,6 +299,12 @@ public function capture($payment, $amount) Mage::log('stop capture', null, 'qp_capture.log'); } + /** + * Refund Payment + * + * @param $orderid + * @param $refundtotal + */ public function refund($orderid, $refundtotal) { $order = Mage::getModel('sales/order')->load($orderid); @@ -328,6 +372,11 @@ public function refund($orderid, $refundtotal) $order->save(); } + /** + * Cancel Payment + * + * @param Mage_Sales_Model_Order $order + */ public function cancel(Mage_Sales_Model_Order $order) { $orderid = explode("-", $order->getIncrementId()); @@ -382,6 +431,14 @@ public function cancel(Mage_Sales_Model_Order $order) $order->save(); } + /** + * Create transaction + * + * @param $order + * @param $transactionId + * @param $type + * @return false|Mage_Core_Model_Abstract + */ public function createTransaction($order, $transactionId, $type) { $transaction = Mage::getModel('sales/order_payment_transaction'); @@ -405,6 +462,12 @@ public function createTransaction($order, $transactionId, $type) return $transaction; } + /** + * Get row from quickpay_order_status table + * + * @param $order_id + * @return bool + */ public function getQuickPay($order_id) { if ($order_id) { @@ -498,8 +561,13 @@ public function removeFromStock($incrementId) } } + /** + * Get installed version of extension + * + * @return string + */ public function getInstalledVersion() { - return (string)Mage::getConfig()->getNode()->modules->Quickpay_Payment->version; + return (string) Mage::getConfig()->getNode()->modules->Quickpay_Payment->version; } } diff --git a/app/code/community/Quickpay/Payment/Model/System/Config/Source/Cardtype.php b/app/code/community/Quickpay/Payment/Model/System/Config/Source/Cardtype.php index a096c8a..421041f 100644 --- a/app/code/community/Quickpay/Payment/Model/System/Config/Source/Cardtype.php +++ b/app/code/community/Quickpay/Payment/Model/System/Config/Source/Cardtype.php @@ -4,9 +4,18 @@ class QuickPay_Payment_Model_System_Config_Source_Cardtype public function toOptionArray() { return array( - array('value' => '', 'label' => Mage::helper('quickpaypayment')->__('Alle betalingsmetoder')), - array('value' => 'creditcard', 'label' => Mage::helper('quickpaypayment')->__('Alle kreditkort')), - array('value' => 'specific-cards', 'label' => Mage::helper('quickpaypayment')->__('Vælg specifikke betalingsmetoder')), + array( + 'value' => '', + 'label' => Mage::helper('quickpaypayment')->__('Alle betalingsmetoder') + ), + array( + 'value' => 'creditcard', + 'label' => Mage::helper('quickpaypayment')->__('Alle kreditkort') + ), + array( + 'value' => 'specific-cards', + 'label' => Mage::helper('quickpaypayment')->__('Vælg specifikke betalingsmetoder') + ), ); } } diff --git a/app/code/community/Quickpay/Payment/controllers/OrderController.php b/app/code/community/Quickpay/Payment/controllers/OrderController.php index 003ee03..1085287 100644 --- a/app/code/community/Quickpay/Payment/controllers/OrderController.php +++ b/app/code/community/Quickpay/Payment/controllers/OrderController.php @@ -1 +1,27 @@ -getRequest()->getParams(); $order_id = isset($request['id']) ? $request['id'] : 0; $info_type = Mage::helper('quickpaypayment')->getInfoType($order_id); if ($info_type == 'normal') { $fields = Mage::helper('quickpaypayment')->getFields($order_id); } else { $fields = array(); } $content = $this ->getLayout() ->createBlock('core/template') ->setTemplate('quickpaypayment/grid/info.phtml') ->setFields($fields) ->setInfoType($info_type) ->toHtml(); $this->getResponse()->setBody($content); } } \ No newline at end of file +getRequest()->getParams(); + $order_id = isset($request['id']) ? $request['id'] : 0; + $info_type = Mage::helper('quickpaypayment')->getInfoType($order_id); + + if ($info_type == 'normal') { + $fields = Mage::helper('quickpaypayment')->getFields($order_id); + } else { + $fields = array(); + } + + $content = $this + ->getLayout() + ->createBlock('core/template') + ->setTemplate('quickpaypayment/grid/info.phtml') + ->setFields($fields) + ->setInfoType($info_type) + ->toHtml(); + + $this->getResponse()->setBody($content); + } +} \ No newline at end of file diff --git a/app/code/community/Quickpay/Payment/controllers/PaymentController.php b/app/code/community/Quickpay/Payment/controllers/PaymentController.php index e5e2250..bb25011 100644 --- a/app/code/community/Quickpay/Payment/controllers/PaymentController.php +++ b/app/code/community/Quickpay/Payment/controllers/PaymentController.php @@ -1,19 +1,19 @@ _getSession()->getQuote()->hasItems()) { - $this->getResponse()->setHeader('HTTP/1.1', '403 Session Expired'); - exit ; - } - } - + /** + * Get payment method + * + * @return Quickpay_Payment_Model_Payment + */ public function getPayment() { return Mage::getSingleton('quickpaypayment/payment'); } + /** + * Handle redirect to QuickPay + */ public function redirectAction() { $session = $this->_getSession(); @@ -34,6 +34,9 @@ public function redirectAction() $session->unsRedirectUrl(); } + /** + * Handle customer cancelling payment + */ public function cancelAction() { //Read quote id from session and attempt to restore @@ -51,16 +54,19 @@ public function cancelAction() $this->_redirect('checkout/cart'); } + /** + * Handle customer being redirected from QuickPay + */ public function successAction() { $order = Mage::getModel('sales/order')->loadByIncrementId($this->_getSession()->getLastRealOrderId()); $payment = Mage::getModel('quickpaypayment/payment'); - $quoteID = Mage::getSingleton("checkout/cart")->getQuote()->getId(); + $quoteID = Mage::getSingleton('checkout/cart')->getQuote()->getId(); if ($quoteID) { - $quote = Mage::getModel("sales/quote")->load($quoteID); + $quote = Mage::getModel('sales/quote')->load($quoteID); $quote->setIsActive(false)->save(); } @@ -86,6 +92,11 @@ public function successAction() $this->_redirect('checkout/onepage/success'); } + /** + * Handle callback from QuickPay + * + * @return $this + */ public function callbackAction() { Mage::log("Logging callback data", null, 'qp_callback.log'); @@ -108,8 +119,8 @@ public function callbackAction() // Save the order into the quickpaypayment_order_status table // IMPORTANT to update the status as 1 to ensure that the stock is handled correctly! - if (($request->accepted && $operation->type == 'authorize' && $operation->qp_status_code == "20000") || ($operation->type == 'authorize' && $operation->qp_status_code == "20200" && $operation->pending == TRUE)) { - if ($operation->pending == TRUE) { + if (($request->accepted && $operation->type == 'authorize' && $operation->qp_status_code == "20000") || ($operation->type == 'authorize' && $operation->qp_status_code == "20200" && $operation->pending == true)) { + if ($operation->pending == true) { Mage::log('Transaction accepted but pending', null, 'qp_callback.log'); } else { Mage::log('Transaction accepted', null, 'qp_callback.log'); @@ -185,6 +196,7 @@ public function callbackAction() } $payment = Mage::getModel('quickpaypayment/payment'); + // TODO: Consider to set pending payments in another state, must be handled in the api functions if ($order->getStatus() != $payment->getConfigData('order_status_after_payment')) { $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, $payment->getConfigData('order_status_after_payment')); @@ -197,7 +209,7 @@ public function callbackAction() * If test mode is disabled and the order is placed with a test card, reject it * We wait until this moment since qpCancel will fail without a row in quickpaypayment_order_status */ - if (! $payment->getConfigData('testmode') && $request->test_mode == 1) { + if (!$payment->getConfigData('testmode') && $request->test_mode == 1) { Mage::log('Attempted callback with test card while testmode is disabled for order #' . $order->getIncrementId(), null, 'qp_debug.log'); //Cancel order if ($order->canCancel()) { @@ -218,17 +230,6 @@ public function callbackAction() if ((int)Mage::getStoreConfig('cataloginventory/item_options/manage_stock') == 1) { Mage::helper('quickpaypayment')->removeFromStock($order->getIncrementId()); } - } else { - Mage::log('Transaction not ok', null, 'qp_callback.log'); - $msg = "Der er fejl ved et betalings forsoeg:
"; - $msg .= "Info:
"; - $msg .= "qpstat: " . ((isset($operation->qp_status_code)) ? $operation->qp_status_code : '') . "
"; - $msg .= "qpmsg: " . ((isset($operation->qp_status_msg)) ? $operation->qp_status_msg : '') . "
"; - $msg .= "chstat: " . ((isset($operation->aq_status_code)) ? $operation->aq_status_code : '') . "
"; - $msg .= "chstatmsg: " . ((isset($operation->aq_status_msg)) ? $operation->aq_status_msg : '') . "
"; - $msg .= "amount: " . ((isset($operation->amount)) ? $operation->amount : '') . "
"; - $order->addStatusToHistory($order->getStatus(), $msg); - $order->save(); } } else { $this->getResponse()->setBody('Checksum mismatch.');