function successful_request($posted)
 {
     $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
     if (!empty($posted['f_code'])) {
         $order = new jigoshop_order((int) $posted['mer_txn']);
         if ($order->status !== 'completed') {
             switch ($posted['f_code']) {
                 case 'Ok':
                     $order->add_order_note(__('Atom Standard payment completed', 'jigoshop'));
                     $order->payment_complete();
                     wp_safe_redirect(add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(jigoshop_get_page_id('thanks')))));
                     exit;
                     // case '0' : // Pending
                     // case '-2' : // Failed
                     // $order->update_status('on-hold', sprintf(__('Atom payment failed (%s)', 'jigoshop'), strtolower($posted['status']) ) );
                     // break;
                 // case '0' : // Pending
                 // case '-2' : // Failed
                 // $order->update_status('on-hold', sprintf(__('Atom payment failed (%s)', 'jigoshop'), strtolower($posted['status']) ) );
                 // break;
                 case 'F':
                     $order->update_status('cancelled', __('Atom payment cancelled', 'jigoshop'));
                     break;
                 default:
                     $order->update_status('cancelled', __('Atom exception', 'jigoshop'));
                     break;
             }
         }
         exit;
     }
 }
Exemple #2
0
 /**
  * Update lead status of the specified payment
  *
  * @param string $payment
  */
 public static function update_status(Pronamic_Pay_Payment $payment, $can_redirect = false)
 {
     $id = $payment->get_source_id();
     $order = new jigoshop_order((int) $id);
     $data = new Pronamic_WP_Pay_Extensions_Jigoshop_PaymentData($order);
     $should_update = !in_array($order->status, array(Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_COMPLETED, Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_PROCESSING));
     if ($should_update) {
         $url = $data->get_normal_return_url();
         switch ($payment->status) {
             case Pronamic_WP_Pay_Statuses::CANCELLED:
                 $order->update_status(Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_CANCELLED, __('iDEAL payment cancelled.', 'pronamic_ideal'));
                 $url = $data->get_cancel_url();
                 break;
             case Pronamic_WP_Pay_Statuses::EXPIRED:
                 // Jigoshop PayPal gateway uses 'on-hold' order status for an 'expired' payment
                 // @see http://plugins.trac.wordpress.org/browser/jigoshop/tags/1.2.1/gateways/paypal.php#L430
                 $order->update_status(Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_ON_HOLD, __('iDEAL payment expired.', 'pronamic_ideal'));
                 break;
             case Pronamic_WP_Pay_Statuses::FAILURE:
                 // Jigoshop PayPal gateway uses 'on-hold' order status for an 'failure' in the payment
                 // @see http://plugins.trac.wordpress.org/browser/jigoshop/tags/1.2.1/gateways/paypal.php#L431
                 $order->update_status('failed', __('iDEAL payment failed.', 'pronamic_ideal'));
                 break;
             case Pronamic_WP_Pay_Statuses::SUCCESS:
                 // Payment completed
                 $order->add_order_note(__('iDEAL payment completed.', 'pronamic_ideal'));
                 $order->payment_complete();
                 $url = $data->get_success_url();
                 break;
             case Pronamic_WP_Pay_Statuses::OPEN:
                 $order->add_order_note(__('iDEAL payment open.', 'pronamic_ideal'));
                 break;
             default:
                 $order->add_order_note(__('iDEAL payment unknown.', 'pronamic_ideal'));
                 break;
         }
         if ($url && $can_redirect) {
             wp_redirect($url, 303);
             exit;
         }
     }
 }
