Completed
Branch master (076535)
by
unknown
06:25
created
espresso.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -37,138 +37,138 @@
 block discarded – undo
37 37
  * @since       4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time.
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time.
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
 <div class="error">
49 49
     <p>
50 50
         <?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
     </p>
56 56
 </div>
57 57
 <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
 <div class="error">
74 74
     <p>
75 75
         <?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
-                    );
86
-        ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
+					);
86
+		?>
87 87
     </p>
88 88
 </div>
89 89
 <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96 96
 
97
-        require_once __DIR__ . '/vendor/autoload.php';
97
+		require_once __DIR__ . '/vendor/autoload.php';
98 98
 
99
-        /**
100
-         * espresso_version
101
-         * Returns the plugin version
102
-         *
103
-         * @return string
104
-         */
105
-        function espresso_version(): string
106
-        {
107
-            return apply_filters('FHEE__espresso__espresso_version', '5.0.39.rc.000');
108
-        }
99
+		/**
100
+		 * espresso_version
101
+		 * Returns the plugin version
102
+		 *
103
+		 * @return string
104
+		 */
105
+		function espresso_version(): string
106
+		{
107
+			return apply_filters('FHEE__espresso__espresso_version', '5.0.39.rc.000');
108
+		}
109 109
 
110
-        /**
111
-         * espresso_plugin_activation
112
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
-         */
114
-        function espresso_plugin_activation()
115
-        {
116
-            update_option('ee_espresso_activation', true);
117
-            update_option('event-espresso-core_allow_tracking', 'no');
118
-            update_option('event-espresso-core_tracking_notice', 'hide');
119
-            // Run WP GraphQL activation callback
120
-            espressoLoadWpGraphQL();
121
-            graphql_activation_callback();
122
-        }
110
+		/**
111
+		 * espresso_plugin_activation
112
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
+		 */
114
+		function espresso_plugin_activation()
115
+		{
116
+			update_option('ee_espresso_activation', true);
117
+			update_option('event-espresso-core_allow_tracking', 'no');
118
+			update_option('event-espresso-core_tracking_notice', 'hide');
119
+			// Run WP GraphQL activation callback
120
+			espressoLoadWpGraphQL();
121
+			graphql_activation_callback();
122
+		}
123 123
 
124
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
124
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
125 125
 
126
-        /**
127
-         * espresso_plugin_deactivation
128
-         */
129
-        function espresso_plugin_deactivation()
130
-        {
131
-            // Run WP GraphQL deactivation callback
132
-            espressoLoadWpGraphQL();
133
-            graphql_deactivation_callback();
134
-            delete_option('event-espresso-core_allow_tracking');
135
-            delete_option('event-espresso-core_tracking_notice');
136
-        }
137
-        register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
126
+		/**
127
+		 * espresso_plugin_deactivation
128
+		 */
129
+		function espresso_plugin_deactivation()
130
+		{
131
+			// Run WP GraphQL deactivation callback
132
+			espressoLoadWpGraphQL();
133
+			graphql_deactivation_callback();
134
+			delete_option('event-espresso-core_allow_tracking');
135
+			delete_option('event-espresso-core_tracking_notice');
136
+		}
137
+		register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
138 138
 
139
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
140
-        bootstrap_espresso();
141
-    }
139
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
140
+		bootstrap_espresso();
141
+	}
142 142
 }
143 143
 
144 144
 if (! function_exists('espresso_deactivate_plugin')) {
145
-    /**
146
-     *    deactivate_plugin
147
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
-     *
149
-     * @access public
150
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
-     * @return    void
152
-     */
153
-    function espresso_deactivate_plugin(string $plugin_basename = '')
154
-    {
155
-        if (! function_exists('deactivate_plugins')) {
156
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
-        }
158
-        unset($_GET['activate'], $_REQUEST['activate']);
159
-        deactivate_plugins($plugin_basename);
160
-    }
145
+	/**
146
+	 *    deactivate_plugin
147
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
+	 *
149
+	 * @access public
150
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
+	 * @return    void
152
+	 */
153
+	function espresso_deactivate_plugin(string $plugin_basename = '')
154
+	{
155
+		if (! function_exists('deactivate_plugins')) {
156
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
+		}
158
+		unset($_GET['activate'], $_REQUEST['activate']);
159
+		deactivate_plugins($plugin_basename);
160
+	}
161 161
 }
162 162
 
163 163
 
