Visa Developer Community

Helper

Token Validation Failed

https://sandbox.api.visa.com/cybersource/v2/payments?apikey=ML0H1V41TFGN6FQQ4QJM21OIVovNYRupFrUkHbFj...
{"clientReferenceInformation": {"code": "TC50171_3"},"processingInformation": {"commerceIndicator": "internet"},"aggregatorInformation": {"subMerchant": {"cardAcceptorID": "1234567890","country": "US","phoneNumber": "650-432-0000","address1": "900 Metro Center","postalCode": "94404-2775","locality": "Foster City","name": "Visa Inc","administrativeArea": "CA","region": "PEN","email": "test@cybs.com"},"name": "V-Internatio","aggregatorID": "123456789"},"orderInformation": {"billTo": {"country": "US","lastName": "VDP","address2": "Address 2","address1": "201 S. Division St.","postalCode": "48104-2201","locality": "Ann Arbor","administrativeArea": "MI","firstName": "RTS","phoneNumber": "999999999","district": "MI","buildingNumber": "123","company": "Visa","email": "test@cybs.com"},"amountDetails": {"totalAmount": "102.21","currency": "USD"}},"paymentInformation": {"card": {"expirationYear": "2031","number": "5555555555554444","securityCode": "123","expirationMonth": "12","type": "002"}}}
CybersourcePayment
Response Status:
Unauthorized
Response Headers:
X-SERVED-BY: l55c010
X-CORRELATION-ID: 1534233003_630_89_l55c010_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
Pragma: no-cache
Connection: close
Content-Length: 112
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: application/json;charset=UTF-8
Date: Tue, 14 Aug 2018 07:50:03 GMT
Expires: -1
Server: Apache


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

 

 

 

 

 

5 REPLIES 5
Valued Supporter

Re: Token Validation Failed

Hi @Erfan

 

Thanks for reaching out. We are checking on our end. Please share the groovy script and SOAP UI Project to help debug further.

 

Thank you, 

Vaibhav 

 

 

Helper

Re: Token Validation Failed

Thank you for your support.

 

I have attached the groovy script and soap ui project. I got success messge for the visa hello word api. but in the case of cybersource payment i got the token validation failed message

Groovy script is as follows and SoapUI project link is click here

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 = 'ML0H1V41TFGN6FQQ4QJM21OIVovNYRupFrUkHbFjZZ8vftXxs'
def sharedSecret = 'Qa+Ik$0PhYWlnE+9qOy1qWgenxqU5CPZ@htRuz+2'
def URI = "/cybersource/v2/payments"
def QS = "apikey="+APIKey
def timeStampUTC = String.valueOf(System.currentTimeMillis().intdiv(1000L))
def payload = '{'+
   ' "clientReferenceInformation": {'+
   ' "code": "TC50171_3"'+
   '},'+
   '"processingInformation": {'+
   ' "commerceIndicator": "internet"'+
   '},'+
  ' "aggregatorInformation": {'+
      '"subMerchant": {'+
         '"cardAcceptorID": "1234567890",'+
         '"country": "US",'+
        ' "phoneNumber": "650-432-0000",'+
         ' "address1": "900 Metro Center",'+
         '"postalCode": "94404-2775",'+
         '"locality": "Foster City",'+
         '"name": "Visa Inc",'+
         '"administrativeArea": "CA",'+
         '"region": "PEN",'+
         '"email": "test@cybs.com"'+
      '},'+
      '"name": "V-Internatio",'+
      '"aggregatorID": "123456789"'+
   '},'+
   '"orderInformation": {'+
      '"billTo": {'+
         '"country": "US",'+
         '"lastName": "VDP",'+
         '"address2": "Address 2",'+
         '"address1": "201 S. Division St.",'+
         '"postalCode": "48104-2201",'+
         '"locality": "Ann Arbor",'+
         '"administrativeArea": "MI",'+
         '"firstName": "RTS",'+
         '"phoneNumber": "999999999",'+
         '"district": "MI",'+
         '"buildingNumber": "123",'+
         '"company": "Visa",'+
         '"email": "test@cybs.com"'+
      '},'+
      '"amountDetails": {'+
         '"totalAmount": "102.21",'+
         '"currency": "USD"'+
      '}'+
   '},'+
   '"paymentInformation": {'+
      '"card": {'+
         '"expirationYear": "2031",'+
         '"number": "5555555555554444",'+
         '"securityCode": "123",'+
         '"expirationMonth": "12",'+
         '"type": "002"'+
      '}'+
   '}'+
