PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
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 2.31.0 All 254 releases
give / src / Subscriptions / Actions / LoadSubscriptionAdminOptions.php

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

78 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Subscriptions\Actions;
4
5 use Give\API\REST\V3\Routes\Donations\ValueObjects\DonationRoute;
6 use Give\BetaFeatures\Facades\FeatureFlag;
7 use Give\Framework\PaymentGateways\PaymentGateway;
8 use Give\Subscriptions\ValueObjects\SubscriptionStatus;
9
10 /**
11 * The purpose of this action is to have a centralized place for localizing options used on many different places
12 * by donation scripts (list tables, blocks, etc.)
13 *
14 * @since 4.8.0
15 */
16 class LoadSubscriptionAdminOptions
17 {
18 public function __invoke()
19 {
20 wp_register_script('give-subscription-options', false);
21 wp_localize_script('give-subscription-options', 'GiveSubscriptionOptions', $this->getSubscriptionOptions());
22 wp_enqueue_script('give-subscription-options');
23 }
24
25 /**
26 * Get all donation options for localization
27 *
28 * @since 4.8.0
29 */
30 private function getSubscriptionOptions(): array
31 {
32 $isAdmin = is_admin();
33
34 return [
35 'isAdmin' => $isAdmin,
36 'adminUrl' => admin_url(),
37 'pluginUrl' => GIVE_PLUGIN_URL,
38 'apiRoot' => rest_url(DonationRoute::NAMESPACE),
39 'legacyApiRoot' => esc_url_raw(rest_url('give-api/v2/admin')),
40 'apiNonce' => wp_create_nonce('wp_rest'),
41 'syncSubscriptionNonce' => wp_create_nonce( 'sync-subscription-details' ),
42 'subscriptionsAdminUrl' => admin_url('edit.php?post_type=give_forms&page=give-subscriptions'),
43 'currency' => give_get_currency(),
44 'subscriptionStatuses' => SubscriptionStatus::labels(),
45 'isRecurringEnabled' => defined('GIVE_RECURRING_VERSION') ? GIVE_RECURRING_VERSION : null,
46 'eventTicketsEnabled' => FeatureFlag::eventTickets(),
47 'isFeeRecoveryEnabled' => defined('GIVE_FEE_RECOVERY_VERSION'),
48 'mode' => give_is_test_mode() ? 'test' : 'live',
49 'gateways' => $this->getGateways(),
50 ];
51 }
52
53 /**
54 * Get gateways
55 *
56 * @since 4.8.0
57 */
58 private function getGateways(): array
59 {
60 $enabledGateways = array_keys(give_get_enabled_payment_gateways());
61
62 $gateways = array_map(static function ($gatewayClass) use ($enabledGateways) {
63 /** @var PaymentGateway $gateway */
64 $gateway = give($gatewayClass);
65
66 return [
67 'id' => $gateway::id(),
68 'enabled' => in_array($gateway::id(), $enabledGateways, true),
69 'label' => $gateway->getName(),
70 'supportsSubscriptions' => $gateway->supportsSubscriptions(),
71 'supportsRefund' => $gateway->supportsRefund(),
72 ];
73 }, give()->gateways->getPaymentGateways());
74
75 return array_values($gateways);
76 }
77 }
78