Introduction

To do an online credit card transaction in ASP.NET using PayPal Payflow Pro, you’ll need to set up a Payflow Pro online payment gateway account at PayPal.com, download and install .NET SKD for Payflow Pro, and create an ASP.NET application that sends a transaction request to and receives a transaction response from Payflow Pro.

Payflow Pro Online Payment Gateway Account

At the time of writing this article, the account creation link is: https://registration.paypal.com/welcomePage.do?producttype=C2&country=US&mode=try. PayPal documentation indicates that a testing account can be created, which can then be activated as a production account if needed. Upon the completion of an account setup, you’ll have four user parameters as login credentials to access the account, as shown in the table below.

Using these credentials, you are able to log into https://manager.paypal.com to manage your account settings, to view/manage transactions, and to generate reports, etc. These same user parameters are also required for online transaction in your ASP.NET application.

Download and install the package to your local development machine. By default, it is installed at C:\Program Files\Payflow SDK for .NET\. Browse to the folder, you’ll see two DLLs: Payflow_dotNET_1.1.dll and Payflow_dotNET_2.0.dll which are, as their names imply, for .NET Framework 1.1 and 2.0 respectively. Choose the version you need and RENAME it to Payfow_dotNET.dll before adding a reference to your web application in Visual Studio. As you can see, the SDK has not been updated to the current .NET Framework 4. However, it works fine in the application coded in .NET Framework 4 using Visual Studio 2010.

How Online Transaction Works

Utilizing .NET SDK for Payflow Pro classes, your application sends a transaction request to a Payflow Pro host, where Payflow Pro server processes the request and then sends back a transaction response to your application to notify you of the transaction status. In the request and response cycle, a credit card transaction is accomplished and funds are moved in or out of your bank account that is linked to your Payflow Pro payment gateway account.

Host Name

The host name is a URL for the Payflow Pro server. Payflow Pro provides one for testing and another for production.

For testing : pilot-payflowpro.paypal.com

For production: payflowpro.paypal.com

Please note that both testing transaction and production transaction go through the same Payflow Pro account. When you log into https://manager.paypal.com, you are able to search, view and manage both.

Transaction Request

A transaction request consists of a string of name value pairs concatenated with a “&”, which contains all payment information needed in a transaction, such as transaction type, payment method, credit card information, user parameters (credentials) for Payflow Pro account, etc. Some are required, and some optional. Here is an example of a transaction request string:

In which, TRXTYPE=S indicates it is a sale transaction type and TENDER=C shows that a credit card is used as the method of payment. The tables below lists common parameters and their descriptions used in a transaction request.

If a parameter is marked as required, it has to be included in a transaction request to get accepted by Payflow Pro server.

Transaction Response

Similarly, a transaction response that your application receives from Payflow Pro is also a string of name value pairs. It provides transaction results including status, transaction number, authorization code, or errors. The string shown below is an example.

RESULT=0 means that the transaction is approved. Any value that is greater than 0 indicates a decline or an error. RESPMSG (response message) gives a brief description for an approved transaction, a declined transaction, or an error corresponding to a result code. The table below displays typical parameters in a Payflow Pro response.

ASP.NET Application

Now let’s take a look at how we can implement the transaction process discussed above in an ASP.NET application using .NET SDK for Payflow Pro. A demo application has been prepared for download. It is coded in Visual Studio 2010, .NET Framework 4 using Payflow_dotNET.dll for Framework 2.0.

The application has only one ASP.NET page that collects payment amount and credit card information, constructs a transaction request string, sends the request to and receives a transaction response from Payflow Pro, and then displays the data on the page.

The above screen shot illustrates the web interface for collecting the required data. Upon clicking the Submit button, the transaction request string is constructed and sent to Payflow Pro host, and a response string is then received from the host. The screen shot below displays the name values pairs of the request and the response respectively.

When you run this application, you may not see a successful transaction but a failed status. This is because invalid user parameters (USER, VENDOR, PARTNER and PWD) are used in the transaction request. You’ll need to update the user parameters stored in the <appSettings> section of the web.config with valid values associated with your Payflow Pro account.

In the application, the Payflow_dotNET_2.0.dll that came with the .NET SDK for Payflow Pro installation was renamed to Payflow_dotNET.dll and then added to the Visual Studio project as a reference.

First of all, a string of name value pairs is concatenated and assigned to the variable PayPalRequest. This string includes transaction type (TRXTYPE=S: sale), payment method (TENDER=C: credit card), credit card number, expiration date, amount to charge, user parameters (credentials) for Payflow Pro account, etc. More may be added as needed.

Secondly, an instance of PayflowNETAPI is created so that its properties and methods are exposed to our application.

Thirdly, the method PayflowNETAPI.SubmitTransaction() is called to perform the transaction. This method requires two parameters, a transaction request string built earlier and a RequestId that is an unique ID generated by PayflowUtility object. The return type of the method is a string (stored in the variable PayPalResponse), which is the response from Payflow Pro, consisting of name value pair for transaction results. That is all for a transaction cycle. The rest of the code displays the transaction data on the page, which can be handled differently depending on the requirements in a real world business application.

