Friday, January 30, 2009

How to Integrate paypal with HTML

How to Integrate paypal with HTML

Paypal is very common payment gate way and mostly used in HTML ,PHP,.NET web sites for sub mit payment to vendor.


Now I am explain steps of integrating in Paypal in our application.

Suppose we have a page where we set the item and price and other inforamation in html hidden fields.
General structure of page is as follows.


[form id="Form1" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"]
[input type="hidden" name="cmd" value="_xclick"] [input type="hidden" name="business" value="mca.mk_1233244379_biz@gmail.com"]
[input type="hidden" name="item_name" value="Item1"]
[input type="hidden" name="amount" value="100.00"]
[input type="hidden" name="currency_code" value="USD"]
[input type="hidden" name="return" value="http://localhost/eStoreFrontCS/Default2.aspx"]
[input type="hidden" name="cancel_return" value="http://localhost/eStoreFrontCS/Default.aspx"]
[asp:Label id="Label2" style="Z-INDEX: 101; LEFT: 784px; POSITION: absolute; TOP: 8px" runat="server"
ForeColor="White" BackColor="#C04000" Font-Bold="True" Width="20045px"]Loading payment process.....[/asp:Label]
[asp:Label id="Label3" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 8px" runat="server"
Font-Bold="True"]Wait ...[/asp:Label]
[/form]

In action tag we give the url of sandbox. This is starting step with paypal. Open the paypal.com

1)https://developer.paypal.com/ -] Signup now
2)after it you will recive a message “ Sandbox Signup Complete”
3)Check Email account which u specify in signup process. And click link for confermation.
4)Open paypal site with given link.
5)Choose option “Create a preconfigured buyer or seller account.” under TEST ACCOUNT tab.
6)Create a Buyer Account (Use to represent your customer's experience) must open “ Show Advanced Options “ link and give starting balance amout as 5000 USD or as your requirement. In Add note section copypaste the password so u can check it any time in test account secton.
7)Create a Seller Account (Use to represent yourself as the merchant) and also provide sum banalce under “ Show Advanced Options “ In Add note section copypaste the password so u can check it any time in test account secton.
8)Now the work with paypal site is over. Now come on your HTML page. And copy paste all code under form tag.
9)And after it put this script which submit page when it will load
10)[script language="JavaScript"]Form1.submit()[/script]
11) and now this will redirect u on this link https://www.sandbox.paypal.com/us/cgi-bin/webscr? With querystring.
12)Now in “ LOG IN TO PAYPAL “ frame put details of Buyer Account which u created for above code the details ar e as follows mca.mk_1233244323_per@gmail.com / pwd is testpwdtestpwd
13)enter pwd testpwdtestpwd
14) now confermation screen will come
15) Click on pay now button. And u wil get thanks msg window.
16)Now we have to check the effects on murchent and buyer account. So opent sandbox account.
17) Buyer account is debit form 100 USD
18)And murchant account is Credit by 96.8 USD.
Hope with above steps u can get basic idea of paypal account.

Thanks
HelpOnDesk Team

Friday, January 9, 2009

Retrive CSV from DATABASE

HI
Aprox in every project we need to send mail to all registred user then we can retrive emailAddress
in CSV format and form frontend we can fetch all values from for loop and send these emails to user
in single database cycle.

Basic example of this type SP is as follows :-


create proc SelectEmailAddressInCSV
as
set nocount on
DECLARE @xyz VARCHAR(100)
declare @abc varchar(100)

set @abc=''

declare selemail cursor for

select email from dataadi

open selemail
fetch NEXT from selemail into @xyz
WHILE @@Fetch_status = 0
begin


set @abc= @abc+ @xyz+','

FETCH NEXT FROM selemail INTO @xyz
END
print @abc
CLOSE selemail
DEALLOCATE selemail


Table of dataadi is as follows

CREATE TABLE [dbo].[dataadi](
[ID] [int] NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Email] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_dataadi] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


So Run this script and modified as your need


simppily we can add these three lines

DECLARE @values varchar(150), @delimiter char
SET @delimiter = ','
SELECT @values = COALESCE(@values + @delimiter, '') + u_name FROM tblsplit
SELECT @values AS [List of Emails]

Thanks
HelpOnDesk Team

Template for SP geting values one by one from CSV (Comma Seprated Values)