Exemple #3
0
function jigoshop_pay_action()
{
    if (!is_jigoshop_single_page(JIGOSHOP_PAY)) {
        return;
    }
    if (isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id'])) {
        // Pay for existing order
        $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') {
            // Set customer location to order location
            if ($order->billing_country) {
                jigoshop_customer::set_country($order->billing_country);
            }
            if ($order->billing_state) {
                jigoshop_customer::set_state($order->billing_state);
            }
            if ($order->billing_postcode) {
                jigoshop_customer::set_postcode($order->billing_postcode);
            }
            // Pay form was posted - process payment
            if (isset($_POST['pay']) && jigoshop::verify_nonce('pay')) {
                // Update payment method
                if ($order->order_total > 0) {
                    $payment_method = jigowatt_clean($_POST['payment_method']);
                    $data = (array) maybe_unserialize(get_post_meta($order_id, 'order_data', true));
                    $data['payment_method'] = $payment_method;
                    update_post_meta($order_id, 'order_data', $data);
                    $available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
                    $result = $available_gateways[$payment_method]->process_payment($order_id);
                    // Redirect to success/confirmation/payment page
                    if ($result['result'] == 'success') {
                        wp_safe_redirect($result['redirect']);
                        exit;
                    }
                } else {
                    // No payment was required for order
                    $order->payment_complete();
                    // filter redirect page
                    $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
                    wp_safe_redirect(get_permalink($checkout_redirect));
                    exit;
                }
            }
        } elseif ($order->status != 'pending') {
            jigoshop::add_error(__('Your order has already been paid for. Please contact us if you need assistance.', 'jigoshop'));
        } else {
            jigoshop::add_error(__('Invalid order.', 'jigoshop'));
        }
    } else {
        // Pay for order after checkout step
        if (isset($_GET['order'])) {
            $order_id = $_GET['order'];
        } else {
            $order_id = 0;
        }
        if (isset($_GET['key'])) {
            $order_key = $_GET['key'];
        } else {
            $order_key = '';
        }
        if ($order_id > 0) {
            $order = new jigoshop_order($order_id);
            if ($order->order_key != $order_key || $order->status != 'pending') {
                wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
                exit;
            }
        } else {
            wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
            exit;
        }
    }
}
 /**
  * Process the checkout after the confirm order button is pressed
  */
 public function process_checkout()
 {
     if (!defined('JIGOSHOP_CHECKOUT')) {
         define('JIGOSHOP_CHECKOUT', true);
     }
     // Initialize cart
     jigoshop_cart::get_cart();
     jigoshop_cart::calculate_totals();
     if (isset($_POST) && $_POST && !isset($_POST['login'])) {
         jigoshop::verify_nonce('process_checkout');
         // this will fill in our $posted array with validated data
         self::validate_checkout();
         $gateway = jigoshop_payment_gateways::get_gateway($this->posted['payment_method']);
         if (self::process_gateway($gateway)) {
             $gateway->validate_fields();
         }
         do_action('jigoshop_after_checkout_validation', $this->posted, $_POST, sizeof(jigoshop::$errors));
         if (jigoshop::has_errors()) {
             return false;
         }
         if (!isset($_POST['update_totals'])) {
             $user_id = get_current_user_id();
             // Create customer account and log them in
             if ($this->show_signup && !$user_id && $this->posted['create_account']) {
                 $user_id = $this->create_user_account();
                 if ($user_id === 0) {
                     return false;
                 }
             }
             $billing = array('first_name' => $this->posted['billing_first_name'], 'last_name' => $this->posted['billing_last_name'], 'company' => $this->posted['billing_company'], 'address_1' => $this->posted['billing_address_1'], 'address_2' => $this->posted['billing_address_2'], 'city' => $this->posted['billing_city'], 'state' => $this->posted['billing_state'], 'postcode' => $this->posted['billing_postcode'], 'country' => $this->posted['billing_country'], 'phone' => $this->posted['billing_phone'], 'email' => $this->posted['billing_email']);
             jigoshop_customer::set_country($billing['country']);
             jigoshop_customer::set_state($billing['state']);
             jigoshop_customer::set_postcode($billing['postcode']);
             if (isset($this->posted['billing_euvatno']) && $this->valid_euvatno) {
                 $billing['euvatno'] = $this->posted['billing_euvatno'];
                 $billing['euvatno'] = str_replace(' ', '', $billing['euvatno']);
                 // If country code is not provided - add one.
                 if (strpos($billing['euvatno'], $billing['country']) === false) {
                     $billing['euvatno'] = $billing['country'] . $billing['euvatno'];
                 }
             }
             // Get shipping/billing
             if (!empty($this->posted['shiptobilling'])) {
                 $shipping = $billing;
                 unset($shipping['phone'], $shipping['email']);
             } elseif (jigoshop_shipping::is_enabled()) {
                 $shipping = array('first_name' => $this->posted['shipping_first_name'], 'last_name' => $this->posted['shipping_last_name'], 'company' => $this->posted['shipping_company'], 'address_1' => $this->posted['shipping_address_1'], 'address_2' => $this->posted['shipping_address_2'], 'city' => $this->posted['shipping_city'], 'state' => $this->posted['shipping_state'], 'postcode' => $this->posted['shipping_postcode'], 'country' => $this->posted['shipping_country']);
             }
             jigoshop_customer::set_shipping_country($shipping['country']);
             jigoshop_customer::set_shipping_state($shipping['state']);
             jigoshop_customer::set_shipping_postcode($shipping['postcode']);
             // Update totals based on processed customer address
             jigoshop_cart::calculate_totals();
             // Save billing/shipping to user meta fields
             if ($user_id > 0) {
                 foreach ($billing as $field => $value) {
                     update_user_meta($user_id, 'billing_' . $field, $value);
                 }
                 if (isset($shipping)) {
                     foreach ($shipping as $field => $value) {
                         update_user_meta($user_id, 'shipping_' . $field, $value);
                     }
                 }
             }
             if (!isset($_POST['submit_action']) || $_POST['submit_action'] != 'place_order') {
                 $result = jigoshop::redirect(jigoshop_get_page_id(JIGOSHOP_CHECKOUT));
                 return array('result' => 'redirect', 'redirect' => $result);
             }
             // Order meta data
             $data = array();
             $applied_coupons = array_map(function ($coupon) {
                 return JS_Coupons::get_coupon($coupon);
             }, jigoshop_cart::get_coupons());
             do_action('jigoshop_checkout_update_order_total', $this->posted);
             foreach ($billing as $field => $value) {
                 $data['billing_' . $field] = $value;
             }
             if (isset($shipping)) {
                 foreach ($shipping as $field => $value) {
                     $data['shipping_' . $field] = $value;
                 }
             }
             $data['order_discount_coupons'] = $applied_coupons;
             $data['shipping_method'] = $this->posted['shipping_method'];
             $data['shipping_service'] = $this->posted['shipping_service'];
             $data['payment_method'] = $this->posted['payment_method'];
             $data['payment_method_title'] = $gateway->title;
             $data['order_subtotal'] = jigoshop_cart::get_subtotal();
             $data['order_discount_subtotal'] = jigoshop_cart::get_discount_subtotal();
             $data['order_shipping'] = jigoshop_cart::get_shipping_total();
             $data['order_discount'] = jigoshop_cart::get_total_discount(false);
             $data['order_tax'] = jigoshop_cart::get_taxes_as_string();
             $data['order_tax_no_shipping_tax'] = jigoshop_cart::get_total_cart_tax_without_shipping_tax();
             $data['order_tax_divisor'] = jigoshop_cart::get_tax_divisor();
             $data['order_shipping_tax'] = jigoshop_cart::get_shipping_tax();
             $data['order_total'] = jigoshop_cart::get_total(false);
             $data['order_total_prices_per_tax_class_ex_tax'] = jigoshop_cart::get_price_per_tax_class_ex_tax();
             if ($this->valid_euvatno) {
                 $data['order_tax'] = '';
                 $temp = jigoshop_cart::get_total_cart_tax_without_shipping_tax();
                 $data['order_total'] -= $data['order_shipping_tax'] + $temp;
                 $data['order_shipping_tax'] = 0;
             }
             // Cart items
             $order_items = array();
             foreach (jigoshop_cart::get_cart() as $values) {
                 /** @var jigoshop_product $product */
                 $product = $values['data'];
                 // Check stock levels
                 if (!$product->has_enough_stock($values['quantity'])) {
                     jigoshop::add_error(sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologize for any inconvenience caused.', 'jigoshop'), $product->get_title()));
                     if (self::get_options()->get('jigoshop_show_stock') == 'yes') {
                         jigoshop::add_error(sprintf(__('We have only %d available at this time.', 'jigoshop'), $product->get_stock()));
                     }
                     break;
                 }
                 // Calc item tax to store
                 $rates = $product->get_tax_destination_rate();
                 $rates = current($rates);
                 if (isset($rates['rate'])) {
                     $rate = $rates['rate'];
                 } else {
                     $rate = 0.0;
                 }
                 if ($this->valid_euvatno) {
                     $rate = 0.0;
                 }
                 $price_inc_tax = $product->get_price_with_tax();
                 if (!empty($values['variation_id'])) {
                     $product_id = $values['variation_id'];
                 } else {
                     $product_id = $values['product_id'];
                 }
                 $custom_products = (array) jigoshop_session::instance()->customized_products;
                 $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : '';
                 if (!empty($custom)) {
                     unset($custom_products[$product_id]);
                     jigoshop_session::instance()->customized_products = $custom_products;
                 }
                 $order_items[] = apply_filters('new_order_item', array('id' => $values['product_id'], 'variation_id' => $values['variation_id'], 'variation' => $values['variation'], 'customization' => $custom, 'name' => $product->get_title(), 'qty' => (int) $values['quantity'], 'cost' => $product->get_price_excluding_tax(), 'cost_inc_tax' => $price_inc_tax, 'taxrate' => $rate), $values);
             }
             if (jigoshop::has_errors()) {
                 return false;
             }
             // Insert or update the post data
             $create_new_order = true;
             $order_data = array('post_type' => 'shop_order', 'post_title' => 'Order – ' . date('F j, Y @ h:i A'), 'post_status' => 'publish', 'post_excerpt' => $this->posted['order_comments'], 'post_author' => 1);
             $order_id = 0;
             if (isset(jigoshop_session::instance()->order_awaiting_payment) && jigoshop_session::instance()->order_awaiting_payment > 0) {
                 $order_id = absint(jigoshop_session::instance()->order_awaiting_payment);
                 $terms = wp_get_object_terms($order_id, 'shop_order_status', array('fields' => 'slugs'));
                 $order_status = isset($terms[0]) ? $terms[0] : 'pending';
                 // Resume the unpaid order if its pending
                 if ($order_status == 'pending' || $order_status == 'failed') {
                     $create_new_order = false;
                     $order_data['ID'] = $order_id;
                     wp_update_post($order_data);
                 }
             }
             if ($create_new_order) {
                 $order_id = wp_insert_post($order_data);
             }
             if (is_wp_error($order_id) || $order_id === 0) {
                 jigoshop::add_error(__('Error: Unable to create order. Please try again.', 'jigoshop'));
                 return false;
             }
             // Update post meta
             update_post_meta($order_id, 'order_data', $data);
             update_post_meta($order_id, 'order_key', uniqid('order_'));
             update_post_meta($order_id, 'customer_user', (int) $user_id);
             update_post_meta($order_id, 'order_items', $order_items);
             wp_set_object_terms($order_id, 'pending', 'shop_order_status');
             $order = new jigoshop_order($order_id);
             /* Coupon usage limit */
             foreach ($data['order_discount_coupons'] as $coupon) {
                 $coupon_id = JS_Coupons::get_coupon_post_id($coupon['code']);
                 if ($coupon_id !== false) {
                     $usage_count = get_post_meta($coupon_id, 'usage', true);
                     $usage_count = empty($usage_count) ? 1 : $usage_count + 1;
                     update_post_meta($coupon_id, 'usage', $usage_count);
                 }
             }
             if ($create_new_order) {
                 do_action('jigoshop_new_order', $order_id);
             } else {
                 do_action('jigoshop_resume_order', $order_id);
             }
             do_action('jigoshop_checkout_update_order_meta', $order_id, $this->posted);
             // can't just simply check needs_payment() here, as paypal may have force payment set to true
             if (self::process_gateway($gateway)) {
                 // Store Order ID in session so it can be re-used after payment failure
                 jigoshop_session::instance()->order_awaiting_payment = $order_id;
                 // Process Payment
                 $result = $gateway->process_payment($order_id);
                 // Redirect to success/confirmation/payment page
                 if ($result['result'] == 'success') {
                     return $result;
                 }
                 return false;
             } else {
                 // No payment was required for order
                 $order->payment_complete();
                 // Empty the Cart
                 jigoshop_cart::empty_cart();
                 // Redirect to success/confirmation/payment page
                 $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
                 return array('result' => 'redirect', 'redirect' => $checkout_redirect);
             }
         }
     }
     return true;
 }
Exemple #5
0
	/**
	 * Successful Payment!
	 **/
	function successful_request( $posted ) {
		
		// Custom holds post ID
	    if ( !empty($posted['txn_type']) && !empty($posted['invoice']) ) {
	
	        $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money');
	
	        if (!in_array(strtolower($posted['txn_type']), $accepted_types)) exit;
			
			$order = new jigoshop_order( (int) $posted['custom'] );
	
	        if ($order->order_key!==$posted['invoice']) exit;
	        
	        // Sandbox fix
	        if ($posted['test_ipn']==1 && $posted['payment_status']=='Pending') $posted['payment_status'] = 'completed';
			
			
			if ($order->status !== 'completed') :
		        // We are here so lets check status and do actions
		        switch (strtolower($posted['payment_status'])) :
		            case 'completed' :
		            	// Payment completed
		                $order->add_order_note( __('IPN payment completed', 'jigoshop') );
		                $order->payment_complete();
		            break;
		            case 'denied' :
		            case 'expired' :
		            case 'failed' :
		            case 'voided' :
		                // Hold order
		                $order->update_status('on-hold', sprintf(__('Payment %s via IPN.', 'jigoshop'), strtolower(sanitize($posted['payment_status'])) ) );
		            break;
		            default:
		            	// No action
		            break;
		        endswitch;
			endif;
			
			exit;
			
	    }
		
	}
Exemple #6
0
 /**
  * Successful payment processing
  *
  * @param array $posted
  */
 function successful_request($posted)
 {
     $posted = stripslashes_deep($posted);
     // 'custom' holds post ID (Order ID)
     if (!empty($posted['custom']) && !empty($posted['txn_type']) && !empty($posted['invoice'])) {
         $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money', 'subscr_payment');
         $order = new jigoshop_order((int) $posted['custom']);
         // Sandbox fix
         if (isset($posted['test_ipn']) && $posted['test_ipn'] == 1 && strtolower($posted['payment_status']) == 'pending') {
             $posted['payment_status'] = 'completed';
         }
         $merchant = $this->testmode == 'no' ? $this->email : $this->testemail;
         if ($order->status !== 'completed') {
             // We are here so lets check status and do actions
             switch (strtolower($posted['payment_status'])) {
                 case 'completed':
                     if (!in_array(strtolower($posted['txn_type']), $accepted_types)) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Unknown "txn_type" of "%s" for Order ID: %s.', 'jigoshop'), $posted['txn_type'], $posted['custom']));
                         exit;
                     }
                     if ($order->get_order_number() !== $posted['invoice']) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Order Invoice Number does NOT match PayPal posted invoice (%s) for Order ID: .', 'jigoshop'), $posted['invoice'], $posted['custom']));
                         exit;
                     }
                     // Validate Amount
                     if (number_format((double) $order->order_total, $this->decimals, '.', '') != $posted['mc_gross']) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment amounts do not match initial order (gross %s).', 'jigoshop'), $posted['mc_gross']));
                         exit;
                     }
                     if (strcasecmp(trim($posted['business']), trim($merchant)) != 0) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment Merchant email received does not match PayPal Gateway settings. (%s)', 'jigoshop'), $posted['business']));
                         exit;
                     }
                     if (!in_array($posted['mc_currency'], apply_filters('jigoshop_multi_currencies_available', array(Jigoshop_Base::get_options()->get('jigoshop_currency'))))) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment currency received (%s) does not match Shop currency.', 'jigoshop'), $posted['mc_currency']));
                         exit;
                     }
                     $order->add_order_note(__('PayPal Standard payment completed', 'jigoshop'));
                     $order->payment_complete();
                     jigoshop_log('PAYPAL: IPN payment completed for Order ID: ' . $posted['custom']);
                     break;
                 case 'denied':
                 case 'expired':
                 case 'failed':
                 case 'voided':
                     // Failed order
                     $order->update_status('failed', sprintf(__('Payment %s via IPN.', 'jigoshop'), strtolower($posted['payment_status'])));
                     jigoshop_log("PAYPAL: failed order with status = " . strtolower($posted['payment_status']) . "for Order ID: " . $posted['custom']);
                     break;
                 case 'refunded':
                 case 'reversed':
                 case 'chargeback':
                     jigoshop_log("PAYPAL: payment status type - '" . $posted['payment_status'] . "' - not supported for Order ID: " . $posted['custom']);
                     break;
             }
         }
         exit;
     } else {
         jigoshop_log("PAYPAL: function 'successful_request' -- empty initial required values -- EXITING!\n'posted' values = " . print_r($posted, true));
     }
 }
