How to Process Credit Cards with PayPal Payments Pro Using PHP

How to Process Credit Cards with PayPal Payments Pro Using PHP

Tutorial Details
  • Difficulty: Intermediate
  • Topics: PHP, Paypal
  • Time required: 30 minutes

PayPal is one of the most popular payment processing platforms available today for many reasons. Its ease of use and its connection to the eBay platform are just the tip of the iceberg. While one of its most popular features is the ability to simply sign in to your PayPal account to submit payments, merchants using PayPal can also accept credit cards directly just like a traditional merchant account solution would provide. 

PayPal calls this solution Payments Pro, and I’m going to show you exactly how you can process credit cards directly with PayPal’s API using their Payments Pro web service API’s.


Step 1: Setup the Directory Structure

The first thing I like to do with any project is to create a basic structure organized for the project.  In this case, our structure is very simple as our project will consist of only 2 files:

Directory Structure

 As you might have guessed, we’ll be storing our configuration information in config.php, and we’ll actually handle the processing code in process-credit-card.php.


Step 2: Setup the Config File

Our /includes/config.php file will house our values for the PayPal API information we need including the end-point URL, API version, and our API username, password, and signature that we’ll be using. 

// Set sandbox (test mode) to true/false.
$sandbox = TRUE;

// Set PayPal API version and credentials.
$api_version = '85.0';
$api_endpoint = $sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
$api_username = $sandbox ? 'SANDBOX_USERNAME_GOES_HERE' : 'LIVE_USERNAME_GOES_HERE';
$api_password = $sandbox ? 'SANDBOX_PASSWORD_GOES_HERE' : 'LIVE_PASSWORD_GOES_HERE';
$api_signature = $sandbox ? 'SANDBOX_SIGNATURE_GOES_HERE' : 'LIVE_SIGNATURE_GOES_HERE';

Reviewing the config.php code, you can see that first we set a variable for $sandbox.  For now, we’ll leave this to TRUE because we want to interact with PayPal’s sandbox (test) servers for development purposes.  You’ll need to remember to change this to FALSE when you’re ready to move your project to a live server.

Then, based on the value of $sandbox we’re setting values to other variables for our API information.  You’ll just want to fill in those placeholders with your own details accordingly.  Now we’re ready to build our credit card processing script.


Step 3: Create an API Request

Now we can begin to build our process-credit-card.php page.  The first thing we need to do here is include our config file.

// Include config file
require_once('includes/config.php');

Next, we need to build a name-value-pair string that includes all of the data we need to send PayPal in order to process this payment.  A name-value-pair string looks just like something you might see when passing data via URL parameters.  We just need to make sure our parameter names are in all caps.

PARAM1=value1&PARAM2=value2&PARAM3=value3…etc.

So, you might be thinking to yourself “How do I know what to use for my variable names in my string?”  The good news is PayPal provides very good documentation on this.  We can see all of the possible variables that we can pass PayPal including customer details, order item details, and credit card information.  Some of this information is required in order to process a payment, but many of the variables available are optional.  For demonstration purposes, we’ll keep this pretty simple and just pass the required information.

We’ll store all of our request parameters in an array so that we can loop through this array to easily generate our NVP string.  All requests require the following parameters by default:

  • METHOD – The name of the API call you’re making.
  • USER – The API username
  • PWD – The API password
  • SIGNATURE – The API signature
  • VERSION – The API version

Then you can refer to the PayPal documentation for any API request you’d like to make to see what other parameters should be included.  For the sake of this demonstration, our array will be built as follows.

// Store request params in an array
$request_params = array
					(
					'METHOD' => 'DoDirectPayment', 
					'USER' => $api_username, 
					'PWD' => $api_password, 
					'SIGNATURE' => $api_signature, 
					'VERSION' => $api_version, 
					'PAYMENTACTION' => 'Sale', 					
					'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
					'CREDITCARDTYPE' => 'MasterCard', 
					'ACCT' => '5522340006063638', 						
					'EXPDATE' => '022013', 			
					'CVV2' => '456', 
					'FIRSTNAME' => 'Tester', 
					'LASTNAME' => 'Testerson', 
					'STREET' => '707 W. Bay Drive', 
					'CITY' => 'Largo', 
					'STATE' => 'FL', 					
					'COUNTRYCODE' => 'US', 
					'ZIP' => '33770', 
					'AMT' => '100.00', 
					'CURRENCYCODE' => 'USD', 
					'DESC' => 'Testing Payments Pro' 
					);

