PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / src / Subscriptions / Actions / GenerateNextRenewalForSubscription.php

GenerateNextRenewalForSubscription.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/Subscriptions/Actions/GenerateNextRenewalForSubscription.php

45 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Give\Subscriptions\Actions;
6
7 use DateInterval;
8 use DateTime;
9 use DateTimeInterface;
10 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
11 use Give\Framework\Support\Facades\DateTime\Temporal;
12 use Give\Subscriptions\ValueObjects\SubscriptionPeriod;
13
14 /**
15 * Generates the next renewal date for a subscription. A base date may be provided, otherwise it will default to the
16 * current date.
17 *
18 * @since 2.23.0
19 */
20 class GenerateNextRenewalForSubscription
21 {
22 /**
23 * @since 4.17.0 Declare the nullable parameter explicitly.
24 */
25 public function __invoke(
26 SubscriptionPeriod $period,
27 int $frequency,
28 ?DateTimeInterface $baseDate = null
29 ): DateTimeInterface {
30 if ( $frequency < 1 ) {
31 throw new InvalidArgumentException('Frequency must be greater than 0');
32 }
33
34 // Calculate the quarter as times 3 months
35 if ($period->equals(SubscriptionPeriod::QUARTER())) {
36 $frequency *= 3;
37 $period = SubscriptionPeriod::MONTH();
38 }
39
40 $baseDate = $baseDate ?? new DateTime('now', wp_timezone());
41
42 return Temporal::withoutMicroseconds($baseDate->modify("$frequency {$period->getValue()}"));
43 }
44 }
45