Passed
Push — master ( 1e5dda...630150 )
by Brian
04:15
created
templates/payment-forms/cart-item.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -24,64 +24,64 @@  discard block
 block discarded – undo
24 24
 
25 25
 				<?php
26 26
 
27
-					// Fires before printing a line item column.
28
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
27
+                    // Fires before printing a line item column.
28
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29 29
 
30
-					// Item name.
31
-					if ( 'name' == $key ) {
30
+                    // Item name.
31
+                    if ( 'name' == $key ) {
32 32
 
33
-						// Display the name.
34
-						echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
33
+                        // Display the name.
34
+                        echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
35 35
 
36
-						// And an optional description.
36
+                        // And an optional description.
37 37
                         $description = $item->get_description();
38 38
 
39 39
                         if ( ! empty( $description ) ) {
40 40
                             $description = wp_kses_post( $description );
41 41
                             echo "<small class='form-text text-muted pr-2 m-0'>$description</small>";
42
-						}
42
+                        }
43 43
 
44
-						// Price help text.
44
+                        // Price help text.
45 45
                         $description = getpaid_item_recurring_price_help_text( $item, $currency );
46 46
                         if ( $description ) {
47 47
                             echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>";
48
-						}
48
+                        }
49 49
 
50
-					}
50
+                    }
51 51
 
52
-					// Item price.
53
-					if ( 'price' == $key ) {
52
+                    // Item price.
53
+                    if ( 'price' == $key ) {
54 54
 
55
-						// Set the currency position.
56
-						$position = wpinv_currency_position();
55
+                        // Set the currency position.
56
+                        $position = wpinv_currency_position();
57 57
 
58
-						if ( $position == 'left_space' ) {
59
-							$position = 'left';
60
-						}
58
+                        if ( $position == 'left_space' ) {
59
+                            $position = 'left';
60
+                        }
61 61
 
62
-						if ( $position == 'right_space' ) {
63
-							$position = 'right';
64
-						}
62
+                        if ( $position == 'right_space' ) {
63
+                            $position = 'right';
64
+                        }
65 65
 
66
-						if ( $item->user_can_set_their_price() ) {
67
-							$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
-							$minimum          = (float) $item->get_minimum_price();
69
-							$validate_minimum = '';
70
-							$class            = '';
71
-							$data_minimum     = '';
66
+                        if ( $item->user_can_set_their_price() ) {
67
+                            $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
+                            $minimum          = (float) $item->get_minimum_price();
69
+                            $validate_minimum = '';
70
+                            $class            = '';
71
+                            $data_minimum     = '';
72 72
 
73
-							if ( $minimum > 0 ) {
74
-								$validate_minimum = sprintf(
75
-									esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
-									sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
-								);
73
+                            if ( $minimum > 0 ) {
74
+                                $validate_minimum = sprintf(
75
+                                    esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
+                                    sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
+                                );
78 78
 
79
-								$class = 'getpaid-validate-minimum-amount';
79
+                                $class = 'getpaid-validate-minimum-amount';
80 80
 
81
-								$data_minimum     = "data-minimum-amount='$minimum'";
82
-							}
81
+                                $data_minimum     = "data-minimum-amount='$minimum'";
82
+                            }
83 83
 
84
-							?>
84
+                            ?>
85 85
 								<div class="input-group input-group-sm">
86 86
 									<?php if( 'left' == $position ) : ?>
87 87
 										<div class="input-group-prepend">
@@ -105,37 +105,37 @@  discard block
 block discarded – undo
105 105
 								</div>
106 106
 
107 107
 							<?php
108
-						} else {
109
-							echo wpinv_price( $item->get_price(), $currency );
110
-							?>
108
+                        } else {
109
+                            echo wpinv_price( $item->get_price(), $currency );
110
+                            ?>
111 111
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
112 112
 							<?php
113
-						}
114
-					}
113
+                        }
114
+                    }
115 115
 
