woocommerce-paypal-payments/modules/ppcp-wc-gateway/extensions.php

110 lines
4.4 KiB
PHP
Raw Normal View History

2020-04-02 08:38:00 +03:00
<?php
2020-08-28 08:13:45 +03:00
/**
* The extensions of the gateway module.
*
2020-09-11 14:11:10 +03:00
* @package WooCommerce\PayPalCommerce\WcGateway
2020-08-28 08:13:45 +03:00
*/
2020-04-28 12:31:12 +03:00
2020-04-02 08:38:00 +03:00
declare(strict_types=1);
2020-09-11 14:11:10 +03:00
namespace WooCommerce\PayPalCommerce\WcGateway;
2020-04-02 08:38:00 +03:00
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
use WooCommerce\WooCommerce\Logging\Logger\WooCommerceLogger;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
2020-07-10 15:45:49 +03:00
use Psr\Log\LoggerInterface;
2020-07-02 12:48:40 +03:00
2020-08-28 08:13:45 +03:00
return array(
2020-06-30 11:03:57 +03:00
2021-10-13 15:02:10 +03:00
'api.merchant_email' => static function ( ContainerInterface $container ): string {
2020-08-28 08:13:45 +03:00
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'merchant_email' ) ? (string) $settings->get( 'merchant_email' ) : '';
},
2021-10-13 15:02:10 +03:00
'api.merchant_id' => static function ( ContainerInterface $container ): string {
2020-08-28 08:13:45 +03:00
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'merchant_id' ) ? (string) $settings->get( 'merchant_id' ) : '';
},
2021-10-13 15:02:10 +03:00
'api.partner_merchant_id' => static function ( ContainerInterface $container ): string {
$environment = $container->get( 'onboarding.environment' );
/**
* The environment.
*
* @var Environment $environment
*/
return $environment->current_environment_is( Environment::SANDBOX ) ?
(string) $container->get( 'api.partner_merchant_id-sandbox' ) : (string) $container->get( 'api.partner_merchant_id-production' );
2020-08-28 08:13:45 +03:00
},
2021-10-13 15:02:10 +03:00
'api.key' => static function ( ContainerInterface $container ): string {
2020-08-28 08:13:45 +03:00
$settings = $container->get( 'wcgateway.settings' );
$key = $settings->has( 'client_id' ) ? (string) $settings->get( 'client_id' ) : '';
return $key;
},
2021-10-13 15:02:10 +03:00
'api.secret' => static function ( ContainerInterface $container ): string {
2020-08-28 08:13:45 +03:00
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'client_secret' ) ? (string) $settings->get( 'client_secret' ) : '';
},
2021-10-13 15:02:10 +03:00
'api.prefix' => static function ( ContainerInterface $container ): string {
2020-08-28 08:13:45 +03:00
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'prefix' ) ? (string) $settings->get( 'prefix' ) : 'WC-';
},
2021-10-13 15:02:10 +03:00
'api.endpoint.order' => static function ( ContainerInterface $container ): OrderEndpoint {
2020-08-28 08:13:45 +03:00
$order_factory = $container->get( 'api.factory.order' );
$patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
/**
* The session handler.
*
* @var SessionHandler $session_handler
*/
$session_handler = $container->get( 'session.handler' );
$bn_code = $session_handler->bn_code();
2020-07-16 09:28:00 +03:00
2020-08-28 08:13:45 +03:00
/**
* The settings.
*
* @var Settings $settings
*/
$settings = $container->get( 'wcgateway.settings' );
$intent = $settings->has( 'intent' ) && strtoupper( (string) $settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
$application_context_repository = $container->get( 'api.repository.application-context' );
$subscription_helper = $container->get( 'subscription.helper' );
2020-08-28 08:13:45 +03:00
return new OrderEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$order_factory,
$patch_collection_factory,
$intent,
$logger,
$application_context_repository,
$subscription_helper,
2020-08-28 08:13:45 +03:00
$bn_code
);
},
2021-10-13 15:02:10 +03:00
'woocommerce.logger.woocommerce' => function ( ContainerInterface $container ): LoggerInterface {
2022-03-29 14:04:43 +03:00
if ( ! function_exists( 'wc_get_logger' ) || ! $container->get( 'wcgateway.logging.is-enabled' ) ) {
2020-08-28 08:13:45 +03:00
return new NullLogger();
}
2020-07-10 15:45:49 +03:00
2020-08-28 08:13:45 +03:00
$source = $container->get( 'woocommerce.logger.source' );
return new WooCommerceLogger(
wc_get_logger(),
$source
);
},
2022-10-31 15:57:47 +04:00
'wcgateway.settings.fields' => function ( ContainerInterface $container, array $fields ): array {
$get_connection_tab_fields = require __DIR__ . '/connection-tab-settings.php';
$connection_tab_fields = $get_connection_tab_fields( $container, $fields ) ?? array();
$get_pay_later_tab_fields = require __DIR__ . '/pay-later-tab-settings.php';
$pay_later_tab_fields = $get_pay_later_tab_fields( $container, $fields ) ?? array();
return array_merge( $connection_tab_fields, $pay_later_tab_fields );
},
2020-08-28 08:13:45 +03:00
);