Skip to content

Commit

Permalink
Try fixing IPN flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Resonious committed Feb 1, 2024
1 parent 4b41c83 commit b2673f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions includes/class-wc-gateway-komoju-ipn-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class WC_Gateway_Komoju_IPN_Handler extends WC_Gateway_Komoju_Response
*/
public function __construct($gateway, $webhookSecretToken = '', $secret_key = '', $invoice_prefix = '', $useOnHold = false)
{
add_action('woocommerce_api_wc_gateway_komoju', [$this, 'check_response']);
add_action('valid-komoju-standard-ipn-request', [$this, 'valid_response']);
add_action('invoke_komoju_ipn_handler', [$this, 'check_response']);
add_action('valid_komoju_standard_ipn_request', [$this, 'valid_response']);
add_action('komoju_capture_payment_async', [$this, 'payment_complete_async'], 10, 3);

$this->gateway = $gateway;
Expand Down Expand Up @@ -77,7 +77,7 @@ public function check_response()
$webhookEvent = new WC_Gateway_Komoju_Webhook_Event($entityBody);

// NOTE: direct function call doesn't work
do_action('valid-komoju-standard-ipn-request', $webhookEvent);
do_action('valid_komoju_standard_ipn_request', $webhookEvent);
exit;
}
wp_die('Failed to verify KOMOJU authenticity', 'Komoju IPN', ['response' => 401]);
Expand Down
10 changes: 10 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ function woocommerce_komoju_load_script_as_module($tag, $handle, $src)
return '<script type="module" src="' . esc_attr($src) . '"></script>';
}

function woocommerce_komoju_handle_http_request()
{
// Force WC to load our gateway, causing WC_Gateway_Komoju_IPN_Handler to get instantiated.
WC()->payment_gateways()->payment_gateways();

// This action is registered when WC_Gateway_Komoju_IPN_Handler is instantiated.
do_action('invoke_komoju_ipn_handler');
}

add_filter('woocommerce_payment_gateways', 'woocommerce_add_komoju_gateway');
add_filter('woocommerce_get_settings_pages', 'woocommerce_add_komoju_settings_page');
add_action('woocommerce_api_wc_gateway_komoju', 'woocommerce_komoju_handle_http_request');

add_action('wp_enqueue_scripts', 'woocommerce_komoju_load_scripts');
add_filter('script_loader_tag', 'woocommerce_komoju_load_script_as_module', 10, 3);
Expand Down

0 comments on commit b2673f5

Please sign in to comment.