Exemplo n.º 1
0
function jigoshop_checkout( $atts ) {

	if (!defined('JIGOSHOP_CHECKOUT')) define('JIGOSHOP_CHECKOUT', true);
	
	if (sizeof(jigoshop_cart::$cart_contents)==0) :
		wp_redirect(get_permalink(get_option('jigoshop_cart_page_id')));
		exit;
	endif;
	
	$non_js_checkout = (isset($_POST['update_totals']) && $_POST['update_totals']) ? true : false;
	
	$_checkout = jigoshop_checkout::instance();
	
	$_checkout->process_checkout();
	
	$result = jigoshop_cart::check_cart_item_stock();
	
	if (is_wp_error($result)) jigoshop::add_error( $result->get_error_message() );
	
	if ( jigoshop::error_count()==0 && $non_js_checkout) jigoshop::add_message( __('The order totals have been updated. Please confirm your order by pressing the Place Order button at the bottom of the page.', 'jigoshop') );
	
	jigoshop::show_messages();
	
	jigoshop_get_template('checkout/form.php', false);
	
}
 /**
  * @param int $order_id
  * @return array
  */
 function process_payment($order_id)
 {
     $order = new jigoshop_order($order_id);
     $this->init_paymentwall_configs();
     $return = array('result' => 'fail', 'redirect' => '');
     $charge = new Paymentwall_Charge();
     try {
         $charge->create(array_merge($this->prepare_user_profile_data($order), $this->prepare_card_info($order)));
         $response = $charge->getPublicData();
         if ($charge->isSuccessful()) {
             if ($charge->isCaptured()) {
                 // Add order note
                 $order->add_order_note(sprintf(__('Brick payment approved (ID: %s, Card: xxxx-%s)', PW_JIGO_TEXT_DOMAIN), $charge->getId(), $charge->getCard()->getAlias()));
                 // Payment complete
                 $order->payment_complete();
                 $return['result'] = 'success';
                 $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
                 $return['redirect'] = add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect)));
             } elseif ($charge->isUnderReview()) {
                 $order->update_status('on-hold');
             }
             // Clear shopping cart
             jigoshop_cart::empty_cart();
         } else {
             $errors = json_decode($response, true);
             jigoshop::add_error(__($errors['error']['message']), 'error');
         }
     } catch (Exception $e) {
         jigoshop::add_error($e->getMessage(), 'error');
     }
     // Return redirect
     return $return;
 }
Exemplo n.º 3
0
function jigoshop_checkout($atts)
{
    if (!defined('JIGOSHOP_CHECKOUT')) {
        define('JIGOSHOP_CHECKOUT', true);
    }
    $non_js_checkout = isset($_POST['update_totals']) && $_POST['update_totals'] ? true : false;
    $result = jigoshop_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        jigoshop::add_error($result->get_error_message());
    }
    if (!jigoshop::has_errors() && $non_js_checkout) {
        jigoshop::add_message(__('The order totals have been updated. Please confirm your order by pressing the Place Order button at the bottom of the page.', 'jigoshop'));
    }
    jigoshop::show_messages();
    jigoshop_get_template('checkout/form.php', false);
}
Exemplo n.º 4
0
function jigoshop_cart($atts)
{
    unset(jigoshop_session::instance()->selected_rate_id);
    // Process Discount Codes
    if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) {
        $coupon_code = sanitize_title($_POST['coupon_code']);
        jigoshop_cart::add_discount($coupon_code);
    } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) {
        // Update Shipping
        unset(jigoshop_session::instance()->chosen_shipping_method_id);
        $country = $_POST['calc_shipping_country'];
        $state = $_POST['calc_shipping_state'];
        $postcode = $_POST['calc_shipping_postcode'];
        if ($postcode && !jigoshop_validation::is_postcode($postcode, $country)) {
            jigoshop::add_error(__('Please enter a valid postcode/ZIP.', 'jigoshop'));
            $postcode = '';
        } elseif ($postcode) {
            $postcode = jigoshop_validation::format_postcode($postcode, $country);
        }
        if ($country) {
            // Update customer location
            jigoshop_customer::set_location($country, $state, $postcode);
            jigoshop_customer::set_shipping_location($country, $state, $postcode);
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        } else {
            jigoshop_customer::set_shipping_location('', '', '');
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        }
    } elseif (isset($_POST['shipping_rates'])) {
        $rates_params = explode(":", $_POST['shipping_rates']);
        $available_methods = jigoshop_shipping::get_available_shipping_methods();
        $shipping_method = $available_methods[$rates_params[0]];
        if ($rates_params[1] != null) {
            jigoshop_session::instance()->selected_rate_id = $rates_params[1];
        }
        $shipping_method->choose();
        // chooses the method selected by user.
    }
    // Re-Calc prices. This needs to happen every time the cart page is loaded and after checking post results.
    jigoshop_cart::calculate_totals();
    $result = jigoshop_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        jigoshop::add_error($result->get_error_message());
    }
    jigoshop_render('shortcode/cart', array('cart' => jigoshop_cart::get_cart(), 'coupons' => jigoshop_cart::get_coupons()));
}
Exemplo n.º 5
0
	/**
	 * Applies a coupon code
	 *
	 * @param   string	code	The code to apply
	 * @return   bool	True if the coupon is applied, false if it does not exist or cannot be applied
	 */
	function add_discount( $coupon_code ) {

		if ($the_coupon = jigoshop_coupons::get_coupon($coupon_code)) :

			// Check if applied
			if (jigoshop_cart::has_discount($coupon_code)) :
				jigoshop::add_error( __('Discount code already applied!', 'jigoshop') );
				return false;
			endif;

			// Check it can be used with cart
			if (!jigoshop_coupons::is_valid($coupon_code)) :
				jigoshop::add_error( __('Invalid coupon.', 'jigoshop') );
				return false;
			endif;

			// If its individual use then remove other coupons
			if ($the_coupon['individual_use']=='yes') :
				self::$applied_coupons = array();
			endif;

			foreach (self::$applied_coupons as $coupon) :
				$coupon = jigoshop_coupons::get_coupon($coupon);
				if ($coupon['individual_use']=='yes') :
					self::$applied_coupons = array();
				endif;
			endforeach;

			self::$applied_coupons[] = $coupon_code;
			self::set_session();
			jigoshop::add_message( __('Discount code applied successfully.', 'jigoshop') );
			return true;

		else :
			jigoshop::add_error( __('Coupon does not exist!', 'jigoshop') );
			return false;
		endif;
		return false;

	}
