name')); }, /** * Retrieves the list of inbox note instances. * * @returns InboxNoteInterface[] */ 'wcgateway.settings.inbox-notes' => static function (ContainerInterface $container): array { $inbox_note_factory = $container->get('wcgateway.settings.inbox-note-factory'); assert($inbox_note_factory instanceof InboxNoteFactory); $settings = $container->get('wcgateway.settings'); assert($settings instanceof Settings); $settings_model = $container->get('settings.data.settings'); assert($settings_model instanceof SettingsModel); $messages_apply = $container->get('button.helper.messages-apply'); assert($messages_apply instanceof MessagesApply); $settings_provider = $container->get('settings.settings-provider'); assert($settings_provider instanceof SettingsProvider); $is_working_capital_feature_flag_enabled = apply_filters( // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention 'woocommerce.feature-flags.woocommerce_paypal_payments.working_capital_enabled', \true ); return array($inbox_note_factory->create_note(__('PayPal Working Capital', 'woocommerce-paypal-payments'), __('Business loans from $1k to $230k for first-time borrowers. Looking to fuel your business growth? With a PayPal Working Capital loan, approved loans are funded in minutes and repaid as a share of your sales. Minimum payment required every 90 days. The lender for PayPal Working Capital is WebBank.', 'woocommerce-paypal-payments'), Note::E_WC_ADMIN_NOTE_INFORMATIONAL, 'ppcp-working-capital-inbox-note', Note::E_WC_ADMIN_NOTE_UNACTIONED, $is_working_capital_feature_flag_enabled && $container->get('api.shop.country') === 'US' && $settings_model->get_stay_updated(), new InboxNoteAction('learn_more', __('Learn More', 'woocommerce-paypal-payments'), 'https://www.paypal.com/us/business/financial-services/working-capital?partner_camp_id=woocommerce_ppwc', Note::E_WC_ADMIN_NOTE_UNACTIONED, \true))); }, 'wcgateway.void-button.assets' => function (ContainerInterface $container): VoidButtonAssets { return new VoidButtonAssets($container->get('wcgateway.asset_getter'), $container->get('ppcp.asset-version'), $container->get('api.endpoint.order.cached'), $container->get('wcgateway.processor.refunds')); }, 'wcgateway.void-button.endpoint' => function (ContainerInterface $container): VoidOrderEndpoint { return new VoidOrderEndpoint($container->get('button.request-data'), $container->get('api.endpoint.order'), $container->get('wcgateway.processor.refunds'), $container->get('woocommerce.logger.woocommerce')); }, 'wcgateway.settings.admin-settings-enabled' => static function (ContainerInterface $container): bool { return $container->has('settings.asset_getter'); }, 'wcgateway.contact-module.eligibility.check' => static function (ContainerInterface $container): callable { $feature_enabled = (bool) apply_filters( // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention 'woocommerce.feature-flags.woocommerce_paypal_payments.contact_module_enabled', getenv('PCP_CONTACT_MODULE_ENABLED') !== '0' ); /** * Decides, whether the current merchant is eligible to use the * "Contact Module" feature on this site. */ return static function () use ($feature_enabled, $container) { if (!$feature_enabled) { return \false; } $details = $container->get('settings.merchant-details'); assert($details instanceof MerchantDetails); $enable_contact_module = 'US' === $details->get_merchant_country(); /** * The contact module is enabled for US-based merchants by default. * This filter provides the official way to opt-out of using it on this store. */ return (bool) apply_filters('woocommerce_paypal_payments_contact_module_enabled', $enable_contact_module); }; }, /** * Returns a centralized list of feature eligibility checks. * * This is a helper service which is used by the `MerchantDetails` class and * should not be directly accessed. */ 'wcgateway.feature-eligibility.list' => static function (ContainerInterface $container): array { return array(FeaturesDefinition::FEATURE_SAVE_PAYPAL_AND_VENMO => $container->get('save-payment-methods.eligibility.check'), FeaturesDefinition::FEATURE_ADVANCED_CREDIT_AND_DEBIT_CARDS => $container->get('card-fields.eligibility.check'), FeaturesDefinition::FEATURE_GOOGLE_PAY => $container->get('googlepay.eligibility.check'), FeaturesDefinition::FEATURE_APPLE_PAY => $container->get('applepay.eligibility.check'), FeaturesDefinition::FEATURE_CONTACT_MODULE => $container->get('wcgateway.contact-module.eligibility.check')); }, /** * Returns a prefix for the site, ensuring the same site always gets the same prefix (unless the URL changes). */ 'wcgateway.settings.invoice-prefix' => static function (ContainerInterface $container): string { $site_url = get_site_url(get_current_blog_id()); $hash = md5($site_url); $letters = preg_replace('~\d~', '', $hash) ?? ''; $prefix = substr($letters, 0, 6); return $prefix ? $prefix . '-' : ''; }, /** * Returns random 6 characters length alphabetic prefix, followed by a hyphen. */ 'wcgateway.settings.invoice-prefix-random' => static function (ContainerInterface $container): string { $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $prefix = ''; for ($i = 0; $i < 6; $i++) { $prefix .= $characters[wp_rand(0, strlen($characters) - 1)]; } return $prefix . '-'; }, 'wcgateway.store-api.endpoint.cart' => static function (ContainerInterface $container): CartEndpoint { return new CartEndpoint($container->get('wcgateway.store-api.factory.cart'), $container->get('woocommerce.logger.woocommerce')); }, 'wcgateway.store-api.factory.cart' => static function (ContainerInterface $container): CartFactory { return new CartFactory($container->get('wcgateway.store-api.factory.cart-totals'), $container->get('wcgateway.store-api.factory.shipping-rates')); }, 'wcgateway.store-api.factory.cart-totals' => static function (ContainerInterface $container): CartTotalsFactory { return new CartTotalsFactory($container->get('wcgateway.store-api.factory.money')); }, 'wcgateway.store-api.factory.shipping-rates' => static function (ContainerInterface $container): ShippingRatesFactory { return new ShippingRatesFactory($container->get('wcgateway.store-api.factory.money')); }, 'wcgateway.store-api.factory.money' => static function (ContainerInterface $container): MoneyFactory { return new MoneyFactory(); }, 'wcgateway.shipping.callback.endpoint' => static function (ContainerInterface $container): ShippingCallbackEndpoint { return new ShippingCallbackEndpoint($container->get('wcgateway.store-api.endpoint.cart'), $container->get('api.factory.amount'), $container->get('woocommerce.logger.woocommerce'), $container->get('button.session.storage.card-data.transient')); }, 'wcgateway.shipping.callback.factory.url' => static function (ContainerInterface $container): ShippingCallbackUrlFactory { return new ShippingCallbackUrlFactory($container->get('wcgateway.store-api.endpoint.cart'), $container->get('wcgateway.shipping.callback.endpoint')); }, 'wcgateway.server-side-shipping-callback-enabled' => static function (ContainerInterface $container): bool { // SSSC depends on Woo's Store API, which currently doesn't work with plain permalinks because of the rest_get_url_prefix bug. $has_plain_permalinks = empty(get_option('permalink_structure')); $last_webhook_storage = $container->get('webhook.last-webhook-storage'); assert($last_webhook_storage instanceof WebhookEventStorage); // Not directly related, but if webhooks are not arriving then SSSC probably is not accessible too. $webhooks_working = !$last_webhook_storage->is_empty(); $enabled = getenv('PCP_SERVER_SIDE_SHIPPING_CALLBACK_ENABLED') !== '0' && !$has_plain_permalinks && $webhooks_working; return apply_filters( // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 'woocommerce.feature-flags.woocommerce_paypal_payments.server_side_shipping_callback_enabled', $enabled ); }, 'wcgateway.appswitch-enabled' => static function (ContainerInterface $container): bool { return apply_filters( // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 'woocommerce.feature-flags.woocommerce_paypal_payments.appswitch_enabled', getenv('PCP_APPSWITCH_ENABLED') !== '0' ); }, );