I am trying to integrate TrialPay with WordPress. TrialPay can send me either a POST or GET Request, and I have to receive it. When I send the response, there can be no HTML, only a “1” in the response.
I have tried a rewrite endpoint from some code someone gave me, but in the response the whole home page HTML is included.
function wpd_trialpay_endpoint(){
add_rewrite_endpoint( 'trialpay', EP_PAGES );
}
add_action( 'init', 'wpd_trialpay_endpoint' );
function wpd_trialpay_parse( $request ){
if( array_key_exists( 'trialpay', $request->query_vars ) ){
$toaward = $_GET['reward_amount'];
$user = $_GET['sid'];
if (mycred_add('Points_for_TrialPay_Offer', 1, 1, '%plural% for TrialPay offer completion', $_POST['oid'] )) {
echo "1";
//header("HTTP/1.1 200 OK");
} else {
echo "Fail!";
//header("HTTP/1.1 412 Precondition Failed");
}
die;
}
}
add_action( 'parse_request', 'wpd_trialpay_parse' );
Is this the right way to do this? When I navigate to mysite.com/offer/trialpay (/offer is a blank page), the page outputs a “1” like intended. When I test the page with a POST request, it returns the whole front page HTML. What am I missing?
create a init action hook and manage all the post and get parameters in the callback function. here’s an example:
this code is supposed to go in your plugin or inside functions.php if you’re working with a theme