public CreateCustomerResponse Updatetokendetails(string tokenid)
        {
            IRapidClient ewayClient = RapidClientFactory.NewRapidClient(apiKey, password, rapidEndpoint);

            Customer customer = new Customer()
            {
                Title     = "Mr.",
                FirstName = "Tom",
                LastName  = "Jones",
                Address   = new Address()
                {
                    Country = "au"
                },
                CardDetails = new CardDetails()
                {
                    Name        = "Tom Jones",
                    Number      = "4444333322221111",
                    ExpiryMonth = "12",
                    ExpiryYear  = "25",
                    CVN         = "123"
                },
                TokenCustomerID = tokenid,
            };

            CreateCustomerResponse response = ewayClient.UpdateCustomer(PaymentMethod.Direct, customer);

            ViewBag.response = response;
            QueryCustomerResponse customerresponse = ewayClient.QueryCustomer(long.Parse(tokenid));

            return(response);
        }
        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());
        }