Re: Token Validation Error

nickmaina
Regular Visitor

Token Validation Error

Literally spent more than 3 days just to call my first request after the hello world. Been getting

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

on CyberSource process payments endpoint.

Even tried to use SOAPUI but getting the 400 error.

{"responseStatus": {
   "code": "9501",
   "severity": "ERROR",
   "message": "Invalid input found, please correct the input data",
   "info": "",
   "status": "400"
}}

All this is just a copy paste from the api explorer.

My XPAY function

def x_pay_token(secret, resource_path, query_string, body=''):
    """Generates the XPayToken
    XPayToken = "xv2:"+ timestamp + ":" + SHA256HMAC(shared_secret, message)
    """
    if not isinstance(secret, bytes):
        secret = bytes(secret, encoding='utf8')

    timestamp = current_timestamp()
    
    # pre_hash_string = timestamp + resource_path + query_string + request_body
    pre_hash_string = (timestamp + resource_path +
                       query_string + body).rstrip().encode('utf-8')

    hash = hmac.new(secret, msg=pre_hash_string,
                    digestmod=hashlib.sha256).hexdigest()
    return 'xv2:' + timestamp + ':' + hash

The request data am passing

{
"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.00",
"currency": "USD"
}
},
"paymentInformation": {
"card": {
"expirationYear": "2031",
"number": "5555555555554444",
"securityCode": "123",
"expirationMonth": "12",
"type": "002"
}
}
}

My Header

POST https://sandbox.api.visa.com/cybersource/v2/payments?apikey=UZMCW8ZFX8W6MOG1QEET21v6E7n-DnQUEbvmQ46De-v4CQPgQ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
x-pay-token: xv2:1518988231:bb2115c5ee971fb1ca10bcfe76d65db929c6655bde52b203205f234772bd4307
Content-Length: 1033
Host: sandbox.api.visa.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

 

4 REPLIES 4
vkamboj
Community Moderator

Re: Token Validation Error

Hi Nick, 

 

Thank you for your inquiry. I am reviewing the error you have received; I will get back to you soon. 

 

Thanks, 

Vaibhav

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

Re: Token Validation Error

Hi, 

 

Thank you for your patience. Please use the following uri in the token generation: 

def URI = "v2/payments" instead of def URI = “cybersource/v2/payments”

 

Thank you, 

Vaibhav 

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

Re: Token Validation Error

 

This is now the response.


{
"ID": null,
"status": "500",
"statusInformation": {
"reason": "SYSTEM_ERROR",
"message": "Request failed due to unknown system error."
},
"submitTimeUTC": "2018-02-21T08:12:34Z"
}

 Refernces: https://community.developer.visa.com/t5/Visa-Developer-Capabilities/Cybersource-Payments-API-V2-Issu...

 

We even tried to use the github sample codes and just changed the api keys and secret in config file and it still fails.

vkamboj
Community Moderator

Re: Token Validation Error

Hi Nick, 

 

The recommendation is to change only the URI used for the token not the URI to which submit the request. 

 

Thank you, 

Vaibhav

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