Ejemplo n.º 1
0
        public ActionResult Subscription(string id)
        {
            int ID    = Int32.Parse(id);
            var token = "";

            //Check if token exist otherwise send details to Shared Payment Gateway
            using (AimyEntities db = new AimyEntities()) {
                var checktokenexist = (from sub in db.CssSubscriptions
                                       join org in db.Orgs on sub.OrgId equals org.Id
                                       join pay in db.CssPaymentSetups on org.Id equals pay.OrgId
                                       where sub.Id == ID
                                       select new
                {
                    token = pay.CustomerId,
                    orgid = org.Id
                }
                                       ).FirstOrDefault();
                //check if token exits
                if (checktokenexist.token != "")
                {
                    // token = checktokenexist.token;
                    token = "910287958561"; //only because this hasn't been save to db ..
                    CreateTransactionResponse response = UseTokenRet(token);
                    ViewBag.response = response;
                }
                else //send to sharepayment gateway
                {
                }
            }
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Ewayresponse(String AccessCode)
        {
            IRapidClient ewayClient = RapidClientFactory.NewRapidClient(apiKey, password, rapidEndpoint);

            QueryTransactionResponse response = ewayClient.QueryTransaction(AccessCode);
            string tokenid = response.Transaction.Customer.TokenCustomerID;

            //save the tokenid and response for the view
            ViewBag.token    = tokenid;
            ViewBag.response = response;


            if ((bool)response.TransactionStatus.Status)
            {
                Console.WriteLine("Payment successful! ID: " + response.TransactionStatus.TransactionID);
                //Get organisation name to save in CssPaymentSetup
                QueryCustomerResponse customerresponse = ewayClient.QueryCustomer(long.Parse(tokenid));

                string[] orgN    = customerresponse.Customers.Select(c => c.CompanyName).ToArray();
                string   orgname = orgN[0];

                int orgid;
                using (AimyEntities db = new AimyEntities())
                {
                    int[] orgids = db.Orgs.Where(o => o.Name == orgname).Select(o => o.Id).ToArray();
                    orgid = orgids[0];
                }
                //Get the credit card details to save in CssPaymentSetup
                string[] cd         = customerresponse.Customers.Select(cc => cc.CardDetails).Select(d => d.Number).ToArray();
                string   creditcard = cd[0];

                using (AimyEntities db = new AimyEntities())
                {
                    CssPaymentSetup savetoken = new CssPaymentSetup();
                    savetoken.CustomerId       = tokenid;
                    savetoken.IsActive         = true;
                    savetoken.MaskedCardNumber = creditcard;
                    savetoken.OrgId            = orgid;
                    savetoken.CreatedOn        = DateTime.Today;
                    //CreatedBy is the userid that can be retrieve from session current user -- for now we assign 3694
                    savetoken.CreatedBy = 3694;

                    db.CssPaymentSetups.Add(savetoken);
                    db.SaveChanges();
                };
            }
            else if (tokenid == null)
            {
                string[] errorCodes = response.TransactionStatus.ProcessingDetails.ResponseMessage.Split(new[] { ", " }, StringSplitOptions.None);

                foreach (string errorCode in errorCodes)
                {
                    Console.WriteLine("Response Message: "
                                      + RapidClientFactory.UserDisplayMessage(errorCode, "EN"));
                }
            }

            return(View());
        }