<?php

	include "library.php";

	$cxn = start_code( true );

//echo "xx<br>";
//exit();


		// this is the latest payment code, 19/07/17
		
		// the return URL after payment is set in PayPal on the Settings, Profile and Settings, Selling Tools, Website Preferences tab


		/* get variables */

	$account_id = val( $_SESSION, "account_id" );


		/* if the user is not logged in them direct them to the login page then back to here */

	if ($account_id == "")
	{
		$_SESSION['nextpage'] = url_encode( "buy_credits.php" );

	    jump_to_page( "login.php" );		/* must happen before print output */

		exit();
	}

	$return_url = http_protocol."://aubusinessesforsale.com";
	$notification_url = http_protocol."://aubusinessesforsale.com/payment_notification.php";
	$acceptance_code = $account_id;

	page_header( "Buy Credits", $cxn );

    $query = "SELECT * FROM account WHERE id = ".$account_id;

    $result = run_query( $query, $cxn );

    $data = get_row( $result );

    $credits_balance = val( $data, "credits_balance" );
    
    
    echo black( "In order to see the contact details for a listed business-for-sale you must purchase credits.<br><br>" );

    echo black( "It costs one credit to see the contact details for one business.<br><br><br>" );

    if ($credits_balance == 0)
        echo black( "Your credit balance is: 0 credits<br><br>" );
    else
    if ($credits_balance == 1)
        echo black( "Your credit balance is: 1 credit<br><br>" );
    else
        echo black( "Your credit balance is: ".$credits_balance." credits<br><br>" );
    

	echo "<br><br><br><br><br><br>";
        
	echo "<table width='100%'><tr><td width='10%'></td><td>";

	generate_button( $account_id, "Buy 1 credit&nbsp;&nbsp;($10)", "10.00", $return_url, $notification_url, $acceptance_code, "form1" );

	generate_button( $account_id, "Buy 5 credits&nbsp;&nbsp;($50)", "50.00", $return_url, $notification_url, $acceptance_code, "form2" );

	generate_button( $account_id, "Buy 10 credits&nbsp;&nbsp;($100)", "100.00", $return_url, $notification_url, $acceptance_code, "form3" );

	echo "</td></tr></table>";
	
	echo "<br><br>";	

	echo "<table width='100%'><tr><td width='10%'></td><td>";

    echo '<img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/PP_logo_h_100x26.png" alt="PayPal Logo">';	

	echo "</td></tr></table>";


	function generate_button( $member_id, $button_text, $amount, $return_url, $notification_url, $acceptance_code, $form_name )
	{
		echo "<form id='".$form_name."' name='".$form_name."' action='https://www.paypal.com/cgi-bin/webscr' method='POST'>";

			// buy-now button
					
		echo "<input type='hidden' name='cmd' value='_xclick'>";
		
		
			// the business

		echo "<input type='hidden' name='business' value='admin@aubusinessesforsale.com'>";
		
		
			// the item
			
		echo "<input type='hidden' name='item_name' value='Australian Businesses for Sale Platform credits purchase'>";
		
//		echo "<span class='fprompt'>Donation amount \$US&nbsp;&nbsp;</span><input class='finput' type='text' name='amount' size='8' value='2.00'><br><br><br>";
		
		echo "<input type='hidden' name='amount' value='".$amount."'>";

		echo "<input type='hidden' name='currency_code' value='AUD'>";
		

			// code to identify which member purchased the membership
			
		echo "<input type='hidden' name='custom' value='".$acceptance_code.",".$amount."'>";


			// return URL's
			
		echo "<input type='hidden' name='notify_url' value='".$notification_url."'>";
		echo "<input type='hidden' name='shopping_url' value='".$return_url."'>";
		echo "<input type='hidden' name='return_url' value='".$return_url."'>";
//		echo "<input type='hidden' name='custom' value='".$custom."'>";

			// payment button
			
//		echo "<input type='image' name='submit' border='0' src='https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_buynow_107x26.png' alt='Australian Businesses for Sale Platform credits purchase'>";		

    	show_green_button_submit( $button_text, 195, $form_name );

		echo "</form>";
//<img src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/gold-pill-paypal-34px.png" alt="PayPal">

	}

?>