Failed License::setRenewedTime()

Created on 3 July 2023, over 1 year ago
Updated 8 July 2023, over 1 year ago

Problem/Motivation

I have this error when the license has to be renewed, this is the message on the queues page:

Failed - Renew recurring order - Drupal\commerce_license\Entity\License::setRenewedTime(): Argument #1 ($timestamp) must be of type int, null given, called in /modules/contrib/commerce_license/src/Plugin/Commerce/SubscriptionType/LicenseSubscription.php on line 88.

Proposed resolution

When a subscription is first created there is no data for "Last renewed", so it uses the "Next Renewal Time".
Replace line 88 of commerce_license/src/Plugin/Commerce/SubscriptionType/LicenseSubscription.php.

$license->setRenewedTime($subscription->getRenewedTime());

To:

if ($subscription->getRenewedTime() === NULL) {
      $license->setRenewedTime($subscription->getNextRenewalTime());
} else {
      $license->setRenewedTime($subscription->getRenewedTime());
}
πŸ› Bug report
Status

Closed: duplicate

Version

3.0

Component

Code

Created by

πŸ‡΅πŸ‡ΎParaguay rubenjara Paraguay

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @rubenjara
  • πŸ‡«πŸ‡·France liliplanet Cannes

    Yes, same error on cron

  • πŸ‡΅πŸ‡ΎParaguay rubenjara Paraguay
  • Assigned to TomTech
  • Status changed to Closed: duplicate over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States TomTech

    Hi @rubenjara!

    Thanks for the report.

    After researching, this appears to be an issue in commerce recurring, which has been resolved in the current dev release:

    https://www.drupal.org/project/commerce_recurring/issues/3337411 πŸ› RecurringOrderManager calls onSubscriptionRenew before updating subscription Fixed

    Previously, recurringOrderManager was calling onSubscriptionRenew() before calling setRenewedTime()

          $subscription->getType()->onSubscriptionRenew($subscription, $order, $next_order);
          $next_order->save();
          // Update the subscription with the new order and renewal timestamp.
          $subscription->addOrder($next_order);
          $subscription->setRenewedTime($this->time->getCurrentTime());
          $subscription->setNextRenewalTime($next_billing_period->getEndDate()->getTimestamp());
          $subscription->save();
    

    This is fixed in the patch, by setting the renewed time before calling onSubscriptionRenew:

          $subscription->setRenewedTime($this->time->getCurrentTime());
          $subscription->setNextRenewalTime($next_billing_period->getEndDate()->getTimestamp());
          $subscription->getType()->onSubscriptionRenew($subscription, $order, $next_order);
          $next_order->save();
          // Update the subscription with the new order and renewal timestamp.
          $subscription->addOrder($next_order);
          $subscription->save();
    
Production build 0.71.5 2024