@Renaissance
public class HomeController : Controller
{
IHostingEnvironment _env;
IConfiguration _config;
public HomeController(IHostingEnvironment env, IConfiguration config)
{
_env = env;
_config = config;
}
public IActionResult Index()
{
customerAddressType BillTo = new customerAddressType
{
address = "120 Sceneic Drive",
city = "Twinsburg ",
state = "OH",
zip = "14326",
firstName = "Sam",
lastName = "Donald",
country = "USA",
phoneNumber = "4454546589",
};
int CreditCardTransactionID = 121212;
decimal Amount = 100;
int OrderID = 1234567;
string IPAddress = "127.0.0.1";
int CustomerID = 5129999;
transactionTypeEnum transtype = transactionTypeEnum.authCaptureTransaction;
merchantAuthenticationType mat = new merchantAuthenticationType
{
name = _config.GetValue<string>("Authorize.Net:TransactionKey"),
ItemElementName = ItemChoiceType.transactionKey,
Item = _config.GetValue<string>("Authorize.Net:Password"),
};
string CancelURL;
string ReturnURL;
string URL;
string CommunicatorURL;
string PaymentPageURL;
string ShowReceipt = "false";
string HostURL = _config.GetValue<string>("RootURL");
switch ((_env.EnvironmentName ?? "").Trim().ToUpper())
{
case "DEVELOPMENT":
string NGrokPath = $"{HostURL}/Home";
CommunicatorURL = $"{NGrokPath}/Communicator";
CancelURL = $"{NGrokPath}/Cancel";
ReturnURL = $"{NGrokPath}/Returning";
PaymentPageURL = $"{NGrokPath}/";
URL = $"{NGrokPath}";
break;
case "STAGING":
case "PRODUCTION":
CommunicatorURL = $"{HostURL}/Home/Communicator";
CancelURL = $"{HostURL}/Home/Cancel";
ReturnURL = $"{HostURL}/Home/Returning";
PaymentPageURL = $"{HostURL}/";
ShowReceipt = "true";
break;
default:
return Error();
}
HostedPayment hp = new HostedPayment(mat, AuthorizeNet.Environment.SANDBOX);
HostedToken ht = hp.AttemptTransaction(CreditCardTransactionID, Amount, OrderID, IPAddress, CustomerID, null, false, transtype, BillTo, ReturnURL, CancelURL, CommunicatorURL, PaymentPageURL, ShowReceipt);
return View(ht);
}
public IActionResult Cancel()
{
return Content("Cancelled");
}
public IActionResult Returning()
{
return Content("Done!");
}
public IActionResult Communicator()
{
return View();
}
[Route("/Home/Empty1")]
[Route("/Home/Home/Empty1")]
public IActionResult Empty1()
{
return View();
}
[HttpPost]
public IActionResult WebHook()
{
string s = "";
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
s = reader.ReadToEnd();
}
System.Diagnostics.Debug.WriteLine("##### " + s);
return Ok();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
I used the suggestion in this link for now as a workaround. Also I want the json result to be pushed to webhook, if you could share any thoughts about that that would be helpful.
https://stackoverflow.com/questions/43700622/how-to-implement-authorize-net-hosted-payments-iframe-l...
Thanks
Chitti