Paypal Integration with PHP - php

I'm looking to implement a very simple Paypal integration whereby I can enter a valid Paypal Email address (recipient) and a dollar amount, and click "Pay." Ideally, it would send the money from my paypal account automatically via my API key.
I currently have Mass Pay set up with PHP, and it's working fine, except that it charges me 2% on every payment, and doesn't pass back the Transaction ID. It also kinda seems unnecessary since I don't need to pay multiple people at once.
Since I only need to do one transaction at a time, I'm wondering if anyone knows of a simpler Paypal API for single outgoing transactions from my account.
I've been reading the documentation all day and I've yet to find what I'm looking for.
Any advice is greatly appreciated!

PayPal has sample codes for integrating various PayPal features on it's website. This includes PHP take a look at the list of features and I'm sure what you are looking for is there.
Also from the paypal site:
PayPal receives the MassPay request and returns a response indicating
success or failure. If PayPal returns a successful response, then
PayPal processes the payments and, if you have Instant Payment
Notifications (IPN) enabled, PayPal sends a notification to the Notify
URL specified in your account profile. If you do not have IPN enabled,
you can view the details of the MassPay transaction in your PayPal
account.
This implies that in the case of mass pay you need to provide a URL where paypal sends payment notifications. Your program can probably check this url to figure out whether a payment has been made or not, I would suspect this would be the case for all payment integration. That being said I would print_r the the response from paypal, I'm sure something like a transaction id will probably be in there. In the case of DoAuthorization it does return the transaction id
In the case of mass pay it does return the transaction id if IPN is enabled

Related

Payment info using paypal

I have Integrated Paypal using php. I know there is return url ,that means when payment is received it will return to the url for our website.My Question is if payment is received and due to internet problem it does not return to our web page, how do I know that payment is received from a particular user?
If there is a network issue and PayPal cannot issue the IPN message, then according to their documentation, they will retry 15 times up to 4 days.
The IPN message service does not assume that your listener will receive all IPN messages. Because the Internet is not 100% reliable, IPNs can get lost or be delayed. To address these issues, the IPN message service includes a retry mechanism that re-sends a message at various intervals until your listener acknowledges receipt. An IPN message may be present up to four days after the original was sent. The maximum number of retries is 15.
https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/
This item below might help. Instant Payment Notification should work, but in the case of a network failure, if the payment reached PayPal but the purchaser did not get back to your site to complete a purchase, then you should still receive an email from PayPal telling you that you have received a payment.
using paypal button - can my webpage tell if paypal transaction was successful or not?
You get a confirmation email with their name and email address - be aware that occasionally this may not be the user's current, most active email address. You can also log in to your PayPal dashboard to see all details as well, of course.
You can look up your payment details from the email and compare them to your own user records in your database. If the email they use for PayPal is not the same as the one they registered on your site with, you can still look up their name from the email - in practice it seems to happen extremely rarely that payments have such a problem in my personal experience
I set up a script which emails my users with a passcode to get to the online product they bought which is emailed to them so they can submit that later along with their email address. This is the first thing that happens on return to my script so at least if the site fails to respond properly they can get to what they bought later.
The script uses PHPMailer and cc's me with their passcode so I have it available to re-send to them if they write with a complaint. It doesn't help if the PayPal return for Instant Payment Notification fails completely but the other answers cover that very fully and detail the PayPal repeat attempt process well.
Instant Payment Notification scripts can be downloaded from PayPal for modification by yourself as per the article linked to above.
To be perfectly honest, this is one of PayPal Standard's largest holes. IPN is a POST callback (as is PDT) and they check to make sure they get a 200 response or else they retry (and you can use the IPN history in your PayPal account to resend missing IPNs). But this method still relies on you getting the callback in a timely manner and it's not foolproof. Worse, you need to verify the IPN call and that introduces yet another point of failure in calling PayPal to make sure they did indeed send you the IPN you got.
There's a couple of ways to deal with this
Audit your account regularly. This is a good idea in general, but for a small website this shouldn't be terribly hard. Match your invoices up to your PayPal payments. Obviously this doesn't scale well so...
Switch to Payments Pro. There's more hurdles to this (like more PCI compliance, SSL certificate, etc) but the major advantage is that the API is far less susceptible to the whims of the Internet and only involves one call for credit cards (you can ignore the IPN because the API tells you everything you need to know). The worst that can happen is you send a payment API call and fail to get a response. This is exceptionally rare as PayPal makes sure their API is 99.9% reliable (IPN relies on your server being reliable). Speaking from experience, Payments Pro has far fewer issues than IPN does.
In your application, you should have a status field for orders. If you haven't received the ipn, you wouldn't change the status to Paid.
After that, if you receive an email from Paypal that someone has paid, check the order number, and change the status manually.
how do I know that payment is received from a particular user?
Paypal will send an email both user and you.
Paypal offers 2 solutions for your problem.
PayPal IPN - it notifies the server with a POST request to a specific URL, whena transaction has been successful, declined, aborted by user and so on. Paypal provide an IPN Simulator (the worst simulator ever) in order to test its functionality. you may give it a try at : https://developer.paypal.com/developer/ipnSimulator/
Paypal WebHooks - The webhooks are the "New Kid in the Block",they are basically "user-defined HTTP callbacks that receive events for the subscribed event types. Webhooks are asynchronous, the order is not guaranteed, and idempotency may lead to the same event being sent more than once." as stated in the Paypal documentation.
You can read more about it on : https://developer.paypal.com/docs/integration/direct/rest-webhooks-overview/
For any further help, comment below and I shall try to help.
Cheers,
You have to use notify_url for this purpose
<input type="hidden" name="notify_url" value="https://domain-name.com/ipn.php">

