protected void Page_Load(object sender, EventArgs e) { // Do we have any special handling? PayPalNavigation nav = new PayPalNavigation(Request.QueryString); switch (nav.GatewayExit.ToUpper()) { case "CANCEL": { InvokePaymentCancelled(); CheckoutControl.Hide(); pnlProceedToPayPal.Visible = false; return; } case "RETURN": { PayPalIPNParameters ipn = new PayPalIPNParameters(Request.Form, Request.BinaryRead(Request.ContentLength)); // Here there is no check about the validity of the PayPal response (IPN), // because it's just a message displayed to the customer. // Everything is checked in the NOTIFY case received from PayPal in the PayPalIPN.aspx page. switch (ipn.payment_status.ToLower()) { case "completed": InvokePaymentSucceeded(); break; default: InvokePaymentRequiresConfirmation(); break; } CheckoutControl.Hide(); pnlProceedToPayPal.Visible = false; return; } } if (nav.GatewayExit.Length > 0) { //If the PayPalExit is anything else with length > 0, then don't do any processing HttpContext.Current.Response.Redirect(Common.Globals.NavigateURL(PortalSettings.ActiveTab.TabID), false); return; } // Continue with display of payment control... if (Page.IsPostBack == false) { PayPalSettings settings = new PayPalSettings(StoreSettings.GatewaySettings); if (!settings.IsValid()) { lblError.Text = Localization.GetString("GatewayNotConfigured", LocalResourceFile); lblError.Visible = true; pnlProceedToPayPal.Visible = false; return; } SurchargePercent = settings.SurchargePercent; SurchargeFixed = settings.SurchargeFixed; btnConfirmOrder.Attributes.Add("OnClick", ScriptAvoidDoubleClick(btnConfirmOrder, Localization.GetString("Processing", this.LocalResourceFile))); string message = Localization.GetString("lblConfirmMessage", LocalResourceFile); lblConfirmMessage.Text = string.Format(message, PortalSettings.PortalName); message = Localization.GetString("paypalimage", LocalResourceFile); paypalimage.AlternateText = message; lblError.Text = string.Empty; lblError.Visible = false; paypalimage.ImageUrl = settings.ButtonURL; } }
private void ConfirmOrder() { Page.Validate(); if (Page.IsValid == false) { return; } // Adds order to db... OrderInfo order = CheckoutControl.GetFinalizedOrderInfo(); IAddressInfo billingAddress = CheckoutControl.BillingAddress; GenerateOrderConfirmation(); CheckoutControl.Hide(); pnlProceedToPayPal.Visible = false; // Set order status to "Awaiting Payment"... CheckoutControl.Order = UpdateOrderStatus(order, OrderInfo.OrderStatusList.AwaitingPayment); // Clear basket CurrentCart.DeleteCart(PortalId, StoreSettings.SecureCookie); // Clear cookies ClearOrderIdCookie(); // Process transaction string url; string urlAuthority = Request.Url.GetLeftPart(UriPartial.Authority); TransactionDetails transaction = new TransactionDetails(); PayPalNavigation nav = new PayPalNavigation(Request.QueryString) { OrderID = order.OrderID, GatewayExit = "return" }; url = nav.GetNavigationUrl(); if (url.StartsWith(urlAuthority) == false) { url = urlAuthority + url; } transaction.ReturnURL = url; nav.GatewayExit = "cancel"; url = nav.GetNavigationUrl(); if (url.StartsWith(urlAuthority) == false) { url = urlAuthority + url; } transaction.CancelURL = url; string language = Request.QueryString["language"]; if (string.IsNullOrEmpty(language)) { language = System.Threading.Thread.CurrentThread.CurrentCulture.ToString(); } transaction.NotifyURL = urlAuthority + TemplateSourceDirectory + "/PayPalIPN.aspx?language=" + language; string message = Localization.GetString("PayPalReturnTo", LocalResourceFile); transaction.Cbt = string.Format(message, PortalSettings.PortalName); transaction.Email = billingAddress.Email; PayPalGatewayProvider provider = new PayPalGatewayProvider(StoreSettings.GatewaySettings); provider.ProcessTransaction(CheckoutControl.BillingAddress, order, transaction); }