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
|
|
|
|
2025-02-03 13:34:30 +01:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
|
|
|
|
use WooCommerce\WooCommerce\Logging\Logger\WooCommerceLogger;
|
2022-11-09 10:11:31 +02:00
|
|
|
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
|
|
|
|
2023-12-19 17:26:09 +00:00
|
|
|
'api.merchant_email' => static function ( string $previous, 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' ) : '';
|
|
|
|
},
|
2023-12-19 17:26:09 +00:00
|
|
|
'api.merchant_id' => static function ( string $previous, 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' ) : '';
|
|
|
|
},
|
2023-12-19 17:26:09 +00:00
|
|
|
'api.partner_merchant_id' => static function ( string $previous, ContainerInterface $container ): string {
|
2020-10-13 09:42:34 +03:00
|
|
|
$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
|
|
|
},
|
2023-12-19 17:26:09 +00:00
|
|
|
'api.key' => static function ( string $previous, 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;
|
|
|
|
},
|
2023-12-19 17:26:09 +00:00
|
|
|
'api.secret' => static function ( string $previous, 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' ) : '';
|
|
|
|
},
|
2023-12-19 17:26:09 +00:00
|
|
|
'api.prefix' => static function ( string $previous, 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-';
|
|
|
|
},
|
2023-12-19 17:26:09 +00:00
|
|
|
'woocommerce.logger.woocommerce' => function ( LoggerInterface $previous, 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
|
|
|
|
);
|
|
|
|
},
|
2023-12-19 17:26:09 +00:00
|
|
|
'wcgateway.settings.fields' => function ( array $fields, ContainerInterface $container ): array {
|
2023-11-07 16:34:16 +02:00
|
|
|
$files = array(
|
|
|
|
'paypal-smart-button-fields.php',
|
|
|
|
'connection-tab-fields.php',
|
|
|
|
'pay-later-tab-fields.php',
|
2023-11-08 08:39:53 +02:00
|
|
|
'card-button-fields.php',
|
2023-11-07 16:34:16 +02:00
|
|
|
);
|
2022-10-31 15:57:47 +04:00
|
|
|
|
2023-11-07 16:34:16 +02:00
|
|
|
return array_merge(
|
|
|
|
...array_map(
|
|
|
|
function ( string $file ) use ( $container, $fields ): array {
|
|
|
|
$path_to_settings_fields = __DIR__ . '/src/Settings/Fields/';
|
|
|
|
/**
|
|
|
|
* Skip path check.
|
|
|
|
*
|
|
|
|
* @psalm-suppress UnresolvableInclude
|
|
|
|
*/
|
|
|
|
$get_fields = require $path_to_settings_fields . $file;
|
|
|
|
return $get_fields( $container, $fields ) ?? array();
|
|
|
|
},
|
|
|
|
$files
|
|
|
|
)
|
|
|
|
);
|
2022-10-31 15:57:47 +04:00
|
|
|
},
|
2020-08-28 08:13:45 +03:00
|
|
|
);
|