Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Online Payment With ASP.NET Sites

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Just Me - 25 Sep 2007 15:41 GMT
Hi,

OK, Ive been asked to provide a public site with a means of selling some
products, I have never done this before, so im a bit of a newbie really.
What I am looking for is a method of acheiving this within the ASP.NET
develpment arena,

Byt which I dont mean that I want to design a shopping cart system, I want a
low impact , low cost if possible way of being able to set up my products
and sell them using a third party like worldpay etc.

I know that there are dummy option button bits of  HTML they can give you,
but I want something a bit slicker. In essence, I need to be able to allow
my customer to sell downloadable products on line such as white papers,
reports, e-books etc. Does anyone know of a good method of doing this.

Cheers
Larry Bud - 25 Sep 2007 16:08 GMT
> Hi,
>
[quoted text clipped - 11 lines]
> my customer to sell downloadable products on line such as white papers,
> reports, e-books etc. Does anyone know of a good method of doing this.

I don't see how you can do this without a shopping cart, unless you
plan on a lot of manual processing.  I mean, in simplest forms, a user
could send you money via PayPal, then you e-mail him the file.

So what's wrong with a shopping cart?  Click on the docs you want,
Check Out, and Pay.  Once payment is verified, you can give the user a
temporary download link that contains a ZIP of all the docs he bought.
Mark Rae [MVP] - 25 Sep 2007 16:14 GMT
> I don't see how you can do this without a shopping cart, unless you
> plan on a lot of manual processing.  I mean, in simplest forms, a user
[quoted text clipped - 3 lines]
> Check Out, and Pay.  Once payment is verified, you can give the user a
> temporary download link that contains a ZIP of all the docs he bought.

I agree - a shopping cart is definitely the way to go here...

Not only that, it's what potential customers will be expecting to see, and
are already familiar with...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Just Me - 25 Sep 2007 16:21 GMT
Who said, I didnt want a shopping cart ????

What I said was I dont want to 'Design' a shopping cart. Im looking for
something what has already been designed but will fit into the asp.net
development aread.

;-)

>> I don't see how you can do this without a shopping cart, unless you
>> plan on a lot of manual processing.  I mean, in simplest forms, a user
[quoted text clipped - 8 lines]
> Not only that, it's what potential customers will be expecting to see, and
> are already familiar with...
Mark Rae [MVP] - 25 Sep 2007 16:29 GMT
> What I said was I dont want to 'Design' a shopping cart. Im looking for
> something what has already been designed but will fit into the asp.net
> development aread.

PayPal has an ASP.NET shopping card, but it's fairly awful...

I designed my own - took about half an hour...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Just Me - 25 Sep 2007 17:20 GMT
You must feel great being so competent, but it doesent help me much.

Dont worry, I'll research it and find an answer myself.

>> What I said was I dont want to 'Design' a shopping cart. Im looking for
>> something what has already been designed but will fit into the asp.net
[quoted text clipped - 3 lines]
>
> I designed my own - took about half an hour...
Mark Rae [MVP] - 25 Sep 2007 17:45 GMT
> You must feel great being so competent, but it doesent help me much.

Didn't mean to sound dismissive - judging from your previous posts in this
newsgroup, you're clearly not a beginner, and this is most definitely not
beyond your abilities in any way...

At a basic level, it is simply a matter of storing a Dictionary<int, int>
object in Session

The first element of the Dictionary is the unique product identifier and the
second is the number of units that the customer has decided to purchase

Starting with that, the rest of it pretty much writes itself...

When the customer adds an item to their cart, it checks whether that product
id already exists in the Dictionary. If no, it adds it with a count of 1. If
yes, it increments the count by 1. Same process but in reverse if the
customer chooses to remove (or decrement the amount) of an item.

The checkout page uses the Session["cart"] object to fetch more detail about
the item(s), and adds stuff like VAT / sales tax, region etc.

When the user clicks the Checkout button, a PayPal form is built in the
background and then the whole thing redirects to the PayPal site, which
takes over from there.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Just Me - 25 Sep 2007 17:53 GMT
Mark,

Thanks for your reply. I dont actually have an issue with working out how to
select , store, pick etc from a list of choices. Perhaps I could have been
clearer in my question and thinking it through as I write this; undoubtedly
this is true, if I had put more thought into what I was trying to get from
an answer, I would not have left ambiguity in my question and wasted
everyones time including my own, for that I apologise.

I am interested in the building of the html page/form in the background for
submission as you refer to, if you have an example of this, i would be very
grateful, im sure I can work it out myself, but I would nevertheless like to
see how you did it.

