示例#1
0
        public async Task <ActionResult> InitStall(int id)
        {
            try
            {
                var stall = Models.Stall.FindById(id, _db);
                if (stall == null)
                {
                    StallApplication.BizErrorFormat("stall {0} not exist", id);
                    return(View("Error"));
                }

                if (!stall.UserId.Equals(CurrentUser.Id))
                {
                    StallApplication.BizErrorFormat("user id not match {0} <> {1}", stall.UserId, CurrentUser.Id);
                    return(View("Error"));
                }

                var initResult = await stall.Init();

                if (initResult.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    StallApplication.BizErrorFormat("Failed to init stall, {0}", initResult.Message);
                    return(View("Error"));
                }
            }
            catch (Exception ex)
            {
                StallApplication.BizError("Failed to init stall", ex);
                return(View("Error"));
            }
        }
示例#2
0
        /// <summary>
        /// verify px payment match transaction
        /// if pay success set transaction as paid
        /// </summary>
        /// <param name="resultId"></param>
        /// <param name="isSuccess"></param>
        /// <returns></returns>
        public static bool VerifyPxPayPayment(string resultId, bool isSuccess, out int outPaymentId)
        {
            outPaymentId = 0;
            try
            {
                //check response
                StallApplication.BizInfoFormat("[ACCOUNTANT-PXPAY]start to get pxpay payment result={0}", resultId);
                ResponseOutput output = _pxPay.ProcessResponse(resultId);
                if (output == null)
                {
                    StallApplication.BizError("[ACCOUNTANT-PXPAY]can not get pxpay payment result - resposne is null");
                    return(false);
                }
                if (!(isSuccess ? "1" : "0").Equals(output.Success))
                {
                    StallApplication.BizErrorFormat("[ACCOUNTANT-PXPAY]payment result not match except {0} - actual {1}", output.Success, isSuccess);
                    StallApplication.BizErrorFormat("[ACCOUNTANT-PXPAY]{0}", output);
                    return(false);
                }

                //set payment
                int     paymentId = int.Parse(output.TxnId.Split('-')[0]);
                decimal amount    = decimal.Parse(output.AmountSettlement);
                using (StallEntities db = new StallEntities())
                {
                    Payment payment = db.Payments.FirstOrDefault(o => o.Id == paymentId);
                    if (payment == null)
                    {
                        StallApplication.BizErrorFormat("[ACCOUNTANT-PXPAY]payment {0} can not mactch payment {1}", resultId, outPaymentId);
                        StallApplication.BizErrorFormat("[ACCOUNTANT-PXPAY]{0}", output);
                        return(false);
                    }

                    payment.ResponseTime = DateTime.Now;
                    outPaymentId         = paymentId;
                    bool result = true;
                    if (!isSuccess)
                    {
                        //pay fail
                        StallApplication.BizErrorFormat("[ACCOUNT-PAPAY]pay failed payment id={0}", payment.Id);
                    }
                    else
                    {
                        //pay success
                        if (payment.Amount != amount)
                        {
                            StallApplication.BizErrorFormat("[ACCOUNT-PAPAY]pxpay amount {0} <> transaction amount {1}", amount, payment.Amount);
                            result = false;
                        }
                        else
                        {
                            payment.HasPaid = true;
                        }
                    }
                    payment.PxPayResponse = output.ToString();
                    db.SaveChanges();
                    return(result);
                }
            }
            catch (Exception ex)
            {
                StallApplication.SysError("can not get pxpay payment result", ex);
                return(false);
            }
        }