'}'
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)

Thanks in advance.

Helper

Re: Token Validation Failed

Thank you for your support.

 

I have attached the groovy script and soap ui project. I got success messge for the visa hello word api. but in the case of cybersource payment i got the token validation failed message

Groovy script is as follows and SoapUI project link is click here

For groovy script please past from here in soap ui project

 

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 = 'ML0H1V41TFGN6FQQ4QJM21OIVovNYRupFrUkHbFjZZ8vftXxs'
def sharedSecret = 'Qa+Ik$0PhYWlnE+9qOy1qWgenxqU5CPZ@htRuz+2'
def URI = "/cybersource/v2/payments"
def QS = "apikey="+APIKey
def timeStampUTC = String.valueOf(System.currentTimeMillis().intdiv(1000L))
def payload = '{'+
   ' "clientReferenceInformation": {'+
   ' "code": "TC50171_3"'+
   '},'+
   '"processingInformation": {'+
   ' "commerceIndicator": "internet"'+
   '},'+
  ' "aggregatorInformation": {'+
      '"subMerchant": {'+
         '"cardAcceptorID": "1234567890",'+
         '"country": "US",'+
        ' "phoneNumber": "650-432-0000",'+
         ' "address1": "900 Metro Center",'+
         '"postalCode": "94404-2775",'+
         '"locality": "Foster City",'+
         '"name": "Visa Inc",'+
         '"administrativeArea": "CA",'+
         '"region": "PEN",'+
         '"email": "test@cybs.com"'+
      '},'+
      '"name": "V-Internatio",'+
      '"aggregatorID": "123456789"'+
   '},'+
   '"orderInformation": {'+
      '"billTo": {'+
         '"country": "US",'+
         '"lastName": "VDP",'+
         '"address2": "Address 2",'+
         '"address1": "201 S. Division St.",'+
         '"postalCode": "48104-2201",'+
         '"locality": "Ann Arbor",'+
         '"administrativeArea": "MI",'+
         '"firstName": "RTS",'+
         '"phoneNumber": "999999999",'+
         '"district": "MI",'+
         '"buildingNumber": "123",'+
         '"company": "Visa",'+
         '"email": "test@cybs.com"'+
      '},'+
      '"amountDetails": {'+
         '"totalAmount": "102.21",'+
         '"currency": "USD"'+
      '}'+
   '},'+
   '"paymentInformation": {'+
      '"card": {'+
         '"expirationYear": "2031",'+
         '"number": "5555555555554444",'+
         '"securityCode": "123",'+
         '"expirationMonth": "12",'+
         '"type": "002"'+
      '}'+
   '}'+
'}'
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)

Thanks in advance

Helper

Re: Token Validation Failed

Thank you for your support.

 

I have attached the groovy script and soap ui project. I got success messge for the visa hello word api. but in the case of cybersource payment i got the token validation failed message

Groovy script is as follows and SoapUI project link is http://203.223.132.108:6012/tempfile/cybersourcepayment-soapui-project.xml

For groovy script please past from here in soap ui project

 

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 = 'ML0H1V41TFGN6FQQ4QJM21OIVovNYRupFrUkHbFjZZ8vftXxs'
def sharedSecret = 'Qa+Ik$0PhYWlnE+9qOy1qWgenxqU5CPZ@htRuz+2'
def URI = "/cybersource/v2/payments"
def QS = "apikey="+APIKey
def timeStampUTC = String.valueOf(System.currentTimeMillis().intdiv(1000L))
def payload = '{'+
   ' "clientReferenceInformation": {'+
   ' "code": "TC50171_3"'+
   '},'+
   '"processingInformation": {'+
   ' "commerceIndicator": "internet"'+
   '},'+
  ' "aggregatorInformation": {'+
      '"subMerchant": {'+
         '"cardAcceptorID": "1234567890",'+
         '"country": "US",'+
        ' "phoneNumber": "650-432-0000",'+
         ' "address1": "900 Metro Center",'+
         '"postalCode": "94404-2775",'+
         '"locality": "Foster City",'+
         '"name": "Visa Inc",'+
         '"administrativeArea": "CA",'+
         '"region": "PEN",'+
         '"email": "test@cybs.com"'+
      '},'+
      '"name": "V-Internatio",'+
      '"aggregatorID": "123456789"'+
   '},'+
   '"orderInformation": {'+
      '"billTo": {'+
         '"country": "US",'+
         '"lastName": "VDP",'+
         '"address2": "Address 2",'+
         '"address1": "201 S. Division St.",'+
         '"postalCode": "48104-2201",'+
         '"locality": "Ann Arbor",'+
         '"administrativeArea": "MI",'+
         '"firstName": "RTS",'+
         '"phoneNumber": "999999999",'+
         '"district": "MI",'+
         '"buildingNumber": "123",'+
         '"company": "Visa",'+
         '"email": "test@cybs.com"'+
      '},'+
      '"amountDetails": {'+
         '"totalAmount": "102.21",'+
         '"currency": "USD"'+
      '}'+
   '},'+
   '"paymentInformation": {'+
      '"card": {'+
         '"expirationYear": "2031",'+
         '"number": "5555555555554444",'+
         '"securityCode": "123",'+
         '"expirationMonth": "12",'+
         '"type": "002"'+
      '}'+
   '}'+