You may have noticed that in the code sample, Payflow Pro host name is not used anywhere. This is because the host name is placed in the <appSettings> section of web.config file. The SDK knows where to retrieve it directly during a method call. The listing below shows the standard settings provided by the SDK. Some are related to tracing and logging tasks that the SDK also does. These are not turned on in the demo.

<appSettings><!-- Payflow Pro Host Name. This is the host name for the PayPal Payment Gateway.
For testing: pilot-payflowpro.paypal.com.
For production: payflowpro.paypal.com
--><addkey="PAYFLOW_HOST"value="pilot-payflowpro.paypal.com"/><!-- TRACE value when set to ON will show the
complete exception stack trace in the response message, if any.
Change TRACE value to "ON" to switch on the stack trace in response message.--><addkey="TRACE"value="OFF"/><!-- This is a LOG level tag.To switch on logging change the
logger level from "OFF" to any of the following:
a. DEBUG
b. INFO
c. WARN
d. ERROR
e. FATAL
--><addkey="LOG_LEVEL"value="OFF"/><!-- Relative path for LOG file. --><addkey="LOG_FILE"value="logs\PayflowSDK.log"/><!-- Log file filesize constant. --><addkey="LOGFILE_SIZE"value="102300"/></appSettings>

Summary

This article takes a sale credit card transaction as an example to demonstrate how to use .NET SDK for Payflow Pro in ASP.NET. There are other types of transaction, such as Authorization, Void, Delayed Capture, etc. that can all be done using the SDK. No matter what transaction type is involved, in general, it is a similar process of sending a transaction request to a Payflow Pro host and receiving a transaction response from the host, as illustrated in our demo application.

Thanks for this wonderful article. I have a query on this. please ignore if this is silly.

I just wanted to know that if I give a valid Credit Card Number, Pin and other details and enter an amount Rs.100/-, will Rs.100 be reduced from my account. or does this program and sample code just displays the status of whether the account information is valid?. Is there anyway that I could test.

My second question to clarify is that the changes done in Web-config File would the account details to which the amount has to be credited. Am I correct. Please correct me if I went wrong. I mean the USER, VENDOR, PARTNER, PWD.

I just wanted to know that if I give a valid Credit Card Number, Pin and other details and enter an amount Rs.100/-, will Rs.100 be reduced from my account. or does this program and sample code just displays the status of whether the account information is valid?. Is there anyway that I could test.

If the PayfowPro testing URL is used, your card will NOT be charged (not reduced from you credit card) but you will still see the transaction record of the same amount at https://manager.paypal.com/[^]

vk0489 wrote:

My second question to clarify is that the changes done in Web-config File would the account details to which the amount has to be credited. Am I correct. Please correct me if I went wrong. I mean the USER, VENDOR, PARTNER, PWD.

After you sign up for a PayflowPro account, you'll have your own USER, VENDOR, PARTNER and PWD information for the account. When you use these values in the web.config, all transactions will go through your PayflowPro account. PayflowPro is a payment service. The money goes to your bank account that is linked to the PayflowPro account.

I need to create an Authorized transaction but instead of using the credit card number I need to use the OrigID which was generated from a previous payment? Do you know if this is this possible?

So something kind of like this reference transaction but it would create an authorized trn instead
BaseTender Tender = new BaseTender("C",null);
ReferenceTransaction Trans = new ReferenceTransaction("S", _orig_id,user_info, payflow_connection, invoice, Tender, PayflowUtility.RequestId);

This would be a good question to ask at paypal.com. Unfortunately, I do not know the answer. It really comes down to the question if the processing server url is different for international transaction or not.

I think it is doable but I have not tried. One thing to keep in mind is that SharePoint requires "digitally signed" DLLs. Not sure if the Payflow Pro DLL meets that requirements. If not, you'll need to alter settings in web.config to allow the unassigned DLLs. Thanks,

I do not know if PayPal.com handles Indian credit cards or not. This would be a good question to post at the PayPal forum. The message "Under review by Fraud Service" indicated that the transaction reached PayPal service but not approved.

Try your credentials manually at manager.paypal.com [^]to see if they are correct. These four pieces of information are set when you create a Payflow Pro account. I do not know if any other types of PayPal account would work or not. Thanks,

Hi,
Nice post. I have a problem would you please help me
i am getting following error
errorcode= 26
Invalid vendor account
I am already have a sandbox account and i m unable to process any transaction
Please help

Paypal is saying that manager.paypal.com will not work from India. So is that the reason why i am getting this "Invalid Vendor Account" error. I have credentials for "Paypal.com" but not for "manager.paypal.com".

If your PayPal account only consists of user name and password, it will not work. You'll need a PayFlow Pro account which consists of four pieces of information (see the table near the top of the article). I do not have any knowledge for accessing manager.paypal.com from India. I assume that there should exist an equivalent site. Thanks,

The API should work the same way in a Windows app as in a web. Some parameters may be placed in the app.config instead of web.config. Alternatively, the host information can be passed into PayflowNETAPI object during declaration: PayflowNETAPI PFAPI=new PayflowNETAPI(hostname here). Thanks,

It is working in windows. Thank you so much. But i am getting error always even though i provide correct details of credit card and also Paypal username,pwd,VEndor and Partner. I am getting error "RESULT=26&RESPMSG=Invalid vendor account".