Jun 04 2007

Implementation step 4

Posted by admin under Commerce and payment

ALL ARTICLES IN THIS SERIE

But instead we are getting redirected to shopckeckout.aspx. Here's the secret on how to make the whole shopping cart available to Paypal.

Buy posting multiple form fields (named after a certain scheme) we can send the whole shopping cart to Paypal.:

item_name_1
item_number_1
amount_1
quantity_1

item_name_2
item_number_2
amount_2
quantity_2

etc

So we create those form fields by using server side code - with values from the current shopping cart of course:



	<BODY onload="document.payment_provider_form.submit()">
				<h2>Please wait while redirecting to Paypal for payment </h2>
		<form name="payment_provider_form" method="post" action="https://www.paypal.com/cgi-bin/webscr">
			<br>
			<br>
			Click here is nothing happens... <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit"
				alt="Make payments with PayPal - it's fast, free and secure!"> <input name="business" type="hidden" value="stefan.holmberg@systementor.se">
			<input name="cmd" type="hidden" value="_cart"> <input name="upload" type="hidden" value="1">
			<input name="rm" type="hidden" value="2"> <input name="no_shipping" type="hidden" value="1">
			<input name="no_note" type="hidden" value="1"> <input name="cs" type="hidden" value="0">
			<input name="currency_code" type="hidden" value="USD">
			<asp:PlaceHolder id="plHej" runat="server"></asp:PlaceHolder>
		</form>
				

</body>





            foreach (ObjClasses.ShoppingCartItem oItem in ObjClasses.ShoppingCart.GetCurrentUsersCart)
            {
                //Rabatt
                if (oItem.PerPrice < 0)
                    continue;

                string sTxt = oItem.PrArticle.PaypalID;
                sTxt += " " + oItem.PrArticle.Name;

                //Apply discount
                double dPerPrice = oItem.PerPrice;

                double dTotalPrice = dPerPrice * oItem.Count;

                sAdd = "<input name=\"item_name_" + nCount.ToString() + "\" type=\"hidden\" value=\"" + sTxt + "\"> ";
                plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
                sAdd = "<input name=\"item_number_" + nCount.ToString() + "\" type=\"hidden\" value=\"" + oItem.PrArticle.PaypalID + "\"> ";
                plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));

                sAdd = "<input name=\"amount_" + nCount.ToString() + "\" type=\"hidden\" value=\"" + dPerPrice.ToString("0.00").Replace(",", ".") + "\"> ";
                plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
                sAdd = "<input name=\"quantity_" + nCount.ToString() + "\" type=\"hidden\" value=\"" + (oItem.Count).ToString() + "\"> ";
                plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));
                nCount++;
            }
            nCount--;
            sAdd = "<input name=\"num_cart_items\" type=\"hidden\" value=\"" + nCount.ToString() + "\"> ";
            plHej.Controls.Add(new System.Web.UI.LiteralControl(sAdd));




And that's it. Please download the whole solution - it's hard to explain in words but considering the whole solution is contained in 4 small files, I bet/hope you will be able to get a grip on how to use it pretty soon.


Attachments