function cheque_checkout_action()
 {
     $retval = array();
     $items = $this->param('items');
     if (!$items) {
         return array('error' => __('Your cart is empty', 'nggallery'));
     }
     $customer = array('name' => $this->param('customer_name'), 'email' => $this->param('customer_email'), 'address' => $this->param('customer_address'), 'city' => $this->param('customer_city'), 'state' => $this->param('customer_state'), 'postal' => $this->param('customer_postal'), 'country' => $this->param('customer_country'));
     $retval['customer'] = $customer;
     // Presently we only do basic field validation: ensure that each field is filled and that
     // the country selected exists in C_NextGen_Pro_Currencies::$countries
     foreach ($customer as $key => $val) {
         if (empty($val)) {
             $retval['error'] = __('Please fill all fields and try again', 'nggallery');
             break;
         }
     }
     // No error yet?
     if (!isset($retval['error'])) {
         if (empty(C_NextGen_Pro_Currencies::$countries[$customer['country']])) {
             return array('error' => __('Invalid country selected, please try again.', 'nggallery'));
         } else {
             $customer['country'] = C_NextGen_Pro_Currencies::$countries[$customer['country']]['name'];
         }
         $checkout = new C_NextGen_Pro_Checkout();
         $cart = new C_NextGen_Pro_Cart();
         $settings = C_NextGen_Settings::get_instance();
         $currency = C_NextGen_Pro_Currencies::$currencies[$settings->ecommerce_currency];
         foreach ($items as $image_id => $image_items) {
             if ($image = C_Image_Mapper::get_instance()->find($image_id)) {
                 $cart->add_image($image_id, $image);
                 foreach ($image_items as $item_id => $quantity) {
                     if ($item = C_Pricelist_Item_Mapper::get_instance()->find($item_id)) {
                         $item->quantity = $quantity;
                         $cart->add_item($image_id, $item_id, $item);
                     }
                 }
             }
         }
         // Calculate the total
         $use_home_country = intval($this->param('use_home_country'));
         $order_total = $cart->get_total($use_home_country);
         // Create the order
         if (!$cart->has_items()) {
             return array('error' => __('Your cart is empty', 'nggallery'));
         }
         $order = $checkout->create_order($cart->to_array(), $customer['name'], $customer['email'], $order_total, 'cheque', $customer['address'], $customer['city'], $customer['state'], $customer['postal'], $customer['country'], $use_home_country, 'unverified');
         $order->status = 'unverified';
         $order->gateway_admin_note = __('Payment was successfully made via Check. Once you have received payment, you can click “Verify” in the View Orders page and a confirmation email will be sent to the user.');
         C_Order_Mapper::get_instance()->save($order);
         $checkout->send_email_notification($order->hash);
         $retval['order'] = $order->hash;
         $retval['redirect'] = $checkout->get_thank_you_page_url($order->hash, TRUE);
     }
     return $retval;
 }
 function route()
 {
     if (isset($_REQUEST['ngg_stripe_rtn']) && isset($_REQUEST['order'])) {
         $checkout = C_NextGen_Pro_Checkout::get_instance();
         $checkout->redirect_to_thank_you_page($_REQUEST['order']);
     }
 }
 static function get_instance()
 {
     if (!self::$_instance) {
         $klass = get_class();
         self::$_instance = new $klass();
     }
     return self::$_instance;
 }
 function paypal_express_checkout_action()
 {
     $retval = array();
     $checkout = C_NextGen_Pro_Checkout::get_instance();
     $response = $checkout->set_express_checkout();
     unset($response['token']);
     // for security reasons
     return $response;
 }
 function process_paypal_responses()
 {
     // Process return from PayPal
     if (isset($_REQUEST['ngg_ppxc_rtn'])) {
         $checkout = C_NextGen_Pro_Checkout::get_instance();
         if ($order_hash = $checkout->create_paypal_express_order()) {
             $checkout->redirect_to_thank_you_page($order_hash);
         }
     } elseif (isset($_REQUEST['ngg_ppxc_ccl'])) {
         $checkout = C_NextGen_Pro_Checkout::get_instance();
         $checkout->redirect_to_cancel_page();
     }
 }
 function process_paypal_responses()
 {
     // Process return from PayPal
     if (isset($_REQUEST['ngg_pstd_rtn'])) {
         C_NextGen_Pro_Checkout::get_instance()->create_paypal_standard_order();
     } elseif (isset($_REQUEST['ngg_pstd_cnl'])) {
         $checkout = C_NextGen_Pro_Checkout::get_instance();
         $checkout->redirect_to_cancel_page();
     } elseif (isset($_REQUEST['ngg_pstd_nfy'])) {
         $checkout = C_NextGen_Pro_Checkout::get_instance();
         $checkout->paypal_ipn_listener();
     }
 }
 function paypal_standard_order_action()
 {
     $retval = array();
     if ($items = $this->param('items')) {
         $checkout = new C_NextGen_Pro_Checkout();
         $cart = new C_NextGen_Pro_Cart();
         $settings = C_NextGen_Settings::get_instance();
         $currency = C_NextGen_Pro_Currencies::$currencies[$settings->ecommerce_currency];
         foreach ($items as $image_id => $image_items) {
             if ($image = C_Image_Mapper::get_instance()->find($image_id)) {
                 $cart->add_image($image_id, $image);
                 foreach ($image_items as $item_id => $quantity) {
                     if ($item = C_Pricelist_Item_Mapper::get_instance()->find($item_id)) {
                         $item->quantity = $quantity;
                         $cart->add_item($image_id, $item_id, $item);
                     }
                 }
             }
         }
         // Calculate the total
         $use_home_country = intval($this->param('use_home_country'));
         $order_total = $cart->get_total($use_home_country);
         // Create the order
         if ($cart->has_items()) {
             $order = $checkout->create_order($cart->to_array(), __('PayPal Customer', 'nggallery'), 'Unknown', $order_total, 'paypal_standard');
             $order->status = 'unverified';
             $order->use_home_country = $use_home_country;
             $order->gateway_admin_note = __('Payment was successfully made via PayPal Standard, with no further payment action required.');
             C_Order_Mapper::get_instance()->save($order);
             $retval['order'] = $order->hash;
         } else {
             $retval['error'] = __('Your cart is empty', 'nggallery');
         }
     }
     return $retval;
 }
 /**
  * Processes 'verify cheque payment' bulk action
  */
 function process_cheque_bulk_actions()
 {
     global $typenow;
     if ($typenow !== 'ngg_order') {
         return;
     }
     if (empty($_REQUEST['post'])) {
         return;
     }
     $wp_list_table = _get_list_table('WP_Posts_List_Table');
     $action = $wp_list_table->current_action();
     $ids = array_map('intval', $_REQUEST['post']);
     if (empty($ids)) {
         return;
     }
     $url = remove_query_arg(array('verify_cheques'), wp_get_referer());
     if (!$url) {
         $url = admin_url('edit.php?post_type=ngg_order');
     }
     $url = add_query_arg('paged', $wp_list_table->get_pagenum(), $url);
     switch ($action) {
         case 'verify_cheques':
             $checkout = new C_NextGen_Pro_Checkout();
             $verified = 0;
             foreach ($ids as $post_id) {
                 $order = C_Order_Mapper::get_instance()->find($post_id, TRUE);
                 if ($order->status !== 'unverified' || $order->payment_gateway !== 'cheque') {
                     continue;
                 }
                 $order->status = 'verified';
                 if ($order->save()) {
                     $verified++;
                     $checkout->send_email_receipt($order->hash);
                 }
             }
             if (session_id() == '') {
                 session_start();
             }
             $_SESSION['ngg_verified_cheques'] = $verified;
             session_write_close();
             wp_redirect($url);
             throw new E_Clean_Exit();
         default:
             return;
     }
 }
 function is_order_verified_action()
 {
     $retval = array('verified' => FALSE);
     if ($order = C_Order_Mapper::get_instance()->find_by_hash($this->param('order'))) {
         if ($order->status == 'verified') {
             $retval['verified'] = TRUE;
             $checkout = C_NextGen_Pro_Checkout::get_instance();
             $retval['thank_you_page_url'] = $checkout->get_thank_you_page_url($order->hash, TRUE);
         }
     } else {
         $retval['error'] = __("We're sorry, but we couldn't find your order.", 'nextgen-gallery-pro');
     }
     return $retval;
 }
 function stripe_checkout_action()
 {
     $retval = array();
     $checkout = C_NextGen_Pro_Checkout::get_instance();
     return $checkout->create_stripe_charge();
 }
 function custom_edit_link($url)
 {
     global $post;
     // we can't always assume $post exists
     if (empty($post)) {
         return $url;
     }
     if ($post->post_type == 'ngg_pricelist') {
         $url = admin_url('/edit.php?post_type=ngg_pricelist&ngg_edit=1&id=' . $post->ID);
     } elseif ($post->post_type == 'ngg_order') {
         $mapper = C_Order_Mapper::get_instance();
         if ($order = $mapper->find($post->ID)) {
             $checkout = C_NextGen_Pro_Checkout::get_instance();
             $url = $checkout->get_thank_you_page_url($order->hash);
         }
     }
     return $url;
 }