Receive form only if Paypal payment is complete - php

I'm looking for a way to receive a form result by email only if the payment has been completed on Paypal.
I have a form next to my shopping cart.
I want people to fill the form, then they can browse in the shopping cart.
Once they click on "Checkout" in the shopping cart, they are redirected on Paypal.
The form I talked before is still on hold...not sent yet.
When the guy fills his credit card information, click Proceed on Paypal, and THEN...
When the payment is complete, the form he filled on my website will be submited.
But if he decide to close the paypal window and stop shopping, I won't receive it.
I need your help guys/girls.
I'm not sure what language I need to make this work.
I'm guessing PHP and Javascript.
Thanks a lot,
This function is very important for us.

Check out the IPN (Instant Payment Notification).
https://www.paypal.com/ipn/
It will send a message to your server after a payment has been made, sounds like what you are looking for. You can write the listener in PHP and they provide example code.

Related

Paypal shopping cart - Setting database value when successfully completed transaction

I've got a question about the PayPal transaction system. I try to implement a paypal shopping cart in my website. But what I want to do is I want to have like "PrePaid credits" on my website. So when the transaction successfully processed. A database value will change given the credits the user wanted to buy.
I dont have a idea on what to search for. I only know standard php. Not any modification such as paypal. So can anyone give me a code/website where I can find some usefull code?
Thank you!
PS: If you have any suggestions on the post to make it even clearer please comment.
You would use the PayPal IPN (Instant Payment Notification), so a user would click 'Purchase x credits' on your site (you would have a custom field with the user's ID, it would then take them to PayPal via custom form you put together, that form has a return URL which after the payment has been successfully made, would return them to that URL, and you would make that success return URL update your database with the details.
So on a successful return from PayPal, your page would update the database with the custom value (User ID) we initially passed in the form along with the amount of credits they purchase (this can be passed via custom value OR you could just use PayPal's callback information returned with the query (it'll be posted to your page from PayPal I believe).
PayPal Sample Code
Getting Started with the PayPal IPN
Nettuts - Using PayPal's Instant Payment Notification

How online shopping works in this case?

I would like to create a web form for the buyer to fill and then a direction to Paypal to pay the item, then comeback to the page and if the purchase is approved it submits the form and wait send me an email with its details.
I know how to create the form but front-end, and also I know how to send a php email to submit the form. But what about the payment part ?!
Can someone explain me how it works.
Is it possible to create something like this?
Any tutorial or similar example, links would be useful.
Look into the Paypal API
https://www.paypal.com/cgi-bin/webscr?cmd=_dcc_hub-outside
When the user successfully completes the transaction the result is sent back to the page, you then check if the result was successful, if so onwards with whatever code.

Does paypal generate any event after clicking pay now button?

I've a shopping cart implemented in PHP and the checkout process is handled by PayPal. When the customer presses pay now button in PayPal, does it generate any events so that i may process that information and based on the stock levels in my database decide whether to accept the payment or not?
No, but you can do that after payment with PayPal IPN, it sends all the data about purchase back ..
You could use javascript to query your server about stock levels on-click, and submit the form if everything looks OK.

Handling canceled Paypal payments

I am currently using Paypal as a payment system on a website I'm working and so far everything works great...except one thing. Once the payment is complete, Paypal calls the IPN page I provided and everything's good. But if the person cancels the payment, I'm not sure how I'm supposed to know that since Paypal doesn't call the IPN in that case (at least, from what I understand).
Sure, if the person clicks on "Cancel and return to the website", he will come back to the Cancel page I provided. But what if he just closes the paypal page? He would never return to my website's cancel page.
In some cases, I guess it wouldn't be much of a problem. I'm sure there is a way to know if the payment is canceled but I just can't find it, which is why I'm here.
Thanks for your help.
you should be able to implement some sort of confirmation field in your transaction table, eg: ipn_confirmed.
You set it to default as unconfirmed and set it as confirmed when paypal's IPN return the value. Then, you will only process request that is confirmed. If there is a glitch in the matrix, you will need your customer to contact you and send his/her paypal's transaction info and match is with your data. If it match, process it.

click pay now in paypal page update my database too

I have a table to store my credit from user has been paid.
credit
+id
+amount
My goal is when you user click on button pay now in paypal page I have abiltity to update my table the amount field.
Anybody know the ways to do this,
thanks
EDIT: look at this code
http://www.micahcarrick.com/04-19-2005/php-paypal-ipn-integration-class.html
If the button goes off to PayPal, you'll need to intercept the request first, either with AJAX, or send to a PHP script, and then send on through to PayPal.
PayPal's Instant Payment Notification protocol is usually what's used to do this.

Categories