I have an error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
com.paypal.sdk.services.CallerServices.set_APIProfile(IAPIProfile value) +49
ASPDotNetSamples.PayPalAPI..ctor() +98
ASPDotNetSamples.wppro.DirectPaymentAuthorization.PayButton_Click(Object sender, EventArgs e) +62
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
<%@ Page language="c#" Codebehind="DirectPaymentAuthorization.aspx.cs" AutoEventWireup="false" Inherits="ASPDotNetSamples.wppro.DirectPaymentAuthorization" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<%----%>
<style type="text/css">
.style1 {
width: 47px;
}
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h1>Direct Payment</h1>
NOTE: The only currency supported by the Direct Payment API at this time is US
dollars (USD).<br />
<br />
<strong>Payment</strong>
<table>
<tr>
<td>Amount:
</td>
<td>
<asp:TextBox Runat="server" ID="PaymentAmountTextBox">1.00</asp:TextBox>
</td>
<td>USD</td>
</tr>
</table>
<br />
<strong>Buyer Name</strong>
<table>
<tbody>
<tr>
<td>First Name:
</td>
<td>
<asp:TextBox Runat="server" ID="BuyerFirstNameTextBox">John</asp:TextBox>
</td>
<td><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>Last Name:
</td>
<td>
<asp:TextBox Runat="server" ID="BuyerLastNameTextBox">Doe</asp:TextBox>
</td>
<td><font size="-1" color="red">Required</font></td>
</tr>
</tbody>
</table>
<br />
<strong>Address</strong>
<table>
<tr>
<td>Address1:
</td>
<td>
<asp:TextBox Runat="server" ID="BuyerAddress1TextBox">123 Fake St</asp:TextBox>
</td>
<td><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>Address2:
</td>
<td><asp:TextBox Runat="server" ID="BuyerAddress2TextBox"></asp:TextBox></td>
</tr>
<tr>
<td>City:
</td>
<td><asp:TextBox Runat="server" ID="BuyerCityTextBox">Omaha</asp:TextBox></td>
<td><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>State:
</td>
<td><asp:TextBox Runat="server" ID="BuyerStateTextBox">NE</asp:TextBox>
</td>
<td><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>Zip Code:
</td>
<td><asp:TextBox Runat="server" ID="BuyerZipCodeTextBox">68104</asp:TextBox></td>
<td><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>Country:
</td>
<td>United States</td>
</tr>
</table>
<br />
<strong>Credit Card</strong>
<table>
<tbody>
<tr>
<td>Type:
</td>
<td>
<asp:DropDownList Runat="server" ID="CreditCartTypeDropDownList" OnSelectedIndexChanged="CreditCartTypeDropDownList_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Selected="True" value="Visa">Visa</asp:ListItem>
<asp:ListItem value="MasterCard">MasterCard</asp:ListItem>
<asp:ListItem value="Discover">Discover</asp:ListItem>
<asp:ListItem value="Amex">American Express</asp:ListItem>
</asp:DropDownList>
</td>
<td class="style1"><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>Credit Card Number:
</td>
<td><asp:TextBox runat="server" ID="CreditCardNumberTextBox">4059042064101342</asp:TextBox></td>
<td class="style1"><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>Card Verification Number:
</td>
<td><asp:TextBox runat="server" ID="CVV2TextBox" Text='000'>962</asp:TextBox></td>
<td class="style1"><font size="-1" color="red">Required</font></td>
</tr>
<tr>
<td>Expiration Date:
</td>
<td>
<asp:DropDownList Runat="server" ID="ExpMonthDropDownList">
<asp:ListItem value="01">01</asp:ListItem>
<asp:ListItem value="02">02</asp:ListItem>
<asp:ListItem value="03">03</asp:ListItem>
<asp:ListItem value="04">04</asp:ListItem>
<asp:ListItem value="05">05</asp:ListItem>
<asp:ListItem value="06">06</asp:ListItem>
<asp:ListItem value="07">07</asp:ListItem>
<asp:ListItem value="08">08</asp:ListItem>
<asp:ListItem value="09">09</asp:ListItem>
<asp:ListItem value="10">10</asp:ListItem>
<asp:ListItem value="11">11</asp:ListItem>
<asp:ListItem value="12">12</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList Runat="server" ID="ExpYearDropDownList">
<asp:ListItem value="2005">2005</asp:ListItem>
<asp:ListItem Value="2006">2006</asp:ListItem>
<asp:ListItem value="2007">2007</asp:ListItem>
<asp:ListItem value="2008">2008</asp:ListItem>
<asp:ListItem value="2009">2009</asp:ListItem>
<asp:ListItem value="2010">2010</asp:ListItem>
<asp:ListItem value="2011">2011</asp:ListItem>
<asp:ListItem value="2012">2012</asp:ListItem>
<asp:ListItem value="2013">2013</asp:ListItem>
<asp:ListItem value="2014">2014</asp:ListItem>
<asp:ListItem Selected="True" value="2007">2007</asp:ListItem>
</asp:DropDownList>
</td>
<td class="style1"><font size="-1" color="red">Required</font></td>
</tr>
</tbody>
</table>
<br />
<asp:Button runat="server" ID="PayButton" OnClick="PayButton_Click" Text="Pay" OnClientClick="PayButton_Click"></asp:Button>
<%----%>
<input type="button" value="Cancel" onclick="javascript:history.back()" />
<h3><a href="../Calls.aspx">Home</a></h3>
</form>
</body>
</html>
That was my C# Code
using System;
using System.Web.UI.WebControls;
using com.paypal.soap.api;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Xml;
using System.Web.Configuration;
using ASPDotNetSamples.wppro;
namespace ASPDotNetSamples.wppro
{
public class DirectPaymentAuthorization : System.Web.UI.Page
{
protected Button GetButton;
protected TextBox PaymentAmountTextBox;
protected TextBox BuyerFirstNameTextBox;
protected TextBox BuyerLastNameTextBox;
protected TextBox BuyerAddress1TextBox;
protected TextBox BuyerAddress2TextBox;
protected TextBox BuyerCityTextBox;
protected TextBox BuyerStateTextBox;
protected TextBox BuyerZipCodeTextBox;
protected DropDownList CreditCartTypeDropDownList;
protected TextBox CreditCardNumberTextBox;
protected TextBox CVV2TextBox;
protected DropDownList ExpMonthDropDownList;
protected DropDownList ExpYearDropDownList;
protected Button PayButton;
private void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
FillInGeneratedCreditCardNumber();
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
this.DataBind();
}
public override void DataBind()
{
if (this.TransactionID != null)
{
PayPalAPI api = new PayPalAPI();
this.PayPalResponse = api.GetTransactionDetails(this.TransactionID);
}
base.DataBind();
}
protected void CreditCartTypeDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
FillInGeneratedCreditCardNumber();
}
private void FillInGeneratedCreditCardNumber()
{
this.CreditCardNumberTextBox.Text = Util.GenerateCreditCardNumber(this.CreditCartTypeDropDownList.SelectedValue);
}
protected void PayButton_Click(object sender, EventArgs e)
{
string value1 = ConfigurationManager.AppSettings["API_USERNAME"];
string value2 = ConfigurationManager.AppSettings["API_PASSWORD"];
string value3 = ConfigurationManager.AppSettings["API_SIGNATURE"];
string value4 = ConfigurationManager.AppSettings["API_ENVIORMENT"];
PayPalAPI api = new PayPalAPI();
int expMonth = int.Parse(this.ExpMonthDropDownList.SelectedValue);
int expYear = int.Parse(this.ExpYearDropDownList.SelectedValue);
this.PayPalResponse = api.DoDirectPayment(
this.PaymentAmountTextBox.Text,
this.BuyerFirstNameTextBox.Text,
this.BuyerFirstNameTextBox.Text,
this.BuyerAddress1TextBox.Text,
this.BuyerAddress2TextBox.Text,
this.BuyerCityTextBox.Text,
this.BuyerStateTextBox.Text,
this.BuyerZipCodeTextBox.Text,
this.CreditCartTypeDropDownList.SelectedValue,
this.CreditCardNumberTextBox.Text,
this.CVV2TextBox.Text,
expMonth,
expYear, PaymentActionCodeType.Authorization);
Response.Redirect("Receipt.aspx");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.BuyerFirstNameTextBox.TextChanged += new System.EventHandler(this.BuyerFirstNameTextBox_TextChanged);
this.ExpYearDropDownList.SelectedIndexChanged += new System.EventHandler(this.ExpYearDropDownList_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BuyerFirstNameTextBox_TextChanged(object sender, System.EventArgs e)
{
}
private void ExpYearDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}