protected void SettleRequestButton_Click(object sender, EventArgs e)
    {
        try
        {
            string result;

            BypassCertificateError();

            ir.shaparak.bpm.PaymentGatewayImplService bpService = new ir.shaparak.bpm.PaymentGatewayImplService();
            result = bpService.bpSettleRequest(Int64.Parse(TerminalIdTextBox.Text),
                                               UserNameTextBox.Text,
                                               UserPasswordTextBox.Text,
                                               Int64.Parse(SettleOrderIdTextBox.Text),
                                               Int64.Parse(SettleSaleOrderIdTextBox.Text),
                                               Int64.Parse(SettleSaleReferenceIdTextBox.Text));
            SettleOutputLabel.Text = result;
        }
        catch (Exception exp)
        {
            SettleOutputLabel.Text = "Error: " + exp.Message;
        }
    }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult CallBack()
        {
            string comment;
            var    resCode = Request.Params["ResCode"];
            var    orderId = int.Parse(Request.Params["OrderId"] ?? "0");
            var    order   = _orderService.GetOrderById(orderId);

            #region [After Call Mellat WebService]
            if (!string.IsNullOrEmpty(Request.Params["RefId"]) &&
                !string.IsNullOrEmpty(Request.Params["saleOrderId"]) &&
                !string.IsNullOrEmpty(Request.Params["SaleReferenceId"]))
            {
                var refId           = Request.Params["RefId"];
                var saleOrderId     = long.Parse(Request.Params["saleOrderId"]);
                var saleReferenceId = long.Parse(Request.Params["SaleReferenceId"]);
                if (resCode == "0")
                {
                    if (order != null)
                    {
                        try
                        {
                            #region [Mellat : bpVerifyRequest , bpSettleRequest]
                            var terminalId   = _mellatPaymentSettings.TerminalId;
                            var userName     = _mellatPaymentSettings.UserName;
                            var userPassword = _mellatPaymentSettings.UserPassword;
                            BypassCertificateError();
                            var bpService             = new ir.shaparak.bpm.PaymentGatewayImplService();
                            var resultOfVerifyRequest = bpService.bpVerifyRequest(Int64.Parse(terminalId),
                                                                                  userName,
                                                                                  userPassword,
                                                                                  saleOrderId,
                                                                                  saleOrderId,
                                                                                  saleReferenceId);
                            var settleRequestArray = resultOfVerifyRequest.Split(',');
                            if (settleRequestArray[0] == "0")
                            {
                                var resultOfSettleRequest = bpService.bpSettleRequest(Int64.Parse(terminalId),
                                                                                      userName,
                                                                                      userPassword,
                                                                                      saleOrderId,
                                                                                      saleOrderId,
                                                                                      saleReferenceId);
                                if (resultOfSettleRequest != "0")
                                {
                                    throw new Exception();
                                }
                            }
                            else
                            {
                                throw new Exception();
                            }

                            #endregion
                            #region [mark order as paid]
                            if (_orderProcessingService.CanMarkOrderAsPaid(order))
                            {
                                //TODO : check saleOrderId is match by this Order.CaptureTransactionId
                                order.CaptureTransactionId      = saleOrderId.ToString(CultureInfo.InvariantCulture);
                                order.SubscriptionTransactionId = string.Format("[RefId = {0}]", refId);

                                order.AuthorizationTransactionId = string.Format("[SaleReferenceId = {0}]",
                                                                                 saleReferenceId.ToString(CultureInfo.InvariantCulture));
                                order.AuthorizationTransactionResult = string.Format("[ResCode = {0}]", resCode);

                                _orderService.UpdateOrder(order);
                                _orderProcessingService.MarkOrderAsPaid(order);
                            }
                            #endregion
                        }
                        catch
                        {
                            comment = string.Format("Error in Mellat Pay Verify or Pay Settle. OrderId= {0}", orderId);
                            _logger.Error(comment);
                            return(RedirectToAction("Error", "PaymentMellat", new
                            {
                                result = comment,
                                cashRefId = Request.Params["SaleReferenceId"],
                                insRefId = "",
                                cashOrder = Request.Params["saleOrderId"],
                                insOrder = "",
                                id = order.Id
                            }));
                        }
                        return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
                    }
                    comment = string.Format("Order Not Found. OrderId= {0}", orderId);
                    _logger.Error(comment);
                    return(RedirectToAction("Error", "PaymentMellat", new
                    {
                        result = comment,
                        cashRefId = Request.Params["SaleReferenceId"],
                        insRefId = "",
                        cashOrder = Request.Params["saleOrderId"],
                        insOrder = "",
                        id = orderId
                    }));
                }
                comment = Utility.ErrorCode("bpPayRequest", resCode);
                _logger.Warning(comment);
                return(RedirectToAction("Error", "PaymentMellat", new
                {
                    result = comment,
                    cashRefId = Request.Params["SaleReferenceId"],
                    insRefId = "",
                    cashOrder = Request.Params["saleOrderId"],
                    insOrder = "",
                    id = order.Id
                }));
            }
            comment = Utility.ErrorCode("bpPayRequest", resCode);
            _logger.Error(comment);
            return(RedirectToAction("Error", "PaymentMellat", new
            {
                result = comment,
                cashRefId = Request.Params["SaleReferenceId"],
                insRefId = "",
                cashOrder = Request.Params["saleOrderId"],
                insOrder = "",
                id = order.Id
            }));

            #endregion
        }