Passed
Push — master ( eb862d...1f939a )
by Brian
06:09 queued 17s
created
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission refresh prices class
@@ -23,24 +23,24 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31 31
 			'has_subscription_group'           => $submission->has_subscription_group(),
32 32
 			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33
-            'is_free'                          => ! $submission->should_collect_payment_details(),
33
+            'is_free'                          => !$submission->should_collect_payment_details(),
34 34
 		);
35 35
 
36
-		$this->add_totals( $submission );
37
-		$this->add_texts( $submission );
38
-		$this->add_items( $submission );
39
-		$this->add_fees( $submission );
40
-		$this->add_discounts( $submission );
41
-		$this->add_taxes( $submission );
42
-		$this->add_gateways( $submission );
43
-		$this->add_data( $submission );
36
+		$this->add_totals($submission);
37
+		$this->add_texts($submission);
38
+		$this->add_items($submission);
39
+		$this->add_fees($submission);
40
+		$this->add_discounts($submission);
41
+		$this->add_taxes($submission);
42
+		$this->add_gateways($submission);
43
+		$this->add_data($submission);
44 44
 
45 45
 	}
46 46
 
@@ -49,30 +49,30 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @param GetPaid_Payment_Form_Submission $submission
51 51
 	 */
52
-	public function add_totals( $submission ) {
52
+	public function add_totals($submission) {
53 53
 
54 54
 		$this->response = array_merge(
55 55
 			$this->response,
56 56
 			array(
57 57
 
58 58
 				'totals'        => array(
59
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
61
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
62
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
63
-					'total'     => $submission->format_amount( $submission->get_total() ),
64
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
59
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
60
+					'discount'  => $submission->format_amount($submission->get_discount()),
61
+					'fees'      => $submission->format_amount($submission->get_fee()),
62
+					'tax'       => $submission->format_amount($submission->get_tax()),
63
+					'total'     => $submission->format_amount($submission->get_total()),
64
+					'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES),
65 65
 				),
66 66
 
67 67
 				'recurring'     => array(
68
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
+					'subtotal'  => $submission->format_amount($submission->get_recurring_subtotal()),
69
+					'discount'  => $submission->format_amount($submission->get_recurring_discount()),
70
+					'fees'      => $submission->format_amount($submission->get_recurring_fee()),
71
+					'tax'       => $submission->format_amount($submission->get_recurring_tax()),
72
+					'total'     => $submission->format_amount($submission->get_recurring_total()),
73 73
 				),
74 74
 
75
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
75
+				'initial_amt'   => wpinv_round_amount($submission->get_total(), null, true),
76 76
 				'currency'      => $submission->get_currency(),
77 77
 
78 78
 			)
@@ -85,53 +85,53 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @param GetPaid_Payment_Form_Submission $submission
87 87
 	 */
88
-	public function add_texts( $submission ) {
88
+	public function add_texts($submission) {
89 89
 
90
-		$payable = $submission->format_amount( $submission->get_total() );
91
-		$groups  = getpaid_get_subscription_groups( $submission );
90
+		$payable = $submission->format_amount($submission->get_total());
91
+		$groups  = getpaid_get_subscription_groups($submission);
92 92
 
93
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
93
+		if ($submission->has_recurring && 2 > count($groups)) {
94 94
 
95
-			$recurring = new WPInv_Item( $submission->has_recurring );
96
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
-			$main_item = reset( $groups );
95
+			$recurring = new WPInv_Item($submission->has_recurring);
96
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
97
+			$main_item = reset($groups);
98 98
 
99
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
99
+			if ($submission->get_total() == $submission->get_recurring_total()) {
100 100
 				$payable = "$payable / $period";
101
-			} else if ( $main_item ) {
101
+			} else if ($main_item) {
102 102
 
103
-				$main_item = reset( $main_item );
103
+				$main_item = reset($main_item);
104 104
 
105 105
 				// Calculate the next renewal date.
106
-				$_period      = $main_item->get_recurring_period( true );
106
+				$_period      = $main_item->get_recurring_period(true);
107 107
 				$_interval    = $main_item->get_recurring_interval();
108 108
 
109 109
 				// If the subscription item has a trial period...
110
-				if ( $main_item->has_free_trial() ) {
111
-					$_period   = $main_item->get_trial_period( true );
110
+				if ($main_item->has_free_trial()) {
111
+					$_period   = $main_item->get_trial_period(true);
112 112
 					$_interval = $main_item->get_trial_interval();
113 113
 				}
114 114
 
115 115
 				$payable = sprintf(
116
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
117
-					$submission->format_amount( $submission->get_total() ),
118
-					$submission->format_amount( $submission->get_recurring_total() ),
116
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
117
+					$submission->format_amount($submission->get_total()),
118
+					$submission->format_amount($submission->get_recurring_total()),
119 119
 					$period
120 120
 				);
121 121
 
122 122
 				$payable .= sprintf(
123 123
 					'<small class="text-muted form-text">%s</small>',
124 124
 					sprintf(
125
-						__( 'First renewal on %s', 'invoicing' ),
126
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
125
+						__('First renewal on %s', 'invoicing'),
126
+						getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp'))))
127 127
 					)
128 128
 				);
129 129
 
130 130
 			} else {
131 131
 				$payable = sprintf(
132
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
133
-					$submission->format_amount( $submission->get_total() ),
134
-					$submission->format_amount( $submission->get_recurring_total() ),
132
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
133
+					$submission->format_amount($submission->get_total()),
134
+					$submission->format_amount($submission->get_recurring_total()),
135 135
 					$period
136 136
 				);
137 137
 			}
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
 			'.getpaid-checkout-total-payable' => $payable,
143 143
 		);
144 144
 
145
-		foreach ( $submission->get_items() as $item ) {
145
+		foreach ($submission->get_items() as $item) {
146 146
 			$item_id                                               = $item->get_id();
147
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
148
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
149
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
147
+			$initial_price                                         = $submission->format_amount($item->get_sub_total() - $item->item_discount);
148
+			$recurring_price                                       = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount);
149
+			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price);
150 150
 		}
151 151
 
152
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
152
+		$this->response = array_merge($this->response, array('texts' => $texts));
153 153
 
154 154
 	}
155 155
 
@@ -158,19 +158,19 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @param GetPaid_Payment_Form_Submission $submission
160 160
 	 */
161
-	public function add_items( $submission ) {
161
+	public function add_items($submission) {
162 162
 
163 163
 		// Add items.
164 164
 		$items = array();
165 165
 
166
-        foreach ( $submission->get_items() as $item ) {
166
+        foreach ($submission->get_items() as $item) {
167 167
 			$item_id           = $item->get_id();
168
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
168
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
169 169
 		}
170 170
 
171 171
 		$this->response = array_merge(
172 172
 			$this->response,
173
-			array( 'items' => $items )
173
+			array('items' => $items)
174 174
 		);
175 175
 
176 176
 	}
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @param GetPaid_Payment_Form_Submission $submission
182 182
 	 */
183
-	public function add_fees( $submission ) {
183
+	public function add_fees($submission) {
184 184
 
185 185
 		$fees = array();
186 186
 
187
-        foreach ( $submission->get_fees() as $name => $data ) {
188
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
187
+        foreach ($submission->get_fees() as $name => $data) {
188
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
189 189
 		}
190 190
 
191 191
 		$this->response = array_merge(
192 192
 			$this->response,
193
-			array( 'fees' => $fees )
193
+			array('fees' => $fees)
194 194
 		);
195 195
 
196 196
 	}
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
 	 *
201 201
 	 * @param GetPaid_Payment_Form_Submission $submission
202 202
 	 */
203
-	public function add_discounts( $submission ) {
203
+	public function add_discounts($submission) {
204 204
 
205 205
 		$discounts = array();
206 206
 
207
-        foreach ( $submission->get_discounts() as $name => $data ) {
208
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
207
+        foreach ($submission->get_discounts() as $name => $data) {
208
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
209 209
 		}
210 210
 
211 211
 		$this->response = array_merge(
212 212
 			$this->response,
213
-			array( 'discounts' => $discounts )
213
+			array('discounts' => $discounts)
214 214
 		);
215 215
 
216 216
 	}
@@ -220,24 +220,24 @@  discard block
 block discarded – undo
220 220
 	 *
221 221
 	 * @param GetPaid_Payment_Form_Submission $submission
222 222
 	 */
223
-	public function add_taxes( $submission ) {
223
+	public function add_taxes($submission) {
224 224
 
225 225
 		$taxes  = array();
226 226
 		$markup = '';
227
-        foreach ( $submission->get_taxes() as $name => $data ) {
228
-			$name          = sanitize_text_field( $name );
229
-			$amount        = $submission->format_amount( $data['initial_tax'] );
227
+        foreach ($submission->get_taxes() as $name => $data) {
228
+			$name          = sanitize_text_field($name);
229
+			$amount        = $submission->format_amount($data['initial_tax']);
230 230
 			$taxes[$name]  = $amount;
231 231
 			$markup       .= "<small class='form-text'>$name : $amount</small>";
232 232
 		}
233 233
 
234
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
234
+		if (wpinv_display_individual_tax_rates() && !empty($taxes)) {
235 235
 			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
236 236
 		}
237 237
 
238 238
 		$this->response = array_merge(
239 239
 			$this->response,
240
-			array( 'taxes' => $taxes )
240
+			array('taxes' => $taxes)
241 241
 		);
242 242
 
243 243
 	}
@@ -247,29 +247,29 @@  discard block
 block discarded – undo
247 247
 	 *
248 248
 	 * @param GetPaid_Payment_Form_Submission $submission
249 249
 	 */
250
-	public function add_gateways( $submission ) {
250
+	public function add_gateways($submission) {
251 251
 
252
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
252
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
253 253
 
254
-		if ( $this->response['has_recurring'] ) {
254
+		if ($this->response['has_recurring']) {
255 255
 
256
-			foreach ( $gateways as $i => $gateway ) {
256
+			foreach ($gateways as $i => $gateway) {
257 257
 
258 258
 				if (
259
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
260
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
261
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
262
-					unset( $gateways[ $i ] );
259
+					!getpaid_payment_gateway_supports($gateway, 'subscription')
260
+					|| ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group'))
261
+					|| ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) {
262
+					unset($gateways[$i]);
263 263
 				}
264 264
 
265 265
 			}
266 266
 
267 267
 		}
268 268
 
269
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
269
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
270 270
 		$this->response = array_merge(
271 271
 			$this->response,
272
-			array( 'gateways' => $gateways )
272
+			array('gateways' => $gateways)
273 273
 		);
274 274
 
275 275
 	}
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @param GetPaid_Payment_Form_Submission $submission
281 281
 	 */
282
-	public function add_data( $submission ) {
282
+	public function add_data($submission) {
283 283
 
284 284
 		$this->response = array_merge(
285 285
 			$this->response,
Please login to merge, or discard this patch.