woocommerce-paypal-payments/modules/ppcp-webhooks/extensions.php

82 lines
3.2 KiB
PHP
Raw Normal View History

2020-07-06 11:04:06 +03:00
<?php
2020-08-27 13:10:16 +03:00
/**
* The webhook module extensions.
*
2020-09-11 14:11:10 +03:00
* @package WooCommerce\PayPalCommerce\Webhooks
2020-08-27 13:10:16 +03:00
*/
2020-07-06 11:04:06 +03:00
declare(strict_types=1);
2020-09-11 14:11:10 +03:00
namespace WooCommerce\PayPalCommerce\Webhooks;
2020-07-06 11:04:06 +03:00
2021-09-16 13:48:20 +03:00
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
2021-09-16 13:48:20 +03:00
return array(
'wcgateway.settings.fields' => static function ( $container, array $fields ): array {
$status_page_fields = array(
'webhook_status_heading' => array(
'heading' => __( 'Webhook Status', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => Settings::CONNECTION_TAB_ID,
2022-10-28 15:46:40 +02:00
'description' => sprintf(
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
__( 'Status of the webhooks subscription. More information about the webhooks is available in the %1$sWebhook Status documentation%2$s.', 'woocommerce-paypal-payments' ),
'<a href="https://woocommerce.com/document/woocommerce-paypal-payments/#webhook-status" target="_blank">',
'</a>'
),
),
'webhooks_list' => array(
'title' => __( 'Subscribed webhooks', 'woocommerce-paypal-payments' ),
2021-09-16 13:48:20 +03:00
'type' => 'ppcp-table',
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => Settings::CONNECTION_TAB_ID,
2021-09-16 13:48:20 +03:00
'classes' => array( 'ppcp-webhooks-table' ),
'value' => function () use ( $container ) : array {
return $container->get( 'webhook.status.registered-webhooks-data' );
},
),
'webhooks_resubscribe' => array(
2021-09-16 17:08:43 +03:00
'title' => __( 'Resubscribe webhooks', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',
'text' => '<button type="button" class="button ppcp-webhooks-resubscribe">' . esc_html__( 'Resubscribe', 'woocommerce-paypal-payments' ) . '</button>',
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => Settings::CONNECTION_TAB_ID,
2021-09-16 17:08:43 +03:00
'description' => __( 'Click to remove the current webhook subscription and subscribe again, for example, if the website domain or URL structure changed.', 'woocommerce-paypal-payments' ),
),
2021-09-16 13:48:20 +03:00
);
2021-09-22 17:13:38 +03:00
$is_registered = $container->get( 'webhook.is-registered' );
if ( $is_registered ) {
$status_page_fields = array_merge(
$status_page_fields,
array(
'webhooks_simulate' => array(
'title' => __( 'Webhook simulation', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',
'text' => '<button type="button" class="button ppcp-webhooks-simulate">' . esc_html__( 'Simulate', 'woocommerce-paypal-payments' ) . '</button>',
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => Settings::CONNECTION_TAB_ID,
2021-09-22 17:13:38 +03:00
'description' => __( 'Click to request a sample webhook payload from PayPal, allowing to check that your server can successfully receive webhooks.', 'woocommerce-paypal-payments' ),
),
)
);
}
2021-09-16 13:48:20 +03:00
return array_merge( $fields, $status_page_fields );
},
);