Thank you.

>> You must feel great being so competent, but it doesent help me much.
>
[quoted text clipped - 23 lines]
> background and then the whole thing redirects to the PayPal site, which
> takes over from there.
Mark Rae [MVP] - 25 Sep 2007 18:05 GMT
> I am interested in the building of the html page/form in the background
> for submission as you refer to, if you have an example of this, i would be
> very grateful, im sure I can work it out myself, but I would nevertheless
> like to see how you did it.

This will only work for PayPal, obviously, but several other payment
gateways have similar mechanisms:

private void BindData()
{
 Dictionary<string, byte> dicCart = (Dictionary<string,
byte>)Session["dicCart"];
 string strPayPalForm;
 DataRow objRow = null;
 LinkButton lnkRemove;
 decimal curItemTotal = 0;
 decimal curSubTotal = 0;
 decimal curShipping = 0;
 decimal curShippingTotal = 0;
 decimal curTotal = 0;

 try
 {
  if(dicCart.Count == 0)
  {
   tblCart.Visible = false;
               ClientScript.RegisterStartupScript(GetType(), "emptyCart",
"alert('There are no items in your shopping
cart');window.location='default.aspx';", true);
  }
  else
  {
   tblCart.Visible = true;

   strPayPalForm = String.Empty;

               strPayPalForm += "<form target=\"paypal\" id=\"frmPayPal\"
action=\"" +
System.Configuration.ConfigurationManager.AppSettings["PayPalURL"] + "\"
method=\"post\">\r\n";
   strPayPalForm += "\t<input type=\"hidden\" name=\"cmd\" value=\"_cart\"
/>\r\n";
   strPayPalForm += "\t<input type=\"hidden\" name=\"upload\" value=\"1\"
/>\r\n";
               strPayPalForm += "\t<input type=\"hidden\" name=\"business\"
value=\"" +
System.Configuration.ConfigurationManager.AppSettings["PayPalAccount"] + "\"
/>\r\n";
   strPayPalForm += "\t<input type=\"hidden\" name=\"currency_code\"
value=\"GBP\" />\r\n";

   using (DataSet objDS = new DataSet())
   {
    objDS.ReadXml(Request.PhysicalApplicationPath +
"\\App_Data\\merch.xml");
    DataColumn[] objPK = new DataColumn[1];
    objPK[0] = objDS.Tables[0].Columns["id"];
    objDS.Tables[0].PrimaryKey = objPK;

    int intItem = 1;

    foreach (KeyValuePair<string, byte> kvpItem in dicCart)
    {
     objRow = objDS.Tables[0].Rows.Find(kvpItem.Key);

     using (TableRow objTR = new TableRow()) // create a new row
     {
      // item -----------------------------------------------------
      using (TableCell objTD = new TableCell())
      {
       objTD.Text = objRow["item_type"].ToString();
       objTD.HorizontalAlign = HorizontalAlign.Left;
       objTR.Cells.Add(objTD);
      }

      // description ----------------------------------------------
      using (TableCell objTD = new TableCell())
      {
       objTD.Text = objRow["item_description"].ToString();
       objTD.HorizontalAlign = HorizontalAlign.Left;
       objTR.Cells.Add(objTD);
      }
      strPayPalForm += "<input type=\"hidden\" name=\"item_name_" +
intItem.ToString() + "\" value=\"" + objRow["item_description"].ToString() +
"\" />\r\n";

      // quantity -------------------------------------------------
      using (TableCell objTD = new TableCell())
      {
       objTD.Controls.Add(new LiteralControl(kvpItem.Value.ToString() +
"&nbsp;"));
       lnkRemove = (LinkButton)pnlCart.FindControl("lnkRemove_" +
kvpItem.Key);
       lnkRemove.Visible = true;
       if (kvpItem.Value == 1)
       {
        lnkRemove.ToolTip = "Remove this item from your shopping cart";
       }
       else
       {
        lnkRemove.ToolTip = "Reduce the quantity of this item";
       }
       objTD.Controls.Add(lnkRemove);
       objTD.HorizontalAlign = HorizontalAlign.Right;
       objTR.Cells.Add(objTD);
      }
      strPayPalForm += "<input type=\"hidden\" name=\"quantity_" +
intItem.ToString() + "\" value=\"" + kvpItem.Value.ToString() + "\" />\r\n";

      // unit cost ------------------------------------------------
      using (TableCell objTD = new TableCell())
      {
       objTD.Text = objRow["item_cost"].ToString();
       objTD.HorizontalAlign = HorizontalAlign.Right;
       objTR.Cells.Add(objTD);
      }
      strPayPalForm += "<input type=\"hidden\" name=\"amount_" +
intItem.ToString() + "\" value=\"" + objRow["item_cost"].ToString() + "\"
/>\r\n";

      // total cost -----------------------------------------------
      curItemTotal = Convert.ToDecimal(Convert.ToDecimal(kvpItem.Value) *
Convert.ToDecimal(objRow["item_cost"].ToString()));
      curSubTotal += curItemTotal;
      switch (cmbShipping.SelectedValue)
      {
       case "1":  // UK
       {
        curShipping = Convert.ToDecimal(objRow["item_ship_uk"].ToString());
        strPayPalForm += "<input type=\"hidden\" name=\"shipping_" +
intItem.ToString() + "\" value=\"" + curShipping.ToString() + "\" />\r\n";
        if (kvpItem.Value > 1)
        {
         strPayPalForm += "<input type=\"hidden\" name=\"shipping2_" +
intItem.ToString() + "\" value=\"" + curShipping.ToString() + "\" />\r\n";
        }
        curShippingTotal +=
Convert.ToDecimal(Convert.ToDecimal(kvpItem.Value) * curShipping);
        break;
       }
       case "2":  // EU
       {
        curShipping =
Convert.ToDecimal(objRow["item_ship_europe"].ToString());
        strPayPalForm += "<input type=\"hidden\" name=\"shipping_" +
intItem.ToString() + "\" value=\"" + curShipping.ToString() + "\" />\r\n";
        if (kvpItem.Value > 1)
        {
         strPayPalForm += "<input type=\"hidden\" name=\"shipping2_" +
intItem.ToString() + "\" value=\"" + curShipping.ToString() + "\" />\r\n";
        }
        curShippingTotal +=
Convert.ToDecimal(Convert.ToDecimal(kvpItem.Value) * curShipping);
        break;
       }
       case "3":  // rest of world
       {
        curShipping =
Convert.ToDecimal(objRow["item_ship_world"].ToString());
        strPayPalForm += "<input type=\"hidden\" name=\"shipping_" +
intItem.ToString() + "\" value=\"" + curShipping.ToString() + "\" />\r\n";
        if (kvpItem.Value > 1)
        {
         strPayPalForm += "<input type=\"hidden\" name=\"shipping2_" +
intItem.ToString() + "\" value=\"" + curShipping.ToString() + "\" />\r\n";
        }
        curShippingTotal +=
Convert.ToDecimal(Convert.ToDecimal(kvpItem.Value) * curShipping);
        break;
       }
      }
      using (TableCell objTD = new TableCell())
      {
       objTD.Text = curItemTotal.ToString("#,##0.00");
       objTD.HorizontalAlign = HorizontalAlign.Right;
       objTR.Cells.Add(objTD);
      }

      tblCart.Rows.AddAt(intItem, objTR); // add the row to the table
     }
     intItem++;
    }
   }

   lblShipping.Text = curShippingTotal.ToString("#,##0.00");
   curTotal = curSubTotal + curShippingTotal;
   lblTotal.Text = curTotal.ToString("#,##0.00");
   strPayPalForm += "<input type=\"button\" value=\"Continue shopping\"
onclick=\"location.href='default.aspx';\" />\r\n";
   strPayPalForm += "&nbsp;\r\n";
   strPayPalForm += "<input type=\"submit\" value=\"Proceed to checkout\"
onclick=\"return submitPayPal();\" />";

   strPayPalForm += "</form>";
   ((Literal)Master.FindControl("litAdditional")).Text =
strPayPalForm.Replace("\r\n", String.Empty);
  }
 }
 catch (Exception ex)
 {
  CApplication.GlobalExceptionHandler(ex);
 }
}

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Just Me - 25 Sep 2007 19:21 GMT
Many thanks for that.

I will digest it, and attempt to use it.

Regards

>> I am interested in the building of the html page/form in the background
>> for submission as you refer to, if you have an example of this, i would
[quoted text clipped - 201 lines]
>  }
> }
sloan - 25 Sep 2007 21:20 GMT
You might want to check out the
http://www.asp.net/downloads/starter-kits/paypal-ecommerce/

if you want minimal coding effort.

Remember, the key word in "Starter Kit" is "Starter", and not "Complete
Solution".

> Hi,
>
[quoted text clipped - 13 lines]
>
> Cheers

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.