Solved

Implementing a paypal with a custom built shopping cart

Posted on 2011-09-10
3
557 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Pdf to Mobi 1 29
Hovering effect 9 29
Asp.net mvc entity issue 6 20
What .NET website keeps me current? 9 31
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

18 Experts available now in Live!

Get 1:1 Help Now