cancel
Showing results for 
Search instead for 
Did you mean: 

Missing or invalid token

I am evaluating Authorize.Net as a likely solution for initial and re-curing billing for my Saas application. I have been putting together a proof of concept for my manager. It is an ASP.Net WinForms app. I have been following the examples from the csharp_cim and hostedProfileManage downloads. Also with help from the documentation I've been able to get most everything working in a suprisingly small amount of time. I am however having an issue getting the pop-up to display the users profile to enter payment options. I have implemented it per the hostedProfileManage  example and I am generating the token per the csharp_cim example. When the popup displays it gives me the error "Missing or invalid token." I have verified that the token is populated in the hidden form per the example and that the token is recently generated. I noticed that the token that I get is about half as long as the token that was pre-populated in the example, I'm not sure if that's normal.

 

Any advise you can offer will be greatly appreciated.

dscott_amt
Member
1 ACCEPTED SOLUTION

Accepted Solutions

Question. So you did uncomment the line?

AuthorizeNetPopup.options.useTestEnvironment = true;

2. Have you debug the getToken and copy and paste the result to the examplePage.html?

3. Make sure there is no space between the double quote for the Token hidden field.

 

It work for me with your code. I copied your code to the sample code for C# soap cim. Updated the web reference, call your method with my test loginID, Key and custprofid. and copy and paste the resp.token to the examplePage.html and uncomment the usetestenvironment = true line. Run the html in IE and it work.

 

 

View solution in original post

6 REPLIES 6

Since the token required the loginID and transactionKey. Maybe it enter wrong? or it try to get it from the wrong URL(sandbox vs production)?

RaynorC1emen7
Expert

Here is the code that I am using. It seems to work correctly. I get a response code OK and a token returns. I steped through the javascript to ensure that it is setting:

 

form.action = "https://test.authorize.net/profile/"+ opt.action;

 

and that the value of hdnToken in the form is set to what was returned by the GetToken function.

opt.action is set to "manage".

 

private string GetToken(long custProfId )
{
    CustomerProfileWS.Service service = new CustomerProfileWS.Service();
    service.Url = "https://apitest.authorize.net/soap/v1/Service.asmx";

    CustomerProfileWS.MerchantAuthenticationType auth = new CustomerProfileWS.MerchantAuthenticationType();
    auth.name = "MY_API_LOGIN_ID";
    auth.transactionKey = "MY_TRANSACTION_KEY";

    CustomerProfileWS.GetHostedProfilePageResponseType resp = service.GetHostedProfilePage(auth, custProfId, null);

    if (resp.resultCode == AuthorizeNetSandbox.CustomerProfileWS.MessageTypeEnum.Ok)
    {
        return resp.token;
    }
    else
    {
        foreach (CustomerProfileWS.MessagesTypeMessage message in resp.messages)
            System.Diagnostics.Debug.WriteLine(string.Format("[Code: {0}] {1}", message.code, message.text));
    }
    return string.Empty;
}

 

Any additional help will be greatly appreciated.

Question. So you did uncomment the line?

AuthorizeNetPopup.options.useTestEnvironment = true;

2. Have you debug the getToken and copy and paste the result to the examplePage.html?

3. Make sure there is no space between the double quote for the Token hidden field.

 

It work for me with your code. I copied your code to the sample code for C# soap cim. Updated the web reference, call your method with my test loginID, Key and custprofid. and copy and paste the resp.token to the examplePage.html and uncomment the usetestenvironment = true line. Run the html in IE and it work.

 

 

Forgot to tell you, the token I got is shorter than the one in the examplePage.html.

Run a few more test. space before and after in the token field didn't cause an error. Did you change the letter case in token? or remove char like the forward slash "/"?

I hadn't tried copying the token into the examplepage.html. That worked. This tells me that I must have not copied something correctly from the example page to my application. Thank you so much for the suggestion!