mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* The subscription module.
|
|
*
|
|
* @package WooCommerce\PayPalCommerce\Subscription
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace WooCommerce\PayPalCommerce\Subscription;
|
|
|
|
use Dhii\Container\ServiceProvider;
|
|
use Dhii\Modular\Module\ModuleInterface;
|
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokenEndpoint;
|
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
|
use Interop\Container\ServiceProviderInterface;
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
/**
|
|
* Class SubscriptionModule
|
|
*/
|
|
class SubscriptionModule implements ModuleInterface {
|
|
|
|
/**
|
|
* Setup the module.
|
|
*
|
|
* @return ServiceProviderInterface
|
|
*/
|
|
public function setup(): ServiceProviderInterface {
|
|
return new ServiceProvider(
|
|
require __DIR__ . '/../services.php',
|
|
require __DIR__ . '/../extensions.php'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Runs the module.
|
|
*
|
|
* @param ContainerInterface|null $container The container.
|
|
*/
|
|
public function run( ContainerInterface $container = null ) {
|
|
add_action(
|
|
'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID,
|
|
function ( $amount, $order ) use ( $container ) {
|
|
$this->renew( $order, $container );
|
|
},
|
|
10,
|
|
2
|
|
);
|
|
|
|
add_action(
|
|
'woocommerce_scheduled_subscription_payment_' . CreditCardGateway::ID,
|
|
function ( $amount, $order ) use ( $container ) {
|
|
$this->renew( $order, $container );
|
|
},
|
|
10,
|
|
2
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param $order
|
|
* @param ContainerInterface|null $container
|
|
* @return void
|
|
*/
|
|
protected function renew( $order, ?ContainerInterface $container ) {
|
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
|
return;
|
|
}
|
|
|
|
/** @var RenewalHandler $handler */
|
|
$handler = $container->get( 'subscription.renewal-handler' );
|
|
$handler->renew( $order );
|
|
}
|
|
|
|
/**
|
|
* Returns the key for the module.
|
|
*
|
|
* @return string|void
|
|
*/
|
|
public function getKey() {
|
|
}
|
|
}
|