Solved

Complete javascript after call to PayPal

Posted on 2013-02-03
3
345 Views
Last Modified: 2016-03-24
What is the best way to implement a call to PayPal so that after a customer completes the payment process, they are then directed back to the original site where the rest of the javascript can continue?

Perhaps I am not even thinking of this problem in the right terms  Basically I want some javascript code to run, but only after a successful PayPal payment has been completed.

Here is the code for the call to PayPal:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  <input type="hidden" name="cmd" value="_s-xclick">
  <input type="hidden" name="hosted_button_id" value="123456789">
  <input type="image"
      src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.gif"
      border="0" name="submit"
      alt="PayPal - The safer, easier way to pay online!">
  <img alt="" border="0"
      src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1"
      height="1">
</form>

Open in new window


Any ideas or best practices for me to consider?  Thanks.
0
Comment
Question by:DanielAttard
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38848823
when you create your form(button) with paypal, you have the possibility to set this URL in the step two.
You can use the same url/page and add a parameter in the url
or use a different page
0
 
LVL 11

Accepted Solution

by:
Andrew Angell earned 500 total points
ID: 38849006
When using a standard button like you are you just need to set the return URL during the button creation process.  This will be where the user is sent after successful payment.  

That said, there is no guarantee that the user will make it back to this page with Payments Standard.  Even if you have auto-return enabled in your PayPal account the buyer could simply close the browser prior to the return and the code you want to run would never run.

If you have code that you need to make sure runs every time, guaranteed, then you should use Instant Payment Notification (IPN) to handle that for you.  IPN will be triggered regardless of whether or not the user makes it back to your site.
0
 

Author Comment

by:DanielAttard
ID: 38849660
Great points angelleye.  I hadn't thought about the possibility of the user not making it to the return URL.  In my particular use-case, I absolutely need my javascript code to run at the moment the payment is processed on PayPal.  I will start reading-up on IPN.
Thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question