Exemplo n.º 6
0
 private function process_gateway_http_redirect($order, $gateway)
 {
     $data = new Pronamic_WP_Pay_Extensions_Jigoshop_PaymentData($order);
     $payment = Pronamic_WP_Pay_Plugin::start($this->config_id, $gateway, $data);
     $error = $gateway->get_error();
     if (is_wp_error($error)) {
         jigoshop::add_error(Pronamic_WP_Pay_Plugin::get_default_error_message());
         if (current_user_can('administrator')) {
             foreach ($error->get_error_codes() as $code) {
                 jigoshop::add_error($error->get_error_message($code));
             }
         }
         // see https://github.com/jigoshop/jigoshop/blob/1.4.9/shortcodes/pay.php#L55
         return array('result' => 'failed');
     } else {
         // We can't redirect directly to the action URL because of Jigoshop wp_safe_redirect() usage.
         // $url = $payment->get_action_url();
         $url = add_query_arg('payment_redirect', $payment->get_id(), home_url('/'));
         return array('result' => 'success', 'redirect' => $url);
     }
 }
        exit;
    }
    if ($isViewOrder) {
        if (!isset($_GET['order'])) {
            wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
            exit;
        }
        $order = new jigoshop_order($_GET['order']);
        if ($order->user_id != get_current_user_id()) {
            wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
            exit;
        }
    }
    if ($isChangePassword) {
        $user_id = get_current_user_id();
        if ($_POST && $user_id > 0 && jigoshop::verify_nonce('change_password')) {
            if ($_POST['password-1'] && $_POST['password-2']) {
                if ($_POST['password-1'] == $_POST['password-2']) {
                    wp_update_user(array('ID' => $user_id, 'user_pass' => $_POST['password-1']));
                    jigoshop::add_message(__('Password changed successfully.', 'jigoshop'));
                    wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id(JIGOSHOP_MY_ACCOUNT))));
                    exit;
                } else {
                    jigoshop::add_error(__('Passwords do not match.', 'jigoshop'));
                }
            } else {
                jigoshop::add_error(__('Please enter your password.', 'jigoshop'));
            }
        }
    }
});
	/** Process the checkout after the confirm order button is pressed */
	function process_checkout() {
	
		global $wpdb;
		
		do_action('jigoshop_before_checkout_process');
		
		if (isset($_POST) && $_POST && !isset($_POST['login'])) :

			jigoshop_cart::calculate_totals();
			
			jigoshop::verify_nonce('process_checkout');
			
			if (sizeof(jigoshop_cart::$cart_contents)==0) :
				jigoshop::add_error( sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>','jigoshop'), home_url()) );
			endif;
						
			// Checkout fields
			$this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? jigowatt_clean($_POST['shiptobilling']) : '';
			$this->posted['payment_method'] = isset($_POST['payment_method']) ? jigowatt_clean($_POST['payment_method']) : '';
			$this->posted['shipping_method'] = isset($_POST['shipping_method']) ? jigowatt_clean($_POST['shipping_method']) : '';
			$this->posted['order_comments'] = isset($_POST['order_comments']) ? jigowatt_clean($_POST['order_comments']) : '';
			$this->posted['terms'] = isset($_POST['terms']) ? jigowatt_clean($_POST['terms']) : '';
			$this->posted['createaccount'] = isset($_POST['createaccount']) ? jigowatt_clean($_POST['createaccount']) : '';
			$this->posted['account-username'] = isset($_POST['account-username']) ? jigowatt_clean($_POST['account-username']) : '';
			$this->posted['account-password'] = isset($_POST['account-password']) ? jigowatt_clean($_POST['account-password']) : '';
			$this->posted['account-password-2'] = isset($_POST['account-password-2']) ? jigowatt_clean($_POST['account-password-2']) : '';
			
			if (jigoshop_cart::ship_to_billing_address_only()) $this->posted['shiptobilling'] = 'true';
			
			// Billing Information
			foreach ($this->billing_fields as $field) :
				
				$this->posted[$field['name']] = isset($_POST[$field['name']]) ? jigowatt_clean($_POST[$field['name']]) : '';
				
				// Format
				if (isset($field['format'])) switch ( $field['format'] ) :
					case 'postcode' : $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break;
				endswitch;
				
				// Required
				if ( isset($field['required']) && $field['required'] && empty($this->posted[$field['name']]) ) jigoshop::add_error( $field['label'] . __(' (billing) is a required field.','jigoshop') );
	
				// Validation
				if (isset($field['validate']) && !empty($this->posted[$field['name']])) switch ( $field['validate'] ) :
					case 'phone' :
						if (!jigoshop_validation::is_phone( $this->posted[$field['name']] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid number.','jigoshop') ); endif;
					break;
					case 'email' :
						if (!jigoshop_validation::is_email( $this->posted[$field['name']] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid email address.','jigoshop') ); endif;
					break;
					case 'postcode' :
						if (!jigoshop_validation::is_postcode( $this->posted[$field['name']], $_POST['billing-country'] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid postcode/ZIP.','jigoshop') ); 
						else :
							$this->posted[$field['name']] = jigoshop_validation::format_postcode( $this->posted[$field['name']], $_POST['billing-country'] );
						endif;
					break;
				endswitch;
				
			endforeach;
			
			// Shipping Information
			if (jigoshop_cart::needs_shipping() && !jigoshop_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) :
				
				foreach ($this->shipping_fields as $field) :
					if (isset( $_POST[$field['name']] )) $this->posted[$field['name']] = jigowatt_clean($_POST[$field['name']]); else $this->posted[$field['name']] = '';
					
					// Format
					if (isset($field['format'])) switch ( $field['format'] ) :
						case 'postcode' : $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break;
					endswitch;
					
					// Required
					if ( isset($field['required']) && $field['required'] && empty($this->posted[$field['name']]) ) jigoshop::add_error( $field['label'] . __(' (shipping) is a required field.','jigoshop') );
		
					// Validation
					if (isset($field['validate']) && !empty($this->posted[$field['name']])) switch ( $field['validate'] ) :
						case 'postcode' :
							if (!jigoshop_validation::is_postcode( $this->posted[$field['name']], $this->posted['shipping-country'] )) : jigoshop::add_error( $field['label'] . __(' (shipping) is not a valid postcode/ZIP.','jigoshop') ); 
							else :
								$this->posted[$field['name']] = jigoshop_validation::format_postcode( $this->posted[$field['name']], $this->posted['shipping-country'] );
							endif;
						break;
					endswitch;
					
				endforeach;
			
			endif;

			if (is_user_logged_in()) :
				$this->creating_account = false;
			elseif (isset($this->posted['createaccount']) && $this->posted['createaccount']) :
				$this->creating_account = true;
			elseif ($this->must_create_account) :
				$this->creating_account = true;
			else :
				$this->creating_account = false;
			endif;
			
			if ($this->creating_account && !$user_id) :
			
				if ( empty($this->posted['account-username']) ) jigoshop::add_error( __('Please enter an account username.','jigoshop') );
				if ( empty($this->posted['account-password']) ) jigoshop::add_error( __('Please enter an account password.','jigoshop') );
				if ( $this->posted['account-password-2'] !== $this->posted['account-password'] ) jigoshop::add_error( __('Passwords do not match.','jigoshop') );
			
				// Check the username
				if ( !validate_username( $this->posted['account-username'] ) ) :
					jigoshop::add_error( __('Invalid email/username.','jigoshop') );
				elseif ( username_exists( $this->posted['account-username'] ) ) :
					jigoshop::add_error( __('An account is already registered with that username. Please choose another.','jigoshop') );
				endif;
				
				// Check the e-mail address
				if ( email_exists( $this->posted['billing-email'] ) ) :
					jigoshop::add_error( __('An account is already registered with your email address. Please login.','jigoshop') );
				endif;
			endif;
			
			// Terms
			if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && get_option('jigoshop_terms_page_id')>0 ) jigoshop::add_error( __('You must accept our Terms &amp; Conditions.','jigoshop') );
			
			if (jigoshop_cart::needs_shipping()) :
			
				// Shipping Method
				$available_methods = jigoshop_shipping::get_available_shipping_methods();
				if (!isset($available_methods[$this->posted['shipping_method']])) :
					jigoshop::add_error( __('Invalid shipping method.','jigoshop') );
				endif;	
			
			endif;	
			
			if (jigoshop_cart::needs_payment()) :
				// Payment Method
				$available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
				if (!isset($available_gateways[$this->posted['payment_method']])) :
					jigoshop::add_error( __('Invalid payment method.','jigoshop') );
				else :
					// Payment Method Field Validation
					$available_gateways[$this->posted['payment_method']]->validate_fields();
				endif;
			endif;
					
			if (!isset($_POST['update_totals']) && jigoshop::error_count()==0) :
				
				$user_id = get_current_user_id();
				
				while (1) :
					
					// Create customer account and log them in
					if ($this->creating_account && !$user_id) :
				
						$reg_errors = new WP_Error();
						do_action('register_post', $this->posted['billing-email'], $this->posted['billing-email'], $reg_errors);
						$errors = apply_filters( 'registration_errors', $reg_errors, $this->posted['billing-email'], $this->posted['billing-email'] );
				
		                // if there are no errors, let's create the user account
						if ( !$reg_errors->get_error_code() ) :
		
			                $user_pass = $this->posted['account-password'];
			                $user_id = wp_create_user( $this->posted['account-username'], $user_pass, $this->posted['billing-email'] );
			                if ( !$user_id ) {
			                	jigoshop::add_error( sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'jigoshop'), get_option('admin_email')));
			                    break;
			                }
		
		                    // Change role
		                    wp_update_user( array ('ID' => $user_id, 'role' => 'customer') ) ;
		
		                    // send the user a confirmation and their login details
		                    wp_new_user_notification( $user_id, $user_pass );
		
		                    // set the WP login cookie
		                    $secure_cookie = is_ssl() ? true : false;
		                    wp_set_auth_cookie($user_id, true, $secure_cookie);
						
						else :
							jigoshop::add_error( $reg_errors->get_error_message() );
		                	break;                    
						endif;
						
					endif;

					// Get shipping/billing
					if ( !empty($this->posted['shiptobilling']) ) :
					
						$shipping_first_name = $this->posted['billing-first_name'];
						$shipping_last_name = $this->posted['billing-last_name'];
						$shipping_company = $this->posted['billing-company'];
						$shipping_address_1 = $this->posted['billing-address'];
						$shipping_address_2 = $this->posted['billing-address-2'];
						$shipping_city = $this->posted['billing-city'];							
						$shipping_state = $this->posted['billing-state'];
						$shipping_postcode = $this->posted['billing-postcode'];	
						$shipping_country = $this->posted['billing-country'];
						
					elseif ( jigoshop_cart::needs_shipping() ) :
								
						$shipping_first_name = $this->posted['shipping-first_name'];
						$shipping_last_name = $this->posted['shipping-last_name'];
						$shipping_company = $this->posted['shipping-company'];
						$shipping_address_1 = $this->posted['shipping-address'];
						$shipping_address_2 = $this->posted['shipping-address-2'];
						$shipping_city = $this->posted['shipping-city'];							
						$shipping_state = $this->posted['shipping-state'];
						$shipping_postcode = $this->posted['shipping-postcode'];	
						$shipping_country = $this->posted['shipping-country'];
						
					endif;
					
					// Save billing/shipping to user meta fields
					if ($user_id>0) :
						update_user_meta( $user_id, 'billing-first_name', $this->posted['billing-first_name'] );
						update_user_meta( $user_id, 'billing-last_name', $this->posted['billing-last_name'] );
						update_user_meta( $user_id, 'billing-company', $this->posted['billing-company'] );
						update_user_meta( $user_id, 'billing-email', $this->posted['billing-email'] );
						update_user_meta( $user_id, 'billing-address', $this->posted['billing-address'] );
						update_user_meta( $user_id, 'billing-address-2', $this->posted['billing-address-2'] );
						update_user_meta( $user_id, 'billing-city', $this->posted['billing-city'] );
						update_user_meta( $user_id, 'billing-postcode', $this->posted['billing-postcode'] );
						update_user_meta( $user_id, 'billing-country', $this->posted['billing-country'] );
						update_user_meta( $user_id, 'billing-state', $this->posted['billing-state'] );
						update_user_meta( $user_id, 'billing-phone', $this->posted['billing-phone'] );

						if ( empty($this->posted['shiptobilling']) && jigoshop_cart::needs_shipping() ) :
							update_user_meta( $user_id, 'shipping-first_name', $this->posted['shipping-first_name'] );
							update_user_meta( $user_id, 'shipping-last_name', $this->posted['shipping-last_name'] );
							update_user_meta( $user_id, 'shipping-company', $this->posted['shipping-company'] );
							update_user_meta( $user_id, 'shipping-address', $this->posted['shipping-address'] );
							update_user_meta( $user_id, 'shipping-address-2', $this->posted['shipping-address-2'] );
							update_user_meta( $user_id, 'shipping-city', $this->posted['shipping-city'] );
							update_user_meta( $user_id, 'shipping-postcode', $this->posted['shipping-postcode'] );
							update_user_meta( $user_id, 'shipping-country', $this->posted['shipping-country'] );
							update_user_meta( $user_id, 'shipping-state', $this->posted['shipping-state'] );
						elseif ( $this->posted['shiptobilling'] && jigoshop_cart::needs_shipping() ) :
							update_user_meta( $user_id, 'shipping-first_name', $this->posted['billing-first_name'] );
							update_user_meta( $user_id, 'shipping-last_name', $this->posted['billing-last_name'] );
							update_user_meta( $user_id, 'shipping-company', $this->posted['billing-company'] );
							update_user_meta( $user_id, 'shipping-address', $this->posted['billing-address'] );
							update_user_meta( $user_id, 'shipping-address-2', $this->posted['billing-address-2'] );
							update_user_meta( $user_id, 'shipping-city', $this->posted['billing-city'] );
							update_user_meta( $user_id, 'shipping-postcode', $this->posted['billing-postcode'] );
							update_user_meta( $user_id, 'shipping-country', $this->posted['billing-country'] );
							update_user_meta( $user_id, 'shipping-state', $this->posted['billing-state'] );
						endif;
						
					endif;
					
					// Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected last time.
					
					$_tax = new jigoshop_tax();
					
					$order_data = array(
						'post_type' => 'shop_order',
						'post_title' => 'Order &ndash; '.date('F j, Y @ h:i A'),
						'post_status' => 'publish',
						'post_excerpt' => $this->posted['order_comments'],
						'post_author' => 1
					);
					
					// Order meta data
					$data = array();
					$data['billing_first_name'] 	= $this->posted['billing-first_name'];
					$data['billing_last_name'] 		= $this->posted['billing-last_name'];
					$data['billing_company'] 		= $this->posted['billing-company'];
					$data['billing_address_1'] 		= $this->posted['billing-address'];
					$data['billing_address_2'] 		= $this->posted['billing-address-2'];
					$data['billing_city'] 			= $this->posted['billing-city'];
					$data['billing_postcode'] 		= $this->posted['billing-postcode'];
					$data['billing_country'] 		= $this->posted['billing-country'];
					$data['billing_state'] 			= $this->posted['billing-state'];
					$data['billing_email']			= $this->posted['billing-email'];
					$data['billing_phone']			= $this->posted['billing-phone'];
					$data['shipping_first_name'] 	= $shipping_first_name;
					$data['shipping_last_name'] 	= $shipping_last_name;
					$data['shipping_company']	 	= $shipping_company;
					$data['shipping_address_1']		= $shipping_address_1;
					$data['shipping_address_2']		= $shipping_address_2;
					$data['shipping_city']			= $shipping_city;
					$data['shipping_postcode']		= $shipping_postcode;
					$data['shipping_country']		= $shipping_country;
					$data['shipping_state']			= $shipping_state;
					$data['shipping_method']		= $this->posted['shipping_method'];
					$data['payment_method']			= $this->posted['payment_method'];
					$data['order_subtotal']			= number_format(jigoshop_cart::$subtotal_ex_tax, 2, '.', '');
					$data['order_shipping']			= number_format(jigoshop_cart::$shipping_total, 2, '.', '');
					$data['order_discount']			= number_format(jigoshop_cart::$discount_total, 2, '.', '');
					$data['order_tax']				= number_format(jigoshop_cart::$tax_total, 2, '.', '');
					$data['order_shipping_tax']		= number_format(jigoshop_cart::$shipping_tax_total, 2, '.', '');
					$data['order_total']			= number_format(jigoshop_cart::$total, 2, '.', '');
					
					// Cart items
					$order_items = array();
					
					foreach (jigoshop_cart::$cart_contents as $item_id => $values) :
						
						$_product = $values['data'];
			
						// Calc item tax to store
						$rate = '';
						if ( $_product->is_taxable()) :
							$rate = $_tax->get_rate( $_product->data['tax_class'] );
						endif;
						
						$order_items[] = array(
					 		'id' 		=> $item_id,
					 		'name' 		=> $_product->get_title(),
					 		'qty' 		=> (int) $values['quantity'],
					 		'cost' 		=> $_product->get_price_excluding_tax(),
					 		'taxrate' 	=> $rate
					 	);
					 	
					 	// Check stock levels
					 	if ($_product->managing_stock()) :
							if (!$_product->is_in_stock() || !$_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 apologise for any inconvenience caused.', 'jigoshop'), $_product->get_title() ) );
		                		break;
								
							endif;
						else :
						
							if (!$_product->is_in_stock()) :
							
								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 apologise for any inconvenience caused.', 'jigoshop'), $_product->get_title() ) );
		                		break;

							endif;
							
						endif;
					 	
					endforeach;
					
					if (jigoshop::error_count()>0) break;
					
					// Insert or update the post data
					if (isset($_SESSION['order_awaiting_payment']) && $_SESSION['order_awaiting_payment'] > 0) :
						
						$order_id = (int) $_SESSION['order_awaiting_payment'];
						$order_data['ID'] = $order_id;
						wp_update_post( $order_data );
					
					else :
						$order_id = wp_insert_post( $order_data );
						
						if (is_wp_error($order_id)) :
							jigoshop::add_error( 'Error: Unable to create order. Please try again.' );
			                break;
						endif;
					endif;

					// 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);
					
					// Inserted successfully 
					do_action('jigoshop_new_order', $order_id);

					if (jigoshop_cart::needs_payment()) :
						
						// Store Order ID in session so it can be re-used after payment failure
						$_SESSION['order_awaiting_payment'] = $order_id;
					
						// Process Payment
						$result = $available_gateways[$this->posted['payment_method']]->process_payment( $order_id );
						
						// Redirect to success/confirmation/payment page
						if ($result['result']=='success') :
						
							if (is_ajax()) : 
								ob_clean();
								echo json_encode($result);
								exit;
							else :
								wp_safe_redirect( $result['redirect'] );
								exit;
							endif;
							
						endif;
					
					else :
					
						// No payment was required for order
						$order->payment_complete();
						
						// Empty the Cart
						jigoshop_cart::empty_cart();
						
						// Redirect to success/confirmation/payment page
						if (is_ajax()) : 
							ob_clean();
							echo json_encode( array('redirect'	=> get_permalink(get_option('jigoshop_thanks_page_id'))) );
							exit;
						else :
							wp_safe_redirect( get_permalink(get_option('jigoshop_thanks_page_id')) );
							exit;
						endif;
						
					endif;
					
					// Break out of loop
					break;
				
				endwhile;
	
			endif;
			
			// If we reached this point then there were errors
			if (is_ajax()) : 
				ob_clean();
				jigoshop::show_messages();
				exit;
			else :
				jigoshop::show_messages();
			endif;
		
		endif;
	}
Exemplo n.º 9
0
/**
 * Outputs the pay page - payment gateways can hook in here to show payment forms etc
 **/
function jigoshop_pay() {
	
	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;
					endif;
				else :
					
					// No payment was required for order
					$order->payment_complete();
					wp_safe_redirect( get_permalink(get_option('jigoshop_thanks_page_id')) );
					exit;
					
				endif;
	
			endif;
			
			// Show messages
			jigoshop::show_messages();
			
			// Show form
			jigoshop_pay_for_existing_order( $order );
		
		elseif ($order->status!='pending') :
			
			jigoshop::add_error( __('Your order has already been paid for. Please contact us if you need assistance.', 'jigoshop') );
			
			jigoshop::show_messages();
			
		else :
		
			jigoshop::add_error( __('Invalid order.', 'jigoshop') );
			
			jigoshop::show_messages();
			
		endif;
		
	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') :
		
				?>
				<ul class="order_details">
					<li class="order">
						<?php _e('Order:', 'jigoshop'); ?>
						<strong># <?php echo $order->id; ?></strong>
					</li>
					<li class="date">
						<?php _e('Date:', 'jigoshop'); ?>
						<strong><?php echo date(get_option('date_format'), strtotime($order->order_date)); ?></strong>
					</li>
					<li class="total">
						<?php _e('Total:', 'jigoshop'); ?>
						<strong><?php echo jigoshop_price($order->order_total); ?></strong>
					</li>
					<li class="method">
						<?php _e('Payment method:', 'jigoshop'); ?>
						<strong><?php 
							$gateways = jigoshop_payment_gateways::payment_gateways();
							if (isset($gateways[$order->payment_method])) echo $gateways[$order->payment_method]->title;
							else echo $order->payment_method; 
						?></strong>
					</li>
				</ul>
				
				<?php do_action( 'receipt_' . $order->payment_method, $order_id ); ?>
				
				<div class="clear"></div>
				<?php
				
			else :
			
				wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
				exit;
				
			endif;
			
		else :
			
			wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
			exit;
			
		endif;

	endif;
}
Exemplo n.º 10
0
 /**
  * Applies a coupon code
  *
  * @param string $coupon_code The code to apply
  * @return bool True if the coupon is applied, false if it does not exist or cannot be applied
  */
 public static function add_discount($coupon_code)
 {
     if (!self::is_valid_coupon($coupon_code)) {
         return false;
     }
     // Check for other individual_use coupons before adding this coupon.
     foreach (self::get_coupons() as $code) {
         $current = JS_Coupons::get_coupon($code);
         if ($current['individual_use']) {
             jigoshop::add_error(__("There is already an 'individual use' coupon on the Cart.  No other coupons can be added until it is removed.", 'jigoshop'));
             return false;
         }
     }
     $coupon = JS_Coupons::get_coupon($coupon_code);
     // Remove other coupons if this one is individual_use.
     if ($coupon['individual_use']) {
         if (!empty(self::$applied_coupons)) {
             jigoshop::add_error(__("This is an 'individual use' coupon.  All other discount coupons have been removed.", 'jigoshop'));
             self::$applied_coupons = array();
         }
     }
     // check if coupon is already applied and only add a new coupon
     if (!self::has_discount($coupon_code) && !empty($_POST['coupon_code'])) {
         self::$applied_coupons[] = $coupon_code;
     }
     // select free shipping method
     if ($coupon['free_shipping']) {
         if (Jigoshop_Base::get_options()->get('jigoshop_select_free_shipping_method') == 'yes') {
             jigoshop_session::instance()->chosen_shipping_method_id = 'free_shipping';
         }
     }
     jigoshop_session::instance()->coupons = self::$applied_coupons;
     jigoshop::add_message(__('Discount coupon applied successfully.', 'jigoshop'));
     return true;
 }
Exemplo n.º 11
0
function jigoshop_change_password() {

	$user_id = get_current_user_id();
	
	if (is_user_logged_in()) :
		
		if ($_POST) :
			
			if ($user_id>0 && jigoshop::verify_nonce('change_password')) :
				
				if ( $_POST['password-1'] && $_POST['password-2']  ) :
					
					if ( $_POST['password-1']==$_POST['password-2'] ) :
	
						wp_update_user( array ('ID' => $user_id, 'user_pass' => $_POST['password-1']) ) ;
						
						wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
						exit;
						
					else :
					
						jigoshop::add_error( __('Passwords do not match.','jigoshop') );
					
					endif;
				
				else :
				
					jigoshop::add_error( __('Please enter your password.','jigoshop') );
					
				endif;			
				
			endif;
		
		endif;
		
		jigoshop::show_messages();

		?>
		<form action="<?php echo get_permalink(get_option('jigoshop_change_password_page_id')); ?>" method="post">
	
			<p class="form-row form-row-first">
				<label for="password-1"><?php _e('New password', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="password" class="input-text" name="password-1" id="password-1" />
			</p>
			<p class="form-row form-row-last">
				<label for="password-2"><?php _e('Re-enter new password', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="password" class="input-text" name="password-2" id="password-2" />
			</p>
			<div class="clear"></div>
			<?php jigoshop::nonce_field('change_password')?>
			<p><input type="submit" class="button" name="save_password" value="<?php _e('Save', 'jigoshop'); ?>" /></p>
	
		</form>
		<?php
		
	else :
	
		wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
		exit;
		
	endif;
	
}
Exemplo n.º 12
0
 /**
  * Check a nonce and sets jigoshop error in case it is invalid
  * To fail silently, set the error_message to an empty string
  *
  * @param  string $action then nonce action
  * @return   bool
  */
 public static function verify_nonce($action)
 {
     $name = '_n';
     $action = 'jigoshop-' . $action;
     $request = array_merge($_GET, $_POST);
     if (!wp_verify_nonce($request[$name], $action)) {
         jigoshop::add_error(__('Action failed. Please refresh the page and retry.', 'jigoshop'));
         return false;
     }
     return true;
 }
Exemplo n.º 13
0
function jigoshop_cart( $atts ) {
	
	$errors = array();
	
	// Process Discount Codes
	if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) :
	
		$coupon_code = stripslashes(trim($_POST['coupon_code']));
		jigoshop_cart::add_discount($coupon_code);

	// Remove from cart
	elseif ( isset($_GET['remove_item']) && $_GET['remove_item'] > 0  && jigoshop::verify_nonce('cart', '_GET')) :
	
		jigoshop_cart::set_quantity( $_GET['remove_item'], 0 );
		
		jigoshop::add_message( __('Cart updated.', 'jigoshop') );
	
	// Update Cart
	elseif (isset($_POST['update_cart']) && $_POST['update_cart']  && jigoshop::verify_nonce('cart')) :
		
		$cart_totals = $_POST['cart'];
		
		if (sizeof(jigoshop_cart::$cart_contents)>0) : 
			foreach (jigoshop_cart::$cart_contents as $item_id => $values) :
				
				if (isset($cart_totals[$item_id]['qty'])) jigoshop_cart::set_quantity( $item_id, $cart_totals[$item_id]['qty'] );
				
			endforeach;
		endif;
		
		jigoshop::add_message( __('Cart updated.', 'jigoshop') );
	
	// Update Shipping
	elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) :

		unset($_SESSION['_chosen_method_id']);
		$country 	= $_POST['calc_shipping_country'];
		$state 	= $_POST['calc_shipping_state'];
		
		$postcode 	= $_POST['calc_shipping_postcode'];
		
		if ($postcode && !jigoshop_validation::is_postcode( $postcode, $country )) : 
			jigoshop::add_error( __('Please enter a valid postcode/ZIP.','jigoshop') ); 
			$postcode = '';
		elseif ($postcode) :
			$postcode = jigoshop_validation::format_postcode( $postcode, $country );
		endif;
		
		if ($country) :
		
			// Update customer location
			jigoshop_customer::set_location( $country, $state, $postcode );
			jigoshop_customer::set_shipping_location( $country, $state, $postcode );
			
			// Re-calc price
			jigoshop_cart::calculate_totals();
			
			jigoshop::add_message(  __('Shipping costs updated.', 'jigoshop') );
		
		else :
		
			jigoshop_customer::set_shipping_location( '', '', '' );
			
			jigoshop::add_message(  __('Shipping costs updated.', 'jigoshop') );
			
		endif;
			
	endif;
	
	$result = jigoshop_cart::check_cart_item_stock();
	if (is_wp_error($result)) :
		jigoshop::add_error( $result->get_error_message() );
	endif;
	
	jigoshop::show_messages();
	
	if (sizeof(jigoshop_cart::$cart_contents)==0) :
		echo '<p>'.__('Your cart is empty.', 'jigoshop').'</p>';
		return;
	endif;
	
	?>
	<form action="<?php echo jigoshop_cart::get_cart_url(); ?>" method="post">
	<table class="shop_table cart" cellspacing="0">
		<thead>
			<tr>
				<th class="product-remove"></th>
				<th class="product-thumbnail"></th>
				<th class="product-name"><span class="nobr"><?php _e('Product Name', 'jigoshop'); ?></span></th>
				<th class="product-price"><span class="nobr"><?php _e('Unit Price', 'jigoshop'); ?></span></th>
				<th class="product-quantity"><?php _e('Quantity', 'jigoshop'); ?></th>
				<th class="product-subtotal"><?php _e('Price', 'jigoshop'); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			if (sizeof(jigoshop_cart::$cart_contents)>0) : 
				foreach (jigoshop_cart::$cart_contents as $item_id => $values) :
					$_product = $values['data'];
					if ($_product->exists() && $values['quantity']>0) :
						echo '
							<tr>
								<td class="product-remove"><a href="'.jigoshop_cart::get_remove_url($item_id).'" class="remove" title="Remove this item">&times;</a></td>
								<td class="product-thumbnail"><a href="'.get_permalink($item_id).'">';
						
						if (has_post_thumbnail($item_id)) echo get_the_post_thumbnail($item_id, 'shop_tiny'); 
						else echo '<img src="'.jigoshop::plugin_url(). '/assets/images/placeholder.png" alt="Placeholder" width="'.jigoshop::get_var('shop_tiny_w').'" height="'.jigoshop::get_var('shop_tiny_h').'" />'; 
							
						echo '	</a></td>
								<td class="product-name"><a href="'.get_permalink($item_id).'">' . apply_filters('jigoshop_cart_product_title', $_product->get_title(), $_product) . '</a></td>
								<td class="product-price">'.jigoshop_price($_product->get_price()).'</td>
								<td class="product-quantity"><div class="quantity"><input name="cart['.$item_id.'][qty]" value="'.$values['quantity'].'" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div></td>
								<td class="product-subtotal">'.jigoshop_price($_product->get_price()*$values['quantity']).'</td>
							</tr>';
					endif;
				endforeach; 
			endif;
			
			do_action( 'jigoshop_shop_table_cart' );
			?>
			<tr>
				<td colspan="6" class="actions">
					<div class="coupon">
						<label for="coupon_code"><?php _e('Coupon', 'jigoshop'); ?>:</label> <input name="coupon_code" class="input-text" id="coupon_code" value="" /> <input type="submit" class="button" name="apply_coupon" value="<?php _e('Apply Coupon', 'jigoshop'); ?>" />
					</div>
					<?php jigoshop::nonce_field('cart') ?>
					<input type="submit" class="button" name="update_cart" value="<?php _e('Update Shopping Cart', 'jigoshop'); ?>" /> <a href="<?php echo jigoshop_cart::get_checkout_url(); ?>" class="checkout-button button-alt"><?php _e('Proceed to Checkout &rarr;', 'jigoshop'); ?></a>
				</td>
			</tr>
		</tbody>
	</table>
	</form>
	<div class="cart-collaterals">
		
		<?php do_action('cart-collaterals'); ?>

		<div class="cart_totals">
		<?php
		// Hide totals if customer has set location and there are no methods going there
		$available_methods = jigoshop_shipping::get_available_shipping_methods();
		if ($available_methods || !jigoshop_customer::get_shipping_country() || !jigoshop_shipping::$enabled ) : 
			?>
			<h2><?php _e('Cart Totals', 'jigoshop'); ?></h2>
			<table cellspacing="0" cellpadding="0">
				<tbody>
					<tr>
						<th><?php _e('Subtotal', 'jigoshop'); ?></th>
						<td><?php echo jigoshop_cart::get_cart_subtotal(); ?></td>
					</tr>
					
					<?php if (jigoshop_cart::get_cart_shipping_total()) : ?><tr>
						<th><?php _e('Shipping', 'jigoshop'); ?> <small><?php echo jigoshop_countries::shipping_to_prefix().' '.jigoshop_countries::$countries[ jigoshop_customer::get_shipping_country() ]; ?></small></th>
						<td><?php echo jigoshop_cart::get_cart_shipping_total(); ?> <small><?php echo jigoshop_cart::get_cart_shipping_title(); ?></small></td>
					</tr><?php endif; ?>
					<?php if (jigoshop_cart::get_cart_tax()) : ?><tr>
						<th><?php _e('Tax', 'jigoshop'); ?> <?php if (jigoshop_customer::is_customer_outside_base()) : ?><small><?php echo sprintf(__('estimated for %s', 'jigoshop'), jigoshop_countries::estimated_for_prefix() . jigoshop_countries::$countries[ jigoshop_countries::get_base_country() ] ); ?></small><?php endif; ?></th>
						<td><?php 
							echo jigoshop_cart::get_cart_tax(); 
						?></td>
					</tr><?php endif; ?>
					
					<?php if (jigoshop_cart::get_total_discount()) : ?><tr class="discount">
						<th><?php _e('Discount', 'jigoshop'); ?></th>
						<td>-<?php echo jigoshop_cart::get_total_discount(); ?></td>
					</tr><?php endif; ?>
					<tr>
						<th><strong><?php _e('Total', 'jigoshop'); ?></strong></th>
						<td><strong><?php echo jigoshop_cart::get_total(); ?></strong></td>
					</tr>
				</tbody>
			</table>

			<?php
			else :
				echo '<p>'.__('Sorry, it seems that there are no available shipping methods to your location. Please contact us if you require assistance or wish to make alternate arrangements.', 'jigoshop').'</p>';
			endif;
		?>
		</div>
		
		<?php jigoshop_shipping_calculator(); ?>
		
	</div>
	<?php		
}
Exemplo n.º 14
0
    /**
     *  Generate the futurepay payment iframe
     */
    protected function call_futurepay($order_id)
    {
        // Get the order
        $order = new jigoshop_order($order_id);
        $data = array('gmid' => $this->gmid, 'reference' => $order_id . '-' . uniqid(), 'email' => $order->billing_email, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_line_1' => $order->billing_address_1, 'address_line_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $order->billing_country, 'zip' => $order->billing_postcode, 'phone' => $order->billing_phone, 'shipping_address_line_1' => $order->shipping_address_1, 'shipping_address_line_2' => $order->shipping_address_2, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'shipping_zip' => $order->shipping_postcode, 'shipping_date' => date('Y/m/d g:i:s'));
        // for Jigoshop 1.7, FuturePay doesn't allow negative prices (or 0.00 ) which affects discounts
        // with FuturePay doing the calcs, so we will bundle all products into ONE line item with
        // a quantity of ONE and send it that way using the final order total after shipping
        // and discounts are applied
        // all product titles will be comma delimited with their quantities
        $item_names = array();
        if (sizeof($order->items) > 0) {
            foreach ($order->items as $item) {
                $_product = $order->get_product_from_item($item);
                $title = $_product->get_title();
                // if variation, insert variation details into product title
                if ($_product instanceof jigoshop_product_variation) {
                    $title .= ' (' . jigoshop_get_formatted_variation($_product, $item['variation'], true) . ')';
                }
                $item_names[] = $item['qty'] . ' x ' . $title;
            }
        }
        // now add the one line item to the necessary product field arrays
        $data['sku'][] = "Products";
        $data['price'][] = $order->order_total;
        // futurepay only needs final order amount
        $data['tax_amount'][] = 0;
        $data['description'][] = sprintf(__('Order %s', 'jigoshop'), $order->get_order_number()) . ' = ' . implode(', ', $item_names);
        $data['quantity'][] = 1;
        try {
            $response = wp_remote_post(self::$request_url . 'merchant-request-order-token', array('body' => http_build_query($data), 'sslverify' => false));
            // Convert error to exception
            if (is_wp_error($response)) {
                if (class_exists('WP_Exception') && $response instanceof WP_Exception) {
                    throw $response;
                } else {
                    jigoshop_log($response->get_error_message());
                    throw new Exception($response->get_error_message());
                }
            }
            // Fetch the body from the result, any errors should be caught before proceeding
            $response = trim(wp_remote_retrieve_body($response));
            // we need something to validate the response.  Valid transactions begin with 'FPTK'
            if (!strstr($response, 'FPTK')) {
                $error_message = isset(self::$futurepay_errorcodes[$response]) ? self::$futurepay_errorcodes[$response] : __('An unknown error has occured with code = ', 'jigoshop') . $response;
                $order->add_order_note(sprintf(__('FUTUREPAY: %s', 'jigoshop'), $error_message));
                jigoshop::add_error(sprintf(__('FUTUREPAY: %s.  Please try again or select another gateway for your Order.', 'jigoshop'), $error_message));
                wp_safe_redirect(get_permalink(jigoshop_get_page_id('checkout')));
                exit;
            }
            /**
             *  If we're good to go, haul in FuturePay's javascript and display the payment form
             *  so that the customer can enter his ID and password
             */
            echo '<div id="futurepay"></div>';
            echo '<script src="' . self::$request_url . 'cart-integration/' . $response . '"></script>';
            echo '<script type="text/javascript">
				/*<![CDATA[*/
				jQuery(window).load( function() {
					FP.CartIntegration();

					// Need to replace form html
					jQuery("#futurepay").html(FP.CartIntegration.getFormContent());
					FP.CartIntegration.displayFuturePay();
				});

				function FuturePayResponseHandler(response) {
					if (response.error) {
						// TODO: we need something better than this
						alert(response.code + " " + response.message);
					}
					else {
						window.location.replace("./?futurepay="+response.transaction_id);
					}

				}
				/*]]>*/
			</script>';
            echo '<input type="button" class="button alt" name="place_order" id="place_order" value="Place Order" onclick="FP.CartIntegration.placeOrder();" />';
        } catch (Exception $e) {
            echo '<div class="jigoshop_error">' . $e->getMessage() . '</div>';
            jigoshop_log('FUTUREPAY ERROR: ' . $e->getMessage());
        }
    }
Exemplo n.º 15
0
function my_cart($atts)
{
    $errors = array();
    unset(jigoshop_session::instance()->selected_rate_id);
    // Process Discount Codes
    if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) {
        $coupon_code = stripslashes(trim($_POST['coupon_code']));
        jigoshop_cart::add_discount($coupon_code);
        // Update Shipping
    } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) {
        unset(jigoshop_session::instance()->chosen_shipping_method_id);
        $country = $_POST['calc_shipping_country'];
        $state = $_POST['calc_shipping_state'];
        $postcode = $_POST['calc_shipping_postcode'];
        if ($postcode && !jigoshop_validation::is_postcode($postcode, $country)) {
            jigoshop::add_error(__('Please enter a valid postcode/ZIP.', 'jigoshop'));
            $postcode = '';
        } elseif ($postcode) {
            $postcode = jigoshop_validation::format_postcode($postcode, $country);
        }
        if ($country) {
            // Update customer location
            jigoshop_customer::set_location($country, $state, $postcode);
            jigoshop_customer::set_shipping_location($country, $state, $postcode);
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        } else {
            jigoshop_customer::set_shipping_location('', '', '');
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        }
    } elseif (isset($_POST['shipping_rates'])) {
        $rates_params = explode(":", $_POST['shipping_rates']);
        $available_methods = jigoshop_shipping::get_available_shipping_methods();
        $shipping_method = $available_methods[$rates_params[0]];
        if ($rates_params[1] != NULL) {
            jigoshop_session::instance()->selected_rate_id = $rates_params[1];
        }
        $shipping_method->choose();
        // choses the method selected by user.
    }
    // Re-Calc prices. This needs to happen every time the cart page is loaded and after checking post results. It will happen twice for coupon.
    jigoshop_cart::calculate_totals();
    $result = jigoshop_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        jigoshop::add_error($result->get_error_message());
    }
    jigoshop::show_messages();
    if (sizeof(jigoshop_cart::$cart_contents) == 0) {
        echo '<p>' . __('Your cart is empty.', 'jigoshop') . '</p>';
        ?>
<p><a href="<?php 
        echo esc_url(jigoshop_cart::get_shop_url());
        ?>
" class="button"><?php 
        _e('&larr; Return to Shop', 'jigoshop');
        ?>
</a></p><?php 
        return;
    }
    ?>
    <form action="<?php 
    echo esc_url(jigoshop_cart::get_cart_url());
    ?>
" method="post">
        <table class="shop_table cart" cellspacing="0" id="shop-cart">
            <thead>
                <tr>
                    <th class="product-remove">Remove</th>
                    <th class="product-thumbnail"></th>
                    <th class="product-name"><span class="nobr"><?php 
    _e('Product Name', 'jigoshop');
    ?>
</span></th>
                    <th class="product-price"><span class="nobr"><?php 
    _e('Unit Price', 'jigoshop');
    ?>
</span></th>
                    <th class="product-quantity"><?php 
    _e('Quantity', 'jigoshop');
    ?>
</th>
                    <th class="product-subtotal"><?php 
    _e('Price', 'jigoshop');
    ?>
</th>
                </tr>
                <?php 
    do_action('jigoshop_shop_table_cart_head');
    ?>
            </thead>
            <tbody>
                <?php 
    if (sizeof(jigoshop_cart::$cart_contents) > 0) {
        foreach (jigoshop_cart::$cart_contents as $cart_item_key => $values) {
            $_product = $values['data'];
            if ($_product->exists() && $values['quantity'] > 0) {
                $additional_description = jigoshop_cart::get_item_data($values);
                ?>
                            <tr>
                                <td class="product-remove"><a href="<?php 
                echo esc_url(jigoshop_cart::get_remove_url($cart_item_key));
                ?>
" class="remove" title="<?php 
                echo esc_attr(__('Remove this item.', 'jigoshop'));
                ?>
">&times;</a></td>
                                <td class="product-thumbnail"><a href="<?php 
                echo esc_url(apply_filters('jigoshop_product_url_display_in_cart', get_permalink($values['product_id']), $cart_item_key));
                ?>
">
                                    <?php 
                if ($values['variation_id'] && has_post_thumbnail($values['variation_id'])) {
                    echo get_the_post_thumbnail($values['variation_id'], 'shop_tiny');
                } else {
                    if (has_post_thumbnail($values['product_id'])) {
                        echo get_the_post_thumbnail($values['product_id'], 'shop_tiny');
                    } else {
                        echo '<img src="' . jigoshop::assets_url() . '/assets/images/placeholder.png" alt="Placeholder" width="' . jigoshop::get_var('shop_tiny_w') . '" height="' . jigoshop::get_var('shop_tiny_h') . '" />';
                    }
                }
                ?>
</a>
                                </td>

                                <td class="product-name">
                                    <a href="<?php 
                echo esc_url(apply_filters('jigoshop_product_url_display_in_cart', get_permalink($values['product_id']), $cart_item_key));
                ?>
"><?php 
                echo apply_filters('jigoshop_cart_product_title', $_product->get_title(), $_product);
                ?>
</a>
                                    <?php 
                echo $additional_description;
                ?>
                                    <?php 
                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_products[$product_id])) {
                    ?>
											<dl class="customization">
												<dt class="customized_product_label"><?php 
                    echo apply_filters('jigoshop_customized_product_label', __('Personal: ', 'jigoshop'));
                    ?>
</dt>
												<dd class="customized_product"><?php 
                    echo esc_textarea($custom);
                    ?>
</dd>
											</dl>
											<?php 
                }
                ?>
                                </td>
                                <td class="product-price"><span class="m-label">Unit price:</span><?php 
                echo jigoshop_price($_product->get_price());
                ?>
</td>
                                <td class="product-quantity">
                                    <span class="m-label">Quantity:</span>
                                     <div class="quantity"><input name="cart[<?php 
                echo $cart_item_key;
                ?>
][qty]" value="<?php 
                echo esc_attr($values['quantity']);
                ?>
" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
                                </td>
                                <td class="product-subtotal"><span class="m-label">Price:</span><?php 
                echo jigoshop_price($_product->get_price() * $values['quantity']);
                ?>
</td>
                            </tr>
                            <?php 
            }
        }
    }
    do_action('jigoshop_shop_table_cart_body');
    ?>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="6" class="actions">

                        <?php 
    $coupons = JS_Coupons::get_coupons();
    if (!empty($coupons)) {
        ?>
                            <div class="coupon">
                                <label for="coupon_code"><?php 
        _e('Coupon', 'jigoshop');
        ?>
:</label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" />
                                <input type="submit" class="button" name="apply_coupon" value="<?php 
        _e('Apply Coupon', 'jigoshop');
        ?>
" />
                            </div>
                        <?php 
    }
    ?>

                        <?php 
    jigoshop::nonce_field('cart');
    ?>
                        <input type="submit" class="button" name="update_cart" value="<?php 
    _e('Update Shopping Cart', 'jigoshop');
    ?>
