Passed
Push — master ( e374ab...2f869e )
by Brian
05:16
created
templates/payment-forms/elements/gateway_select.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,45 +7,45 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // The payment methods select title.
13
-if ( empty( $text ) ) {
14
-    $text = __( 'Select Payment Method', 'invoicing' );
13
+if (empty($text)) {
14
+    $text = __('Select Payment Method', 'invoicing');
15 15
 }
16 16
 
17 17
 // An array of active payment methods.
18
-$gateways = wpinv_get_enabled_payment_gateways( true );
18
+$gateways = wpinv_get_enabled_payment_gateways(true);
19 19
 
20 20
 // The current invoice id.
21 21
 $invoice_id     = 0;
22 22
 $chosen_gateway = wpinv_get_default_gateway();
23 23
 
24
-if ( ! empty( $form->invoice ) ) {
24
+if (!empty($form->invoice)) {
25 25
     $invoice_id = $form->invoice->get_id();
26 26
     $chosen_gateway = $form->invoice->get_gateway();
27 27
 }
28 28
 
29 29
 ?>
30 30
 
31
-    <?php do_action( 'getpaid_before_payment_form_gateway_select', $form ); ?>
31
+    <?php do_action('getpaid_before_payment_form_gateway_select', $form); ?>
32 32
     <div class="mt-4 mb-4 getpaid-gateways">
33 33
 
34
-        <?php do_action( 'wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form ); ?>
34
+        <?php do_action('wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form); ?>
35 35
 
36 36
         <div class="getpaid-select-gateway-title-div">
37
-            <h6><?php echo sanitize_text_field( $text ); ?></h6>
37
+            <h6><?php echo sanitize_text_field($text); ?></h6>
38 38
         </div>
39 39
 
40 40
         <div class="getpaid-available-gateways-div">
41 41
 
42
-            <?php foreach ( array_keys( $gateways ) as $gateway ) : ?>
42
+            <?php foreach (array_keys($gateways) as $gateway) : ?>
43 43
 
44
-                <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class( $gateway ) ;?>" data-checkout-label='<?php echo esc_attr( apply_filters( "getpaid_gateway_{$gateway}_checkout_button_label", '' ) ); ?>'>
44
+                <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class($gateway); ?>" data-checkout-label='<?php echo esc_attr(apply_filters("getpaid_gateway_{$gateway}_checkout_button_label", '')); ?>'>
45 45
 
46 46
                     <label class="d-block w-100 getpaid-gateway-radio">
47
-                        <input type="radio" value="<?php echo esc_attr( $gateway ) ;?>" <?php checked( $gateway, $chosen_gateway ) ;?> name="wpi-gateway">
48
-                        <span><?php echo sanitize_text_field( wpinv_get_gateway_checkout_label( $gateway ) ); ?></span>
47
+                        <input type="radio" value="<?php echo esc_attr($gateway); ?>" <?php checked($gateway, $chosen_gateway); ?> name="wpi-gateway">
48
+                        <span><?php echo sanitize_text_field(wpinv_get_gateway_checkout_label($gateway)); ?></span>
49 49
                     </label>
50 50
 
51 51
                 </div>
@@ -56,22 +56,22 @@  discard block
 block discarded – undo
56 56
 
57 57
         <div class="getpaid-gateway-descriptions-div">
58 58
 
59
-            <?php foreach ( array_keys( $gateways ) as $gateway ) : ?>
59
+            <?php foreach (array_keys($gateways) as $gateway) : ?>
60 60
 
61
-                <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class( $gateway ) ;?>" style="display: none;">
61
+                <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class($gateway); ?>" style="display: none;">
62 62
                     <?php
63 63
 
64
-                        $description = wpinv_get_gateway_description( $gateway );
64
+                        $description = wpinv_get_gateway_description($gateway);
65 65
 
66
-                        if ( wpinv_is_test_mode( $gateway ) ) {
67
-                            $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) );
66
+                        if (wpinv_is_test_mode($gateway)) {
67
+                            $sandbox_notice = apply_filters("getpaid_{$gateway}_sandbox_notice", __('SANDBOX ENABLED: No real payments will occur.', 'invoicing'));
68 68
                             $description = "$description $sandbox_notice";
69 69
                         }
70 70
 
71
-                        echo wpautop( wp_kses_post( $description ) );
71
+                        echo wpautop(wp_kses_post($description));
72 72
 
73
-                        do_action( 'wpinv_' . $gateway . '_checkout_fields', $invoice_id ) ;
74
-                        do_action( 'wpinv_' . $gateway . '_cc_form', $invoice_id, $form ) ;
73
+                        do_action('wpinv_' . $gateway . '_checkout_fields', $invoice_id);
74
+                        do_action('wpinv_' . $gateway . '_cc_form', $invoice_id, $form);
75 75
 
76 76
                     ?>
77 77
                 </div>
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
             <?php
85 85
                 echo aui()->alert(
86 86
                     array(
87
-                        'content'     => __( 'None of the available payment gateways support subscriptions.', 'invoicing' ),
87
+                        'content'     => __('None of the available payment gateways support subscriptions.', 'invoicing'),
88 88
                         'type'        => 'danger',
89 89
                     )
90 90
                 );
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
             <?php
96 96
                 echo aui()->alert(
97 97
                     array(
98
-                        'content'     => __( 'There is no active payment gateway available to process your request.', 'invoicing' ),
98
+                        'content'     => __('There is no active payment gateway available to process your request.', 'invoicing'),
99 99
                         'type'        => 'danger',
100 100
                     )
101 101
                 );
102 102
             ?>
103 103
         </div>
104 104
 
105
-        <?php do_action( 'wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form ); ?>
105
+        <?php do_action('wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form); ?>
106 106
 
107 107
     </div>
108
-    <?php do_action( 'getpaid_after_payment_form_gateway_select', $form ); ?>
108
+    <?php do_action('getpaid_after_payment_form_gateway_select', $form); ?>
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -12,280 +12,280 @@
 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
-		$this->add_data( $submission );
42
-
43
-	}
44
-
45
-	/**
46
-	 * Adds totals to a response for submission refresh prices.
47
-	 *
48
-	 * @param GetPaid_Payment_Form_Submission $submission
49
-	 */
50
-	public function add_totals( $submission ) {
51
-
52
-		$this->response = array_merge(
53
-			$this->response,
54
-			array(
55
-
56
-				'totals'        => array(
57
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
58
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
59
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
60
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
61
-					'total'     => $submission->format_amount( $submission->get_total() ),
62
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
63
-				),
64
-
65
-				'recurring'     => array(
66
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
67
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
68
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
69
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
70
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
71
-				),
72
-
73
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
74
-				'currency'      => $submission->get_currency(),
75
-
76
-			)
77
-		);
78
-
79
-	}
80
-
81
-	/**
82
-	 * Adds texts to a response for submission refresh prices.
83
-	 *
84
-	 * @param GetPaid_Payment_Form_Submission $submission
85
-	 */
86
-	public function add_texts( $submission ) {
87
-
88
-		$payable = $submission->format_amount( $submission->get_total() );
89
-
90
-		if ( $submission->has_recurring != 0 ) {
91
-
92
-			$recurring = new WPInv_Item( $submission->has_recurring );
93
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
94
-
95
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
96
-				$payable = "$payable / $period";
97
-			} else {
98
-				$payable = sprintf(
99
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
100
-					$submission->format_amount( $submission->get_total() ),
101
-					$submission->format_amount( $submission->get_recurring_total() ),
102
-					$period
103
-				);
104
-			}
105
-
106
-		}
107
-
108
-		$texts = array(
109
-			'.getpaid-checkout-total-payable' => $payable,
110
-		);
111
-
112
-		foreach ( $submission->get_items() as $item ) {
113
-			$item_id                                               = $item->get_id();
114
-			$initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
115
-			$recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
116
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
117
-		}
118
-
119
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
120
-
121
-	}
122
-
123
-	/**
124
-	 * Adds items to a response for submission refresh prices.
125
-	 *
126
-	 * @param GetPaid_Payment_Form_Submission $submission
127
-	 */
128
-	public function add_items( $submission ) {
129
-
130
-		// Add items.
131
-		$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
+        $this->add_data( $submission );
42
+
43
+    }
44
+
45
+    /**
46
+     * Adds totals to a response for submission refresh prices.
47
+     *
48
+     * @param GetPaid_Payment_Form_Submission $submission
49
+     */
50
+    public function add_totals( $submission ) {
51
+
52
+        $this->response = array_merge(
53
+            $this->response,
54
+            array(
55
+
56
+                'totals'        => array(
57
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
58
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
59
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
60
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
61
+                    'total'     => $submission->format_amount( $submission->get_total() ),
62
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
63
+                ),
64
+
65
+                'recurring'     => array(
66
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
67
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
68
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
69
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
70
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
71
+                ),
72
+
73
+                'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
74
+                'currency'      => $submission->get_currency(),
75
+
76
+            )
77
+        );
78
+
79
+    }
80
+
81
+    /**
82
+     * Adds texts to a response for submission refresh prices.
83
+     *
84
+     * @param GetPaid_Payment_Form_Submission $submission
85
+     */
86
+    public function add_texts( $submission ) {
87
+
88
+        $payable = $submission->format_amount( $submission->get_total() );
89
+
90
+        if ( $submission->has_recurring != 0 ) {
91
+
92
+            $recurring = new WPInv_Item( $submission->has_recurring );
93
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
94
+
95
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
96
+                $payable = "$payable / $period";
97
+            } else {
98
+                $payable = sprintf(
99
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
100
+                    $submission->format_amount( $submission->get_total() ),
101
+                    $submission->format_amount( $submission->get_recurring_total() ),
102
+                    $period
103
+                );
104
+            }
105
+
106
+        }
107
+
108
+        $texts = array(
109
+            '.getpaid-checkout-total-payable' => $payable,
110
+        );
132 111
 
133 112
         foreach ( $submission->get_items() as $item ) {
134
-			$item_id           = $item->get_id();
135
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
136
-		}
113
+            $item_id                                               = $item->get_id();
114
+            $initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
115
+            $recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
116
+            $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
117
+        }
137 118
 
138
-		$this->response = array_merge(
139
-			$this->response,
140
-			array( 'items' => $items )
141
-		);
119
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
142 120
 
143
-	}
121
+    }
144 122
 
