Verisign PayMent Relation Method
#region Verisign PayMent Relation Method
protected void VeriSignDoDirectPayment_Click(object sender, EventArgs e)
{
try
{
string ResponseOut = DoPayflowPro("1");
if (GetResponseValue(ResponseOut, "RESULT") == "0")
{
Response.Write(ResponseOut);
}
else
{
Response.Write(GetResponseValue(ResponseOut, "RESPMSG"));
}
}
catch (Exception x)
{
Response.Write(x.Message);
}
}
public string DoPayflowPro(string OrderTotal)
{
PayFlowPro.PFPro pfpro = new PayFlowPro.PFPro();
string ResponseOut = "";
int pCtlx;
string user = "verisgin user";
string Vendor = "verisgin Vendor";
string Partner = "verisgin Partner";
string Password = "verisgin Password";
string HostAddress = "payflow.verisign.com";
string street ="";//持卡人帐单地址
string zip = "";//持卡人帐单邮编
int HostPort = 443;
int Timeout = 60;
string ProxyAddress = "";
int ProxyPort = 0;
string ProxyLogon = "";
string ProxyPassword = "";
string ParmList = "TRXTYPE=S&TENDER=C&COMMENT1=Frontsql Transaction";
ParmList = ParmList + "&USER=" + user;
ParmList = ParmList + "&VENDOR=" + Vendor;
ParmList = ParmList + "&PARTNER=" + Partner;
ParmList = ParmList + "&PWD=" + Password;
ParmList = ParmList + "&ACCT=1111111111111111";
ParmList = ParmList + "&EXPDATE=1206"; //month + year
ParmList = ParmList + "&STREET="+street;
ParmList = ParmList + "&ZIP=" + zip;
ParmList = ParmList + "&AMT=" + OrderTotal;
pCtlx = pfpro.CreateContext(HostAddress, HostPort, Timeout,
ProxyAddress, ProxyPort, ProxyLogon, ProxyPassword);
ResponseOut = pfpro.SubmitTransaction(pCtlx, ParmList);
pfpro.DestroyContext(pCtlx);
return ResponseOut;
}
public string GetResponseValue(string rOut, string attri)
{
//Faiule RESULT=23&PNREF=VKNE1DD3CCDC&RESPMSG=Invalid account number&AVSADDR=X&AVSZIP=X&IAVS=N
string[] str = rOut.Split('&');
string backstr = "";
//int i = str.Length - 1;
for (int i = 0; i < str.Length; i++)
{
if (str[i].Contains(attri))
{
backstr = str[i].Substring(str[i].IndexOf('=') + 1);
}
}
return backstr;
}
#endregion
protected void VeriSignDoDirectPayment_Click(object sender, EventArgs e)
{
try
{
string ResponseOut = DoPayflowPro("1");
if (GetResponseValue(ResponseOut, "RESULT") == "0")
{
Response.Write(ResponseOut);
}
else
{
Response.Write(GetResponseValue(ResponseOut, "RESPMSG"));
}
}
catch (Exception x)
{
Response.Write(x.Message);
}
}
public string DoPayflowPro(string OrderTotal)
{
PayFlowPro.PFPro pfpro = new PayFlowPro.PFPro();
string ResponseOut = "";
int pCtlx;
string user = "verisgin user";
string Vendor = "verisgin Vendor";
string Partner = "verisgin Partner";
string Password = "verisgin Password";
string HostAddress = "payflow.verisign.com";
string street ="";//持卡人帐单地址
string zip = "";//持卡人帐单邮编
int HostPort = 443;
int Timeout = 60;
string ProxyAddress = "";
int ProxyPort = 0;
string ProxyLogon = "";
string ProxyPassword = "";
string ParmList = "TRXTYPE=S&TENDER=C&COMMENT1=Frontsql Transaction";
ParmList = ParmList + "&USER=" + user;
ParmList = ParmList + "&VENDOR=" + Vendor;
ParmList = ParmList + "&PARTNER=" + Partner;
ParmList = ParmList + "&PWD=" + Password;
ParmList = ParmList + "&ACCT=1111111111111111";
ParmList = ParmList + "&EXPDATE=1206"; //month + year
ParmList = ParmList + "&STREET="+street;
ParmList = ParmList + "&ZIP=" + zip;
ParmList = ParmList + "&AMT=" + OrderTotal;
pCtlx = pfpro.CreateContext(HostAddress, HostPort, Timeout,
ProxyAddress, ProxyPort, ProxyLogon, ProxyPassword);
ResponseOut = pfpro.SubmitTransaction(pCtlx, ParmList);
pfpro.DestroyContext(pCtlx);
return ResponseOut;
}
public string GetResponseValue(string rOut, string attri)
{
//Faiule RESULT=23&PNREF=VKNE1DD3CCDC&RESPMSG=Invalid account number&AVSADDR=X&AVSZIP=X&IAVS=N
string[] str = rOut.Split('&');
string backstr = "";
//int i = str.Length - 1;
for (int i = 0; i < str.Length; i++)
{
if (str[i].Contains(attri))
{
backstr = str[i].Substring(str[i].IndexOf('=') + 1);
}
}
return backstr;
}
#endregion
AuthorizeNet
AuthorizeNet PayMent Relation Method
#region AuthorizeNet PayMent Relation Method
protected void AuthorizeNetDoDirectPayment_Click(object sender, EventArgs e)
{
try
{
Response.Write(AuthorizeNetDoDirectPaymentMethod("1"));
}
catch (Exception x)
{
Response.Write(x.Message);
}
}
protected string AuthorizeNetDoDirectPaymentMethod(string dTotal)
{
string returnStr = "";
String result = "";
String strPost = "x_login=" + "username" +
"&x_tran_key=" + "key" +
"&x_method=CC" +
"&x_type=AUTH_CAPTURE" +
"&x_amount=" + dTotal +
"&x_delim_data=TRUE" +
"&x_delim_char=|" +
"&x_relay_response=FALSE" +
"&x_card_num=" + "1111111111111111" +
"&x_exp_date=" + 1206 + //Month + Year
"&x_version=3.1" +
//the following is optional however it's good to have for records
"&x_first_name=" + "Bill FirstName" +
"&x_last_name=" + "Bill LastName" +
"&x_address=" + "Bill Address" +
"&x_city=" + "Bill City" +
"&x_state=" + "Bill State" +
"&x_zip=" + "Bill Zip" +
"&x_currency_code=" + "USD" +
"&x_country=" + "Bill Country" +
"&x_card_code=" + "credit card security code ";
//you can set this up to send you an email if you like
//by adding this:
//&x_merchant_email=me@email.com
//you can also have them send you customer an email
//&x_email=mycustomer@email.com&x_email_customer=TRUE
string serverURL = "https://test.authorize.net/gateway/transact.dll"; //正式环境 https://authorize.net/gateway/transact.dll
bool useTestServer = serverURL.IndexOf("test") >= 0;
if (useTestServer)
strPost += "&x_test_request=TRUE";
HttpRequestHandler http = new HttpRequestHandler(serverURL);
result = http.POST(strPost);
string[] lines = result.Split('|');
//the response flag is the first item
// //1=success, 2=declined, 3=error
string sFlag = lines[0];
if (sFlag == "1")
{
//trans.GatewayResponse = lines[37];
//trans.AuthorizationCode = lines[4];
//return the transactionID
//trans.GatewayResponse = result;
returnStr = lines[3] + "(" + lines[37] + ")";
}
else if (sFlag == "2")
{
//trans.GatewayResponse = lines[3];
returnStr = lines[3];
throw new Exception("Declined: " + returnStr);
}
else
{
//trans.GatewayResponse = lines[3];
returnStr = lines[3];
throw new Exception("Error: " + returnStr);
}
return returnStr;
}
#endregion
protected void AuthorizeNetDoDirectPayment_Click(object sender, EventArgs e)
{
try
{
Response.Write(AuthorizeNetDoDirectPaymentMethod("1"));
}
catch (Exception x)
{
Response.Write(x.Message);
}
}
protected string AuthorizeNetDoDirectPaymentMethod(string dTotal)
{
string returnStr = "";
String result = "";
String strPost = "x_login=" + "username" +
"&x_tran_key=" + "key" +
"&x_method=CC" +
"&x_type=AUTH_CAPTURE" +
"&x_amount=" + dTotal +
"&x_delim_data=TRUE" +
"&x_delim_char=|" +
"&x_relay_response=FALSE" +
"&x_card_num=" + "1111111111111111" +
"&x_exp_date=" + 1206 + //Month + Year
"&x_version=3.1" +
//the following is optional however it's good to have for records
"&x_first_name=" + "Bill FirstName" +
"&x_last_name=" + "Bill LastName" +
"&x_address=" + "Bill Address" +
"&x_city=" + "Bill City" +
"&x_state=" + "Bill State" +
"&x_zip=" + "Bill Zip" +
"&x_currency_code=" + "USD" +
"&x_country=" + "Bill Country" +
"&x_card_code=" + "credit card security code ";
//you can set this up to send you an email if you like
//by adding this:
//&x_merchant_email=me@email.com
//you can also have them send you customer an email
//&x_email=mycustomer@email.com&x_email_customer=TRUE
string serverURL = "https://test.authorize.net/gateway/transact.dll"; //正式环境 https://authorize.net/gateway/transact.dll
bool useTestServer = serverURL.IndexOf("test") >= 0;
if (useTestServer)
strPost += "&x_test_request=TRUE";
HttpRequestHandler http = new HttpRequestHandler(serverURL);
result = http.POST(strPost);
string[] lines = result.Split('|');
//the response flag is the first item
// //1=success, 2=declined, 3=error
string sFlag = lines[0];
if (sFlag == "1")
{
//trans.GatewayResponse = lines[37];
//trans.AuthorizationCode = lines[4];
//return the transactionID
//trans.GatewayResponse = result;
returnStr = lines[3] + "(" + lines[37] + ")";
}
else if (sFlag == "2")
{
//trans.GatewayResponse = lines[3];
returnStr = lines[3];
throw new Exception("Declined: " + returnStr);
}
else
{
//trans.GatewayResponse = lines[3];
returnStr = lines[3];
throw new Exception("Error: " + returnStr);
}
return returnStr;
}
#endregion
PayPal
详细请参考: http://paypaltech.com/Dave/api_sourcebook/html/index.html
using
System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using cSharpSignatureExamples.PPSVC; // using statement for WSDL Reference
namespace cSharpSignatureExamples
{
/**//// <summary>
/// Summary description for DoDirectPayment.
/// </summary>
public class DoDirectPayment : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//################set up Request########################
//instantiate DoDirectPaymentRequestType and RequestDetails objects
DoDirectPaymentRequestType DoDirectPmtReqType = new DoDirectPaymentRequestType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();
//set paymentaction
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale;
//set IP
DoDirectPmtReqType.DoDirectPaymentRequestDetails.IPAddress = Request.UserHostAddress;
//set CreditCard info
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = "4719294777609143";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Visa;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CVV2 = "587";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = 1;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpYear = 2007;
//set billing address
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = "Bob";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = "Fakebuyer";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = "1541 N 121st st";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = "Apt 12";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = "Los Angeles";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = "CA";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = "90210";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.US;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Phone = "210-899-4111";
//setup individual items
//item 1
PaymentDetailsItemType item1 = new PaymentDetailsItemType();
item1.Amount = new BasicAmountType();
item1.Amount.Value = "2.00";
item1.Amount.currencyID = CurrencyCodeType.USD;
item1.Quantity = "1";
item1.Tax = new BasicAmountType();
item1.Tax.Value = "1.00";
item1.Tax.currencyID = CurrencyCodeType.USD;
item1.Name = "Item 1";
item1.Number = "SKU 1";
//item 2
PaymentDetailsItemType item2 = new PaymentDetailsItemType();
item2.Amount = new BasicAmountType();
item2.Amount.Value = "5.00";
item2.Amount.currencyID = CurrencyCodeType.USD;
item2.Quantity = "1";
item2.Tax = new BasicAmountType();
item2.Tax.Value = "1.00";
item2.Tax.currencyID = CurrencyCodeType.USD;
item2.Name = "Item 2";
item2.Number = "SKU 2";
PaymentDetailsItemType[] itemArray = new PaymentDetailsItemType[2];
itemArray.SetValue(item1, 0);
itemArray.SetValue(item2, 1);
//set payment Details
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.Custom = System.DateTime.Now.ToLongTimeString();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[2];
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = itemArray;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem.SetValue(item1, 0);
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem.SetValue(item2, 1);
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = "11.00";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.Value = "2.00";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.Value = "2.00";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.Value = "7.00";
//individual items
//set ship to address
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress = new AddressType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name = "Sally Fakebuyer";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1 = "58654 Happy Valley";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName = "Oakland";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.StateOrProvince = "CA";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode = "94603";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CountrySpecified = true;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country = CountryCodeType.US;
DoDirectPaymentReq DoDPReq = new DoDirectPaymentReq();
DoDPReq.DoDirectPaymentRequest = DoDirectPmtReqType;
DoDPReq.DoDirectPaymentRequest.Version = "2.20";
//################### FINISH set up req ##############
//################ setup request Header, API credentials #######
PayPalAPIAASoapBinding PPInterface = new PayPalAPIAASoapBinding();
UserIdPasswordType user = new UserIdPasswordType();
//set api credentials - username, password, signature
user.Username = "3token_api1.sandbox.com";
user.Password = "JAVL2F5LJQAYUNQJ";
user.Signature = "ABjwDNHZ2vaJeK5UyS4MMW7IBQdlAfz0gnsA.AYAfpMVAoAB6ko-w9v4";
// set API server URL - this is for the Sandbox
PPInterface.Url = "https://api-aa.sandbox.paypal.com/2.0/";
// if this was the production site, you'd use
// PPInterface.Url = "https://api-aa-3t.paypal.com/2.0/";
PPInterface.RequesterCredentials = new CustomSecurityHeaderType();
PPInterface.RequesterCredentials.Credentials = new UserIdPasswordType();
PPInterface.RequesterCredentials.Credentials = user;
try
{
//make call return response
DoDirectPaymentResponseType DPRes = new DoDirectPaymentResponseType();
DPRes = PPInterface.DoDirectPayment(DoDPReq);
//print some output
switch (DPRes.Ack)
{
case AckCodeType.Success:
Response.Write("API response: <b>" + DPRes.Ack.ToString() +
"</b><br> Timestamp: <b>" + DPRes.Timestamp.ToLongTimeString() +
"</b><br> Version: <b>" + DPRes.Version +
"</b><br> TransactionID: <b>" + DPRes.TransactionID +
"</b><br> AVS Code: <b>" + DPRes.AVSCode +
"</b><br> CVV2 Code: <b>" + DPRes.CVV2Code);
break;
default: // show errors if Ack is NOT Success
Response.Write("API response: <b>" + DPRes.Ack.ToString() +
"</b><br> Timestamp: <b>" + DPRes.Timestamp.ToLongTimeString() +
"</b><br> Version: <b>" + DPRes.Version.ToString() +
"</b><br> Error code: <b>" + DPRes.Errors[0].ErrorCode +
"</b><br> Short error: <b>" + DPRes.Errors[0].ShortMessage +
"</b><br> Long error: <b>" + DPRes.Errors[0].LongMessage);
break;
}
}
catch (Exception ex) // if there is some exception, catch it and print the error
{
Response.Write(ex.ToString());
}
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using cSharpSignatureExamples.PPSVC; // using statement for WSDL Reference
namespace cSharpSignatureExamples
{
/**//// <summary>
/// Summary description for DoDirectPayment.
/// </summary>
public class DoDirectPayment : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//################set up Request########################
//instantiate DoDirectPaymentRequestType and RequestDetails objects
DoDirectPaymentRequestType DoDirectPmtReqType = new DoDirectPaymentRequestType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();
//set paymentaction
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale;
//set IP
DoDirectPmtReqType.DoDirectPaymentRequestDetails.IPAddress = Request.UserHostAddress;
//set CreditCard info
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = "4719294777609143";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Visa;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CVV2 = "587";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = 1;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpYear = 2007;
//set billing address
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = "Bob";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = "Fakebuyer";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = "1541 N 121st st";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = "Apt 12";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = "Los Angeles";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = "CA";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = "90210";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.US;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Phone = "210-899-4111";
//setup individual items
//item 1
PaymentDetailsItemType item1 = new PaymentDetailsItemType();
item1.Amount = new BasicAmountType();
item1.Amount.Value = "2.00";
item1.Amount.currencyID = CurrencyCodeType.USD;
item1.Quantity = "1";
item1.Tax = new BasicAmountType();
item1.Tax.Value = "1.00";
item1.Tax.currencyID = CurrencyCodeType.USD;
item1.Name = "Item 1";
item1.Number = "SKU 1";
//item 2
PaymentDetailsItemType item2 = new PaymentDetailsItemType();
item2.Amount = new BasicAmountType();
item2.Amount.Value = "5.00";
item2.Amount.currencyID = CurrencyCodeType.USD;
item2.Quantity = "1";
item2.Tax = new BasicAmountType();
item2.Tax.Value = "1.00";
item2.Tax.currencyID = CurrencyCodeType.USD;
item2.Name = "Item 2";
item2.Number = "SKU 2";
PaymentDetailsItemType[] itemArray = new PaymentDetailsItemType[2];
itemArray.SetValue(item1, 0);
itemArray.SetValue(item2, 1);
//set payment Details
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.Custom = System.DateTime.Now.ToLongTimeString();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[2];
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = itemArray;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem.SetValue(item1, 0);
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem.SetValue(item2, 1);
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = "11.00";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.Value = "2.00";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.Value = "2.00";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal = new BasicAmountType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.currencyID = CurrencyCodeType.USD;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.Value = "7.00";
//individual items
//set ship to address
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress = new AddressType();
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name = "Sally Fakebuyer";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1 = "58654 Happy Valley";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName = "Oakland";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.StateOrProvince = "CA";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode = "94603";
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CountrySpecified = true;
DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country = CountryCodeType.US;
DoDirectPaymentReq DoDPReq = new DoDirectPaymentReq();
DoDPReq.DoDirectPaymentRequest = DoDirectPmtReqType;
DoDPReq.DoDirectPaymentRequest.Version = "2.20";
//################### FINISH set up req ##############
//################ setup request Header, API credentials #######
PayPalAPIAASoapBinding PPInterface = new PayPalAPIAASoapBinding();
UserIdPasswordType user = new UserIdPasswordType();
//set api credentials - username, password, signature
user.Username = "3token_api1.sandbox.com";
user.Password = "JAVL2F5LJQAYUNQJ";
user.Signature = "ABjwDNHZ2vaJeK5UyS4MMW7IBQdlAfz0gnsA.AYAfpMVAoAB6ko-w9v4";
// set API server URL - this is for the Sandbox
PPInterface.Url = "https://api-aa.sandbox.paypal.com/2.0/";
// if this was the production site, you'd use
// PPInterface.Url = "https://api-aa-3t.paypal.com/2.0/";
PPInterface.RequesterCredentials = new CustomSecurityHeaderType();
PPInterface.RequesterCredentials.Credentials = new UserIdPasswordType();
PPInterface.RequesterCredentials.Credentials = user;
try
{
//make call return response
DoDirectPaymentResponseType DPRes = new DoDirectPaymentResponseType();
DPRes = PPInterface.DoDirectPayment(DoDPReq);
//print some output
switch (DPRes.Ack)
{
case AckCodeType.Success:
Response.Write("API response: <b>" + DPRes.Ack.ToString() +
"</b><br> Timestamp: <b>" + DPRes.Timestamp.ToLongTimeString() +
"</b><br> Version: <b>" + DPRes.Version +
"</b><br> TransactionID: <b>" + DPRes.TransactionID +
"</b><br> AVS Code: <b>" + DPRes.AVSCode +
"</b><br> CVV2 Code: <b>" + DPRes.CVV2Code);
break;
default: // show errors if Ack is NOT Success
Response.Write("API response: <b>" + DPRes.Ack.ToString() +
"</b><br> Timestamp: <b>" + DPRes.Timestamp.ToLongTimeString() +
"</b><br> Version: <b>" + DPRes.Version.ToString() +
"</b><br> Error code: <b>" + DPRes.Errors[0].ErrorCode +
"</b><br> Short error: <b>" + DPRes.Errors[0].ShortMessage +
"</b><br> Long error: <b>" + DPRes.Errors[0].LongMessage);
break;
}
}
catch (Exception ex) // if there is some exception, catch it and print the error
{
Response.Write(ex.ToString());
}
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}