I am trying to get a return value from the payable function, the idea is a user must pay the fees and in return, he will get his special code. My JS test code is as follow
it('get special code which was stored by the admin',async()=> {
const user = accounts[4];
// get the deployed contract instance
contractInstance = await MyContract.deployed()
const expectedCode = "Wolvorine";
const fees = "1";
let result1 = await contractInstance.getCode(user,{from:user,value:fees}) ;
assert.equal(result1,expectedCode, " Code which was stored by the admin must be equal to the expected value")
My contract which returns the value is as below
function getCode(address _identityaddress) payable
public returns (string memory)
{
require((identity_details[_identityaddress].identityaddress==msg.sender));
require(msg.value >= attestationFee);
Transaction memory p = identity_details[_identityaddress];
return (p.code);
}
Here Transaction is a structure data type that has code as a string variable inside. If I make this function without payable and don't take any money from the caller then return value accurately returns me the code. But since I am using payable and receiving ethers, therefore, it is returning me a big transaction object instead of my returned value.
What is the best way to tackle this issue since I want the user to use MetaMask only one time where he will just pay and then get this value in one shot?