PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.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 2.3.2 All 256 releases
give / src / PaymentGateways / Gateways / Offline / Actions / DisableGatewayWhenDisabledPerForm.php

DisableGatewayWhenDisabledPerForm.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/PaymentGateways/Gateways/Offline/Actions/DisableGatewayWhenDisabledPerForm.php

50 lines 1.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\PaymentGateways\Gateways\Offline\Actions;
4
5 use Give\DonationForms\Models\DonationForm;
6 use Give\Framework\Exceptions\Primitives\RuntimeException;
7 use Give\Framework\PaymentGateways\PaymentGateway;
8 use Give\PaymentGateways\Gateways\Offline\OfflineGateway;
9
10 /**
11 * Checks to see if the Offline gateway is disabled for the form and disables it if so. *
12 *
13 * @since 3.0.0
14 */
15 class DisableGatewayWhenDisabledPerForm
16 {
17 /**
18 * @since 3.0.0
19 *
20 * @param array<PaymentGateway> $gateways
21 *
22 * @return array<PaymentGateway>
23 */
24 public function __invoke(array $gateways, int $formId): array
25 {
26 if (!array_key_exists(OfflineGateway::id(), $gateways)) {
27 return $gateways;
28 }
29
30 $form = DonationForm::find($formId);
31
32 $paymentGatewaysBlock = $form->blocks->findByName('givewp/payment-gateways');
33 if (!$paymentGatewaysBlock) {
34 throw new RuntimeException('Payment gateways block not found');
35 }
36
37 if (!$paymentGatewaysBlock->hasAttribute('offlineEnabled')) {
38 return $gateways;
39 }
40
41 ['offlineEnabled' => $enabled] = $paymentGatewaysBlock->getAttributes();
42
43 if (!$enabled) {
44 unset($gateways[OfflineGateway::id()]);
45 }
46
47 return $gateways;
48 }
49 }
50