2020-04-02 08:38:00 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Inpsyde\PayPalCommerce\WcGateway;
|
|
|
|
|
|
|
|
use Dhii\Container\ServiceProvider;
|
|
|
|
use Dhii\Modular\Module\ModuleInterface;
|
2020-04-13 12:39:34 +03:00
|
|
|
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
2020-04-02 08:38:00 +03:00
|
|
|
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
|
|
|
use Interop\Container\ServiceProviderInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
|
|
|
class WcGatewayModule implements ModuleInterface
|
|
|
|
{
|
|
|
|
|
|
|
|
public function setup(): ServiceProviderInterface
|
|
|
|
{
|
|
|
|
return new ServiceProvider(
|
|
|
|
require __DIR__.'/../services.php',
|
|
|
|
require __DIR__.'/../extensions.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
public function run(ContainerInterface $container)
|
2020-04-02 08:38:00 +03:00
|
|
|
{
|
|
|
|
add_filter(
|
|
|
|
'woocommerce_payment_gateways',
|
2020-04-06 11:16:18 +03:00
|
|
|
function ($methods) use ($container) : array {
|
2020-04-02 08:38:00 +03:00
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
$methods[] = $container->get('wcgateway.gateway');
|
2020-04-02 08:38:00 +03:00
|
|
|
return (array) $methods;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'woocommerce_available_payment_gateways',
|
2020-04-06 11:16:18 +03:00
|
|
|
function ($methods) use ($container) : array {
|
|
|
|
$disabler = $container->get('wcgateway.disabler');
|
2020-04-02 08:38:00 +03:00
|
|
|
/**
|
|
|
|
* @var DisableGateways $disabler
|
|
|
|
*/
|
|
|
|
return $disabler->handler((array) $methods);
|
|
|
|
}
|
|
|
|
);
|
2020-04-13 12:39:34 +03:00
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'woocommerce_order_actions',
|
|
|
|
function ($orderActions) : array {
|
|
|
|
$orderActions['ppcp_authorize_order'] = __(
|
|
|
|
'Authorize PayPal Order',
|
|
|
|
'woocommerce-paypal-gateway'
|
|
|
|
);
|
|
|
|
return $orderActions;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_order_action_ppcp_authorize_order',
|
|
|
|
function (\WC_Order $wcOrder) use ($container) {
|
|
|
|
$payPalOrderId = get_post_meta($wcOrder->get_id(), '_paypal_order_id', true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var OrderEndpoint $orderEndpoint
|
|
|
|
*/
|
|
|
|
$orderEndpoint = $container->get('api.endpoint.order');
|
|
|
|
|
|
|
|
$orderEndpoint->authorize($payPalOrderId);
|
|
|
|
|
|
|
|
$wcOrder->update_status('processing');
|
|
|
|
}
|
|
|
|
);
|
2020-04-02 08:38:00 +03:00
|
|
|
}
|
2020-04-06 11:16:18 +03:00
|
|
|
}
|