-
Notifications
You must be signed in to change notification settings - Fork 47
/
extensions.php
92 lines (85 loc) · 3.6 KB
/
extensions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* The extensions of the gateway module.
*
* @package Inpsyde\PayPalCommerce\WcGateway
*/
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway;
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
use Inpsyde\WooCommerce\Logging\Logger\NullLogger;
use Inpsyde\WooCommerce\Logging\Logger\WooCommerceLogger;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
return array(
'api.merchant_email' => static function ( ContainerInterface $container ): string {
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'merchant_email' ) ? (string) $settings->get( 'merchant_email' ) : '';
},
'api.merchant_id' => static function ( ContainerInterface $container ): string {
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'merchant_id' ) ? (string) $settings->get( 'merchant_id' ) : '';
},
'api.partner_merchant_id' => static function (): string {
// @ToDo: Replace with the real merchant id of platform
return 'KQ8FCM66JFGDL';
},
'api.key' => static function ( ContainerInterface $container ): string {
$settings = $container->get( 'wcgateway.settings' );
$key = $settings->has( 'client_id' ) ? (string) $settings->get( 'client_id' ) : '';
return $key;
},
'api.secret' => static function ( ContainerInterface $container ): string {
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'client_secret' ) ? (string) $settings->get( 'client_secret' ) : '';
},
'api.prefix' => static function ( ContainerInterface $container ): string {
$settings = $container->get( 'wcgateway.settings' );
return $settings->has( 'prefix' ) ? (string) $settings->get( 'prefix' ) : 'WC-';
},
'api.endpoint.order' => static function ( ContainerInterface $container ): OrderEndpoint {
$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();
/**
* 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' );
$pay_pal_request_id_repository = $container->get( 'api.repository.paypal-request-id' );
return new OrderEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$order_factory,
$patch_collection_factory,
$intent,
$logger,
$application_context_repository,
$pay_pal_request_id_repository,
$bn_code
);
},
'woocommerce.logger.woocommerce' => function ( ContainerInterface $container ): LoggerInterface {
$settings = $container->get( 'wcgateway.settings' );
if ( ! function_exists( 'wc_get_logger' ) || ! $settings->has( 'logging_enabled' ) || ! $settings->get( 'logging_enabled' ) ) {
return new NullLogger();
}
$source = $container->get( 'woocommerce.logger.source' );
return new WooCommerceLogger(
wc_get_logger(),
$source
);
},
);