@@ -12,315 +12,315 @@ |
||
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 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
34 | - ); |
|
35 | - |
|
36 | - $this->add_totals( $submission ); |
|
37 | - $this->add_texts( $submission ); |
|
38 | - $this->add_items( $submission ); |
|
39 | - $this->add_fees( $submission ); |
|
40 | - $this->add_discounts( $submission ); |
|
41 | - $this->add_taxes( $submission ); |
|
42 | - $this->add_gateways( $submission ); |
|
43 | - $this->add_data( $submission ); |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Adds totals to a response for submission refresh prices. |
|
49 | - * |
|
50 | - * @param GetPaid_Payment_Form_Submission $submission |
|
51 | - */ |
|
52 | - public function add_totals( $submission ) { |
|
53 | - |
|
54 | - $this->response = array_merge( |
|
55 | - $this->response, |
|
56 | - array( |
|
57 | - |
|
58 | - 'totals' => array( |
|
59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
65 | - ), |
|
66 | - |
|
67 | - 'recurring' => array( |
|
68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | - ), |
|
74 | - |
|
75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
76 | - 'currency' => $submission->get_currency(), |
|
77 | - |
|
78 | - ) |
|
79 | - ); |
|
80 | - |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Adds texts to a response for submission refresh prices. |
|
85 | - * |
|
86 | - * @param GetPaid_Payment_Form_Submission $submission |
|
87 | - */ |
|
88 | - public function add_texts( $submission ) { |
|
89 | - |
|
90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
92 | - |
|
93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
94 | - |
|
95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | - $main_item = reset( $groups ); |
|
98 | - |
|
99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
100 | - $payable = "$payable / $period"; |
|
101 | - } else if ( $main_item ) { |
|
102 | - |
|
103 | - $main_item = reset( $main_item ); |
|
104 | - |
|
105 | - // Calculate the next renewal date. |
|
106 | - $_period = $main_item->get_recurring_period( true ); |
|
107 | - $_interval = $main_item->get_recurring_interval(); |
|
108 | - |
|
109 | - // If the subscription item has a trial period... |
|
110 | - if ( $main_item->has_free_trial() ) { |
|
111 | - $_period = $main_item->get_trial_period( true ); |
|
112 | - $_interval = $main_item->get_trial_interval(); |
|
113 | - } |
|
114 | - |
|
115 | - $payable = sprintf( |
|
116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | - $submission->format_amount( $submission->get_total() ), |
|
118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
119 | - $period |
|
120 | - ); |
|
121 | - |
|
122 | - $payable .= sprintf( |
|
123 | - '<small class="text-muted form-text">%s</small>', |
|
124 | - sprintf( |
|
125 | - __( 'First renewal on %s', 'invoicing' ), |
|
126 | - date_i18n( 'Y-m-d', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) |
|
127 | - ) |
|
128 | - ); |
|
129 | - |
|
130 | - } else { |
|
131 | - $payable = sprintf( |
|
132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | - $submission->format_amount( $submission->get_total() ), |
|
134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
135 | - $period |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - } |
|
140 | - |
|
141 | - $texts = array( |
|
142 | - '.getpaid-checkout-total-payable' => $payable, |
|
143 | - ); |
|
144 | - |
|
145 | - foreach ( $submission->get_items() as $item ) { |
|
146 | - $item_id = $item->get_id(); |
|
147 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
148 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
149 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
150 | - } |
|
151 | - |
|
152 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
153 | - |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Adds items to a response for submission refresh prices. |
|
158 | - * |
|
159 | - * @param GetPaid_Payment_Form_Submission $submission |
|
160 | - */ |
|
161 | - public function add_items( $submission ) { |
|
162 | - |
|
163 | - // Add items. |
|
164 | - $items = array(); |
|
34 | + ); |
|
35 | + |
|
36 | + $this->add_totals( $submission ); |
|
37 | + $this->add_texts( $submission ); |
|
38 | + $this->add_items( $submission ); |
|
39 | + $this->add_fees( $submission ); |
|
40 | + $this->add_discounts( $submission ); |
|
41 | + $this->add_taxes( $submission ); |
|
42 | + $this->add_gateways( $submission ); |
|
43 | + $this->add_data( $submission ); |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Adds totals to a response for submission refresh prices. |
|
49 | + * |
|
50 | + * @param GetPaid_Payment_Form_Submission $submission |
|
51 | + */ |
|
52 | + public function add_totals( $submission ) { |
|
53 | + |
|
54 | + $this->response = array_merge( |
|
55 | + $this->response, |
|
56 | + array( |
|
57 | + |
|
58 | + 'totals' => array( |
|
59 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
65 | + ), |
|
66 | + |
|
67 | + 'recurring' => array( |
|
68 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | + ), |
|
74 | + |
|
75 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
76 | + 'currency' => $submission->get_currency(), |
|
77 | + |
|
78 | + ) |
|
79 | + ); |
|
80 | + |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Adds texts to a response for submission refresh prices. |
|
85 | + * |
|
86 | + * @param GetPaid_Payment_Form_Submission $submission |
|
87 | + */ |
|
88 | + public function add_texts( $submission ) { |
|
89 | + |
|
90 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
92 | + |
|
93 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
94 | + |
|
95 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | + $main_item = reset( $groups ); |
|
98 | + |
|
99 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
100 | + $payable = "$payable / $period"; |
|
101 | + } else if ( $main_item ) { |
|
102 | + |
|
103 | + $main_item = reset( $main_item ); |
|
104 | + |
|
105 | + // Calculate the next renewal date. |
|
106 | + $_period = $main_item->get_recurring_period( true ); |
|
107 | + $_interval = $main_item->get_recurring_interval(); |
|
108 | + |
|
109 | + // If the subscription item has a trial period... |
|
110 | + if ( $main_item->has_free_trial() ) { |
|
111 | + $_period = $main_item->get_trial_period( true ); |
|
112 | + $_interval = $main_item->get_trial_interval(); |
|
113 | + } |
|
114 | + |
|
115 | + $payable = sprintf( |
|
116 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | + $submission->format_amount( $submission->get_total() ), |
|
118 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
119 | + $period |
|
120 | + ); |
|
121 | + |
|
122 | + $payable .= sprintf( |
|
123 | + '<small class="text-muted form-text">%s</small>', |
|
124 | + sprintf( |
|
125 | + __( 'First renewal on %s', 'invoicing' ), |
|
126 | + date_i18n( 'Y-m-d', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) |
|
127 | + ) |
|
128 | + ); |
|
129 | + |
|
130 | + } else { |
|
131 | + $payable = sprintf( |
|
132 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | + $submission->format_amount( $submission->get_total() ), |
|
134 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
135 | + $period |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + } |
|
140 | + |
|
141 | + $texts = array( |
|
142 | + '.getpaid-checkout-total-payable' => $payable, |
|
143 | + ); |
|
165 | 144 | |
166 | 145 | foreach ( $submission->get_items() as $item ) { |
167 | - $item_id = $item->get_id(); |
|
168 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
169 | - } |
|
146 | + $item_id = $item->get_id(); |
|
147 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
148 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
149 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
150 | + } |
|
151 | + |
|
152 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
170 | 153 | |
171 | - $this->response = array_merge( |
|
172 | - $this->response, |
|
173 | - array( 'items' => $items ) |
|
174 | - ); |
|
154 | + } |
|
175 | 155 | |
176 | - } |
|
156 | + /** |
|
157 | + * Adds items to a response for submission refresh prices. |
|
158 | + * |
|
159 | + * @param GetPaid_Payment_Form_Submission $submission |
|
160 | + */ |
|
161 | + public function add_items( $submission ) { |
|
177 | 162 | |
178 | - /** |
|
179 | - * Adds fees to a response for submission refresh prices. |
|
180 | - * |
|
181 | - * @param GetPaid_Payment_Form_Submission $submission |
|
182 | - */ |
|
183 | - public function add_fees( $submission ) { |
|
163 | + // Add items. |
|
164 | + $items = array(); |
|
165 | + |
|
166 | + foreach ( $submission->get_items() as $item ) { |
|
167 | + $item_id = $item->get_id(); |
|
168 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
169 | + } |
|
184 | 170 | |
185 | - $fees = array(); |
|
171 | + $this->response = array_merge( |
|
172 | + $this->response, |
|
173 | + array( 'items' => $items ) |
|
174 | + ); |
|
175 | + |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Adds fees to a response for submission refresh prices. |
|
180 | + * |
|
181 | + * @param GetPaid_Payment_Form_Submission $submission |
|
182 | + */ |
|
183 | + public function add_fees( $submission ) { |
|
184 | + |
|
185 | + $fees = array(); |
|
186 | 186 | |
187 | 187 | foreach ( $submission->get_fees() as $name => $data ) { |
188 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
189 | - } |
|
188 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
189 | + } |
|
190 | 190 | |
191 | - $this->response = array_merge( |
|
192 | - $this->response, |
|
193 | - array( 'fees' => $fees ) |
|
194 | - ); |
|
191 | + $this->response = array_merge( |
|
192 | + $this->response, |
|
193 | + array( 'fees' => $fees ) |
|
194 | + ); |
|
195 | 195 | |
196 | - } |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Adds discounts to a response for submission refresh prices. |
|
200 | - * |
|
201 | - * @param GetPaid_Payment_Form_Submission $submission |
|
202 | - */ |
|
203 | - public function add_discounts( $submission ) { |
|
198 | + /** |
|
199 | + * Adds discounts to a response for submission refresh prices. |
|
200 | + * |
|
201 | + * @param GetPaid_Payment_Form_Submission $submission |
|
202 | + */ |
|
203 | + public function add_discounts( $submission ) { |
|
204 | 204 | |
205 | - $discounts = array(); |
|
205 | + $discounts = array(); |
|
206 | 206 | |
207 | 207 | foreach ( $submission->get_discounts() as $name => $data ) { |
208 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
209 | - } |
|
208 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
209 | + } |
|
210 | 210 | |
211 | - $this->response = array_merge( |
|
212 | - $this->response, |
|
213 | - array( 'discounts' => $discounts ) |
|
214 | - ); |
|
211 | + $this->response = array_merge( |
|
212 | + $this->response, |
|
213 | + array( 'discounts' => $discounts ) |
|
214 | + ); |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * Adds taxes to a response for submission refresh prices. |
|
220 | - * |
|
221 | - * @param GetPaid_Payment_Form_Submission $submission |
|
222 | - */ |
|
223 | - public function add_taxes( $submission ) { |
|
224 | - |
|
225 | - $taxes = array(); |
|
226 | - $markup = ''; |
|
218 | + /** |
|
219 | + * Adds taxes to a response for submission refresh prices. |
|
220 | + * |
|
221 | + * @param GetPaid_Payment_Form_Submission $submission |
|
222 | + */ |
|
223 | + public function add_taxes( $submission ) { |
|
224 | + |
|
225 | + $taxes = array(); |
|
226 | + $markup = ''; |
|
227 | 227 | foreach ( $submission->get_taxes() as $name => $data ) { |
228 | - $name = sanitize_text_field( $name ); |
|
229 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
230 | - $taxes[$name] = $amount; |
|
231 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
232 | - } |
|
233 | - |
|
234 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
235 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
236 | - } |
|
237 | - |
|
238 | - $this->response = array_merge( |
|
239 | - $this->response, |
|
240 | - array( 'taxes' => $taxes ) |
|
241 | - ); |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Adds gateways to a response for submission refresh prices. |
|
247 | - * |
|
248 | - * @param GetPaid_Payment_Form_Submission $submission |
|
249 | - */ |
|
250 | - public function add_gateways( $submission ) { |
|
251 | - |
|
252 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
253 | - |
|
254 | - if ( $this->response['has_recurring'] ) { |
|
255 | - |
|
256 | - foreach ( $gateways as $i => $gateway ) { |
|
257 | - |
|
258 | - if ( |
|
259 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
260 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
261 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
262 | - unset( $gateways[ $i ] ); |
|
263 | - } |
|
264 | - |
|
265 | - } |
|
266 | - |
|
267 | - } |
|
268 | - |
|
269 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
270 | - $this->response = array_merge( |
|
271 | - $this->response, |
|
272 | - array( 'gateways' => $gateways ) |
|
273 | - ); |
|
274 | - |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Standardizes prices. |
|
279 | - * |
|
280 | - * @param int $item_id |
|
281 | - * @param float $item_total |
|
282 | - * @param string $discount_code |
|
283 | - * @param bool $recurring |
|
284 | - */ |
|
285 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
286 | - |
|
287 | - $standardadized_price = $item_total; |
|
288 | - |
|
289 | - // Do we have a $discount_code? |
|
290 | - if ( ! empty( $discount_code ) ) { |
|
291 | - |
|
292 | - $discount = new WPInv_Discount( $discount_code ); |
|
293 | - |
|
294 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
295 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
296 | - } |
|
297 | - |
|
298 | - } |
|
299 | - |
|
300 | - return max( 0, $standardadized_price ); |
|
301 | - |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Adds data to a response for submission refresh prices. |
|
306 | - * |
|
307 | - * @param GetPaid_Payment_Form_Submission $submission |
|
308 | - */ |
|
309 | - public function add_data( $submission ) { |
|
310 | - |
|
311 | - $this->response = array_merge( |
|
312 | - $this->response, |
|
313 | - array( |
|
314 | - 'js_data' => apply_filters( |
|
315 | - 'getpaid_submission_js_data', |
|
316 | - array( |
|
317 | - 'is_recurring' => $this->response['has_recurring'], |
|
318 | - ), |
|
319 | - $submission |
|
320 | - ) |
|
321 | - ) |
|
322 | - ); |
|
323 | - |
|
324 | - } |
|
228 | + $name = sanitize_text_field( $name ); |
|
229 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
230 | + $taxes[$name] = $amount; |
|
231 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
232 | + } |
|
233 | + |
|
234 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
235 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
236 | + } |
|
237 | + |
|
238 | + $this->response = array_merge( |
|
239 | + $this->response, |
|
240 | + array( 'taxes' => $taxes ) |
|
241 | + ); |
|
242 | + |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Adds gateways to a response for submission refresh prices. |
|
247 | + * |
|
248 | + * @param GetPaid_Payment_Form_Submission $submission |
|
249 | + */ |
|
250 | + public function add_gateways( $submission ) { |
|
251 | + |
|
252 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
253 | + |
|
254 | + if ( $this->response['has_recurring'] ) { |
|
255 | + |
|
256 | + foreach ( $gateways as $i => $gateway ) { |
|
257 | + |
|
258 | + if ( |
|
259 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
260 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
261 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
262 | + unset( $gateways[ $i ] ); |
|
263 | + } |
|
264 | + |
|
265 | + } |
|
266 | + |
|
267 | + } |
|
268 | + |
|
269 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
270 | + $this->response = array_merge( |
|
271 | + $this->response, |
|
272 | + array( 'gateways' => $gateways ) |
|
273 | + ); |
|
274 | + |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Standardizes prices. |
|
279 | + * |
|
280 | + * @param int $item_id |
|
281 | + * @param float $item_total |
|
282 | + * @param string $discount_code |
|
283 | + * @param bool $recurring |
|
284 | + */ |
|
285 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
286 | + |
|
287 | + $standardadized_price = $item_total; |
|
288 | + |
|
289 | + // Do we have a $discount_code? |
|
290 | + if ( ! empty( $discount_code ) ) { |
|
291 | + |
|
292 | + $discount = new WPInv_Discount( $discount_code ); |
|
293 | + |
|
294 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
295 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
296 | + } |
|
297 | + |
|
298 | + } |
|
299 | + |
|
300 | + return max( 0, $standardadized_price ); |
|
301 | + |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Adds data to a response for submission refresh prices. |
|
306 | + * |
|
307 | + * @param GetPaid_Payment_Form_Submission $submission |
|
308 | + */ |
|
309 | + public function add_data( $submission ) { |
|
310 | + |
|
311 | + $this->response = array_merge( |
|
312 | + $this->response, |
|
313 | + array( |
|
314 | + 'js_data' => apply_filters( |
|
315 | + 'getpaid_submission_js_data', |
|
316 | + array( |
|
317 | + 'is_recurring' => $this->response['has_recurring'], |
|
318 | + ), |
|
319 | + $submission |
|
320 | + ) |
|
321 | + ) |
|
322 | + ); |
|
323 | + |
|
324 | + } |
|
325 | 325 | |
326 | 326 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission refresh prices class |
@@ -23,24 +23,24 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'has_subscription_group' => $submission->has_subscription_group(), |
32 | 32 | 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
33 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
33 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
34 | 34 | ); |
35 | 35 | |
36 | - $this->add_totals( $submission ); |
|
37 | - $this->add_texts( $submission ); |
|
38 | - $this->add_items( $submission ); |
|
39 | - $this->add_fees( $submission ); |
|
40 | - $this->add_discounts( $submission ); |
|
41 | - $this->add_taxes( $submission ); |
|
42 | - $this->add_gateways( $submission ); |
|
43 | - $this->add_data( $submission ); |
|
36 | + $this->add_totals($submission); |
|
37 | + $this->add_texts($submission); |
|
38 | + $this->add_items($submission); |
|
39 | + $this->add_fees($submission); |
|
40 | + $this->add_discounts($submission); |
|
41 | + $this->add_taxes($submission); |
|
42 | + $this->add_gateways($submission); |
|
43 | + $this->add_data($submission); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param GetPaid_Payment_Form_Submission $submission |
51 | 51 | */ |
52 | - public function add_totals( $submission ) { |
|
52 | + public function add_totals($submission) { |
|
53 | 53 | |
54 | 54 | $this->response = array_merge( |
55 | 55 | $this->response, |
56 | 56 | array( |
57 | 57 | |
58 | 58 | 'totals' => array( |
59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
59 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
60 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
61 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
62 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
63 | + 'total' => $submission->format_amount($submission->get_total()), |
|
64 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
65 | 65 | ), |
66 | 66 | |
67 | 67 | 'recurring' => array( |
68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
68 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
69 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
70 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
71 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
72 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
73 | 73 | ), |
74 | 74 | |
75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
75 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
76 | 76 | 'currency' => $submission->get_currency(), |
77 | 77 | |
78 | 78 | ) |
@@ -85,53 +85,53 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param GetPaid_Payment_Form_Submission $submission |
87 | 87 | */ |
88 | - public function add_texts( $submission ) { |
|
88 | + public function add_texts($submission) { |
|
89 | 89 | |
90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
90 | + $payable = $submission->format_amount($submission->get_total()); |
|
91 | + $groups = getpaid_get_subscription_groups($submission); |
|
92 | 92 | |
93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
93 | + if ($submission->has_recurring && 2 > count($groups)) { |
|
94 | 94 | |
95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | - $main_item = reset( $groups ); |
|
95 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
96 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
97 | + $main_item = reset($groups); |
|
98 | 98 | |
99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
99 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
100 | 100 | $payable = "$payable / $period"; |
101 | - } else if ( $main_item ) { |
|
101 | + } else if ($main_item) { |
|
102 | 102 | |
103 | - $main_item = reset( $main_item ); |
|
103 | + $main_item = reset($main_item); |
|
104 | 104 | |
105 | 105 | // Calculate the next renewal date. |
106 | - $_period = $main_item->get_recurring_period( true ); |
|
106 | + $_period = $main_item->get_recurring_period(true); |
|
107 | 107 | $_interval = $main_item->get_recurring_interval(); |
108 | 108 | |
109 | 109 | // If the subscription item has a trial period... |
110 | - if ( $main_item->has_free_trial() ) { |
|
111 | - $_period = $main_item->get_trial_period( true ); |
|
110 | + if ($main_item->has_free_trial()) { |
|
111 | + $_period = $main_item->get_trial_period(true); |
|
112 | 112 | $_interval = $main_item->get_trial_interval(); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $payable = sprintf( |
116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | - $submission->format_amount( $submission->get_total() ), |
|
118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
116 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
117 | + $submission->format_amount($submission->get_total()), |
|
118 | + $submission->format_amount($submission->get_recurring_total()), |
|
119 | 119 | $period |
120 | 120 | ); |
121 | 121 | |
122 | 122 | $payable .= sprintf( |
123 | 123 | '<small class="text-muted form-text">%s</small>', |
124 | 124 | sprintf( |
125 | - __( 'First renewal on %s', 'invoicing' ), |
|
126 | - date_i18n( 'Y-m-d', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) |
|
125 | + __('First renewal on %s', 'invoicing'), |
|
126 | + date_i18n('Y-m-d', strtotime("+$_interval $_period", current_time('timestamp'))) |
|
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | |
130 | 130 | } else { |
131 | 131 | $payable = sprintf( |
132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | - $submission->format_amount( $submission->get_total() ), |
|
134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
132 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
133 | + $submission->format_amount($submission->get_total()), |
|
134 | + $submission->format_amount($submission->get_recurring_total()), |
|
135 | 135 | $period |
136 | 136 | ); |
137 | 137 | } |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | '.getpaid-checkout-total-payable' => $payable, |
143 | 143 | ); |
144 | 144 | |
145 | - foreach ( $submission->get_items() as $item ) { |
|
145 | + foreach ($submission->get_items() as $item) { |
|
146 | 146 | $item_id = $item->get_id(); |
147 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
148 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
149 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
147 | + $initial_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false)); |
|
148 | + $recurring_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true)); |
|
149 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
150 | 150 | } |
151 | 151 | |
152 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
152 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
153 | 153 | |
154 | 154 | } |
155 | 155 | |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @param GetPaid_Payment_Form_Submission $submission |
160 | 160 | */ |
161 | - public function add_items( $submission ) { |
|
161 | + public function add_items($submission) { |
|
162 | 162 | |
163 | 163 | // Add items. |
164 | 164 | $items = array(); |
165 | 165 | |
166 | - foreach ( $submission->get_items() as $item ) { |
|
166 | + foreach ($submission->get_items() as $item) { |
|
167 | 167 | $item_id = $item->get_id(); |
168 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
168 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | $this->response = array_merge( |
172 | 172 | $this->response, |
173 | - array( 'items' => $items ) |
|
173 | + array('items' => $items) |
|
174 | 174 | ); |
175 | 175 | |
176 | 176 | } |
@@ -180,17 +180,17 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @param GetPaid_Payment_Form_Submission $submission |
182 | 182 | */ |
183 | - public function add_fees( $submission ) { |
|
183 | + public function add_fees($submission) { |
|
184 | 184 | |
185 | 185 | $fees = array(); |
186 | 186 | |
187 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
188 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
187 | + foreach ($submission->get_fees() as $name => $data) { |
|
188 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | $this->response = array_merge( |
192 | 192 | $this->response, |
193 | - array( 'fees' => $fees ) |
|
193 | + array('fees' => $fees) |
|
194 | 194 | ); |
195 | 195 | |
196 | 196 | } |
@@ -200,17 +200,17 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @param GetPaid_Payment_Form_Submission $submission |
202 | 202 | */ |
203 | - public function add_discounts( $submission ) { |
|
203 | + public function add_discounts($submission) { |
|
204 | 204 | |
205 | 205 | $discounts = array(); |
206 | 206 | |
207 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
208 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
207 | + foreach ($submission->get_discounts() as $name => $data) { |
|
208 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | $this->response = array_merge( |
212 | 212 | $this->response, |
213 | - array( 'discounts' => $discounts ) |
|
213 | + array('discounts' => $discounts) |
|
214 | 214 | ); |
215 | 215 | |
216 | 216 | } |
@@ -220,24 +220,24 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @param GetPaid_Payment_Form_Submission $submission |
222 | 222 | */ |
223 | - public function add_taxes( $submission ) { |
|
223 | + public function add_taxes($submission) { |
|
224 | 224 | |
225 | 225 | $taxes = array(); |
226 | 226 | $markup = ''; |
227 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
228 | - $name = sanitize_text_field( $name ); |
|
229 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
227 | + foreach ($submission->get_taxes() as $name => $data) { |
|
228 | + $name = sanitize_text_field($name); |
|
229 | + $amount = $submission->format_amount($data['initial_tax']); |
|
230 | 230 | $taxes[$name] = $amount; |
231 | 231 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
232 | 232 | } |
233 | 233 | |
234 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
234 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
235 | 235 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
236 | 236 | } |
237 | 237 | |
238 | 238 | $this->response = array_merge( |
239 | 239 | $this->response, |
240 | - array( 'taxes' => $taxes ) |
|
240 | + array('taxes' => $taxes) |
|
241 | 241 | ); |
242 | 242 | |
243 | 243 | } |
@@ -247,29 +247,29 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @param GetPaid_Payment_Form_Submission $submission |
249 | 249 | */ |
250 | - public function add_gateways( $submission ) { |
|
250 | + public function add_gateways($submission) { |
|
251 | 251 | |
252 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
252 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
253 | 253 | |
254 | - if ( $this->response['has_recurring'] ) { |
|
254 | + if ($this->response['has_recurring']) { |
|
255 | 255 | |
256 | - foreach ( $gateways as $i => $gateway ) { |
|
256 | + foreach ($gateways as $i => $gateway) { |
|
257 | 257 | |
258 | 258 | if ( |
259 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
260 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
261 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
262 | - unset( $gateways[ $i ] ); |
|
259 | + !getpaid_payment_gateway_supports($gateway, 'subscription') |
|
260 | + || ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group')) |
|
261 | + || ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) { |
|
262 | + unset($gateways[$i]); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | } |
266 | 266 | |
267 | 267 | } |
268 | 268 | |
269 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
269 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
270 | 270 | $this->response = array_merge( |
271 | 271 | $this->response, |
272 | - array( 'gateways' => $gateways ) |
|
272 | + array('gateways' => $gateways) |
|
273 | 273 | ); |
274 | 274 | |
275 | 275 | } |
@@ -282,22 +282,22 @@ discard block |
||
282 | 282 | * @param string $discount_code |
283 | 283 | * @param bool $recurring |
284 | 284 | */ |
285 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
285 | + public function standardize_price($item_id, $item_total, $discount_code, $recurring = false) { |
|
286 | 286 | |
287 | 287 | $standardadized_price = $item_total; |
288 | 288 | |
289 | 289 | // Do we have a $discount_code? |
290 | - if ( ! empty( $discount_code ) ) { |
|
290 | + if (!empty($discount_code)) { |
|
291 | 291 | |
292 | - $discount = new WPInv_Discount( $discount_code ); |
|
292 | + $discount = new WPInv_Discount($discount_code); |
|
293 | 293 | |
294 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
295 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
294 | + if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) { |
|
295 | + $standardadized_price = $item_total - $discount->get_discounted_amount($item_total); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | } |
299 | 299 | |
300 | - return max( 0, $standardadized_price ); |
|
300 | + return max(0, $standardadized_price); |
|
301 | 301 | |
302 | 302 | } |
303 | 303 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @param GetPaid_Payment_Form_Submission $submission |
308 | 308 | */ |
309 | - public function add_data( $submission ) { |
|
309 | + public function add_data($submission) { |
|
310 | 310 | |
311 | 311 | $this->response = array_merge( |
312 | 312 | $this->response, |
@@ -13,94 +13,94 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * Process Payment. |
|
96 | - * |
|
97 | - * |
|
98 | - * @param WPInv_Invoice $invoice Invoice. |
|
99 | - * @param array $submission_data Posted checkout fields. |
|
100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
95 | + * Process Payment. |
|
96 | + * |
|
97 | + * |
|
98 | + * @param WPInv_Invoice $invoice Invoice. |
|
99 | + * @param array $submission_data Posted checkout fields. |
|
100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Get the PayPal request URL for an invoice. |
|
127 | - * |
|
128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function get_request_url( $invoice ) { |
|
126 | + * Get the PayPal request URL for an invoice. |
|
127 | + * |
|
128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function get_request_url( $invoice ) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
144 | 144 | |
145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | /** |
150 | - * Get PayPal Args for passing to PP. |
|
151 | - * |
|
152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function get_paypal_args( $invoice ) { |
|
150 | + * Get PayPal Args for passing to PP. |
|
151 | + * |
|
152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function get_paypal_args( $invoice ) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | - |
|
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | - $force_one_line_item = true; |
|
162 | - } |
|
163 | - |
|
164 | - $paypal_args = apply_filters( |
|
165 | - 'getpaid_paypal_args', |
|
166 | - array_merge( |
|
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | - ), |
|
170 | - $invoice |
|
171 | - ); |
|
172 | - |
|
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | + |
|
160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | + $force_one_line_item = true; |
|
162 | + } |
|
163 | + |
|
164 | + $paypal_args = apply_filters( |
|
165 | + 'getpaid_paypal_args', |
|
166 | + array_merge( |
|
167 | + $this->get_transaction_args( $invoice ), |
|
168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + ), |
|
170 | + $invoice |
|
171 | + ); |
|
172 | + |
|
173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Get transaction args for paypal request. |
|
178 | - * |
|
179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function get_transaction_args( $invoice ) { |
|
183 | - |
|
184 | - return array( |
|
177 | + * Get transaction args for paypal request. |
|
178 | + * |
|
179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function get_transaction_args( $invoice ) { |
|
183 | + |
|
184 | + return array( |
|
185 | 185 | 'cmd' => '_cart', |
186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | - * Get line item args for paypal request. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
209 | + * Get line item args for paypal request. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
218 | + if ( $force_one_line_item ) { |
|
219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
220 | 220 | } |
221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Get line item args for paypal request as a single line item. |
|
244 | - * |
|
245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
249 | - $this->delete_line_items(); |
|
243 | + * Get line item args for paypal request as a single line item. |
|
244 | + * |
|
245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
249 | + $this->delete_line_items(); |
|
250 | 250 | |
251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
252 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
253 | 253 | |
254 | - return $this->get_line_items(); |
|
254 | + return $this->get_line_items(); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Return all line items. |
|
259 | - */ |
|
260 | - protected function get_line_items() { |
|
261 | - return $this->line_items; |
|
262 | - } |
|
258 | + * Return all line items. |
|
259 | + */ |
|
260 | + protected function get_line_items() { |
|
261 | + return $this->line_items; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | /** |
265 | - * Remove all line items. |
|
266 | - */ |
|
267 | - protected function delete_line_items() { |
|
268 | - $this->line_items = array(); |
|
265 | + * Remove all line items. |
|
266 | + */ |
|
267 | + protected function delete_line_items() { |
|
268 | + $this->line_items = array(); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Prepare line items to send to paypal. |
|
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
275 | - */ |
|
276 | - protected function prepare_line_items( $invoice ) { |
|
277 | - $this->delete_line_items(); |
|
278 | - |
|
279 | - // Items. |
|
280 | - foreach ( $invoice->get_items() as $item ) { |
|
281 | - $amount = $item->get_price(); |
|
282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
272 | + * Prepare line items to send to paypal. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | + */ |
|
276 | + protected function prepare_line_items( $invoice ) { |
|
277 | + $this->delete_line_items(); |
|
278 | + |
|
279 | + // Items. |
|
280 | + foreach ( $invoice->get_items() as $item ) { |
|
281 | + $amount = $item->get_price(); |
|
282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | - * Add PayPal Line Item. |
|
295 | - * |
|
296 | - * @param string $item_name Item name. |
|
297 | - * @param int $quantity Item quantity. |
|
298 | - * @param float $amount Amount. |
|
299 | - * @param string $item_number Item number. |
|
300 | - */ |
|
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | - |
|
304 | - $item = apply_filters( |
|
305 | - 'getpaid_paypal_line_item', |
|
306 | - array( |
|
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | - 'quantity' => (float) $quantity, |
|
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | - 'item_number' => $item_number, |
|
311 | - ), |
|
312 | - $item_name, |
|
313 | - $quantity, |
|
314 | - $amount, |
|
315 | - $item_number |
|
316 | - ); |
|
317 | - |
|
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
294 | + * Add PayPal Line Item. |
|
295 | + * |
|
296 | + * @param string $item_name Item name. |
|
297 | + * @param int $quantity Item quantity. |
|
298 | + * @param float $amount Amount. |
|
299 | + * @param string $item_number Item number. |
|
300 | + */ |
|
301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | + |
|
304 | + $item = apply_filters( |
|
305 | + 'getpaid_paypal_line_item', |
|
306 | + array( |
|
307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | + 'quantity' => (float) $quantity, |
|
309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | + 'item_number' => $item_number, |
|
311 | + ), |
|
312 | + $item_name, |
|
313 | + $quantity, |
|
314 | + $amount, |
|
315 | + $item_number |
|
316 | + ); |
|
317 | + |
|
318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | - * |
|
329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | - * |
|
331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | - $max_paypal_length = 2083; |
|
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | - |
|
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | - return $paypal_args; |
|
341 | - } |
|
342 | - |
|
343 | - return apply_filters( |
|
344 | - 'getpaid_paypal_args', |
|
345 | - array_merge( |
|
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
348 | - ), |
|
349 | - $invoice |
|
350 | - ); |
|
327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | + * |
|
329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | + * |
|
331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | + $max_paypal_length = 2083; |
|
337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | + |
|
339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | + return $paypal_args; |
|
341 | + } |
|
342 | + |
|
343 | + return apply_filters( |
|
344 | + 'getpaid_paypal_args', |
|
345 | + array_merge( |
|
346 | + $this->get_transaction_args( $invoice ), |
|
347 | + $this->get_line_item_args( $invoice, true ) |
|
348 | + ), |
|
349 | + $invoice |
|
350 | + ); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | - * Processes recurring invoices. |
|
356 | - * |
|
357 | - * @param array $paypal_args PayPal args. |
|
358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
359 | - */ |
|
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
355 | + * Processes recurring invoices. |
|
356 | + * |
|
357 | + * @param array $paypal_args PayPal args. |
|
358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
359 | + */ |
|
360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
385 | - // Trial period length. |
|
386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
385 | + // Trial period length. |
|
386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
387 | 387 | |
388 | - // Trial period. |
|
389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
388 | + // Trial period. |
|
389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
390 | 390 | |
391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
413 | 413 | |
414 | - // Subscription price |
|
415 | - $paypal_args['a3'] = $recurring_amount; |
|
414 | + // Subscription price |
|
415 | + $paypal_args['a3'] = $recurring_amount; |
|
416 | 416 | |
417 | - // Subscription duration |
|
418 | - $paypal_args['p3'] = $interval; |
|
417 | + // Subscription duration |
|
418 | + $paypal_args['p3'] = $interval; |
|
419 | 419 | |
420 | - // Subscription period |
|
421 | - $paypal_args['t3'] = $period; |
|
420 | + // Subscription period |
|
421 | + $paypal_args['t3'] = $period; |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
427 | 427 | |
428 | - // Non-recurring payments |
|
429 | - $paypal_args['src'] = 0; |
|
428 | + // Non-recurring payments |
|
429 | + $paypal_args['src'] = 0; |
|
430 | 430 | |
431 | - } else { |
|
431 | + } else { |
|
432 | 432 | |
433 | - $paypal_args['src'] = 1; |
|
433 | + $paypal_args['src'] = 1; |
|
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ( $bill_times > 0 ) { |
|
436 | 436 | |
437 | - // An initial period is being used to charge a sign-up fee |
|
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | - $bill_times--; |
|
440 | - } |
|
437 | + // An initial period is being used to charge a sign-up fee |
|
438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | + $bill_times--; |
|
440 | + } |
|
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,19 +458,19 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | return apply_filters( |
461 | - 'getpaid_paypal_subscription_args', |
|
462 | - $paypal_args, |
|
463 | - $invoice |
|
461 | + 'getpaid_paypal_subscription_args', |
|
462 | + $paypal_args, |
|
463 | + $invoice |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | - * Processes ipns and marks payments as complete. |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function verify_ipn() { |
|
469 | + * Processes ipns and marks payments as complete. |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function verify_ipn() { |
|
474 | 474 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
475 | 475 | } |
476 | 476 | |
@@ -480,10 +480,10 @@ discard block |
||
480 | 480 | public function sandbox_notice() { |
481 | 481 | |
482 | 482 | return sprintf( |
483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | - '</a>' |
|
486 | - ); |
|
483 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | + '</a>' |
|
486 | + ); |
|
487 | 487 | |
488 | 488 | } |
489 | 489 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
103 | + public function process_payment($invoice, $submission_data, $submission) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
106 | + $paypal_redirect = $this->get_request_url($invoice); |
|
107 | 107 | |
108 | 108 | // Add a note about the request url. |
109 | 109 | $invoice->add_note( |
110 | 110 | sprintf( |
111 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
112 | - esc_url( $paypal_redirect ) |
|
111 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
112 | + esc_url($paypal_redirect) |
|
113 | 113 | ), |
114 | 114 | false, |
115 | 115 | false, |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | |
119 | 119 | // Redirect to PayPal |
120 | - wp_redirect( $paypal_redirect ); |
|
120 | + wp_redirect($paypal_redirect); |
|
121 | 121 | exit; |
122 | 122 | |
123 | 123 | } |
@@ -128,21 +128,21 @@ discard block |
||
128 | 128 | * @param WPInv_Invoice $invoice Invoice object. |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public function get_request_url( $invoice ) { |
|
131 | + public function get_request_url($invoice) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
137 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
138 | 138 | |
139 | - if ( $invoice->is_recurring() ) { |
|
139 | + if ($invoice->is_recurring()) { |
|
140 | 140 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
141 | 141 | } else { |
142 | 142 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
143 | 143 | } |
144 | 144 | |
145 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
145 | + return add_query_arg($paypal_args, $this->endpoint); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -152,25 +152,25 @@ discard block |
||
152 | 152 | * @param WPInv_Invoice $invoice Invoice object. |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - protected function get_paypal_args( $invoice ) { |
|
155 | + protected function get_paypal_args($invoice) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
158 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice); |
|
159 | 159 | |
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
160 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
161 | 161 | $force_one_line_item = true; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $paypal_args = apply_filters( |
165 | 165 | 'getpaid_paypal_args', |
166 | 166 | array_merge( |
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
167 | + $this->get_transaction_args($invoice), |
|
168 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
169 | 169 | ), |
170 | 170 | $invoice |
171 | 171 | ); |
172 | 172 | |
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
173 | + return $this->fix_request_length($invoice, $paypal_args); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | * @param WPInv_Invoice $invoice Invoice object. |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - protected function get_transaction_args( $invoice ) { |
|
182 | + protected function get_transaction_args($invoice) { |
|
183 | 183 | |
184 | 184 | return array( |
185 | 185 | 'cmd' => '_cart', |
186 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
186 | + 'business' => wpinv_get_option('paypal_email', false), |
|
187 | 187 | 'no_shipping' => '1', |
188 | 188 | 'shipping' => '0', |
189 | 189 | 'no_note' => '1', |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | 'rm' => is_ssl() ? 2 : 1, |
192 | 192 | 'upload' => 1, |
193 | 193 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
194 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
195 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
196 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
197 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
194 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
195 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
196 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
197 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
198 | 198 | 'custom' => $invoice->get_id(), |
199 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
200 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
201 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
202 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
203 | - 'cbt' => get_bloginfo( 'name' ) |
|
199 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
200 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
201 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
202 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
203 | + 'cbt' => get_bloginfo('name') |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | } |
@@ -212,30 +212,30 @@ discard block |
||
212 | 212 | * @param bool $force_one_line_item Create only one item for this invoice. |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
215 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
219 | - return $this->get_line_item_args_single_item( $invoice ); |
|
218 | + if ($force_one_line_item) { |
|
219 | + return $this->get_line_item_args_single_item($invoice); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // Send each line item individually. |
223 | 223 | $line_item_args = array(); |
224 | 224 | |
225 | 225 | // Prepare line items. |
226 | - $this->prepare_line_items( $invoice ); |
|
226 | + $this->prepare_line_items($invoice); |
|
227 | 227 | |
228 | 228 | // Add taxes to the cart |
229 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
230 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
229 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
230 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Add discount. |
234 | - if ( $invoice->get_total_discount() > 0 ) { |
|
235 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
234 | + if ($invoice->get_total_discount() > 0) { |
|
235 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge($line_item_args, $this->get_line_items()); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | * @param WPInv_Invoice $invoice Invoice object. |
246 | 246 | * @return array |
247 | 247 | */ |
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
248 | + protected function get_line_item_args_single_item($invoice) { |
|
249 | 249 | $this->delete_line_items(); |
250 | 250 | |
251 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
252 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
251 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
252 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
253 | 253 | |
254 | 254 | return $this->get_line_items(); |
255 | 255 | } |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
275 | 275 | */ |
276 | - protected function prepare_line_items( $invoice ) { |
|
276 | + protected function prepare_line_items($invoice) { |
|
277 | 277 | $this->delete_line_items(); |
278 | 278 | |
279 | 279 | // Items. |
280 | - foreach ( $invoice->get_items() as $item ) { |
|
280 | + foreach ($invoice->get_items() as $item) { |
|
281 | 281 | $amount = $item->get_price(); |
282 | 282 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
283 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
287 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
288 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
@@ -298,15 +298,15 @@ discard block |
||
298 | 298 | * @param float $amount Amount. |
299 | 299 | * @param string $item_number Item number. |
300 | 300 | */ |
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
301 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
302 | + $index = (count($this->line_items) / 4) + 1; |
|
303 | 303 | |
304 | 304 | $item = apply_filters( |
305 | 305 | 'getpaid_paypal_line_item', |
306 | 306 | array( |
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
307 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
308 | 308 | 'quantity' => (float) $quantity, |
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
309 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
310 | 310 | 'item_number' => $item_number, |
311 | 311 | ), |
312 | 312 | $item_name, |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | $item_number |
316 | 316 | ); |
317 | 317 | |
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
318 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
319 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items['amount_' . $index] = $item['amount']; |
|
323 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -332,19 +332,19 @@ discard block |
||
332 | 332 | * @param array $paypal_args Arguments sent to Paypal in the request. |
333 | 333 | * @return array |
334 | 334 | */ |
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
335 | + protected function fix_request_length($invoice, $paypal_args) { |
|
336 | 336 | $max_paypal_length = 2083; |
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
337 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
338 | 338 | |
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
339 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
340 | 340 | return $paypal_args; |
341 | 341 | } |
342 | 342 | |
343 | 343 | return apply_filters( |
344 | 344 | 'getpaid_paypal_args', |
345 | 345 | array_merge( |
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
346 | + $this->get_transaction_args($invoice), |
|
347 | + $this->get_line_item_args($invoice, true) |
|
348 | 348 | ), |
349 | 349 | $invoice |
350 | 350 | ); |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | * @param array $paypal_args PayPal args. |
358 | 358 | * @param WPInv_Invoice $invoice Invoice object. |
359 | 359 | */ |
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
360 | + public function process_subscription($paypal_args, $invoice) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
363 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
364 | 364 | return $paypal_args; |
365 | 365 | } |
366 | 366 | |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
369 | 369 | |
370 | 370 | // Subscription name. |
371 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
371 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
372 | 372 | |
373 | 373 | // Get subscription args. |
374 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
374 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
375 | 375 | $interval = (int) $subscription->get_frequency(); |
376 | 376 | $bill_times = (int) $subscription->get_bill_times(); |
377 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
378 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
379 | - $subscription_item = $invoice->get_recurring( true ); |
|
377 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
378 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
379 | + $subscription_item = $invoice->get_recurring(true); |
|
380 | 380 | |
381 | - if ( $subscription_item->has_free_trial() ) { |
|
381 | + if ($subscription_item->has_free_trial()) { |
|
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
@@ -388,28 +388,28 @@ discard block |
||
388 | 388 | // Trial period. |
389 | 389 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
390 | 390 | |
391 | - } else if ( $initial_amount != $recurring_amount ) { |
|
391 | + } else if ($initial_amount != $recurring_amount) { |
|
392 | 392 | |
393 | 393 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
394 | 394 | |
395 | - if ( 1 == $bill_times ) { |
|
395 | + if (1 == $bill_times) { |
|
396 | 396 | $param_number = 3; |
397 | 397 | } else { |
398 | 398 | $param_number = 1; |
399 | 399 | } |
400 | 400 | |
401 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
401 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
402 | 402 | |
403 | 403 | // Sign Up interval |
404 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
404 | + $paypal_args['p' . $param_number] = $interval; |
|
405 | 405 | |
406 | 406 | // Sign Up unit of duration |
407 | - $paypal_args[ 't' . $param_number ] = $period; |
|
407 | + $paypal_args['t' . $param_number] = $period; |
|
408 | 408 | |
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if (!isset($param_number) || 1 == $param_number) { |
|
413 | 413 | |
414 | 414 | // Subscription price |
415 | 415 | $paypal_args['a3'] = $recurring_amount; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
427 | 427 | |
428 | 428 | // Non-recurring payments |
429 | 429 | $paypal_args['src'] = 0; |
@@ -432,15 +432,15 @@ discard block |
||
432 | 432 | |
433 | 433 | $paypal_args['src'] = 1; |
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ($bill_times > 0) { |
|
436 | 436 | |
437 | 437 | // An initial period is being used to charge a sign-up fee |
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
438 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
439 | 439 | $bill_times--; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
443 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | $paypal_args['rm'] = 2; |
450 | 450 | |
451 | 451 | // Get rid of redudant items. |
452 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
452 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
453 | 453 | |
454 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
455 | - unset( $paypal_args[ $arg ] ); |
|
454 | + if (isset($paypal_args[$arg])) { |
|
455 | + unset($paypal_args[$arg]); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @return void |
472 | 472 | */ |
473 | 473 | public function verify_ipn() { |
474 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
474 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | public function sandbox_notice() { |
481 | 481 | |
482 | 482 | return sprintf( |
483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
483 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
484 | 484 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
485 | 485 | '</a>' |
486 | 486 | ); |