Click here to Skip to main content
Full site     10M members (34.2K online)    

ASP.NET and Paypal with Dynamic Ordering Values

Scenarios

Today, in this article I will show you how to integrate Paypal ordering with dynamic values into an Asp.net website using C# and Master page.

You can find many articles on the internet with the same contents posted by someone to guide you how to integrate/implement Paypal into your website. However, almost of those posts only aim to introduce the basic concepts related to paypal.

When starting to research this issue, I also consult many sources on the internet, but I cannot find the contents as my expectations. In addition, I see many people have troubles while working with this issue. Therefore, I have taken the time to write an article to guide all of you How to combine Paypal into Asp.Net website in the best way and easiest to understand.

In this article, instead of aiming to the concepts and theories about Paypal, I will only focus on the development.  

Step 1: Create your Master page.

Step 2: Create a Default page. In this page will display a list of products which you want to sell and integrate Paypal payment.

In this demo, I will provide hardcode data for the products. So, when you use this my demo as your reference then then function to provide dynamic product’s data need to be changed. This is an easy task as I knowJ.

Once your ordering data is ready then you are able to submit your order. Next to step 3 for more detail.

Step 3: When you submit your order in step 2, then the system will redirect you to a page called as PaypalProcess. In this page, we will work with paypal controls and assign the values to them before your order is processing.

Normally, we have controls with name as “cmd, business, item_name, item_number, amount, no_shipping, quantity”. Maybe, it still has other controls, but I think with these items are enough for our purposes.

Step 4: What codes to be needed to have?   

public class PaypalEntity
{ 
public string Business { get; set; }
public string ItemName { get; set; }
public string ItemNumber { get; set; }
public string Amount { get; set; }
public string NoShipping { get; set; }
public string Quantity { get; set; }
} 

Front code:  

<form id="frmPaypal" method="post" action="https://www.paypal.com/cgi-bin/webscr" runat="server">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="<%= this.BusinessValue %>" />
<input type="hidden" name="item_name" value="<%= this.ItemNameValue %>" />
<input type="hidden" name="item_number" value="<%= this.ItemNumberValue %>" />
<input type="hidden" name="amount" value="<%= this.AmountValue %>" />
<input type="hidden" name="no_shipping" value="<%= this.NoShippingValue %>" />
<input type="hidden" name="quantity" value="<%= this.QuantityValue %>" />
</form>  

Behind code

public partial class PaypalProcess : System.Web.UI.Page
{
PaypalEntity pe = new PaypalEntity();        
protected string BusinessValue { get; set; }
protected string ItemNameValue { get; set; }
protected string ItemNumberValue { get; set; }
protected string AmountValue { get; set; }
protected string NoShippingValue { get; set; }
protected string QuantityValue { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
pe = (PaypalEntity)Session["myOrderingEntity"];
this.BusinessValue = pe.Business;
this.ItemNameValue = pe.ItemName;
this.ItemNumberValue = pe.ItemNumber;
this.AmountValue = pe.Amount;
this.NoShippingValue = pe.NoShipping;
this.QuantityValue = pe.Quantity;
}
}
}

Hope that help everyone, who is looking for the help this issue! Smile | :)  

Happy coding.  

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search 
Per page   
-- There are no messages in this forum --

Last Updated 13 May 2013 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2013