As said in the introduction, most developers, even if they have no
previous experience with PayPal, start directly with the API. Google
search brings up either API Reference or the SDKs and Downloads page and then browsing through Documentation
starts. I don't want to say that there is something wrong with using
PayPal API for payments; I want to say that in most of the cases, it's
not necessary to go down that path.
PayPal API is much more than just a mechanism for payment - if you look at the provided API Reference page, you'll see that there are lots of methods not tied directly to "user performing payment". You can use the API to browse through the history of your transactions, issue a refund, or update a recurring payments profile. So how do you start using it?
First and foremost, you'll need to enable API access in your account; follow these steps:
Now that you have credentials to make API calls, how do you perform them? The approach that will work equally well with all platforms is to download the SDK, target the appropriate API endpoint, and start making HTTP calls with either Name-Value pairs or SOAP.
However, for .NET developers, I recommend a different approach. Considering that Visual Studio has an awesome WSDL parser, I urge you to just add a Web Service Reference to https://www.paypal.com/wsdl/PayPalSvc.wsdl. After a few moments, you'll have an up-to-date class ready to serve you with all the benefits of strong typing - no building of HTTP requests, no copy-pasting field names, and no cumbersome parsing of responses. You have the same thing available for Sandbox at: https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl.
To be able to call methods that are part of Direct Payment (
Lastly, once you start dealing with credit cards, you'll need to take care of PCI Compliance; here is a nice forum thread that provides more information on that.
If you get stuck on anything, I suggest that you first visit the PayPal Developer Community and ask your question in the appropriate forum. A number of great, knowledable developers monitor those forums, and it's highly probable that you'll receive an answer to almost any PayPal issue within an hour. I also have an account on that site (lepipele) and try to answer questions whenever I have time; so feel free to send me a private message if you drop by or run into trouble.
PayPal API is much more than just a mechanism for payment - if you look at the provided API Reference page, you'll see that there are lots of methods not tied directly to "user performing payment". You can use the API to browse through the history of your transactions, issue a refund, or update a recurring payments profile. So how do you start using it?
First and foremost, you'll need to enable API access in your account; follow these steps:
- Log in to your Premier or Business account
- Click the Profile sub tab
- Click the API Access link under the Account Information header
- Click the link that says Request API Credentials / View API Certificate
- Select either API Signature or API Certificate
Step 5 from activating API Access
I recommend that you select API Signature, and the examples that
follow will assume you made this choice. There is nothing wrong with
selecting API Certificate; I just find it more demanding from a setup
perspective.Now that you have credentials to make API calls, how do you perform them? The approach that will work equally well with all platforms is to download the SDK, target the appropriate API endpoint, and start making HTTP calls with either Name-Value pairs or SOAP.
However, for .NET developers, I recommend a different approach. Considering that Visual Studio has an awesome WSDL parser, I urge you to just add a Web Service Reference to https://www.paypal.com/wsdl/PayPalSvc.wsdl. After a few moments, you'll have an up-to-date class ready to serve you with all the benefits of strong typing - no building of HTTP requests, no copy-pasting field names, and no cumbersome parsing of responses. You have the same thing available for Sandbox at: https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl.
Express Checkout
Express Checkout is the most flexible PayPal integration solution. The user is redirected to PayPal just for authentication and confirmation that he wants to pay for your services, and after that, everything is done on your website; you'll make calls to the PayPal API in the background. The following picture describes the process (taken from this page):
Express Checkout flow
- You'll add a PayPal Checkout button that invokes the
SetExpressCheckout
method of the PayPal API after it is clicked. - If you are invoking this method for one time payment, it'll be valid if you include only the required fields. Setting the
NOSHIPPING
variable to 1 is important if you are selling some online service (it'll help you skip the Shipping info page). - If you are invoking this method in order to set recurring payments, be sure to set
L_BILLINGTYPE0
toRecurringPayments
andL_BILLINGAGREEMENTDESCRIPTION0
to a valid description of your service. SetExpressCheckout
will return a 20 char token that will uniquely identify your transaction. This token is valid for 3 hours. After you receive it, redirect the user to https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=[TOKEN] (you can guess what the URL for Sandbox is, right?).- The user will review payment information, and if everything is OK,
enter the login credentials. After this, PayPal will redirect him to the
URL you specified with
RETURNURL
when you calledSetExpressCheckout
. - When your
RETURNURL
is hit, you need to invoke theGetExpressCheckoutDetails
method and see the details of the actual transaction; verify that everything is in order. - Now, all that is left is to commit the transaction. Depending on what you did in step 1, there are two things that can be done.
- For one time payments, you'll just invoke
DoExpressCheckoutPayment
and forward the appropriate variables. - For recurring payments, you'll invoke the
CreateRecurringPayments
method. It is required that you include the DESC field and match it to the value entered in L_BILLINGAGREEMENTDESCRIPTION0 when you calledSetExpressCheckout
.
Direct Payment (Website Payments Pro)
Most developers aren't aware that the PayPal platform can be used for just Credit Card processing. This part of the PayPal API is called Direct Payment, and when combined with Express Checkout (which only services customers with PayPal accounts), you get what is referred to as Website Payments Pro on the PayPal Developer Center.To be able to call methods that are part of Direct Payment (
DoDirectPayment
and CreateRecurringPayments
), you first need to satisfy some conditions:- Have a Business account that is based in US, UK, or Canada
- Oblige that you'll implement both Express Checkout and Direct Payment on your website
- Submit application for Website Payments Pro through your PayPal account and have it approved
- Pay monthly fee (currently $30 per month)
Lastly, once you start dealing with credit cards, you'll need to take care of PCI Compliance; here is a nice forum thread that provides more information on that.
Conclusion
My hope is that this article gave you good overview of PayPal integration options. If it did that, I'll be at peace - as once you have an understanding of the concepts laid out in this article, you'll easily fetch the needed details from the provided links. Sure, there are some topics we haven't touched, like Encrypted Website Payments, PayPal API Certificates, or Payflow Gateway, but I think you can tackle even that on your own once you fully understand all things written here.If you get stuck on anything, I suggest that you first visit the PayPal Developer Community and ask your question in the appropriate forum. A number of great, knowledable developers monitor those forums, and it's highly probable that you'll receive an answer to almost any PayPal issue within an hour. I also have an account on that site (lepipele) and try to answer questions whenever I have time; so feel free to send me a private message if you drop by or run into trouble.
No comments:
Post a Comment