You’ll notice we’re using our config variables from config.php, and then I’m simply loading static data for the other values.  In a standard project, though, you’ll most likely be populating these values with form data, session data, or some other form of dynamic data.

Now we can simply loop through this array to generate our NVP string.

// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
	$nvp_string .= '&'.$var.'='.urlencode($val);	
}

The value of $nvp_string is now:

METHOD=DoDirectPayment&USER=sandbo*****e.com&PWD=12***74&SIGNATURE=AiKZ******6W18v&VERSION=85.0&PAYMENTACTION=Sale&IPADDRESS=72.135.111.9&CREDITCARDTYPE=MasterCard&ACCT=5522340006063638&EXPDATE=022013&CVV2=456&FIRSTNAME=Tester&LASTNAME=Testerson&STREET=707+W.+Bay+Drive&CITY=Largo&STATE=FL&COUNTRYCODE=US&ZIP=33770&AMT=100.00&CURRENCYCODE=USD&DESC=Testing+Payments+Pro

This string is what we’ll send to PayPal for our request.


Step 4: Send the HTTP Request to PayPal

Now that our NVP string is ready to go we need to send this to the PayPal server to be processed accordingly.  To do this, we’ll use PHP’s CURL methods.

// Send NVP string to PayPal and store response
$curl = curl_init();
		curl_setopt($curl, CURLOPT_VERBOSE, 1);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($curl, CURLOPT_TIMEOUT, 30);
		curl_setopt($curl, CURLOPT_URL, $api_endpoint);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);

$result = curl_exec($curl);		
curl_close($curl);

Here you can see that we’ve setup CURL with a few simple options and we’re using our $api_endpoint and $nvp_string variables accordingly.

This data will be sent over to PayPal and we will receive the API response back in our $result variable so that we can see the result and send the user to a successful or failure page based on whether or not the call succeeded or not.


Step 5: Parse the API Response

The value that we get back in $result from the previous step will be an NVP string just like the one we generated and sent to PayPal.  When we run our current script we get a successful response back that looks like this:

TIMESTAMP=2012%2d04%2d16T07%3a59%3a36Z&CORRELATIONID=9eb40cd84a7d3&ACK=Success&VERSION=85%2e0&BUILD=2764190&AMT=100%2e00&CURRENCYCODE=USD&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=160896645A8111040

One very simple way to parse this result is to use PHP’s parse_str() function.  This will load all of the response data into PHP variables matching the names and values returned in the response.  For example, if we do the following:

  // Parse the API response
  $nvp_response_array = parse_str($result);
  

We would end up with access to the following PHP variables:

  • $TIMESTAMP
  • $CORRELATIONID
  • $ACK
  • $VERSION
  • $BUILD
  • $AMT
  • $CURRENCYCODE
  • $AVSCODE
  • $CVV2MATCH
  • $TRANSACTIONID

We can then proceed to use these variables to present information back to our customer, populate values in email receipts we’d like to generate, update database information, or anything else we need to do once an order is completed.

