pronamic / wp-pronamic-pay-restrict-content-pro

Restrict Content Pro driver for the WordPress payment processing library. http://www.wp-pay.org/extensions/restrict-content-pro/
3 stars 1 forks source link

Next payment date is time sensitive #24

Closed remcotolsma closed 1 month ago

remcotolsma commented 1 month ago

Restrict Content Pro does not have the ability to set a time on the expiration date, so we set the time to 00:00:00.

https://github.com/pronamic/wp-pronamic-pay-restrict-content-pro/blob/f8c50a8d7dc82e6f306851499699d435cc6ac9bf/src/SubscriptionUpdater.php#L113-L120

This can go wrong when determining the phase in which the next new period should be started:

  1. https://github.com/pronamic/wp-pay-core/blob/cc89c297372ebd818cc5e0bae737ac58ba8e74b8/src/Subscriptions/SubscriptionsFollowUpPaymentsController.php#L317-L348
  2. https://github.com/pronamic/wp-pay-core/blob/cc89c297372ebd818cc5e0bae737ac58ba8e74b8/src/Subscriptions/Subscription.php#L770-L783
  3. https://github.com/pronamic/wp-pay-core/blob/cc89c297372ebd818cc5e0bae737ac58ba8e74b8/src/Subscriptions/Subscription.php#L785-L805
  4. https://github.com/pronamic/wp-pay-core/blob/cc89c297372ebd818cc5e0bae737ac58ba8e74b8/src/Subscriptions/SubscriptionPhase.php#L426-L442

For example, with a subscription with the following initial phase:

      "sequence_number": 1,
      "start_date": "2023-07-31T12:09:52+00:00",
      "end_date": "2024-07-31T12:09:52+00:00",
      "interval": "P1Y",

And a regular phase:

      "sequence_number": 2,
      "start_date": "2024-07-31T12:09:52+00:00",
      "end_date": null,
      "interval": "P1Y",

A next payment date on 31-07-2024 (00:00:00) falls under the initial phase, while it should actually fall under the regular phase?

We discovered this via an internal HelpScout ticket: https://secure.helpscout.net/conversation/2665799921/27549?viewId=1425710.

Related issues:

remcotolsma commented 1 month ago

It appears that Restrict Content itself works with 23:59:59 in: https://github.com/stellarwp/restrict-content/blob/1b7914806e9703b6820d9073f0e6d965ebee7337/core/includes/admin/members/member-actions.php#L41

$expiration    = 'none' !== $expiration ? date( 'Y-m-d 23:59:59', strtotime( $_POST['expiration'], current_time( 'timestamp' ) ) ) : $expiration;

We can also work with the time of the phases.