PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.2.0
GiveWP – Donation Plugin and Fundraising Platform v4.2.0
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 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / PaymentGateways / Webhooks / EventHandlers / Actions / UpdateSubscriptionStatus.php
UpdateSubscriptionStatus.php
74 lines 2.0 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 3.6.0
45 */
46 protected function getMessageFromStatus(SubscriptionStatus $status): string
47 {
48 $message = '';
49
50 switch (true):
51 case ($status->isCompleted()):
52 $message = __('Subscription Completed.', 'give');
53 break;
54 case ($status->isExpired()):
55 $message = __('Subscription Expired.', 'give');
56 break;
57 case ($status->isActive()):
58 $message = __('Subscription Active.', 'give');
59 break;
60 case ($status->isCancelled()):
61 $message = __('Subscription Cancelled.', 'give');
62 break;
63 case ($status->isFailing()):
64 $message = __('Subscription Failing.', 'give');
65 break;
66 case ($status->isSuspended()):
67 $message = __('Subscription Suspended.', 'give');
68 break;
69 endswitch;
70
71 return $message;
72 }
73 }
74