Authorize.net Integration eCommerce Payment Gateway ( Direct Post Method New! )
https://developer.authorize.net/integration/fifteenminutes/csharp
These steps assume that your web server is on the public internet and can be accessed via a domain name or IP address.
Step 1:Sign up for a Test Account.
Sign up for a test account to obtain an API Login ID and Transaction Key. These keys will authenticate requests to the payment gateway.
Step 2: Download the Authorize.Net C# SDK and include it in your project
Download the SDK
Create a new ASP.NET MVC application and add a reference to the AuthorizeNET.dll from the SDK
Step 3: Modify web.config.
Add the AuthorizeNET.Helpers namespace to the web.config, under system.web/pages:
...
Step 4: Create a checkout form that posts directly to Authorize.Net
Add the following code to the Home/Index View - this will create a form which will submit a test transaction to Authorize.Net (with hardcoded values). This code uses the SDKs CheckoutFormBuilder to create the form for you - just include your API login and Transaction Key:
In this code, the CheckoutFormBuilder is creating the form that will post to AuthorizeNET, setting the "TestMode" to true. We're sending along an additional piece of information here as well: an order id. This isn't required by the API, but let's you identify the order when we get the response.
Step 5: Create an Action to handle the response from Authorize.Net.
This example uses ASP.NET MVC - if you're using ASP.NET WebForms, you can put this code on PageLoad().
In the above code we passed in the URL "http://YOURSERVER.com/home/sim", so we need to create an Action called "Sim" in our application's HomeController. The form POST from Authorize.Net will include all the transaction information including an MD5 hash which we can use to validate the post's origin.
Open up the HomeController and paste the code below:
[HttpPost] public ActionResult Sim(FormCollection post) { var response = new AuthorizeNET.SIMResponse(post); //first order of business - validate that it was Auth.net that posted this using the //MD5 hash that was passed back to us var isValid = response.Validate("YOUR_API_LOGIN_ID", "YOUR_API_LOGIN_ID"); //if it's not valid - just send them to the home page. Don't throw - that's how //hackers figure out what's wrong :) if (!isValid) return Redirect("/"); //the URL to redirect to- this MUST be absolute var returnUrl = "http://YOUR_SERVER.com/?m="+response.Message; return Content(AuthorizeNET.Helpers.CheckoutFormBuilders.Redirecter(returnUrl)); }This uses SDK classes to parse the response and validate it's origin using the MD5 hash.
An important thing to understand at this point is that Authorize.Net will take whatever content we respond with and it will display it on their server, to our user. So if we simply returned the string "Thank You!" - that's what would be displayed to the user. This response, however, is sent from the Authorize.Net server - not our own - and you can see this if you look at the URL in the address bar upon completion of the transaction. Since that's not what we want, we send a response that causes the user to be redirected to a url on our sever.
It's important to keep in mind that this whole process is "out of session" - which means your user session no longer exists in this response context. The user, in this case, is the Authorize.Net server in that it's notifying our server of a transaction - it has no notion of your current user's session - so our next task is to return the information from Authorize.Net to the current user - and we do this by redirecting away from Authorize.Net using some javascript. In the last line, we're using the SDK to generate this javascript.
For the simplicity of this example, we're redirecting back to the home page of our application so we can see the result.
There are a few considerations here that you will need to manage as a developer - specifically how you manage the order data, and how you display the response from Authorize.Net to the user.
Step 6: Add some code to handle the redirect from Authorize.Net
Add some code to receive the message in the HomeController, Index action. The sample application provides a more complete way of handling the response from Authorize.Net - here we just show the response. To do that, add some code to the Index action to pull the message from the URL:
public ActionResult Index () { ViewData["message"] = Request.QueryString["m"] ?? ""; return View (); }Step 7: Test your HTML form and verify the transaction.
Visit the new payment experience you've just built. Complete the payment form.
Select "Visa" and enter the test credit card number 4111111111111111, any expiration date (MMYY) in the future (such as "1120"), and hit "Submit".
Verify payment transaction success on your transaction report.
Learn More
To accept real payments, you'll need a merchant account. Learn more or apply for a merchant account
These steps assume that your web server is on the public internet and can be accessed via a domain name or IP address.
Step 1:Sign up for a Test Account.
Sign up for a test account to obtain an API Login ID and Transaction Key. These keys will authenticate requests to the payment gateway.
Step 2: Download the Authorize.Net C# SDK and include it in your project
Download the SDK
Create a new ASP.NET MVC application and add a reference to the AuthorizeNET.dll from the SDK
Step 3: Modify web.config.
Add the AuthorizeNET.Helpers namespace to the web.config, under system.web/pages:
Step 4: Create a checkout form that posts directly to Authorize.Net
Add the following code to the Home/Index View - this will create a form which will submit a test transaction to Authorize.Net (with hardcoded values). This code uses the SDKs CheckoutFormBuilder to create the form for you - just include your API login and Transaction Key:
In this code, the CheckoutFormBuilder is creating the form that will post to AuthorizeNET, setting the "TestMode" to true. We're sending along an additional piece of information here as well: an order id. This isn't required by the API, but let's you identify the order when we get the response.
Step 5: Create an Action to handle the response from Authorize.Net.
This example uses ASP.NET MVC - if you're using ASP.NET WebForms, you can put this code on PageLoad().
In the above code we passed in the URL "http://YOURSERVER.com/home/sim", so we need to create an Action called "Sim" in our application's HomeController. The form POST from Authorize.Net will include all the transaction information including an MD5 hash which we can use to validate the post's origin.
Open up the HomeController and paste the code below:
[HttpPost] public ActionResult Sim(FormCollection post) { var response = new AuthorizeNET.SIMResponse(post); //first order of business - validate that it was Auth.net that posted this using the //MD5 hash that was passed back to us var isValid = response.Validate("YOUR_API_LOGIN_ID", "YOUR_API_LOGIN_ID"); //if it's not valid - just send them to the home page. Don't throw - that's how //hackers figure out what's wrong :) if (!isValid) return Redirect("/"); //the URL to redirect to- this MUST be absolute var returnUrl = "http://YOUR_SERVER.com/?m="+response.Message; return Content(AuthorizeNET.Helpers.CheckoutFormBuilders.Redirecter(returnUrl)); }This uses SDK classes to parse the response and validate it's origin using the MD5 hash.
An important thing to understand at this point is that Authorize.Net will take whatever content we respond with and it will display it on their server, to our user. So if we simply returned the string "Thank You!" - that's what would be displayed to the user. This response, however, is sent from the Authorize.Net server - not our own - and you can see this if you look at the URL in the address bar upon completion of the transaction. Since that's not what we want, we send a response that causes the user to be redirected to a url on our sever.
It's important to keep in mind that this whole process is "out of session" - which means your user session no longer exists in this response context. The user, in this case, is the Authorize.Net server in that it's notifying our server of a transaction - it has no notion of your current user's session - so our next task is to return the information from Authorize.Net to the current user - and we do this by redirecting away from Authorize.Net using some javascript. In the last line, we're using the SDK to generate this javascript.
For the simplicity of this example, we're redirecting back to the home page of our application so we can see the result.
There are a few considerations here that you will need to manage as a developer - specifically how you manage the order data, and how you display the response from Authorize.Net to the user.
Step 6: Add some code to handle the redirect from Authorize.Net
Add some code to receive the message in the HomeController, Index action. The sample application provides a more complete way of handling the response from Authorize.Net - here we just show the response. To do that, add some code to the Index action to pull the message from the URL:
public ActionResult Index () { ViewData["message"] = Request.QueryString["m"] ?? ""; return View (); }Step 7: Test your HTML form and verify the transaction.
Visit the new payment experience you've just built. Complete the payment form.
Select "Visa" and enter the test credit card number 4111111111111111, any expiration date (MMYY) in the future (such as "1120"), and hit "Submit".
Verify payment transaction success on your transaction report.
Learn More
To accept real payments, you'll need a merchant account. Learn more or apply for a merchant account
Comments
Shopping Cart Software Solutions
mentalist
yasmin Kaufen
meal kits Making cooking a little easier. It's hard, it takes time and who's got the time after a long day of work, looking after kids and being on your feet all day ? I bet you don't and neither do I.. making cheap and tasty modern day meal kits the new normal among all the changes going on in our world today.
BUY SPOTIFY PLAYS REAL PLAYS TO BOOST YOUR MUSIC.
We will promote your tracks and give you very good promotion Buy spotify plays