HI,
Many time we need to update many records in database. for example if we using select all check boxes for delete or update the reocrds then we can save the selected id corespondit to selected check boxes and then pass all vlues in dataset as the form of CSV and the with the help of following SP we can get values one by one and
fire the query.
Template for SP to get values one by one from CSV. suppy two inputs first the csv and then charter which i used for seprate the values



create proc [ufn_CountChar] ( @pInput VARCHAR(1000), @pSearchChar CHAR(1) )
as
BEGIN

/*DECLARE @vInputLength INT*/
DECLARE @vIndex INT
DECLARE @vCount INT
DECLARE @s varchar(2)
DECLARE @str varchar(10)
declare @SubStr varchar(1000)

set @SubStr=''
SET @vCount = 0
SET @vIndex = 1
/*SET @vInputLength = LEN(@pInput)*/
set @str=''

WHILE @vIndex <= len(@pInput)
BEGIN
IF SUBSTRING(@pInput, @vIndex, 1) = @pSearchChar
BEGIN
SET @vCount = @vCount + 1
set @SubStr = substring(@pInput,len(@SubStr),len( @str))
select 'update insert delete query with this value - ' + @str
set @str=''
END
else
BEGIN
set @s=SUBSTRING(@pInput,@vindex,1)
set @str=@str+@s
print ' i m in else part'+ space(3)+ @str
if( @vIndex = len(@pInput))
begin
select 'update insert delete query with this value - ' + @str
end

END
SET @vIndex = @vIndex + 1

END

--select @str


END
GO

--ufn_CountChar 'afd,hghg,hgjgh',','

uplaoding an image and creating Thumbnail of same image according to heigth and width

Hi
in this article we create a class for uplaoding an image and creating
Thumbnail of same image according to heigth and width of orignal image
means if we uplaod a landscapte image then its thumbnail will genrate as
landscape if image is as potrate its thumbnail will genrate as portrare.


call this function

