Ejemplo n.º 1
0
        public ReturnState ChargeCreditCard(CustomerObject co, Promotion promo, int payTypeFk, decimal budget)
        {
            var sw = new ServiceClientWrapper();
            var gr = sw.CreateProfile(co);
            if (gr != null && gr.isGood && !gr.isError)
            {
                var refNum = gr.CustomerRefNum;
                gr = sw.AuthorizeAndCapture(refNum, double.Parse(budget.ToString()));
                if (gr != null && gr.isApproved && !gr.isError && gr.ResponseCode == "00")
                {
                    var tr = new TransactionRepository(_dbcontext);
                    var amount = decimal.Parse(gr.amountRedeemedNoDecimal);
                    var cp =
                        _dbcontext.CreditCardProfiles.Add(new CreditCardProfile
                                                              {
                                                                  CustomerRefNum = refNum,
                                                                  CustomerFK = promo.ProductGroup.CustomerFK
                                                              });
                    var tran = _dbcontext.Transactions.Add(new Transaction
                                                               {
                                                                   CreatedDate = DateTime.Now,
                                                                   Amount = amount,
                                                                   CreditCardProfileFK = cp.CreditCardProfilePK,
                                                                   AuthCode = gr.AuthCode,
                                                                   TxRefNum = gr.TxRefNum
                                                               });
                    tran.SemplestTransactions.Add(new SemplestTransaction
                                                      {
                                                          CreatedDate = DateTime.Now,
                                                          Amount = amount,
                                                          TransactionTypeFK = tr.GetTransactionTypeCode("MediaSpend")
                                                      });
                    promo.RemainingBudgetInCycle += amount;
                    promo.StartBudgetInCycle += amount;
                    promo.CreditCardProfileFK = cp.CreditCardProfilePK;
                    _dbcontext.PromotionBudgets.Add(new PromotionBudget
                                                        {
                                                            TransactionsFK = tran.TransactionsPK,
                                                            PromotionFK = promo.PromotionPK,
                                                            BudgetCarryOverAmount = 0,
                                                            BudgetToAddAmount = amount,
                                                            BudgetToAddDate = DateTime.Now,
                                                            CreatedDate = DateTime.Now,
                                                            IsValid = true,
                                                            IsAppliedToPromotion = true
                                                        });
                    return new ReturnState(false, false, string.Empty, null);
                }
                return gr == null
                           ? new ReturnState(true, false, "Server Exception", null)
                           : new ReturnState(true, true, gr.Message, null);
            }

            return gr == null
                       ? new ReturnState(true, false, "Server Exception", null)
                       : new ReturnState(true, true, "Card Declined", null);
        }
Ejemplo n.º 2
0
        public ActionResult AddNewCard(FormCollection fc)
        {
            try
            {
                Credential c = ((Credential)(Session[Semplest.SharedResources.SEMplestConstants.SESSION_USERID]));

                

                #region handle form data here....
                //handle form data
                if (fc["ExpirationDate"].ToString().Split(',')[0] == "-Select Month-" )
                { 
                    //no exp month has been selected
                }
                if (fc["ExpirationDate"].ToString().Split(',')[1] == "-Select Year-")
                { 
                    //no exp year has been selected
                }
                if (fc["CardNumber"].ToString() == "")
                {
                    //no card number entered
                }
                if (fc["FirstName"].ToString() == "")
                {
                    //no FirstName  entered
                }
                if (fc["LastName"].ToString() == "")
                {
                    //no LastName entered
                }
                if (fc["Address"].ToString() == "")
                {
                    //no Address entered
                }
                if (fc["City"].ToString() == "")
                {
                    //no City entered
                }
                if (fc["zip"].ToString() == "")
                {
                    //no zip entered
                }
                if (fc["phone"].ToString() == "")
                {
                    //no zip entered
                }
                if (fc["email"].ToString() == "")
                {
                    //no zip entered
                }

                #endregion

                //make api call 
                CustomerObject co = new CustomerObject() {  ExpireDateMMYY = fc["ExpirationDate"].ToString().Split(',')[0].ToString() + fc["ExpirationDate"].ToString().Split(',')[1],
                                                            creditCardNumber = fc["CardNumber"],
                                                            FirstName = fc["FirstName"].ToString(),
                                                            LastName = fc["FirstName"].ToString(),
                                                            Address1 = fc["Address"].ToString(),
                                                            City = fc["City"].ToString(),
                                                            ZipCode = fc["zip"].ToString(),
                                                            Phone = fc["phone"].ToString(),
                                                            Email = fc["email"].ToString(),
                                                             StateAbbr=fc["state"].ToString()};

                ServiceClientWrapper scw=new ServiceClientWrapper();
                GatewayReturnObject myret = scw.CreateProfile(co);
                if (myret.Message != "Profile Request Processed") throw new Exception();
                if (myret.isGood != true) throw new Exception();


                string customerreferencenumber = myret.CustomerRefNum.ToString();
                var dbContext = new SemplestModel.Semplest();
                var custid = ((Credential)(Session[Semplest.SharedResources.SEMplestConstants.SESSION_USERID])).User.Customer.CustomerPK;
                var trans = dbContext.CreditCardProfiles.Add(new CreditCardProfile() { CustomerFK = custid, CustomerRefNum = customerreferencenumber });
                
                //to do: add nickname for dropdown so that we can avoid calling the cc api everytime we are on the billinglaunch page
                //save nickname to creditcardprofiles
                

                //return to billinglaunch,
                //update the card drop down, select the last one added





                /////////////////////////////////////////////////////
                //info: to charge card call AuthorizeAndCapture below
                //double amountToCharge=2.0;
                //GatewayReturnObject myret3 = scw.AuthorizeAndCapture(myret.CustomerRefNum, amountToCharge);

               



            }
            catch (Exception ex)
            {

            }

            return View();


        }