I know that the recommended practice to use the custom variable of Paypal buttons is to pass an identifier which is a reference to some data in a database and then when Paypal returns a response, verified that id with its corresponding reference in the database in order to do extra processing,
But my question is, if I save data in the database when the user clicks on the Paypal button, the user gets redirect to the Paypal, how will I know that the transaction was never completed if the user clicks on the back button on his browser? Because if the user does that, I will get no response from Paypal (Completed or not). If I don't have any response from Paypal, then I just saved some data in my database for no reason.
How should I solve this issue?
I have a big form with a lot of fields, so I cannot send all that data in the custom variable since there is a limit.
Please help!
I would save them as "pending" status when they're unpaid. Then if the payment never completes you would have a record of the pending order and you could either follow up on those to try and convert them into an order or simply delete all pending orders to clean it up.
Related
i have IPN data sending back the correct info, i have the product id and i also have a text box for user's to write in their in-game-name in on my website.
im stuggling to attach the username input with the IPN product_id. what i want it to do is when the user clicks the paypal button, it process's the transaction and if approved the username entered from the website and product_id get placed into a array or something that i can later put into my database
im quite new to php and html please bare with me
When you create a PayPal transaction, pass a variable named custom with the values you want to store as part of the transaction.
For old-style HTML integrations that use no API or JS, this is documented here: https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/Appx-websitestandard-htmlvariables/#payment-transaction-variables
IPN is very old and clunky. Crrent PayPal integrations don't use IPN at all, but rather two routes on your server that call the PayPal API -- one for 'Create Order' and one for 'Capture Order', documented here: https://developer.paypal.com/docs/business/checkout/server-side-api-calls/#server-side-api-calls
When you do that capture call you get an immediate response of success/failure and can update your database/system accordingly. Thus there is no need to wait around for PayPal to send you an IPN notification.
Those two routes on your server should return JSON data (and only JSON data) when called. The approval flow to pair with them is https://developer.paypal.com/demo/checkout/#/pattern/server
You can add POST data values to your fetch request.
I have a website where I want the form data to be submitted only if I know the customer has paid via the PayPal button. Right now I have it at the point where they can pay and I verify it (via IPN) and that's about it.
I'm looking for some ideas on the best way to approach this? I was thinking that when the IPN verifies I can insert a column into the DB saying "paid" and store some information in the session. You can then only access the form if that data is in the session. Once the form has been completed I can update the status from "paid" to "completed" and remove the session data. I would remove the session data because a customer can pay as many times as they like with different form data each time.
Any other ideas? Also, this isn't a site where you would log in.
To sum it up, I want the customer to pay first (and I know they paid) then fill out a form.
If you don't have any login mechanism, I would request an email aswell when paying, Store the email + paymentID (unique PK) in the DB, when payment comes back through IPN, email the customer with a secret passkey, you can only move forward with that passkey.
In my opinion sessions are a problem to use for paying user. what happens if that user's computer crashs right after he paid. He has no way to access his product. An email + secret passkey would enable him to
I have already done a small e-commerce with Paypal and it works, but I feel like it is done wrongly.
Because the page that handles the IPN response from Paypal can't read $_SESSION variables, before the user submits the form and is redirected to Paypal, I get all the cart items and store them in a table in the database and also I register a new order with the user information but with the status 0 ( not completed ).
Then, after the user pays and I get the IPN response, I check if the status is completed, check if the amount paid is correct, currency and the usual checks to make sure the payment is successful.
The problem with this approach is that if the user once redirected to Paypal, decide to leave/close the browser/Paypal tab, I will have a failed order registered in the database and I can't delete it but manually.
How can I handle this kind of situation, and is it correct to register the order/cart before the user pays ?
Thank you and sorry for the long post.
If you want to check if the transaction occurs rely on the IPN messages. Depending on which api you are using you have several way to customize the IPN message with useful information for you, ie:
using paypal custom field
define dynamically the IPN url with extra parameter ie www.yoursite.com/ipn?myvar=myval
That way you can have a hook between the payment and the actual user in your application.
Obiusly the php session attributes of the user is not available when the http post comes from paypal.
I've set up my IPN on PayPal and I get the transaction id, product name and all that but my question is how can I set up custom fields that I can retrieve after payment using the IPN?
Thanks in advance
There is a parameter called CUSTOM that you include in your button code or API calls. Anything you pass here will come back in IPN as $_POST['custom']. If you need multiple parameters you could store them there as an NVP string or however you want to pass them and then parse them back out within your IPN script.
Alternatively, you could save all your order data to your database prior to sending the user over to PayPal. Then you can include your db record ID in the PayPal payment using the INVOICE parameter, which again, would come back in IPN as $_POST['invoice']. With that you could pull the data back out of your DB based on the record ID and process it accordingly.
Am I correct in my understanding that I can only pass-through one custom variable from a form I create to PayPal using IPN?
I have my IPN script up and running with no issues. However, upon payment notification I need to store information input by the user from a form on my site into a MySQL database.
In this specific case its for a sports league registration form. The user fills out info regarding their team (i.e. Team name, League, ect..) then pays the league fee via PayPal. Upon verification I'd like to store their team name, the league they're signing up for and other info I need to collect in my database. But since I can only pass-through one custom variable from my form through the PayPal IPN process, I'm a bit stumped.
I've read other posts about storing the info immediately in the database, then marking it 'paid' upon verification. However, how could I accomplish this since when the user clicks Pay Now, the form action performed is the PayPal payment process (as opposed to an insert statement I create). Where would I perform a database INSERT with the posted form information?
Tips or advice would be appreciated!
However, how could I accomplish this since when the user clicks Pay Now, the form action performed is the PayPal payment process (as opposed to an insert statement I create). Where would I perform a database INSERT with the posted form information?
Perform the INSERT before sending the customer to PayPal. Before that, define a unique random key for the transaction. Put that key
into the database record that's being inserted and
pass it to PayPal's IPN.
Once notification comes back from PayPal, you can use the key to identify the record (with all the info already in it) and mark it paid.