\n"; $html .= "
Existing Users:
\n"; $html .= wp_login_form(array('echo' => false)); $html .= "Lost Password"; $html .= " | New Users: Register"; $html .= "
\n"; } else { $result = self::showInvoice(); if(!$result) { $html .= "The shopping cart is empty."; } else { $html .= "Welcome, " .wp_get_current_user()->user_login. "!"; $html .= $result; if($sandbox) { $html .= "
"; } else { $html .= ""; } $i = 1; foreach($_SESSION['artistography_cart'] as $product => $qty) { $album->loadById($product); $html .= ""; $html .= ""; $html .= ""; $i++; } $html .= " "; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "
"; $html .= "
"; } } return $html; } public static function shortCodeShowThankyou( $atts, $content=null, $code="" ) { GLOBAL $i18n_domain; $html = ""; /* empty the cart */ session_destroy(); $html .= "Thank you for completing your order with us. To see all of your completed orders please click here.

"; $html .= ""; return $html; } public static function shortCodeShowOrders( $atts, $content=null, $code="" ) { GLOBAL $i18n_domain; $html = ""; return $html; } // IPN Guide: https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/ipnguide.pdf //http://code.tutsplus.com/tutorials/wordpress-and-paypal-an-introduction--wp-25074 public static function shortCodeIPN( $atts, $content=null, $code="" ) { GLOBAL $i18n_domain, $TABLE_NAME; $html = ""; $req = 'cmd=_notify-validate'; foreach($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&key=$value"; } $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " .strlen($req). "\r\n\r\n"; $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // http error } else { fputs ($fp, $header . $req); while(!feof($fp)) { $res = fgets($fp, 1024); $fh = fopen('results.txt', 'w'); fwrite($fh, $res); fclose($fh); if (strcmp($res, "VERIFIED") == 0) { $firstName = $_POST['first_name']; $lastName = $_POST['last_name']; $payerEmail = $_POST['payer_email']; $addressStreet = $_POST['address_street']; $addressZip = $_POST['address_zip']; $addressCity = $_POST['address_city']; $productsBought = $_POST['']; $txnID = $_POST['txn_id']; //Used to store quickly items bought $i = 1; foreach($_POST as $key => $value) { if($key == 'item_name'.$i) { $products_bought[] = $value; $i++; } } $products = serialize($products_bought); $wpdb->insert($wpdb->prefix.$TABLE_NAME[TABLE_ARTIST_ORDERS], array( 'forename' => $firstName, 'surname' => $lastName, 'email' => $payerEmail, 'address_line_1' => $addressStreet, 'postcode' => $addressZip, 'town' => $addressCity, 'itemsOrdered' => $products, 'created' => current_time('mysql'), 'txn_id' => $txnID, 'user_ip' => $_SERVER['REMOTE_ADDR'] ), array( '%s', // FORENAME '%s', // SURNAME '%s', // EMAIL '%s', // ADDRESS 1 '%s', // PCODE '%s', // TOWN '%s', // ORDERED '%s', // STATUS '%s', // CREATED '%s' // USER IP )); } else if (strcmp($res, "INVALID") == 0) { // You may prefer to store the transaction even if fail } /* end if */ } /* end while */ fclose($fp); } /* end if */ return $html; } public function showCart() { GLOBAL $i18n_domain, $checkout_icon_url, $checkout_icon_width, $checkout_icon_height; $order = new Orders; $album = new Music; $total = (float)"0.00"; /*** Display Cart Contents ***/ if(!empty($_SESSION['artistography_cart'])) { foreach($_SESSION['artistography_cart'] as $product => $qty) { $album->loadById($product); $total += ($qty * (float)($album->price)); $html = "
"; } $html .= "
" .__("Quanity", $i18n_domain). " " .__("Item", $i18n_domain). " " .__("Price", $i18n_domain). " " .__("Action", $i18n_domain). "
$qty $album->artist_name - $album->album_name " .CURRENCY. "$album->price
Total:" .CURRENCY.number_format(round($total, 2), 2). "

\n "; } else { $html = "The shopping cart is empty."; } return $html; } public function showInvoice() { GLOBAL $i18n_domain; $order = new Orders; $album = new Music; $total = (float)"0.00"; /*** Display Cart Contents ***/ if(!empty($_SESSION['artistography_cart'])) { foreach($_SESSION['artistography_cart'] as $product => $qty) { $album->loadById($product); $total += ($qty * (float)($album->price)); $html = "
"; } $html .= "
" .__("Quanity", $i18n_domain). " " .__("Item", $i18n_domain). " " .__("Price", $i18n_domain). "
$qty $album->artist_name - $album->album_name " .CURRENCY. "$album->price
Total:" .CURRENCY.number_format(round($total, 2), 2). "

\n "; } else { return false; } return $html; } } /* end class Sales */ ?>