116
-					// Item quantity.
117
-					if ( 'quantity' == $key ) {
116
+                    // Item quantity.
117
+                    if ( 'quantity' == $key ) {
118 118
 
119
-						if ( $item->allows_quantities() ) {
120
-							?>
119
+                        if ( $item->allows_quantities() ) {
120
+                            ?>
121 121
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required>
122 122
 							<?php
123
-						} else {
124
-							echo (float) $item->get_quantity();
125
-							echo '&nbsp;&nbsp;&nbsp;';
126
-							?>
123
+                        } else {
124
+                            echo (float) $item->get_quantity();
125
+                            echo '&nbsp;&nbsp;&nbsp;';
126
+                            ?>
127 127
 								<input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'>
128 128
 							<?php
129
-						}
130
-					}
129
+                        }
130
+                    }
131 131
 
132
-					// Item sub total.
133
-					if ( 'subtotal' == $key ) {
134
-						echo wpinv_price( $item->get_sub_total(), $currency );
135
-					}
132
+                    // Item sub total.
133
+                    if ( 'subtotal' == $key ) {
134
+                        echo wpinv_price( $item->get_sub_total(), $currency );
135
+                    }
136 136
 
137
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
-				?>
137
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
+                ?>
139 139
 
140 140
 			</div>
141 141
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -12,255 +12,255 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-		$this->add_gateways( $submission );
41
-
42
-	}
43
-
44
-	/**
45
-	 * Adds totals to a response for submission refresh prices.
46
-	 *
47
-	 * @param GetPaid_Payment_Form_Submission $submission
48
-	 */
49
-	public function add_totals( $submission ) {
50
-
51
-		$this->response = array_merge(
52
-			$this->response,
53
-			array(
54
-
55
-				'totals'        => array(
56
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
58
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
59
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
60
-					'total'     => $submission->format_amount( $submission->get_total() ),
61
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
62
-				),
63
-
64
-				'recurring'     => array(
65
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
66
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
67
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
68
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
69
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
70
-				),
71
-
72
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
73
-				'currency'      => $submission->get_currency(),
74
-
75
-			)
76
-		);
77
-
78
-	}
79
-
80
-	/**
81
-	 * Adds texts to a response for submission refresh prices.
82
-	 *
83
-	 * @param GetPaid_Payment_Form_Submission $submission
84
-	 */
85
-	public function add_texts( $submission ) {
86
-
87
-		$payable = $submission->format_amount( $submission->get_total() );
88
-
89
-		if ( $submission->has_recurring != 0 ) {
90
-
91
-			$recurring = new WPInv_Item( $submission->has_recurring );
92
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
93
-
94
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
95
-				$payable = "$payable / $period";
96
-			} else {
97
-				$payable = sprintf(
98
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
99
-					$submission->format_amount( $submission->get_total() ),
100
-					$submission->format_amount( $submission->get_recurring_total() ),
101
-					$period
102
-				);
103
-			}
104
-
105
-		}
106
-
107
-		$texts = array(
108
-			'.getpaid-checkout-total-payable' => $payable,
109
-		);
110
-
111
-		foreach ( $submission->get_items() as $item_id => $item ) {
112
-			$initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
113
-			$recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
114
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
115
-		}
116
-
117
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
118
-
119
-	}
120
-
121
-	/**
122
-	 * Adds items to a response for submission refresh prices.
123
-	 *
124
-	 * @param GetPaid_Payment_Form_Submission $submission
125
-	 */
126
-	public function add_items( $submission ) {
127
-
128
-		// Add items.
129
-		$items = array();
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+        $this->add_gateways( $submission );
41
+
42
+    }
43
+
44
+    /**
45
+     * Adds totals to a response for submission refresh prices.
46
+     *
47
+     * @param GetPaid_Payment_Form_Submission $submission
48
+     */
49
+    public function add_totals( $submission ) {
50
+
51
+        $this->response = array_merge(
52
+            $this->response,
53
+            array(
54
+
55
+                'totals'        => array(
56
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
58
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
59
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
60
+                    'total'     => $submission->format_amount( $submission->get_total() ),
61
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
62
+                ),
63
+
64
+                'recurring'     => array(
65
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
66
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
67
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
68
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
69
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
70
+                ),
71
+
72
+                'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
73
+                'currency'      => $submission->get_currency(),
74
+
75
+            )
76
+        );
77
+
78
+    }
79
+
80
+    /**
81
+     * Adds texts to a response for submission refresh prices.
82
+     *
83
+     * @param GetPaid_Payment_Form_Submission $submission
84
+     */
85
+    public function add_texts( $submission ) {
86
+
87
+        $payable = $submission->format_amount( $submission->get_total() );
88
+
89
+        if ( $submission->has_recurring != 0 ) {
90
+
91
+            $recurring = new WPInv_Item( $submission->has_recurring );
92
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
93
+
94
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
95
+                $payable = "$payable / $period";
96
+            } else {
97
+                $payable = sprintf(
98
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
99
+                    $submission->format_amount( $submission->get_total() ),
100
+                    $submission->format_amount( $submission->get_recurring_total() ),
101
+                    $period
102
+                );
103
+            }
104
+
105
+        }
106
+
107
+        $texts = array(
108
+            '.getpaid-checkout-total-payable' => $payable,
109
+        );
130 110
 
