Solved

Implementing a paypal with a custom built shopping cart

Posted on 2011-09-10
3
559 Views
Last Modified: 2012-05-12
Hi

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)
    {
        Page.Validate();
        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;

            //redirect
            Response.Redirect("PayPalProcessing.aspx");
        }
    }

On PaypalProcessing.aspx....

Code Behind
private Invoice _selectedInvoice = new Invoice();
    public Invoice SelectedInvoice
    {
        get
        {
            if (_selectedInvoice.InvoiceId == "")
            {
                try
                {
                    _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 -->
			<%=SelectedInvoice.PaypalItemList%>
			<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" />
		</form>
		<%=SelectedInvoice.ToString() %>

Open in new window

0
Comment
Question by:jazz__man
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Friman001
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.
0
 
LVL 4

Expert Comment

by:Friman001
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!
0
 
LVL 10

Accepted Solution

by:
CSIPComputing earned 500 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.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now