Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanbo/67d704653b0bca26c7c6ae37fb831e1c to your computer and use it in GitHub Desktop.
Save vanbo/67d704653b0bca26c7c6ae37fb831e1c to your computer and use it in GitHub Desktop.
WooCommerce Paysafe: End server to server notification on Hosted
// Actions
add_action( 'woocommerce_api_wc_gateway_paysafe_response', 'vanbodevelops_intercept_hosted_response', 9 );
function vanbodevelops_intercept_hosted_response() {
/**
* @var \WcPaysafe\Gateways\Redirect\Gateway $gateway
*/
$gateway = vanbodevelops_get_gateway( 'netbanx' );
if ( 'hosted' != $gateway->get_option( 'integration', 'hosted' ) ) {
return;
}
// End execution if this is a server to server notification
if ( '' != \WcPaysafe\Paysafe::get_field( 'paysafe-redirect', $_GET, '' ) ) {
// Return 204 status
header( "HTTP/1.0 204 No Content" );
exit;
// If you want to just delay the execution by some time, delete line 16 and 17 and uncomment the line below
// sleep(30); // Delay by 30 seconds
}
}
/**
* @param $name
*
* @return bool|mixed
*/
function vanbodevelops_get_gateway($name) {
foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
if ( $name == $gateway->id ) {
return $gateway;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment