I have created a plugin for my hashcheck but it did not return me any value

I have created a plugin for my hashcheck and I am trying to save the value into a custom state but It return me nothing.
Here is my code;

const crypto = require("crypto");

function generateRequestHash() {
  const siteCode = "MIN-MIN-003";
  const countryCode = "ZA";
  const currencyCode = "ZAR";
  const amount = 25.01; // Convert to string
  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 = "My private Key";
  const isTest = false;

  // Use a delimiter between parameters
  const inputString = `${siteCode}|${countryCode}|${currencyCode}|${amount}|${transactionReference}|${bankReference}|${cancelUrl}|${errorUrl}|${successUrl}|${notifyUrl}|${isTest}|${privateKey}`;

  // Return the hash instead of logging it
  return generateRequestHashCheck(inputString);
}

function generateRequestHashCheck(inputString) {
  const stringToHash = inputString.toLowerCase();
  return getSha512Hash(stringToHash);
}

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

// Call the function and store the hash
const calculatedHashResult = generateRequestHash();
console.log(calculatedHashResult);

As you can see the return value is store in calculatedHashResult and i select the data type text in plugin return data type but it did not return me anything.

These are the step but step preview and here you can see that it do not return me anything.

Please reply me if you know anything I am stuck on this problem for a very long time. Thanks!

you don’t return anything in your code

Well if I run on it on a code debugger it give me the hashed value. If I am missing anything please let me know.
Thanks!

logging something in the console is not returing a value from your server side action. Even the plugin editor will tell you what to return if you read the hints

I fix it but I am getting this error now.

plugin error

it is very clear. It means what it literally says: in the editor you set a return type (different from a string) but you are returning a string.

Yes see I have selected Text as return data type:

And here is my code

function(properties, context) {
const crypto = require("crypto");

function generateRequestHash() {
  const siteCode = "MIN-MIN-003    ";
  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.com/notify.html"; // Corrected the URL
  const privateKey = "";
  const isTest = false;

  // Concatenate values with a separator
  const inputString = ${siteCode}|${countryCode}|${currencyCode}|${amount}|${transactionReference}|${bankReference}|${cancelUrl}|${errorUrl}|${successUrl}|${notifyUrl}|${isTest.toString()}|${privateKey};

  return generateRequestHashCheck(inputString);
}

function generateRequestHashCheck(inputString) {
  const stringToHash = inputString.toLowerCase();
  return getSha512Hash(stringToHash);
}

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

const calculatedHashResult = generateRequestHash();
console.log(calculatedHashResult);
return calculatedHashResult;

}

Please help me out here Thanks!

Read the hint on the plugin editor where it tells you how to structure the returning object. You are returning a string instead of an object with the properties described in your settings. :wave: