I have parent post rental with field balance and child post payment with field payment amount. When new payment form is submitted I want to subtract the payment amount from the balance and update balance filed in rental post.
That will create a debug.log file in your /wp-content/ directory which you can examine in any text editor.
Update your code snippet to print the variables to the log, e.g.
error_log("payment_for: " . $payment_for);
Although I don't think it applies here, in cases where the variable may be an object or array, it's useful to output using print_r for readability, e.g.
The rental-payment relationship is a one-to-many relationship?
$post_id is the ID of a child post, and you are trying to retrieve the id of the parent rental post?
If this were a many-to-many relationship it cannot work with the toolset_get_related_post function, which only works when there is only one possible result (the singular parent). If there were more than one possible result (because you were aiming to retrieve a child post ID or because this was a many-to-many relationship) you would need to use toolset_get_related_posts instead (https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts).
In which case toolset_get_related_post is the correct function to use.
It only takes two arguments, the ID of the child post and the slug of the relationship.
Assuming these are correct, that leads to a third possibility: there is no parent post.
1. Does the form to publish a child post include a selector for the parent post?
2. Is it set when submitting the form?
3. After submitting the form if you edit the child post in the backend, can you see that the child post is actually connected to a parent post?
Yes the child form includes a selector for the parent post and after submitting the form I can see that the payment is connected to the correct rental.