145
-	/**
146
-	 * Adds fees to a response for submission refresh prices.
147
-	 *
148
-	 * @param GetPaid_Payment_Form_Submission $submission
149
-	 */
150
-	public function add_fees( $submission ) {
123
+    /**
124
+     * Adds items to a response for submission refresh prices.
125
+     *
126
+     * @param GetPaid_Payment_Form_Submission $submission
127
+     */
128
+    public function add_items( $submission ) {
151 129
 
152
-		$fees = array();
130
+        // Add items.
131
+        $items = array();
153 132
 
154
-        foreach ( $submission->get_fees() as $name => $data ) {
155
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
156
-		}
133
+        foreach ( $submission->get_items() as $item ) {
134
+            $item_id           = $item->get_id();
135
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
136
+        }
157 137
 
158
-		$this->response = array_merge(
159
-			$this->response,
160
-			array( 'fees' => $fees )
161
-		);
138
+        $this->response = array_merge(
139
+            $this->response,
140
+            array( 'items' => $items )
141
+        );
162 142
 
163
-	}
143
+    }
164 144
 
165
-	/**
166
-	 * Adds discounts to a response for submission refresh prices.
167
-	 *
168
-	 * @param GetPaid_Payment_Form_Submission $submission
169
-	 */
170
-	public function add_discounts( $submission ) {
145
+    /**
146
+     * Adds fees to a response for submission refresh prices.
147
+     *
148
+     * @param GetPaid_Payment_Form_Submission $submission
149
+     */
150
+    public function add_fees( $submission ) {
171 151
 
172
-		$discounts = array();
152
+        $fees = array();
173 153
 
174
-        foreach ( $submission->get_discounts() as $name => $data ) {
175
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
176
-		}
154
+        foreach ( $submission->get_fees() as $name => $data ) {
155
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
156
+        }
177 157
 
178
-		$this->response = array_merge(
179
-			$this->response,
180
-			array( 'discounts' => $discounts )
181
-		);
158
+        $this->response = array_merge(
159
+            $this->response,
160
+            array( 'fees' => $fees )
161
+        );
182 162
 
183
-	}
163
+    }
184 164
 
