public JsonResult EwayTransaction(Order order)
        {
            var transaction = new Transaction()
            {
                PaymentDetails = new PaymentDetails()
                {
                    TotalAmount        = (int)order.TotalAmount * 100,
                    InvoiceNumber      = order.OrderNumber,
                    InvoiceDescription = order.Id.ToString()
                },
                SaveCustomer    = true,
                RedirectURL     = ConfigurationManager.AppSettings["redirectURL"],
                CancelURL       = ConfigurationManager.AppSettings["cancelURL"],
                TransactionType = TransactionTypes.Purchase
            };
            var response = GeteWayClient().Create(eWAY.Rapid.Enums.PaymentMethod.ResponsiveShared, transaction);

            if (response.Errors != null)
            {
                var transactionErrorMessage = string.Empty;
                foreach (var errorCode in response.Errors)
                {
                    transactionErrorMessage += "Error: " + RapidClientFactory.UserDisplayMessage(errorCode, "EN");
                }
                return(Json(transactionErrorMessage, JsonRequestBehavior.AllowGet));
            }

            var transactionObject = new TransactionObject()
            {
                Order            = order,
                SharedPaymentUrl = response.SharedPaymentUrl
            };

            return(Json(transactionObject, JsonRequestBehavior.AllowGet));
        }
        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);
        }
Example #3
0
        protected IRapidClient CreateRapidApiClient()
        {
            var client = RapidClientFactory.NewRapidClient(APIKEY, PASSWORD, ENDPOINT);

            client.SetVersion(GetVersion());
            return(client);
        }
        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));
        }
Example #5
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 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());
        }
Example #7
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));
        }
Example #8
0
        public void UserDisplayMessage_ReturnValidErrorMessage()
        {
            //Arrange
            var testMessage = "Invalid TransactionType, account not certified for eCome only MOTO or Recurring available";
            //Act
            var message = RapidClientFactory.UserDisplayMessage("V6010", "en");

            //Assert
            Assert.AreEqual(message, testMessage);
        }
Example #9
0
        public void UserDisplayMessage_ReturnInvalidErrorMessage()
        {
            //Arrange
            var testMessage = SystemConstants.INVALID_ERROR_CODE_MESSAGE;
            //Act
            var message = RapidClientFactory.UserDisplayMessage("blahblah", "en");

            //Assert
            Assert.AreEqual(message, testMessage);
        }
Example #10
0
        public void UserDisplayMessage_ReturnDefaultEnglishLanguage()
        {
            //Arrange
            var testMessage = "Invalid TransactionType, account not certified for eCome only MOTO or Recurring available";
            //Act
            var message1 = RapidClientFactory.UserDisplayMessage("V6010", "de");
            var message2 = RapidClientFactory.UserDisplayMessage("V6010", "blahblah");

            //Assert
            Assert.AreEqual(message1, testMessage);
            Assert.AreEqual(message2, testMessage);
        }
Example #11
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());
        }
Example #13
0
        private PaymentResponse ProcessPayResponse(CreateTransactionResponse parResponse)
        {
            var response = new PaymentResponse();

            response.Result = ServiceResult.Error;

            if (parResponse == null)
            {
                return(response);
            }

            if (parResponse.TransactionStatus == null)
            {
                return(response);
            }

            if (!parResponse.TransactionStatus.Status.HasValue)
            {
                return(response);
            }

            if (parResponse.TransactionStatus.Status.Value)
            {
                response.Result = ServiceResult.Success;
                return(response);
            }

            var errorCodes = new[]
            {
                "S5000", "S5085", "S5086", "S5087", "S5099", "F9023", "F7000", "D4403", "D4406", "D4459", "D4496",
                "S9996", "S9902", "S9992"
            };

            var codes = parResponse.TransactionStatus.ProcessingDetails.ResponseMessage.Split(new[] { ", " },
                                                                                              StringSplitOptions.None);

            foreach (var code in codes)
            {
                if (errorCodes.Contains(code))
                {
                    response.Result = ServiceResult.Error;
                }
                response.Errors.Add(RapidClientFactory.UserDisplayMessage(code, "EN"));
            }
            return(response);
        }
        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));
        }
Example #15
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));
        }
        public JsonResult VerifyAccessCode(string accessCode)
        {
            try
            {
                var response = GeteWayClient().QueryTransaction(accessCode);
                if (response.Transaction == null)
                {
                    var _returnMessage = "success" + SharedService.GenerateCoupon(6).ToUpper();
                    return(Json(_returnMessage, JsonRequestBehavior.AllowGet));
                }
                var returnMessage = string.Empty;
                if (response.TransactionStatus.Status != null && (bool)response.TransactionStatus.Status)
                {
                    returnMessage = "success" + response.TransactionStatus.TransactionID;
                }
                else
                {
                    var errorCodes = response.TransactionStatus.ProcessingDetails.ResponseMessage.Split(new[] { ", " }, StringSplitOptions.None);

                    returnMessage = errorCodes.Aggregate(returnMessage, (current, errorCode) => current + ("Response Message: " + RapidClientFactory.UserDisplayMessage(errorCode, "EN")));
                }
                return(Json(returnMessage, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Example #17
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);
            }
        }
Example #18
0
 protected IRapidClient CreateRapidApiClient()
 {
     return(RapidClientFactory.NewRapidClient(APIKEY, PASSWORD, ENDPOINT));
 }