Passed
Push — master ( 1bb01d...57b9dd )
by Brian
05:12
created
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -12,227 +12,227 @@
 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)'),
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
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
113
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
114
-		}
115
-
116
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
117
-
118
-	}
119
-
120
-	/**
121
-	 * Adds items to a response for submission refresh prices.
122
-	 *
123
-	 * @param GetPaid_Payment_Form_Submission $submission
124
-	 */
125
-	public function add_items( $submission ) {
126
-
127
-		// Add items.
128
-		$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)'),
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
+        );
129 110
 
130 111
         foreach ( $submission->get_items() as $item_id => $item ) {
131
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
132
-		}
112
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
113
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
114
+        }
133 115
 
134
-		$this->response = array_merge(
135
-			$this->response,
136
-			array( 'items' => $items )
137
-		);
116
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
138 117
 
139
-	}
118
+    }
140 119
 
141
-	/**
142
-	 * Adds fees to a response for submission refresh prices.
143
-	 *
144
-	 * @param GetPaid_Payment_Form_Submission $submission
145
-	 */
146
-	public function add_fees( $submission ) {
120
+    /**
121
+     * Adds items to a response for submission refresh prices.
122
+     *
123
+     * @param GetPaid_Payment_Form_Submission $submission
124
+     */
125
+    public function add_items( $submission ) {
126
+
127
+        // Add items.
128
+        $items = array();
129
+
130
+        foreach ( $submission->get_items() as $item_id => $item ) {
131
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
132
+        }
133
+
134
+        $this->response = array_merge(
135
+            $this->response,
136
+            array( 'items' => $items )
137
+        );
138
+
139
+    }
147 140
 
148
-		$fees = array();
141
+    /**
142
+     * Adds fees to a response for submission refresh prices.
143
+     *
144
+     * @param GetPaid_Payment_Form_Submission $submission
145
+     */
146
+    public function add_fees( $submission ) {
147
+
148
+        $fees = array();
149 149
 
150 150
         foreach ( $submission->get_fees() as $name => $data ) {
151
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
152
-		}
151
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
152
+        }
153 153
 
154
-		$this->response = array_merge(
155
-			$this->response,
156
-			array( 'fees' => $fees )
157
-		);
154
+        $this->response = array_merge(
155
+            $this->response,
156
+            array( 'fees' => $fees )
157
+        );
158 158
 
159
-	}
159
+    }
160 160
 
161
-	/**
162
-	 * Adds discounts to a response for submission refresh prices.
163
-	 *
164
-	 * @param GetPaid_Payment_Form_Submission $submission
165
-	 */
166
-	public function add_discounts( $submission ) {
161
+    /**
162
+     * Adds discounts to a response for submission refresh prices.
163
+     *
164
+     * @param GetPaid_Payment_Form_Submission $submission
165
+     */
166
+    public function add_discounts( $submission ) {
167 167
 
168
-		$discounts = array();
168
+        $discounts = array();
169 169
 
170 170
         foreach ( $submission->get_discounts() as $name => $data ) {
171
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
172
-		}
171
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
172
+        }
173 173
 
174
-		$this->response = array_merge(
175
-			$this->response,
176
-			array( 'discounts' => $discounts )
177
-		);
174
+        $this->response = array_merge(
175
+            $this->response,
176
+            array( 'discounts' => $discounts )
177
+        );
178 178
 
179
-	}
179
+    }
180 180
 
181
-	/**
182
-	 * Adds taxes to a response for submission refresh prices.
183
-	 *
184
-	 * @param GetPaid_Payment_Form_Submission $submission
185
-	 */
186
-	public function add_taxes( $submission ) {
187
-
188
-		$taxes  = array();
189
-		$markup = '';
181
+    /**
182
+     * Adds taxes to a response for submission refresh prices.
183
+     *
184
+     * @param GetPaid_Payment_Form_Submission $submission
185
+     */
186
+    public function add_taxes( $submission ) {
187
+
188
+        $taxes  = array();
189
+        $markup = '';
190 190
         foreach ( $submission->get_taxes() as $name => $data ) {
191
-			$name          = sanitize_text_field( $name );
192
-			$amount        = $submission->format_amount( $data['initial_tax'] );
193
-			$taxes[$name]  = $amount;
194
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
195
-		}
191
+            $name          = sanitize_text_field( $name );
192
+            $amount        = $submission->format_amount( $data['initial_tax'] );
193
+            $taxes[$name]  = $amount;
194
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
195
+        }
196 196
 
197
-		if ( wpinv_display_individual_tax_rates() ) {
198
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
199
-		}
197
+        if ( wpinv_display_individual_tax_rates() ) {
198
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
199
+        }
200 200
 
201
-		$this->response = array_merge(
202
-			$this->response,
203
-			array( 'taxes' => $taxes )
204
-		);
201
+        $this->response = array_merge(
202
+            $this->response,
203
+            array( 'taxes' => $taxes )
204
+        );
205 205
 
206
-	}
206
+    }
207 207
 
208
-	/**
209
-	 * Adds gateways to a response for submission refresh prices.
210
-	 *
211
-	 * @param GetPaid_Payment_Form_Submission $submission
212
-	 */
213
-	public function add_gateways( $submission ) {
208
+    /**
209
+     * Adds gateways to a response for submission refresh prices.
210
+     *
211
+     * @param GetPaid_Payment_Form_Submission $submission
212
+     */
213
+    public function add_gateways( $submission ) {
214 214
 
215
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
215
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
216 216
 
217
-		if ( $this->response['has_recurring'] ) {
217
+        if ( $this->response['has_recurring'] ) {
218 218
 
219
-			foreach ( $gateways as $i => $gateway ) {
219
+            foreach ( $gateways as $i => $gateway ) {
220 220
 
221
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
222
-					unset( $gateways[ $i ] );
223
-				}
221
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
222
+                    unset( $gateways[ $i ] );
223
+                }
224 224
 
225
-			}
225
+            }
226 226
 
227
-		}
227
+        }
228 228
 
229 229
 
230
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
231
-		$this->response = array_merge(
232
-			$this->response,
233
-			array( 'gateways' => $gateways )
234
-		);
230
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
231
+        $this->response = array_merge(
232
+            $this->response,
233
+            array( 'gateways' => $gateways )
234
+        );
235 235
 
236
-	}
236
+    }
237 237
 
238 238
 }
Please login to merge, or discard this patch.