Skip to content

Commit

Permalink
Fix windows line endings in ordercontroller, remove faulty error mess…
Browse files Browse the repository at this point in the history
…age in callback
  • Loading branch information
RBech committed Mar 14, 2017
1 parent d4cc0d1 commit 7579351
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 36 deletions.
84 changes: 76 additions & 8 deletions app/code/community/Quickpay/Payment/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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');
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
<?phpclass Quickpay_Payment_OrderController extends Mage_Adminhtml_Controller_Action{ public function indexAction() { $request = $this->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); }}
<?php

class Quickpay_Payment_OrderController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$request = $this->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);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php
class Quickpay_Payment_PaymentController extends Mage_Core_Controller_Front_Action
{
protected function _expireAjax()
{
if (! $this->_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();
Expand All @@ -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
Expand All @@ -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();
}

Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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'));
Expand All @@ -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()) {
Expand All @@ -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:<br/>";
$msg .= "Info: <br/>";
$msg .= "qpstat: " . ((isset($operation->qp_status_code)) ? $operation->qp_status_code : '') . "<br/>";
$msg .= "qpmsg: " . ((isset($operation->qp_status_msg)) ? $operation->qp_status_msg : '') . "<br/>";
$msg .= "chstat: " . ((isset($operation->aq_status_code)) ? $operation->aq_status_code : '') . "<br/>";
$msg .= "chstatmsg: " . ((isset($operation->aq_status_msg)) ? $operation->aq_status_msg : '') . "<br/>";
$msg .= "amount: " . ((isset($operation->amount)) ? $operation->amount : '') . "<br/>";
$order->addStatusToHistory($order->getStatus(), $msg);
$order->save();
}
} else {
$this->getResponse()->setBody('Checksum mismatch.');
Expand Down

0 comments on commit 7579351

Please sign in to comment.