public function processPayment() { $v = Validator::make(["amount" => Input::get("amount"), "email" => Input::get("email")], ["amount" => "required|integer", "email" => "required|email"]); if ($v->passes()) { $billing = new Billing(); $billing->name = Input::get("name"); $billing->address = Input::get("address"); $billing->city = Input::get("city"); $billing->state = Input::get("state"); $billing->zip = Input::get("zip"); $billing->email = Input::get("email"); $billing->phone = Input::get("phone"); $billing->save(); $order = new Order(); $order->amount = Input::get("amount"); $order->billing_id = $billing->id; $order->save(); $bitcoinRedirectURL = URL::to("/"); if (Input::get('type') == "bitpay") { try { $bitpayResponse = $this->bitpayRequestCurl($order->id, $order->amount, $billing); } catch (\Exception $e) { Session::flash("error_msg", $e->getMessage()); return Redirect::back(); } //Set order status to pending since user didnt paid yet and serialize the response maybe useful later $order->type = "bitpay"; $order->status = "Pending"; $order->response = serialize($bitpayResponse); $bitcoinRedirectURL = $bitpayResponse->url; } if (Input::get('type') == "coinbase") { try { $coinbaseResponse = $this->coinbaseRequestCurl($order->id, $order->amount); } catch (\Exception $e) { Session::flash("error_msg", $e->getMessage()); return Redirect::back(); } $order->type = "coinbase"; $order->status = "Pending"; $order->response = serialize($coinbaseResponse); $bitcoinRedirectURL = "https://www.coinbase.com/checkouts/" . $coinbaseResponse->button->code; } return Redirect::to($bitcoinRedirectURL); } else { $response = ""; $messages = $v->messages()->all(); foreach ($messages as $message) { $response .= "<li style='margin-left:10px;'>{$message}</li>"; } Session::flash("error_msg", $response); return Redirect::back()->withInput(); } }
/** * ecartregcust::add_user() * * @param mixed $data * @return */ private function add_user() { require_once(ABSPATH."/wp-includes/registration.php"); $Errors =& EcartErrors(); $Errors->reset(); if (empty($_POST['customer']['email'])) { $this->form_error = 'Email address is required.'; return false; } if ($this->email_exists($_POST['customer']['email'])) { $this->form_error = 'Email address is already registered with another customer.'; return false; } if (empty($_POST['customer']['password'])) { $this->form_error = 'Password is required.'; return false; } if ($_POST['customer']['password'] !== $_POST['customer']['confirm-password']) { $this->form_error = 'Passwords do not match.'; return false; } if ($this->ecart_account_type == 'wordpress') { if (empty($_POST['customer']['loginname'])) { $this->form_error = 'Username is already registered.'; return false; } if (email_exists($_POST['customer']['email'])) { $this->form_error = 'Email address is already registered with another user.'; return false; } } if ($this->show_billing) { if (empty($_POST['billing']['address'])) { $this->form_error = 'Street address is required.'; return false; } if (empty($_POST['billing']['city'])) { $this->form_error = 'City is required.'; return false; } if (empty($_POST['billing']['state'])) { $this->form_error = 'State is required.'; return false; } if (empty($_POST['billing']['postcode'])) { $this->form_error = 'Postcode is required.'; return false; } } $customer_data = $_POST['customer']; $ecart_customer = new Customer(); $ecart_customer->updates($customer_data); if ($this->ecart_account_type == 'wordpress') { $ecart_customer->create_wpuser(); // not logged in, create new account $customer_data['wpuser'] = $ecart_customer->wpuser; unset($ecart_customer->password); if ($Errors->exist(ECART_ERR)) { $ecart_error = $Errors->get(ECART_ERR); $this->form_error = implode(', ', $ecart_error[0]->messages); return false; } } else { $ecart_customer->password = wp_hash_password($data['password']); } $ecart_customer->save(); if ($Errors->exist(ECART_ERR)) { $ecart_error = $Errors->get(ECART_ERR); $this->form_error = implode(', ', $ecart_error[0]->messages); return false; } if ($this->show_billing) { $billing_data = $_POST['billing']; $ecart_billing = new Billing(); $ecart_billing->updates($billing_data); $ecart_billing->customer = $ecart_customer->id; $ecart_billing->save(); } return $customer_data; }
function customers_list() { global $Shopp, $Customers, $wpdb; $db = DB::get(); $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'per_page' => false, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); if ($page == "shopp-customers" && !empty($deleting) && !empty($selected) && is_array($selected)) { foreach ($selected as $deletion) { $Customer = new Customer($deletion); $Billing = new Billing($Customer->id, 'customer'); $Billing->delete(); $Shipping = new Shipping($Customer->id, 'customer'); $Shipping->delete(); $Customer->delete(); } } if (!empty($_POST['save'])) { check_admin_referer('shopp-save-customer'); if ($_POST['id'] != "new") { $Customer = new Customer($_POST['id']); $Billing = new Billing($Customer->id, 'customer'); $Shipping = new Shipping($Customer->id, 'customer'); } else { $Customer = new Customer(); } $Customer->updates($_POST); if (!empty($_POST['new-password']) && !empty($_POST['confirm-password']) && $_POST['new-password'] == $_POST['confirm-password']) { $Customer->password = wp_hash_password($_POST['new-password']); if (!empty($Customer->wpuser)) { wp_set_password($_POST['new-password'], $Customer->wpuser); } } $Customer->save(); $Billing->updates($_POST['billing']); $Billing->save(); $Shipping->updates($_POST['shipping']); $Shipping->save(); } $pagenum = absint($pagenum); if (empty($pagenum)) { $pagenum = 1; } if (!$per_page || $per_page < 0) { $per_page = 20; } $index = $per_page * ($pagenum - 1); if (!empty($start)) { $startdate = $start; list($month, $day, $year) = explode("/", $startdate); $starts = mktime(0, 0, 0, $month, $day, $year); } if (!empty($end)) { $enddate = $end; list($month, $day, $year) = explode("/", $enddate); $ends = mktime(23, 59, 59, $month, $day, $year); } $customer_table = DatabaseObject::tablename(Customer::$table); $billing_table = DatabaseObject::tablename(Billing::$table); $purchase_table = DatabaseObject::tablename(Purchase::$table); $users_table = $wpdb->users; $where = ''; if (!empty($s)) { $s = stripslashes($s); if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER)) { foreach ($props as $search) { $keyword = !empty($search[2]) ? $search[2] : $search[3]; switch (strtolower($search[1])) { case "company": $where .= (empty($where) ? "WHERE " : " AND ") . "c.company LIKE '%{$keyword}%'"; break; case "login": $where .= (empty($where) ? "WHERE " : " AND ") . "u.user_login LIKE '%{$keyword}%'"; break; case "address": $where .= (empty($where) ? "WHERE " : " AND ") . "(b.address LIKE '%{$keyword}%' OR b.xaddress='%{$keyword}%')"; break; case "city": $where .= (empty($where) ? "WHERE " : " AND ") . "b.city LIKE '%{$keyword}%'"; break; case "province": case "state": $where .= (empty($where) ? "WHERE " : " AND ") . "b.state='{$keyword}'"; break; case "zip": case "zipcode": case "postcode": $where .= (empty($where) ? "WHERE " : " AND ") . "b.postcode='{$keyword}'"; break; case "country": $where .= (empty($where) ? "WHERE " : " AND ") . "b.country='{$keyword}'"; break; } } } elseif (strpos($s, '@') !== false) { $where .= (empty($where) ? "WHERE " : " AND ") . "c.email='{$s}'"; } else { $where .= (empty($where) ? "WHERE " : " AND ") . " (c.id='{$s}' OR CONCAT(c.firstname,' ',c.lastname) LIKE '%{$s}%' OR c.company LIKE '%{$s}%')"; } } if (!empty($starts) && !empty($ends)) { $where .= (empty($where) ? "WHERE " : " AND ") . ' (UNIX_TIMESTAMP(c.created) >= ' . $starts . ' AND UNIX_TIMESTAMP(c.created) <= ' . $ends . ')'; } $customercount = $db->query("SELECT count(*) as total FROM {$customer_table} AS c {$where}"); $query = "SELECT c.*,b.city,b.state,b.country, u.user_login, SUM(p.total) AS total,count(distinct p.id) AS orders FROM {$customer_table} AS c LEFT JOIN {$purchase_table} AS p ON p.customer=c.id LEFT JOIN {$billing_table} AS b ON b.customer=c.id LEFT JOIN {$users_table} AS u ON u.ID=c.wpuser AND (c.wpuser IS NULL OR c.wpuser !=0) {$where} GROUP BY c.id ORDER BY c.created DESC LIMIT {$index},{$per_page}"; $Customers = $db->query($query, AS_ARRAY); $num_pages = ceil($customercount->total / $per_page); $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => $num_pages, 'current' => $pagenum)); $ranges = array('all' => __('Show New Customers', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft® Excel.xls', 'Shopp')); $formatPref = $Shopp->Settings->get('customerexport_format'); if (!$formatPref) { $formatPref = 'tab'; } $columns = array_merge(Customer::exportcolumns(), Billing::exportcolumns(), Shipping::exportcolumns()); $selected = $Shopp->Settings->get('customerexport_columns'); if (empty($selected)) { $selected = array_keys($columns); } $authentication = $Shopp->Settings->get('account_system'); include "{$this->basepath}/core/ui/customers/customers.php"; }
/** * order() * Handles new order notifications from Google */ function order($XML) { global $Shopp; $db = DB::get(); // Check if this is a Shopp order or not $origin = $XML->getElementContent('shopping-cart-agent'); if (empty($origin) || substr($origin, 0, strpos("/", SHOPP_GATEWAY_USERAGENT)) == SHOPP_GATEWAY_USERAGENT) { return true; } $buyer = $XML->getElement('buyer-billing-address'); $buyer = $buyer['CHILDREN']; $Customer = new Customer(); $name = $XML->getElement('structured-name'); $Customer->firstname = $buyer['structured-name']['CHILDREN']['first-name']['CONTENT']; $Customer->lastname = $buyer['structured-name']['CHILDREN']['last-name']['CONTENT']; if (empty($name)) { $name = $buyer['contact-name']['CONTENT']; $names = explode(" ", $name); $Customer->firstname = $names[0]; $Customer->lastname = $names[count($names) - 1]; } $Customer->email = $buyer['email']['CONTENT']; $Customer->phone = $buyer['phone']['CONTENT']; $Customer->save(); $Billing = new Billing(); $Billing->customer = $Customer->id; $Billing->address = $buyer['address1']['CONTENT']; $Billing->xaddress = $buyer['address2']['CONTENT']; $Billing->city = $buyer['city']['CONTENT']; $Billing->state = $buyer['region']['CONTENT']; $Billing->country = $buyer['country-code']['CONTENT']; $Billing->postcode = $buyer['postal-code']['CONTENT']; $Billing->save(); $shipto = $XML->getElement('buyer-shipping-address'); $shipto = $shipto['CHILDREN']; $Shipping = new Shipping(); $Shipping->customer = $Customer->id; $Shipping->address = $shipto['address1']['CONTENT']; $Shipping->xaddress = $shipto['address2']['CONTENT']; $Shipping->city = $shipto['city']['CONTENT']; $Shipping->state = $shipto['region']['CONTENT']; $Shipping->country = $shipto['country-code']['CONTENT']; $Shipping->postcode = $shipto['postal-code']['CONTENT']; $Shipping->save(); $Purchase = new Purchase(); $Purchase->customer = $Customer->id; $Purchase->billing = $Billing->id; $Purchase->shipping = $Shipping->id; $Purchase->copydata($Customer); $Purchase->copydata($Billing); $Purchase->copydata($Shipping, 'ship'); $Purchase->freight = $XML->getElementContent('shipping-cost'); $Purchase->tax = $XML->getElementContent('total-tax'); $Purchase->total = $XML->getElementContent('order-total'); $Purchase->subtotal = $Purchase->total - $Purchase->frieght - $Purchase->tax; $Purchase->gateway = "Google Checkout"; $Purchase->transactionid = $XML->getElementContent('google-order-number'); $Purchase->transtatus = $XML->getElementContent('financial-order-state'); $Purchase->ip = $XML->getElementContent('customer-ip'); $orderdata = $XML->getElement('shopp-order-data'); $data = array(); if (is_array($orderdata) && count($orderdata) > 0) { foreach ($orderdata as $input) { $data[$input['ATTRS']['name']] = $input['CONTENT']; } } $Purchase->data = $data; $Purchase->save(); $items = $XML->getElement('item'); if (key($items) === "CHILDREN") { $items = array($items); } foreach ($items as $item) { $xml = $item['CHILDREN']; $itemdata = $xml['merchant-private-item-data']['CHILDREN']; $inputdata = $itemdata['shopp-item-data-list']['CHILDREN']['shopp-item-data']; $data = array(); if (is_array($inputdata) && count($inputdata) > 0) { foreach ($inputdata as $input) { $data[$input['ATTRS']['name']] = $input['CONTENT']; } } $Product = new Product($itemdata['shopp-product-id']['CONTENT']); $Item = new Item($Product, $itemdata['shopp-price-id']['CONTENT'], false, $data); $Item->quantity($xml['quantity']['CONTENT']); $Purchased = new Purchased(); $Purchased->copydata($Item); $Purchased->purchase = $Purchase->id; if (!empty($Purchased->download)) { $Purchased->keygen(); } $Purchased->save(); if ($Item->inventory) { $Item->unstock(); } } }