Get data, process payment and then get it again - php

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.

Related

attach website username to paypal IPN product_id

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.

Paypal custom variable unique identifier

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.

Adding an additional variable to a paypal email link

I'm using a paypal button link, and trying to pass arguments to it for the IPN listener.
(I passed them like this: www.paypal.com/.../&name1=value1&name2=value2)
The payment is done fine, and my IPN Listener is called.
The thing is, those additional parameters are not getting into my IPN listener.
Does anyone know how can I pass them, or what am I doing wrong?
If you were going to do it that way you would actually include those URL parameters on the end of your NotifyURL as opposed to the PayPal URL. I wouldn't recommend doing it that way, though, because it can cause issues depending on the values of the parameters.
Instead, you can use the single CUSTOM parameter in your button code and put an NVP string in there. That would come back in IPN as $_POST['custom'] and then you could parse the individual parameters and values back out of that.
Another option would be to save the order details in your database prior to sending the user over to PayPal. You can then include the order ID from your database in the button code using the INVOICE parameter, and again, that would come back in IPN as $_POST['invoice']. At that point you can hit your database to pull the data you need back out based on that record ID and processing it accordingly.

Capturing custom PayPal data using PHP

I have a custom store where I'm selling a single product (as a gift), I need to be able to store the recipients address (different from paypal users), a message for the gift and the name they want their gift to be from (if any).
I'd really like to capture the data on this page:
http://sendvalentinesflowers.co.uk/responsive-buy-rose.html
It appears that the standard buttons don't allow this much data to be passed/stored along side a transaction. I'm just wondering how this HAS to be done with IPN? I'm looking for the simplest way to do it.
I would save all of the information in your local database as "pending" prior to sending the user over to PayPal for payment. You can include the invoice parameter in your PayPal code and set the value to the record ID of your local record.
This invoice value will be returned in IPN so you can pull the data back out and process it as necessary, and also update the existing record's payment status according to the current IPN.

Pass on vars during paypal payment

How do I pass on vars during a paypal payment?
I would like to get the user's id and the item number back (when transaction is completed).
Thanks in advance
Unfortunately, it does not appear the api return a userid or email that i can find- but it does require you send it. there is a transaction number that can be cross referenced in your own database - here is a link for more reading.
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APExecutePaymentAPI
I recommend maintaining all the customer information in your own database, and when using the api call, since you will receive an immediate ack, you will know if it is successful - and can use that to trigger a write to your database of the same information you just sent, along with the response.

Categories