Beispiel #1
0
        /// <summary>
        /// Do the post to the gateway and retrieve the response
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Response</returns>
        public CreateTransactionResponse ProcessRequest(Transaction request)
        {
//            var ewayClient = RapidClientFactory.NewRapidClient("44DD7Cns/tsiCi4GiJSIaM5qGLNMZmdPZ9ADSKSt+ctDUx6SjkGzzi9DVLy4Uoh8GCZ99f", "ZlVMyKbt", RapidEndpoint);
            var ewayClient = RapidClientFactory.NewRapidClient("44DD7A3Z5yFY0uS6s+PeaUvVI6MrmoZF8BpNE2UY4lvDbbJOdzK0bj3zVLxkfhCH7FMAlo", "K4ReUOmQ", RapidEndpoint);

            return(ewayClient.Create(PaymentMethod.Direct, request));
        }
        public ActionResult TokenNoPayment()
        {
            IRapidClient ewayClient = RapidClientFactory.NewRapidClient(apiKey, password, rapidEndpoint);

            Customer customer = new Customer()
            {
                Title     = "Ms.",
                FirstName = "Jane",
                LastName  = "Smith",
                Address   = new Address()
                {
                    Country = "nz"
                },
                CompanyName = "SKIDS HO[DisableForTesting]",
                Url         = "http://localhost:53738",
                RedirectURL = "http://localhost:53738/Home/Ewayresponse"
            };

            CreateCustomerResponse Customerresponse = ewayClient.Create(PaymentMethod.ResponsiveShared, customer);

            if (Customerresponse.Errors != null)
            {
                foreach (string errorCode in Customerresponse.Errors)
                {
                    Console.WriteLine("Error Message: " + RapidClientFactory.UserDisplayMessage(errorCode, "EN"));
                }
            }

            return(Redirect(Customerresponse.SharedPaymentUrl));
        }
        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);
        }
Beispiel #4
0
        protected IRapidClient CreateRapidApiClient()
        {
            var client = RapidClientFactory.NewRapidClient(APIKEY, PASSWORD, ENDPOINT);

            client.SetVersion(GetVersion());
            return(client);
        }
        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());
        }
Beispiel #6
0
        public IRapidClient GeteWayClient()
        {
            var apiKey        = ConfigurationManager.AppSettings["apiKey"];
            var password      = ConfigurationManager.AppSettings["password"];
            var rapidEndpoint = ConfigurationManager.AppSettings["rapidEndpoint"];

            return(RapidClientFactory.NewRapidClient(apiKey, password, rapidEndpoint));
        }
Beispiel #7
0
        IRapidClient GetRapidClient()
        {
            if (string.IsNullOrEmpty(AppConfigProvider.GetAppConfigValue("eWAY.APIKey")) ||
                string.IsNullOrEmpty(AppConfigProvider.GetAppConfigValue("eWAY.APIPassword")))
            {
                throw new Exceptions.MissingConfigurationFailure("Missing eWAY configuration settings.");
            }

            return(RapidClientFactory.NewRapidClient(
                       apiKey: AppConfigProvider.GetAppConfigValue("eWAY.APIKey"),
                       password: AppConfigProvider.GetAppConfigValue("eWAY.APIPassword"),
                       rapidEndpoint: AppConfigProvider.GetAppConfigValue <bool>("UseLiveTransactions")
                                        ? "Production"
                                        : "Sandbox"));
        }
        public ActionResult UseToken(string token)
        {
            IRapidClient ewayClient = RapidClientFactory.NewRapidClient(apiKey, password, rapidEndpoint);



            //1. Charging the customer with token ... note refer to https://eway.io/api-v3/#token-payments
            // tokenpayment method is not used in rapid sdk Api
            Transaction transaction = new Transaction()
            {
                Customer = new Customer()
                {
                    TokenCustomerID = token,
                },

                PaymentDetails = new PaymentDetails()
                {
                    TotalAmount   = 10000,
                    InvoiceNumber = "14632"
                },
                RedirectURL = "http://localhost:53738/Home/Ewayresponse",

                TransactionType = TransactionTypes.Recurring
            };


            CreateTransactionResponse response = ewayClient.Create(PaymentMethod.Direct, transaction);



            if (response.Errors != null)
            {
                foreach (string errorCode in response.Errors)
                {
                    Console.WriteLine("Error Message: " + RapidClientFactory.UserDisplayMessage(errorCode, "EN"));
                }
            }

            ViewBag.token    = token;
            ViewBag.response = response;
            //ViewBag.totalamount =

            int totalamount = response.Transaction.PaymentDetails.TotalAmount / 100;

            ViewBag.totalamount = totalamount;
            return(View());
        }
        public ActionResult TokenWithPayment()
        {
            IRapidClient ewayClient = RapidClientFactory.NewRapidClient(apiKey, password, rapidEndpoint);

            Customer customer = new Customer()
            {
                Title     = "Ms.",
                FirstName = "Jane",
                LastName  = "Smith",
                Address   = new Address()
                {
                    Country = "nz"
                },
                CompanyName = "SKIDS HO[DisableForTesting]",
                Url         = "http://localhost:53738",
                RedirectURL = "http://localhost:53738/Home/Ewayresponse"
            };


            Transaction transaction = new Transaction()
            {
                Customer       = customer,
                PaymentDetails = new PaymentDetails()
                {
                    TotalAmount        = 10000,
                    InvoiceDescription = "Parent subscription",
                    InvoiceNumber      = "4536",
                },
                RedirectURL     = "http://localhost:53738/Home/Ewayresponse",
                TransactionType = TransactionTypes.Purchase,
                SaveCustomer    = true,
            };

            CreateTransactionResponse transactionresponse = ewayClient.Create(PaymentMethod.ResponsiveShared, transaction);

            if (transactionresponse.Errors != null)
            {
                foreach (string errorCode in transactionresponse.Errors)
                {
                    Console.WriteLine("Error Message: " + RapidClientFactory.UserDisplayMessage(errorCode, "EN"));
                }
            }

            return(Redirect(transactionresponse.SharedPaymentUrl));
        }
