Re: Payment Post Request is not working

vyasnidhi
Dabbler

Payment Post Request is not working

Hi Team

 

We have request to post payment to cyber source. We have successfully setup our merchant account, when I'm sending the GET request to access the customer it is working fine. See the request below : 

String url = 'https://apitest.cybersource.com/tms/v2/customers/138895A53E3CDBA7E063AF598E0AD556';Map<String, String> headers = new Map<String, String>();
headers.put('Content-Type', 'application/json');
headers.put('Date', Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z'));String apiKey = '082ee2dc-675d-4263-9d98-742e511e22d9';
String secretKey = 'kVBkeMo4tjLCM+xUNjylPDbhbMSR2IsQUOfwl/NpBLc=';HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('content-type', 'application/json;charset=UTF-8');
req.setHeader('date', Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z'));
        req.setHeader('host', 'apitest.cybersource.com');
        req.setHeader('v-c-merchant-id', 'allcloud_1709815830');
req.setHeader('Signature', 'keyid="082ee2dc-675d-4263-9d98-742e511e22d9", algorithm="HmacSHA256", headers="host request-target v-c-merchant-id", signature="sviUy/bV+gYkNJyMWVY66uc2VnqFC/7zD1CeRwmmBQ0="');
req.setHeader('digest','');Http http = new Http();
HttpResponse res = http.send(req);
System.debug('res.getBody()'+res.getBody());
System.debug('res.getStatusCode()'+res.getStatusCode());
System.debug('res.getStatus()'+res.getStatus());

 

But when i'm trying to POST payment to Cybersource I'm getting 401 Authentication Failed error. 

See the request below : 

 

String reqBody = '{'+
' \"clientReferenceInformation\": {'+
' \"code\": \"TC50171_3\"'+
' },'+
' \"paymentInformation\": {'+
' \"card\": {'+
' \"number\": \"4111111111111111\",'+
' \"expirationMonth\": \"12\",'+
' \"expirationYear\": \"2031\"'+
' }'+
' },'+
' \"orderInformation\": {'+
' \"amountDetails\": {'+
' \"totalAmount\": \"102.21\",'+
' \"currency\": \"USD\"'+
' },'+
' \"billTo\": {'+
' \"firstName\": \"John\",'+
' \"lastName\": \"Doe\",'+
' \"address1\": \"1 Market St\",'+
' \"locality\": \"san francisco\",'+
' \"administrativeArea\": \"CA\",'+
' \"postalCode\": \"94105\",'+
' \"country\": \"US\",'+
' \"email\": \"test@cybs.com\",'+
' \"phoneNumber\": \"4158880000\"'+
' }'+
' }'+
'}';

String digestString = CybersourceUtility.generateDigest(reqBody);
system.debug(digestString);

String reqTarget = '/pts/v2/payments';
String signatureString = CybersourceUtility.generateSignature('post', reqTarget, digestString);
system.debug(signatureString);

String url = 'https://apitest.cybersource.com/pts/v2/payments';

Map<String, String> headers = new Map<String, String>();
headers.put('Content-Type', 'application/json');
headers.put('Date', Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z'));
String apiKey = '082ee2dc-675d-4263-9d98-742e511e22d9';
String secretKey = 'kVBkeMo4tjLCM+xUNjylPDbhbMSR2IsQUOfwl/NpBLc=';

HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('POST');
req.setBody(reqBody);
req.setHeader('content-type', 'application/json;charset=UTF-8');
req.setHeader('date', Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z'));
req.setHeader('host', 'apitest.cybersource.com');
req.setHeader('v-c-merchant-id', 'allcloud_1709815830');
req.setHeader('Signature', signatureString);
req.setHeader('digest',digestString);
Http http = new Http();
HttpResponse res = http.send(req);
System.debug('res.getBody()'+res.getBody());
System.debug('res.getStatusCode()'+res.getStatusCode());
System.debug('res.getStatus()'+res.getStatus());

 

Can you please help me to identify the issue?

3 REPLIES 3
SyedSa
Community Moderator

Re: Payment Post Request is not working

Hi @vyasnidhiThank you for reaching out. One of our agents will look into this and get back to you soon. Until then, if any community members know a solution, please feel free to reply to this thread.

vyasnidhi
Dabbler

Re: Payment Post Request is not working

Hi Team

 

Did you find any solution for this? It is a blocker for me. I'll really appreciate any help.

API_Products
Visa Developer Support Specialist

Re: Payment Post Request is not working

Hi @vyasnidhi,

 

Please reach out to the CyberSource team directly using the phone number below.

CyberSource Support
800-709-7779 




Thanks,

Diana H.



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