@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,60 +10,60 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Item tax. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Item tax. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $item_tax = 0; |
|
67 | 67 | |
68 | 68 | /* |
69 | 69 | |-------------------------------------------------------------------------- |
@@ -81,232 +81,232 @@ discard block |
||
81 | 81 | */ |
82 | 82 | |
83 | 83 | /** |
84 | - * Get the item name. |
|
85 | - * |
|
86 | - * @since 1.0.19 |
|
87 | - * @param string $context View or edit context. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the item name without a suffix. |
|
97 | - * |
|
98 | - * @since 1.0.19 |
|
99 | - * @param string $context View or edit context. |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function get_raw_name( $context = 'view' ) { |
|
103 | - return parent::get_name( $context ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Get the item description. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @param string $context View or edit context. |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get_description( $context = 'view' ) { |
|
114 | - |
|
115 | - if ( isset( $this->custom_description ) ) { |
|
116 | - return $this->custom_description; |
|
117 | - } |
|
118 | - |
|
119 | - return parent::get_description( $context ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the sub total. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - * @param string $context View or edit context. |
|
127 | - * @return float |
|
128 | - */ |
|
129 | - public function get_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the recurring sub total. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * @param string $context View or edit context. |
|
138 | - * @return float |
|
139 | - */ |
|
140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | - |
|
142 | - if ( $this->is_recurring() ) { |
|
143 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | - } |
|
145 | - |
|
146 | - return 0; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @deprecated |
|
151 | - */ |
|
152 | - public function get_qantity( $context = 'view' ) { |
|
153 | - return $this->get_quantity( $context ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get the item quantity. |
|
158 | - * |
|
159 | - * @since 1.0.19 |
|
160 | - * @param string $context View or edit context. |
|
161 | - * @return int |
|
162 | - */ |
|
163 | - public function get_quantity( $context = 'view' ) { |
|
164 | - $quantity = (int) $this->quantity; |
|
165 | - |
|
166 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | - $quantity = 1; |
|
168 | - } |
|
169 | - |
|
170 | - if ( 'view' == $context ) { |
|
171 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | - } |
|
173 | - |
|
174 | - return $quantity; |
|
175 | - |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Get the item meta data. |
|
180 | - * |
|
181 | - * @since 1.0.19 |
|
182 | - * @param string $context View or edit context. |
|
183 | - * @return meta |
|
184 | - */ |
|
185 | - public function get_item_meta( $context = 'view' ) { |
|
186 | - $meta = $this->meta; |
|
187 | - |
|
188 | - if ( 'view' == $context ) { |
|
189 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | - } |
|
191 | - |
|
192 | - return $meta; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Returns whether or not customers can update the item quantity. |
|
198 | - * |
|
199 | - * @since 1.0.19 |
|
200 | - * @param string $context View or edit context. |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function get_allow_quantities( $context = 'view' ) { |
|
204 | - $allow_quantities = (bool) $this->allow_quantities; |
|
205 | - |
|
206 | - if ( 'view' == $context ) { |
|
207 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | - } |
|
209 | - |
|
210 | - return $allow_quantities; |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Returns whether or not the item is required. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public function get_is_required( $context = 'view' ) { |
|
222 | - $is_required = (bool) $this->is_required; |
|
223 | - |
|
224 | - if ( 'view' == $context ) { |
|
225 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | - } |
|
227 | - |
|
228 | - return $is_required; |
|
229 | - |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Prepares form data for use. |
|
234 | - * |
|
235 | - * @since 1.0.19 |
|
236 | - * @return array |
|
237 | - */ |
|
238 | - public function prepare_data_for_use( $required = null ) { |
|
239 | - |
|
240 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | - return array( |
|
242 | - 'title' => strip_tags( $this->get_name() ), |
|
243 | - 'id' => $this->get_id(), |
|
244 | - 'price' => $this->get_price(), |
|
245 | - 'recurring' => $this->is_recurring(), |
|
246 | - 'description' => $this->get_description(), |
|
247 | - 'allow_quantities' => $this->allows_quantities(), |
|
248 | - 'required' => $required, |
|
249 | - ); |
|
250 | - |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Prepares form data for ajax use. |
|
255 | - * |
|
256 | - * @since 1.0.19 |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - public function prepare_data_for_invoice_edit_ajax( $currency = '' ) { |
|
260 | - |
|
261 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | - |
|
263 | - if ( $description ) { |
|
264 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | - } |
|
266 | - |
|
267 | - return array( |
|
268 | - 'id' => $this->get_id(), |
|
269 | - 'texts' => array( |
|
270 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
271 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
272 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
273 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ), |
|
274 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ), |
|
275 | - ), |
|
276 | - 'inputs' => array( |
|
277 | - 'item-id' => $this->get_id(), |
|
278 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
279 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
280 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
281 | - 'item-price' => $this->get_price(), |
|
282 | - ) |
|
283 | - ); |
|
284 | - |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Prepares form data for saving (cart_details). |
|
289 | - * |
|
290 | - * @since 1.0.19 |
|
291 | - * @return array |
|
292 | - */ |
|
293 | - public function prepare_data_for_saving() { |
|
294 | - |
|
295 | - return array( |
|
296 | - 'post_id' => $this->invoice_id, |
|
297 | - 'item_id' => $this->get_id(), |
|
298 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
299 | - 'item_description' => $this->get_description(), |
|
300 | - 'tax' => $this->item_tax, |
|
301 | - 'item_price' => $this->get_price(), |
|
302 | - 'quantity' => (int) $this->get_quantity(), |
|
303 | - 'discount' => $this->item_discount, |
|
304 | - 'subtotal' => $this->get_sub_total(), |
|
305 | - 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
306 | - 'meta' => $this->get_item_meta(), |
|
307 | - ); |
|
308 | - |
|
309 | - } |
|
84 | + * Get the item name. |
|
85 | + * |
|
86 | + * @since 1.0.19 |
|
87 | + * @param string $context View or edit context. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function get_name( $context = 'view' ) { |
|
91 | + $name = parent::get_name( $context ); |
|
92 | + return $name . wpinv_get_item_suffix( $this ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the item name without a suffix. |
|
97 | + * |
|
98 | + * @since 1.0.19 |
|
99 | + * @param string $context View or edit context. |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function get_raw_name( $context = 'view' ) { |
|
103 | + return parent::get_name( $context ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Get the item description. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @param string $context View or edit context. |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get_description( $context = 'view' ) { |
|
114 | + |
|
115 | + if ( isset( $this->custom_description ) ) { |
|
116 | + return $this->custom_description; |
|
117 | + } |
|
118 | + |
|
119 | + return parent::get_description( $context ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the sub total. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + * @param string $context View or edit context. |
|
127 | + * @return float |
|
128 | + */ |
|
129 | + public function get_sub_total( $context = 'view' ) { |
|
130 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the recurring sub total. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * @param string $context View or edit context. |
|
138 | + * @return float |
|
139 | + */ |
|
140 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | + |
|
142 | + if ( $this->is_recurring() ) { |
|
143 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | + } |
|
145 | + |
|
146 | + return 0; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @deprecated |
|
151 | + */ |
|
152 | + public function get_qantity( $context = 'view' ) { |
|
153 | + return $this->get_quantity( $context ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get the item quantity. |
|
158 | + * |
|
159 | + * @since 1.0.19 |
|
160 | + * @param string $context View or edit context. |
|
161 | + * @return int |
|
162 | + */ |
|
163 | + public function get_quantity( $context = 'view' ) { |
|
164 | + $quantity = (int) $this->quantity; |
|
165 | + |
|
166 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | + $quantity = 1; |
|
168 | + } |
|
169 | + |
|
170 | + if ( 'view' == $context ) { |
|
171 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | + } |
|
173 | + |
|
174 | + return $quantity; |
|
175 | + |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Get the item meta data. |
|
180 | + * |
|
181 | + * @since 1.0.19 |
|
182 | + * @param string $context View or edit context. |
|
183 | + * @return meta |
|
184 | + */ |
|
185 | + public function get_item_meta( $context = 'view' ) { |
|
186 | + $meta = $this->meta; |
|
187 | + |
|
188 | + if ( 'view' == $context ) { |
|
189 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | + } |
|
191 | + |
|
192 | + return $meta; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Returns whether or not customers can update the item quantity. |
|
198 | + * |
|
199 | + * @since 1.0.19 |
|
200 | + * @param string $context View or edit context. |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function get_allow_quantities( $context = 'view' ) { |
|
204 | + $allow_quantities = (bool) $this->allow_quantities; |
|
205 | + |
|
206 | + if ( 'view' == $context ) { |
|
207 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | + } |
|
209 | + |
|
210 | + return $allow_quantities; |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Returns whether or not the item is required. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public function get_is_required( $context = 'view' ) { |
|
222 | + $is_required = (bool) $this->is_required; |
|
223 | + |
|
224 | + if ( 'view' == $context ) { |
|
225 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | + } |
|
227 | + |
|
228 | + return $is_required; |
|
229 | + |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Prepares form data for use. |
|
234 | + * |
|
235 | + * @since 1.0.19 |
|
236 | + * @return array |
|
237 | + */ |
|
238 | + public function prepare_data_for_use( $required = null ) { |
|
239 | + |
|
240 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | + return array( |
|
242 | + 'title' => strip_tags( $this->get_name() ), |
|
243 | + 'id' => $this->get_id(), |
|
244 | + 'price' => $this->get_price(), |
|
245 | + 'recurring' => $this->is_recurring(), |
|
246 | + 'description' => $this->get_description(), |
|
247 | + 'allow_quantities' => $this->allows_quantities(), |
|
248 | + 'required' => $required, |
|
249 | + ); |
|
250 | + |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Prepares form data for ajax use. |
|
255 | + * |
|
256 | + * @since 1.0.19 |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + public function prepare_data_for_invoice_edit_ajax( $currency = '' ) { |
|
260 | + |
|
261 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | + |
|
263 | + if ( $description ) { |
|
264 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | + } |
|
266 | + |
|
267 | + return array( |
|
268 | + 'id' => $this->get_id(), |
|
269 | + 'texts' => array( |
|
270 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
271 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
272 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
273 | + 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ), |
|
274 | + 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ), |
|
275 | + ), |
|
276 | + 'inputs' => array( |
|
277 | + 'item-id' => $this->get_id(), |
|
278 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
279 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
280 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
281 | + 'item-price' => $this->get_price(), |
|
282 | + ) |
|
283 | + ); |
|
284 | + |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Prepares form data for saving (cart_details). |
|
289 | + * |
|
290 | + * @since 1.0.19 |
|
291 | + * @return array |
|
292 | + */ |
|
293 | + public function prepare_data_for_saving() { |
|
294 | + |
|
295 | + return array( |
|
296 | + 'post_id' => $this->invoice_id, |
|
297 | + 'item_id' => $this->get_id(), |
|
298 | + 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
299 | + 'item_description' => $this->get_description(), |
|
300 | + 'tax' => $this->item_tax, |
|
301 | + 'item_price' => $this->get_price(), |
|
302 | + 'quantity' => (int) $this->get_quantity(), |
|
303 | + 'discount' => $this->item_discount, |
|
304 | + 'subtotal' => $this->get_sub_total(), |
|
305 | + 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
306 | + 'meta' => $this->get_item_meta(), |
|
307 | + ); |
|
308 | + |
|
309 | + } |
|
310 | 310 | |
311 | 311 | /* |
312 | 312 | |-------------------------------------------------------------------------- |
@@ -318,70 +318,70 @@ discard block |
||
318 | 318 | | object. |
319 | 319 | */ |
320 | 320 | |
321 | - /** |
|
322 | - * Set the item qantity. |
|
323 | - * |
|
324 | - * @since 1.0.19 |
|
325 | - * @param int $quantity The item quantity. |
|
326 | - */ |
|
327 | - public function set_quantity( $quantity ) { |
|
328 | - |
|
329 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
330 | - $quantity = 1; |
|
331 | - } |
|
332 | - |
|
333 | - $this->quantity = (int) $quantity; |
|
334 | - |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Set the item meta data. |
|
339 | - * |
|
340 | - * @since 1.0.19 |
|
341 | - * @param array $meta The item meta data. |
|
342 | - */ |
|
343 | - public function set_item_meta( $meta ) { |
|
344 | - $this->meta = maybe_unserialize( $meta ); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Set whether or not the quantities are allowed. |
|
349 | - * |
|
350 | - * @since 1.0.19 |
|
351 | - * @param bool $allow_quantities |
|
352 | - */ |
|
353 | - public function set_allow_quantities( $allow_quantities ) { |
|
354 | - $this->allow_quantities = (bool) $allow_quantities; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Set whether or not the item is required. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param bool $is_required |
|
362 | - */ |
|
363 | - public function set_is_required( $is_required ) { |
|
364 | - $this->is_required = (bool) $is_required; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Sets the custom item description. |
|
369 | - * |
|
370 | - * @since 1.0.19 |
|
371 | - * @param string $description |
|
372 | - */ |
|
373 | - public function set_custom_description( $description ) { |
|
374 | - $this->custom_description = $description; |
|
375 | - } |
|
321 | + /** |
|
322 | + * Set the item qantity. |
|
323 | + * |
|
324 | + * @since 1.0.19 |
|
325 | + * @param int $quantity The item quantity. |
|
326 | + */ |
|
327 | + public function set_quantity( $quantity ) { |
|
328 | + |
|
329 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
330 | + $quantity = 1; |
|
331 | + } |
|
332 | + |
|
333 | + $this->quantity = (int) $quantity; |
|
334 | + |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Set the item meta data. |
|
339 | + * |
|
340 | + * @since 1.0.19 |
|
341 | + * @param array $meta The item meta data. |
|
342 | + */ |
|
343 | + public function set_item_meta( $meta ) { |
|
344 | + $this->meta = maybe_unserialize( $meta ); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Set whether or not the quantities are allowed. |
|
349 | + * |
|
350 | + * @since 1.0.19 |
|
351 | + * @param bool $allow_quantities |
|
352 | + */ |
|
353 | + public function set_allow_quantities( $allow_quantities ) { |
|
354 | + $this->allow_quantities = (bool) $allow_quantities; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Set whether or not the item is required. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param bool $is_required |
|
362 | + */ |
|
363 | + public function set_is_required( $is_required ) { |
|
364 | + $this->is_required = (bool) $is_required; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Sets the custom item description. |
|
369 | + * |
|
370 | + * @since 1.0.19 |
|
371 | + * @param string $description |
|
372 | + */ |
|
373 | + public function set_custom_description( $description ) { |
|
374 | + $this->custom_description = $description; |
|
375 | + } |
|
376 | 376 | |
377 | 377 | /** |
378 | 378 | * We do not want to save items to the database. |
379 | 379 | * |
380 | - * @return int item id |
|
380 | + * @return int item id |
|
381 | 381 | */ |
382 | 382 | public function save( $data = array() ) { |
383 | 383 | return $this->get_id(); |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | /* |
387 | 387 | |-------------------------------------------------------------------------- |
@@ -393,23 +393,23 @@ discard block |
||
393 | 393 | */ |
394 | 394 | |
395 | 395 | /** |
396 | - * Checks whether the item has enabled dynamic pricing. |
|
397 | - * |
|
398 | - * @since 1.0.19 |
|
399 | - * @return bool |
|
400 | - */ |
|
401 | - public function is_required() { |
|
396 | + * Checks whether the item has enabled dynamic pricing. |
|
397 | + * |
|
398 | + * @since 1.0.19 |
|
399 | + * @return bool |
|
400 | + */ |
|
401 | + public function is_required() { |
|
402 | 402 | return (bool) $this->get_is_required(); |
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Checks whether users can edit the quantities. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @return bool |
|
410 | - */ |
|
411 | - public function allows_quantities() { |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Checks whether users can edit the quantities. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @return bool |
|
410 | + */ |
|
411 | + public function allows_quantities() { |
|
412 | 412 | return (bool) $this->get_allow_quantities(); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | 415 | } |
@@ -232,26 +232,26 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
235 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
235 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
236 | 236 | |
237 | 237 | $chosen = false; |
238 | 238 | if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
239 | 239 | $chosen = $invoice->get_gateway(); |
240 | 240 | } |
241 | 241 | |
242 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
242 | + $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
243 | 243 | |
244 | - if ( false !== $chosen ) { |
|
245 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | - } |
|
244 | + if ( false !== $chosen ) { |
|
245 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | + } |
|
247 | 247 | |
248 | - if ( ! empty ( $chosen ) ) { |
|
249 | - $enabled_gateway = urldecode( $chosen ); |
|
250 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | - $enabled_gateway = 'manual'; |
|
252 | - } else { |
|
253 | - $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | - } |
|
248 | + if ( ! empty ( $chosen ) ) { |
|
249 | + $enabled_gateway = urldecode( $chosen ); |
|
250 | + } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | + $enabled_gateway = 'manual'; |
|
252 | + } else { |
|
253 | + $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
257 | 257 | if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
265 | + return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_record_gateway_error( $title = '', $message = '' ) { |
@@ -270,21 +270,21 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
273 | - $ret = 0; |
|
274 | - $args = array( |
|
275 | - 'meta_key' => '_wpinv_gateway', |
|
276 | - 'meta_value' => $gateway_id, |
|
277 | - 'nopaging' => true, |
|
278 | - 'post_type' => 'wpi_invoice', |
|
279 | - 'post_status' => $status, |
|
280 | - 'fields' => 'ids' |
|
281 | - ); |
|
282 | - |
|
283 | - $payments = new WP_Query( $args ); |
|
284 | - |
|
285 | - if( $payments ) |
|
286 | - $ret = $payments->post_count; |
|
287 | - return $ret; |
|
273 | + $ret = 0; |
|
274 | + $args = array( |
|
275 | + 'meta_key' => '_wpinv_gateway', |
|
276 | + 'meta_value' => $gateway_id, |
|
277 | + 'nopaging' => true, |
|
278 | + 'post_type' => 'wpi_invoice', |
|
279 | + 'post_status' => $status, |
|
280 | + 'fields' => 'ids' |
|
281 | + ); |
|
282 | + |
|
283 | + $payments = new WP_Query( $args ); |
|
284 | + |
|
285 | + if( $payments ) |
|
286 | + $ret = $payments->post_count; |
|
287 | + return $ret; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | function wpinv_settings_update_gateways( $input ) { |
@@ -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' ); |
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_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $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 = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
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 = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
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' => (int) $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' => (int) $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 = wpinv_get_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 |
@@ -12,216 +12,216 @@ |
||
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 | - ), |
|
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 | + ), |
|
62 | 62 | |
63 | - 'recurring' => array( |
|
64 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
65 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
66 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
67 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
68 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
69 | - ), |
|
63 | + 'recurring' => array( |
|
64 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
65 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
66 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
67 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
68 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
69 | + ), |
|
70 | 70 | |
71 | - ) |
|
72 | - ); |
|
71 | + ) |
|
72 | + ); |
|
73 | 73 | |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Adds texts to a response for submission refresh prices. |
|
78 | - * |
|
79 | - * @param GetPaid_Payment_Form_Submission $submission |
|
80 | - */ |
|
81 | - public function add_texts( $submission ) { |
|
76 | + /** |
|
77 | + * Adds texts to a response for submission refresh prices. |
|
78 | + * |
|
79 | + * @param GetPaid_Payment_Form_Submission $submission |
|
80 | + */ |
|
81 | + public function add_texts( $submission ) { |
|
82 | 82 | |
83 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
83 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
84 | 84 | |
85 | - if ( $submission->has_recurring != 0 ) { |
|
85 | + if ( $submission->has_recurring != 0 ) { |
|
86 | 86 | |
87 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
88 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
87 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
88 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
89 | 89 | |
90 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
91 | - $payable = "$payable / $period"; |
|
92 | - } else { |
|
93 | - $payable = sprintf( |
|
94 | - __( '%1$s (renews at %2$s / %3$s)'), |
|
95 | - $submission->format_amount( $submission->get_total() ), |
|
96 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
97 | - $period |
|
98 | - ); |
|
99 | - } |
|
90 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
91 | + $payable = "$payable / $period"; |
|
92 | + } else { |
|
93 | + $payable = sprintf( |
|
94 | + __( '%1$s (renews at %2$s / %3$s)'), |
|
95 | + $submission->format_amount( $submission->get_total() ), |
|
96 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
97 | + $period |
|
98 | + ); |
|
99 | + } |
|
100 | 100 | |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | - $texts = array( |
|
104 | - '.getpaid-checkout-total-payable' => $payable, |
|
105 | - ); |
|
103 | + $texts = array( |
|
104 | + '.getpaid-checkout-total-payable' => $payable, |
|
105 | + ); |
|
106 | 106 | |
107 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
108 | - $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
109 | - $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
110 | - } |
|
107 | + foreach ( $submission->get_items() as $item_id => $item ) { |
|
108 | + $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
109 | + $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
110 | + } |
|
111 | 111 | |
112 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
112 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
113 | 113 | |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Adds items to a response for submission refresh prices. |
|
118 | - * |
|
119 | - * @param GetPaid_Payment_Form_Submission $submission |
|
120 | - */ |
|
121 | - public function add_items( $submission ) { |
|
116 | + /** |
|
117 | + * Adds items to a response for submission refresh prices. |
|
118 | + * |
|
119 | + * @param GetPaid_Payment_Form_Submission $submission |
|
120 | + */ |
|
121 | + public function add_items( $submission ) { |
|
122 | 122 | |
123 | - // Add items. |
|
124 | - $items = array(); |
|
123 | + // Add items. |
|
124 | + $items = array(); |
|
125 | 125 | |
126 | 126 | foreach ( $submission->get_items() as $item_id => $item ) { |
127 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
128 | - } |
|
127 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
128 | + } |
|
129 | 129 | |
130 | - $this->response = array_merge( |
|
131 | - $this->response, |
|
132 | - array( 'items' => $items ) |
|
133 | - ); |
|
130 | + $this->response = array_merge( |
|
131 | + $this->response, |
|
132 | + array( 'items' => $items ) |
|
133 | + ); |
|
134 | 134 | |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Adds fees to a response for submission refresh prices. |
|
139 | - * |
|
140 | - * @param GetPaid_Payment_Form_Submission $submission |
|
141 | - */ |
|
142 | - public function add_fees( $submission ) { |
|
137 | + /** |
|
138 | + * Adds fees to a response for submission refresh prices. |
|
139 | + * |
|
140 | + * @param GetPaid_Payment_Form_Submission $submission |
|
141 | + */ |
|
142 | + public function add_fees( $submission ) { |
|
143 | 143 | |
144 | - $fees = array(); |
|
144 | + $fees = array(); |
|
145 | 145 | |
146 | 146 | foreach ( $submission->get_fees() as $name => $data ) { |
147 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
148 | - } |
|
147 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
148 | + } |
|
149 | 149 | |
150 | - $this->response = array_merge( |
|
151 | - $this->response, |
|
152 | - array( 'fees' => $fees ) |
|
153 | - ); |
|
150 | + $this->response = array_merge( |
|
151 | + $this->response, |
|
152 | + array( 'fees' => $fees ) |
|
153 | + ); |
|
154 | 154 | |
155 | - } |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * Adds discounts to a response for submission refresh prices. |
|
159 | - * |
|
160 | - * @param GetPaid_Payment_Form_Submission $submission |
|
161 | - */ |
|
162 | - public function add_discounts( $submission ) { |
|
157 | + /** |
|
158 | + * Adds discounts to a response for submission refresh prices. |
|
159 | + * |
|
160 | + * @param GetPaid_Payment_Form_Submission $submission |
|
161 | + */ |
|
162 | + public function add_discounts( $submission ) { |
|
163 | 163 | |
164 | - $discounts = array(); |
|
164 | + $discounts = array(); |
|
165 | 165 | |
166 | 166 | foreach ( $submission->get_discounts() as $name => $data ) { |
167 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
168 | - } |
|
167 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
168 | + } |
|
169 | 169 | |
170 | - $this->response = array_merge( |
|
171 | - $this->response, |
|
172 | - array( 'discounts' => $discounts ) |
|
173 | - ); |
|
170 | + $this->response = array_merge( |
|
171 | + $this->response, |
|
172 | + array( 'discounts' => $discounts ) |
|
173 | + ); |
|
174 | 174 | |
175 | - } |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Adds taxes to a response for submission refresh prices. |
|
179 | - * |
|
180 | - * @param GetPaid_Payment_Form_Submission $submission |
|
181 | - */ |
|
182 | - public function add_taxes( $submission ) { |
|
177 | + /** |
|
178 | + * Adds taxes to a response for submission refresh prices. |
|
179 | + * |
|
180 | + * @param GetPaid_Payment_Form_Submission $submission |
|
181 | + */ |
|
182 | + public function add_taxes( $submission ) { |
|
183 | 183 | |
184 | - $taxes = array(); |
|
184 | + $taxes = array(); |
|
185 | 185 | |
186 | 186 | foreach ( $submission->get_taxes() as $name => $data ) { |
187 | - $taxes[$name] = $submission->format_amount( $data['initial_tax'] ); |
|
188 | - } |
|
187 | + $taxes[$name] = $submission->format_amount( $data['initial_tax'] ); |
|
188 | + } |
|
189 | 189 | |
190 | - $this->response = array_merge( |
|
191 | - $this->response, |
|
192 | - array( 'taxes' => $taxes ) |
|
193 | - ); |
|
190 | + $this->response = array_merge( |
|
191 | + $this->response, |
|
192 | + array( 'taxes' => $taxes ) |
|
193 | + ); |
|
194 | 194 | |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Adds gateways to a response for submission refresh prices. |
|
199 | - * |
|
200 | - * @param GetPaid_Payment_Form_Submission $submission |
|
201 | - */ |
|
202 | - public function add_gateways( $submission ) { |
|
197 | + /** |
|
198 | + * Adds gateways to a response for submission refresh prices. |
|
199 | + * |
|
200 | + * @param GetPaid_Payment_Form_Submission $submission |
|
201 | + */ |
|
202 | + public function add_gateways( $submission ) { |
|
203 | 203 | |
204 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
204 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
205 | 205 | |
206 | - if ( $this->response['has_recurring'] ) { |
|
206 | + if ( $this->response['has_recurring'] ) { |
|
207 | 207 | |
208 | - foreach ( $gateways as $i => $gateway ) { |
|
208 | + foreach ( $gateways as $i => $gateway ) { |
|
209 | 209 | |
210 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
211 | - unset( $gateways[ $i ] ); |
|
212 | - } |
|
210 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
211 | + unset( $gateways[ $i ] ); |
|
212 | + } |
|
213 | 213 | |
214 | - } |
|
214 | + } |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
220 | - $this->response = array_merge( |
|
221 | - $this->response, |
|
222 | - array( 'gateways' => $gateways ) |
|
223 | - ); |
|
219 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
220 | + $this->response = array_merge( |
|
221 | + $this->response, |
|
222 | + array( 'gateways' => $gateways ) |
|
223 | + ); |
|
224 | 224 | |
225 | - } |
|
225 | + } |
|
226 | 226 | |
227 | 227 | } |
@@ -13,450 +13,450 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Enable Subscriptions. |
|
147 | - if ( $this->supports( 'subscription' ) ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
149 | - } |
|
150 | - |
|
151 | - // Enable sandbox. |
|
152 | - if ( $this->supports( 'sandbox' ) ) { |
|
153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
154 | - } |
|
155 | - |
|
156 | - // Gateway settings. |
|
157 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Enable Subscriptions. |
|
147 | + if ( $this->supports( 'subscription' ) ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
149 | + } |
|
150 | + |
|
151 | + // Enable sandbox. |
|
152 | + if ( $this->supports( 'sandbox' ) ) { |
|
153 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
154 | + } |
|
155 | + |
|
156 | + // Gateway settings. |
|
157 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
158 | 158 | |
159 | 159 | |
160 | - // Gateway checkout fiellds. |
|
161 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | - |
|
163 | - // Process payment. |
|
164 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
160 | + // Gateway checkout fiellds. |
|
161 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | + |
|
163 | + // Process payment. |
|
164 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
165 | + |
|
166 | + // Change the checkout button text. |
|
167 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
168 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
169 | + } |
|
170 | + |
|
171 | + // Check if a gateway is valid for a given currency. |
|
172 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | + |
|
174 | + // Generate the transaction url. |
|
175 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | + |
|
177 | + // Generate the subscription url. |
|
178 | + add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
179 | + |
|
180 | + // Confirm payments. |
|
181 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | + |
|
183 | + // Verify IPNs. |
|
184 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | + |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Checks if this gateway is a given gateway. |
|
190 | + * |
|
191 | + * @since 1.0.19 |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + public function is( $gateway ) { |
|
195 | + return $gateway == $this->id; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Returns a users saved tokens for this gateway. |
|
200 | + * |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function get_tokens( $sandbox = null ) { |
|
205 | + |
|
206 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
207 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
208 | + |
|
209 | + if ( is_array( $tokens ) ) { |
|
210 | + $this->tokens = $tokens; |
|
211 | + } |
|
212 | + |
|
213 | + } |
|
214 | + |
|
215 | + if ( ! is_bool( $sandbox ) ) { |
|
216 | + return $this->tokens; |
|
217 | + } |
|
218 | + |
|
219 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
220 | + return wp_list_filter( $this->tokens, $args ); |
|
221 | + |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Saves a token for this gateway. |
|
226 | + * |
|
227 | + * @since 1.0.19 |
|
228 | + */ |
|
229 | + public function save_token( $token ) { |
|
230 | + |
|
231 | + $tokens = $this->get_tokens(); |
|
232 | + $tokens[] = $token; |
|
233 | + |
|
234 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
235 | + |
|
236 | + $this->tokens = $tokens; |
|
237 | + |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Return the title for admin screens. |
|
242 | + * |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + public function get_method_title() { |
|
246 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Return the description for admin screens. |
|
251 | + * |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public function get_method_description() { |
|
255 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Get the success url. |
|
260 | + * |
|
261 | + * @param WPInv_Invoice $invoice Invoice object. |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function get_return_url( $invoice ) { |
|
265 | + |
|
266 | + // Payment success url |
|
267 | + $return_url = add_query_arg( |
|
268 | + array( |
|
269 | + 'payment-confirm' => $this->id, |
|
270 | + 'invoice_key' => $invoice->get_key(), |
|
271 | + 'utm_nooverride' => 1 |
|
272 | + ), |
|
273 | + wpinv_get_success_page_uri() |
|
274 | + ); |
|
275 | + |
|
276 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Confirms payments when rendering the success page. |
|
281 | + * |
|
282 | + * @param string $content Success page content. |
|
283 | + * @return string |
|
284 | + */ |
|
285 | + public function confirm_payment( $content ) { |
|
286 | + |
|
287 | + // Retrieve the invoice. |
|
288 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
289 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
290 | + |
|
291 | + // Ensure that it exists and that it is pending payment. |
|
292 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
293 | + return $content; |
|
294 | + } |
|
295 | + |
|
296 | + // Can the user view this invoice?? |
|
297 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
298 | + return $content; |
|
299 | + } |
|
300 | + |
|
301 | + // Show payment processing indicator. |
|
302 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Processes ipns and marks payments as complete. |
|
307 | + * |
|
308 | + * @return void |
|
309 | + */ |
|
310 | + public function verify_ipn() {} |
|
311 | + |
|
312 | + /** |
|
313 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
314 | + * |
|
315 | + * @param string $transaction_url transaction url. |
|
316 | + * @param WPInv_Invoice $invoice Invoice object. |
|
317 | + * @return string transaction URL, or empty string. |
|
318 | + */ |
|
319 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
320 | + |
|
321 | + $transaction_id = $invoice->get_transaction_id(); |
|
322 | + |
|
323 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
324 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
325 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
326 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
327 | + } |
|
328 | + |
|
329 | + return $transaction_url; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
334 | + * |
|
335 | + * @param string $subscription_url transaction url. |
|
336 | + * @param WPInv_Invoice $invoice Invoice object. |
|
337 | + * @return string subscription URL, or empty string. |
|
338 | + */ |
|
339 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
340 | + |
|
341 | + $profile_id = $invoice->get_subscription_id(); |
|
342 | + |
|
343 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
344 | + |
|
345 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
346 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
347 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
348 | + |
|
349 | + } |
|
350 | + |
|
351 | + return $subscription_url; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Check if the gateway is available for use. |
|
356 | + * |
|
357 | + * @return bool |
|
358 | + */ |
|
359 | + public function is_available() { |
|
360 | + return ! empty( $this->enabled ); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Return the gateway's title. |
|
365 | + * |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public function get_title() { |
|
369 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Return the gateway's description. |
|
374 | + * |
|
375 | + * @return string |
|
376 | + */ |
|
377 | + public function get_description() { |
|
378 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Process Payment. |
|
383 | + * |
|
384 | + * |
|
385 | + * @param WPInv_Invoice $invoice Invoice. |
|
386 | + * @param array $submission_data Posted checkout fields. |
|
387 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
388 | + * @return void |
|
389 | + */ |
|
390 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
391 | + // Process the payment then either redirect to the success page or the gateway. |
|
392 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Process refund. |
|
397 | + * |
|
398 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
399 | + * a passed in amount. |
|
400 | + * |
|
401 | + * @param WPInv_Invoice $invoice Invoice. |
|
402 | + * @param float $amount Refund amount. |
|
403 | + * @param string $reason Refund reason. |
|
404 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
405 | + */ |
|
406 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
407 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Displays the payment fields, credit cards etc. |
|
412 | + * |
|
413 | + * @param int $invoice_id 0 or invoice id. |
|
414 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
415 | + */ |
|
416 | + public function payment_fields( $invoice_id, $form ) { |
|
417 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Filters the gateway settings. |
|
422 | + * |
|
423 | + * @param array $admin_settings |
|
424 | + */ |
|
425 | + public function admin_settings( $admin_settings ) { |
|
426 | + return $admin_settings; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Retrieves the value of a gateway setting. |
|
431 | + * |
|
432 | + * @param string $option |
|
433 | + */ |
|
434 | + public function get_option( $option, $default = false ) { |
|
435 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Check if a gateway supports a given feature. |
|
440 | + * |
|
441 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
442 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
443 | + * |
|
444 | + * @param string $feature string The name of a feature to test support for. |
|
445 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
446 | + * @since 1.0.19 |
|
447 | + */ |
|
448 | + public function supports( $feature ) { |
|
449 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
450 | + } |
|
165 | 451 | |
166 | - // Change the checkout button text. |
|
167 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
168 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
169 | - } |
|
170 | - |
|
171 | - // Check if a gateway is valid for a given currency. |
|
172 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | - |
|
174 | - // Generate the transaction url. |
|
175 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | - |
|
177 | - // Generate the subscription url. |
|
178 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
179 | - |
|
180 | - // Confirm payments. |
|
181 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | - |
|
183 | - // Verify IPNs. |
|
184 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | - |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Checks if this gateway is a given gateway. |
|
190 | - * |
|
191 | - * @since 1.0.19 |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - public function is( $gateway ) { |
|
195 | - return $gateway == $this->id; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Returns a users saved tokens for this gateway. |
|
200 | - * |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function get_tokens( $sandbox = null ) { |
|
205 | - |
|
206 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
207 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
208 | - |
|
209 | - if ( is_array( $tokens ) ) { |
|
210 | - $this->tokens = $tokens; |
|
211 | - } |
|
212 | - |
|
213 | - } |
|
214 | - |
|
215 | - if ( ! is_bool( $sandbox ) ) { |
|
216 | - return $this->tokens; |
|
217 | - } |
|
218 | - |
|
219 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
220 | - return wp_list_filter( $this->tokens, $args ); |
|
221 | - |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Saves a token for this gateway. |
|
226 | - * |
|
227 | - * @since 1.0.19 |
|
228 | - */ |
|
229 | - public function save_token( $token ) { |
|
230 | - |
|
231 | - $tokens = $this->get_tokens(); |
|
232 | - $tokens[] = $token; |
|
233 | - |
|
234 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
235 | - |
|
236 | - $this->tokens = $tokens; |
|
237 | - |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Return the title for admin screens. |
|
242 | - * |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - public function get_method_title() { |
|
246 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Return the description for admin screens. |
|
251 | - * |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public function get_method_description() { |
|
255 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Get the success url. |
|
260 | - * |
|
261 | - * @param WPInv_Invoice $invoice Invoice object. |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function get_return_url( $invoice ) { |
|
265 | - |
|
266 | - // Payment success url |
|
267 | - $return_url = add_query_arg( |
|
268 | - array( |
|
269 | - 'payment-confirm' => $this->id, |
|
270 | - 'invoice_key' => $invoice->get_key(), |
|
271 | - 'utm_nooverride' => 1 |
|
272 | - ), |
|
273 | - wpinv_get_success_page_uri() |
|
274 | - ); |
|
275 | - |
|
276 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Confirms payments when rendering the success page. |
|
281 | - * |
|
282 | - * @param string $content Success page content. |
|
283 | - * @return string |
|
284 | - */ |
|
285 | - public function confirm_payment( $content ) { |
|
286 | - |
|
287 | - // Retrieve the invoice. |
|
288 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
289 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
290 | - |
|
291 | - // Ensure that it exists and that it is pending payment. |
|
292 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
293 | - return $content; |
|
294 | - } |
|
295 | - |
|
296 | - // Can the user view this invoice?? |
|
297 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
298 | - return $content; |
|
299 | - } |
|
300 | - |
|
301 | - // Show payment processing indicator. |
|
302 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Processes ipns and marks payments as complete. |
|
307 | - * |
|
308 | - * @return void |
|
309 | - */ |
|
310 | - public function verify_ipn() {} |
|
311 | - |
|
312 | - /** |
|
313 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
314 | - * |
|
315 | - * @param string $transaction_url transaction url. |
|
316 | - * @param WPInv_Invoice $invoice Invoice object. |
|
317 | - * @return string transaction URL, or empty string. |
|
318 | - */ |
|
319 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
320 | - |
|
321 | - $transaction_id = $invoice->get_transaction_id(); |
|
322 | - |
|
323 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
324 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
325 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
326 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
327 | - } |
|
328 | - |
|
329 | - return $transaction_url; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
334 | - * |
|
335 | - * @param string $subscription_url transaction url. |
|
336 | - * @param WPInv_Invoice $invoice Invoice object. |
|
337 | - * @return string subscription URL, or empty string. |
|
338 | - */ |
|
339 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
340 | - |
|
341 | - $profile_id = $invoice->get_subscription_id(); |
|
342 | - |
|
343 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
344 | - |
|
345 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
346 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
347 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
348 | - |
|
349 | - } |
|
350 | - |
|
351 | - return $subscription_url; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Check if the gateway is available for use. |
|
356 | - * |
|
357 | - * @return bool |
|
358 | - */ |
|
359 | - public function is_available() { |
|
360 | - return ! empty( $this->enabled ); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Return the gateway's title. |
|
365 | - * |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public function get_title() { |
|
369 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Return the gateway's description. |
|
374 | - * |
|
375 | - * @return string |
|
376 | - */ |
|
377 | - public function get_description() { |
|
378 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Process Payment. |
|
383 | - * |
|
384 | - * |
|
385 | - * @param WPInv_Invoice $invoice Invoice. |
|
386 | - * @param array $submission_data Posted checkout fields. |
|
387 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
388 | - * @return void |
|
389 | - */ |
|
390 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
391 | - // Process the payment then either redirect to the success page or the gateway. |
|
392 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Process refund. |
|
397 | - * |
|
398 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
399 | - * a passed in amount. |
|
400 | - * |
|
401 | - * @param WPInv_Invoice $invoice Invoice. |
|
402 | - * @param float $amount Refund amount. |
|
403 | - * @param string $reason Refund reason. |
|
404 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
405 | - */ |
|
406 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
407 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Displays the payment fields, credit cards etc. |
|
412 | - * |
|
413 | - * @param int $invoice_id 0 or invoice id. |
|
414 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
415 | - */ |
|
416 | - public function payment_fields( $invoice_id, $form ) { |
|
417 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Filters the gateway settings. |
|
422 | - * |
|
423 | - * @param array $admin_settings |
|
424 | - */ |
|
425 | - public function admin_settings( $admin_settings ) { |
|
426 | - return $admin_settings; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Retrieves the value of a gateway setting. |
|
431 | - * |
|
432 | - * @param string $option |
|
433 | - */ |
|
434 | - public function get_option( $option, $default = false ) { |
|
435 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Check if a gateway supports a given feature. |
|
440 | - * |
|
441 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
442 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
443 | - * |
|
444 | - * @param string $feature string The name of a feature to test support for. |
|
445 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
446 | - * @since 1.0.19 |
|
447 | - */ |
|
448 | - public function supports( $feature ) { |
|
449 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Returns the credit card form html. |
|
454 | - * |
|
455 | - * @param bool $save whether or not to display the save button. |
|
456 | - */ |
|
452 | + /** |
|
453 | + * Returns the credit card form html. |
|
454 | + * |
|
455 | + * @param bool $save whether or not to display the save button. |
|
456 | + */ |
|
457 | 457 | public function get_cc_form( $save = false ) { |
458 | 458 | |
459 | - ob_start(); |
|
459 | + ob_start(); |
|
460 | 460 | |
461 | 461 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
462 | 462 | |
@@ -551,8 +551,8 @@ discard block |
||
551 | 551 | 'name' => $this->id . '[cc_cvv2]', |
552 | 552 | 'id' => "$id_prefix-cc-cvv2", |
553 | 553 | 'label' => __( 'CCV', 'invoicing' ), |
554 | - 'label_type' => 'vertical', |
|
555 | - 'class' => 'form-control-sm', |
|
554 | + 'label_type' => 'vertical', |
|
555 | + 'class' => 'form-control-sm', |
|
556 | 556 | ) |
557 | 557 | ); |
558 | 558 | ?> |
@@ -562,175 +562,175 @@ discard block |
||
562 | 562 | |
563 | 563 | <?php |
564 | 564 | |
565 | - if ( $save ) { |
|
566 | - echo $this->save_payment_method_checkbox(); |
|
567 | - } |
|
565 | + if ( $save ) { |
|
566 | + echo $this->save_payment_method_checkbox(); |
|
567 | + } |
|
568 | 568 | |
569 | - ?> |
|
569 | + ?> |
|
570 | 570 | </div> |
571 | 571 | |
572 | 572 | </div> |
573 | 573 | <?php |
574 | 574 | |
575 | - return ob_get_clean(); |
|
575 | + return ob_get_clean(); |
|
576 | 576 | |
577 | 577 | } |
578 | 578 | |
579 | - /** |
|
580 | - * Displays a new payment method entry form. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - */ |
|
584 | - public function new_payment_method_entry( $form ) { |
|
585 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Grab and display our saved payment methods. |
|
590 | - * |
|
591 | - * @since 1.0.19 |
|
592 | - */ |
|
593 | - public function saved_payment_methods() { |
|
594 | - $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
595 | - |
|
596 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
597 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
598 | - } |
|
599 | - |
|
600 | - $html .= $this->get_new_payment_method_option_html(); |
|
601 | - $html .= '</ul>'; |
|
602 | - |
|
603 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Gets saved payment method HTML from a token. |
|
608 | - * |
|
609 | - * @since 1.0.19 |
|
610 | - * @param array $token Payment Token. |
|
611 | - * @return string Generated payment method HTML |
|
612 | - */ |
|
613 | - public function get_saved_payment_method_option_html( $token ) { |
|
614 | - |
|
615 | - return sprintf( |
|
616 | - '<li class="getpaid-payment-method form-group"> |
|
579 | + /** |
|
580 | + * Displays a new payment method entry form. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + */ |
|
584 | + public function new_payment_method_entry( $form ) { |
|
585 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Grab and display our saved payment methods. |
|
590 | + * |
|
591 | + * @since 1.0.19 |
|
592 | + */ |
|
593 | + public function saved_payment_methods() { |
|
594 | + $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
595 | + |
|
596 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
597 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
598 | + } |
|
599 | + |
|
600 | + $html .= $this->get_new_payment_method_option_html(); |
|
601 | + $html .= '</ul>'; |
|
602 | + |
|
603 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Gets saved payment method HTML from a token. |
|
608 | + * |
|
609 | + * @since 1.0.19 |
|
610 | + * @param array $token Payment Token. |
|
611 | + * @return string Generated payment method HTML |
|
612 | + */ |
|
613 | + public function get_saved_payment_method_option_html( $token ) { |
|
614 | + |
|
615 | + return sprintf( |
|
616 | + '<li class="getpaid-payment-method form-group"> |
|
617 | 617 | <label> |
618 | 618 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
619 | 619 | <span>%3$s</span> |
620 | 620 | </label> |
621 | 621 | </li>', |
622 | - esc_attr( $this->id ), |
|
623 | - esc_attr( $token['id'] ), |
|
624 | - esc_html( $token['name'] ), |
|
625 | - checked( empty( $token['default'] ), false, false ) |
|
626 | - ); |
|
622 | + esc_attr( $this->id ), |
|
623 | + esc_attr( $token['id'] ), |
|
624 | + esc_html( $token['name'] ), |
|
625 | + checked( empty( $token['default'] ), false, false ) |
|
626 | + ); |
|
627 | 627 | |
628 | - } |
|
628 | + } |
|
629 | 629 | |
630 | - /** |
|
631 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
632 | - * |
|
633 | - * @since 1.0.19 |
|
634 | - */ |
|
635 | - public function get_new_payment_method_option_html() { |
|
630 | + /** |
|
631 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
632 | + * |
|
633 | + * @since 1.0.19 |
|
634 | + */ |
|
635 | + public function get_new_payment_method_option_html() { |
|
636 | 636 | |
637 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
637 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
638 | 638 | |
639 | - return sprintf( |
|
640 | - '<li class="getpaid-new-payment-method"> |
|
639 | + return sprintf( |
|
640 | + '<li class="getpaid-new-payment-method"> |
|
641 | 641 | <label> |
642 | 642 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
643 | 643 | <span>%2$s</span> |
644 | 644 | </label> |
645 | 645 | </li>', |
646 | - esc_attr( $this->id ), |
|
647 | - esc_html( $label ) |
|
648 | - ); |
|
646 | + esc_attr( $this->id ), |
|
647 | + esc_html( $label ) |
|
648 | + ); |
|
649 | 649 | |
650 | - } |
|
650 | + } |
|
651 | 651 | |
652 | - /** |
|
653 | - * Outputs a checkbox for saving a new payment method to the database. |
|
654 | - * |
|
655 | - * @since 1.0.19 |
|
656 | - */ |
|
657 | - public function save_payment_method_checkbox() { |
|
652 | + /** |
|
653 | + * Outputs a checkbox for saving a new payment method to the database. |
|
654 | + * |
|
655 | + * @since 1.0.19 |
|
656 | + */ |
|
657 | + public function save_payment_method_checkbox() { |
|
658 | 658 | |
659 | - return sprintf( |
|
660 | - '<p class="form-group getpaid-save-payment-method"> |
|
659 | + return sprintf( |
|
660 | + '<p class="form-group getpaid-save-payment-method"> |
|
661 | 661 | <label> |
662 | 662 | <input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
663 | 663 | <span>%2$s</span> |
664 | 664 | </label> |
665 | 665 | </p>', |
666 | - esc_attr( $this->id ), |
|
667 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
668 | - ); |
|
666 | + esc_attr( $this->id ), |
|
667 | + esc_html__( 'Save payment method', 'invoicing' ) |
|
668 | + ); |
|
669 | 669 | |
670 | - } |
|
670 | + } |
|
671 | 671 | |
672 | - /** |
|
673 | - * Registers the gateway. |
|
674 | - * |
|
675 | - * @return array |
|
676 | - */ |
|
677 | - public function register_gateway( $gateways ) { |
|
672 | + /** |
|
673 | + * Registers the gateway. |
|
674 | + * |
|
675 | + * @return array |
|
676 | + */ |
|
677 | + public function register_gateway( $gateways ) { |
|
678 | 678 | |
679 | - $gateways[ $this->id ] = array( |
|
679 | + $gateways[ $this->id ] = array( |
|
680 | 680 | |
681 | - 'admin_label' => $this->method_title, |
|
681 | + 'admin_label' => $this->method_title, |
|
682 | 682 | 'checkout_label' => $this->title, |
683 | - 'ordering' => $this->order, |
|
684 | - |
|
685 | - ); |
|
686 | - |
|
687 | - return $gateways; |
|
688 | - |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Checks whether or not this is a sandbox request. |
|
693 | - * |
|
694 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
695 | - * @return bool |
|
696 | - */ |
|
697 | - public function is_sandbox( $invoice = null ) { |
|
698 | - |
|
699 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
700 | - return $invoice->get_mode() == 'test'; |
|
701 | - } |
|
702 | - |
|
703 | - return wpinv_is_test_mode( $this->id ); |
|
704 | - |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Renames the checkout button |
|
709 | - * |
|
710 | - * @return string |
|
711 | - */ |
|
712 | - public function rename_checkout_button() { |
|
713 | - return $this->checkout_button_text; |
|
714 | - } |
|
715 | - |
|
716 | - /** |
|
717 | - * Validate gateway currency |
|
718 | - * |
|
719 | - * @return bool |
|
720 | - */ |
|
721 | - public function validate_currency( $validation, $currency ) { |
|
722 | - |
|
723 | - // Required currencies. |
|
724 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
725 | - return false; |
|
726 | - } |
|
727 | - |
|
728 | - // Excluded currencies. |
|
729 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
730 | - return false; |
|
731 | - } |
|
732 | - |
|
733 | - return $validation; |
|
734 | - } |
|
683 | + 'ordering' => $this->order, |
|
684 | + |
|
685 | + ); |
|
686 | + |
|
687 | + return $gateways; |
|
688 | + |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Checks whether or not this is a sandbox request. |
|
693 | + * |
|
694 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
695 | + * @return bool |
|
696 | + */ |
|
697 | + public function is_sandbox( $invoice = null ) { |
|
698 | + |
|
699 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
700 | + return $invoice->get_mode() == 'test'; |
|
701 | + } |
|
702 | + |
|
703 | + return wpinv_is_test_mode( $this->id ); |
|
704 | + |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * Renames the checkout button |
|
709 | + * |
|
710 | + * @return string |
|
711 | + */ |
|
712 | + public function rename_checkout_button() { |
|
713 | + return $this->checkout_button_text; |
|
714 | + } |
|
715 | + |
|
716 | + /** |
|
717 | + * Validate gateway currency |
|
718 | + * |
|
719 | + * @return bool |
|
720 | + */ |
|
721 | + public function validate_currency( $validation, $currency ) { |
|
722 | + |
|
723 | + // Required currencies. |
|
724 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
725 | + return false; |
|
726 | + } |
|
727 | + |
|
728 | + // Excluded currencies. |
|
729 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
730 | + return false; |
|
731 | + } |
|
732 | + |
|
733 | + return $validation; |
|
734 | + } |
|
735 | 735 | |
736 | 736 | } |
@@ -229,7 +229,7 @@ |
||
229 | 229 | */ |
230 | 230 | function wpinv_send_back_to_checkout() { |
231 | 231 | |
232 | - // Do we have any errors? |
|
232 | + // Do we have any errors? |
|
233 | 233 | if ( wpinv_get_errors() ) { |
234 | 234 | wp_send_json_error( getpaid_get_errors_html( true, false ) ); |
235 | 235 | } |
@@ -12,431 +12,431 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN' ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Check PayPal IPN validity. |
|
106 | - */ |
|
107 | - protected function validate_ipn() { |
|
108 | - |
|
109 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
110 | - |
|
111 | - // Retrieve the associated invoice. |
|
112 | - $posted = wp_unslash( $_POST ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | - |
|
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
117 | - } |
|
118 | - |
|
119 | - // Validate the IPN. |
|
120 | - $posted['cmd'] = '_notify-validate'; |
|
121 | - |
|
122 | - // Send back post vars to paypal. |
|
123 | - $params = array( |
|
124 | - 'body' => $posted, |
|
125 | - 'timeout' => 60, |
|
126 | - 'httpversion' => '1.1', |
|
127 | - 'compress' => false, |
|
128 | - 'decompress' => false, |
|
129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | - ); |
|
131 | - |
|
132 | - // Post back to get a response. |
|
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | - |
|
135 | - // Check to see if the request was valid. |
|
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | - return false; |
|
144 | - } |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_unslash( $_POST ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 500 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN' ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
101 | + wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Check PayPal IPN validity. |
|
106 | + */ |
|
107 | + protected function validate_ipn() { |
|
108 | + |
|
109 | + wpinv_error_log( 'Validating PayPal IPN response' ); |
|
110 | + |
|
111 | + // Retrieve the associated invoice. |
|
112 | + $posted = wp_unslash( $_POST ); |
|
113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | + |
|
115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
117 | + } |
|
118 | + |
|
119 | + // Validate the IPN. |
|
120 | + $posted['cmd'] = '_notify-validate'; |
|
121 | + |
|
122 | + // Send back post vars to paypal. |
|
123 | + $params = array( |
|
124 | + 'body' => $posted, |
|
125 | + 'timeout' => 60, |
|
126 | + 'httpversion' => '1.1', |
|
127 | + 'compress' => false, |
|
128 | + 'decompress' => false, |
|
129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | + ); |
|
131 | + |
|
132 | + // Post back to get a response. |
|
133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | + |
|
135 | + // Check to see if the request was valid. |
|
136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | + wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + if ( is_wp_error( $response ) ) { |
|
142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | - return false; |
|
148 | - |
|
149 | - } |
|
146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | + return false; |
|
148 | + |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Check currency from IPN matches the invoice. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @param string $currency currency to validate. |
|
156 | - */ |
|
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
151 | + /** |
|
152 | + * Check currency from IPN matches the invoice. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @param string $currency currency to validate. |
|
156 | + */ |
|
157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
160 | 160 | |
161 | - /* translators: %s: currency code. */ |
|
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + /* translators: %s: currency code. */ |
|
162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | - } |
|
164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | + } |
|
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Check payment amount from IPN matches the invoice. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * @param float $amount amount to validate. |
|
175 | - */ |
|
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
170 | + /** |
|
171 | + * Check payment amount from IPN matches the invoice. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * @param float $amount amount to validate. |
|
175 | + */ |
|
176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
178 | 178 | |
179 | - /* translators: %s: Amount. */ |
|
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + /* translators: %s: Amount. */ |
|
180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | - } |
|
182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | + } |
|
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Verify receiver email from PayPal. |
|
190 | - * |
|
191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
192 | - * @param string $receiver_email Email to validate. |
|
193 | - */ |
|
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
188 | + /** |
|
189 | + * Verify receiver email from PayPal. |
|
190 | + * |
|
191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
192 | + * @param string $receiver_email Email to validate. |
|
193 | + */ |
|
194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
199 | 199 | |
200 | - /* translators: %s: email address . */ |
|
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + /* translators: %s: email address . */ |
|
201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | - } |
|
203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | + } |
|
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email' ); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Handles one time payments. |
|
211 | - * |
|
212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
213 | - * @param array $posted Posted data. |
|
214 | - */ |
|
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | - |
|
217 | - // Collect payment details |
|
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | - |
|
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | - |
|
224 | - // Update the transaction id. |
|
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | - $invoice->save(); |
|
228 | - } |
|
209 | + /** |
|
210 | + * Handles one time payments. |
|
211 | + * |
|
212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
213 | + * @param array $posted Posted data. |
|
214 | + */ |
|
215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | + |
|
217 | + // Collect payment details |
|
218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | + |
|
221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | + |
|
224 | + // Update the transaction id. |
|
225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | + $invoice->save(); |
|
228 | + } |
|
229 | 229 | |
230 | - // Process a refund. |
|
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
230 | + // Process a refund. |
|
231 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | - } |
|
235 | + if ( ! $invoice->is_refunded() ) { |
|
236 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | + } |
|
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
240 | - } |
|
239 | + return wpinv_error_log( $posted['reason_code'] ); |
|
240 | + } |
|
241 | 241 | |
242 | - // Process payments. |
|
243 | - if ( $payment_status == 'completed' ) { |
|
242 | + // Process payments. |
|
243 | + if ( $payment_status == 'completed' ) { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
247 | - } |
|
245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
247 | + } |
|
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | 250 | |
251 | - $note = ''; |
|
252 | - |
|
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | - } |
|
251 | + $note = ''; |
|
252 | + |
|
253 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | + } |
|
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | - } |
|
257 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | + } |
|
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
261 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | + return wpinv_error_log( 'Invoice marked as paid.' ); |
|
263 | 263 | |
264 | - } |
|
264 | + } |
|
265 | 265 | |
266 | - // Pending payments. |
|
267 | - if ( $payment_status == 'pending' ) { |
|
266 | + // Pending payments. |
|
267 | + if ( $payment_status == 'pending' ) { |
|
268 | 268 | |
269 | - /* translators: %s: pending reason. */ |
|
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
269 | + /* translators: %s: pending reason. */ |
|
270 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | 271 | |
272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
273 | - } |
|
272 | + return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
273 | + } |
|
274 | 274 | |
275 | - /* translators: %s: payment status. */ |
|
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
275 | + /* translators: %s: payment status. */ |
|
276 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Handles one time payments. |
|
282 | - * |
|
283 | - * @param WPInv_Invoice $invoice Invoice object. |
|
284 | - * @param array $posted Posted data. |
|
285 | - */ |
|
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | - } |
|
280 | + /** |
|
281 | + * Handles one time payments. |
|
282 | + * |
|
283 | + * @param WPInv_Invoice $invoice Invoice object. |
|
284 | + * @param array $posted Posted data. |
|
285 | + */ |
|
286 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * Handles subscription sign ups. |
|
292 | - * |
|
293 | - * @param WPInv_Invoice $invoice Invoice object. |
|
294 | - * @param array $posted Posted data. |
|
295 | - */ |
|
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
290 | + /** |
|
291 | + * Handles subscription sign ups. |
|
292 | + * |
|
293 | + * @param WPInv_Invoice $invoice Invoice object. |
|
294 | + * @param array $posted Posted data. |
|
295 | + */ |
|
296 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | 297 | |
298 | - wpinv_error_log( 'Processing subscription signup' ); |
|
298 | + wpinv_error_log( 'Processing subscription signup' ); |
|
299 | 299 | |
300 | - // Make sure the invoice has a subscription. |
|
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
300 | + // Make sure the invoice has a subscription. |
|
301 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
305 | - } |
|
303 | + if ( empty( $subscription ) ) { |
|
304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
305 | + } |
|
306 | 306 | |
307 | - // Validate the IPN. |
|
308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
307 | + // Validate the IPN. |
|
308 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | 311 | |
312 | - // Activate the subscription. |
|
313 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
314 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
315 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
316 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
317 | - $subscription->activate(); |
|
312 | + // Activate the subscription. |
|
313 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
314 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
315 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
316 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
317 | + $subscription->activate(); |
|
318 | 318 | |
319 | - // Set the transaction id. |
|
320 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
321 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
322 | - } |
|
319 | + // Set the transaction id. |
|
320 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
321 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
322 | + } |
|
323 | 323 | |
324 | - // Update the payment status. |
|
325 | - $invoice->mark_paid(); |
|
324 | + // Update the payment status. |
|
325 | + $invoice->mark_paid(); |
|
326 | 326 | |
327 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
327 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
328 | 328 | |
329 | - wpinv_error_log( 'Subscription started.' ); |
|
330 | - } |
|
329 | + wpinv_error_log( 'Subscription started.' ); |
|
330 | + } |
|
331 | 331 | |
332 | - /** |
|
333 | - * Handles subscription renewals. |
|
334 | - * |
|
335 | - * @param WPInv_Invoice $invoice Invoice object. |
|
336 | - * @param array $posted Posted data. |
|
337 | - */ |
|
338 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
332 | + /** |
|
333 | + * Handles subscription renewals. |
|
334 | + * |
|
335 | + * @param WPInv_Invoice $invoice Invoice object. |
|
336 | + * @param array $posted Posted data. |
|
337 | + */ |
|
338 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
339 | 339 | |
340 | - // Make sure the invoice has a subscription. |
|
341 | - $subscription = wpinv_get_subscription( $invoice ); |
|
340 | + // Make sure the invoice has a subscription. |
|
341 | + $subscription = wpinv_get_subscription( $invoice ); |
|
342 | 342 | |
343 | - if ( empty( $subscription ) ) { |
|
344 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
345 | - } |
|
343 | + if ( empty( $subscription ) ) { |
|
344 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
345 | + } |
|
346 | 346 | |
347 | - // Abort if this is the first payment. |
|
348 | - if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
349 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
350 | - $invoice->save(); |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
347 | + // Abort if this is the first payment. |
|
348 | + if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
349 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
350 | + $invoice->save(); |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
355 | 355 | |
356 | - // Abort if the payment is already recorded. |
|
357 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
358 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
359 | - } |
|
356 | + // Abort if the payment is already recorded. |
|
357 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
358 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
359 | + } |
|
360 | 360 | |
361 | - $args = array( |
|
362 | - 'transaction_id' => $posted['txn_id'], |
|
363 | - 'gateway' => $this->id, |
|
364 | - ); |
|
365 | - |
|
366 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
367 | - |
|
368 | - if ( empty( $invoice ) ) { |
|
369 | - return; |
|
370 | - } |
|
371 | - |
|
372 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
374 | - |
|
375 | - $subscription->renew(); |
|
376 | - wpinv_error_log( 'Subscription renewed.' ); |
|
377 | - |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Handles subscription cancelations. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice Invoice object. |
|
384 | - */ |
|
385 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
386 | - |
|
387 | - // Make sure the invoice has a subscription. |
|
388 | - $subscription = wpinv_get_subscription( $invoice ); |
|
389 | - |
|
390 | - if ( empty( $subscription ) ) { |
|
391 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
392 | - } |
|
393 | - |
|
394 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
395 | - $subscription->cancel(); |
|
396 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
361 | + $args = array( |
|
362 | + 'transaction_id' => $posted['txn_id'], |
|
363 | + 'gateway' => $this->id, |
|
364 | + ); |
|
365 | + |
|
366 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
367 | + |
|
368 | + if ( empty( $invoice ) ) { |
|
369 | + return; |
|
370 | + } |
|
371 | + |
|
372 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
373 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
374 | + |
|
375 | + $subscription->renew(); |
|
376 | + wpinv_error_log( 'Subscription renewed.' ); |
|
377 | + |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Handles subscription cancelations. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice Invoice object. |
|
384 | + */ |
|
385 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
386 | + |
|
387 | + // Make sure the invoice has a subscription. |
|
388 | + $subscription = wpinv_get_subscription( $invoice ); |
|
389 | + |
|
390 | + if ( empty( $subscription ) ) { |
|
391 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
392 | + } |
|
393 | + |
|
394 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
395 | + $subscription->cancel(); |
|
396 | + wpinv_error_log( 'Subscription cancelled.' ); |
|
397 | 397 | |
398 | - } |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * Handles subscription completions. |
|
402 | - * |
|
403 | - * @param WPInv_Invoice $invoice Invoice object. |
|
404 | - * @param array $posted Posted data. |
|
405 | - */ |
|
406 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
407 | - |
|
408 | - // Make sure the invoice has a subscription. |
|
409 | - $subscription = wpinv_get_subscription( $invoice ); |
|
400 | + /** |
|
401 | + * Handles subscription completions. |
|
402 | + * |
|
403 | + * @param WPInv_Invoice $invoice Invoice object. |
|
404 | + * @param array $posted Posted data. |
|
405 | + */ |
|
406 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
407 | + |
|
408 | + // Make sure the invoice has a subscription. |
|
409 | + $subscription = wpinv_get_subscription( $invoice ); |
|
410 | 410 | |
411 | - if ( empty( $subscription ) ) { |
|
412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
413 | - } |
|
411 | + if ( empty( $subscription ) ) { |
|
412 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
413 | + } |
|
414 | 414 | |
415 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
416 | - $subscription->complete(); |
|
417 | - wpinv_error_log( 'Subscription completed.' ); |
|
415 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
416 | + $subscription->complete(); |
|
417 | + wpinv_error_log( 'Subscription completed.' ); |
|
418 | 418 | |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - /** |
|
422 | - * Handles subscription fails. |
|
423 | - * |
|
424 | - * @param WPInv_Invoice $invoice Invoice object. |
|
425 | - * @param array $posted Posted data. |
|
426 | - */ |
|
427 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
421 | + /** |
|
422 | + * Handles subscription fails. |
|
423 | + * |
|
424 | + * @param WPInv_Invoice $invoice Invoice object. |
|
425 | + * @param array $posted Posted data. |
|
426 | + */ |
|
427 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
428 | 428 | |
429 | - // Make sure the invoice has a subscription. |
|
430 | - $subscription = wpinv_get_subscription( $invoice ); |
|
429 | + // Make sure the invoice has a subscription. |
|
430 | + $subscription = wpinv_get_subscription( $invoice ); |
|
431 | 431 | |
432 | - if ( empty( $subscription ) ) { |
|
433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
434 | - } |
|
432 | + if ( empty( $subscription ) ) { |
|
433 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
434 | + } |
|
435 | 435 | |
436 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
437 | - $subscription->failing(); |
|
438 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
436 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
437 | + $subscription->failing(); |
|
438 | + wpinv_error_log( 'Subscription marked as failing.' ); |
|
439 | 439 | |
440 | - } |
|
440 | + } |
|
441 | 441 | |
442 | 442 | } |
@@ -43,64 +43,64 @@ discard block |
||
43 | 43 | <td class="w-75"> |
44 | 44 | <?php |
45 | 45 | |
46 | - switch ( $key ) { |
|
46 | + switch ( $key ) { |
|
47 | 47 | |
48 | - case 'status': |
|
49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
50 | - break; |
|
48 | + case 'status': |
|
49 | + echo sanitize_text_field( $subscription->get_status_label() ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'start_date': |
|
53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
54 | - break; |
|
52 | + case 'start_date': |
|
53 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'expiry_date': |
|
57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
58 | - break; |
|
56 | + case 'expiry_date': |
|
57 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
58 | + break; |
|
59 | 59 | |
60 | - case 'initial_amount': |
|
61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
60 | + case 'initial_amount': |
|
61 | + echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
62 | 62 | |
63 | - if ( $subscription->has_trial_period() ) { |
|
63 | + if ( $subscription->has_trial_period() ) { |
|
64 | 64 | |
65 | - echo "<small class='text-muted'> "; |
|
66 | - printf( |
|
67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
69 | - ); |
|
70 | - echo '</small>'; |
|
65 | + echo "<small class='text-muted'> "; |
|
66 | + printf( |
|
67 | + _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | + sanitize_text_field( $subscription->get_trial_period() ) |
|
69 | + ); |
|
70 | + echo '</small>'; |
|
71 | 71 | |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - break; |
|
74 | + break; |
|
75 | 75 | |
76 | - case 'recurring_amount': |
|
77 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
80 | - break; |
|
76 | + case 'recurring_amount': |
|
77 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
78 | + $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | + echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
80 | + break; |
|
81 | 81 | |
82 | - case 'item': |
|
83 | - $item = get_post( $subscription->get_product_id() ); |
|
82 | + case 'item': |
|
83 | + $item = get_post( $subscription->get_product_id() ); |
|
84 | 84 | |
85 | - if ( ! empty( $item ) ) { |
|
86 | - echo esc_html( get_the_title( $item ) ); |
|
87 | - } else { |
|
88 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
89 | - } |
|
85 | + if ( ! empty( $item ) ) { |
|
86 | + echo esc_html( get_the_title( $item ) ); |
|
87 | + } else { |
|
88 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
89 | + } |
|
90 | 90 | |
91 | - break; |
|
91 | + break; |
|
92 | 92 | |
93 | - case 'payments': |
|
93 | + case 'payments': |
|
94 | 94 | |
95 | - $max_activations = (int) $subscription->get_bill_times(); |
|
96 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
95 | + $max_activations = (int) $subscription->get_bill_times(); |
|
96 | + echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
97 | 97 | |
98 | - break; |
|
98 | + break; |
|
99 | 99 | |
100 | - } |
|
101 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
100 | + } |
|
101 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
102 | 102 | |
103 | - ?> |
|
103 | + ?> |
|
104 | 104 | </td> |
105 | 105 | |
106 | 106 | </tr> |
@@ -117,17 +117,17 @@ discard block |
||
117 | 117 | <span class="form-text"> |
118 | 118 | |
119 | 119 | <?php |
120 | - if ( $subscription->can_cancel() ) { |
|
121 | - printf( |
|
122 | - '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
123 | - esc_url( $subscription->get_cancel_url() ), |
|
124 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | - __( 'Cancel Subscription', 'invoicing' ) |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
130 | - ?> |
|
120 | + if ( $subscription->can_cancel() ) { |
|
121 | + printf( |
|
122 | + '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
123 | + esc_url( $subscription->get_cancel_url() ), |
|
124 | + esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | + __( 'Cancel Subscription', 'invoicing' ) |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
130 | + ?> |
|
131 | 131 | |
132 | 132 | <a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
133 | 133 | </span> |
134 | 134 | \ No newline at end of file |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | |
20 | 20 | // Define constants. |
21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
26 | - define( 'WPINV_VERSION', '1.1.0' ); |
|
26 | + define( 'WPINV_VERSION', '1.1.0' ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
46 | - return $GLOBALS['invoicing']; |
|
46 | + return $GLOBALS['invoicing']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |