PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
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 2.3.2 2.30.0 All 255 releases
give / src / Framework / PaymentGateways / Actions / HandleGatewaySubscriptionCommand.php

HandleGatewaySubscriptionCommand.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Framework/PaymentGateways/Actions/HandleGatewaySubscriptionCommand.php

79 lines 2.6 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\Actions;
4
5 use Exception;
6 use Give\Donations\Models\Donation;
7 use Give\Framework\FieldsAPI\Exceptions\TypeNotSupported;
8 use Give\Framework\Http\Response\Types\JsonResponse;
9 use Give\Framework\Http\Response\Types\RedirectResponse;
10 use Give\Framework\PaymentGateways\CommandHandlers\RedirectOffsiteHandler;
11 use Give\Framework\PaymentGateways\CommandHandlers\RespondToBrowserHandler;
12 use Give\Framework\PaymentGateways\CommandHandlers\SubscriptionCompleteHandler;
13 use Give\Framework\PaymentGateways\CommandHandlers\SubscriptionProcessingHandler;
14 use Give\Framework\PaymentGateways\CommandHandlers\SubscriptionSyncedHandler;
15 use Give\Framework\PaymentGateways\Commands\GatewayCommand;
16 use Give\Framework\PaymentGateways\Commands\RedirectOffsite;
17 use Give\Framework\PaymentGateways\Commands\RespondToBrowser;
18 use Give\Framework\PaymentGateways\Commands\SubscriptionComplete;
19 use Give\Framework\PaymentGateways\Commands\SubscriptionProcessing;
20 use Give\Framework\PaymentGateways\Commands\SubscriptionSynced;
21 use Give\Subscriptions\Models\Subscription;
22
23
24 /**
25 * @since 2.27.0
26 */
27 class HandleGatewaySubscriptionCommand
28 {
29 /**
30 *
31 * Handle gateway subscription command
32 *
33 * @since 2.27.0 return responses
34 * @since 2.26.0 add RespondToBrowser command
35 * @since 2.21.0 Handle RedirectOffsite response.
36 * @since 2.18.0
37 *
38 * @return JsonResponse|RedirectResponse
39 * @throws TypeNotSupported
40 * @throws Exception
41 */
42 public function __invoke(
43 GatewayCommand $command,
44 Donation $donation,
45 Subscription $subscription
46 ) {
47 if ($command instanceof SubscriptionComplete) {
48 (new SubscriptionCompleteHandler())($command, $subscription, $donation);
49
50 return new RedirectResponse(give_get_success_page_uri());
51 }
52
53 if ($command instanceof SubscriptionProcessing) {
54 (new SubscriptionProcessingHandler($command, $subscription, $donation))();
55
56 return new RedirectResponse(give_get_success_page_uri());
57 }
58
59 if ($command instanceof RedirectOffsite) {
60 return (new RedirectOffsiteHandler())($command);
61 }
62
63 if ($command instanceof RespondToBrowser) {
64 return (new RespondToBrowserHandler())($command);
65 }
66
67 if ($command instanceof SubscriptionSynced) {
68 return (new SubscriptionSyncedHandler())($command);
69 }
70
71 throw new TypeNotSupported(
72 sprintf(
73 "Return type must be an instance of %s",
74 GatewayCommand::class
75 )
76 );
77 }
78 }
79