Enable renewals for PayPal and credit card, remove deprecated subscription methods

This commit is contained in:
dinamiko 2021-03-01 12:37:13 +01:00
parent b9c2550f3b
commit 4b50f8caeb
2 changed files with 34 additions and 13 deletions

View file

@ -120,7 +120,7 @@ class RenewalHandler {
'order' => $wc_order,
)
);
\WC_Subscriptions_Manager::process_subscription_payment_failure_on_order( $wc_order );
return;
}
$this->logger->log(
@ -156,12 +156,13 @@ class RenewalHandler {
}
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
$payer = $this->payer_factory->from_customer( $customer );
$order = $this->order_endpoint->create(
$order = $this->order_endpoint->create(
array( $purchase_unit ),
$payer,
$token,
(string) $wc_order->get_id()
$token
);
$this->capture_order( $order, $wc_order );
}
@ -192,7 +193,6 @@ class RenewalHandler {
'order' => $wc_order,
)
);
\WC_Subscriptions_Manager::process_subscription_payment_failure_on_order( $wc_order );
}
return $token;
}
@ -210,13 +210,11 @@ class RenewalHandler {
'processing',
__( 'Payment received.', 'woocommerce-paypal-payments' )
);
\WC_Subscriptions_Manager::process_subscription_payments_on_order( $wc_order );
}
if ( $order->intent() === 'AUTHORIZE' ) {
$this->order_endpoint->authorize( $order );
$wc_order->update_meta_data( PayPalGateway::CAPTURED_META_KEY, 'false' );
\WC_Subscriptions_Manager::process_subscription_payments_on_order( $wc_order );
}
}
}

View file

@ -11,7 +11,10 @@ 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;
@ -40,16 +43,36 @@ class SubscriptionModule implements ModuleInterface {
public function run( ContainerInterface $container = null ) {
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 );
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 );
}
/**