How to Integrate PayPal Payments Pro Using PHP

How to Integrate PayPal Payments Pro Using PHP

This is a video screencast that was created to go along with this Nettuts+ tutorial.

Step by step instructions on creating a PHP application to process credit cards using PayPal Payments Pro, specifically the DoDirectPayment API.

The tutorial includes the steps for creating a basic application structure with configuration details, generating an NVP API request to send to PayPal via HTTP POST, and parsing the response data returned from PayPal to handle the result accordingly.

Share:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

22 comments

  1. Hello angelleye,

    I am using your paypal payment pro DoDirectPayment library for credit card transactions and its good at sandbox when my client test it live then he faild the transaction. he told me that paypal says this method is old ??? is paypal payment pro method is old and payflow is new ?

    Hope you give me better answer.

    There is no error generated by paypal. client told me that our site is not connected with paypal but its done at sandbox :(

    Any help appreciated.

    Thanks in advance,
    Aezaz

    • Hi Aezaz,

      They have a new version of Payments Pro now, but DoDirectPayment still works with it. It’s just a matter of having it enabled on your live account. Have you signed up for Pro on that account? It costs an extra $30/mo so you have to get signed up and agree to that charge before it’ll become active for you.

      • Hi Andrew,

        Thanks for your help. Now its working live. but i have one question that is, i have used DoDirect method of paypal payments pro and paypal say its old method :( , can you tell me which one is new method for direct payment ?

        Thanks again for your help.
        Aezaz

        • Unfortunately, some of the PayPal reps are misinformed about their own products. PayPal has launched a new version of Payments Pro (3.0) but it still works with DirectPayment. They are opening up the PayFlow gateway to PayPal merchants now, too, which is what they actually did with 2.0. Technically, you have access to both PayFlow and DoDirectPayment, but lots of reps seem to think you have to use PayFlow. In reality, even if you build API requests using the PayFlow API, if your merchant is PayPal, the PayPal system actually rewrites it and pushes it through DoDirectPayment anyway.

  2. Quick question:
    I’d like to check if the following is possible with/without any specific compliance requirements to be met by the Merchant (like PCI/DSS).

    1. The first time, all card details are accepted on the merchant site, and a call to DoDirectPayment() is made to process payments.

    2. Now, the Merchant ‘saves’ the card details into their private db.

    3. The next time the same customer (who is logged in) comes in to make a payment….the Merchant’s site does not ask the customer to fill in the info, but simply uses the saved info (say, by using the last 4 digits of the card as a user selected option) and calls DoDirectPayment() to do the payment.

    Would this be possible?…basically, trying to avoid the filling in card details for every purchase on the same site for the same customer.

    • Actually saving the CC data to your local database would indeed raise PCI Compliance issues and would cause you to go through a lot of headaches (and spend a lot of money) to be officially compliant. The good news, though, is that you don’t have to do that. You can use what are called Reference Transactions instead.

      Reference transactions are exactly what you mention…using previously saved info to process a new payment…but PayPal is the one saving the CC data on their servers. Using the DoReferenceTransaction API you can simply pass in the transaction ID of a previous Auth or Sale transaction along with a new amount to be charged. PayPal will process it using the info they have saved from the previous transaction.

      This is a much more secure way of doing it and is definitely recommended.

  3. I am using your great library to communicate with Paypal. We are using the CreateRecurringPaymentsProfile for subscriptions. I am getting a timeout error (after 3 to 5 seconds) when connecting to Paypal. It doesn’t matter if we hit the sandbox or production. Same error for both sites. Any ideas?

    Thanks
    Eric

    • Hi Eric,

      Do you know if you have a Firewall or something that could be blocking communication with PayPal’s servers? If you want to send me a copy of what you’re working with I’ll see if I can reproduce the problem.

      Andrew

      • Andrew, thanks for answering. The issue was an ill formatted expiration date for the credit card. Correcting that got us by the timeout error. Hopefully that helps someone in the same boat.

        Now on to the next issue. Learning to hate paypal more each day

  4. Hi Andrew,
    I’m getting the following error using CreateRecurringPaymentsProfile. Any ideas:

    An error occurred in script ‘/Applications/MAMP/htdocs/HelpYouSponsor/modules/paypal/includes/paypal.class.php’ on line 6600: Declaration of PayPal_Adaptive::CURLRequest() should be compatible with PayPal::CURLRequest($Request) Date/Time: 10-15-2012 14:53:48

    The script is working and I’m getting successful test transactions but my error script always spits this out.

    Thanks,
    Chad

    • I’m not sure what would be causing that. I don’t seem to be getting that. Contact me directly and I can work with you to try and figure out where that’s coming from.

  5. Vince Hartmanq

    Hi Andrew,

    I’m receiving the same error as Chad received above for GetVerifiedStatus.

    Strict Standards: Declaration of PayPal_Adaptive::CURLRequest() should be compatible with PayPal::CURLRequest($Request) in \includes\paypal.adaptive.class.php on line 4336

    I’m receiving the data back for the verified Paypal account, but I don’t know how to specifically fix this error with curl().

    Thanks,
    Vince

    • Can you send me a copy of the file you’re working with and I’ll see if I can reproduce the issue and figure out what’s up..??

    • at least for me, this strict standards error reporting was covering up a simple curl function not being found. you use phpinfo or just comment out strict error reporting for sandbox mode in the config to see where the real error is. definitely try the second option if you’re working with php 5.4+ where e_all now includes e_strict.

  6. Mike Jouwstra

    I am also getting PayPal_Adaptive::CURLRequest() should be compatible with PayPal::CURLRequest($Request)

    Have you found any causes to this error? I’m running php version 5.4.4, and my config for sandbox has E_ALL for error reporting. Commenting out the error reporting doesn’t seem to get rid of it.

    Thanks!
    Mike

    • Sorry for the delay getting back to you. I’ve got this fixed in my current local version. I have a few things I need to fine-tune before I release the next official update, though. If you want to contact me directly I’d be happy to get you the current version that resolves this warning.

      • Hi Andrew, i’ve got the same problem. I’m new to integrate your library on my apps. And in my opinion, if we set ‘display_errors’ to ’0′ it will not show the error anymore. But i dont know this is safe or not??

        And in my opinion, it is because in parent class(paypal.class.php) on method CURLRequest receive one parameter but on child class (paypal.adaptive.class) receive 3 params. This maybe cause the error.

        Trying to solved it with add parameter on parent and child class just like this :
        paypal.class => function CURLRequest($Request=”, $APIName=”, $APIOperation=”)
        paypal.adaptive.class => function CURLRequest($Request=”, $APIName=”, $APIOperation=”)
        paypal.payflow.class => function CURLRequest($Request=”, $APIName=”, $APIOperation=”)
        But i dont know, is it secure/safe enough??

        • Yes, simply setting display_errors to 0 will get rid of it and you won’t have any issues. I ran it that way for a long time and still have quite a few solutions in place that don’t have the fix included.

          You are correct about the fix, though, so you may just want to go ahead and do that. You just need to make it so that function has the same parameters in all of the child classes as it does in the parent class. I’ve done this already with my local copy, but I still have some other things I need to get done before I upload the official update.

          What you’ve outlined here, though, is exactly what I did to fix it. Just add those extra parameters in each class that function exists.

  7. Eric Uldall

    [Errors] => Array
    (
    [0] => Array
    (
    [Receiver] =>
    [Category] => Application
    [Domain] => PLATFORM
    [ErrorID] => 580001
    [ExceptionID] =>
    [Message] => Invalid request: {0}
    [Parameter] =>
    [Severity] => Error
    [Subdomain] => Application
    )

    )

    I’m getting an error but can’t tell what the error means. Any help is appreciated. I’m using the demo for adaptive payments and have all required fields filled out.

    Thanks,

    Eric

    • Please send me a copy of your RAW request that is getting generated. It’s available in the result that comes back from the library when you make the call.

    • Hi Eric,

      I’m sorry for the delay getting back to you. I’d be happy to help, but that error alone isn’t doing me much good. Can you send me a copy of the RAW request you’re using, or the file you’re using to generate it? Please do so directly via the Contact page on my site.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>