I use SoapUI to test CyberSource Payment API. https://sandbox.api.visa.com/cybersource/payments/v1/authorizations.
I got the error Code 9159."Token validation failed" . Could you help me ?
===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 = 'MyAPIKey"
def sharedSecret ="MysharedSecret"
def URI = "payments/v1/authorizations"
def QS = "apikey="+APIKey
def timeStampUTC = String.valueOf(System.currentTimeMillis().intdiv(1000L))
def payload = ""
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)
=========================
Hello Rey,
The error you are getting will be shown when the x-pay-token sent in the header is invalid.
Few things to note while generating token:
Note:
For Flex Keys resource we have to send xpaytoken
https://sandbox.api.visa.com/cybersource/payments/flex/v1/keys?apikey={apikey}
for flex Tokens there will be no xpaytoken
https://sandbox.api.visa.com/cybersource/payments/flex/v1/tokens
Try this out and keep me updated!
I still got the same problem When I use SoapUI.
I downloaded Pyhton sample code to run nosetests. Token Valid is ok.(That mean the value of Apikey, Shared Secret is correct).
Could you help me to view attach file(it it SoapUI screen),Groovy code ?
Thanks !