mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Show webhooks
This commit is contained in:
parent
0b029a9392
commit
e2a7f6d8d9
12 changed files with 5132 additions and 7 deletions
|
@ -9,6 +9,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Webhooks;
|
||||
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Webhook;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Assets\WebhooksStatusPageAssets;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\CheckoutOrderApproved;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\CheckoutOrderCompleted;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureCompleted;
|
||||
|
@ -18,7 +22,7 @@ use Psr\Container\ContainerInterface;
|
|||
|
||||
return array(
|
||||
|
||||
'webhook.registrar' => function( $container ) : WebhookRegistrar {
|
||||
'webhook.registrar' => function( $container ) : WebhookRegistrar {
|
||||
$factory = $container->get( 'api.factory.webhook' );
|
||||
$endpoint = $container->get( 'api.endpoint.webhook' );
|
||||
$rest_endpoint = $container->get( 'webhook.endpoint.controller' );
|
||||
|
@ -30,7 +34,7 @@ return array(
|
|||
$logger
|
||||
);
|
||||
},
|
||||
'webhook.endpoint.controller' => function( $container ) : IncomingWebhookEndpoint {
|
||||
'webhook.endpoint.controller' => function( $container ) : IncomingWebhookEndpoint {
|
||||
$webhook_endpoint = $container->get( 'api.endpoint.webhook' );
|
||||
$webhook_factory = $container->get( 'api.factory.webhook' );
|
||||
$handler = $container->get( 'webhook.endpoint.handler' );
|
||||
|
@ -45,7 +49,7 @@ return array(
|
|||
... $handler
|
||||
);
|
||||
},
|
||||
'webhook.endpoint.handler' => function( $container ) : array {
|
||||
'webhook.endpoint.handler' => function( $container ) : array {
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$prefix = $container->get( 'api.prefix' );
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
|
@ -57,4 +61,61 @@ return array(
|
|||
new PaymentCaptureCompleted( $logger, $prefix ),
|
||||
);
|
||||
},
|
||||
|
||||
'webhook.status.registered-webhooks' => function( $container ) : array {
|
||||
$endpoint = $container->get( 'api.endpoint.webhook' );
|
||||
assert( $endpoint instanceof WebhookEndpoint );
|
||||
|
||||
return $endpoint->list();
|
||||
},
|
||||
|
||||
'webhook.status.registered-webhooks-data' => function( $container ) : array {
|
||||
$empty_placeholder = __( 'No webhooks found.', 'woocommerce-paypal-payments' );
|
||||
|
||||
$webhooks = array();
|
||||
try {
|
||||
$webhooks = $container->get( 'webhook.status.registered-webhooks' );
|
||||
} catch ( Exception $exception ) {
|
||||
$empty_placeholder = sprintf(
|
||||
'<span class="error">%s</span>',
|
||||
__( 'Failed to load webhooks.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'headers' => array(
|
||||
__( 'URL', 'woocommerce-paypal-payments' ),
|
||||
__( 'Tracked events', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'data' => array_map(
|
||||
function ( Webhook $webhook ): array {
|
||||
return array(
|
||||
esc_html( $webhook->url() ),
|
||||
implode(
|
||||
',<br/>',
|
||||
array_map(
|
||||
'esc_html',
|
||||
$webhook->humanfriendly_event_names()
|
||||
)
|
||||
),
|
||||
);
|
||||
},
|
||||
$webhooks
|
||||
),
|
||||
'empty_placeholder' => $empty_placeholder,
|
||||
);
|
||||
},
|
||||
|
||||
'webhook.status.assets' => function( $container ) : WebhooksStatusPageAssets {
|
||||
return new WebhooksStatusPageAssets(
|
||||
$container->get( 'webhook.module-url' )
|
||||
);
|
||||
},
|
||||
|
||||
'webhook.module-url' => static function ( $container ): string {
|
||||
return plugins_url(
|
||||
'/modules/ppcp-webhooks/',
|
||||
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue