Drupal commerce payment callback endpoint
so - this sounds like an IPN (instant payment notification), commerce payment does not handle that, so you have to pass the ipn url defined in hook_menu to your gateway in the specific parameter when submitting the _redirect_form, or setting it in your gateway configuration - depends on the gateway ..

/**
 * Implements hook_menu().
 *
 * adds the callback uri
 */
function YOUR_MODULE_menu() {
  $items = array();

  // Define an always accessible path to receive IPNs.
  $items['some_uri/IPN/%'] = array(
    'page callback' =&gt; 'your_module_process_ipn',
    'page arguments' =&gt; array(2),
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );

  return $items;
}


so - your ipn looks like this httpx://example.domain/some_uri/IPN/What/ever
maybe that the What/ever is set by the gateway. if nothing is set, adjust the item in hook_menu !

then your callback function does take the action, like:

/**
 * Processes an incoming IPN.
 *
 * @param $uri
 *   dynamic URI
 * @param $debug_ipn
 *   Optionally specify an IPN array for debug purposes; if left empty, the IPN
 *     be pulled from the $_POST.
 *
 */
function commerce_postfinance_process_ipn($uri = NULL, $debug_ipn = array()) {
  $ret = 'IPN failed';
  if (ipn_valid($uri, $debug_ipn)) {
    $ret = 'IPN OK';
  }

  print $ret;
  exit(0); // hook_exit will not be invoked !
}


and in the ipn_valid function you access the $_POST array.


  don't forget to create a commerce payment transaction if the ipn is
  OK.


refer the paypal wps module for this (see funciton commerce_paypal_wps_paypal_ipn_process)