Showing results for 
Search instead for 
Did you mean: 

How to redirect to Hosted Payment Page?



I'm trying to redirect to a hosted payment page using .net with c#. I have the basic app that is getting a token using 'getHostedPaymentPageResponse', and I'm putting the token received to a form and submitting the form to "" with POST method. But I keep getting "Missing or invalid token" error. Following is my code:



<form runat="server" action="" id="formAuthorizeNetTestPage" name="formAuthorizeNetTestPage" method="POST">
<input type="hidden" name="token" value="" runat="server" id="redirectToken"/>
<p>Customer ID: </p>
<asp:TextBox runat="server" ID="customerID"></asp:TextBox>
<p>Amount: </p>
<asp:TextBox runat="server" ID="amount_input"></asp:TextBox>
<asp:Button ID="Button1" OnClick="Button1_Click" runat="server" text="Pay"/>


Code Behind:

public void Button1_Click(object sender, EventArgs e)
System.Diagnostics.Debug.WriteLine("Hello, Button1 Clicked");
decimal amount = decimal.Parse(amount_input.Text);
string customerId = customerID.Text;
var ApiResponse = Run(LoginId, TransactionKey, amount, customerId, redirectToken, formAuthorizeNetTestPage, body_container);


public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount, string customerProfileId, System.Web.UI.HtmlControls.HtmlInputHidden token_input, System.Web.UI.HtmlControls.HtmlForm formAuthorizeNetTestPage, System.Web.UI.HtmlControls.HtmlGenericControl body_container)
System.Diagnostics.Debug.WriteLine("GetAnAcceptPaymentPage Sample");
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = ApiTransactionKey,

settingType[] settings = new settingType[]{
new settingType()
// More settings can be added here as and when required
settings[0] = new settingType();
settings[0].settingName = settingNameEnum.hostedProfileReturnUrl.ToString();
settings[0].settingValue = "";

var request = new getHostedProfilePageRequest();
request.customerProfileId = customerProfileId;
request.hostedProfileSettings = settings;

var controller = new getHostedProfilePageController(request);

// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();

// validate response
if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
System.Diagnostics.Debug.WriteLine("Message code : " + response.messages.message[0].code);
System.Diagnostics.Debug.WriteLine("Message text : " + response.messages.message[0].text);
System.Diagnostics.Debug.WriteLine("Token : " + response.token);
else if (response != null)
System.Diagnostics.Debug.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text);
System.Diagnostics.Debug.WriteLine("Failed to get hosted payment page");
token_input.Value = response.token;
formAuthorizeNetTestPage.Action = "";
body_container.Attributes.Add("onload", "document.getElementById('formAuthorizeNetTestPage').submit();");

return response;




Please read the steps in INTEGRATING THE FORM USING A REDIRECT section here:-

Authorize.Net Developer Authorize.Net Developer
Authorize.Net Developer

Thanks. I got it fixed. Obviously, the form was being submitted with a different token input name instead of just name="token".


How did you fix that exactly?

How did you fix that exactly?