Passed
Pull Request — master (#433)
by Brian
04:54
created
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,217 +12,217 @@
 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
-			)
73
-		);
74
-
75
-	}
76
-
77
-	/**
78
-	 * Adds texts to a response for submission refresh prices.
79
-	 *
80
-	 * @param GetPaid_Payment_Form_Submission $submission
81
-	 */
82
-	public function add_texts( $submission ) {
83
-
84
-		$payable = $submission->format_amount( $submission->get_total() );
85
-
86
-		if ( $submission->has_recurring != 0 ) {
87
-
88
-			$recurring = new WPInv_Item( $submission->has_recurring );
89
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
90
-
91
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
92
-				$payable = "$payable / $period";
93
-			} else {
94
-				$payable = sprintf(
95
-					__( '%1$s (renews at %2$s / %3$s)'),
96
-					$submission->format_amount( $submission->get_total() ),
97
-					$submission->format_amount( $submission->get_recurring_total() ),
98
-					$period
99
-				);
100
-			}
101
-
102
-		}
103
-
104
-		$texts = array(
105
-			'.getpaid-checkout-total-payable' => $payable,
106
-		);
107
-
108
-		foreach ( $submission->get_items() as $item_id => $item ) {
109
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
110
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
111
-		}
112
-
113
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
114
-
115
-	}
116
-
117
-	/**
118
-	 * Adds items to a response for submission refresh prices.
119
-	 *
120
-	 * @param GetPaid_Payment_Form_Submission $submission
121
-	 */
122
-	public function add_items( $submission ) {
123
-
124
-		// Add items.
125
-		$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
+            )
73
+        );
74
+
75
+    }
76
+
77
+    /**
78
+     * Adds texts to a response for submission refresh prices.
79
+     *
80
+     * @param GetPaid_Payment_Form_Submission $submission
81
+     */
82
+    public function add_texts( $submission ) {
83
+
84
+        $payable = $submission->format_amount( $submission->get_total() );
85
+
86
+        if ( $submission->has_recurring != 0 ) {
87
+
88
+            $recurring = new WPInv_Item( $submission->has_recurring );
89
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
90
+
91
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
92
+                $payable = "$payable / $period";
93
+            } else {
94
+                $payable = sprintf(
95
+                    __( '%1$s (renews at %2$s / %3$s)'),
96
+                    $submission->format_amount( $submission->get_total() ),
97
+                    $submission->format_amount( $submission->get_recurring_total() ),
98
+                    $period
99
+                );
100
+            }
101
+
102
+        }
103
+
104
+        $texts = array(
105
+            '.getpaid-checkout-total-payable' => $payable,
106
+        );
107
+
108
+        foreach ( $submission->get_items() as $item_id => $item ) {
109
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
110
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
111
+        }
112
+
113
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
114
+
115
+    }
116
+
117
+    /**
118
+     * Adds items to a response for submission refresh prices.
119
+     *
120
+     * @param GetPaid_Payment_Form_Submission $submission
121
+     */
122
+    public function add_items( $submission ) {
123
+
124
+        // Add items.
125
+        $items = array();
126 126
 
127 127
         foreach ( $submission->get_items() as $item_id => $item ) {
128
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
129
-		}
128
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
129
+        }
130 130
 
131
-		$this->response = array_merge(
132
-			$this->response,
133
-			array( 'items' => $items )
134
-		);
131
+        $this->response = array_merge(
132
+            $this->response,
133
+            array( 'items' => $items )
134
+        );
135 135
 
136
-	}
136
+    }
137 137
 
