Need help to run javascript and pass the date to API

I am trying to integrate Ozow payment method to my bubble.io app and for that first I have to run a javascript code and get an hashcheck code from it. After that I have to pass the hashcheck value to API. So the API will know how much that product cost and know about user profile.

const crypto = require("crypto");

function generateRequestHash() {
  const siteCode = "[YOUR SITE CODE]";
  const countryCode = "ZA";
  const currencyCode = "ZAR";
  const amount = 25.01;
  const transactionReference = "123";
  const bankReference = "ABC123";
  const cancelUrl = "http://mydomain.com/cancel.html";
  const errorUrl = "http://mydomain.com/error.html";
  const successUrl = "http://mydomain.com/success.html";
  const notifyUrl = "http://mydomain/notify.html";
  const privateKey = "[YOUR PRIVATE KEY]";
  const isTest = false;

  const inputString = `${siteCode}${countryCode}${currencyCode}${amount}${transactionReference}${bankReference}${cancelUrl}${errorUrl}${successUrl}${notifyUrl}${isTest}${privateKey}`;

  const calculatedHashResult = generateRequestHashCheck(inputString);
  console.log(`Hashcheck: ${calculatedHashResult}`);
}

function generateRequestHashCheck(inputString) {
  const stringToHash = inputString.toLowerCase();
  console.log(`Before Hashcheck: ${stringToHash}`);
  return getSha512Hash(stringToHash);
}

function getSha512Hash(stringToHash) {
  const hash = crypto.createHash("sha512");
  hash.update(stringToHash);
  return hash.digest("hex");
}

generateRequestHash();


Here is the javascript code but it is not returning me anything. I’m new to bubble so your help will means me a lot. Thank you.

Try turning this into a plugin.

Create an action and make it server based.

Add the return object, add this inside the function, then return the data from generateRequestHash.

Use another action after this is ran, to get the data.

Your other alternative is to load this library from a script via CDN, but the server-based approach is your best bet.

Thanks for your reply. Yes I am using Toolkit to add javascript code in the app.


Here is my run action using toolkit.

Please let me know if do anything wrong because I write the function name correct and call it correctly.

at the top, change this: const crypto = require(‘crypto’)
to:

const crypto = window.crypto

Still nothing. Can you please provide me your discord name if you do not mind so I can share you my screen and show you what am I doing? I really need someone help and send the project to my boss otherwise I will loss my job.

Thanks.

I’m not available for person-to-person right now. If it’s that delicate, you can always hire me for the job as I can probably have what you need made in a matter of an hour.

My recommended suggestion is to make your own private plugin and follow the steps I provided you earlier.

You shouldn’t be taking on a project with this level of “coding” if you don’t have experience with it. Let alone take money for it.

This topic was automatically closed after 70 days. New replies are no longer allowed.