Logging PayPal payments in application

I have several ambiguities in using paypal methods and cases, when IPN messages are sent. Im developing app, in which im using paypal(sandbox) for making deposits and cashouts. Each of these both transactions I want to log in my app and here some obscurity raises becouse I need to capture as many cases that may occur. So I'll take it gradually and I'll be thankful also for each partial response.
Firstly, I have some general questions:
In my app, im using BuyNow button, AdaptivePayment methods PAY and PaymentDetails and Merchant method GetTransactionDetails. Are these methods part of Bussines account and for free (there are no monthly fees) right? I cant afford to pay some monthly fees from begining.
May arise any problems, when i'll deploy it to non-sanbox environment?
cashout
For cashout Im using Adaptive payment PAY method.
When My app client make a cashout to his/her paypal account, I can catch through IPN message, that payment is completed and using AdaptivePayment PaymentDetails method and Merchant GetTransactionDetails method I can find out, that there is pending status with paymentreview reason. So on receiver side, where I dont have access, is payment review possibility. Thus receiver can DENY payment and here is a question, how to get information about this user action, becouse an IPN message doesn't come.
Another case that im facing is when client of my app make cashout to
his/her bussines paypal account with different currency from sender
(my bussines paypal account). There is pending status too, but with
reason "multicurrency" in IPN message. Here is similar problem to
previous point 1)... again, I cant get IPN message, which
determine, if user accepted or not the transacion.
deposit
For deposit Im using PayPal standard Buy now button.
PAYER SIDE(my app client): I dont understand, why there is payment
review (accept/deny) in payer account profile, when status of
payment is completed? Is it common behavior only in sandbox
environment? Or is it possible accept/deny payment on payer side in
non-sandbox?
RECEIVER SIDE(my bussines paypal account): There is payment review
too, on receiver side, and if im right, these links (accept/deny)
are similar to links on payer side, arent? There is refund
posibility too, exists some API method to refund programatically?
Correct, each of the products you mentioned do not have a monthly fee.
If a user accepts or denies a pending payment that would trigger another IPN with the completed status. Are you saying you've tested this specifically and you're seeing otherwise?
Receivers would only have to accept/deny in cases where there is currency conversion or maybe they have fraud filters set to flag specific transactions, etc. In most cases there should be no review necessary.