185
-	/**
186
-	 * Adds taxes to a response for submission refresh prices.
187
-	 *
188
-	 * @param GetPaid_Payment_Form_Submission $submission
189
-	 */
190
-	public function add_taxes( $submission ) {
165
+    /**
166
+     * Adds discounts to a response for submission refresh prices.
167
+     *
168
+     * @param GetPaid_Payment_Form_Submission $submission
169
+     */
170
+    public function add_discounts( $submission ) {
191 171
 
192
-		$taxes  = array();
193
-		$markup = '';
194
-        foreach ( $submission->get_taxes() as $name => $data ) {
195
-			$name          = sanitize_text_field( $name );
196
-			$amount        = $submission->format_amount( $data['initial_tax'] );
197
-			$taxes[$name]  = $amount;
198
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
199
-		}
172
+        $discounts = array();
173
+
174
+        foreach ( $submission->get_discounts() as $name => $data ) {
175
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
176
+        }
200 177
 
201
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
202
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
203
-		}
178
+        $this->response = array_merge(
179
+            $this->response,
180
+            array( 'discounts' => $discounts )
181
+        );
204 182
 
205
-		$this->response = array_merge(
206
-			$this->response,
207
-			array( 'taxes' => $taxes )
208
-		);
183
+    }
209 184
 
