namespace WPForms\Tasks\Actions;
use WPForms\Integrations\Stripe\Api\WebhooksManager;
use WPForms\Integrations\Stripe\Helpers;
* Class WebhooksAutoConfigurationTask.
class WebhooksAutoConfigurationTask extends Task {
const ACTION = 'wpforms_process_webhooks_auto_configuration';
const STATUS = 'wpforms_process_webhooks_auto_configuration_status';
const IN_PROGRESS = 'in_progress';
const COMPLETED = 'completed';
private $webhooks_manager;
protected $log_title = 'Migration';
public function __construct() {
parent::__construct( self::ACTION );
$this->webhooks_manager = new WebhooksManager();
$status = get_option( self::STATUS );
// This task is run in \WPForms\Migrations\Upgrade184::run(),
// and started in \WPForms\Migrations\UpgradeBase::run_async().
// Bail out if a task is not started or completed.
if ( ! $status || $status === self::COMPLETED ) {
// Mark that the task is in progress.
update_option( self::STATUS, self::IN_PROGRESS );
$tasks = wpforms()->obj( 'tasks' );
// Add new if none exists.
if ( $tasks->is_scheduled( self::ACTION ) !== false ) {
$tasks->create( self::ACTION )->async()->register();
private function hooks() {
add_action( self::ACTION, [ $this, 'process' ] );
public function process() {
// If the Stripe account is connected, then try to configure webhooks.
if ( Helpers::has_stripe_keys() && $this->webhooks_manager->connect() ) {
$this->log( 'Stripe Payments: Webhooks configured during migration to WPForms 1.8.4.' );
// Mark that the task is completed.
update_option( self::STATUS, self::COMPLETED );