get the permission must the user have to access to the 'Access denied ' page
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.