210
-	}
185
+    /**
186
+     * Adds taxes to a response for submission refresh prices.
187
+     *
188
+     * @param GetPaid_Payment_Form_Submission $submission
189
+     */
190
+    public function add_taxes( $submission ) {
191
+
192
+        $taxes  = array();
193
+        $markup = '';
194
+        foreach ( $submission->get_taxes() as $name => $data ) {
195
+            $name          = sanitize_text_field( $name );
196
+            $amount        = $submission->format_amount( $data['initial_tax'] );
197
+            $taxes[$name]  = $amount;
198
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
199
+        }
211 200
 
212
-	/**
213
-	 * Adds gateways to a response for submission refresh prices.
214
-	 *
215
-	 * @param GetPaid_Payment_Form_Submission $submission
216
-	 */
217
-	public function add_gateways( $submission ) {
201
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
202
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
203
+        }
218 204
 
219
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
205
+        $this->response = array_merge(
206
+            $this->response,
207
+            array( 'taxes' => $taxes )
208
+        );
220 209
 
221
-		if ( $this->response['has_recurring'] ) {
210
+    }
222 211
 
223
-			foreach ( $gateways as $i => $gateway ) {
212
+    /**
213
+     * Adds gateways to a response for submission refresh prices.
214
+     *
215
+     * @param GetPaid_Payment_Form_Submission $submission
216
+     */
217
+    public function add_gateways( $submission ) {
224 218
 
225
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
226
-					unset( $gateways[ $i ] );
227
-				}
219
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
228 220
 
229
-			}
221
+        if ( $this->response['has_recurring'] ) {
230 222
 
231
-		}
223
+            foreach ( $gateways as $i => $gateway ) {
232 224
 
225
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
226
+                    unset( $gateways[ $i ] );
227
+                }
233 228
 
234
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
235
-		$this->response = array_merge(
236
-			$this->response,
237
-			array( 'gateways' => $gateways )
238
-		);
229
+            }
239 230
 
240
-	}
231
+        }
241 232
 
242
-	/**
243
-	 * Standardizes prices.
244
-	 *
245
-	 * @param int $item_id
246
-	 * @param float $item_total
247
-	 * @param string $discount_code
248
-	 * @param bool $recurring
249
-	 */
250
-	public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
251 233
 
