2020-04-02 08:38:00 +03:00
|
|
|
<?php
|
2020-04-09 14:36:52 +03:00
|
|
|
|
2020-04-02 08:38:00 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Inpsyde\PayPalCommerce\Button;
|
|
|
|
|
|
|
|
use Dhii\Data\Container\ContainerInterface;
|
2020-04-09 14:34:45 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Button\Assets\DisabledSmartButton;
|
|
|
|
use Inpsyde\PayPalCommerce\Button\Assets\SmartButton;
|
|
|
|
use Inpsyde\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
2020-04-08 16:23:33 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint;
|
2020-04-02 08:38:00 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint;
|
|
|
|
use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
|
|
|
|
use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
|
|
|
|
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
|
|
|
|
|
|
|
return [
|
2020-04-28 12:31:12 +03:00
|
|
|
'button.smart-button' => static function (ContainerInterface $container): SmartButtonInterface {
|
2020-04-09 14:34:45 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
2020-04-13 09:07:20 +03:00
|
|
|
$payeeRepository = $container->get('api.repository.payee');
|
2020-04-09 14:34:45 +03:00
|
|
|
if (wc_string_to_bool($settings->get('enabled'))) {
|
|
|
|
return new SmartButton(
|
|
|
|
$container->get('button.url'),
|
|
|
|
$container->get('session.handler'),
|
2020-04-13 09:07:20 +03:00
|
|
|
$settings,
|
|
|
|
$payeeRepository
|
2020-04-09 14:34:45 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return new DisabledSmartButton();
|
2020-04-02 08:38:00 +03:00
|
|
|
},
|
2020-04-28 12:31:12 +03:00
|
|
|
'button.url' => static function (ContainerInterface $container): string {
|
2020-04-06 11:16:18 +03:00
|
|
|
return plugins_url(
|
|
|
|
'/modules/ppcp-button/',
|
|
|
|
dirname(__FILE__, 3) . '/woocommerce-paypal-commerce-gateway.php'
|
|
|
|
);
|
2020-04-02 08:38:00 +03:00
|
|
|
},
|
2020-04-28 12:31:12 +03:00
|
|
|
'button.request-data' => static function (ContainerInterface $container): RequestData {
|
2020-04-02 08:38:00 +03:00
|
|
|
return new RequestData();
|
|
|
|
},
|
2020-04-28 12:31:12 +03:00
|
|
|
'button.endpoint.change-cart' => static function (ContainerInterface $container): ChangeCartEndpoint {
|
2020-04-09 14:36:52 +03:00
|
|
|
if (!\WC()->cart) {
|
2020-04-02 08:38:00 +03:00
|
|
|
throw new RuntimeException('cant initialize endpoint at this moment');
|
|
|
|
}
|
|
|
|
$cart = WC()->cart;
|
|
|
|
$shipping = WC()->shipping();
|
|
|
|
$requestData = $container->get('button.request-data');
|
2020-04-10 16:39:25 +03:00
|
|
|
$repository = $container->get('api.repository.cart');
|
2020-04-29 12:11:53 +03:00
|
|
|
$dataStore = \WC_Data_Store::load('product');
|
|
|
|
return new ChangeCartEndpoint($cart, $shipping, $requestData, $repository, $dataStore);
|
2020-04-02 08:38:00 +03:00
|
|
|
},
|
2020-04-28 12:31:12 +03:00
|
|
|
'button.endpoint.create-order' => static function (ContainerInterface $container): CreateOrderEndpoint {
|
2020-04-02 08:38:00 +03:00
|
|
|
$requestData = $container->get('button.request-data');
|
2020-04-10 16:39:25 +03:00
|
|
|
$repository = $container->get('api.repository.cart');
|
2020-04-02 08:38:00 +03:00
|
|
|
$apiClient = $container->get('api.endpoint.order');
|
2020-04-16 10:29:25 +03:00
|
|
|
$payerFactory = $container->get('api.factory.payer');
|
|
|
|
return new CreateOrderEndpoint($requestData, $repository, $apiClient, $payerFactory);
|
2020-04-06 11:16:18 +03:00
|
|
|
},
|
2020-04-28 12:31:12 +03:00
|
|
|
'button.endpoint.approve-order' => static function (ContainerInterface $container): ApproveOrderEndpoint {
|
2020-04-08 16:23:33 +03:00
|
|
|
$requestData = $container->get('button.request-data');
|
|
|
|
$apiClient = $container->get('api.endpoint.order');
|
|
|
|
$sessionHandler = $container->get('session.handler');
|
|
|
|
return new ApproveOrderEndpoint($requestData, $apiClient, $sessionHandler);
|
|
|
|
},
|
2020-04-02 08:38:00 +03:00
|
|
|
];
|