164 164
 if (! function_exists('espressoLoadWpGraphQL')) {
165
-    function espressoLoadWpGraphQL()
166
-    {
167
-        if (
168
-            ! class_exists('WPGraphQL')
169
-            && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
-        ) {
171
-            require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
-        }
173
-    }
165
+	function espressoLoadWpGraphQL()
166
+	{
167
+		if (
168
+			! class_exists('WPGraphQL')
169
+			&& is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
+		) {
171
+			require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
+		}
173
+	}
174 174
 }
Please login to merge, or discard this patch.
core/services/payments/PaymentProcessorFees.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -28,162 +28,162 @@
 block discarded – undo
28 28
  */
29 29
 class PaymentProcessorFees
30 30
 {
31
-    public const  GATEWAY_PAYPAL  = 'PayPal Commerce';
32
-
33
-    public const  GATEWAY_SQUARE  = 'Square';
34
-
35
-    public const  GATEWAY_STRIPE  = 'Stripe';
36
-
37
-    private GracePeriod $grace_period;
38
-
39
-    private LicenseData $license_data;
40
-
41
-    /**
42
-     * @var float[][] $gateway_fees
43
-     */
44
-    private array $gateway_fees = [
45
-        LicenseData::LICENSE_ACTIVE  => [
46
-            PaymentProcessorFees::GATEWAY_PAYPAL => 0.00,
47
-            PaymentProcessorFees::GATEWAY_SQUARE => 0.00,
48
-            PaymentProcessorFees::GATEWAY_STRIPE => 0.00,
49
-        ],
50
-        LicenseData::LICENSE_EXPIRED => [
51
-            PaymentProcessorFees::GATEWAY_PAYPAL => 3.00,
52
-            PaymentProcessorFees::GATEWAY_SQUARE => 2.50,
53
-            PaymentProcessorFees::GATEWAY_STRIPE => 3.00,
54
-        ],
55
-        LicenseData::LICENSE_DECAF   => [
56
-            PaymentProcessorFees::GATEWAY_PAYPAL => 3.00,
57
-            PaymentProcessorFees::GATEWAY_SQUARE => 2.50,
58
-            PaymentProcessorFees::GATEWAY_STRIPE => 3.00,
59
-        ],
60
-    ];
61
-
62
-    private array $partner_gateways = [
63
-        PaymentProcessorFees::GATEWAY_PAYPAL,
64
-        PaymentProcessorFees::GATEWAY_SQUARE,
65
-        PaymentProcessorFees::GATEWAY_STRIPE,
66
-    ];
67
-
68
-
69
-    /**
70
-     * @param GracePeriod $grace_period
71
-     * @param LicenseData $license_data
72
-     */
73
-    public function __construct(GracePeriod $grace_period, LicenseData $license_data)
74
-    {
75
-        $this->grace_period = $grace_period;
76
-        $this->license_data = $license_data;
77
-    }
78
-
79
-
80
-    /**
81
-     * @param EE_Transaction $transaction
82
-     * @param string         $payment_method_name
83
-     * @param float          $amount
84
-     * @return float
85
-     * @throws EE_Error|ReflectionException|RuntimeException
86
-     * @throws Exception
87
-     */
88
-    public function applyGatewayPartnerFees(
89
-        EE_Transaction $transaction,
90
-        string $payment_method_name,
91
-        float $amount = 0.00
92
-    ): float {
93
-        $processing_fee = $this->forPaymentMethod($payment_method_name);
94
-        if ($processing_fee <= 0.00) {
95
-            return $amount;
96
-        }
97
-        $grand_total = $transaction->total_line_item(false);
98
-        if (
99
-            ! $grand_total instanceof EE_Line_Item
100
-            || ! $grand_total->is_total()
101
-            || $grand_total->TXN_ID() !== $transaction->ID()
102
-        ) {
103
-            // throw RuntimeException if total_line_item is not a total line item
104
-            throw new RuntimeException(
105
-                sprintf(
106
-                    esc_html__(
107
-                        'Invalid or missing grand total line item for transaction %1$d.',
108
-                        'event_espresso'
109
-                    ),
110
-                    $transaction->ID()
111
-                )
112
-            );
113
-        }
114
-        $line_item = EEH_Line_Item::add_percentage_based_item(
115
-            EEH_Line_Item::get_pre_tax_subtotal($grand_total),
116
-            esc_html__('Payment Processing Fee', 'event_espresso'),
117
-            $processing_fee,
118
-            '',
119
-            false,
120
-            sanitize_key(
121
-                sprintf(
122
-                    '%1$s-fee-%2$d',
123
-                    $payment_method_name,
124
-                    $transaction->ID()
125
-                )
126
-            ),
127
-            true
128
-        );
129
-        $line_item->save();
130
-        return $grand_total->recalculate_total_including_taxes();
131
-    }
132
-
133
-
134
-    /**
135
-     * Returns the fee for a specific payment method based on the license status.
136
-     *
137
-     * @param string $payment_method_name
138
-     * @return float
139
-     * @throws Exception|OutOfBoundsException|RuntimeException
140
-     */
141
-    public function forPaymentMethod(string $payment_method_name): float
142
-    {
143
-        if (! $this->isPartnerGateway($payment_method_name)) {
144
-            return 0.0;
145
-        }
146
-        $license_status = $this->license_data->licenseStatus();
147
-        $license_expires = $this->license_data->licenseExpiry();
148
-        // decaf, new activations, or expired licenses are allowed a grace period
149
-        if ($this->grace_period->withinGracePeriod($license_status, $license_expires)) {
150
-            return 0.0;
151
-        }
152
-        return $this->getGatewayFee($payment_method_name, $license_status);
153
-    }
154
-
155
-
156
-    /**
157
-     * Checks if a gateway is a partner gateway.
158
-     *
159
-     * @param string $payment_method_name
160
-     * @return bool
161
-     */
162
-    private function isPartnerGateway(string $payment_method_name): bool
163
-    {
164
-        return in_array($payment_method_name, $this->partner_gateways, true);
165
-    }
166
-
167
-
168
-    /**
169
-     * Returns the fee for a specific payment method based on the license status.
170
-     *
171
-     * @param string $payment_method_name
172
-     * @param string $license_status
173
-     * @return float
174
-     * @throws OutOfBoundsException
175
-     */
176
-    private function getGatewayFee(string $payment_method_name, string $license_status): float
177
-    {
178
-        if (isset($this->gateway_fees[ $license_status ][ $payment_method_name ])) {
179
-            return $this->gateway_fees[ $license_status ][ $payment_method_name ];
180
-        }
181
-        throw new OutOfBoundsException(
182
-            sprintf(
183
-                esc_html__('A partner fee for %1$s with %2$s license is not defined.', 'event_espresso'),
184
-                $payment_method_name,
185
-                $license_status
186
-            )
187
-        );
188
-    }
31
+	public const  GATEWAY_PAYPAL  = 'PayPal Commerce';
32
+
33
+	public const  GATEWAY_SQUARE  = 'Square';
34
+
35
+	public const  GATEWAY_STRIPE  = 'Stripe';
36
+
37
+	private GracePeriod $grace_period;
38
+
39
+	private LicenseData $license_data;
40
+
41
+	/**
42
+	 * @var float[][] $gateway_fees
43
+	 */
44
+	private array $gateway_fees = [
45
+		LicenseData::LICENSE_ACTIVE  => [
46
+			PaymentProcessorFees::GATEWAY_PAYPAL => 0.00,
47
+			PaymentProcessorFees::GATEWAY_SQUARE => 0.00,
48
+			PaymentProcessorFees::GATEWAY_STRIPE => 0.00,
49
+		],
50
+		LicenseData::LICENSE_EXPIRED => [
51
+			PaymentProcessorFees::GATEWAY_PAYPAL => 3.00,
52
+			PaymentProcessorFees::GATEWAY_SQUARE => 2.50,
53
+			PaymentProcessorFees::GATEWAY_STRIPE => 3.00,
54
+		],
55
+		LicenseData::LICENSE_DECAF   => [
56
+			PaymentProcessorFees::GATEWAY_PAYPAL => 3.00,
57
+			PaymentProcessorFees::GATEWAY_SQUARE => 2.50,
58
+			PaymentProcessorFees::GATEWAY_STRIPE => 3.00,
59
+		],
60
+	];
61
+
62
+	private array $partner_gateways = [
63
+		PaymentProcessorFees::GATEWAY_PAYPAL,
64
+		PaymentProcessorFees::GATEWAY_SQUARE,
65
+		PaymentProcessorFees::GATEWAY_STRIPE,
66
+	];
67
+
68
+
69
+	/**
70
+	 * @param GracePeriod $grace_period
71
+	 * @param LicenseData $license_data
72
+	 */
73
+	public function __construct(GracePeriod $grace_period, LicenseData $license_data)
74
+	{
75
+		$this->grace_period = $grace_period;
76
+		$this->license_data = $license_data;
77
+	}
78
+
79
+
80
+	/**
81
+	 * @param EE_Transaction $transaction
82
+	 * @param string         $payment_method_name
83
+	 * @param float          $amount
84
+	 * @return float
85
+	 * @throws EE_Error|ReflectionException|RuntimeException
86
+	 * @throws Exception
87
+	 */
88
+	public function applyGatewayPartnerFees(
89
+		EE_Transaction $transaction,
90
+		string $payment_method_name,
91
+		float $amount = 0.00
92
+	): float {
93
+		$processing_fee = $this->forPaymentMethod($payment_method_name);
94
+		if ($processing_fee <= 0.00) {
95
+			return $amount;
96
+		}
97
+		$grand_total = $transaction->total_line_item(false);
98
+		if (
99
+			! $grand_total instanceof EE_Line_Item
100
+			|| ! $grand_total->is_total()
101
+			|| $grand_total->TXN_ID() !== $transaction->ID()
102
+		) {
103
+			// throw RuntimeException if total_line_item is not a total line item
104
+			throw new RuntimeException(
105
+				sprintf(
106
+					esc_html__(
107
+						'Invalid or missing grand total line item for transaction %1$d.',
108
+						'event_espresso'
109
+					),
110
+					$transaction->ID()
111
+				)
112
+			);
113
+		}
114
+		$line_item = EEH_Line_Item::add_percentage_based_item(
115
+			EEH_Line_Item::get_pre_tax_subtotal($grand_total),
116
+			esc_html__('Payment Processing Fee', 'event_espresso'),
117
+			$processing_fee,
118
+			'',
119
+			false,
120
+			sanitize_key(
121
+				sprintf(
122
+					'%1$s-fee-%2$d',
123
+					$payment_method_name,
124
+					$transaction->ID()
125
+				)
126
+			),
127
+			true
128
+		);
129
+		$line_item->save();
130
+		return $grand_total->recalculate_total_including_taxes();
131
+	}
132
+
133
+
134
+	/**
135
+	 * Returns the fee for a specific payment method based on the license status.
136
+	 *
137
+	 * @param string $payment_method_name
138
+	 * @return float
139
+	 * @throws Exception|OutOfBoundsException|RuntimeException
140
+	 */
141
+	public function forPaymentMethod(string $payment_method_name): float
142
+	{
143
+		if (! $this->isPartnerGateway($payment_method_name)) {
144
+			return 0.0;
145
+		}
146
+		$license_status = $this->license_data->licenseStatus();
147
+		$license_expires = $this->license_data->licenseExpiry();
148
+		// decaf, new activations, or expired licenses are allowed a grace period
149
+		if ($this->grace_period->withinGracePeriod($license_status, $license_expires)) {
150
+			return 0.0;
151
+		}
152
+		return $this->getGatewayFee($payment_method_name, $license_status);
153
+	}
154
+
155
+
156
+	/**
157
+	 * Checks if a gateway is a partner gateway.
158
+	 *
159
+	 * @param string $payment_method_name
160
+	 * @return bool
161
+	 */
162
+	private function isPartnerGateway(string $payment_method_name): bool
163
+	{
164
+		return in_array($payment_method_name, $this->partner_gateways, true);
165
+	}
166
+
167
+
168
+	/**
169
+	 * Returns the fee for a specific payment method based on the license status.
170
+	 *
171
+	 * @param string $payment_method_name
172
+	 * @param string $license_status
173
+	 * @return float
174
+	 * @throws OutOfBoundsException
175
+	 */
176
+	private function getGatewayFee(string $payment_method_name, string $license_status): float
177
+	{
178
+		if (isset($this->gateway_fees[ $license_status ][ $payment_method_name ])) {
179
+			return $this->gateway_fees[ $license_status ][ $payment_method_name ];
180
+		}
181
+		throw new OutOfBoundsException(
182
+			sprintf(
183
+				esc_html__('A partner fee for %1$s with %2$s license is not defined.', 'event_espresso'),
184
+				$payment_method_name,
185
+				$license_status
186
+			)
187
+		);
188
+	}
189 189
 }
Please login to merge, or discard this patch.