How do i create a payment method+gateway with a custom function called by the gateway to determine whether payment is successful?
The answer, is that uc_payment_process() needs to be called in hook_order() when the $op variable is 'submit' with the payment method ID as the first argument.

The missing link to bring payment methods, gateways and actual payments together is as follows:

&lt;?php

/**
 * Implements hook_order
 * This is the bit that actually gets the method/gateway-combo into gear
 * when an order is submitted in the checkout process.
 */

  function uc_securepaytoken_order( $op, $arg1, $arg2 ) {

    switch( $op ) {
        case 'submit':

          if($arg1-&gt;payment_method == 'sptoken') {


            // Attempt to process the payment
            $pass = uc_payment_process( 'sptoken', $arg1-&gt;order_id, $arg1-&gt;order_total, $data, TRUE, NULL, FALSE);

            // If the payment failed, store the data back in the session and
            // halt the checkout process.

            if(!$pass) {
            $message = 'We were unable to process this payment. Please verify your details and try again. If the problem persists, contact us to complete your order';
            return array(array('pass' =&gt; FALSE, 'message' =&gt; $message ));
            }

          }

        break;
    }
}

?&gt;


The next "gotcha" is that the return value from uc_payment_process() is only TRUE if your callback function defined by the gateway returns an array that looks something like this (but with success = TRUE). Check out the uc_credit module for more clues.

&lt;?php
$result = array(
    'success' =&gt; FALSE,
    'comment' =&gt; 'Invalid transaction type',
    'message' =&gt; 'Invalid transaction type',
    'data' =&gt; array(
        'module' =&gt; 'uc_securepaytoken', 
        'transaction_id' =&gt; 0,
    ),
    'uid' =&gt; $user-&gt;uid,
    'log_payment' =&gt; 0,
);
?&gt;


For further reading check:


http://api.lullabot.com/uc_payment_process - API Reference
http://www.commerceguys.com/resources/articles/122 - Post explains uc_payment_process() and a few other UC API concepts but no explicit reference to hook_order() unfortunately :(