Thứ Ba, 29 tháng 7, 2008

Application using webservice to GetBalance

using System;
using System.Windows.Forms;

namespace WindowsApplication1
{
// Add web reference to http://www.paypal.com/wsdl/PayPalSvc.wsdl
// This makes com.paypal.www namespace available
using com.paypal.www;

public partial class Form1 : Form
{
private void GetBalance()
{
try
{
UserIdPasswordType user = new UserIdPasswordType();
user.Username = "";
user.Password = "";
user.Signature = "";

PayPalAPISoapBinding PPInterface = new PayPalAPISoapBinding();

PPInterface.RequesterCredentials = new CustomSecurityHeaderType();
PPInterface.Url = "https://api.sandbox.paypal.com/2.0/"; // sandbox
//PPInterface.Url = "https://api.paypal.com/2.0/"; // production
PPInterface.RequesterCredentials.Credentials = user;

GetBalanceReq BalanceReq = new GetBalanceReq();
BalanceReq.GetBalanceRequest = new GetBalanceRequestType();
BalanceReq.GetBalanceRequest.Version = "3.2";

GetBalanceResponseType BalanceResType = PPInterface.GetBalance(BalanceReq);

switch (BalanceResType.Ack)
{
case AckCodeType.Success:
this.label1.Text =
BalanceResType.BalanceTimeStamp + " " +
BalanceResType.Balance.currencyID + " " +
BalanceResType.Balance.Value;
break;
case AckCodeType.Failure:
this.label1.Text = BalanceResType.Errors[0].LongMessage;
break;
default:
this.label1.Text = "BalanceResType.Ack = " + BalanceResType.Ack;
break;
}
}
catch (Exception exception)
{
this.label1.Text = exception.Message;
}
}


public Form1()
{
InitializeComponent();

GetBalance();
}
}
}

Không có nhận xét nào: