2020-07-28 12:27:42 +03:00
|
|
|
<?php
|
2020-08-27 11:50:10 +03:00
|
|
|
/**
|
|
|
|
* The subscription module.
|
|
|
|
*
|
2020-09-11 14:11:10 +03:00
|
|
|
* @package WooCommerce\PayPalCommerce\Subscription
|
2020-08-27 11:50:10 +03:00
|
|
|
*/
|
2020-07-28 12:27:42 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
namespace WooCommerce\PayPalCommerce\Subscription;
|
2020-07-28 12:27:42 +03:00
|
|
|
|
|
|
|
use Dhii\Container\ServiceProvider;
|
|
|
|
use Dhii\Modular\Module\ModuleInterface;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
2020-07-28 12:27:42 +03:00
|
|
|
use Interop\Container\ServiceProviderInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
2020-08-27 11:50:10 +03:00
|
|
|
/**
|
|
|
|
* Class SubscriptionModule
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
class SubscriptionModule implements ModuleInterface {
|
2020-07-28 12:27:42 +03:00
|
|
|
|
2020-08-27 11:50:10 +03:00
|
|
|
/**
|
|
|
|
* Setup the module.
|
|
|
|
*
|
|
|
|
* @return ServiceProviderInterface
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
public function setup(): ServiceProviderInterface {
|
|
|
|
return new ServiceProvider(
|
|
|
|
require __DIR__ . '/../services.php',
|
|
|
|
require __DIR__ . '/../extensions.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-27 11:50:10 +03:00
|
|
|
* Runs the module.
|
|
|
|
*
|
2020-09-16 10:18:45 +03:00
|
|
|
* @param ContainerInterface|null $container The container.
|
2020-08-27 11:08:36 +03:00
|
|
|
*/
|
2020-09-16 10:18:45 +03:00
|
|
|
public function run( ContainerInterface $container = null ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
add_action(
|
|
|
|
'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID,
|
|
|
|
static function ( $amount, $order ) use ( $container ) {
|
|
|
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$handler = $container->get( 'subscription.renewal-handler' );
|
|
|
|
$handler->renew( $order );
|
|
|
|
},
|
|
|
|
10,
|
|
|
|
2
|
|
|
|
);
|
|
|
|
}
|
2020-09-16 10:18:45 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the key for the module.
|
|
|
|
*
|
|
|
|
* @return string|void
|
|
|
|
*/
|
|
|
|
public function getKey() {
|
|
|
|
}
|
2020-07-28 12:27:42 +03:00
|
|
|
}
|