138
-	/**
139
-	 * Adds fees to a response for submission refresh prices.
140
-	 *
141
-	 * @param GetPaid_Payment_Form_Submission $submission
142
-	 */
143
-	public function add_fees( $submission ) {
138
+    /**
139
+     * Adds fees to a response for submission refresh prices.
140
+     *
141
+     * @param GetPaid_Payment_Form_Submission $submission
142
+     */
143
+    public function add_fees( $submission ) {
144 144
 
145
-		$fees = array();
145
+        $fees = array();
146 146
 
147 147
         foreach ( $submission->get_fees() as $name => $data ) {
148
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
149
-		}
148
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
149
+        }
150 150
 
151
-		$this->response = array_merge(
152
-			$this->response,
153
-			array( 'fees' => $fees )
154
-		);
151
+        $this->response = array_merge(
152
+            $this->response,
153
+            array( 'fees' => $fees )
154
+        );
155 155
 
156
-	}
156
+    }
157 157
 
158
-	/**
159
-	 * Adds discounts to a response for submission refresh prices.
160
-	 *
161
-	 * @param GetPaid_Payment_Form_Submission $submission
162
-	 */
163
-	public function add_discounts( $submission ) {
158
+    /**
159
+     * Adds discounts to a response for submission refresh prices.
160
+     *
161
+     * @param GetPaid_Payment_Form_Submission $submission
162
+     */
163
+    public function add_discounts( $submission ) {
164 164
 
165
-		$discounts = array();
165
+        $discounts = array();
166 166
 
167 167
         foreach ( $submission->get_discounts() as $name => $data ) {
168
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
169
-		}
168
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
169
+        }
170 170
 
171
-		$this->response = array_merge(
172
-			$this->response,
173
-			array( 'discounts' => $discounts )
174
-		);
171
+        $this->response = array_merge(
172
+            $this->response,
173
+            array( 'discounts' => $discounts )
174
+        );
175 175
 
176
-	}
176
+    }
177 177
 
178
-	/**
179
-	 * Adds taxes to a response for submission refresh prices.
180
-	 *
181
-	 * @param GetPaid_Payment_Form_Submission $submission
182
-	 */
183
-	public function add_taxes( $submission ) {
178
+    /**
179
+     * Adds taxes to a response for submission refresh prices.
180
+     *
181
+     * @param GetPaid_Payment_Form_Submission $submission
182
+     */
183
+    public function add_taxes( $submission ) {
184 184
 
185
-		$taxes = array();
185
+        $taxes = array();
186 186
 
187 187
         foreach ( $submission->get_taxes() as $name => $data ) {
188
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
189
-		}
188
+            $taxes[$name] = $submission->format_amount( $data['initial_tax'] );
189
+        }
190 190
 
191
-		$this->response = array_merge(
192
-			$this->response,
193
-			array( 'taxes' => $taxes )
194
-		);
191
+        $this->response = array_merge(
192
+            $this->response,
193
+            array( 'taxes' => $taxes )
194
+        );
195 195
 
196
-	}
196
+    }
197 197
 
198
-	/**
199
-	 * Adds gateways to a response for submission refresh prices.
200
-	 *
201
-	 * @param GetPaid_Payment_Form_Submission $submission
202
-	 */
203
-	public function add_gateways( $submission ) {
198
+    /**
199
+     * Adds gateways to a response for submission refresh prices.
200
+     *
201
+     * @param GetPaid_Payment_Form_Submission $submission
202
+     */
203
+    public function add_gateways( $submission ) {
204 204
 
205
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
205
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
206 206
 
207
-		if ( $this->response['has_recurring'] ) {
207
+        if ( $this->response['has_recurring'] ) {
208 208
 
209
-			foreach ( $gateways as $i => $gateway ) {
209
+            foreach ( $gateways as $i => $gateway ) {
210 210
 
211
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
212
-					unset( $gateways[ $i ] );
213
-				}
211
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
212
+                    unset( $gateways[ $i ] );
213
+                }
214 214
 
215
-			}
215
+            }
216 216
 
217
-		}
217
+        }
218 218
 
219 219
 
220
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
221
-		$this->response = array_merge(
222
-			$this->response,
223
-			array( 'gateways' => $gateways )
224
-		);
220
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
221
+        $this->response = array_merge(
222
+            $this->response,
223
+            array( 'gateways' => $gateways )
224
+        );
225 225
 
226
-	}
226
+    }
227 227
 
228 228
 }
Please login to merge, or discard this patch.