" /> <a href="<?php 
    echo esc_url(jigoshop_cart::get_checkout_url());
    ?>
" class="checkout-button button-alt"><?php 
    _e('Proceed to Checkout &rarr;', 'jigoshop');
    ?>
</a>
                    </td>
                </tr>
                <?php 
    if (count(jigoshop_cart::$applied_coupons)) {
        ?>
                    <tr>
                        <td colspan="6" class="applied-coupons">
                            <div>
                                <span class="applied-coupons-label"><?php 
        _e('Applied Coupons: ', 'jigoshop');
        ?>
</span>
								<?php 
        foreach (jigoshop_cart::$applied_coupons as $code) {
            ?>
                                <a href="?unset_coupon=<?php 
            echo $code;
            ?>
" id="<?php 
            echo $code;
            ?>
" class="applied-coupons-values"><?php 
            echo $code;
            ?>
									<span class="close">&times;</span>
								</a>
								<?php 
        }
        ?>
                            </div>
                        </td>
                    </tr>
                    <?php 
    }
    do_action('jigoshop_shop_table_cart_foot');
    ?>
            </tfoot>
            <?php 
    do_action('jigoshop_shop_table_cart');
    ?>
        </table>
    </form>
    <div class="cart-collaterals">

        <?php 
    do_action('cart-collaterals');
    ?>

        <div class="cart_totals">
            <?php 
    // Hide totals if customer has set location and there are no methods going there
    $available_methods = jigoshop_shipping::get_available_shipping_methods();
    $jigoshop_options = Jigoshop_Base::get_options();
    if ($available_methods || !jigoshop_customer::get_shipping_country() || !jigoshop_shipping::is_enabled()) {
        ?>
                <h2><?php 
        _e('Cart Totals', 'jigoshop');
        ?>
</h2>

                <div class="cart_totals_table">
                    <table cellspacing="0" cellpadding="0">
                        <tbody>

                            <tr>
							   <?php 
        $price_label = jigoshop_cart::show_retail_price() ? __('Retail Price', 'jigoshop') : __('Subtotal', 'jigoshop');
        ?>

								<th class="cart-row-subtotal-title"><?php 
        echo $price_label;
        ?>
</th>
                                <td class="cart-row-subtotal"><?php 
        echo jigoshop_cart::get_cart_subtotal();
        ?>
</td>
                            </tr>

                            <?php 
        if (jigoshop_cart::get_cart_shipping_total()) {
            ?>
							<tr>
                                <th class="cart-row-shipping-title"><?php 
            _e('Shipping', 'jigoshop');
            ?>
 <small><?php 
            echo jigoshop_countries::shipping_to_prefix() . ' ' . __(jigoshop_countries::$countries[jigoshop_customer::get_shipping_country()], 'jigoshop');
            ?>
</small></th>
                                <td class="cart-row-shipping"><?php 
            echo jigoshop_cart::get_cart_shipping_total();
            ?>
 <small><?php 
            echo jigoshop_cart::get_cart_shipping_title();
            ?>
</small></td>
                            </tr>
                            <?php 
        }
        ?>

                            <?php 
        if (jigoshop_cart::show_retail_price()) {
            ?>
                                <tr>
                                    <th class="cart-row-subtotal-title"><?php 
            _e('Subtotal', 'jigoshop');
            ?>
</th>
                                    <td class="cart-row-subtotal"><?php 
            echo jigoshop_cart::get_cart_subtotal(true, true);
            ?>
</td>
                                </tr>
                            <?php 
        }
        ?>

                            <?php 
        if (jigoshop_cart::tax_after_coupon()) {
            ?>
                                <tr class="discount">
                                    <th class="cart-row-discount-title"><?php 
            _e('Discount', 'jigoshop');
            ?>
</th>
									<td class="cart-row-discount">-<?php 
            echo jigoshop_cart::get_total_discount();
            ?>
</td>
                                </tr>
                            <?php 
        }
        ?>

                            <?php 
        if (Jigoshop_Base::get_options()->get_option('jigoshop_calc_taxes') == 'yes') {
            foreach (jigoshop_cart::get_applied_tax_classes() as $tax_class) {
                if (jigoshop_cart::get_tax_for_display($tax_class)) {
                    ?>
                                        <tr>
                                            <th class="cart-row-tax-title"><?php 
                    echo jigoshop_cart::get_tax_for_display($tax_class);
                    ?>
</th>
                                            <td class="cart-row-tax"><?php 
                    echo jigoshop_cart::get_tax_amount($tax_class);
                    ?>
</td>
                                        </tr>
                                    <?php 
                }
            }
        }
        ?>

							<?php 
        if (!jigoshop_cart::tax_after_coupon() && jigoshop_cart::get_total_discount()) {
            ?>
							<tr class="discount">
								<th class="cart-row-discount-title"><?php 
            _e('Discount', 'jigoshop');
            ?>
</th>
								<td class="cart-row-discount">-<?php 
            echo jigoshop_cart::get_total_discount();
            ?>
</td>
							</tr>
							<?php 
        }
        ?>

							<tr>
								<th class="cart-row-total-title"><strong><?php 
        _e('Total', 'jigoshop');
        ?>
</strong></th>
								<td class="cart-row-total"><strong><?php 
        echo jigoshop_cart::get_total();
        ?>
</strong></td>
							</tr>

						</tbody>
					</table>
				</div>
			<?php 
    } else {
        echo '<p>' . __(jigoshop_shipping::get_shipping_error_message(), 'jigoshop') . '</p>';
    }
    ?>
		</div>

		<?php 
    jigoshop_shipping_calculator();
    ?>

	</div>
	<?php 
}
Exemplo n.º 16
0
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', '_GET')) :
			
			// 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') );
			
		endif;
		
		wp_safe_redirect(jigoshop_cart::get_cart_url());
		exit;
		
	endif;
}
 private function create_user_account()
 {
     $reg_errors = new WP_Error();
     do_action('register_post', $this->posted['billing_email'], $this->posted['billing_email'], $reg_errors);
     if ($reg_errors->get_error_code()) {
         jigoshop::add_error($reg_errors->get_error_message());
         return 0;
     }
     $user_pass = $this->posted['account_password'];
     $user_id = wp_create_user($this->posted['account_username'], $user_pass, $this->posted['billing_email']);
     if (!$user_id) {
         jigoshop::add_error(sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'jigoshop'), self::get_options()->get('jigoshop_email')));
         return 0;
     }
     wp_update_user(array('ID' => $user_id, 'role' => 'customer', 'first_name' => $this->posted['billing_first_name'], 'last_name' => $this->posted['billing_last_name']));
     do_action('jigoshop_created_customer', $user_id);
     // send the user a confirmation and their login details
     if (apply_filters('jigoshop_new_user_notification', true, $user_id, $user_pass)) {
         wp_new_user_notification($user_id, $user_pass);
     }
     wp_set_auth_cookie($user_id, true, is_ssl());
     return $user_id;
 }
        <div class="row-fluid">   
            <div id="content" class="span12">
                
                <?php 
