get the permission must the user have to access to the 'Access denied ' page i'm working on a drupal 7 online payment module , 

and i need to know if there is a Drupal 7 function that can track (each time and for all the users) if 'the logging online user' is requesting an 'Access denied ' page , and then get the permission must the user have to access to that page


  PS: i'm creating a drupal payment module , the payment will be by
  roles , for exemple ( user1 can create 'Blog content type' just if he
  has the permission on that, if not i i need to know which 'Access
  denied ' page he is in and it's role so i can show him a message to
  buy this role depending on the price in the database) all what i need
  is the string permission of the page


thanks in advance ^_^
The only answer I can think of is to roll this functionality yourself with some coding in a custom module.

You probably want to use Chain Menu Access and the drupal API function user_role_permissions.

You can use the chain menu access api to put a fired-last menu access check that does some comparisons over previous access checks and Roles:

&lt;?php
  chain_menu_access_chain($menu, 'an/existing/path', '_mymodule_new_access_callback_check_permissions_to_roles');
?&gt;


Then use the drupal api user_role_permissions to see what Role has X permission that was failed in a parent-chained access callback. You could store that for example in the users $_SESSION data. Then write a custom 404 page that shows them purchase options.