Exemple #7
0
 /**
  * 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;
 }
Exemple #8
0
 /**
  * Successful Payment!
  **/
 function successful_request($posted)
 {
     // Custom holds post ID
     if (!empty($posted['mb_transaction_id'])) {
         $order = new jigoshop_order((int) $posted['transaction_id']);
         if ($order->status !== 'completed') {
             // We are here so lets check status and do actions
             switch ($posted['status']) {
                 case '2':
                     // Processed
                     $order->add_order_note(__('Skrill payment completed', 'jigoshop'));
                     $order->payment_complete();
                     break;
                 case '0':
                     // Pending
                 // Pending
                 case '-2':
                     // Failed
                     $order->update_status('on-hold', sprintf(__('Skrill payment failed (%s)', 'jigoshop'), strtolower($posted['status'])));
                     break;
                 case '-1':
                     // Cancelled
                     $order->update_status('cancelled', __('Skrill payment cancelled', 'jigoshop'));
                     break;
                 default:
                     $order->update_status('cancelled', __('Skrill exception', 'jigoshop'));
                     break;
             }
         }
         exit;
     }
 }
 function check_ipn_response()
 {
     $this->kaznachey_init();
     $request_json = file_get_contents('php://input');
     $request = json_decode($request_json, true);
     $request_sign = md5($request["ErrorCode"] . $request["OrderId"] . $request["MerchantInternalPaymentId"] . $request["MerchantInternalUserId"] . number_format($request["OrderSum"], 2, ".", "") . number_format($request["Sum"], 2, ".", "") . strtoupper($request["Currency"]) . $request["CustomMerchantInfo"] . strtoupper($this->merchnatSecretKey));
     if ($request['SignatureEx'] == $request_sign) {
         $order = new jigoshop_order($request["MerchantInternalPaymentId"]);
         if ($order->id) {
             $order->add_order_note(__('Заказ оплачен. Платеж через www.kaznachey.ua', 'jigoshop'));
             $order->payment_complete();
         }
     }
 }