public void VerifyGeneratedChecksum() { // Arrange var payGateReturn = new PayGateReturn(); payGateReturn.SetPassPhrase("secret"); Dictionary <string, string> formCollection = new Dictionary <string, string>(); formCollection.Add("PAYGATE_ID", "10011072130"); formCollection.Add("PAY_REQUEST_ID", "26F1EE9D-FB68-D6C2-5D36-ADA8C5F88BC9"); formCollection.Add("TRANSACTION_STATUS", "1"); formCollection.Add("REFERENCE", "PayGate Test"); payGateReturn.FromFormCollection(formCollection); // Act var checksum = payGateReturn.GetCalculatedChecksum(formCollection["PAYGATE_ID"], formCollection["PAY_REQUEST_ID"], formCollection["REFERENCE"]); // Assert Assert.AreEqual("2fae4c5cde9ac8ed70f769c3ff843d72", checksum); }
public ActionResult Return([ModelBinder(typeof(PayGateReturnModelBinder))] PayGateReturn payGateReturnViewModel) { payGateReturnViewModel.SetPassPhrase(payGateSettings.PayGateKey); var calculatedChecksum = payGateReturnViewModel.GetCalculatedChecksum(payGateSettings.PayGateID, Session["PAY_REQUEST_ID"].ToString(), Session["REFERENCE"].ToString()); if (calculatedChecksum != payGateReturnViewModel.CHECKSUM) { // TODO: Add proper error handling. Error model? return(View("Error")); } string message = string.Empty; switch (payGateReturnViewModel.TRANSACTION_STATUS) { case TransactionStatus.NotDone: message = "Transaction not completed. Please try again."; break; case TransactionStatus.Approved: return(View("Success")); case TransactionStatus.Declined: message = "Transaction declined. Please try again."; break; case TransactionStatus.Cancelled: message = "Transaction has been cancelled. Please try again."; break; case TransactionStatus.UserCancelled: message = "Transaction has been cancelled by the user."; break; } ViewBag.Message = message; return(View("Failure")); }