Lack of interest Allow customisation of payment callback response within payment handler

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

mattrogowski

Well-known member
I'm creating a new payment provider integration, and it requires a certain response to be output when the webhook has been processed. Currently payment_callback.php returns output with this:

PHP:
$response
    ->body(htmlspecialchars($state->logMessage))
    ->send($request);

I can't extend this, so means I can only respond with the log message, which isn't what I need, and I don't really want to change what the log message is, as I need to return XML and this isn't going to be suitable as the log message. If this was a method in the payment provider, it could return this by default, but allow it to be overridden. Every other aspect can be overridden, but there is an (incorrect) assumption that the payment gateway doesn't need any custom response data. I'm sure some other payment gateways may require specific responses to callbacks, and this seems like a limitation that doesn't need to exist.
 
Last edited:
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
Somewhat hackish but might work for now:

What about overwriting method log() to call the parent method first and afterwards change $state->logMessage to the XML you need to output, maybe even just in the context of being called straight from payment_callback.php?
 
Good idea, hadn't thought of that - looked into it and almost worked just doing that, if it wasn't for the htmlspecialchars which encoded the XML. So had to get even more hacky and send the response myself too and exit so it didn't continue to the default one:

Code:
public function log(CallbackState $state)
{
    parent::log($state);

    $response = \XF::app()->response();
    $request = \XF::app()->request();

    $response->contentType('text/xml');

    $code = $response->httpCode() == 200 ? 0 : 1;
    $body = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <results>{$code}</results>
    <message>{$state->logMessage}</message>
</Response>
END;

    $response
        ->body($body)
        ->send($request);

    exit;
}

Thanks for the suggestion, I was going to just create another callback PHP file in the root, this is at least self-contained. It does the job but not ideal.
 
Last edited:
Top Bottom