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 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 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()); }
public void UserDisplayMessage_ReturnInvalidErrorMessage() { //Arrange var testMessage = SystemConstants.INVALID_ERROR_CODE_MESSAGE; //Act var message = RapidClientFactory.UserDisplayMessage("blahblah", "en"); //Assert Assert.AreEqual(message, testMessage); }
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); }
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); }
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()); }
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)); }
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)); } }