Repository URL to install this package:
|
Version:
4.1.3 ▾
|
<?php
/**
* Webhooks: Settings
*
* @package SimplePay\Pro\Webhooks
* @copyright Copyright (c) 2020, Sandhills Development, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 4.0.0
*/
namespace SimplePay\Pro\Webhooks;
use SimplePay\Core\Utils;
use SimplePay\Core\Settings\Subsection;
use SimplePay\Core\Settings\Setting;
use SimplePay\Core\Settings\Setting_Input;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Outputs webhook setup content.
*
* @since 4.0.0
*/
function setup_description() {
ob_start();
?>
<p>
<?php esc_html_e( 'Stripe uses webhooks to notify WP Simple Pay when an action has occured on your Stripe account.', 'simple-pay' ); ?>
</p>
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */
__( 'To allow your site to receive webhook notifications add an endpoint in your %1$sStripe dashboard's webhook settings%2$s with the following URL:', 'simple-pay' ),
'<a href="https://dashboard.stripe.com/account/webhooks" target="_blank" rel="noopener noreferrer" class="simpay-external-link">',
Utils\get_external_link_markup() . '</a>'
)
);
?>
</p>
<br />
<p><code><?php echo esc_url( simpay_get_webhook_url() ); ?></code></p>
<br />
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */
__(
'Have questions about webhooks? %1$sView the Webhook documentation%2$s',
'simple-pay'
),
'<a href="' . simpay_docs_link( '', 'webhooks', 'global-settings', true ) . '" target="_blank" rel="noopener noreferrer" class="simpay-external-link">',
Utils\get_external_link_markup() . '</a>'
)
);
?>
</p>
<?php if ( ! simpay_get_account_id() && simpay_check_keys_exist() ) : ?>
<br />
<div id="simpay-webhook-error" style="display: none;">
<p>
<?php esc_html_e( 'Your webhook configuration for the entered API keys is missing or incorrect.', 'simple-pay' ); ?>
</p>
<p>
<button type="button" id="simpay-webhook-create" class="button"><?php esc_html_e( 'Create Webhooks Automatically', 'simple-pay' ); ?></button>
<?php
echo wp_kses_post(
sprintf(
/* translators: %1$s Anchor opening tag, do not translate. %2$s Closing anchor tag, do not translate. */
__( 'or %1$smanually in Stripe%2$s', 'simple-pay' ),
'<a href="https://dashboard.stripe.com/account/webhooks">',
'</a>'
)
);
?>
</p>
</div>
<?php endif; ?>
<?php
return ob_get_clean();
}
/**
* Registers subsection.
*
* @since 4.0.0
*
* @param \SimplePay\Core\Settings\Subsections_Collection $subsections Subsections collection.
*/
function register_subsections( $subsections ) {
// Stripe/Webhooks.
$subsections->add(
new Subsection(
array(
'id' => 'webhooks',
'section' => 'stripe',
'label' => esc_html_x( 'Webhooks', 'settings subsection label', 'simple-pay' ),
'priority' => 20,
)
)
);
}
add_action( 'simpay_register_settings_subsections', __NAMESPACE__ . '\\register_subsections' );
/**
* Registers settings.
*
* @since 4.0.0
*
* @param \SimplePay\Core\Settings\Setting_Collection $settings Settings collection.
*/
function register_settings( $settings ) {
// Setup.
$settings->add(
new Setting(
array(
'id' => 'webhook_setup',
'section' => 'stripe',
'subsection' => 'webhooks',
'label' => esc_html_x( 'Setup', 'setting label', 'simple-pay' ),
'output' => __NAMESPACE__ . '\\setup_description',
)
)
);
// Keys.
$args = array(
'type' => 'password',
'description' => wpautop(
wp_kses(
sprintf(
/* translators: %1$s opening anchor tag and URL, do not translate. %2$s closing anchor tag, do not translate */
__(
'Retrieve your endpoint's secret from your %1$sStripe dashboard's webhook settings%2$s<br />Select an endpoint for which you want to obtain the secret, then select the <em>Click to reveal</em> button.',
'simple-pay'
),
'<a href="https://dashboard.stripe.com/account/webhooks" target="_blank" rel="noopener noreferrer" class="simpay-external-link">',
Utils\get_external_link_markup() . '</a>'
),
array(
'a' => array(
'href' => true,
'target' => true,
'rel' => true,
'class' => true,
),
'em' => array(),
'br' => array(),
'span' => array(
'class' => 'screen-reader-text',
),
)
)
),
'classes' => array(
'regular-text',
),
);
$settings->add(
new Setting_Input(
array_merge(
$args,
array(
'id' => 'test_webhook_endpoint_secret',
'section' => 'stripe',
'subsection' => 'webhooks',
'label' => esc_html_x(
'Test Endpoint Secret',
'setting label',
'simple-pay'
),
'value' => simpay_get_setting( 'test_webhook_endpoint_secret', '' ),
'priority' => 20,
)
)
)
);
$settings->add(
new Setting_Input(
array_merge(
$args,
array(
'id' => 'live_webhook_endpoint_secret',
'section' => 'stripe',
'subsection' => 'webhooks',
'label' => esc_html_x(
'Live Endpoint Secret',
'setting label',
'simple-pay'
),
'value' => simpay_get_setting( 'live_webhook_endpoint_secret', '' ),
'priority' => 30,
)
)
)
);
}
add_action( 'simpay_register_settings', __NAMESPACE__ . '\\register_settings' );