$cart = jigoshop_cart::get_cart();
$nocarterrors = true;
foreach ($cart as $cart_item_key => $values) {
    if ($values['product_id'] == esc_attr(get_theme_mod('_home_adquira_btn_link', '183')) && $values['quantity'] > 1) {
        $jigoerror = 'Só é permitida a aquisição de um ';
        $jigoerror .= get_bloginfo('name');
        $jigoerror .= ' por vez.  Por favor, reduza a quantidade para 1 e tente novamente.';
        jigoshop::add_error($jigoerror);
        $nocarterrors = false;
    }
    if ($values['product_id'] == esc_attr(get_theme_mod('_home_adquira_abrangencia_btn_link', '188')) && $values['quantity'] > 1) {
        jigoshop::add_error('A abrangência familiar vale para toda a família.  Não é necessário adquirir mais de uma abrangência familiar por plano.  Por favor, reduza a quantidade para 1 e tente novamente.');
        $nocarterrors = false;
    }
}
jigoshop::show_messages();
?>
                
                <div class="whiterogue-jigoshop-title">
                    início da contratação
                </div>
                <div class="whiterogue-clearleft">
                    <h4>Você está iniciando o processo de contratação online do <strong><?php 
echo get_bloginfo('name');
?>
</strong>.  Por favor certifique-se de que o produto abaixo atende suas necessidades lendo atentamente a sessão de 
                    <a href="<?php 
Exemplo n.º 19
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;
        }
    }
}
Exemplo n.º 20
0
	/**
	 * Check a nonce and sets jigoshop error in case it is invalid
	 * To fail silently, set the error_message to an empty string
	 * 
	 * @param 	string $name the nonce name
	 * @param	string $action then nonce action
	 * @param   string $method the http request method _POST, _GET or _REQUEST
	 * @param   string $error_message custom error message, or false for default message, or an empty string to fail silently
	 * 
	 * @return   bool
	 */
	public static function verify_nonce($action, $method='_POST', $error_message = false) {
		
		$name = '_n';
		$action = 'jigoshop-' . $action;
		
		if( $error_message === false ) $error_message = __('Action failed. Please refresh the page and retry.', 'jigoshop'); 
		
		if(!in_array($method, array('_GET', '_POST', '_REQUEST'))) $method = '_POST';
		
		/*
		$request = $GLOBALS[$method];
		
		if ( isset($request[$name]) && wp_verify_nonce($request[$name], $action) ) return true;
		*/
		
		if ( isset($_REQUEST[$name]) && wp_verify_nonce($_REQUEST[$name], $action) ) return true;
		
		if( $error_message ) jigoshop::add_error( $error_message );
		
		return false;
		
	}