Jump to content
Larry Ullman's Book Forums

Necuima

Members
  • Posts

    359
  • Joined

  • Last visited

  • Days Won

    7

Posts posted by Necuima

  1. This is now in production.  I've attached the code for anyone else who might be in a similar situation.

    if ($local)
    	{	// development
    		echo <<<DD1
    			<!-- DEVELOPMENT TEST!!!-->
    			<div class="paypal_box">	<!-- right-shifts the div -->
    			<!-- first the PayPal Logo - see: https://www.paypal.com/us/webapps/mpp/logo-center -->
    			<img class="PP_logo" src="./images/PP_logo.jpg" alt="PayPal Logo">
    			<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    			   <input type="hidden" name="cmd" value="_xclick">
    			   <input type="hidden" name="business" value="xxx@yyy.com.au">
    			   <input type="hidden" name="item_name" value="Selected Items">
    			   <input type="hidden" name="item_number" value="">
    			   <input type="hidden" name="amount" value="$total">
    			   <input type="hidden" name="handling" value="0.00">
    			   <input type="hidden" name="shipping" value="0.00">
    			   <input type="hidden" name="currency_code" value="AUD">
    			   <input type="hidden" name="lc" value="AU">
    			   <input type="hidden" name="bn" value="PP-BuyNowBF">
    			   <input type="hidden" name="add" value="1">
    			   <input type="image" src="./images/PayPal_Button.jpg" alt="Submit" width="100"> <!-- the submit button -->
    			</form>
    			</div>	<!-- end paypal_box class div -->
    			<br /><br />
    DD1;
    	}	// end development
    else
    	{	// production - see: https://cvconnect.commercevision.com.au/display/KB/PayPal+Payments
    		echo <<<DD2
    			<!-- PRODUCTION!!!-->
    			<div class="paypal_box">	<!-- right-shifts the div -->
    			<!-- first the PayPal Logo - see: https://www.paypal.com/us/webapps/mpp/logo-center -->
    			<img class="PP_logo" src="./images/PP_logo.jpg" alt="PayPal Logo">
    			<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    			   <input type="hidden" name="cmd" value="_xclick">
    			   <input type="hidden" name="business" value="xxx@yyy.com.au">
    			   <input type="hidden" name="item_name" value="Selected Items">
    			   <input type="hidden" name="item_number" value="">
    			   <input type="hidden" name="amount" value="$total">
    			   <input type="hidden" name="handling" value="0.00">
    			   <input type="hidden" name="shipping" value="0.00">
    			   <input type="hidden" name="currency_code" value="AUD">
    			   <input type="hidden" name="lc" value="AU">
    			   <input type="hidden" name="return" value="https://xxx/index.php?p=thanks_3">
    			   <input type="hidden" name="cancel_return" value="https://xxx/index.php?p=cancel_3">
    			   <input type="hidden" name="bn" value="PP-BuyNowBF">
    			   <input type="hidden" name="add" value="1">
    			   <input type="image" src="./images/PayPal_Button.jpg" alt="Submit" width="100"> <!-- the submit button -->
    			</form>
    			</div>	<!-- end paypal_box class div -->
    			<br /><br />
    DD2;
    	}	// end production

    You will recognise the "$local" from one of your other books 🙂

    As an aside, when obtaining guidance from your E-Commerce book, I used PDO for all database activities and that has worked fine.

    All the best, Necuima

  2. I got there in the end after going down many 'blind alleys'.

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank">
    			   <input type="hidden" name="cmd" value="_xclick">
    			   <!-- <input type="hidden" name="cmd" value="_cart"> -->
    			   <input type="hidden" name="business" value="xxxx@yyyy.com.au">
    			   <input type="hidden" name="item_name" value="Item Description">
    			   <input type="hidden" name="item_number" value="">
    			   <input type="hidden" name="amount" value="$total">
    			   <input type="hidden" name="handling" value="0.00">
    			   <input type="hidden" name="shipping" value="0.00">
    			   <input type="hidden" name="currency_code" value="AUD">
    			   <input type="hidden" name="lc" value="AU">
    			   <input type="hidden" name="bn" value="PP-BuyNowBF">
    			   <input type="hidden" name="add" value="1">
    			   <input type="image" src="./images/PayPal_Button.jpg" alt="Submit" width="100"> <!-- the submit button -->
    			</form>

    Cheers from Oz.

  3. Hi Larry,  From SO the second code should not have the HTML form tags so I removed them but it still does not work.  I have also tried that code just in a simple HTML script but still no access to PP.  I would prefer to use the first script as at least it got me to PayPal if only I could find a way to set the currency to Australian dollars!  This must be a common thing to do - have a shopping cart in your PHP code and then just interface to PayPal with a single amount to process the financial transaction.  I have done similar with Stripe and that works fine but, as mentioned, the website owner insists on PP.  I look forward to your advice and thank you in anticipation.

  4. Hi Larry,

    Found some more code which displays the button nicely but even though the yellow PayPal bar shows the link/hand icon it goes nowhere.  I do have a developer id etc but don't know where to paste it.

     

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank">
    				<div id="smart-button-container" style="width: 60%; margin-left: 21%;">
    				<div style="text-align: left"><label class="checkout_form_mt_right v_align_top" for="description">Item:&nbsp;&nbsp;&nbsp;</label><input type="text" name="descriptionInput" id="description" size="40" value="Selected Jane Welsh Works of Art"></div>
    				  <p id="descriptionError" style="visibility: hidden; color:red; text-align: center;">Please enter a description</p>
    				<div style="text-align: left"><label  class="checkout_form_mt_right v_align_top" for="amount">Amount:&nbsp;&nbsp;</label><input name="amountInput" type="string" id="amount" value="$total"><span> AUD</span><span class='v_align_top white_text'><small><i>&nbsp;&nbsp;Australian dollars</i></small></span></div>
    				  <p id="priceLabelError" style="visibility: hidden; color:red; text-align: center;">Please enter a price</p>
    				<div id="invoiceidDiv" style="text-align: center; display: none;"><label for="invoiceid"> </label><input name="invoiceid" maxlength="127" type="text" id="invoiceid" value="" ></div>
    				  <p id="invoiceidError" style="visibility: hidden; color:red; text-align: center;">Please enter an Invoice ID</p>
    				<div style="text-align: center; margin-top: 0.625rem;" id="paypal-button-container"></div>
    			  </div>
    		  <!-- </form> 	   -->

    I tried it with and without the closing form tag.  There's also a heap of JavaScript which comes with this example from PayPal which I have not touched nor included here.

    Again, any advice will be most appreciated.

  5. Hi Larry,

    I am following your design in part 3 of the book to create a cart which is all fine - great guidance! But the website owner insists that the payment will be via PayPal (PP).  I have looked at part 2 where you use PayPal but with fixed amounts. I am trying to create a button/link to PP for a variable amount and in Australian dollars.  The code works fine as long as I do not try to change the currency.  I also need to add 'thankyou' and 'cancel' links back to the website but I can't seem to do that either. I have Googled for hours without finding the solution.

     

    <!-- now the button -->
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank">
      <input type="hidden" name="cmd" value="_cart">
      <input type="hidden" name="business" value="xxxx@yyyy.com.au">
      <input type="hidden" name="item_name" value="Item Description">
      <input type="hidden" name="item_number" value="">
      <input type="hidden" name="amount" value="$total">
      <input type="hidden" name="handling" value="0.00">
      <input type="hidden" name="shipping" value="0.00">
      <!-- <input type="hidden" name="currency_code" value="AUD"> -->
      <input type="hidden" name="lc" value="AU">
      <input type="hidden" name="bn" value="PP-BuyNowBF">
      <input type="image" src="https://www.paypalobjects.com/en_AU/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
      <img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1">
      <input type="hidden" name="add" value="1">
    </form>

    You can see that I have commented the currency out - with it 'in' I get an error from PP.

    Any guidance will be much appreciated.

    Best regards from Oz :-)

  6. Hi Nootkan,

    The issue that I am trying to help you with is the definition of the PHP variables whose names start with  $color_

    For example, unless $_POST['color'] == 'red') is true, the PHP variable $color_red will not get set. But you try and use it in the print statement whether it is defined or not.

    But you are better off following Larry's guidance and set just one $color variable.

    Cheers

  7. Hi,  I am sorry but I don't think that I can help you with this but I did notice "Username and Password not accepted" - did you check out the link at the end of that message?

    I use my Internet login details with my service provider and have never had a problem.  These details may or may not be the same as your email address.

    Hope it helps.

  8. Ok, the following is how I send emails from PHP. Uses PHPMailer. In XAMPP you need to tell it where your normal email connection is.

    $host = substr($_SERVER['HTTP_HOST'], 0, 5);
    if (in_array($host, array('127.0', '192.1', 'local'))) 
    	{
       	 	$local = TRUE;
    		// echo "Local is true, HOST is $host";
    	}
    else 
    	{
        	$local = FALSE;
    		// echo "Local is false, HOST is $host";
    	}
    
    if ($local)
    	{	// tests for using XAMPP locally
    		ini_set('sendmail_from', 'your email address');		// needed for Win 10 localhost (Development)
    		ini_set('SMTP', 'your email service SMTP server');			// needed for Win 10 localhost (Developmemt)
    	}
    
    require './includes/PHPMailer/PHPMailerAutoload.php';	// available as a free download
    $mail = new PHPMailer(true);
    $mail->setFrom(EMAIL, 'Whoever');
    $mail->addAddress(EMAIL, 'Whoeverr');
    if ($local)
    	$mail->Subject  = 'The email subject';
    else
    	$mail->Subject  = 'The email subject';
    $mail->Body     = 'The email body';
    $mail->addAttachment($report_file);	// optional
    if(!$mail->send()) 
    	{
    		echo '<p>Message was not sent.</p>';
    		echo '<p>Mailer error: ' . $mail->ErrorInfo . '</p>';
    	} 

    The EMAIL constant has the email address that I want to show the email was sent from/to - in this case the receiver and the sender are the same email address - just change them to whatever you want to use.

    Hope it helps.

    P.S., assumes that you are logged in to your email service.

    PPSS, I use PHPMailer as it lets you attach a file to an email if you want/need to.

    • Like 1
  9. Hi Larry,

    I finally got to the point in my complete software re-load/re-build where I could test your suggestion.  I re-downloaded the script from your website and made the suggested change but unfortunately I am still getting the error "on line 29: session_write_close(): Session callback expects true/false return". 

    Here is my modified code:

    // Define the close_session() function:
    // This function takes no arguments.
    // This function closes the database connection.
    function close_session() {
    
    	global $sdbc;
    	mysqli_close($sdbc);
    	return true;
    	
    	// return mysqli_close($sdbc);
    	
    } // End of close_session() function.

    My environment is XAMPP 7.3.5 with PHP 7.3.5 both 64 bit under Windows 10 (64 bit).

    I know that you are a very busy man so please treat this as low priority - I will use a work-around.

    Best regards, Necuima.

  10. Hi Larry,

    On pages 284-5 you mention the browser unload event.

    I'd appreciate your advice re what I imagine is a common issue in that if someone just closes the browser without logging out I want to be able to update a database table to set a logged-out condition. Can this be done reliably either with native JavaScript or jQuery initiating an AJAX call to a PHP module to effect the database update?

    My program is PHP with lots of jQuery.

    Looking forward to your advice re this or similar functionality and thank you in anticipation.

    Cheers, Necuima

×
×
  • Create New...