Implementing a paypal with a custom built shopping cart

Posted on 2011-09-10
Medium Priority
Last Modified: 2012-05-12

I have developed my ecommerce website in asp.net which has its own custom shopping cart. Having read quite a bit about web payments standard it appears that you submit data using a form tag for processing your data at the paypal end.

I found an example of this process online which incidently does not work but there is enough code to demonstrate the process.

My Question is this.
If a user has filled up my shopping cart with say 5 items and different quantities how would I send this to paypal? If I bundle the items up under one title and send this as one transaction how will I know what items my customer has bought? My problem is, without capturing customer details I cannot store orders so how does this work?

On checkout.aspx.....
protected void btnPaypalCheckout_Click(object sender, EventArgs e)
        if (Page.IsValid)
            //store data
            SelectedInvoice.ContactName = this.txtBillingName.Text;
            SelectedInvoice.ContactPhone = this.txtBillingPhone.Text;
            SelectedInvoice.ContactEmail = this.txtBillingEmail.Text;

            SelectedInvoice.ContactAddress1 = this.txtBillingAddress1.Text;
            SelectedInvoice.ContactAddress2 = this.txtBillingAddress2.Text;
            SelectedInvoice.ContactCity = this.txtBillingCity.Text;
            SelectedInvoice.ContactStateProvince = this.cboBillingState.SelectedValue;
            SelectedInvoice.ContactZip = this.txtBillingZip.Text;

            SelectedInvoice.ShipToAddress1 = this.txtShipToAddress1.Text;
            SelectedInvoice.ShipToAddress2 = this.txtShipToAddress2.Text;
            SelectedInvoice.ShipToCity = this.txtShipToCity.Text;
            SelectedInvoice.ShipToStateProvince = this.cboShipToState.SelectedValue;
            SelectedInvoice.ShipToZip = this.txtShipToZip.Text;

            SelectedInvoice.CustomerComments = this.txtCustomerComments.Text;

            Session["Invoice"] = SelectedInvoice;


On PaypalProcessing.aspx....

Code Behind
private Invoice _selectedInvoice = new Invoice();
    public Invoice SelectedInvoice
            if (_selectedInvoice.InvoiceId == "")
                    _selectedInvoice = (Invoice)Session["Invoice"];
                catch { }               
            return _selectedInvoice;

HTML Section
<!-- item_number should get passed back -->
		<form id="Paypal" name="Paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
			<input type="hidden" name="cmd" value="_cart" />
			<input type="hidden" name="upload" value="1" />
			<!-- The following is for aggregated PayPal data instead of itemized -->
			<input type="hidden" name="item_name" value="Aggregated Items" />
			<input type="hidden" name="amount" value="<%=SelectedInvoice.Total.ToString("#.00") %>" />
			<!-- The following is for itemized PayPal data instead of the aggregated version -->
			<input type="hidden" name="tax_cart" value="<%=SelectedInvoice.Taxes.ToString("#.00")%>" />
			<!-- STANDARD DATA -->
			<input type="hidden" name="business" value="<%=System.Web.Configuration.WebConfigurationManager.AppSettings["paypalAccount"] %>" />
			<input type="hidden" name="invoice" value="<%=SelectedInvoice.InvoiceId.ToString()%>" />
			<input type="hidden" name="no_note" value="0" /> 
			<input type="hidden" name="currency_code" value="<%=SelectedInvoice.Currency %>" />
			<input type="hidden" name="lc" value="<%=SelectedInvoice.ShipToCountry %>" /> 
			<input type="hidden" name="return" value="<%=System.Web.Configuration.WebConfigurationManager.AppSettings["websiteUrl"] %>/ThankYou.aspx" />
			<input type="hidden" name="cancel_return" value="<%=System.Web.Configuration.WebConfigurationManager.AppSettings["websiteUrl"] %>" />
			<input type="hidden" name="email" value="<%=System.Web.Configuration.WebConfigurationManager.AppSettings["paypalAccount"] %>" /> 
			<input type="hidden" name="cn" value="How did you hear about us?" />
           <input type="submit" value="Submit Payment Info" />
		<%=SelectedInvoice.ToString() %>

Open in new window

Question by:jazz__man
  • 2

Expert Comment

ID: 36516466
I would go to paypal to ask about this.  I would assume they have a way to send data to them.  You could very easily store all the information from your website into a struct and have easy access to it for send, but as far as sending to paypal, I would say that they would have a method to do that.

Expert Comment

ID: 36516474
I really don't see anything to do with the amount of items or what they purchesed in the checkout code behind file or even how much money they spent.  You would need to add fields for the item name, quantity, cost, ect., too!
LVL 10

Accepted Solution

CSIPComputing earned 2000 total points
ID: 36516663
Paypal publishes a full API for this sort of transaction with full 2-way confirmation and handshaking.

This includes a sandbox environment where you can test etc,

Search paypal for IPN the Instant Payment Notification system.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Ecommerce has truly become one of the most prosperous ways of monetizing your brand on the Internet. However, when it comes to it, auditing is undoubtedly the lifeblood of this type of business.  This article will help you to conduct your ecommerce …
There are more than 1000 cryptocurrencies available across the world, but Bitcoin has gained a significant advantage over others. The cryptocurrencies are capitalizing the market with more than $150 billion dollars.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question