Beispiel #10
0
 protected IRapidClient CreateRapidApiClient()
 {
     return(RapidClientFactory.NewRapidClient(APIKEY, PASSWORD, ENDPOINT));
 }
Beispiel #11
0
        public PaymentResponse Pay(PaymentRequest request)
        {
            using (var context = new DbContext())
            {
                var response   = new PaymentResponse();
                var adaptorLog = new ServiceLog(request);
                adaptorLog.ServiceCode = "eWay";
                adaptorLog.Name        = "eWay";
                adaptorLog.Type        = ServiceLogType.Adaptor;

                adaptorLog.Delay    = Delay;
                adaptorLog.Location = request.Location;

                var ewayClient  = RapidClientFactory.NewRapidClient(_apiKey, _password, _rapidEndpoint);
                var transaction = ProcessPayRequest(request);

                var n = 1;

                adaptorLog.ResponseTime.Start = DateTime.Now;
                var times = new List <DateTime>();
                while (n <= Attemps)
                {
                    var log = new ServiceLog(request);
                    log.ServiceCode        = "eWay";
                    log.Name               = "eWay";
                    log.Type               = ServiceLogType.CloudService;
                    log.Attemps            = n;
                    adaptorLog.Attemps     = n++;
                    log.ResponseTime.Start = DateTime.Now;
                    log.Location           = request.Location;
                    try
                    {
                        times.Add(DateTime.Now);
                        log.ResponseTime.Start = DateTime.Now;
                        var result = ewayClient.Create(PaymentMethod.Direct, transaction);
                        log.ResponseTime.End        = DateTime.Now;
                        adaptorLog.ResponseTime.End = DateTime.Now;
                        response = ProcessPayResponse(result);
                    }
                    catch (Exception ex)
                    {
                        log.ResponseTime.End        = DateTime.Now;
                        adaptorLog.ResponseTime.End = DateTime.Now;
                        response.Result             = ServiceResult.Error;
                        response.Errors.Add(ex.Message);
                    }

                    log.Message = response.Message;
                    log.Result  = response.Result.ToString();
                    //context.Set<ServiceLog>().Add(log);

                    if (response.Result != ServiceResult.Error)
                    {
                        break;
                    }

                    if (n > Attemps)
                    {
                        break;
                    }

                    if (n == 2 && request.Amount2.HasValue)
                    {
                        transaction.PaymentDetails.TotalAmount = (int)(request.Amount2.Value * 100);
                    }
                    if (n == 3 && request.Amount3.HasValue)
                    {
                        transaction.PaymentDetails.TotalAmount = (int)(request.Amount3.Value * 100);
                    }
                    // let's wait 5 seconds to see if this is a temporary network issue.

                    Thread.Sleep(Delay);
                }
                adaptorLog.ResponseTime.Start = times[0];
                adaptorLog.Result             = response.Result.ToString();
                adaptorLog.Message            = response.Message;
                context.Set <Log>().Add(adaptorLog);
                context.SaveChanges();

                return(response);
            }
        }
Beispiel #12
0
        public ActionResult DonatingDetails(DirectPay directPayModel)
        {
            IRapidClient ewayClient  = RapidClientFactory.NewRapidClient(APIKEY, PASSWORD, ENDPOINT);
            Transaction  transaction = new Transaction()
            {
                Customer = new Customer()
                {
                    Title       = directPayModel.Title,
                    FirstName   = directPayModel.FirstName,
                    LastName    = directPayModel.LastName,
                    Email       = directPayModel.Email,
                    CardDetails = new CardDetails()
                    {
                        Name   = directPayModel.CardName,
                        Number = directPayModel.CardNumber,

                        ExpiryMonth = directPayModel.CardExpiryMonth,

                        ExpiryYear = directPayModel.CardExpiryYear,
                        CVN        = directPayModel.CVN,
                    }
                },
                PaymentDetails = new PaymentDetails()
                {
                    TotalAmount = directPayModel.TotalAmount
                },
                TransactionType = TransactionTypes.Purchase,
            };
            CreateTransactionResponse response = ewayClient.Create(PaymentMethod.Direct, transaction);

            if (response.Errors != null)
            {
                foreach (string errorCode in response.Errors)
                {
                    if (errorCode == "V6100")
                    {
                        Message = "Error message: Invalid Credit card name entered, please check the name and try again!!!.";
                    }
                    else if (errorCode == "V6101" || errorCode == "V6102")
                    {
                        Message = "Error message: Invalid Expiryd Date entered,please check the date and try again!!!.";
                    }
                    else if (errorCode == "V6106")
                    {
                        Message = "Error message: Invalid CVN entered,please check the CVN and try again!!!.";
                    }
                    else if (errorCode == "V6110")
                    {
                        Message = "Error message: Invalid card number entered,please check the cardnumber and try again!!!.";
                    }
                    resultModel = new Result {
                        Status = "Payment Failure!!!", Description = Message
                    };
                }
            }
            else
            {
                if ((bool)response.TransactionStatus.Status)
                {
                    Message     = ("Thanks for donating to Charity. Please note your transaction ID: " + response.TransactionStatus.TransactionID);
                    resultModel = new Result {
                        Status = "Payment Success!!!", Description = Message
                    };
                }
            }
            return(RedirectToAction("Result", "Results", resultModel));
        }