252
-		$standardadized_price = $item_total;
234
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
235
+        $this->response = array_merge(
236
+            $this->response,
237
+            array( 'gateways' => $gateways )
238
+        );
253 239
 
254
-		// Do we have a $discount_code?
255
-		if ( ! empty( $discount_code ) ) {
240
+    }
256 241
 
257
-			$discount = new WPInv_Discount( $discount_code );
242
+    /**
243
+     * Standardizes prices.
244
+     *
245
+     * @param int $item_id
246
+     * @param float $item_total
247
+     * @param string $discount_code
248
+     * @param bool $recurring
249
+     */
250
+    public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
251
+
252
+        $standardadized_price = $item_total;
258 253
 
259
-			if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
260
-				$standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
261
-			}
254
+        // Do we have a $discount_code?
255
+        if ( ! empty( $discount_code ) ) {
262 256
 
263
-		}
257
+            $discount = new WPInv_Discount( $discount_code );
264 258
 
265
-    	return max( 0, $standardadized_price );
259
+            if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
260
+                $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
261
+            }
266 262
 
267
-	}
263
+        }
268 264
 
269
-	/**
270
-	 * Adds data to a response for submission refresh prices.
271
-	 *
272
-	 * @param GetPaid_Payment_Form_Submission $submission
273
-	 */
274
-	public function add_data( $submission ) {
265
+        return max( 0, $standardadized_price );
275 266
 
276
-		$this->response = array_merge(
277
-			$this->response,
278
-			array(
279
-				'js_data' => apply_filters(
280
-					'getpaid_submission_js_data',
281
-					array(
282
-						'is_recurring' => $this->response['has_recurring'],
283
-					),
284
-					$submission
285
-				)
286
-			)
287
-		);
267
+    }
288 268
 
289
-	}
269
+    /**
270
+     * Adds data to a response for submission refresh prices.
271
+     *
272
+     * @param GetPaid_Payment_Form_Submission $submission
273
+     */
274
+    public function add_data( $submission ) {
275
+
276
+        $this->response = array_merge(
277
+            $this->response,
278
+            array(
279
+                'js_data' => apply_filters(
280
+                    'getpaid_submission_js_data',
281
+                    array(
282
+                        'is_recurring' => $this->response['has_recurring'],
283
+                    ),
284
+                    $submission
285
+                )
286
+            )
287
+        );
288
+
289
+    }
290 290
 
291 291
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 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,22 +23,22 @@  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
-            'is_free'       => ! $submission->should_collect_payment_details(),
31
+            'is_free'       => !$submission->should_collect_payment_details(),
32 32
 		);
33 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
-		$this->add_data( $submission );
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
+		$this->add_data($submission);
42 42
 
43 43
 	}
44 44
 
@@ -47,30 +47,30 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @param GetPaid_Payment_Form_Submission $submission
49 49
 	 */
