Last active
March 8, 2021 10:04
-
-
Save vanbo/67d704653b0bca26c7c6ae37fb831e1c to your computer and use it in GitHub Desktop.
WooCommerce Paysafe: End server to server notification on Hosted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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