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;
|
2020-08-13 14:20:47 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Button\Endpoint\DataClientIdEndpoint;
|
2020-04-02 08:38:00 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
|
|
|
|
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
2020-07-15 10:27:40 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Button\Helper\ThreeDSecure;
|
2020-06-30 11:56:13 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Onboarding\Environment;
|
2020-06-15 11:48:37 +03:00
|
|
|
use Inpsyde\PayPalCommerce\Onboarding\State;
|
2020-04-02 08:38:00 +03:00
|
|
|
|
|
|
|
return [
|
2020-07-02 13:11:47 +03:00
|
|
|
'button.client_id' => static function (ContainerInterface $container): string {
|
2020-06-30 11:56:13 +03:00
|
|
|
|
|
|
|
$settings = $container->get('wcgateway.settings');
|
|
|
|
$clientId = $settings->has('client_id') ? $settings->get('client_id') : '';
|
|
|
|
if ($clientId) {
|
|
|
|
return $clientId;
|
|
|
|
}
|
|
|
|
|
|
|
|
$env = $container->get('onboarding.environment');
|
|
|
|
/**
|
|
|
|
* @var Environment $env
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ToDo: Add production platform client Id.
|
|
|
|
*/
|
|
|
|
return $env->currentEnvironmentIs(Environment::SANDBOX) ?
|
2020-07-02 09:37:07 +03:00
|
|
|
'AQB97CzMsd58-It1vxbcDAGvMuXNCXRD9le_XUaMlHB_U7XsU9IiItBwGQOtZv9sEeD6xs2vlIrL4NiD' : '';
|
2020-06-30 11:56:13 +03:00
|
|
|
},
|
2020-04-28 12:31:12 +03:00
|
|
|
'button.smart-button' => static function (ContainerInterface $container): SmartButtonInterface {
|
2020-04-30 15:28:48 +03:00
|
|
|
|
2020-06-15 11:48:37 +03:00
|
|
|
$state = $container->get('onboarding.state');
|
|
|
|
/**
|
|
|
|
* @var State $state
|
|
|
|
*/
|
|
|
|
if ($state->currentState() < State::STATE_PROGRESSIVE) {
|
|
|
|
return new DisabledSmartButton();
|
|
|
|
}
|
2020-04-09 14:34:45 +03:00
|
|
|
$settings = $container->get('wcgateway.settings');
|
2020-08-18 13:05:26 +03:00
|
|
|
$paypalDisabled = !$settings->has('enabled') || ! $settings->get('enabled');
|
|
|
|
$creditCardDisabled = !$settings->has('dcc_gateway_enabled') || ! $settings->get('dcc_gateway_enabled');
|
|
|
|
if ($paypalDisabled && $creditCardDisabled) {
|
2020-04-30 15:28:48 +03:00
|
|
|
return new DisabledSmartButton();
|
2020-04-09 14:34:45 +03:00
|
|
|
}
|
2020-04-30 15:28:48 +03:00
|
|
|
$payeeRepository = $container->get('api.repository.payee');
|
|
|
|
$identityToken = $container->get('api.endpoint.identity-token');
|
2020-05-07 12:43:46 +03:00
|
|
|
$payerFactory = $container->get('api.factory.payer');
|
2020-07-10 12:33:13 +03:00
|
|
|
$requestData = $container->get('button.request-data');
|
2020-06-30 11:56:13 +03:00
|
|
|
|
|
|
|
$clientId = $container->get('button.client_id');
|
2020-07-23 11:10:37 +03:00
|
|
|
$dccApplies = $container->get('api.helpers.dccapplies');
|
2020-07-28 12:27:42 +03:00
|
|
|
$subscriptionHelper = $container->get('subscription.helper');
|
2020-04-30 15:28:48 +03:00
|
|
|
return new SmartButton(
|
|
|
|
$container->get('button.url'),
|
|
|
|
$container->get('session.handler'),
|
|
|
|
$settings,
|
|
|
|
$payeeRepository,
|
2020-05-07 12:43:46 +03:00
|
|
|
$identityToken,
|
2020-06-30 11:56:13 +03:00
|
|
|
$payerFactory,
|
2020-07-10 12:33:13 +03:00
|
|
|
$clientId,
|
2020-07-23 11:10:37 +03:00
|
|
|
$requestData,
|
2020-07-28 12:27:42 +03:00
|
|
|
$dccApplies,
|
|
|
|
$subscriptionHelper
|
2020-04-30 15:28:48 +03:00
|
|
|
);
|
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(
|
2020-06-29 11:26:18 +03:00
|
|
|
'/modules.local/ppcp-button/',
|
2020-04-06 11:16:18 +03:00
|
|
|
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');
|
2020-07-16 09:28:00 +03:00
|
|
|
$sessionHandler = $container->get('session.handler');
|
|
|
|
return new CreateOrderEndpoint($requestData, $repository, $apiClient, $payerFactory, $sessionHandler);
|
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');
|
2020-07-16 10:16:43 +03:00
|
|
|
$threeDSecure = $container->get('button.helper.three-d-secure');
|
2020-07-15 10:27:40 +03:00
|
|
|
return new ApproveOrderEndpoint($requestData, $apiClient, $sessionHandler, $threeDSecure);
|
|
|
|
},
|
2020-08-13 14:20:47 +03:00
|
|
|
'button.endpoint.data-client-id' => static function(ContainerInterface $container) : DataClientIdEndpoint {
|
|
|
|
$requestData = $container->get('button.request-data');
|
|
|
|
$tokenEndpoint = $container->get('api.endpoint.identity-token');
|
|
|
|
return new DataClientIdEndpoint(
|
|
|
|
$requestData,
|
|
|
|
$tokenEndpoint
|
|
|
|
);
|
|
|
|
},
|
2020-07-16 10:16:43 +03:00
|
|
|
'button.helper.three-d-secure' => static function (ContainerInterface $container): ThreeDSecure {
|
2020-07-15 10:27:40 +03:00
|
|
|
return new ThreeDSecure();
|
2020-04-08 16:23:33 +03:00
|
|
|
},
|
2020-04-02 08:38:00 +03:00
|
|
|
];
|