50
-	public function add_totals( $submission ) {
50
+	public function add_totals($submission) {
51 51
 
52 52
 		$this->response = array_merge(
53 53
 			$this->response,
54 54
 			array(
55 55
 
56 56
 				'totals'        => array(
57
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
58
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
59
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
60
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
61
-					'total'     => $submission->format_amount( $submission->get_total() ),
62
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
57
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
58
+					'discount'  => $submission->format_amount($submission->get_discount()),
59
+					'fees'      => $submission->format_amount($submission->get_fee()),
60
+					'tax'       => $submission->format_amount($submission->get_tax()),
61
+					'total'     => $submission->format_amount($submission->get_total()),
62
+					'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES),
63 63
 				),
64 64
 
65 65
 				'recurring'     => array(
66
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
67
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
68
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
69
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
70
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
66
+					'subtotal'  => $submission->format_amount($submission->get_recurring_subtotal()),
67
+					'discount'  => $submission->format_amount($submission->get_recurring_discount()),
68
+					'fees'      => $submission->format_amount($submission->get_recurring_fee()),
69
+					'tax'       => $submission->format_amount($submission->get_recurring_tax()),
70
+					'total'     => $submission->format_amount($submission->get_recurring_total()),
71 71
 				),
72 72
 
73
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
73
+				'initial_amt'   => wpinv_round_amount($submission->get_total(), null, true),
74 74
 				'currency'      => $submission->get_currency(),
75 75
 
76 76
 			)
@@ -83,22 +83,22 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @param GetPaid_Payment_Form_Submission $submission
85 85
 	 */
86
-	public function add_texts( $submission ) {
86
+	public function add_texts($submission) {
87 87
 
88
-		$payable = $submission->format_amount( $submission->get_total() );
88
+		$payable = $submission->format_amount($submission->get_total());
89 89
 
90
-		if ( $submission->has_recurring != 0 ) {
90
+		if ($submission->has_recurring != 0) {
91 91
 
92
-			$recurring = new WPInv_Item( $submission->has_recurring );
93
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
92
+			$recurring = new WPInv_Item($submission->has_recurring);
93
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
94 94
 
95
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
95
+			if ($submission->get_total() == $submission->get_recurring_total()) {
96 96
 				$payable = "$payable / $period";
97 97
 			} else {
98 98
 				$payable = sprintf(
99
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
100
-					$submission->format_amount( $submission->get_total() ),
101
-					$submission->format_amount( $submission->get_recurring_total() ),
99
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
100
+					$submission->format_amount($submission->get_total()),
101
+					$submission->format_amount($submission->get_recurring_total()),
102 102
 					$period
103 103
 				);
104 104
 			}
@@ -109,14 +109,14 @@  discard block
 block discarded – undo
109 109
 			'.getpaid-checkout-total-payable' => $payable,
110 110
 		);
111 111
 
112
-		foreach ( $submission->get_items() as $item ) {
112
+		foreach ($submission->get_items() as $item) {
113 113
 			$item_id                                               = $item->get_id();
114
-			$initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
115
-			$recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
116
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
114
+			$initial_price                                         = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false));
115
+			$recurring_price                                       = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true));
116
+			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price);
117 117
 		}
118 118
 
119
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
119
+		$this->response = array_merge($this->response, array('texts' => $texts));
120 120
 
121 121
 	}
122 122
 
@@ -125,19 +125,19 @@  discard block
 block discarded – undo
125 125
 	 *
126 126
 	 * @param GetPaid_Payment_Form_Submission $submission
127 127
 	 */
128
-	public function add_items( $submission ) {
128
+	public function add_items($submission) {
129 129
 
130 130
 		// Add items.
131 131
 		$items = array();
132 132
 
133
-        foreach ( $submission->get_items() as $item ) {
133
+        foreach ($submission->get_items() as $item) {
134 134
 			$item_id           = $item->get_id();
135
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
135
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
136 136
 		}
137 137
 
138 138
 		$this->response = array_merge(
139 139
 			$this->response,
140
-			array( 'items' => $items )
140
+			array('items' => $items)
141 141
 		);
142 142
 
143 143
 	}
@@ -147,17 +147,17 @@  discard block
 block discarded – undo
147 147
 	 *
148 148
 	 * @param GetPaid_Payment_Form_Submission $submission
149 149
 	 */
150
-	public function add_fees( $submission ) {
150
+	public function add_fees($submission) {
151 151
 
152 152
 		$fees = array();
153 153
 
154
-        foreach ( $submission->get_fees() as $name => $data ) {
155
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
154
+        foreach ($submission->get_fees() as $name => $data) {
155
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
156 156
 		}
157 157
 
158 158
 		$this->response = array_merge(
159 159
 			$this->response,
160
-			array( 'fees' => $fees )
160
+			array('fees' => $fees)
161 161
 		);
162 162
 
163 163
 	}
@@ -167,17 +167,17 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @param GetPaid_Payment_Form_Submission $submission
169 169
 	 */
170
-	public function add_discounts( $submission ) {
170
+	public function add_discounts($submission) {
171 171
 
172 172
 		$discounts = array();
173 173
 
174
-        foreach ( $submission->get_discounts() as $name => $data ) {
175
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
174
+        foreach ($submission->get_discounts() as $name => $data) {
175
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
176 176
 		}
177 177
 
178 178
 		$this->response = array_merge(
179 179
 			$this->response,
180
-			array( 'discounts' => $discounts )
180
+			array('discounts' => $discounts)
181 181
 		);
182 182
 
183 183
 	}
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 	 *
188 188
 	 * @param GetPaid_Payment_Form_Submission $submission
189 189
 	 */
190
-	public function add_taxes( $submission ) {
190
+	public function add_taxes($submission) {
191 191
 
192 192
 		$taxes  = array();
193 193
 		$markup = '';
194
-        foreach ( $submission->get_taxes() as $name => $data ) {
195
-			$name          = sanitize_text_field( $name );
196
-			$amount        = $submission->format_amount( $data['initial_tax'] );
194
+        foreach ($submission->get_taxes() as $name => $data) {
195
+			$name          = sanitize_text_field($name);
196
+			$amount        = $submission->format_amount($data['initial_tax']);
197 197
 			$taxes[$name]  = $amount;
198 198
 			$markup       .= "<small class='form-text'>$name : $amount</small>";
199 199
 		}
200 200
 
201
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
201
+		if (wpinv_display_individual_tax_rates() && !empty($taxes)) {
202 202
 			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
203 203
 		}
204 204
 
205 205
 		$this->response = array_merge(
206 206
 			$this->response,
207
-			array( 'taxes' => $taxes )
207
+			array('taxes' => $taxes)
208 208
 		);
209 209
 
210 210
 	}
@@ -214,16 +214,16 @@  discard block
 block discarded – undo
214 214
 	 *
215 215
 	 * @param GetPaid_Payment_Form_Submission $submission
216 216
 	 */
217
-	public function add_gateways( $submission ) {
217
+	public function add_gateways($submission) {
218 218
 
219
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
219
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
220 220
 
221
-		if ( $this->response['has_recurring'] ) {
221
+		if ($this->response['has_recurring']) {
222 222
 
223
-			foreach ( $gateways as $i => $gateway ) {
223
+			foreach ($gateways as $i => $gateway) {
224 224
 
225
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
226
-					unset( $gateways[ $i ] );
225
+				if (!wpinv_gateway_support_subscription($gateway)) {
226
+					unset($gateways[$i]);
227 227
 				}
228 228
 
229 229
 			}
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
 		}
232 232
 
233 233
 
234
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
234
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
235 235
 		$this->response = array_merge(
236 236
 			$this->response,
237
-			array( 'gateways' => $gateways )
237
+			array('gateways' => $gateways)
238 238
 		);
239 239
 
240 240
 	}
@@ -247,22 +247,22 @@  discard block
 block discarded – undo
247 247
 	 * @param string $discount_code
248 248
 	 * @param bool $recurring
249 249
 	 */
250
-	public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
250
+	public function standardize_price($item_id, $item_total, $discount_code, $recurring = false) {
251 251
 
252 252
 		$standardadized_price = $item_total;
253 253
 
254 254
 		// Do we have a $discount_code?
255
-		if ( ! empty( $discount_code ) ) {
255
+		if (!empty($discount_code)) {
256 256
 
257
-			$discount = new WPInv_Discount( $discount_code );
257
+			$discount = new WPInv_Discount($discount_code);
258 258
 
259
-			if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
260
-				$standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
259
+			if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) {
260
+				$standardadized_price = $item_total - $discount->get_discounted_amount($item_total);
261 261
 			}
262 262
 
263 263
 		}
264 264
 
265
-    	return max( 0, $standardadized_price );
265
+    	return max(0, $standardadized_price);
266 266
 
267 267
 	}
268 268
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 *
272 272
 	 * @param GetPaid_Payment_Form_Submission $submission
273 273
 	 */
274
-	public function add_data( $submission ) {
274
+	public function add_data($submission) {
275 275
 
276 276
 		$this->response = array_merge(
277 277
 			$this->response,
Please login to merge, or discard this patch.