131 111
         foreach ( $submission->get_items() as $item_id => $item ) {
132
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
133
-		}
112
+            $initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
113
+            $recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
114
+            $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
115
+        }
134 116
 
135
-		$this->response = array_merge(
136
-			$this->response,
137
-			array( 'items' => $items )
138
-		);
117
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
139 118
 
140
-	}
119
+    }
141 120
 
142
-	/**
143
-	 * Adds fees to a response for submission refresh prices.
144
-	 *
145
-	 * @param GetPaid_Payment_Form_Submission $submission
146
-	 */
147
-	public function add_fees( $submission ) {
121
+    /**
122
+     * Adds items to a response for submission refresh prices.
123
+     *
124
+     * @param GetPaid_Payment_Form_Submission $submission
125
+     */
126
+    public function add_items( $submission ) {
127
+
128
+        // Add items.
129
+        $items = array();
130
+
131
+        foreach ( $submission->get_items() as $item_id => $item ) {
132
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
133
+        }
148 134
 
149
-		$fees = array();
135
+        $this->response = array_merge(
136
+            $this->response,
137
+            array( 'items' => $items )
138
+        );
139
+
140
+    }
141
+
142
+    /**
143
+     * Adds fees to a response for submission refresh prices.
144
+     *
145
+     * @param GetPaid_Payment_Form_Submission $submission
146
+     */
147
+    public function add_fees( $submission ) {
148
+
149
+        $fees = array();
150 150
 
151 151
         foreach ( $submission->get_fees() as $name => $data ) {
152
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
153
-		}
152
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
153
+        }
154 154
 
155
-		$this->response = array_merge(
156
-			$this->response,
157
-			array( 'fees' => $fees )
158
-		);
155
+        $this->response = array_merge(
156
+            $this->response,
157
+            array( 'fees' => $fees )
158
+        );
159 159
 
160
-	}
160
+    }
161 161
 
162
-	/**
163
-	 * Adds discounts to a response for submission refresh prices.
164
-	 *
165
-	 * @param GetPaid_Payment_Form_Submission $submission
166
-	 */
167
-	public function add_discounts( $submission ) {
162
+    /**
163
+     * Adds discounts to a response for submission refresh prices.
164
+     *
165
+     * @param GetPaid_Payment_Form_Submission $submission
166
+     */
167
+    public function add_discounts( $submission ) {
168 168
 
169
-		$discounts = array();
169
+        $discounts = array();
170 170
 
171 171
         foreach ( $submission->get_discounts() as $name => $data ) {
172
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
173
-		}
174
-
175
-		$this->response = array_merge(
176
-			$this->response,
177
-			array( 'discounts' => $discounts )
178
-		);
172
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
173
+        }
179 174
 
180
-	}
175
+        $this->response = array_merge(
176
+            $this->response,
177
+            array( 'discounts' => $discounts )
178
+        );
181 179
 
182
-	/**
183
-	 * Adds taxes to a response for submission refresh prices.
184
-	 *
185
-	 * @param GetPaid_Payment_Form_Submission $submission
186
-	 */
187
-	public function add_taxes( $submission ) {
180
+    }
188 181
 