thumbnail oANB = new thumbnail();
oANB.CreateThumb(FileUpload1, @"Images\", @"Images\Thumbnail\");
oANB.CreateThumb(FileUpload1, @"Images\");


create a class with following code.


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using Microsoft.Win32;
using PAB.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

public class thumbnail
{

public string UploadImage(string filename, string filetype, string str_folder_name_main, string str_folder_name_small,

FileUpload fileupload1, int width, int heigh)
{

if (fileupload1.PostedFile.ContentType == "image/pjpeg" || fileupload1.PostedFile.ContentType == "image/jpeg" ||

fileupload1.PostedFile.ContentType == "image/bmp" || fileupload1.PostedFile.ContentType == "image/gif")
{

string typ = fileupload1.PostedFile.ContentType;

fileupload1.PostedFile.SaveAs( HttpContext.Current.Server.MapPath( str_folder_name_main + filename + filetype));

if (str_folder_name_small.CompareTo(string.Empty) != 0)
{

CreateThumbnail(HttpContext.Current.Server.MapPath(str_folder_name_main + filename + filetype), width, heigh,

HttpContext.Current.Server.MapPath(str_folder_name_small + filename + filetype), 25, 25);
}

return "1";
}
else
{
return "0";
}
}

public string CreateThumbnail(string lcFilename, int lnWidth, int lnHeight, string OutputFilename, int hightPercent, int

widthPercent)
{
try
{
System.Drawing.Bitmap bmpOut = null;
Bitmap loBMP = new Bitmap(lcFilename);
ImageFormat loFormat = loBMP.RawFormat;
System.Drawing.Imaging.EncoderParameters Params = new System.Drawing.Imaging.EncoderParameters(1);
Params.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
decimal lnRatio;
int thumbnamilHigth = Convert.ToInt32((loBMP.Height * hightPercent) / 100);
int thumbnamilWidth = Convert.ToInt32((loBMP.Width * widthPercent) / 100);

bmpOut = new Bitmap(thumbnamilHigth, thumbnamilWidth);

Graphics g = Graphics.FromImage(bmpOut);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.White, 0, 0, thumbnamilHigth, thumbnamilWidth);
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;

g.DrawImage(loBMP, 0, 0, thumbnamilHigth, thumbnamilWidth);
loBMP.Dispose();

bmpOut.Save(OutputFilename, ImageFormat.Jpeg);
bmpOut.Dispose();

return OutputFilename;
}
catch(Exception Ex)
{
return Ex.Message.ToString();

}


}

public bool checkImageType(HtmlInputFile FileUpload1)
{
if (FileUpload1.PostedFile.ContentType == "image/pjpeg" || FileUpload1.PostedFile.ContentType == "image/jpeg" ||

FileUpload1.PostedFile.ContentType == "image/bmp" || FileUpload1.PostedFile.ContentType == "image/gif")
{
return true;
}
else
{
return false;
}
}

public string CreateThumb(FileUpload fileUpload, string actIm, string tmbIm)
{
try
{
string filename = string.Empty;
string imagename = string.Empty;

string imgtype = string.Empty;
thumbnail thumb = new thumbnail();
filename = fileUpload.PostedFile.FileName;

imagename = filename.Substring(filename.LastIndexOf("\\") + 1, (filename.LastIndexOf(".") - 1) -

(filename.LastIndexOf("\\")));
imagename = imagename + DateTime.Now.Ticks.ToString() + GenrateRandomIamgeName(3);
imgtype = filename.Substring(filename.LastIndexOf("."));

if (thumb.UploadImage(imagename, imgtype, actIm, tmbIm, fileUpload, 95, 143).Equals("1"))
{
return imagename + imgtype;
}
else
{
return "";
}
}
catch
{
return "";
}


}

public string CreateThumb(FileUpload fileUpload, string actIm)
{
try
{
string tmbIm = string.Empty;
string filename = string.Empty;
string imagename = string.Empty;

string imgtype = string.Empty;
thumbnail thumb = new thumbnail();
filename = fileUpload.PostedFile.FileName;

imagename = filename.Substring(filename.LastIndexOf("\\") + 1, (filename.LastIndexOf(".") - 1) -

(filename.LastIndexOf("\\")));
imagename = imagename + DateTime.Now.Ticks.ToString() + GenrateRandomIamgeName(3);
imgtype = filename.Substring(filename.LastIndexOf("."));

if (thumb.UploadImage(imagename, imgtype, actIm, tmbIm, fileUpload, 95, 143).Equals("1"))
{
return imagename + imgtype;
}
else
{
return "";
}
}
catch
{
return "";
}


}



public string GenrateRandomIamgeName(int Length)
{
string listOfCharacter = "abcdefghijkmnopqrstuvwxyz0123456789";
Random randNum = new Random();
char[] chars = new char[Length];
int allCharacterCount = listOfCharacter.Length;

for (int i = 0; i < Length; i++)
{
chars[i] = listOfCharacter[(int)((listOfCharacter.Length) * randNum.NextDouble())];
}

return new string(chars);
}


}


Thanks
HelpOnDesk Team

Tuesday, January 6, 2009

session expire problem.

Hi,

In many application we want to live session aprox 2 - 10 Hrs. If we set session time out 10 Hrs then it is extra overload of server.
If we want to live one page then we can apply following idea for solve this problem. just do something with client browser.
so called javaScript for replace image on client borowser. this way session wil never expire on specefic page.or do work with iframes reload.

Second Idea to remove this idea is :-

1)Always create cookie when u add any records in session and write cookie
when session is null after time out in that condition read values from
cookie. in this way u find values after session time out.


In javaScript section:-


[script language="javascript" type="text/javascript"]

function AlwaysLive(imgName) {
myImg = document.getElementById(imgName);
if (myImg) myImg.src = myImg.src.replace(/\?.*$/, '?' + Math.random());
}
window.setInterval("AlwaysLive('imgReload')", 100000); //100 seconds


[/script]



HTML:
[img id="imgReload" width="1" height="1" src="images/close_btn.gif?" alt="" /]

you must save the ? with image extension.

Thanks
HelpOnDesk Team

USE of GENRIC CLASSES

-------------USE GENRIC CLASSES-----------------
Mny friedns ask me how to use Genric in our application, and what is genric.
so second question is on your part what is genric. i m giving two simple but
quite important example of genric which suerly make u understand how to use
genric.

Generic Type
Generics introduce a flexibility that combines type safety with the ability to avoid committing
to a type at design time.
What
Generics enable class, delegate, interface, and struct types, and methods to be created with
type parameters that are placeholder types, which can be substituted when the type is known.
Where
Generics are commonly used in data structures—for example, collections and arrays, or in
passing method parameters.
 
