/** * Process Response from WorldPay */ private function process_response($posted) { $installation_id = $this->get_post('instId'); $cartId = $this->get_post('cartId'); $transId = $this->get_post('transId'); $processed_transID = get_post_meta($cartId, '_worldpay_processed_transID', true); $amount = $this->get_post('amount'); $authAmount = $this->get_post('authAmount'); $authCurrency = $this->get_post('authCurrency'); $currency = $this->get_post('currency'); $shop_currency = Jigoshop_Base::get_options()->get('jigoshop_currency'); $testMode = $this->get_post('testMode'); $error = array(); $order = new jigoshop_order((int) $cartId); // Do all checks only if transaction was processed. switch ($this->get_post('transStatus')) { case 'Y': // If the currency is locked. if ($this->fixed_currency == 'yes') { // All currencies should be the same. if ($currency != $authCurrency || $authCurrency != $shop_currency || $currency != $shop_currency) { $error['Locked_Currency_Error'] = sprintf(__('The currency paid in was different than the one requested. Order #: %s. Currency paid in: %s, the amount paid: %s. You should investigate further.', 'jigoshop'), $order->id, $authCurrency, $authAmount); } // All amounts should be the same if ($order->order_total != $amount || $authAmount != $order->order_total || $authAmount != $amount) { $error['Locked_Amount_Error'] = sprintf(__('There were differences in the amounts received. Order #: %s. Submitted: %s, Paid: %s, Order Total: %s. You should investigate further.', 'jigoshop'), $order->id, $amount, $authAmount, $order->order_total); } } else { // If currency submitted to WorldPay is the same as your store one. // They should always be the same even if you accept multiple currency payments. if ($currency != $shop_currency) { $error['currency'] = sprintf(__('The currency submitted to WorldPay (%s) is different than the main currency of your shop (%s). You should investigate further.', 'jigoshop'), $currency, $shop_currency); } // If multi-currency is supported, at least the amount submitted to WorldPay should be the same as the order total. if ($order->order_total != $amount) { $error['amount'] = sprintf(__('The order total (%s) is different than the amount submitted to WorldPay (%s). You should investigate further.', 'jigoshop'), $order->order_total, $amount); } } // Check merchant. if ($installation_id != $this->installation_id) { $error['instId'] = sprintf(__('Order was paid to installation ID: %s, which is different than the Installation ID set in your shop: %s. You should investigate further.', 'jigoshop'), $installation_id, $this->installation_id); } if ($transId == $processed_transID) { $error['already_processed'] = sprintf(__('Payment with the same transaction ID (%s) was already processed for this order. You should investigate further.', 'jigoshop'), $transId); } if ($this->testmode == 'no' && $testMode > 0) { $error['testmode'] = sprintf(__('Your shop is in Live mode, but you received a Test mode transaction. You should investigate further.', 'jigoshop')); } if (empty($error) && $testMode == 0) { // Payment completed as live response $order->add_order_note(__('WorldPay payment completed. Transaction ID: ' . $transId, 'jigoshop')); update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID); $order->payment_complete(); $args = array('key' => $order->order_key, 'order' => $order->id); $redirect_url = add_query_arg($args, get_permalink(jigoshop_get_page_id('thanks'))); } elseif (empty($error) && $testMode > 0) { // Payment completed as test response $order->add_order_note(__('TESTMODE: WorldPay payment completed. Transaction ID: ' . $transId, 'jigoshop')); update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID); $order->payment_complete(); $args = array('key' => $order->order_key, 'order' => $order->id); $redirect_url = add_query_arg($args, get_permalink(jigoshop_get_page_id('thanks'))); } if (!empty($error) && $this->receive_err_log == 'yes') { $info = sprintf(__('Order #%s ', 'jigoshop'), $order->id); $this->email_worldpay_error_logs($error, $posted, $info); $redirect_url = get_permalink(jigoshop_get_page_id('checkout')); } break; case 'C': if ($testMode == 0) { // Payment was canceled live. $order->cancel_order(__('Order was canceled by customer at WorldPay.', 'jigoshop')); } if ($testMode > 0) { // Payment was canceled in test mode. $order->cancel_order(__('TESTMODE: Order was canceled by customer at WorldPay.', 'jigoshop')); } $redirect_url = $this->get_post('MC_cancel_return'); break; default: // No action $redirect_url = $this->get_post('MC_cancel_return'); break; } echo '<html><head><meta http-equiv="refresh" content="2;url=' . $redirect_url . '"></head><body><WPDISPLAY ITEM=banner></body></html>'; exit; }
function jigoshop_cancel_order() { if (isset($_GET['cancel_order']) && isset($_GET['order']) && isset($_GET['order_id'])) { $order_key = urldecode($_GET['order']); $order_id = (int) $_GET['order_id']; $order = new jigoshop_order($order_id); if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending' && jigoshop::verify_nonce('cancel_order')) { // Cancel the order + restore stock $order->cancel_order(__('Order cancelled by customer.', 'jigoshop')); // Message jigoshop::add_message(__('Your order was cancelled.', 'jigoshop')); } elseif ($order->status != 'pending') { jigoshop::add_error(__('Your order is no longer pending and could not be cancelled. Please contact us if you need assistance.', 'jigoshop')); } else { jigoshop::add_error(__('Invalid order.', 'jigoshop')); } wp_safe_redirect(jigoshop_cart::get_cart_url()); exit; } }