woocommerce-paypal-payments/modules.local/ppcp-api-client/services.php

167 lines
7.1 KiB
PHP
Raw Normal View History

2020-04-02 08:38:00 +03:00
<?php
2020-04-14 19:18:12 +03:00
2020-04-02 08:38:00 +03:00
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\ApiClient;
use Dhii\Data\Container\ContainerInterface;
2020-04-10 12:55:50 +03:00
use Inpsyde\CacheModule\Provider\CacheProviderInterface;
2020-04-02 08:38:00 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Authentication\Bearer;
2020-04-14 11:35:32 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Config\Config;
2020-04-02 08:38:00 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
2020-04-14 15:38:39 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
2020-04-06 10:51:56 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Factory\AddressFactory;
use Inpsyde\PayPalCommerce\ApiClient\Factory\AmountFactory;
2020-04-14 19:18:12 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Factory\AuthorizationFactory;
2020-04-13 11:52:50 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Factory\ErrorResponseCollectionFactory;
2020-04-06 10:51:56 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Factory\ItemFactory;
use Inpsyde\PayPalCommerce\ApiClient\Factory\OrderFactory;
use Inpsyde\PayPalCommerce\ApiClient\Factory\PatchCollectionFactory;
use Inpsyde\PayPalCommerce\ApiClient\Factory\PayeeFactory;
use Inpsyde\PayPalCommerce\ApiClient\Factory\PayerFactory;
2020-04-14 19:18:12 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Factory\PaymentsFactory;
2020-04-06 10:51:56 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use Inpsyde\PayPalCommerce\ApiClient\Factory\ShippingFactory;
2020-04-02 08:38:00 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
2020-04-13 09:07:20 +03:00
use Inpsyde\PayPalCommerce\ApiClient\Repository\PayeeRepository;
2020-04-14 15:38:39 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
2020-04-02 08:38:00 +03:00
return [
2020-04-06 11:16:18 +03:00
'api.host' => function (ContainerInterface $container) : string {
2020-04-02 08:38:00 +03:00
return 'https://api.sandbox.paypal.com';
},
2020-04-06 11:16:18 +03:00
'api.key' => function (ContainerInterface $container) : string {
2020-04-02 08:38:00 +03:00
return 'AQB97CzMsd58-It1vxbcDAGvMuXNCXRD9le_XUaMlHB_U7XsU9IiItBwGQOtZv9sEeD6xs2vlIrL4NiD';
},
2020-04-06 11:16:18 +03:00
'api.secret' => function (ContainerInterface $container) : string {
2020-04-02 08:38:00 +03:00
return 'EILGMYK_0iiSbja8hT-nCBGl0BvKxEB4riHgyEO7QWDeUzCJ5r42JUEvrI7gpGyw0Qww8AIXxSdCIAny';
},
2020-04-06 11:16:18 +03:00
'api.bearer' => function (ContainerInterface $container) : Bearer {
2020-04-10 12:55:50 +03:00
$provider = $container->get('cache.provider');
/**
* @var CacheProviderInterface $provider
*/
$cache = $provider->cacheOrTransientForKey('');
2020-04-02 08:38:00 +03:00
return new Bearer(
2020-04-10 12:55:50 +03:00
$cache,
2020-04-02 08:38:00 +03:00
$container->get('api.host'),
$container->get('api.key'),
$container->get('api.secret')
);
},
2020-04-14 19:18:12 +03:00
'api.endpoint.payments' => function (ContainerInterface $container): PaymentsEndpoint {
2020-04-14 15:38:39 +03:00
$authorizationFactory = $container->get('api.factory.authorization');
$errorResponseFactory = $container->get('api.factory.response-error');
return new PaymentsEndpoint(
$container->get('api.host'),
$container->get('api.bearer'),
$authorizationFactory,
$errorResponseFactory
);
},
2020-04-14 19:18:12 +03:00
'api.endpoint.order' => function (ContainerInterface $container): OrderEndpoint {
2020-04-06 10:51:56 +03:00
$orderFactory = $container->get('api.factory.order');
$patchCollectionFactory = $container->get('api.factory.patch-collection-factory');
2020-04-13 11:52:50 +03:00
$errorResponseFactory = $container->get('api.factory.response-error');
2020-04-13 15:26:30 +03:00
/**
* @var Settings $settings
*/
$settings = $container->get('wcgateway.settings');
$intent = strtoupper($settings->get('intent'));
2020-04-02 08:38:00 +03:00
return new OrderEndpoint(
$container->get('api.host'),
$container->get('api.bearer'),
2020-04-06 10:51:56 +03:00
$orderFactory,
$patchCollectionFactory,
$intent,
2020-04-13 11:52:50 +03:00
$errorResponseFactory
2020-04-02 08:38:00 +03:00
);
},
2020-04-13 09:07:20 +03:00
'api.repository.cart' => function (ContainerInterface $container) : CartRepository {
2020-04-06 10:51:56 +03:00
/*
2020-04-06 11:16:18 +03:00
* ToDo: We need to watch out and see, if we can load the Cart Repository
* only on specific situations.
* @see http://ppc-dev-website.localhost/wp-admin/admin.php?page=wc-settings&tab=tax
2020-04-06 10:51:56 +03:00
*/
2020-04-02 08:38:00 +03:00
$cart = WC()->cart;
2020-04-06 10:51:56 +03:00
if (! $cart) {
2020-04-06 11:16:18 +03:00
/**
* ToDo: The cart repository gets pulled in the wp-admin,
* where there is no WC Cart loaded. Rethink.
**/
2020-04-06 10:51:56 +03:00
$cart = new \WC_Cart();
}
$factory = $container->get('api.factory.purchase-unit');
2020-04-02 08:38:00 +03:00
return new CartRepository($cart, $factory);
},
2020-04-13 09:07:20 +03:00
'api.config.config' => function (ContainerInterface $container) : Config {
return new Config();
},
'api.repository.payee' => function (ContainerInterface $container) : PayeeRepository {
$config = $container->get('api.config.config');
return new PayeeRepository($config);
},
2020-04-06 11:16:18 +03:00
'api.factory.purchase-unit' => function (ContainerInterface $container) : PurchaseUnitFactory {
2020-04-06 10:51:56 +03:00
$amountFactory = $container->get('api.factory.amount');
2020-04-13 09:07:20 +03:00
$payeeRepository = $container->get('api.repository.payee');
2020-04-06 10:51:56 +03:00
$payeeFactory = $container->get('api.factory.payee');
$itemFactory = $container->get('api.factory.item');
$shippingFactory = $container->get('api.factory.shipping');
2020-04-14 19:18:12 +03:00
$paymentsFactory = $container->get('api.factory.payments');
2020-04-06 10:51:56 +03:00
return new PurchaseUnitFactory(
$amountFactory,
2020-04-13 09:07:20 +03:00
$payeeRepository,
2020-04-06 10:51:56 +03:00
$payeeFactory,
$itemFactory,
2020-04-14 19:18:12 +03:00
$shippingFactory,
$paymentsFactory
2020-04-06 10:51:56 +03:00
);
},
2020-04-06 11:16:18 +03:00
'api.factory.patch-collection-factory' => function (ContainerInterface $container)
: PatchCollectionFactory {
2020-04-06 10:51:56 +03:00
return new PatchCollectionFactory();
},
2020-04-06 11:16:18 +03:00
'api.factory.payee' => function (ContainerInterface $container) : PayeeFactory {
2020-04-06 10:51:56 +03:00
return new PayeeFactory();
},
2020-04-06 11:16:18 +03:00
'api.factory.item' => function (ContainerInterface $container) : ItemFactory {
2020-04-06 10:51:56 +03:00
return new ItemFactory();
},
2020-04-06 11:16:18 +03:00
'api.factory.shipping' => function (ContainerInterface $container) : ShippingFactory {
2020-04-06 10:51:56 +03:00
$addressFactory = $container->get('api.factory.address');
return new ShippingFactory($addressFactory);
},
2020-04-06 11:16:18 +03:00
'api.factory.amount' => function (ContainerInterface $container) : AmountFactory {
2020-04-14 11:35:32 +03:00
$itemFactory = $container->get('api.factory.item');
return new AmountFactory($itemFactory);
2020-04-06 10:51:56 +03:00
},
2020-04-06 11:16:18 +03:00
'api.factory.payer' => function (ContainerInterface $container) : PayerFactory {
2020-04-06 10:51:56 +03:00
$addressFactory = $container->get('api.factory.address');
return new PayerFactory($addressFactory);
},
2020-04-06 11:16:18 +03:00
'api.factory.address' => function (ContainerInterface $container) : AddressFactory {
2020-04-06 10:51:56 +03:00
return new AddressFactory();
},
2020-04-13 11:52:50 +03:00
'api.factory.response-error' => function (ContainerInterface $container) : ErrorResponseCollectionFactory {
return new ErrorResponseCollectionFactory();
},
2020-04-06 11:16:18 +03:00
'api.factory.order' => function (ContainerInterface $container) : OrderFactory {
2020-04-06 10:51:56 +03:00
$purchaseUnitFactory = $container->get('api.factory.purchase-unit');
$payerFactory = $container->get('api.factory.payer');
return new OrderFactory($purchaseUnitFactory, $payerFactory);
2020-04-02 08:38:00 +03:00
},
2020-04-14 19:18:12 +03:00
'api.factory.payments' => function (ContainerInterface $container): PaymentsFactory {
$authorizationFactory = $container->get('api.factory.authorization');
return new PaymentsFactory($authorizationFactory);
},
'api.factory.authorization' => function (ContainerInterface $container): AuthorizationFactory {
return new AuthorizationFactory();
2020-04-14 15:38:39 +03:00
},
2020-04-02 08:38:00 +03:00
];