PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.5
GiveWP – Donation Plugin and Fundraising Platform v4.15.5
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 / Framework / PaymentGateways / Webhooks / EventHandlers / Actions / UpdateSubscriptionStatus.php

UpdateSubscriptionStatus.php in GiveWP – Donation Plugin and Fundraising Platform 4.15.5, at src/Framework/PaymentGateways/Webhooks/EventHandlers/Actions/UpdateSubscriptionStatus.php

81 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\PaymentGateways\Webhooks\EventHandlers\Actions;
4
5 use Exception;
6 use Give\Framework\PaymentGateways\Log\PaymentGatewayLog;
7 use Give\Subscriptions\Models\Subscription;
8 use Give\Subscriptions\ValueObjects\SubscriptionStatus;
9
10 /**
11 * @since 3.6.0
12 */
13 class UpdateSubscriptionStatus
14 {
15 /**
16 * @since 3.6.0
17 *
18 * @throws Exception
19 */
20 public function __invoke(
21 Subscription $subscription,
22 SubscriptionStatus $status,
23 string $message = ''
24 ) {
25 $subscription->status = $status;
26 $subscription->save();
27
28 if (empty($message)) {
29 $message = $this->getMessageFromStatus($status);
30 }
31
32 PaymentGatewayLog::info(
33 $message . ' ' . sprintf('Subscription ID: %s.', $subscription->id),
34 [
35 'Payment Gateway' => $subscription->gatewayId,
36 'Gateway Subscription Id' => $subscription->gatewaySubscriptionId,
37 'Subscription ID' => $subscription->id,
38 ]
39 );
40 }
41
42
43 /**
44 * @since 4.5.0 Add support for PAUSED and PENDING statuses
45 * @since 3.6.0
46 */
47 protected function getMessageFromStatus(SubscriptionStatus $status): string
48 {
49 $message = '';
50
51 switch (true):
52 case ($status->isCompleted()):
53 $message = __('Subscription Completed.', 'give');
54 break;
55 case ($status->isExpired()):
56 $message = __('Subscription Expired.', 'give');
57 break;
58 case ($status->isActive()):
59 $message = __('Subscription Active.', 'give');
60 break;
61 case ($status->isCancelled()):
62 $message = __('Subscription Cancelled.', 'give');
63 break;
64 case ($status->isFailing()):
65 $message = __('Subscription Failing.', 'give');
66 break;
67 case ($status->isPaused()):
68 $message = __('Subscription Paused.', 'give');
69 break;
70 case ($status->isPending()):
71 $message = __('Subscription Pending.', 'give');
72 break;
73 case ($status->isSuspended()):
74 $message = __('Subscription Suspended.', 'give');
75 break;
76 endswitch;
77
78 return $message;
79 }
80 }
81