189
-		$taxes  = array();
190
-		$markup = '';
182
+    /**
183
+     * Adds taxes to a response for submission refresh prices.
184
+     *
185
+     * @param GetPaid_Payment_Form_Submission $submission
186
+     */
187
+    public function add_taxes( $submission ) {
188
+
189
+        $taxes  = array();
190
+        $markup = '';
191 191
         foreach ( $submission->get_taxes() as $name => $data ) {
192
-			$name          = sanitize_text_field( $name );
193
-			$amount        = $submission->format_amount( $data['initial_tax'] );
194
-			$taxes[$name]  = $amount;
195
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
196
-		}
192
+            $name          = sanitize_text_field( $name );
193
+            $amount        = $submission->format_amount( $data['initial_tax'] );
194
+            $taxes[$name]  = $amount;
195
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
196
+        }
197 197
 
198
-		if ( wpinv_display_individual_tax_rates() ) {
199
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
200
-		}
198
+        if ( wpinv_display_individual_tax_rates() ) {
199
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
200
+        }
201 201
 
202
-		$this->response = array_merge(
203
-			$this->response,
204
-			array( 'taxes' => $taxes )
205
-		);
202
+        $this->response = array_merge(
203
+            $this->response,
204
+            array( 'taxes' => $taxes )
205
+        );
206 206
 
207
-	}
207
+    }
208 208
 
209
-	/**
210
-	 * Adds gateways to a response for submission refresh prices.
211
-	 *
212
-	 * @param GetPaid_Payment_Form_Submission $submission
213
-	 */
214
-	public function add_gateways( $submission ) {
209
+    /**
210
+     * Adds gateways to a response for submission refresh prices.
211
+     *
212
+     * @param GetPaid_Payment_Form_Submission $submission
213
+     */
214
+    public function add_gateways( $submission ) {
215 215
 
216
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
216
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
217 217
 
218
-		if ( $this->response['has_recurring'] ) {
218
+        if ( $this->response['has_recurring'] ) {
219 219
 
220
-			foreach ( $gateways as $i => $gateway ) {
220
+            foreach ( $gateways as $i => $gateway ) {
221 221
 
222
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
223
-					unset( $gateways[ $i ] );
224
-				}
222
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
223
+                    unset( $gateways[ $i ] );
224
+                }
225 225
 
226
-			}
226
+            }
227 227
 
228
-		}
228
+        }
229 229
 
230 230
 
231
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
232
-		$this->response = array_merge(
233
-			$this->response,
234
-			array( 'gateways' => $gateways )
235
-		);
231
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
232
+        $this->response = array_merge(
233
+            $this->response,
234
+            array( 'gateways' => $gateways )
235
+        );
236 236
 
237
-	}
237
+    }
238 238
 
239
-	/**
240
-	 * Standardizes prices.
241
-	 *
242
-	 * @param int $item_id
243
-	 * @param float $item_total
244
-	 * @param string $discount_code
245
-	 * @param bool $recurring
246
-	 */
247
-	public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
239
+    /**
240
+     * Standardizes prices.
241
+     *
242
+     * @param int $item_id
243
+     * @param float $item_total
244
+     * @param string $discount_code
245
+     * @param bool $recurring
246
+     */
247
+    public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
248 248
 
249
-		$standardadized_price = $item_total;
249
+        $standardadized_price = $item_total;
250 250
 
251
-		// Do we have a $discount_code?
252
-		if ( ! empty( $discount_code ) ) {
251
+        // Do we have a $discount_code?
252
+        if ( ! empty( $discount_code ) ) {
253 253
 
254
-			$discount = new WPInv_Discount( $discount_code );
254
+            $discount = new WPInv_Discount( $discount_code );
255 255
 
256
-			if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
257
-				$standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
258
-			}
256
+            if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
257
+                $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
258
+            }
259 259
 
260
-		}
260
+        }
261 261
 
262
-    	return max( 0, $standardadized_price );
262
+        return max( 0, $standardadized_price );
263 263
 
264
-	}
264
+    }
265 265
 
266 266
 }
Please login to merge, or discard this patch.