Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ PayPal checkout and PHP

Posted by: tudsy Aug 4 2022, 03:48 AM

Hi

I am trying to process transactions using PayPal SDK. I also want to pass php variables to the PayPal code found on their (PayPal) website.

Attached is process1.txt(php) which has the php and the paypal code for a paypal button inside.


Any help will be appreciated.

Thanks. biggrin.gif


Attached File(s)
Attached File  process1.txt ( 5.64k ) Number of downloads: 370

Posted by: CharlesEF Aug 4 2022, 07:13 PM

If this is a paypal process script 'process1.txt(php)' then why all the javascript? PHP (server side scripting) can't run javascript, only the browser can (that's why it's called client side scripting). Javascript can call a PHP script but only if you use AJAX.

Do you want the form to submit when the paypal button is clicked?
Or, do you want the form to stay in place when the paypal button is clicked?

Posted by: tudsy Aug 5 2022, 08:11 AM

Hi

Thanks for that.

When the form is submitted and the PayPal button is clicked, I want the Price, Graphic and url information appearing in the PayPal environment. I might take up your suggestion to use AJAX.

Thanks.





QUOTE(CharlesEF @ Aug 5 2022, 09:43 AM) *

If this is a paypal process script 'process1.txt(php)' then why all the javascript? PHP (server side scripting) can't run javascript, only the browser can (that's why it's called client side scripting). Javascript can call a PHP script but only if you use AJAX.

Do you want the form to submit when the paypal button is clicked?
Or, do you want the form to stay in place when the paypal button is clicked?


Posted by: CharlesEF Aug 5 2022, 02:29 PM

QUOTE(tudsy @ Aug 5 2022, 08:11 AM) *

Hi

Thanks for that.

When the form is submitted and the PayPal button is clicked, I want the Price, Graphic and url information appearing in the PayPal environment. I might take up your suggestion to use AJAX.

Thanks.

If you want the form to submit then all you have to do is make sure that each value you want to send to the PHP script is in some HTML element that will be part of the $_POST array. Price and Graphic might already be in an HTML element. URL might need to be placed in a hidden input so it will be sent to the server in the $_POST array. You might not need the URL in the $_POST array at all, just hard code it in the PHP script. I'm not sure what information is in the URL but do you want users to 'view source' and see it?

Posted by: tudsy Aug 11 2022, 09:40 AM

Hi

Thanks for that.

When I include the updated process1.php (txt) file, I get a white screen. I dont know whats happening.

Attached are the relevant files:

yourart1.php -> form1.php -> process1.php.





QUOTE(CharlesEF @ Aug 6 2022, 04:59 AM) *

QUOTE(tudsy @ Aug 5 2022, 08:11 AM) *

Hi

Thanks for that.

When the form is submitted and the PayPal button is clicked, I want the Price, Graphic and url information appearing in the PayPal environment. I might take up your suggestion to use AJAX.

Thanks.

If you want the form to submit then all you have to do is make sure that each value you want to send to the PHP script is in some HTML element that will be part of the $_POST array. Price and Graphic might already be in an HTML element. URL might need to be placed in a hidden input so it will be sent to the server in the $_POST array. You might not need the URL in the $_POST array at all, just hard code it in the PHP script. I'm not sure what information is in the URL but do you want users to 'view source' and see it?




Attached File(s)
Attached File  process1.txt ( 5.16k ) Number of downloads: 341
Attached File  form1.txt ( 7.38k ) Number of downloads: 320
Attached File  yourart1.txt ( 16.26k ) Number of downloads: 384

Posted by: CharlesEF Aug 13 2022, 02:47 PM

A 'white screen' normally means there is an error in the PHP section of the page. Do you get any errors? Did you check the PHP error log? I only know what you tell me but you don't tell much at all.

Give me some time to go over your script.

Posted by: CharlesEF Aug 17 2022, 01:44 AM

The only thing that I see is a syntax error. This if statement is missing the closing curly brace.

