r' );
return array(
new CheckoutOrderApproved(
$logger,
$order_endpoint,
$container->get( 'session.handler' ),
$container->get( 'wcgateway.funding-source.renderer' ),
$container->get( 'wcgateway.order-processor' )
),
new CheckoutOrderCompleted( $logger ),
new CheckoutPaymentApprovalReversed( $logger ),
new PaymentCaptureRefunded( $logger, $refund_fees_updater ),
new PaymentCaptureReversed( $logger ),
new PaymentCaptureCompleted( $logger, $order_endpoint ),
new VaultPaymentTokenCreated( $logger, $prefix, $authorized_payments_processor, $payment_token_factory, $payment_token_helper ),
new VaultPaymentTokenDeleted( $logger ),
new PaymentCapturePending( $logger ),
new PaymentSaleCompleted( $logger ),
new PaymentSaleRefunded( $logger, $refund_fees_updater ),
new BillingSubscriptionCancelled( $logger ),
new BillingPlanPricingChangeActivated( $logger ),
new CatalogProductUpdated( $logger ),
new BillingPlanUpdated( $logger ),
);
},
'webhook.current' => function( ContainerInterface $container ) : ?Webhook {
$data = (array) get_option( WebhookRegistrar::KEY, array() );
if ( empty( $data ) ) {
return null;
}
$factory = $container->get( 'api.factory.webhook' );
assert( $factory instanceof WebhookFactory );
try {
return $factory->from_array( $data );
} catch ( Exception $exception ) {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
assert( $logger instanceof LoggerInterface );
$logger->error( 'Failed to parse the stored webhook data: ' . $exception->getMessage() );
return null;
}
},
'webhook.is-registered' => function( ContainerInterface $container ) : bool {
return $container->get( 'webhook.current' ) !== null;
},
'webhook.status.registered-webhooks' => function( ContainerInterface $container ) : array {
$endpoint = $container->get( 'api.endpoint.webhook' );
assert( $endpoint instanceof WebhookEndpoint );
$state = $container->get( 'onboarding.state' );
if ( $state->current_state() >= State::STATE_ONBOARDED ) {
return $endpoint->list();
}
return array();
},
'webhook.status.registered-webhooks-data' => function( ContainerInterface $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(
'%s',
__( '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(
',
',
array_map(
'esc_html',
$webhook->humanfriendly_event_names()
)
),
);
},
$webhooks
),
'empty_placeholder' => $empty_placeholder,
);
},
'webhook.status.simulation' => function( ContainerInterface $container ) : WebhookSimulation {
$webhook_endpoint = $container->get( 'api.endpoint.webhook' );
$webhook = $container->get( 'webhook.current' );
return new WebhookSimulation(
$webhook_endpoint,
$webhook,
'CHECKOUT.ORDER.APPROVED',
'2.0'
);
},
'webhook.status.assets' => function( ContainerInterface $container ) : WebhooksStatusPageAssets {
return new WebhooksStatusPageAssets(
$container->get( 'webhook.module-url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'onboarding.environment' )
);
},
'webhook.endpoint.resubscribe' => static function ( ContainerInterface $container ) : ResubscribeEndpoint {
$registrar = $container->get( 'webhook.registrar' );
$request_data = $container->get( 'button.request-data' );
return new ResubscribeEndpoint(
$registrar,
$request_data
);
},
'webhook.endpoint.simulate' => static function ( ContainerInterface $container ) : SimulateEndpoint {
$simulation = $container->get( 'webhook.status.simulation' );
$request_data = $container->get( 'button.request-data' );
return new SimulateEndpoint(
$simulation,
$request_data
);
},
'webhook.endpoint.simulation-state' => static function ( ContainerInterface $container ) : SimulationStateEndpoint {
$simulation = $container->get( 'webhook.status.simulation' );
return new SimulationStateEndpoint(
$simulation
);
},
'webhook.last-webhook-storage' => static function ( ContainerInterface $container ): WebhookEventStorage {
return new WebhookEventStorage( $container->get( 'webhook.last-webhook-storage.key' ) );
},
'webhook.last-webhook-storage.key' => static function ( ContainerInterface $container ): string {
return 'ppcp-last-webhook';
},
'webhook.module-url' => static function ( ContainerInterface $container ): string {
return plugins_url(
'/modules/ppcp-webhooks/',
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
);