Solved

Implementing a paypal with a custom built shopping cart

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn about the eCommerce marketing trends for the year ahead.
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…

821 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