The $ACK value is what will tell us whether or not the API call was successful or not.  Values for $ACK can be:

  • Success
  • SuccessWithWarning
  • Failure
  • FailureWithWarning
  •  

    You can simply redirect your user where they need to go and show them information based on this value.

    A failing API call will result in additional parameters that provide information about why the transaction failed.  If I run this test again with an invalid credit card number, for example, I get the following response back from PayPal:

    TIMESTAMP=2012%2d04%2d16T08%3a08%3a52Z&CORRELATIONID=590d41dbb31e0&ACK=Failure&VERSION=85%2e0&BUILD=2764190&L_ERRORCODE0=10527&L_SHORTMESSAGE0=Invalid%20Data&L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20Please%20enter%20a%20valid%20credit%20card%20number%20and%20type%2e&L_SEVERITYCODE0=Error&AMT=100%2e00&CURRENCYCODE=USD

    Now, when we use parse_str() we end up with the following PHP variables available to us:

    • $TIMESTAMP
    • $CORRELATIONID
    • $ACK
    • $VERSION
    • $BUILD
    • $L_ERRORCODE0
    • $L_SHORTMESSAGE0
    • $L_LONGMESSAGE0
    • $L_SEVERITYCODE0
    • $AMT
    • $CURRENCYCODE

    In this case, $ACK shows a Failure so we know the call did not succeed and we can check the error parameters for more details about what went wrong.

    Additional Data Parsing Option

    While the previous method of parsing the response works just fine, I personally prefer to work with data arrays.  As such, I use the following function to convert the PayPal response into an array.

    // Function to convert NTP string to an array
    function NVPToArray($NVPString)
    {
    	$proArray = array();
    	while(strlen($NVPString))
    	{
    		// name
    		$keypos= strpos($NVPString,'=');
    		$keyval = substr($NVPString,0,$keypos);
    		// value
    		$valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
    		$valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
    		// decoding the respose
    		$proArray[$keyval] = urldecode($valval);
    		$NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
    	}
    	return $proArray;
    }
    

    This allows me to see all of the response data available by simply looking at the contents of the array:

    If I run my script again now I get the following result on screen:

    Array
    (
        [TIMESTAMP] => 2012-04-16T08:15:41Z
        [CORRELATIONID] => 9a652cbabfdd9
        [ACK] => Success
        [VERSION] => 85.0
        [BUILD] => 2764190
        [AMT] => 100.00
        [CURRENCYCODE] => USD
        [AVSCODE] => X
        [CVV2MATCH] => M
        [TRANSACTIONID] => 6VR832690S591564M
    )
    

    And If I were to cause an error again I get the following:

    Array
    (
        [TIMESTAMP] => 2012-04-16T08:18:46Z
        [CORRELATIONID] => 2db182b912a9
        [ACK] => Failure
        [VERSION] => 85.0
        [BUILD] => 2764190
        [L_ERRORCODE0] => 10527
        [L_SHORTMESSAGE0] => Invalid Data
        [L_LONGMESSAGE0] => This transaction cannot be processed. Please enter a valid credit card number and type.
        [L_SEVERITYCODE0] => Error
        [AMT] => 100.00
        [CURRENCYCODE] => USD
    )
    

    You can see this is a nice, easy to navigate result array that contains everything we might need to move the user through our application and update data sources as necessary.


    Conclusion

    As you can see, processing credit cards using PayPal Payments Pro is actually a very simple procedure.  It just involves a few standard steps for working with API web services, and a basic knowledge of working with array data can help as well.

    Good luck, and happy coding!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Ivanhoe123

    Thanks for the tutorial. Stuff like this is necessary to better understand payment processing. It would be great to do the same for Authorize.net or some other leading payment types.

    Btw, are you really using Dreamweaver to code or it’s just because it has those fancy green folder icons? :)

    • http://www.angelleye.com Andrew Angell
      Author

      I could do one for Authorize.net, too. The process is actually very similar, but the request params are simply named differently. Also, they have separate requests for Card Present vs. Card Not Present merchant accounts. Definitely tutorial worthy. I’ll have to see if Nettuts wants to give me another shot!

      I actually do use Dreamweaver quite a bit, especially for simple stuff like this. It just works so nicely with the rest of the Adobe stuff that it’s tough for me to completely ditch.

      I use Eclipse any time I actually need to browse class libraries or work with more complex jobs.

    • Avi

      LOL! I Just Noticed That :D

  • jesperseunri

    What a wonderful and helpful article! Thank you very much :)

    • http://www.angelleye.com Andrew Angell
      Author

      Glad it helped! I’m hoping to add a lot more PayPal and general payment processing related tutorials in the future.

  • Nick

    Is there a downside to using http_build_query() instead of the foreach loop used to build the URL parameters?

    • http://www.angelleye.com Andrew Angell
      Author

      Ya know, I remember trying to use that a while back and I was running into some strange issues where PayPal was rejecting something about the way it got generated. I don’t remember exactly what it was. I just remember it was giving me fits and this way has always worked just fine, so that’s just what I’ve always stuck with.

    • http://codeangry.com/ CodeAngry

      http_build_query() works great with all things Paypal. But people avoid it like the plague. And the reason is simple and it’s the worst joke of them all: PHP 4 compatibility. Now, when PHP 5.4 is up, people still think and code in PHP 4 which is beyond sad. I write everything with 5.3+ compatibility only.

      So mister @Author, change the mindset. Think 5.3+ (Closures, LSB, Namespaces), 5.4+ (Traits, $this in Closures), OOP and pretty code indentation (formatting). You could have written a reusable class for this and allow users to extend it easily. That would have rocked… for them!

      CHECK THIS OUT:
      PayPal API DDP Implementation (https://gist.github.com/3025366)
      Wrote this right now, at anger :) Untested but should work.

      • http://www.angelleye.com Andrew Angell
        Author

        Hi Mister CodeAngry. I appreciate your feedback, but I have to inform you that you’re making incorrect assumptions.

        The problem I was having with http_build_query() wasn’t anything to do with PHP 4 compatibility. I still can’t pin-point what it was, but I know it wasn’t that. I didn’t spend much time on it because this way worked just fine. It’s probably something simple. I may go back to it sometime.

        As for an class library, I do have one, and it’s much more complete than the one you’ve linked to.

        http://www.angelleye.com/download-angell-eye-php-class-library-for-paypal/.

        I also have the same thing specific to CodeIgniter: http://www.angelleye.com/download-codeigniter-php-library-for-paypal-payments-pro/

        When I wrote this article I recommended to Nettuts that I use my library for this but I was told not to, and was instructed to treat it as a very simple, raw sample.

        So calm yourself, and don’t jump to so many conclusions. “It’s a mat, and it has these conclusions on it…and you jump to them!”

  • http://www.rahulparekh.in Rahul Parekh

    Stumbled onto this tutorial through envatos twitter and I’m glad I did. I always assumed working with PayPal API wasn’t really easy but this looks fairly simple. Very helpful.

    • http://www.angelleye.com Andrew Angell
      Author

      Yup, it’s actually pretty simple. Once you get the process down all web services are actually very similar.

      You might want to check out my complete PHP library that I provide for PayPal which includes Payments Pro and a whole lot more.

      http://www.angelleye.com/download-angell-eye-php-class-library-for-paypal/

      I also have a version of it specific to CodeIgniter as well as some training videos for how to use it on my site.

      • Preston

        Now if only the payment and shipping processors could come up with a way to make their own websites easy to use, things would improve.

        My biggest complaint by far with the lot of them is that they all use similar sounding names for all their services. It makes it confusing when dealing with clients. FedEx Express Saver, Super Saver Express, PayPal Pro Express, PayPal Pro Standard, PayPal Website Payments Pro….

        Seriously!!!

      • Furqan

        Hey Andrew! its really looks fine , awsome work bro!
        Before it i was actually pretty much confused, regarding paypal integeration, but it seems as simple from now. Thanks to tutsplus:)

        Can you please give the library to integrate it with codeigniter. Thanks

        Regards,
        Furqan Mahmood

      • http://www.rahulparekh.in/ Rahul Parekh

        Library looks promising. Will definitely look into it once I get started with payment related stuff. Right now it’s just being done manually which is a pain. Need to stop procrastinating I guess.

  • Tintale

    Wonderful post! I guess it would be trivially easy applying the same payment flow to other leading payment gateways. PayPal is so well documented.

  • http://www.creativemanner.com ozgur coruhlu

    Thanks, It seems easy enough.

  • http://javowalker.com Javier Gonzalez

    I think that you must have to do this at HTTPS conection on your server side, even if your request URL of Paypal are HTTPS, because some sniffer software can intercept your package.

    I dont be sure if you have an HTTP of your side and send a package to an HTTPS server, if your conection automatically convert HTTPS too?.

    Any idea?

    • http://www.angelleye.com Andrew Angell
      Author

      You’re going to want an SSL on your server to process credit cards in this manner. Probably should have mentioned that in the article somewhere. Sorry about that.

  • http://NoI'mnotL Eddy

    Can you do the same showing how to do this, with bitcoins
    Honestly that is more interesting, then boring paypal, paypal is old and expensive.
    Bitcoin is young and cheap. It would advice using bit-pay.com

  • Felix

    Some questions and remarks:
    - How do you handle PCI compliance?
    - Payments pro is only available in United States, Canada, and the United Kingdom.

    Thanks, for showing how easy payments could be in 2012 ;)

    Regards Felix

    • pierlo

      oh damn, us poor europeans..

    • http://www.angelleye.com Andrew Angell
      Author

      - You’ll need to make sure and utilize an SSL certificate on your server to process credit cards like this. Also, don’t ever store any card data on your server, even if you’re going to re-bill the same card in the future. For that you can use reference transactions, and I’m going to see if I can do an article on that, too.

      - Yes, Payments Pro is only available in the US, Canada, and UK right now. They’ll be opening it up more in the future. If you’re in another country you may want to look into PayPal Payments Advanced or Hosted Payments Pro.

  • pierlo

    what about using SSL on the website? is it necessary? i’m a noob when it comes to SSL but I was wondering if it’s a security risk to send the credit card data to Paypal from a non-SSL origin domain… can you explain?

    • http://www.angelleye.com Andrew Angell
      Author

      Using this method of processing credit cards, yes, you would need an SSL certificate installed on your server. Those are pretty easy to configure, though, and if you’re hosting with a decent provider they’ll probably do it for you.

      If you don’t want to mess with any of that you may want to consider PayPal Payments Advanced. With that service you POST data directly to PayPal and they handle the security of everything even though the user is still filling in the CC data on a page on your site.

      Gives you that more professional look without the PCI Compliance issues.

    • Alex F

      Pierlo,
      The transmission of the data from your web server to Paypal by cURL is encrypted; however, you will need an SSL certificate for your site to prevent eavesdropping when collecting the credit card data from your customer. Also, you should NEVER store your customer’s credit card data in a database. In addition to the risk of being hacked, it is actually a serious violation of the credit card issuer’s PCI standards, and can leave you liable for any breaches.
      A safer alternative for many websites is to implement a shopping cart (Paypal’s or custom) and refer the sale information (in a very similar format as shown above) to Paypal. The user is sent to paypal’s servers where they can then pay using their paypal account or credit card (they do NOT need to have a Paypal account) and are referred back to your site along with optional custom data in the query string. It is not perfect, and not nearly as seamless as the process shown above, but with this method, your server never touches the sensitive data.
      I hope that helps,
      Alex

      • michael

        it is actually forbidden by the most countries to store credit cards data, many payment processors uses alias, you are able to store alias for credit card payments, but for paypal, there is luckily no need to store such data ;)

      • pierlo

        thanks a lot for the precious info!

      • Furqan

        Really worthful information, Thanks Alex….
        I really want to solve some confusing things in my mind
        do you think its better to redirect to paylpal site and let them handle the security risk ?
        Or its no harm in integrating the API in our site ?… ??

        Actually one of my client has a requirement of Paypal payment modes in his site. What should i suggest him?

        Regards,
        Furqan Mahmood

  • http://frankbroersen.info Frank

    Why not use:

    parse_str($response,$result);

    To put it into an array?

    • http://www.angelleye.com Andrew Angell
      Author

      Simply didn’t think of it. Good tip!

    • Kevin

      That’s what I thought. It would be a lot easier than making a custom function.

  • Igor

    Thanks, It is was interesting.

  • Pomy

    To Andrew Angell,

    A demo will be great addition.

    • http://www.angelleye.com Andrew Angell
      Author

      Hi Pomy,

      I actually did a screencast and included it with this tutorial when I delivered it to Nettuts, however, for some reason they were claiming the video had bad audio and couldn’t be used.

      I wound up posting it on my own YouTube account, and you can see it here: http://youtu.be/sgnnqz4wuUs

  • Avi

    Very Good Article. It would be great to see the same article reflected on a different payment processor (Cybersource, Moneris etc..)

    • http://www.angelleye.com Andrew Angell
      Author

      I’m glad you liked this one. I’m planning on writing more. Just a matter of Nettuts giving me the go ahead. :)

  • http://rommelxcastro.com Rommel

    Dreamweaver lol

    • http://www.angelleye.com Andrew Angell
      Author

      Pretty much the only thing missing from Dreamweaver is a way to browse object oriented class libraries easily. For that I open up Eclipse and work from there, but Dreamweaver works so fluently with the other Adobe products it’s tough to drop entirely.

    • michael

      there is nothing wrong about dreamweaver, it is actually a quite good editor since a few versions ;)

      the “perfect” editor doesnt exist in my opinion, sometimes i use e, sometimes aptana and sometimes dreamweaver cs6 ;)

      • Furqan

        Same here Michael, while you are working with html conversion its more suitable, but for me aptana/eclipse is more comfortable when i am working with frameworks.

  • http://hyperhtml.net Bryce Carr

    I’d highly recommend Stripe over Paypal. There is so much less you need to do to make it work, and it just works. I’d happily write a Stripe Tutorial if interested!

    • http://www.angelleye.com Andrew Angell
      Author

      If you’re doing $3k/mo or more in sales each month you’ll pay a lower transaction fee with PayPal than you will with Stripe. That said, Stripe doesn’t have a monthly fee like PayPal does for Payments Pro, so depending on your situation you may or may not be able to save money.

      As for the integration, though, it’s almost the same thing. You generate a basic request and POST it via CURL. I wouldn’t say it’s any easier or harder than PayPal’s API’s.

      • John Marston

        You mention it but the monthly fees for things like recurring billing and even just basic setup for Payments Pro **greatly** outweigh the benefits of a slightly (0.5%) transaction rate compared to Stripe.

  • Synoptase

    For all the european readers out there, this paypal product is only available to US & UK customers. If you want something similar, you have to use other merchants than paypal.

    Yes, this sucks.

    • http://www.angelleye.com Andrew Angell
      Author

      You might want to look into PayPal Payments Advanced or Hosted Payments Pro. I’ll see if I can do an article on those in the future.

  • http://ilopezdeaudikana.com mutiu

    I’m getting this error….

    “The merchant country is not supported.”

    Wich are the countries where PayPal Payments Pro is available?

    thank you

    • http://www.angelleye.com Andrew Angell
      Author

      Right now Payments Pro is only available in the US, UK, and Canada. You might want to look into PayPal Payments Advanced or Hosted Payments Pro.

      I’m going to see about doing future articles on those.

  • http://bestorders.de Alex Weissenfels

    Hello,
    Is there or could you also make a tutorial about the express checkout ? :) I would appreciate it very much ;)

    best regards

    • http://www.angelleye.com Andrew Angell
      Author

      I’d love to. Just waiting on responses back from the guys at Nettuts to get the next one started. I’ve got all sorts of good PayPal info I can share. :)

  • colm

    thank god someone’s finally done a tutorial on integrating paypal! Been looking everywhere for something like this. Thanks!

    • http://www.angelleye.com Andrew Angell
      Author

      Glad you like it! Keep your eye out. I hope to be adding a lot more PayPal content here in the future.

  • http://www.snilesh.com Nilesh

    Thanks for this excellent post …

    • http://www.angelleye.com Andrew Angell
      Author

      Glad you liked it!

  • http://categorycode.ca Landon Poburan

    Paypal is great. It is such a great solution, so easy to setup both to process and payment integration. Also so many services are setup to integrate with it already like WordPress plugins which really helps streamline our development.

  • http://webduos.com webduos

    this is an Excellent Article. Thanks for this. Its very Usefull for me

  • http://thietkenoithat247.com thiet ke noi that

    a great artice, thanks you very much!

  • http://www.devsign.co.za Devsign Web Design and Web Development

    Exactly what I was looking for, thanks mate!

    • http://www.angelleye.com Andrew Angell
      Author

      Glad I could help! I hope to post more stuff here soon. Just a matter of getting it scheduled with Nettuts.

  • Bazingaa

    Ideally a user must have at least 3-4 cards and pay on time to get full benefit of credit cards. The more the time you get to pay, money saved is the money earned. There is an app which tells you exactly which of your credit card to use, this is very beneficial i have been using it for some time and is great -
    http://goo.gl/yKUQu

  • http://devtechnosys.com suraj

    what it does ?

    curl_setopt($curl, CURLOPT_VERBOSE, 1);

    • http://www.angelleye.com Andrew Angell
      Author

      TRUE to output verbose information. Writes output to STDERR, or the file specified using CURLOPT_STDERR.

  • Killarena

    Really great tutorial :-) !

    I absolutely needed something like this today. Thanks again !

    • http://www.angelleye.com Andrew Angell
      Author

      No problem, glad it helped. I’d love to write more, but unfortunately I’m being told by Nettuts they don’t have any room for me. I guess they’re not too impressed with what I have to offer.

  • Orbitals

    I must be missing something here. What do you use as the API Signature for Sandbox? I can’t see any place to generate one?

    Anyway the tutorial looks good. Just need to get past the first hurdle…

    • http://www.angelleye.com Andrew Angell
      Author

      You can generate your API signature within your PayPal profile under the “Request API Credentials” section. You’ll want to choose PayPal API and then choose Signature.

  • Lanz Ruiz

    Hello, what about the quantity? because i really try many codes with quantity but i dont what was the correct code for it. please help :(

  • Ciwan

    Can we have a similar post but in ASP.net MVC please ?

    • http://www.angelleye.com Andrew Angell
      Author

      I’d love to do something like that but Nettuts is telling me they don’t have any more room for my stuff, which is a shame because I can offer all sorts of PayPal information. If you want more let them know and maybe they’ll change their mind.

  • aezaz

    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

    • http://www.angelleye.com Andrew Angell
      Author

      They did release a new version of Payments Pro, 3.0, that works on the PayFlow Gateway, however, DoDirectPayment is still very much alive and well. In fact, if you’re sending requests to the PayFlow gateway and PayPal is still your merchant, it rewrites the request and sends it to DoDirectPayment.

      Unfortunately, many of the basic PayPal reps aren’t fully aware of what’s going on with their own system. Just make sure you have Payments Pro active on your account and the instructions in this guide will be just fine.

  • http://codeangry.com Claude “CodeAngry” Adrian

    OOP extendable alternative:
    PayPal API DDP Implementation

    Wrote this right now, at anger :) Untested but should work.

    • http://www.angelleye.com Andrew Angell
      Author

      Again, I have a much more complete library available: http://www.angelleye.com/download-angell-eye-php-class-library-for-paypal/

      I’m an official PayPal Partner with this library. It’s been used by hundreds of developers and has been tested thoroughly. I can’t promise there are zero bugs, but if you find something let me know and I’ll get it fixed right away.

      I was told not to write this article in that fashion, but to keep it raw and simple.

  • Douglas

    Very useful and pretty easy stuff for a comparatively complex problem! Thanks a lot for sharing Andrew.

    • http://www.angelleye.com Andrew Angell
      Author

      Glad you got some use out of it. I’ll be providing a lot more material on my own site in the near future. Nettuts is telling me they’re booked and can’t take any more of my stuff.

      Contact me directly if you ever have any other PayPal API questions like Express Checkout, Adaptive Payments, IPN, etc.

      • vikas

        Hi

        can you share code of adaptive payment using credit card by curl or fopen. i don’t want to login at paypal.com . my email id is watermark0913@gmail.com

  • hemisha

    TIMESTAMP=2012%2d07%2d14T06%3a02%3a21Z&CORRELATIONID=df4407d85df3c&ACK=Failure&L_ERRORCODE0=10001&L_SHORTMESSAGE0=Internal%20Error&L_LONGMESSAGE0=Timeout%20processing%20request

    Array
    (
    [TIMESTAMP] => 2012-07-14T06:02:21Z
    [CORRELATIONID] => df4407d85df3c
    [ACK] => Failure
    [L_ERRORCODE0] => 10001
    [L_SHORTMESSAGE0] => Internal Error
    [L_LONGMESSAGE0] => Timeout processing request
    )

    me getting responce like this. so what is the solution foe that ?? is there any solution.. if yes then let me know as soon as possible..

    • http://www.angelleye.com Andrew Angell
      Author

      That error typically means exactly what it says…the servers timed out. This happens extremely rarely on the production servers. I’m assuming you’re working on the sandbox as it does happen there from time to time.

      Contact me directly if you’re still having issues with it and I can help you try to figure out what the issue is.

      • Roshan

        Hi Andrew ,I am developing a hotel booking site..I think to integrate credit card payments through paypal,but I have no experience with paypal development with php..Is your example enough for me to understand and develop my payment solution…I am very thankful if you can reply me..Thanks in advancve

  • http://127.0.0.1 Developers Developers Developers Developers

    PHP Has inbuild functions to build a query string from an array:
    http_build_query($request_params);
    And to parse it back into array:
    parse_str($result, $ARRAY);
    Note, just use the same parse_str function, but specify as the second param the output array.

  • http://www.andykuiper.com Andy Kuiper

    Andrew, are you available for custom work for projects like this? …at a sorta kinda reasonable costs ;-)
    Thanks for the tutorial :-)

    • http://twitter.com/geoff_selby Geoff Selby

      Andy, I don’t know if you are still in need of assistance, but I am currently available for projects like this. (any web development projects, really) You are free to contact me anytime if you are in need of work. geoff@boldcreativesolutions.com

    • Andrew Angell
      Author

      Hi Andy. Sorry, I wasn’t getting my notifications from this so I never realized I was missing comments. I’m always happy to provide a bid on projects if you want to contact me directly about that.

  • http://www.randomwalktrading.com/main lucille

    Hello,

    Do you also have Tutorial Details on How to Process Credit Cards with PayPal Payments Pro Recurring Payments with Direct Payment Using PHP?

    Hoping you can help.

    Thanks and more power!

    Lucille

  • Alejandro

    hello, will have an example for a mobile website? thanks

    • Andrew Angell
      Author

      The process in this article would work for a mobile site, too. You would just build some mobile UI for your app and then this PHP script would be used as a back-end web service that your UI would connect to for the processing.

  • Jame

    This was working for me, but seems to have stopped. All i’m getting now is an empty array, has something changed at PayPal’s end recently?

    • Ed

      having the same experience here – anyone aware of a change that needs to be addressed?

      • amanda

        Any word?

      • Andrew Angell
        Author

        Did you get this resolved or are you still having trouble?

      • Andrew Angell
        Author

        Sorry I never saw this before. Did you get it resolved?

    • David

      This works for me, but only with real information in the sandbox. I haven’t tested it live.

      The “test” data I have results in an empty response.

      • amanda

        Any Answer?

      • Andrew Angell
        Author

        Sounds like something could be wrong with your config setting for $sandbox. The sandbox wouldn’t accept “real” information, so if it’s only working that way you must be hitting the “real” server, too, which means your sandbox config in the class isn’t accurate.

    • amanda

      Any news on this? Did you get an answer to your question?

      • Anouar Abdessalam

        Hi Amanda,
        Try “REST API” it’s simple to use . now you can process credit card easly with this API.

      • Andrew Angell
        Author

        While the REST API is great, but it’s not quite as mature as the “classic API” and as such, it’s not quite as open and limitless. They’ll get there with it, but for now I still personally prefer the classic API.

    • Andrew Angell
      Author

      Sorry, for some reason I don’t get my notifications from Nettuts when people comment on my article. I checked the setting and it’s on, but I still don’t get them.

      Anyway, nothing changed with PayPal’s API servers, so I’m not sure why you’d be experiencing that issue other than CURL not being enabled on your server, or maybe some setting changed with it..??

  • petar

    Thanks very much for this tutorial!
    It is amazing!
    But please, can u tell me what and how my client have to do for transfering money to his account over his website?
    I will implement api but I need to tell him how to register for receiving money?
    Pls can u help me?

    • Andrew Angell
      Author

      I’m not sure I understand your question, but anybody using PayPal would just need to sign up for the account, then add your bank account and verify it, and optionally add a credit card and confirm it. This would give you a PayPal account all setup and ready to go for buying, accepting payments, and transferring money to your own bank account.

  • mohsin

    With this API how to recurring payment

    Please Help

    Thanks,
    in Advance

  • minakshi

    using this code we are able to sends all the credit card details as well as the billing details to merchant account. if yes then please let us know how to do that?
    thank you

  • John Smart

    Thank you so much. I have been working for three days with code and docs from paypal, all to no avail. This is clean, simple, and doers what it says it will. I am indebted to you. Thank you for taking the time to share your hard work, it is so appreciated.

    • Andrew Angell
      Author

      I’m glad it worked out well for you!

  • ubed

    HI dude

    please help me to solve below error.
    Array
    (
    [TIMESTAMP] => 2013-04-04T11:43:07Z
    [CORRELATIONID] => 442377b87af23
    [ACK] => Failure
    [VERSION] => 85.0
    [BUILD] => 5479129
    [L_ERRORCODE0] => 10501
    [L_SHORTMESSAGE0] => Invalid Configuration
    [L_LONGMESSAGE0] => This transaction cannot be processed due to an invalid merchant configuration.
    [L_SEVERITYCODE0] => Error
    [AMT] => 100.00
    [CURRENCYCODE] => USD
    )

    • Andrew Angell
      Author

      That means that Payments Pro (DoDirectPayment) either isn’t approved on your account or you haven’t accepted the billing agreement that comes with it.

  • Matteo

    Good Morning thanks for this intersting post.
    I’d want to know how to change this step to execute a payment with paypal account.

    • Andrew Angell
      Author

      For that you would use the Adaptive Payments API, specifically the Pay API, instead of what this article covers. The process would be the same, but your request would be different. You can see all those details at http://developer.paypal.com under the classic API section.