Help Article

Ask the Community

Find answers or join the conversation in the Community Help Forum.

How do I set up and process an API call using the Payflow .NET SDK?

This tutorial shows you how to set up and process an API call using the Payflow .NET SDK. When finished, you'll be able to communicate with the server and see a response on the page.
 
Disclaimer: This code isn't intended to be used in a production environment; it's just an example and should be used as such. The code is supplied "as is" with no warranty, and should be used only for reference.

 


Download the Payflow .NET SDK

  1. Log in to the PayPal Developer Portal and download the Payflow .NET SDK.
  2. Extract the files from the .zip file, and install the SDK.
  3. Once the SDK is installed, rename the file from payflow_dotNET_2.0.dll to payflow_dotNET.dll.

Create a new project in Visual Studio

  1. Open Visual Studio.
  2. Select File > New Project.

Create a new application

  1. For this example, create a C#, ASP.NET Web Application called "MyFirstAPICall" as shown here:
  2. Click OK, and you'll see your first page, Default.aspx.

Reference the Payflow_dotNET.dll file

  1. Right-click References under Solution Explorer, then select Add Reference.
  2. On the Browse tab, go to the Payflow_dotNET.dll file, then click OK.

Add a new button to the page

  1. Go back to the Default.aspx page.
  2. Click Design.
  3. Drag a Button from the tool box onto the page.

View the button code and add using statements

  1. Double-click the new button.
  2. By default you'll see the following code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace MyFirstAPICall{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
}
}
}
  1. Add the following statements to the "using" section to include the PayPal SDK DLL for the file:
using PayPal.Payments.Common.Utility;
using PayPal.Payments.Communication;
using PayPal.Payments.DataObjects;

Add code for the Button1_Click function

This step uses the actual code of the application.
  1. The following is sample code for the Button1_Click function:
       
    //Set your API Credentials	
    /////////////////////////////////////////////
    //PLEASE NOTE THIS IS NOT CONSIDERED SECURE//
    //THIS IS FOR EXAMPLE PURPOSES ONLY//////////
    /////////////////////////////////////////////
    string USER = "xxxx";
    string VENDOR = "xxxx";
    string PARTNER = "PayPal";
    string PWD = "xxxxx";
    //set the port
    int hostPort = 443;
    //set the timeout
    int timeOut = 30;
    //set the host address (pilot-) for testing
    string hostAddress = "pilot-payflowpro.paypal.com";
    //build a test request string
    string Request = "USER=" + USER + "&PWD=" + PWD + "&VENDOR=" + VENDOR + "&PARTNER=" + PARTNER
    + "&TRXTYPE=S&TENDER=C&ACCT=4111111111111111&EXPDATE=1213&CVV2=123&AMT=99.00&FIRSTNAME=John&LASTNAME=Smith&STREET=123
    Main St.&CITY=San Jose&STATE=CA&ZIP=12345&COMMENT1=Reservation&VERBOSITY=MEDIUM";
    //build a Payflow API Object with the address, port, and timeout
    PayflowNETAPI pfObj = new PayflowNETAPI(hostAddress, hostPort, timeOut);
    //set the response variable to the value of the response from the call and make the call
    string response = pfObj.SubmitTransaction(Request + PayflowUtility.RequestId, PayflowUtility.RequestId);
    //get the status from the response
    string status = PayflowUtility.GetStatus(response);
    //print the status to the page
    Response.Write(status);
    Response.Write("<br />");//line break
    //API Request:
    Response.Write("API Request:\n");
    Response.Write("<br />");//line break
    //print the raw request string to the page
    Response.Write(Request);
    Response.Write("<br />");//line break
    //API Response:
    Response.Write("\nAPI Response:\n");
    Response.Write("<br />");//line break
    //print the raw API response String to the page
    Response.Write(response);
  2. Set the USER, VENDOR, PARTNER, and PWD variables to your API credentials for the Payflow API.
  3. Set the preceding code between the curly braces for the Button1_Click function.

 


Build and run the application

  1. Under Build, select Build MyFirstAPICall.
  2. Click the green arrow to run the application.
  3. Your browser will open and you'll see the button, which will be labeled Button (unless you changed it).
  4. Click the button to show your API Request and Response. For example, the following message indicates a successful transaction:
     
Note: Read through the SDK documentation so you can use it to its full potential. You may also want to review the Payflow Gateway Developer Guide and Reference for more information.
We’re sorry, the page you’re looking for is no longer available. Please try your search again in our Help Centre if you have a question or want to contact us.