コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string resultPayment = "";

                //Redirection if not Login
                if (this.Session["CustID"] == null)
                {
                    Response.Redirect(ConfigurationManager.AppSettings["SecurePath"] + "/UL/Customer/Login.aspx");;
                }

                //Attempt reinitialization
                this.Session["attempt"] = 0;

                //Get id from urlFriendly
                try
                {
                    var segments = Request.GetFriendlyUrlSegments();
                    resultPayment = segments[0];
                }
                catch (Exception ex)
                {
                    ex.GetBaseException();
                    Debug.Write(ex.ToString());
                    lblResult.Text = "Error URL";
                }

                //Test : invoiceID set and Payment executed
                if (this.Session["InvoiceID"] != null && resultPayment != null)
                {
                    try
                    {
                        int invoiceID = Convert.ToInt32(this.Session["InvoiceID"]);

                        //Payment Denied
                        if (resultPayment == "0")
                        {
                            int res;
                            //Reverse the stock modifications in DB
                            //Old cart recuperation from invoiceID
                            ProductSelectionBL         blProdSel = new ProductSelectionBL();
                            List <ProductSelectionDTO> cart      = (List <ProductSelectionDTO>)(this.Session["Cart"]);

                            if (cart.Count != 0)
                            {
                                //Update DB in reverse mode
                                res = blInvoice.UpdateStockProductSelection(invoiceID, cart, true);
                            }
                            else
                            {
                                Debug.Write("\nReverse update database Failed, Cart empty\n");
                            }

                            //Set invoice status as cancelled
                            blInvoice.SetAsCancelled(invoiceID);
                            lblResult.Text = "There is an error in your payment information, the order has been cancelled.";

                            //Cart Reinitialization
                            this.Session.Remove("Cart");
                            Session["Cart"] = new List <ProductSelectionDTO>();
                        }

                        //Payment Approved
                        else if (resultPayment == "1")
                        {
                            //Set PaymentDate
                            List <InvoiceDTO> dtoInvoice = blInvoice.FindInvoiceByID(Convert.ToInt32(this.Session["CustID"]), invoiceID);
                            DateTime          dt         = dtoInvoice[0].GetArrivalDate();

                            //Set invoice status as Paied
                            blInvoice.SetAsPaied(invoiceID);
                            lblResult.Text      = "Your order is well register, thank you ! ";
                            lblArrivalDate.Text = "Your order should arrive around the " + dt.ToString("dd/MM/yyyy");

                            //Send Mail containing invoice information to the customer
                            MailSender(dtoInvoice[0]);

                            //Cart Reinitialization
                            this.Session.Remove("Cart");
                            Session["Cart"] = new List <ProductSelectionDTO>();
                        }
                        else
                        {
                            lblResult.Text = "Error";
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.GetBaseException();
                        Debug.Write(ex.ToString());
                        lblResult.Text = "Error";
                    }
                }
                else
                {
                    Response.Redirect(ConfigurationManager.AppSettings["SecurePath"] + "/UL/Customer/Login.aspx");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// take Invoice/customer information
        /// set a paymentRequest corresponding to the subit button used
        /// Wait until end of payment
        /// Display result
        /// </summary>
        /// <param name="realPayment"></param>
        private void Payment(bool realPayment)
        {
            try
            {
                //Invoice recuperation (List of 1 element)
                int     customerID  = Convert.ToInt32(this.Session["CustID"]);
                int     invoiceID   = Convert.ToInt32(this.Session["InvoiceID"]);
                decimal TotalAmount = blInvoice.FindInvoiceByID(customerID, invoiceID)[0].GetTotal();


                //Payment
                //Created the Payment system
                IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();

                //Making a payment
                PaymentRequest payment = new PaymentRequest();


                if (realPayment == false)
                {
                    //Value to make the payment approved
                    payment.CardName   = "Arthur Anderson";
                    payment.CardNumber = "4444333322221111";
                    payment.CVC        = 123;
                    payment.Expiry     = new DateTime(2020, 11, 1);
                    payment.Amount     = 200;
                }
                else
                {
                    payment.CardName   = TextName.Text;
                    payment.CardNumber = TextCardNumber.Text;
                    payment.CVC        = Convert.ToInt16(TextCSC.Text);
                    payment.Expiry     = new DateTime(Convert.ToInt16(YearExpiration.SelectedValue), Convert.ToInt16(MonthExpiration.SelectedValue), 1);
                    payment.Amount     = TotalAmount;
                }

                payment.Description = "OrderID : " + invoiceID + " for customer : " + customerID;
                var task = paymentSystem.MakePayment(payment);

                while (!task.IsCompleted)
                {
                }                                  //Let time to executing transaction

                //Display result
                if (task.Result.TransactionResult.ToString() == "Approved")
                {
                    lblResult.CssClass = "text-success";
                    lblResult.Text     = "Your paiment is approved !";

                    var urlF = FriendlyUrl.Href("/UL/Customer/checkout", 1);
                    Response.Redirect(ConfigurationManager.AppSettings["SecurePath"] + urlF);
                }
                else if (task.Status.ToString() == "RanToCompletion")
                {
                    lblResult.CssClass = "text-danger";
                    lblResult.Text     = "Issue during the paiment :  " + task.Result.TransactionResult.ToString();
                    lblWait.Visible    = false;
                }
                else
                {
                    lblResult.Text  = "Issue during the paiment procedure, please try later";
                    lblWait.Visible = false;
                }
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
                Debug.Write(ex.ToString());
            }
        }