There are a lot of modifications needed in the paypal provider, and to be honest I don't remember what the original code looked like so I can't explicity list the "changes" you need to make.
I decided to implement a POST rather than a GET, which means an extra page in the payment process, the content of this extra page is a thank you message followed by an invitaion to procedd to paypal.
I used the PayPal developers guide to get the correct field names that need to be in the page, the result of which is this method, which outputs paypal data to the new page:
private void SetupPayPalFields() { IAddressInfo shippingAddress = CheckoutControl.ShippingAddress; IAddressInfo billingAddress = CheckoutControl.BillingAddress;
OrderInfo orderInfo = CheckoutControl.GetOrderDetails();
//Set the paypal url as form target btnContinue.PostBackUrl = _paymentURL;
string returnURL = Request.Url + "&PayPalExit=return"; string cancelURL = Request.Url + "&PayPalExit=cancel"; string notifyURL = Request.Url + "&PayPalExit=notify";
AddHiddenField("cmd", "_cart"); AddHiddenField("upload", "1"); AddHiddenField("business", _settings.PayPalID); AddHiddenField("handling_cart", orderInfo.ShippingCost.ToString("0.00")); AddHiddenField("currency_code", _settings.Currency); AddHiddenField("invoice", orderInfo.OrderID.ToString()); AddHiddenField("return", returnURL); AddHiddenField("cancel_return", cancelURL); AddHiddenField("notify_url", notifyURL); AddHiddenField("rm", "2"); AddHiddenField("lc", "GB"); AddHiddenField("cbt", "Back to " + PortalSettings.PortalName);
//Tax... if (orderInfo.Tax > 0) { AddHiddenField("tax_cart", orderInfo.Tax.ToString("0.00")); }
//Cart Contents... ArrayList cartItems = CurrentCart.GetItems(PortalId); int itemNumber = 1; foreach (ItemInfo itemInfo in cartItems) { AddHiddenField("item_name_" + itemNumber.ToString(), itemInfo.Manufacturer + (itemInfo.Manufacturer.Length > 0 ? " " : "") + itemInfo.ModelName); AddHiddenField("quantity_" + itemNumber.ToString(), itemInfo.Quantity.ToString()); AddHiddenField("amount_" + itemNumber.ToString(), itemInfo.UnitCost.ToString("0.00")); itemNumber++; }
//Customer Address... AddHiddenField("email", UserInfo.Membership.Email); AddHiddenField("first_name", GetFirstName(billingAddress.Name)); AddHiddenField("last_name", GetSurname(billingAddress.Name)); AddHiddenField("address1", billingAddress.Address1); AddHiddenField("address2", billingAddress.Address2); AddHiddenField("city", billingAddress.City); AddHiddenField("zip", billingAddress.PostalCode); AddHiddenField("country", (billingAddress.CountryCode.Equals("United Kingdom") ? "GB" : billingAddress.CountryCode));
AddHiddenField("business_cs_email", UserInfo.Membership.Email); AddHiddenField("business_address1", billingAddress.Address1); AddHiddenField("business_address2", billingAddress.Address2); AddHiddenField("business_city", billingAddress.City); AddHiddenField("business_zip", billingAddress.PostalCode); AddHiddenField("business_country", billingAddress.CountryCode); }
private void AddHiddenField(string name, string value) { System.Web.UI.HtmlControls.HtmlInputHidden htmlHidden = new System.Web.UI.HtmlControls.HtmlInputHidden(); htmlHidden.ID = name; htmlHidden.Name = name; htmlHidden.Value = value; Page.Form.Controls.Add(htmlHidden); }
You'll need to handle the return from paypal too, and will also have to add a "go to paypal" button which posts the form to the paypal url (btnContinue in the example code above).
There are likely more issues that I've forgotten about, please take this as a starting point rather than an exaustive solution.
|