Callback from PayPal. How to know the user paid successfully immediately?

I am running a e-commerce website and I want to integrate PayPal. I need to know immediately whether a user paid successfully or not after they paid via their credit cards. Is there a chance i can do that with PayPal?
I've heard PayPal has a service called IPN, which can post to my server and tell me the transaction's status. But lots of people are complaining that there are huge delays with IPN's PHP API.
Just finished an IPN integration a few hours ago :).
IPN stands for INSTANT payment notifications. In most times it just works(hi Apply fans!).
You add a form with variables such as currency and return URL and with a special page that you expect Paypal to send transaction information when the payment is made. Receiving a notification does not mean funds are sent to your account but the transaction has completed. (possible reasons to not get funds to your account include problems with card provider, incomplete accounts, etc)
You will face some questions regarding specific problems. But I would suggest checking paypal site and it's API docs. They are pretty straight forward and with a little understanding in your programming language and how HTTP works, you can implement it.
I have seen some posts about PayPal IPN system is slow. I have not seen it myself but in most cases, I'm sure you will get paypal API calls just before the user come back to your site.
I've had great success with nSoftware's PayPal plugins.

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! ;)

How do I get data back from Paypal so I can alter my MySQL database accordingly?

I'm just starting out with Paypal, so this is a newbie question.
I've been going through the instructions for setting up Paypal subscription service, but I think I'm looking at the wrong thing.
What I want to acheive is to get back some kind of response from Paypal so that I can update the database on my web site to mark a registered user as having paid. Basically I have a flag in the database that says if the user is subscribed or not. I want to ensure that the user is marked as paid so long as their Paypal subscription is maintained.
While the instructions linked above do say how to set up a button to receive a payment, there's nothing there about getting any data back from Paypal.
I know there are terms like IPN and sandbox that are related to what I'm trying to do, but I can't find clear instructions for how to get started on this process. I'm just circling around and not getting anywhere.
Where do I start on setting this up? Where is there a clear beginner's tutorial?
Also, I'm using PHP/Javascript/MySQL on my website.
PayPal's IPN service is what you want to use. I've used it myself to do just what you're looking to do.
Instant Payment Notification (IPN) is PayPal's message service that
sends a notification when a transaction is affected. Once IPN is
integrated, sellers can automate their back office so they don’t have
to wait for payments to come in to trigger order fulfillment. IPN can
send notifications for these transactions:
Instant payments, including Express Checkout and direct credit card payments
eCheck payments and pending, completed, or denied status payments
Pending payments
Recurring payments and subscriptions
Authorizations
Disputes, chargebacks, reversals, and refunds
You can also view notifications on PayPal’s IPN History page and
resend them if you need to. As PayPal’s interface for handling
purchase confirmation and server-to-server communications, IPN can
also be used to manage and customize a variety of APIs and
communications, including:
Customize your website's response to customer purchases in seconds
Track customers via IPN "pass-through" variables
Notify sellers who deal mostly in software downloads and other digital, online goods
Track affiliate sales and commissions
Store transaction information in your own database
For more about IPN:
Technical Overview (link to new html version of docs on developer central)
Instant Payment Notification Guide (PDF)
Code Samples
I'm not sure if its the same thing, but I just setup my friends website with Express Checkout, and I wanted to add all paid orders to an orders table in my database.
After I call SetExpressCheckout, and the user is returned to my site after going through the purchase flow on Paypal's side,
I used the information from GetExpressCheckoutDetails.
Then, if DoExpressCheckoutPayment
is successful (also called from the "callback" page) I then do the appropriate work in my database as far as logging the order details. For you in this case, it could be updating a record for the user in the database.
Hope that helps a little.

Categories