[Alias Directory Service] Error Token Validation 9159

fmeirinhos
New Contributor

[Alias Directory Service] Error Token Validation 9159

Hi all,

 

I'm using X-Pay-Token.

 

I'm trying to call an API from Alias Directory Service - GetPaymentCredentials.

I was able to call with success Hello World API - /vdp/helloworld. (for this one I had to remove /vdp/ to build this 'message = timestamp + resource_path + query_string + request_body' to generate X-Pay-Token).

 

But when I try to call GetPaymentCredentials - /aliasdirectory/v1/aliases/{aliasId}/paymentCredentials I get this error:

Note that in this case I'm not removing /aliasdirectory/ and that in both cases the X-Pay-Token is generated the same way.

 

<Fault xmlns="https://sandbox.api.visa.com/aliasdirectory/v1/aliases/e336c8c8-2945-4be3-af3e-951ec2d01219">
<responseStatus>
<code>9159</code>
<info/>
<message>Token Validation Failed</message>
<severity>ERROR</severity>
<status>401</status>
</responseStatus>
</Fault>

 

Let me know if you need any more information in order to help solve this issue.

 

Regards,

Fábio

4 REPLIES 4
jenn_kh
Community Moderator

Re: [Alias Directory Service] Error Token Validation 9159

Hi @fmeirinhosThank you for reaching out. One of our agents will look into this and get back to you soon. Until then, if any community member knows a solution, please feel free to reply in this thread. 

hamedkalbani
New Contributor

Re: [Alias Directory Service] Error Token Validation 9159

I have followed the guide "https://developer.visa.com/pages/working-with-visa-apis/x-pay-token" and used the shared secret. I still get 9159 Token Validation Failed.

obank
New Contributor

Re: [Alias Directory Service] Error Token Validation 9159

Hi,

Were you able to solve the problem?

API_Products
Visa Developer Support Specialist

Re: [Alias Directory Service] Error Token Validation 9159

Hey @fmeirinhos,

 

Based on the review of the developer.visa.com platform pages, here are the steps and clarifications to address the error encountered when attempting to call the Alias Directory Service - GetPaymentCredentials API using X-Pay-Token:

1. X-Pay-Token Generation:
- Ensure that you are generating the X-Pay-Token correctly. The token is generated using a combination of the timestamp, resource path, query string, and request body. The formula is:
```
message = timestamp + resource_path + query_string + request_body
```
- Make sure the timestamp is in UNIX format.

2. Resource Path:
- For the GetPaymentCredentials API, the resource path should include the full path including `/aliasdirectory`. For example:
```
resource_path = "/aliasdirectory/v1/aliases/{aliasId}/paymentCredentials"
```

3. Consistency in Token Generation:
- Ensure that the resource path used in the X-Pay-Token generation exactly matches the resource path used in the API request. Inconsistencies in the resource path can lead to token validation errors.

4. Example of Token Generation:
- Here is an example of how you might generate the X-Pay-Token:


```python
# START 
import hmac
import hashlib
import time

api_key = "your_api_key"
shared_secret = "your_shared_secret"
resource_path = "/aliasdirectory/v1/aliases/{aliasId}/paymentCredentials"
request_body = "your_request_body" # Replace with actual request body
timestamp = str(int(time.time()))
query_string = "" # Add query string if any

message = timestamp + resource_path + query_string + request_body
hash_value = hmac.new(shared_secret.encode(), message.encode(), hashlib.sha256).hexdigest()
x_pay_token = "xv2:" + timestamp + ":" + hash_value
# END 
```

 

5. Error Code 9159 - Token Validation Failed:
- The error code 9159 with the message "Token Validation Failed" indicates that the token generated does not match the expected token on the server side. This can be due to discrepancies in the data used to generate the token.

6. Troubleshooting Steps:
- Double-check the resource path, query string, and request body used in the token generation.
- Ensure that the timestamp is correct and in UNIX format.
- Verify that the shared secret and API key are correctly used in the token generation.

7. Further Assistance:
- If the issue persists, contact Visa Developer support for further assistance. Provide them with the detailed error message, the steps you have taken for troubleshooting, and any relevant code snippets used for token generation.

 

By following these steps and ensuring all aspects of the X-Pay-Token generation and API request are correctly configured, you should be able to resolve the error and successfully call the Alias Directory Service - GetPaymentCredentials API.




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.