Hi, I had the same problem when I built a gateway for a customer, the solution might not be the exact solution for you, but it should be a good place to start.
In my gateway where it checks the gateway response I had the following mistake
if ( is_array( $result ) && $result['vpc_TxnResponseCode'] == 0 ) {
//redirect to transaction page and store in DB as a order with
//accepted payment
$sql = "UPDATE
" . WPSC_TABLE_PURCHASE_LOGS .
"SET processed = '2', notes = '" . serialize( $result ) . "'
WHERE sessionid = " . $sessionid;
$wpdb->query( $sql );
$transact_url = get_option( 'transact_url' );
unset( $_SESSION['WpscGatewayErrorMessage'] );
header( "Location: " . $transact_url . $seperator . "sessionid=" . $sessionid );
}
else{
//redirect back to checkout page with errors
$sql = "UPDATE " . WPSC_TABLE_PURCHASE_LOGS .
" SET processed = '5', notes = '" . serialize( $result ) . "'
WHERE sessionid = " . $sessionid;
$wpdb->query( $sql );
// Problem is below, there is no 'checkout_url' option, so transact_url is not being set properly
$transact_url = get_option( 'checkout_url' );
$_SESSION['WpscGatewayErrorMessage'] = __( 'Sorry your transaction did not go through successfully, please try again.' );// . '<br />Gateway Response: ' . getResponseCodeDescription( $result['vpc_TxnResponseCode'] );
header( "Location: " . $transact_url );
}
Notice I was just mistakenly pointing them to a URL that wasn’t defined anywhere, and thus they were ending up back at the home page. Took me a while to figure it out.
The correct redirect URL code for failed transaction should be;
$transact_url = get_option( 'transact_url' );
Not sure how I managed to get it mixed up. You may also want to check in your database that the option ‘transact_url’ has the correct value (should be something like https://www.yoursite.com/store/checkout/).