CODE
if ($age > 13){

Posted by: tudsy Aug 18 2022, 03:55 AM

Hi

Thanks for that. There is no error file produced. Sorry for the lack of information.



QUOTE(CharlesEF @ Aug 14 2022, 05:17 AM) *

A 'white screen' normally means there is an error in the PHP section of the page. Do you get any errors? Did you check the PHP error log? I only know what you tell me but you don't tell much at all.

Give me some time to go over your script.


Posted by: tudsy Aug 18 2022, 03:56 AM

Hi

Thanks for that. There is no error file produced. Sorry for the lack of information.



QUOTE(CharlesEF @ Aug 14 2022, 05:17 AM) *

A 'white screen' normally means there is an error in the PHP section of the page. Do you get any errors? Did you check the PHP error log? I only know what you tell me but you don't tell much at all.

Give me some time to go over your script.


Posted by: CharlesEF Aug 18 2022, 02:42 PM

What version of PHP do you use? When I upgraded to PHP 7.14 I copied 'php.ini-development' to php.ini and all the errors appear on screen. Since you say there is no error log do you see PHP errors on screen?

Posted by: tudsy Aug 18 2022, 02:52 PM




php 8.1







QUOTE(CharlesEF @ Aug 19 2022, 05:12 AM) *

What version of PHP do you use? When I upgraded to PHP 7.14 I copied 'php.ini-development' to php.ini and all the errors appear on screen. Since you say there is no error log do you see PHP errors on screen?


Posted by: CharlesEF Aug 18 2022, 08:46 PM

Insert this line at the top of your PHP script:

CODE
ini_set('display_errors', 1);
Do you see errors on screen now? If you want to change PHP.ini to make it permanent then set
CODE
display_errors = On
Or, in v8.1 just copy 'php.ini-development' to 'php.ini'. This should only be done on a development PC.

Posted by: tudsy Sep 7 2022, 08:10 AM

Hi

I have added 3 hidden input tags in process1.php but I am not sure where to put these in process1.php. Do you put these 3 input tags in the php area or outside the php area of the script process1.php?

Thanks.







QUOTE(CharlesEF @ Aug 19 2022, 11:16 AM) *

Insert this line at the top of your PHP script:
CODE
ini_set('display_errors', 1);
Do you see errors on screen now? If you want to change PHP.ini to make it permanent then set
CODE
display_errors = On
Or, in v8.1 just copy 'php.ini-development' to 'php.ini'. This should only be done on a development PC.




Attached File(s)
Attached File  process1.txt ( 5.42k ) Number of downloads: 181

Posted by: CharlesEF Sep 7 2022, 02:39 PM

Hidden inputs are HTML elements. They go inside the form. When submitted they are passed in the POST array, if you have the name attribute set.

Posted by: CharlesEF Sep 7 2022, 04:27 PM

Did any of the error reporting methods work for you?

Posted by: tudsy Sep 12 2022, 09:29 AM

Hi

Sorry for the late reply.

Yes the error reporting works.

Thanks.



QUOTE(CharlesEF @ Sep 8 2022, 06:57 AM) *

Did any of the error reporting methods work for you?


Posted by: tudsy Sep 12 2022, 12:13 PM

Hi

I found this piece of code on the web:

<?php

function shutdown(){
var_dump(error_get_last());
}

register_shutdown_function('shutdown');

?>

I put this code on top of process1.php script and the output was the word NULL.

Need help!
Thanks.






QUOTE(tudsy @ Sep 12 2022, 11:59 PM) *

Hi

Sorry for the late reply.

Yes the error reporting works.

Thanks.



QUOTE(CharlesEF @ Sep 8 2022, 06:57 AM) *

Did any of the error reporting methods work for you?





Attached File(s)
Attached File  process1.txt ( 5.29k ) Number of downloads: 194

Posted by: CharlesEF Sep 12 2022, 04:39 PM

If error reporting is working now then why do you need this? According to the docs, the shutdown process is called after script execution finishes or exit() is called. When error_get_last is called it returns NULL if there is no error to report. I'll look over your file later, when I have more time. Also, error_get_last returns an array when there is an error. So you should test for an array and use print_r.

Posted by: tudsy Oct 5 2022, 09:22 AM

Hi

Just a quick one. By any chance you had a look at my program?

Thanks.







QUOTE(CharlesEF @ Sep 13 2022, 07:09 AM) *

If error reporting is working now then why do you need this? According to the docs, the shutdown process is called after script execution finishes or exit() is called. When error_get_last is called it returns NULL if there is no error to report. I'll look over your file later, when I have more time. Also, error_get_last returns an array when there is an error. So you should test for an array and use print_r.


Posted by: CharlesEF Oct 6 2022, 03:16 PM

Exactly what problem are you having? I thought it was about the shutdown part. Describe the problem, what you expect from your code and what the code actually does.

Posted by: tudsy Oct 15 2022, 09:36 PM

Hi

Thanks for that.

Process1.php (txt) inserts data in a database from a form (form1.php). It also should produce a paypal button for users to pay with paypal. I ran php -l process1.php and found there to be no syntax errors.

The latest version of process1.txt is that I removed the try-catch block to make it simpler (attached).


Any help would be appreciated.









QUOTE(CharlesEF @ Oct 7 2022, 05:46 AM) *

Exactly what problem are you having? I thought it was about the shutdown part. Describe the problem, what you expect from your code and what the code actually does.

Attached File  process1.txt ( 3.47k ) Number of downloads: 128

Posted by: CharlesEF Oct 16 2022, 01:30 AM

I don't think I will be able to help this time. I have helped people with Paypal problems in PHP but never Javascript. You would do better to ask at the Paypal Community Support Forum https://www.paypal-community.com/mts.

Posted by: CharlesEF Oct 16 2022, 05:27 PM

Also, I didn't see any button in your HTML. I know nothing about Paypal and Javascript but don't you need a button before you can render it?

Posted by: tudsy Nov 17 2022, 09:31 AM

Hi

After talking to the PayPal community, I have settled on the form below:


<?php



if(isset($_POST['Person']) && isset($_POST['Graphic']) && isset($_POST['Price'])){

$person=$_POST['Person'];
$graphic = $_POST['Graphic'];
$Price = $_POST['Price'];

}

$url = "https://ecovib2d.com.au/workfromhome/yourart/".$person."/Graphic/".$graphic;

?>


<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type='hidden' name='business' value='ecovib2d@live.com' />

<input type="hidden" name="upload" value="1">

<INPUT TYPE="hidden" NAME="return" value= "<?php echo $url; ?>">

<INPUT TYPE="hidden" NAME="currency_code" value="AUD">

<input type='hidden' id = 'Cost' name='Price' value='<?php echo $Price; ?>' />
<input type='hidden' id = 'pic' name='Graphic' value='<?php echo $graphic; ?>' />
<input type="hidden" id='Person' name='Artist' value ='<?php echo $person; ?>'/>

<label for='Age_of_Subscriber'>Enter your Age (in years - Privacy purposes):</label>
<input type='number' id='Age_of_Subscriber' name='Age' size ='3' required min='0' max='200' />
<br>
<br>
<label for='Full_Name'>Enter your First Name:</label>
<input type='text' id='FirstName' name='First_Name' required />
<br>
<br>
<label for='Full_Name'>Enter your Last Name:</label>
<input type='text' id='Surname' name='Last_Name' required />
<br>
<br>

<label for='email'>Enter your Email address:</label>
<input type='email' id='email' name='Email_Address' size='30' placeholder ='Your Email Address' required />
<br>
<br>





<p>
View our Terms of Service (https://ecovib2d.com.au/workfromhome/TOC/website_terms_and_conditions_of_use) and
Privacy Policy (https://ecovib2d.com.au/workfromhome/privacy/privacypolicy.php).</p>

<br>
<br>

<!-- Saved buttons use the "secure click" command -->
<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="item_name" value="Your Graphic - <?php echo $graphic; ?>" >


<input type="hidden" name="amount" value="<?php echo $Price; ?>">

<INPUT TYPE="hidden" name="address_override" value="1">

<!-- Saved buttons display an appropriate button image. -->
<input type='image' name='submit' border='0' src='https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_buynow_107x26.png' alt='Buy Now' />
<img alt='' src='https://paypalobjects.com/en_US/i/scr/pixel.gif' width='1' height='1' />

</form>

The problem now is that I am trying to execute a php script at the same time the submit button is clicked.
Do I need Ajax for this ?

Thanks.

<?php

if($_SERVER['REQUEST_METHOD'] ===' POST'){

if(isset($_POST['submit'])){



include "process.php";

}
}

?>

Posted by: CharlesEF Nov 17 2022, 02:19 PM

The for attribute of a label should point to the id attribute of the element, not the name attribute. Both labels for first and last name need to be changed.

Also, this:

CODE
if(isset($_POST['Person']) && isset($_POST['Graphic']) && isset($_POST['Price']))

Could be:
CODE
if(isset($_POST['Person'], $_POST['Graphic'], $_POST['Price']))


Do you want the page to be visible while the PHP script runs? If yes, then you need to use AJAX. You would also need a place in the page to display the results of the PHP script. I wouldn't use a submit button for this. I would use a normal button that calls the Javascript function that runs the AJAX script. You may need to add logic to your PHP script to prevent multiple payments.

Posted by: CharlesEF Nov 17 2022, 04:33 PM

If you don't want to stay on the same page during the payment process then don't use AJAX. Use a submit button but use your PHP script location in the form action attribute. Now you can show the results of the payment process in a new page.

Posted by: tudsy Nov 26 2022, 04:41 AM

Hi

Hi

I have solved the problem of writing data to a database after the submit button is clicked on a form.

<script type="text/javascript">

$(document).ready(function () {
$("#submit").click(function () {
$.ajax({
type: "POST",
url: "process.php",
data:{

Graphic: $('#pic').val(),
Person: $('#Person').val(),
Price: $('#Cost').val(),
Age: $('#Age_of_Subscriber').val(),
First_Name: $('#FirstName').val(),
Last_Name: $('#SurName').val(),
Email_Address: $('#Email').val(),
}

})

});
});

</script>

Thanks.

Adrian

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)