'}'
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)

Thanks in advance

Highlighted
Valued Supporter

Re: Token Validation Failed

Hello @Erfan

 

Please update the groovy script with the below and add the Request Payload and test.

Request Payload

 

{ "clientReferenceInformation":   {   "code":   "TC50171_3"   },  "processingInformation":   {   "commerceIndicator":   "internet"   },"aggregatorInformation": { "subMerchant":  { "cardAcceptorID": "1234567890", "country": "US",  "phoneNumber": "650-432-0000", "address1":"900 Metro  Center", "postalCode":  "94404-2775", "locality": "Foster  City", "name": "Visa  Inc", "administrativeArea":  "CA", "region":"PEN", "email": "test@cybs.com"  }, "name": "V-Internatio", "aggregatorID":  "123456789" }, "orderInformation": {  "billTo": { "country":"US", "lastName": "VDP", "address2": "Address 2", "address1": "201 S. Division St.", "postalCode": "48104-2201", "locality": "Ann Arbor","administrativeArea": "MI", "firstName": "RTS", "phoneNumber": "999999999", "district": "MI", "buildingNumber": "123", "company": "Visa","email":  "test@cybs.com" },  "amountDetails":  { "totalAmount":  "102.21",  "currency": "USD"  } },  "paymentInformation":  { "card":  {"expirationYear":  "2031",  "number":   "5555555555554444",  "securityCode":  "123",  "expirationMonth":  "12",  "type":   "002"  }  }  }

 

Groovy Script

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 = 'ML0H1V41TFGN6FQQ4QJM21OIVovNYRupFrUkHbFjZZ8vftXxs'

def sharedSecret = 'Qa+Ik$0PhYWlnE+9qOy1qWgenxqU5CPZ@htRuz+2'

def URI = "v2/payments"

def QS = "apikey="+APIKey

def timeStampUTC = String.valueOf(System.currentTimeMillis().intdiv(1000L))

def payload = '{ "clientReferenceInformation":   {   "code":   "TC50171_3"   },  "processingInformation":   {   "commerceIndicator":   "internet"   },"aggregatorInformation": { "subMerchant":  { "cardAcceptorID": "1234567890", "country": "US",  "phoneNumber": "650-432-0000", "address1":"900 Metro  Center", "postalCode":  "94404-2775", "locality": "Foster  City", "name": "Visa  Inc", "administrativeArea":  "CA", "region":"PEN", "email": "test@cybs.com"  }, "name": "V-Internatio", "aggregatorID":  "123456789" }, "orderInformation": {  "billTo": { "country":"US", "lastName": "VDP", "address2": "Address 2", "address1": "201 S. Division St.", "postalCode": "48104-2201", "locality": "Ann Arbor","administrativeArea": "MI", "firstName": "RTS", "phoneNumber": "999999999", "district": "MI", "buildingNumber": "123", "company": "Visa","email":  "test@cybs.com" },  "amountDetails":  { "totalAmount":  "102.21",  "currency": "USD"  } },  "paymentInformation":  { "card":  {"expirationYear":  "2031",  "number":   "5555555555554444",  "securityCode":  "123",  "expirationMonth":  "12",  "type":   "002"  }  }  }'

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)

 

Thank you, 

Vaibhav