Why
Generics overcome the overhead issues of casting and boxing between types, which adversely
affects performance.
How
Generics are specified within a pair of delimiters ("<" and ">") placed after the respective type
or method name. When the type is known, it is substituted for the generic placeholder, as the
following code snippet illustrates. Note that the method
GenericMethod is declared as generic,
as is its parameter. In the Main function, we vary the types of the method.
using System;
using System.Collections.Generic;
using System.Text;
namespace ModelT
{
public class ModelTGenerics
{
public static void GenericMethod(T arg)
{
Console.WriteLine("Calling Model T generic method, " + arg.GetType());
}
public static void Main()
{
//Call the generic method passing different types:
GenericMethod("Hallo Generics");
GenericMethod(16.75);
}
}
}
 
The Standard: Generic Type
The standard acknowledges the use of generics to reduce overhead and increase type
flexibility while retaining the protection of type safety.


In First example we pass two different type in single genric class.
In second example we get data with help of genric class.

First Example :-

add new page in ur test application and paste following code

protected void Page_Load(object sender, EventArgs e)
{
//create a string version of our generic class
Col mystring = new Col();
//set the value
mystring.Val = "hello";

//output that value
Response.Write("Value :- " + mystring.Val+"
");


//output the value's type
Response.Write("Type :- " + mystring.Val.GetType() + "
");

//create another instance of our generic class, using a different type
Col myint = new Col();
//load the value
myint.Val = 5;
//output the value
Response.Write("Value :- "+ myint.Val + "
");
//output the value's type
Response.Write("Type :- " + myint.Val.GetType() + "
");

}
public class Col
{
T t;
public T Val { get { return t; } set { t = value; } }
}



There are a few things to notice. The class name "Col" is our first indication that this Type is generic, specifically the

brackets containing the Type placeholder. This Type placeholder "T" is used to show that if we need to refer to the actual

Type that is going to be used when we write this class, we will represent it as "T". Notice on the next line the variable

declaration "T t;" creates a member variable with the type of T, or the generic Type which we will specify later during

construction of the class (it will actually get inserted by the Common Language Runtime (CLR) automatically for us). The

final item in the class is the public property. Again, notice that we are using the Type placeholder "T" to represent that

generic type for the type of that property. Also notice that we can freely use the private variable "t" within the class.

This example is form
and there is more example for genric on this page.

Second Example :-

In this example we get data with help of genric class

Step 1.
caeate a simple class as following.

using System;

///
/// Summary description for UserInfo
///

public class UserInfo
{
private string _userName = string.Empty;
private string _password = string.Empty;


public UserInfo(string userName, string password)
{
this._userName = userName;
this._password = password;
}

public string UserName
{
get
{
return _userName;
}
}

public string Password
{
get
{
return _password;
}
}
}

Step 2.

create genric class which uses its type as a above class

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Data.SqlClient;

///
/// Summary description for genricList
///

public class genricList
{
public genricList()
{

}
public System.Collections.Generic.IList fillIlist()
{
string st = ConfigurationManager.ConnectionStrings[0].ToString();
IList userinfos = new List();
string connectionString = ConfigurationManager.ConnectionStrings["PUBSConnectionString"].ToString();
string queryString = "SELECT * FROM GenricLogin";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = queryString;

try
{
connection.Open();

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())
{
UserInfo info = new UserInfo(reader[0].ToString(),reader[1].ToString());
userinfos.Add(info);

}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

return userinfos;
}
}

table structure

CREATE TABLE GenricLogin (username varchar(20), password varchar(20))

Insert some values in table

Insert into GenricLogin (username,password)

select 'aaaaa','111111'
union all
select 'bb','222222222'
union all
select 'ccc','33333333'


Step 3

now call this funciton on page and bind your dataGrid with genric

genricList objgenricList = new genricList();
dg.DataSource = objgenricList.fillIlist();
dg.DataBind();


with same way we can add as much classes as we required for bind different tables.


Thanks
HelpOnDesk Team

Monday, January 5, 2009

if session is expire then redirec user like yahoo email

This code is redirect user on page where we show that is current session expired
and relogin login so on defautl button NavigateUrl="~/Admin/Login.aspx" Text="Click here to Login again" becz it is on preRender event so first it will execte

protected void Page_PreRender(object sender, EventArgs e)
{
HttpContext.Current.Response.AppendHeader("Refresh", Convert.ToString(((HttpContext.Current.Session.Timeout * 60) - 5)) + "; Url=Default.aspx");

}

Thanks
HelpOnDesk Team

Genrate Random Password

Hi,

This fucntion is used for Genrate Password.

pass length of password for example GenrateRandomPassword(8);

for better result we can add timeTick for select integer or we can call to time this fuction recurlsivle
and then get substring portion for final password.

in my earlier post i also upload a dataBAse storeprocedure for caseSenstive password.

public static string GenrateRandomPassword(int PasswordLength)
{
string listOfCharacter = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789#$&@-";
Random randNum = new Random();
char[] chars = new char[PasswordLength];
int allCharacterCount = listOfCharacter.Length;

for (int i = 0; i < PasswordLength; i++)
{
chars[i] = listOfCharacter[(int)((listOfCharacter.Length) * randNum.NextDouble())];
}

return new string(chars);
}

Thanks
HelpOnDeskTeam

Print a file without open it but this code work only when we select websete as a filesystem :(

//this code alow print a document without open it. and this code allow pdf / txt/ //doc etc. but works only on filesystem website
/*System.Diagnostics.ProcessStartInfo PrintingProcess = new System.Diagnostics.ProcessStartInfo();
PrintingProcess.Verb = "print";
PrintingProcess.WindowStyle = ProcessWindowStyle.Hidden;
PrintingProcess.FileName = "c:/M.txt";//path for the file
PrintingProcess.UseShellExecute = true;
System.Diagnostics.Process.Start(PrintingProcess); */


The following code automaticaly close its print window un comment last three lines

Process PrintingProcess = new Process();
PrintingProcess.StartInfo.CreateNoWindow = false;
PrintingProcess.StartInfo.Verb = "print";
PrintingProcess.StartInfo.FileName = @"C:\m.txt";
PrintingProcess.Start();
//PrintingProcess.WaitForExit(10000);
//PrintingProcess.CloseMainWindow();
//PrintingProcess.Close();

Thanks
HelponDesk Team

Friday, January 2, 2009

Insert or Update Template for data base stored procedure

Create PROC InsertUpdatetemplate
-- This proc is used for insert or update records
-- it is simple sp with roll back transaction
-- so we have to just upload this format
(


)


as


IF (exists(SELECT * FROM tablename WHERE condition))
BEGIN
--Update
BEGIN TRY
BEGIN TRAN

UPDATE qery

COMMIT TRAN
RETURN 1
END TRY
BEGIN CATCH
ROLLBACK TRAN
SELECT ERROR_NUMBER()[ERROR NUMBER],ERROR_LINE()[ERROR IN LINE],ERROR_PROCEDURE()[ERROR IN PROCEDURE],ERROR_MESSAGE()[ERROR

MESSAGE]
RETURN 0
END CATCH



END
ELSE
BEGIN
-- Insert

BEGIN TRY
BEGIN TRAN

insert query

COMMIT TRAN
RETURN 1
END TRY
BEGIN CATCH
ROLLBACK TRAN
SELECT ERROR_NUMBER()[ERROR NUMBER],ERROR_LINE()[ERROR IN LINE],ERROR_PROCEDURE()[ERROR IN PROCEDURE],ERROR_MESSAGE()[ERROR

MESSAGE]
RETURN 0
END CATCH



END

do not print 'PRINT BUTTON ' on printed copy page

Steps .

1. Create a CSS
like
.print
{
dsplay:none;
}

2. Apply that CSS on those control which u dont want to print while printing

3. Add the refernce of style sheet file. in this case u have to set the media="print"

[link rel="stylesheet" type="text/css" href="Retailer/CSS/StyleSheet2.css" media="print"

/]

Thanks
HelpOnDesk Team

Why should I switch to CDOSYS when my current CDONTS code works great? send mail from cdosys and cdonts

Some time our emails bounce from SMTP SERVER. when i analysis the problem i got three way to send mail. with free SMTP SERVER like gmail. etc server OR USING CDOSYS OR CDONTS. BUT the question: "Why should I switch to CDOSYS when my current CDONTS code works great?". Let me give a few reasons:

* CDONTS has been deprecated in IIS5 and is completely removed from Windows Server 2003, and even Windows XP. Yes, it is

possible to install on Windows Server 2003 but with the performance improvements and other enhancements, there should be no

need to do so.
* CDOSYS carries less overhead than CDONTS.
* HTML functionality is much improved with automatic generation of the TextBody by just setting the HTMLBody property.
* There are some new properties and methods that should have been included with CDONTS but weren't.

in my earlier post i already explain the code of send mail via gmail server so now we will focus on.

USE CDONTS.DLL


STEP 1) AS WE DESCRIBED ABOVE THAT CDONTS.DLL ARE NO MORE OVER IN WINDOW FOLDER SO CONFIGURE IT WHITH THIS WAY

Start + Run, regsvr32 c:\cdonts.dll
OR
Start + Run + cmd,
in command type and run

]regsvr32 [path for dll]

now add refference of cdonts.dll

CDONTS.NewMail mailsend1 = new CDONTS.NewMail();

string From = "helpondesk@blogspot.com";
string Subject = "xxxxxxxxxxxxxxxxxxxxxx";
string Body = "[html][body][table border=0 cellpading=0 cellspacing=0][tr][td]hi from

cdonts[/td][/tr][/table][/body][/html]";
string To = "helpondesk@blogspot.com";
mailsend1.BodyFormat = 0;
mailsend1.MailFormat = 0;
mailsend1.Importance = Convert.ToInt32(CDONTS.CdoImportance.CdoHigh);
mailsend1.Send(From, To, Subject, Body, 1);

how to implement second dll CDOSYS

we can also configure cdosys dll with same way as codonts.dll

using System.Web.Mail;

MailMessage eMail = new MailMessage();
eMail.To = "helpondesk@blogspot.com";

eMail.Subject = " 2222222222";
eMail.Body = "[html][table][tr][td]HI THIS MAIL FROM CDOSYS SO HOW ARE YOU[/td][/tr][/table]";
// Smtp configuration
eMail.From = "helpondesk@blogspot.com";
eMail.Fields.Add(CDO.CdoConfiguration.cdoSMTPAuthenticate, "1");
eMail.Fields.Add(CDO.CdoConfiguration.cdoSendUserName, "helpondesk@blogspot.com");
eMail.Fields.Add(CDO.CdoConfiguration.cdoSendPassword, "mypwd");
SmtpMail.SmtpServer = "smpt.domain.com";
eMail.BodyFormat = MailFormat.Html;
SmtpMail.Send(eMail);


Thanks
HelpOnDesk Team

Thursday, January 1, 2009

Using PayPal Pro With ASP.Net application

Hi Everybody..
"How to use PayPal Pro Method in Asp.Net 2.0 web Application", this is topic for today which, I want to add as my latest post .I hope all of you are well aware of this.Yet I am adding this for quick reference.
You can also take an idea from HERE .
You have to add the following code in your page and modified it as per your need...


protected void Page_Load(object sender, EventArgs e)
{
// Do Your Other Task Here...
UpdatePaymentStatus();
}
protected void UpdatePaymentStatus()
{
#region Paypal Return
try
{
string status = GetSuccessStatus();
if (status != null && status != string.Empty)
{
if (status.Contains("success"))
{
// Do Your DatBase related things ag save the transaction details in DB
// for eg: userID ,Unit Price,And Total Amount or anyother thing as needed
}
if (status.Contains("failed"))
{
// do as per your Logic
}
}
}
catch (Exception Ex)
{
Session["errorMessage"] = Ex.Message.ToString();
//Response.Redirect("index.aspx");
}
#endregion
}
protected void ImgPayMent_Click(object sender, ImageClickEventArgs e)
{
amount = Convert.ToDouble(lblPrice.Text);
string redirect = "";

//redirect += "https://www.paypal.com/cgi-bin/webscr";
redirect += "https://www.sandbox.paypal.com/cgi-bin/webscr";
redirect += "?cmd=_xclick";
redirect += "&business=books._1235082065_biz@gmail.com ";
//Where abc@youdomain.com is Merchant account ID
redirect += "&item_name=" + "My Testing Purpose";
redirect += "&item_number=1";
redirect += "&amount=" + String.Format("{0:0.00} ", amount);// This is amount Double Type
redirect += "&currency_code=USD";
redirect += "&no_shipping=1";
redirect += "&no_note=1";
redirect += "&return=http://HomeUrlOfSite/Purchase.aspx/success/";
redirect += "&cancel_return=http://HomeUrlOfSite/Purchase.aspx/failed/"
Response.Redirect(redirect);
}
protected string GetSuccessStatus()
{
if (Request.PathInfo.Length == 0)
return "";
else if (Request.PathInfo.Contains("success"))
return "success";
else if (Request.PathInfo.Contains("failed"))
return "failed";
return "";
}
}

Thanks:...
Sanjeev Kumar
HelpOnDesk Team