cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a javascript example that anyone can share for calling the Cybersource reporting apis?

I have the report download api working in node.js but I need it working client side using javascript.  I appears that I need the function buffer() in node.js to create the properly formatted byte array.  If you have a javascript example or can point me to how to convert to a byte array in javascript, that would be so helpful.

jburticus
Member
1 ACCEPTED SOLUTION

Accepted Solutions

To enable the report download API on the client-side with JavaScript, you can replicate the Node.js buffer() function using the ArrayBuffer in JavaScript. Here's a simple example:

 

// Node.js buffer function
const nodeBuffer = Buffer.from('YourData', 'utf-8');

// Equivalent ArrayBuffer in JavaScript
const arrayBuffer = new TextEncoder().encode('YourData');

// Converting ArrayBuffer to byte array (Uint8Array)
const byteArray = new Uint8Array(arrayBuffer);

// Now you can use 'byteArray' for further processing

 

This example showcases how to create a byte array in JavaScript, similar to the buffer() function in Node.js. You can adapt this to your specific use case for handling the report download on the client side. 

View solution in original post

AreejAnjum
Member
3 REPLIES 3

To enable the report download API on the client-side with JavaScript, you can replicate the Node.js buffer() function using the ArrayBuffer in JavaScript. Here's a simple example:

 

// Node.js buffer function
const nodeBuffer = Buffer.from('YourData', 'utf-8');

// Equivalent ArrayBuffer in JavaScript
const arrayBuffer = new TextEncoder().encode('YourData');

// Converting ArrayBuffer to byte array (Uint8Array)
const byteArray = new Uint8Array(arrayBuffer);

// Now you can use 'byteArray' for further processing

 

This example showcases how to create a byte array in JavaScript, similar to the buffer() function in Node.js. You can adapt this to your specific use case for handling the report download on the client side. 

AreejAnjum
Member

Thanks for the tip. That worked well!  Do you have an example of the next step which is to hash the public key using the byte array of the secret key? What crypto call are you using to hash the byte array?

Thanks for the tip its working well

hmza312
Member