示例#1
0
        public COM.PayFinalResult PayConfirm(COM.PayVerifiedData mPayVerifiedData)
        {
            var webClient = new WebClient();

            webClient.Encoding = System.Text.Encoding.UTF8;
            webClient.Headers[HttpRequestHeader.ContentType] = "application/json;charset=utf-8";
            var rawMessage = JsonConvert.SerializeObject(mPayVerifiedData);

            rawMessage = webClient.UploadString("http://www.poolban.ir/PayGate/pay/VerifiedCustomerForIPG", rawMessage);

            var Result = JsonConvert.DeserializeObject <COM.PayFinalResult>(rawMessage);

            return(Result);
        }
示例#2
0
        public IHttpActionResult CallBackPayResult(HttpRequestMessage request)
        {
            try
            {
                new System.Threading.Thread(delegate() { Log.DoLog(COM.Action.CallBackPayResult, "", 0, "STAART"); }).Start();

                var form = request.Content.ReadAsFormDataAsync().Result;
                COM.PayEndResult payEndResult = new COM.PayEndResult();

                payEndResult.ErrorCode        = form["ErrorCode"];
                payEndResult.BuyID            = form["BuyID"];
                payEndResult.ErrorDescription = form["ErrorDescription"];
                payEndResult.ReferenceNumber  = form["ReferenceNumber"];
                payEndResult.State            = Int32.Parse(form["State"]);
                payEndResult.Token            = form["Token"];
                payEndResult.TrackingNumber   = form["TrackingNumber"];

                //payEndResult.ErrorCode = JsonConvert.DeserializeObject<string>(form["ErrorCode"]);
                //payEndResult.BuyID = JsonConvert.DeserializeObject<string>(form["BuyID"]);
                //payEndResult.ErrorDescription = JsonConvert.DeserializeObject<string>(form["ErrorDescription"].ToString());
                //payEndResult.ReferenceNumber = JsonConvert.DeserializeObject<string>(form["ReferenceNumber"].ToString());
                //payEndResult.State = JsonConvert.DeserializeObject<int>(form["State"].ToString());
                //payEndResult.Token = JsonConvert.DeserializeObject<string>(form["Token"].ToString());
                //payEndResult.TrackingNumber = JsonConvert.DeserializeObject<string>(form["TrackingNumber"].ToString());

                //COM.PayEndResult payEndResult = new COM.PayEndResult()
                //{
                //    BuyID = BuyID,
                //    ErrorCode = ErrorCode,
                //    ErrorDescription = ErrorDescription,
                //    ReferenceNumber = ReferenceNumber,
                //    State = State,
                //    Token = Token,
                //    TrackingNumber = TrackingNumber
                //};

                COM.PayVerifiedData payVerifiedData = new COM.PayVerifiedData();

                var pay = BLL.Payment.GetPayByBuyID(payEndResult.BuyID);
                if (pay == null)
                {
                    COM.PayVerifiedData mPayVerifiedDataTmp = new COM.PayVerifiedData()
                    {
                        ForceReverse = true,
                        Token        = payEndResult.Token
                    };
                    var resTmp = PayConfirm(mPayVerifiedDataTmp);
                    //chio to Db updte konam Akhe !

                    new System.Threading.Thread(delegate() { Log.DoLog(COM.Action.CallBackPayResult, payEndResult.BuyID, 2, "Bad END"); }).Start();
                    return(Redirect("https://www.hasma.ir/payment/failed"));
                }
                else
                {
                    pay.ReferenceNumber = payEndResult.ReferenceNumber;
                    pay.DargahState     = payEndResult.State;
                    pay.Token           = payEndResult.Token;
                    pay.TrackingNumber  = payEndResult.TrackingNumber;
                    pay.EndMoment       = DateTime.Now;

                    BLL.Payment.UpdatePayAfterDargah(pay);
                }

                COM.PayVerifiedData mPayVerifiedData = new COM.PayVerifiedData()
                {
                    ForceReverse    = false,
                    Token           = pay.Token,
                    TrackingNumber  = pay.TrackingNumber,
                    State           = pay.DargahState ?? 0,
                    ReferenceNumber = pay.ReferenceNumber,
                    Amount          = pay.Amount,
                    BuyID           = pay.BuyID
                };
                var resFinal = PayConfirm(mPayVerifiedData);

                if (resFinal.Status == 1)
                {
                    pay.FinalState = resFinal.Status;
                    pay.IsReverse  = false;
                    BLL.Payment.UpdatePayAfterConfirm(pay);
                }
                else
                {
                    pay.FinalState = resFinal.Status;
                    pay.IsReverse  = true;
                    BLL.Payment.UpdatePayAfterConfirm(pay);
                }

                new System.Threading.Thread(delegate() { Log.DoLog(COM.Action.CallBackPayResult, payEndResult.BuyID, 1, "Happy END"); }).Start();
                return(Redirect("https://www.hasma.ir/payment/Success/" + payEndResult.TrackingNumber));
            }
            catch (Exception e)
            {
                new System.Threading.Thread(delegate() { Log.DoLog(COM.Action.CallBackPayResult, "payEndResult", -100, e.Message); }).Start();
                return(Redirect("https://www.hasma.ir/payment/failed"));
            }
        }