예제 #1
0
        public ActionResult ProfileView(RegistrationViewModel model)
        {
            if (model == null)
            {
                return(View(model));
            }

            long         UrlId           = (long)TempData["UserId"];
            Registration objRegisterUser = _RegistrationRepository.GetClientById(UrlId);

            objRegisterUser.UpdatedDate = DateTime.Now.Date;
            objRegisterUser.UpdatedBy   = Convert.ToInt64(Session["UserId"]);
            objRegisterUser.City        = model.City;
            objRegisterUser.Country     = model.Country;
            objRegisterUser.Email       = model.Email;
            objRegisterUser.FirstName   = model.FirstName;
            objRegisterUser.LastName    = model.LastName;
            objRegisterUser.Phone       = model.Phone;
            objRegisterUser.State       = model.State;
            objRegisterUser.Zipcode     = model.Zipcode;
            _RegistrationRepository.Edit(objRegisterUser);

            return(RedirectToAction("ProfileView", "Client"));
        }
        public ActionResult Purchase(string stripeEmail, string stripeToken, AdManageViewModel model)
        {
            AdManage objAdManage = new AdManage();
            var      result      = new JsonResult();

            int    selectedplan = Convert.ToInt32(TempData["PlanAmount"]);
            string planname     = Enum.GetName(typeof(CommanClass.Plans), selectedplan);
            int    planvalue    = (int)Enum.Parse(typeof(CommanClass.PlanType), planname.ToString());
            int    planamount   = selectedplan * 100;
            string FileName     = string.Empty;
            int    userid       = Convert.ToInt32(Session["UserId"]);
            var    customers    = new StripeCustomerService();
            var    charges      = new StripeChargeService();

            try
            {
                var RegisteredUser = registrationRepository.GetClientById(userid);

                if (!string.IsNullOrEmpty(stripeEmail))
                {
                    var customer = customers.Create(new StripeCustomerCreateOptions
                    {
                        Email       = stripeEmail,
                        SourceToken = stripeToken
                    });

                    var charge = charges.Create(new StripeChargeCreateOptions
                    {
                        Amount      = planamount,
                        Description = selectedplan.ToString(),
                        //Currency = "usd",
                        Currency   = "eur",
                        CustomerId = customer.Id
                    });

                    //Save Response in PaymentTransaction Table
                    PaymentTransaction payment = new PaymentTransaction()
                    {
                        RegistId                             = userid,
                        Customer_stripeEmail                 = stripeEmail,
                        Customer_Id                          = customer.Id,
                        Customer_stripeToken                 = stripeToken,
                        Customer_Created                     = customer.Created,
                        Customer_DefaultSourceId             = customer.DefaultSourceId,
                        Customer_InvoicePrefix               = customer.InvoicePrefix,
                        Customer_StripeResponse_RequestId    = customer.StripeResponse.RequestId,
                        Customer_StripeResponse_ResponseJson = customer.StripeResponse.ResponseJson,

                        Charge_Id     = charge.Id,
                        Charge_Amount = charge.Amount,
                        Charge_BalanceTransactionId = charge.BalanceTransactionId,
                        Charge_Created               = charge.Created,
                        Charge_CustomerId            = charge.CustomerId,
                        Charge_Description           = charge.Description,
                        Charge_FailureCode           = charge.FailureCode,
                        Charge_FailureMessage        = charge.FailureMessage,
                        Charge_Outcome_SellerMessage = charge.Outcome.SellerMessage,
                        Charge_Paid      = charge.Paid,
                        Charge_Source_Id = charge.Source.Id,
                        Charge_Status    = charge.Status,
                        Charge_StripeResponse_RequestId    = charge.StripeResponse.RequestId,
                        Charge_StripeResponse_ResponseJson = charge.StripeResponse.ResponseJson,
                        IsSuccess     = true,
                        Response      = "Complete",
                        PaymentMethod = (int)CommanClass.PaymentMethod.Stripe
                    };
                    _paymentRepository.AddPayment(payment);
                    //_paymentRepository.SaveAll();

                    //Insert stripe response information in PaymentTransaction table
                    //db.PaymentTransaction.Add(payment);
                    //db.SaveChanges();

                    RegisteredUser.PaymentStatus = true;
                    registrationRepository.Edit(RegisteredUser);

                    if (!string.IsNullOrEmpty(charge.FailureCode))
                    {
                        model.ResponseMessage = "Your subscription failed!!";
                        model.Paymentstatus   = CommanClass.PaymentStatus.Failed;
                        return(View(model));
                    }
                }
                //for zarinpal payment plugin
                else
                {
                    //Payment with Zarinpal Service reference.
                    string             authority = string.Empty;
                    int                payment_request_response = 0;
                    PaymentTransaction payment = new PaymentTransaction();
                    try
                    {
                        PaymentGatewayImplementationServicePortTypeClient request = new PaymentGatewayImplementationServicePortTypeClient();
                        Amount = PlanCalculate.CalculatePlanAmount(selectedplan);
                        payment_request_response = request.PaymentRequest(MerchantID, 120, "Test", "", "", ZarinpalCallbackURL, out authority);
                        if (payment_request_response > 0)
                        {
                            if (Request.Files[0].ContentLength > 0)
                            {
                                Guid FileNameGuid = Guid.NewGuid();
                                FileName = FileNameGuid.ToString() + ".html";
                                string _path = Path.Combine(Server.MapPath("~/AdHTML"), FileName);
                                Request.Files[0].SaveAs(_path);
                            }

                            objAdManage             = Mapper.Map <AdManageViewModel, AdManage>(model);
                            objAdManage.Addeddate   = DateTime.Now.Date;
                            objAdManage.RegistAdId  = userid;
                            objAdManage.UpdateDate  = DateTime.Now.Date;
                            objAdManage.UpdatedBy   = userid;
                            objAdManage.UploadFile  = FileName;
                            objAdManage.Description = model.Description;

                            adManageRepository.AddAd(objAdManage);
                            adManageRepository.SaveAll();

                            payment.IsSuccess = false;
                            payment.RegistId  = userid;
                            payment.Authority = authority;
                            payment.Payment_RequestResponse = payment_request_response;
                            payment.Charge_Amount           = Convert.ToInt32(Amount);
                            //Insert in Payment Table
                            Session["IsPaymentPrecessing"] = false;
                            _paymentRepository.InsertPaymentTransactionData(payment);
                            //Redirect to zarinpal gateway site for payment.
                            return(Redirect(ZarinpalPaymentURL + authority));
                        }
                    }
                    catch (Exception ex)
                    {
                        payment.Charge_Amount                = Convert.ToInt32(Amount);
                        payment.IsSuccess                    = false;
                        payment.RegistId                     = userid;
                        payment.Authority                    = authority;
                        payment.Payment_RequestResponse      = payment_request_response;
                        payment.PaymentRequest_ErrorResponse = ex.ToString();
                        _paymentRepository.InsertPaymentTransactionData(payment);
                        Session["PaymentStatus"]       = false;
                        Session["IsPaymentPrecessing"] = false;
                    }
                }

                //Insert in DB
                if (Request.Files[0].ContentLength > 0)
                {
                    //FileName = Convert.ToString(Session["UserId"]) + ".html";
                    Guid FileNameGuid = Guid.NewGuid();
                    FileName = FileNameGuid.ToString() + ".html";
                    string _path = Path.Combine(Server.MapPath("~/AdHTML"), FileName);
                    Request.Files[0].SaveAs(_path);
                }

                // AdManage objAdManage = new AdManage();
                objAdManage             = Mapper.Map <AdManageViewModel, AdManage>(model);
                objAdManage.Addeddate   = DateTime.Now;
                objAdManage.RegistAdId  = Convert.ToInt64(Session["UserId"]);
                objAdManage.UpdateDate  = DateTime.Now;
                objAdManage.UpdatedBy   = Convert.ToInt32(Session["UserId"]);
                objAdManage.UploadFile  = FileName;
                objAdManage.Description = model.Description;

                adManageRepository.AddAd(objAdManage);
                if (adManageRepository.SaveAll())
                {
                    Registration objRegisterUser = registrationRepository.GetClientById(userid);
                    objRegisterUser.PaymentStatus = true;
                    registrationRepository.Edit(objRegisterUser);
                    Session["PaymentStatus"] = true;
                    model.ResponseMessage    = "Your subscription succesfully!!";
                    model.Paymentstatus      = CommanClass.PaymentStatus.Sucess;
                    return(View(model));
                }
                else
                {
                    model.ResponseMessage    = "Your subscription failed!!";
                    model.Paymentstatus      = CommanClass.PaymentStatus.Failed;
                    Session["PaymentStatus"] = false;
                }
            }
            catch (Exception ex)
            {
                //result.Data = "Your subscription failed!! " + ex.Message.ToString();
                model.ResponseMessage    = "Your subscription failed!! " + ex.Message.ToString();
                model.Paymentstatus      = CommanClass.PaymentStatus.Failed;
                Session["PaymentStatus"] = false;
            }

            return(View(model));
        }