Re: Cybersource - Problem with Payment API

Regular Visitor

Cybersource - Problem with Payment API

Hi, my problem is with the Process a Payment API


When I create the X-Pay-Token following this tutorial (I realize that the GET method is used and I need to work with the POST method), so... when I faced with this script the things change: 

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")
byte[] digest = mac.doFinal(data.getBytes())
return digest
def sharedSecret = ‘VALUE_OF_YOUR_SHARED_SECRET’
def URI = "helloworld"
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)


The (def payload="") line in the code above need a new value (the body JSON request) , i try to add this value as string but doesn't work for me. My problem is similar to this . If anyone could provide a Payment Sample (🤞) it would be spectacular 👌




Visa Developer Support Specialist

Re: Cybersource - Problem with Payment API

Hey @robertraf,


I'm happy to help! Currently, the only method to properly query the CyberCource Payments sandbox is creating a merchant account directly with CyberSource: 


Luckily, their site also provides an easy to use method to test their account credentials: 
Additionally, here are the following links for sample code: 


We also have an expert team that manages questions specific to CyberSource. You can give them a call using the number below.


CyberSource Support




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