Paypal integration, query - php

I have a question.
I'm using this Paypal code: http://www.saaraan.com/2012/07/paypal-expresscheckout-with-php
I would like to have a premium function on my website, where an user can buy something and the premium featuren should directly be active on his account. How can I enable this? Where should I put the Query to update his account? I mean, what if the paymentstatus is pending, then I don't have the money. Does he have the possibility to cancel the order?
Or should I add the query after the GetTransactionDetails. Or is there the possibility that the order is complete, but the query will not be excuted?
Thanks!

The best solution for your problem would be to create an IPN listener that would receive the transaction details and, if you code it properly, update your user's account accordingly. You could have it programmed to only update the account if the IPN shows that the paymentstatus is complete, if you want to. I have an IPN listener that has about 8 different scenarios depending on the transaction type and payment status.
Do a little research on IPN listeners and you'll see that you can really use them to handle a lot of the tedious details for you. Paypal's developer site has IPN listener code examples that can help get you started.
Hope this helps.

Related

Passing a custom variable from a PayPal button after a user subscribes

I am working on a subscription service for a test website of mine. I have the infrastructure in place so that when a user registers, they need to subscribe before going to their profile. How can I tell if a user has finished subscribing? I have a flag in my database that will turn to true after they subscribe, but I can't seem to figure out that last handshake.
I tried to set it up when making the button to go to "http://www.example.com/profile.php?completed=true" so that I can simply look for that completed variable, but paypal seems to ignore that. Any thoughts on how to do that?
Upon looking at a similar post on here, I could redirect to a success.php, where it can update the database flag. This is a work around, but is this the only solution? Or is there one similar to what I originally wanted to do? Thanks for your input everyone.
You should make use of Instant Payment Notification
Instant Payment Notification (IPN) is a message service that automatically notifies merchants of events related to PayPal transactions. Merchants can use it to automate back-office and administrative functions, like automatically fulfilling orders and providing customers with order status.

php express checkout recurring created profile successfully but recurring not working

we have implemented express checkout very well.
we get ipn response for each transaction.
we done these thing in sandbox.
now we are making recurring payment with express checkout.
here the recurring profile is creating proper,
But i am not getting any ipn notification for transaction and also not any transaction is done for that profile.
Can anyone suggest me solution for this issue.
Help will be highly appreciated.
Thanks
vijay
Recurring Payments transactions send IPN's just fine, so my guess is your IPN script must not be handling them correctly or maybe just "doing nothing" with them. For example, if you're only handling a specific txn_type, then you might be missing out on other stuff.
Log in to your PayPal account and check your IPN History and you should see a list of all the IPN's it's been sending. You can see if it's returning Success or Fail, there, because another possibility is that your IPN script is simply failing when a certain txn_type hits it.
Your own web server logs can be a big help when troubleshooting that sort of thing, too. If you are getting some IPN's, though, it would be sending them all, so something must be going on to make you think they're not sending when they are.

Unique PayPal IPN variable for buyer and seller

I've been working on a website where people can submit questions to me online and I'll answer them for a small fee. I'm using PayPal to collect this small fee, and I've recently successfully implemented the PayPal IPN in order to collect transaction IDs. What I planned on doing was storing the transaction ID and asking the individual for the transaction ID when they ask a question. Once a transaction ID had a question associated with it, it would be marked as used and could not be used twice. I chose this method over having people create an account and storing variables within each account because I figure people will be deterred from using my service (it's related to academia) so this is kind of perfect.
So.. what's the issue?
I had a friend try it out, and we unfortunately found out that the transaction ID that I got and stored is different from the transaction ID that he got, hence completely breaking the system I had envisioned.
My Question
What is a unique variable passed on through the PayPal IPN that I can use to ask the buyer about and ensure that it doesn't get used twice?
I want the process to be automated, which eliminates the possibility of invoices since you have to do those by hand each time.
Thanks for your thoughts and efforts.
You can pass custom in your PayPal integration, which is subsequently returned in the IPN message.
I.e., for Express Checkout:
METHOD=SetExpressCheckout
PAYMENTREQUEST_0_AMT=1.00
RETURNURL=http://...
CUSTOM=yourUniqueDataHere
Or for Payments Standard:
<input type="hidden" name="custom" value="yourUniqueDataHere">
Once the transaction completes, you can find custom in your IPN message's POST data.

Working with Paypal IPN

What I want to do is have a buy it now button somewhere on my site. When users log on they can click it and pay X amount, then after the transaction has completed I need a script to update 1 field in the database with a value.
Someone recommended using paypal ipn for this.
Is that the best solution for what I am trying to achieve?
Will I need some additional script to work with it or is it "ready-made" with just specific database variables requiring changes?
Paypal has a much nicer workflow for this that does not make the user wait an undetermined time for his payment to arrive: Paypal Express Checkout. With this you actually do know that he paid with paypal the very minute he comes back from the paypal page, and you can do all the things needed to make the transaction happen on your side as well.

Paypal IPN needed?

I'm doing a project involving Paypal, more specifically with the NVP API in PHP. But I just can't seem to figure what to use the IPN feature for.
I mean, when the user has been redirected to Paypal to confirm the purchase, he is redirected back to my website's "Paypal-succes-page", when the transaction is complete. And just to be sure that he actually payed i could use the "PaymentDetails" operation.
Now where does IPN fit in this process? and what is the benefit of it?
Thanks
The integrate with PayPal's services you will notice there are three main channels (and IMO it's important to know this so you can decide the benefits for your application):
IPN: Instant Payment Notification
PDT: Payment Data Transfer
PayPal's API
To use PayPal's IPN you need to add a 'listener' script (example) and add the address to your PayPal account. Whenever an event occurs PayPal will send a message directly to your server via your listener and you then update your accounts appropriately. This is especially useful for running subscription services as events will occur in the background without user intervention and you can capture successful/failed recurring payments etc.
PayPal's PDT is a system for accepting data when a user is redirected back to your site from PayPal. For example, a user clicks 'Buy', they are directed to PayPal, enter information etc. Then, once the payment has been taken, they are redirected back to your site. PayPal can pass details about the transaction including whether it was successful or not so you can display the appropriate success/failed page from your site.
PayPal's API allows you to integrate more deeply with PayPal's services, and you would use this if you were managing payments directly from your site.
These services aren't mutually exclusive, so you can use any combination with your application.
I hope this helps
The IPN feature is a very useful feature which you should use to update your database in my opinion. Sure the user is redirected to your success-page after the purchase where you can validate the payment details.
But what if he closes (by accident or not) the browser before reaching your success page? You will never know the result of the transaction and you will never update your database or process his order accordingly.
When using the IPN you can be sure that the transaction result will always reach you because PayPal will keep on making an offline request to your IPN page until it has reached your servers.
Instant Payment Notification
The typical usage of the IPN is to validate the purchase and to let your script or management system know that the transaction is complete so your system can update any records you may have for your service.
But the most important part is that the transaction is validated.
IPN send all data about transaction to your server - price, items, contacts ... so you can check, if someone don't pay you only 1$ instead of 100$ and confirm your order. It prevets thiefs, cheaters, ... USE IT! ;)

Categories