2020-04-02 08:38:00 +03:00
|
|
|
<?php
|
2020-04-28 12:31:12 +03:00
|
|
|
|
2020-04-02 08:38:00 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Inpsyde\PayPalCommerce\WcGateway;
|
|
|
|
|
2020-07-16 09:28:00 +03:00
|
|
|
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
|
|
|
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
|
|
|
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
2020-07-10 15:45:49 +03:00
|
|
|
use Inpsyde\Woocommerce\Logging\Logger\NullLogger;
|
|
|
|
use Inpsyde\Woocommerce\Logging\Logger\WooCommerceLogger;
|
2020-07-02 12:48:40 +03:00
|
|
|
use Psr\Container\ContainerInterface;
|
2020-07-10 15:45:49 +03:00
|
|
|
use Psr\Log\LoggerInterface;
|
2020-07-02 12:48:40 +03:00
|
|
|
|
2020-04-02 08:38:00 +03:00
|
|
|
return [
|
2020-06-30 11:03:57 +03:00
|
|
|
|
2020-07-02 12:48:40 +03:00
|
|
|
'api.merchant_email' => static function (ContainerInterface $container): string {
|
2020-06-30 11:03:57 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
return $settings->has('merchant_email') ? (string) $settings->get('merchant_email') : '';
|
|
|
|
},
|
2020-07-02 12:48:40 +03:00
|
|
|
'api.merchant_id' => static function (ContainerInterface $container): string {
|
2020-06-30 11:03:57 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
return $settings->has('merchant_id') ? (string) $settings->get('merchant_id') : '';
|
|
|
|
},
|
2020-07-02 12:48:40 +03:00
|
|
|
'api.partner_merchant_id' => static function (): string {
|
2020-06-30 11:03:57 +03:00
|
|
|
// ToDo: Replace with the real merchant id of platform
|
|
|
|
return 'KQ8FCM66JFGDL';
|
|
|
|
},
|
2020-07-02 12:48:40 +03:00
|
|
|
'api.key' => static function (ContainerInterface $container): string {
|
2020-06-30 11:03:57 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
$key = $settings->has('client_id') ? (string) $settings->get('client_id') : '';
|
|
|
|
return $key;
|
|
|
|
},
|
2020-07-02 12:48:40 +03:00
|
|
|
'api.secret' => static function (ContainerInterface $container): string {
|
2020-06-30 11:03:57 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
return $settings->has('client_secret') ? (string) $settings->get('client_secret') : '';
|
|
|
|
},
|
2020-07-28 07:03:15 +03:00
|
|
|
'api.prefix' => static function (ContainerInterface $container): string {
|
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
return $settings->has('prefix') ? (string) $settings->get('prefix') : 'WC-';
|
|
|
|
},
|
2020-07-16 09:28:00 +03:00
|
|
|
'api.endpoint.order' => static function (ContainerInterface $container): OrderEndpoint {
|
|
|
|
$orderFactory = $container->get('api.factory.order');
|
|
|
|
$patchCollectionFactory = $container->get('api.factory.patch-collection-factory');
|
|
|
|
$logger = $container->get('woocommerce.logger.woocommerce');
|
|
|
|
/**
|
|
|
|
* @var SessionHandler $sessionHandler
|
|
|
|
*/
|
|
|
|
$sessionHandler = $container->get('session.handler');
|
|
|
|
$bnCode = $sessionHandler->bnCode();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Settings $settings
|
|
|
|
*/
|
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
$intent = $settings->has('intent') && strtoupper((string) $settings->get('intent')) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
|
|
|
|
$applicationContextRepository = $container->get('api.repository.application-context');
|
2020-08-19 15:19:47 +03:00
|
|
|
$paypalRequestId = $container->get('api.repository.paypal-request-id');
|
2020-07-16 09:28:00 +03:00
|
|
|
return new OrderEndpoint(
|
|
|
|
$container->get('api.host'),
|
|
|
|
$container->get('api.bearer'),
|
|
|
|
$orderFactory,
|
|
|
|
$patchCollectionFactory,
|
|
|
|
$intent,
|
|
|
|
$logger,
|
|
|
|
$applicationContextRepository,
|
2020-08-19 15:19:47 +03:00
|
|
|
$paypalRequestId,
|
2020-07-16 09:28:00 +03:00
|
|
|
$bnCode
|
|
|
|
);
|
|
|
|
},
|
2020-07-10 15:45:49 +03:00
|
|
|
'woocommerce.logger.woocommerce' => function (ContainerInterface $container): LoggerInterface {
|
|
|
|
$settings = $container->get('wcgateway.settings');
|
2020-07-22 11:00:07 +03:00
|
|
|
if (! function_exists('wc_get_logger') || ! $settings->has('logging_enabled') || ! $settings->get('logging_enabled')) {
|
2020-07-10 15:45:49 +03:00
|
|
|
return new NullLogger();
|
|
|
|
}
|
|
|
|
|
|
|
|
$source = $container->get('woocommerce.logger.source');
|
|
|
|
return new WooCommerceLogger(
|
|
|
|
wc_get_logger(),
|
|
|
|
$source
|
|
|
|
);
|
|
|
|
},
|
2020-04-02 08:38:00 +03:00
|
|
|
];
|