Visa Developer Community

Highlighted
Regular Visitor

Cybersource - Problem with Payment API

Hi, my problem is with the Process a Payment API https://developer.visa.com/capabilities/cybersource/reference#cybersource__cybs_payments_v2__v2__pro...

 

When I create the X-Pay-Token following this tutorial https://developer.visa.com/pages/working-with-visa-apis/x-pay-token#generating_the_xpaytoken (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")
mac.init(secretKeySpec)
byte[] digest = mac.doFinal(data.getBytes())
return digest
}
def APIKey = ‘VALUE_OF_YOUR_API_KEY’
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)
log.info(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 https://community.developer.visa.com/t5/Visa-Developer-Capabilities/CyberSource-Payments-API-v2-paym... . If anyone could provide a Payment Sample (🤞) it would be spectacular 👌

 

 

 

1 REPLY 1
Highlighted
Visa Dev Moderator

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:
 
https://developer.cybersource.com 

 

Luckily, their site also provides an easy to use method to test their account credentials:
 
https://developer.cybersource.com/api/reference/api-reference.html 
 
Additionally, here are the following links for sample code:  https://github.com/CyberSource/cybersource-rest-samples-java/blob/master/src/main/java/samples/payme... 

 

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

 

CyberSource Support
800-709-7779 

 



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

Thanks,
Diana

Tags (2)