예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _portalLanguage = PortalSettings.DefaultLanguage;
            string subject   = Localization.GetString("StoreSystempayGateway", LocalResourceFile, _portalLanguage) + Localization.GetString("IPNInfo", LocalResourceFile, _portalLanguage);;
            string reason    = string.Empty;
            bool   sendEmail = false;

            _settings = new SystempaySettings(StoreSettings.GatewaySettings);
            SystempayIPNParameters ipn = new SystempayIPNParameters(Request.Form, _settings.Certificate);
            // Verify payment with Systempay certificate
            PaymentStatus status = VerifyPayment(ipn);

            // What's the user language?
            _userLanguage = Request.QueryString["language"];
            switch (status)
            {
            case PaymentStatus.Abandoned:
            case PaymentStatus.Canceled:
            case PaymentStatus.Captured:
                break;

            case PaymentStatus.Authorised:
                int portalId = PortalSettings.PortalId;
                // Set order status to "Paid"...
                OrderInfo order = UpdateOrderStatus(ipn.vads_order_id, OrderInfo.OrderStatusList.Paid, _userLanguage);
                // Add User to Product Roles
                OrderController orderController = new OrderController();
                orderController.AddUserToRoles(portalId, order);
                // Add User to Order Role
                StoreInfo storeSetting = StoreController.GetStoreInfo(portalId);
                if (storeSetting.OnOrderPaidRoleID != Null.NullInteger)
                {
                    orderController.AddUserToPaidOrderRole(portalId, order.CustomerID, storeSetting.OnOrderPaidRoleID);
                }
                // Special case request validation
                if (ipn.vads_trans_status == "AUTHORISED_TO_VALIDATE")
                {
                    sendEmail = true;
                }
                break;

            case PaymentStatus.Expired:
            case PaymentStatus.Refused:
            case PaymentStatus.Pending:
                // Inform Store Admin
                sendEmail = true;
                break;

            case PaymentStatus.Unattended:
                // Alert Store Admin
                subject   = Localization.GetString("StoreSystempayGateway", LocalResourceFile, _portalLanguage) + Localization.GetString("IPNAlert", LocalResourceFile, _portalLanguage);
                sendEmail = true;
                break;

            default:
                break;
            }
            // Do we need to send an email to the store admin?
            if (sendEmail)
            {
                string paymentStatus = Localization.GetString("PaymentStatus_" + ipn.vads_trans_status, LocalResourceFile, _portalLanguage);
                if (string.IsNullOrEmpty(paymentStatus))
                {
                    paymentStatus = ipn.vads_trans_status;
                }
                string emailIPN = Localization.GetString("EmailIPN", LocalResourceFile, _portalLanguage);
                string body     = string.Format(emailIPN, ipn.vads_order_id, ipn.vads_trans_id, ipn.vads_page_action, paymentStatus, ipn.vads_auth_result, ipn.vads_payment_error);
                SendEmailToAdmin(subject, body);
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Do we have any special handling?
            SystempayNavigation nav = new SystempayNavigation(Request.QueryString);

            switch (nav.GatewayExit.ToUpper())
            {
            case "CANCEL":
            {
                InvokePaymentCancelled();
                CheckoutControl.Hide();
                pnlProceedToSystempay.Visible = false;
                return;
            }

            case "ERROR":
            case "REFUSED":
            {
                InvokePaymentFailed();
                CheckoutControl.Hide();
                pnlProceedToSystempay.Visible = false;
                return;
            }

            case "RETURN":
            {
                SystempaySettings      settings = new SystempaySettings(StoreSettings.GatewaySettings);
                SystempayIPNParameters ipn      = new SystempayIPNParameters(Request.QueryString, settings.Certificate);
                // Here there is no check about the validity of the Systempay response (IPN),
                // because it's just a message displayed to the customer.
                // Everything is checked in the NOTIFY case received from Systempay in the SystempayIPN.aspx page.
                switch (ipn.vads_trans_status.ToLower())
                {
                case "authorised":
                case "authorised_to_validate":
                    InvokePaymentSucceeded();
                    break;

                default:
                    InvokePaymentRequiresConfirmation();
                    break;
                }
                CheckoutControl.Hide();
                pnlProceedToSystempay.Visible = false;
                return;
            }
            }

            if (nav.GatewayExit.Length > 0)
            {
                //If the SystempayExit 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)
            {
                SystempaySettings settings = new SystempaySettings(StoreSettings.GatewaySettings);
                if (!settings.IsValid())
                {
                    lblError.Text    = Localization.GetString("GatewayNotConfigured", LocalResourceFile);
                    lblError.Visible = true;
                    pnlProceedToSystempay.Visible = false;
                    return;
                }

                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("systempayimage", LocalResourceFile);
                systempayimage.AlternateText = message;
                systempayimage.ImageUrl      = settings.ButtonURL;

                lblError.Text    = string.Empty;
                lblError.Visible = false;
            }
        }
예제 #3
0
        private PaymentStatus VerifyPayment(SystempayIPNParameters ipn)
        {
            bool          restoreStock = false;
            PaymentStatus status       = PaymentStatus.Invalid;
            // Default Alert Reason
            string alertReason = Localization.GetString("InvalidIPN", LocalResourceFile, _portalLanguage);

            // Security cheking: Validate signature with the current certificate
            if (ipn.IsValid)
            {
                // Security checking: is this request come from right Systempay account ID
                if (IsFromSite(ipn.vads_site_id))
                {
                    // Security checking: compares some Systempay fields with order fields
                    alertReason = Localization.GetString("WrongOrderInfos", LocalResourceFile, _portalLanguage);
                    OrderController orderController = new OrderController();
                    OrderInfo       order           = orderController.GetOrder(PortalSettings.PortalId, ipn.vads_order_id);
                    // If this order exist
                    if (order != null)
                    {
                        // Currency MUST BE the same!
                        if (_settings.Currency == ipn.vads_currency)
                        {
                            // Everything looks good, validate the transaction!
                            switch (ipn.vads_trans_status.ToLower())
                            {
                            case "abandoned":
                                restoreStock = true;
                                status       = PaymentStatus.Abandoned;
                                break;

                            case "authorised":
                            case "authorised_to_validate":
                                // Grand Total MUST BE the same!
                                if (Math.Round(order.GrandTotal, 2, MidpointRounding.AwayFromZero) == ipn.vads_amount)
                                {
                                    status = PaymentStatus.Authorised;
                                }
                                break;

                            case "canceled":
                                restoreStock = true;
                                status       = PaymentStatus.Canceled;
                                break;

                            case "captured":
                                // Grand Total MUST BE the same!
                                if (Math.Round(order.GrandTotal, 2, MidpointRounding.AwayFromZero) == ipn.vads_amount)
                                {
                                    status = PaymentStatus.Captured;
                                }
                                break;

                            case "expired":
                                restoreStock = true;
                                status       = PaymentStatus.Expired;
                                break;

                            case "refused":
                                restoreStock = true;
                                status       = PaymentStatus.Refused;
                                break;

                            case "under_verification":
                            case "waiting_authorisation":
                            case "waiting_authorisation_to_validate":
                                // Grand Total MUST BE the same!
                                if (Math.Round(order.GrandTotal, 2, MidpointRounding.AwayFromZero) == ipn.vads_amount)
                                {
                                    status = PaymentStatus.Pending;
                                }
                                break;

                            default:
                                status = PaymentStatus.Unattended;
                                break;
                            }

                            if (restoreStock)
                            {
                                List <OrderDetailInfo> orderDetails = orderController.GetOrderDetails(order.OrderID);
                                if (orderDetails != null)
                                {
                                    foreach (OrderDetailInfo detail in orderDetails)
                                    {
                                        orderController.UpdateStockQuantity(detail.ProductID, detail.Quantity);
                                    }
                                    ProductController productController = new ProductController();
                                    productController.ClearAllCaches();
                                }
                            }
                        }
                    }
                }
                else
                {
                    alertReason = Localization.GetString("DifferentReceiverEmail", LocalResourceFile, _portalLanguage);
                }
            }

            // If the transaction is invalid
            if ((status == PaymentStatus.Invalid) || (status == PaymentStatus.Unattended))
            {
                // Add an Admin Alert to the DNN Log
                string        systempayGateway = Localization.GetString("StoreSystempayGateway", LocalResourceFile, _portalLanguage);
                string        adminAlert       = Localization.GetString("SecurityAlert", LocalResourceFile, _portalLanguage);
                LogProperties properties       = new LogProperties
                {
                    new LogDetailInfo(systempayGateway, adminAlert),
                    new LogDetailInfo(Localization.GetString("AlertReason", LocalResourceFile, _portalLanguage), alertReason),
                    new LogDetailInfo(Localization.GetString("FromIP", LocalResourceFile, _portalLanguage), Request.UserHostAddress),
                    new LogDetailInfo(Localization.GetString("IPNPayload", LocalResourceFile, _portalLanguage), ipn.Payload)
                };
                AddEventLog(EventLogController.EventLogType.ADMIN_ALERT.ToString(), properties, true);
                // Send an email to the store admin
                SendEmailToAdmin(systempayGateway + " " + adminAlert, Localization.GetString("EmailAlert", LocalResourceFile, _portalLanguage) + "\r\n\r\n" + alertReason);
            }

            return(status);
        }