Token Validation Failed ( code 9159 ) for x-pay-token value

Solved! Go to solution
SergiyK
Helper

Token Validation Failed ( code 9159 ) for x-pay-token value

I complete all the steps from getting started guide for SOAPUI but I'm getting the "Token validation failed" error when I make a request to the Visa Payments (CyberSource) API ( Create a Sales Transaction ).

 

Here is my changed script and screen

Spoiler
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
def hmac(String secretKey, String data) {
Mac mac = Mac.getInstance("HmacSHA256")
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256")
mac.init(secretKeySpec)
byte[] digest = mac.doFinal(data.getBytes())
return digest
}
def APIKey = 'LT4TY1LKU0M4IJF5YPYU21IXNzxFihpY_9P_ga7Mhwc_D5iPQ'
def sharedSecret = 'kict5shRriA8IVW7Uhkdj/01znJ2Cky#5gk5nGe9'
def URI = 'payments/v1/sales'
def QS = "apikey="+APIKey
def timeStampUTC = String.valueOf(System.currentTimeMillis().intdiv(1000L))
def payload = "{\"payment\":{\"cnv\":\"111\",\"cardExpirationYear\":\"2019\",\"cardExpirationMonth\":\"10\",\"cardNumber\":\"4111111111111111\"};,\"currency\":\"USD\",\"amount\":\"1\"}"
def message = timeStampUTC + URI + QS + payload
def HMACDigest = hmac(sharedSecret,message)
def encodedDigest = HMACDigest.encodeHex().toString()
def XPayToken = "xv2:"+ timeStampUTC + ":" + encodedDigest
testRunner.testCase.setPropertyValue("xpayToken", XPayToken)
log.info(XPayToken)
Spoiler
Screenshot_1.png
Could someone kindly point out what I'm doing wrong?

 

5 REPLIES 5
ricardo_visa
Community Scholar

Re: Token Validation Failed ( code 9159 ) for x-pay-token value

Hi there,

We need your SOAPUI response and please give us more details on how xpay token has been generated.

Thank you,
Ricardo



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

Re: Token Validation Failed ( code 9159 ) for x-pay-token value

Here is raw response from SOAPUI

HTTP/1.1 401 Unauthorized
Server: Apache
X-SERVED-BY: l73c036
X-CORRELATION-ID: 1508741518_532_74_l73c036_VDP_ARM
X-APP-STATUS: 401
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=2592000;includeSubdomains
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: -1
Content-Security-Policy-Report-Only: default-src 'self' https://*.v.me https://*.visa.com;script-src 'self' 'unsafe-inline' 'unsafe-eval'  https://*.visa.com https://*.v.me;img-src 'self' https://*.v.me https://*.visa.com https://*.unica.com https://ad.doubleclick.net;style-src 'self' 'unsafe-inline' https://*.visa.com;object-src  https://*.v.me https://*.visa.com data:;report-uri /logging/logCSPReport;
X-Content-Security-Policy-Report-Only: default-src 'self' https://*.v.me https://*.visa.com;script-src 'self' 'unsafe-inline' 'unsafe-eval'  https://*.visa.com https://*.v.me;img-src 'self' https://*.v.me https://*.visa.com https://*.unica.com https://ad.doubleclick.net;style-src 'self' 'unsafe-inline' https://*.visa.com;object-src  https://*.v.me https://*.visa.com data:;report-uri /logging/logCSPReport;
X-WebKit-CSP-Report-Only: default-src 'self' https://*.v.me https://*.visa.com;script-src 'self' 'unsafe-inline' 'unsafe-eval'  https://*.visa.com https://*.v.me;img-src 'self' https://*.v.me https://*.visa.com https://*.unica.com https://ad.doubleclick.net;style-src 'self' 'unsafe-inline' https://*.visa.com;object-src  https://*.v.me https://*.visa.com data:;report-uri /logging/logCSPReport;
Content-Type: application/json;charset=UTF-8
Content-Length: 112
Date: Mon, 23 Oct 2017 06:51:58 GMT
Connection: keep-alive

{"responseStatus":{"code":"9159","severity":"ERROR","message":"Token validation failed","info":"","status":401}}

 and script from Getting Started Guide adapted to my case:

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
def hmac(String secretKey, String data) {
 Mac mac = Mac.getInstance("HmacSHA256")
 SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256")
 mac.init(secretKeySpec)
 byte[] digest = mac.doFinal(data.getBytes())
 return digest
} 
def APIKey = 'LT4TY1LKU0M4IJF5YPYU21IXNzxFihpY_9P_ga7Mhwc_D5iPQ'
def sharedSecret = 'kict5shRriA8IVW7Uhkdj/01znJ2Cky#5gk5nGe9'
def URI = 'payments/v1/sales'
def QS = "apikey="+APIKey
def timeStampUTC = String.valueOf(System.currentTimeMillis().intdiv(1000L))
def payload = "{\"payment\":{\"cnv\":\"111\",\"cardExpirationYear\":\"2019\",\"cardExpirationMonth\":\"10\",\"cardNumber\":\"4111111111111111\"};,\"currency\":\"USD\",\"amount\":\"1\"}"
def HMACDigest = hmac(sharedSecret, timeStampUTC + URI + QS + payload)
def encodedDigest = HMACDigest.encodeHex().toString()
def XPayToken = "xv2:"+ timeStampUTC + ":" + encodedDigest
testRunner.testCase.setPropertyValue("xpayToken", XPayToken)
log.info(XPayToken)
SergiyK
Helper

Re: Token Validation Failed ( code 9159 ) for x-pay-token value

Sample Code from Dashboard works fine,its just data from Test Data ( and from Api Exlorer too ) not fully match with responses ( only Success tests )

nono
Regular Visitor

Re: Token Validation Failed ( code 9159 ) for x-pay-token value

ok i found my mistake...

i need to set all in one line for json content to trigger the token generation

flomaya
Helper

Re: Token Validation Failed ( code 9159 ) for x-pay-token value

Hi, I have similar problem. Can you explain what do you mean by you "need to set all in one line for json content to trigger the token generation"?

Thanks.