@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_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 = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 8; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 8; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -44,24 +44,24 @@ discard block |
||
44 | 44 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
45 | 45 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | - * Process Payment. |
|
58 | - * |
|
59 | - * @param WPInv_Invoice $invoice Invoice. |
|
60 | - * @param array $submission_data Posted checkout fields. |
|
61 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + * Process Payment. |
|
58 | + * |
|
59 | + * @param WPInv_Invoice $invoice Invoice. |
|
60 | + * @param array $submission_data Posted checkout fields. |
|
61 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | 67 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -82,66 +82,66 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * Output for the order received page. |
|
86 | - * |
|
87 | - * @param WPInv_Invoice $invoice Invoice. |
|
88 | - */ |
|
89 | - public function thankyou_page( $invoice ) { |
|
85 | + * Output for the order received page. |
|
86 | + * |
|
87 | + * @param WPInv_Invoice $invoice Invoice. |
|
88 | + */ |
|
89 | + public function thankyou_page( $invoice ) { |
|
90 | 90 | |
91 | 91 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
92 | 92 | |
93 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
93 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
94 | 94 | |
95 | 95 | if ( ! empty( $this->instructions ) ) { |
96 | 96 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details( $invoice ); |
|
100 | 100 | |
101 | - echo '</div>'; |
|
101 | + echo '</div>'; |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | /** |
108 | - * Add content to the WPI emails. |
|
109 | - * |
|
110 | - * @param WPInv_Invoice $invoice Invoice. |
|
111 | - * @param string $email_type Email format: plain text or HTML. |
|
112 | - * @param bool $sent_to_admin Sent to admin. |
|
113 | - */ |
|
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
108 | + * Add content to the WPI emails. |
|
109 | + * |
|
110 | + * @param WPInv_Invoice $invoice Invoice. |
|
111 | + * @param string $email_type Email format: plain text or HTML. |
|
112 | + * @param bool $sent_to_admin Sent to admin. |
|
113 | + */ |
|
114 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
117 | 117 | |
118 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
118 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ( $this->instructions ) { |
|
121 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details( $invoice ); |
|
125 | 125 | |
126 | - echo '</div>'; |
|
126 | + echo '</div>'; |
|
127 | 127 | |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Get bank details and place into a list format. |
|
134 | - * |
|
135 | - * @param WPInv_Invoice $invoice Invoice. |
|
136 | - */ |
|
137 | - protected function bank_details( $invoice ) { |
|
133 | + * Get bank details and place into a list format. |
|
134 | + * |
|
135 | + * @param WPInv_Invoice $invoice Invoice. |
|
136 | + */ |
|
137 | + protected function bank_details( $invoice ) { |
|
138 | 138 | |
139 | - // Get the invoice country and country $locale. |
|
140 | - $country = $invoice->get_country(); |
|
141 | - $locale = $this->get_country_locale(); |
|
139 | + // Get the invoice country and country $locale. |
|
140 | + $country = $invoice->get_country(); |
|
141 | + $locale = $this->get_country_locale(); |
|
142 | 142 | |
143 | - // Get sortcode label in the $locale array and use appropriate one. |
|
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
143 | + // Get sortcode label in the $locale array and use appropriate one. |
|
144 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | 147 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | |
161 | 161 | if ( ! empty( $value ) ) { |
162 | 162 | $bank_info[ $field ] = array( |
163 | - 'label' => $label, |
|
164 | - 'value' => $value, |
|
165 | - ); |
|
163 | + 'label' => $label, |
|
164 | + 'value' => $value, |
|
165 | + ); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
@@ -172,144 +172,144 @@ discard block |
||
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
177 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
179 | + foreach ( $bank_info as $key => $data ) { |
|
180 | 180 | |
181 | - $key = sanitize_html_class( $key ); |
|
182 | - $label = wp_kses_post( $data['label'] ); |
|
183 | - $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
181 | + $key = sanitize_html_class( $key ); |
|
182 | + $label = wp_kses_post( $data['label'] ); |
|
183 | + $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
184 | 184 | |
185 | - echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL; |
|
186 | - } |
|
185 | + echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL; |
|
186 | + } |
|
187 | 187 | |
188 | - echo '</table>'; |
|
188 | + echo '</table>'; |
|
189 | 189 | |
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Get country locale if localized. |
|
194 | - * |
|
195 | - * @return array |
|
196 | - */ |
|
197 | - public function get_country_locale() { |
|
198 | - |
|
199 | - if ( empty( $this->locale ) ) { |
|
200 | - |
|
201 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
202 | - $this->locale = apply_filters( |
|
203 | - 'getpaid_get_bank_transfer_locale', |
|
204 | - array( |
|
205 | - 'AU' => array( |
|
206 | - 'sortcode' => array( |
|
207 | - 'label' => __( 'BSB', 'invoicing' ), |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'CA' => array( |
|
211 | - 'sortcode' => array( |
|
212 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
213 | - ), |
|
214 | - ), |
|
215 | - 'IN' => array( |
|
216 | - 'sortcode' => array( |
|
217 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
218 | - ), |
|
219 | - ), |
|
220 | - 'IT' => array( |
|
221 | - 'sortcode' => array( |
|
222 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'NZ' => array( |
|
226 | - 'sortcode' => array( |
|
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | - ), |
|
229 | - ), |
|
230 | - 'SE' => array( |
|
231 | - 'sortcode' => array( |
|
232 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
233 | - ), |
|
234 | - ), |
|
235 | - 'US' => array( |
|
236 | - 'sortcode' => array( |
|
237 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
238 | - ), |
|
239 | - ), |
|
240 | - 'ZA' => array( |
|
241 | - 'sortcode' => array( |
|
242 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
243 | - ), |
|
244 | - ), |
|
245 | - ) |
|
246 | - ); |
|
247 | - |
|
248 | - } |
|
249 | - |
|
250 | - return $this->locale; |
|
251 | - |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Filters the gateway settings. |
|
256 | - * |
|
257 | - * @param array $admin_settings |
|
258 | - */ |
|
259 | - public function admin_settings( $admin_settings ) { |
|
193 | + * Get country locale if localized. |
|
194 | + * |
|
195 | + * @return array |
|
196 | + */ |
|
197 | + public function get_country_locale() { |
|
198 | + |
|
199 | + if ( empty( $this->locale ) ) { |
|
200 | + |
|
201 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
202 | + $this->locale = apply_filters( |
|
203 | + 'getpaid_get_bank_transfer_locale', |
|
204 | + array( |
|
205 | + 'AU' => array( |
|
206 | + 'sortcode' => array( |
|
207 | + 'label' => __( 'BSB', 'invoicing' ), |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'CA' => array( |
|
211 | + 'sortcode' => array( |
|
212 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
213 | + ), |
|
214 | + ), |
|
215 | + 'IN' => array( |
|
216 | + 'sortcode' => array( |
|
217 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
218 | + ), |
|
219 | + ), |
|
220 | + 'IT' => array( |
|
221 | + 'sortcode' => array( |
|
222 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'NZ' => array( |
|
226 | + 'sortcode' => array( |
|
227 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | + ), |
|
229 | + ), |
|
230 | + 'SE' => array( |
|
231 | + 'sortcode' => array( |
|
232 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
233 | + ), |
|
234 | + ), |
|
235 | + 'US' => array( |
|
236 | + 'sortcode' => array( |
|
237 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
238 | + ), |
|
239 | + ), |
|
240 | + 'ZA' => array( |
|
241 | + 'sortcode' => array( |
|
242 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
243 | + ), |
|
244 | + ), |
|
245 | + ) |
|
246 | + ); |
|
247 | + |
|
248 | + } |
|
249 | + |
|
250 | + return $this->locale; |
|
251 | + |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Filters the gateway settings. |
|
256 | + * |
|
257 | + * @param array $admin_settings |
|
258 | + */ |
|
259 | + public function admin_settings( $admin_settings ) { |
|
260 | 260 | |
261 | 261 | $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
262 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
262 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
263 | 263 | |
264 | - $locale = $this->get_country_locale(); |
|
264 | + $locale = $this->get_country_locale(); |
|
265 | 265 | |
266 | - // Get sortcode label in the $locale array and use appropriate one. |
|
267 | - $country = wpinv_default_billing_country(); |
|
268 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
266 | + // Get sortcode label in the $locale array and use appropriate one. |
|
267 | + $country = wpinv_default_billing_country(); |
|
268 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
269 | 269 | |
270 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
270 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
271 | 271 | 'type' => 'text', |
272 | 272 | 'id' => 'bank_transfer_ac_name', |
273 | 273 | 'name' => __( 'Account Name', 'invoicing' ), |
274 | - ); |
|
274 | + ); |
|
275 | 275 | |
276 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
276 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
277 | 277 | 'type' => 'text', |
278 | 278 | 'id' => 'bank_transfer_ac_no', |
279 | 279 | 'name' => __( 'Account Number', 'invoicing' ), |
280 | - ); |
|
280 | + ); |
|
281 | 281 | |
282 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
282 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
283 | 283 | 'type' => 'text', |
284 | 284 | 'id' => 'bank_transfer_bank_name', |
285 | 285 | 'name' => __( 'Bank Name', 'invoicing' ), |
286 | - ); |
|
286 | + ); |
|
287 | 287 | |
288 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
288 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
289 | 289 | 'type' => 'text', |
290 | 290 | 'id' => 'bank_transfer_ifsc', |
291 | 291 | 'name' => __( 'IFSC Code', 'invoicing' ), |
292 | - ); |
|
292 | + ); |
|
293 | 293 | |
294 | - $admin_settings['bank_transfer_iban'] = array( |
|
294 | + $admin_settings['bank_transfer_iban'] = array( |
|
295 | 295 | 'type' => 'text', |
296 | 296 | 'id' => 'bank_transfer_iban', |
297 | 297 | 'name' => __( 'IBAN', 'invoicing' ), |
298 | - ); |
|
298 | + ); |
|
299 | 299 | |
300 | - $admin_settings['bank_transfer_bic'] = array( |
|
300 | + $admin_settings['bank_transfer_bic'] = array( |
|
301 | 301 | 'type' => 'text', |
302 | 302 | 'id' => 'bank_transfer_bic', |
303 | 303 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
304 | - ); |
|
304 | + ); |
|
305 | 305 | |
306 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
307 | - 'type' => 'text', |
|
308 | - 'id' => 'bank_transfer_sort_code', |
|
309 | - 'name' => $sortcode, |
|
310 | - ); |
|
306 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
307 | + 'type' => 'text', |
|
308 | + 'id' => 'bank_transfer_sort_code', |
|
309 | + 'name' => $sortcode, |
|
310 | + ); |
|
311 | 311 | |
312 | - $admin_settings['bank_transfer_info'] = array( |
|
312 | + $admin_settings['bank_transfer_info'] = array( |
|
313 | 313 | 'id' => 'bank_transfer_info', |
314 | 314 | 'name' => __( 'Instructions', 'invoicing' ), |
315 | 315 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -319,17 +319,17 @@ discard block |
||
319 | 319 | 'rows' => 5, |
320 | 320 | ); |
321 | 321 | |
322 | - return $admin_settings; |
|
323 | - } |
|
322 | + return $admin_settings; |
|
323 | + } |
|
324 | 324 | |
325 | - /** |
|
326 | - * Processes invoice addons. |
|
327 | - * |
|
328 | - * @param WPInv_Invoice $invoice |
|
329 | - * @param GetPaid_Form_Item[] $items |
|
330 | - * @return WPInv_Invoice |
|
331 | - */ |
|
332 | - public function process_addons( $invoice, $items ) { |
|
325 | + /** |
|
326 | + * Processes invoice addons. |
|
327 | + * |
|
328 | + * @param WPInv_Invoice $invoice |
|
329 | + * @param GetPaid_Form_Item[] $items |
|
330 | + * @return WPInv_Invoice |
|
331 | + */ |
|
332 | + public function process_addons( $invoice, $items ) { |
|
333 | 333 | |
334 | 334 | foreach ( $items as $item ) { |
335 | 335 | $invoice->add_item( $item ); |
@@ -337,66 +337,66 @@ discard block |
||
337 | 337 | |
338 | 338 | $invoice->recalculate_total(); |
339 | 339 | $invoice->save(); |
340 | - } |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * (Maybe) renews a bank transfer subscription profile. |
|
344 | - * |
|
345 | - * |
|
342 | + /** |
|
343 | + * (Maybe) renews a bank transfer subscription profile. |
|
344 | + * |
|
345 | + * |
|
346 | 346 | * @param WPInv_Subscription $subscription |
347 | - */ |
|
348 | - public function maybe_renew_subscription( $subscription ) { |
|
347 | + */ |
|
348 | + public function maybe_renew_subscription( $subscription ) { |
|
349 | 349 | |
350 | 350 | // Ensure its our subscription && it's active. |
351 | 351 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
352 | - $subscription->create_payment(); |
|
352 | + $subscription->create_payment(); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | - /** |
|
358 | - * Process a bank transfer payment. |
|
359 | - * |
|
360 | - * |
|
357 | + /** |
|
358 | + * Process a bank transfer payment. |
|
359 | + * |
|
360 | + * |
|
361 | 361 | * @param WPInv_Invoice $invoice |
362 | - */ |
|
363 | - public function invoice_paid( $invoice ) { |
|
364 | - |
|
365 | - // Abort if not paid by bank transfer. |
|
366 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
367 | - return; |
|
368 | - } |
|
369 | - |
|
370 | - // Is it a parent payment? |
|
371 | - if ( 0 == $invoice->get_parent_id() ) { |
|
372 | - |
|
373 | - // (Maybe) activate subscriptions. |
|
374 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
375 | - |
|
376 | - if ( ! empty( $subscriptions ) ) { |
|
377 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
378 | - |
|
379 | - foreach ( $subscriptions as $subscription ) { |
|
380 | - if ( $subscription->exists() ) { |
|
381 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
382 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
383 | - |
|
384 | - $subscription->set_next_renewal_date( $expiry ); |
|
385 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
386 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
387 | - $subscription->activate(); |
|
388 | - } |
|
389 | - } |
|
362 | + */ |
|
363 | + public function invoice_paid( $invoice ) { |
|
364 | + |
|
365 | + // Abort if not paid by bank transfer. |
|
366 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
367 | + return; |
|
368 | + } |
|
369 | + |
|
370 | + // Is it a parent payment? |
|
371 | + if ( 0 == $invoice->get_parent_id() ) { |
|
372 | + |
|
373 | + // (Maybe) activate subscriptions. |
|
374 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
375 | + |
|
376 | + if ( ! empty( $subscriptions ) ) { |
|
377 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
378 | + |
|
379 | + foreach ( $subscriptions as $subscription ) { |
|
380 | + if ( $subscription->exists() ) { |
|
381 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
382 | + $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
383 | + |
|
384 | + $subscription->set_next_renewal_date( $expiry ); |
|
385 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
386 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
387 | + $subscription->activate(); |
|
388 | + } |
|
389 | + } |
|
390 | 390 | } |
391 | 391 | } else { |
392 | 392 | |
393 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
393 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
394 | 394 | |
395 | - // Renew the subscription. |
|
396 | - if ( $subscription && $subscription->exists() ) { |
|
397 | - $subscription->add_payment( array(), $invoice ); |
|
398 | - $subscription->renew(); |
|
399 | - } |
|
395 | + // Renew the subscription. |
|
396 | + if ( $subscription && $subscription->exists() ) { |
|
397 | + $subscription->add_payment( array(), $invoice ); |
|
398 | + $subscription->renew(); |
|
399 | + } |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Bank transfer Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
44 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
45 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
42 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
43 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
44 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
45 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
48 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
49 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
50 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
51 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
52 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + public function process_payment($invoice, $submission_data, $submission) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
67 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
68 | 68 | |
69 | 69 | // Set it as pending payment. |
70 | - if ( ! $invoice->needs_payment() ) { |
|
70 | + if (!$invoice->needs_payment()) { |
|
71 | 71 | $invoice->mark_paid(); |
72 | - } elseif ( ! $invoice->is_paid() ) { |
|
73 | - $invoice->set_status( 'wpi-onhold' ); |
|
72 | + } elseif (!$invoice->is_paid()) { |
|
73 | + $invoice->set_status('wpi-onhold'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Save it. |
77 | 77 | $invoice->save(); |
78 | 78 | |
79 | 79 | // Send to the success page. |
80 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
80 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -86,17 +86,17 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WPInv_Invoice $invoice Invoice. |
88 | 88 | */ |
89 | - public function thankyou_page( $invoice ) { |
|
89 | + public function thankyou_page($invoice) { |
|
90 | 90 | |
91 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
91 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
92 | 92 | |
93 | 93 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
94 | 94 | |
95 | - if ( ! empty( $this->instructions ) ) { |
|
96 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
95 | + if (!empty($this->instructions)) { |
|
96 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
97 | 97 | } |
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details($invoice); |
|
100 | 100 | |
101 | 101 | echo '</div>'; |
102 | 102 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | * @param string $email_type Email format: plain text or HTML. |
112 | 112 | * @param bool $sent_to_admin Sent to admin. |
113 | 113 | */ |
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
114 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
117 | 117 | |
118 | 118 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ($this->instructions) { |
|
121 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details($invoice); |
|
125 | 125 | |
126 | 126 | echo '</div>'; |
127 | 127 | |
@@ -134,53 +134,53 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Invoice $invoice Invoice. |
136 | 136 | */ |
137 | - protected function bank_details( $invoice ) { |
|
137 | + protected function bank_details($invoice) { |
|
138 | 138 | |
139 | 139 | // Get the invoice country and country $locale. |
140 | 140 | $country = $invoice->get_country(); |
141 | 141 | $locale = $this->get_country_locale(); |
142 | 142 | |
143 | 143 | // Get sortcode label in the $locale array and use appropriate one. |
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
144 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
148 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
149 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
150 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
151 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
152 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
147 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
148 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
149 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
150 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
151 | + 'iban' => __('IBAN', 'invoicing'), |
|
152 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
153 | 153 | 'sort_code' => $sortcode, |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $bank_info = array(); |
157 | 157 | |
158 | - foreach ( $bank_fields as $field => $label ) { |
|
159 | - $value = $this->get_option( $field ); |
|
158 | + foreach ($bank_fields as $field => $label) { |
|
159 | + $value = $this->get_option($field); |
|
160 | 160 | |
161 | - if ( ! empty( $value ) ) { |
|
162 | - $bank_info[ $field ] = array( |
|
161 | + if (!empty($value)) { |
|
162 | + $bank_info[$field] = array( |
|
163 | 163 | 'label' => $label, |
164 | 164 | 'value' => $value, |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info ); |
|
169 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info); |
|
170 | 170 | |
171 | - if ( empty( $bank_info ) ) { |
|
171 | + if (empty($bank_info)) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing')) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | 177 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
179 | + foreach ($bank_info as $key => $data) { |
|
180 | 180 | |
181 | - $key = sanitize_html_class( $key ); |
|
182 | - $label = wp_kses_post( $data['label'] ); |
|
183 | - $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
181 | + $key = sanitize_html_class($key); |
|
182 | + $label = wp_kses_post($data['label']); |
|
183 | + $value = wp_kses_post(wptexturize($data['value'])); |
|
184 | 184 | |
185 | 185 | echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL; |
186 | 186 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function get_country_locale() { |
198 | 198 | |
199 | - if ( empty( $this->locale ) ) { |
|
199 | + if (empty($this->locale)) { |
|
200 | 200 | |
201 | 201 | // Locale information to be used - only those that are not 'Sort Code'. |
202 | 202 | $this->locale = apply_filters( |
@@ -204,42 +204,42 @@ discard block |
||
204 | 204 | array( |
205 | 205 | 'AU' => array( |
206 | 206 | 'sortcode' => array( |
207 | - 'label' => __( 'BSB', 'invoicing' ), |
|
207 | + 'label' => __('BSB', 'invoicing'), |
|
208 | 208 | ), |
209 | 209 | ), |
210 | 210 | 'CA' => array( |
211 | 211 | 'sortcode' => array( |
212 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
212 | + 'label' => __('Bank transit number', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | ), |
215 | 215 | 'IN' => array( |
216 | 216 | 'sortcode' => array( |
217 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
217 | + 'label' => __('IFSC', 'invoicing'), |
|
218 | 218 | ), |
219 | 219 | ), |
220 | 220 | 'IT' => array( |
221 | 221 | 'sortcode' => array( |
222 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
222 | + 'label' => __('Branch sort', 'invoicing'), |
|
223 | 223 | ), |
224 | 224 | ), |
225 | 225 | 'NZ' => array( |
226 | 226 | 'sortcode' => array( |
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
227 | + 'label' => __('Bank code', 'invoicing'), |
|
228 | 228 | ), |
229 | 229 | ), |
230 | 230 | 'SE' => array( |
231 | 231 | 'sortcode' => array( |
232 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
232 | + 'label' => __('Bank code', 'invoicing'), |
|
233 | 233 | ), |
234 | 234 | ), |
235 | 235 | 'US' => array( |
236 | 236 | 'sortcode' => array( |
237 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
237 | + 'label' => __('Routing number', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | ), |
240 | 240 | 'ZA' => array( |
241 | 241 | 'sortcode' => array( |
242 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
242 | + 'label' => __('Branch code', 'invoicing'), |
|
243 | 243 | ), |
244 | 244 | ), |
245 | 245 | ) |
@@ -256,51 +256,51 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @param array $admin_settings |
258 | 258 | */ |
259 | - public function admin_settings( $admin_settings ) { |
|
259 | + public function admin_settings($admin_settings) { |
|
260 | 260 | |
261 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
262 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
261 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
262 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
263 | 263 | |
264 | - $locale = $this->get_country_locale(); |
|
264 | + $locale = $this->get_country_locale(); |
|
265 | 265 | |
266 | 266 | // Get sortcode label in the $locale array and use appropriate one. |
267 | 267 | $country = wpinv_default_billing_country(); |
268 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
268 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
269 | 269 | |
270 | 270 | $admin_settings['bank_transfer_ac_name'] = array( |
271 | 271 | 'type' => 'text', |
272 | 272 | 'id' => 'bank_transfer_ac_name', |
273 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
273 | + 'name' => __('Account Name', 'invoicing'), |
|
274 | 274 | ); |
275 | 275 | |
276 | 276 | $admin_settings['bank_transfer_ac_no'] = array( |
277 | 277 | 'type' => 'text', |
278 | 278 | 'id' => 'bank_transfer_ac_no', |
279 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
279 | + 'name' => __('Account Number', 'invoicing'), |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | $admin_settings['bank_transfer_bank_name'] = array( |
283 | 283 | 'type' => 'text', |
284 | 284 | 'id' => 'bank_transfer_bank_name', |
285 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
285 | + 'name' => __('Bank Name', 'invoicing'), |
|
286 | 286 | ); |
287 | 287 | |
288 | 288 | $admin_settings['bank_transfer_ifsc'] = array( |
289 | 289 | 'type' => 'text', |
290 | 290 | 'id' => 'bank_transfer_ifsc', |
291 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
291 | + 'name' => __('IFSC Code', 'invoicing'), |
|
292 | 292 | ); |
293 | 293 | |
294 | 294 | $admin_settings['bank_transfer_iban'] = array( |
295 | 295 | 'type' => 'text', |
296 | 296 | 'id' => 'bank_transfer_iban', |
297 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
297 | + 'name' => __('IBAN', 'invoicing'), |
|
298 | 298 | ); |
299 | 299 | |
300 | 300 | $admin_settings['bank_transfer_bic'] = array( |
301 | 301 | 'type' => 'text', |
302 | 302 | 'id' => 'bank_transfer_bic', |
303 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
303 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
304 | 304 | ); |
305 | 305 | |
306 | 306 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -311,10 +311,10 @@ discard block |
||
311 | 311 | |
312 | 312 | $admin_settings['bank_transfer_info'] = array( |
313 | 313 | 'id' => 'bank_transfer_info', |
314 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
315 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
314 | + 'name' => __('Instructions', 'invoicing'), |
|
315 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
316 | 316 | 'type' => 'textarea', |
317 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
317 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
318 | 318 | 'cols' => 50, |
319 | 319 | 'rows' => 5, |
320 | 320 | ); |
@@ -329,10 +329,10 @@ discard block |
||
329 | 329 | * @param GetPaid_Form_Item[] $items |
330 | 330 | * @return WPInv_Invoice |
331 | 331 | */ |
332 | - public function process_addons( $invoice, $items ) { |
|
332 | + public function process_addons($invoice, $items) { |
|
333 | 333 | |
334 | - foreach ( $items as $item ) { |
|
335 | - $invoice->add_item( $item ); |
|
334 | + foreach ($items as $item) { |
|
335 | + $invoice->add_item($item); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | $invoice->recalculate_total(); |
@@ -345,10 +345,10 @@ discard block |
||
345 | 345 | * |
346 | 346 | * @param WPInv_Subscription $subscription |
347 | 347 | */ |
348 | - public function maybe_renew_subscription( $subscription ) { |
|
348 | + public function maybe_renew_subscription($subscription) { |
|
349 | 349 | |
350 | 350 | // Ensure its our subscription && it's active. |
351 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
351 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
352 | 352 | $subscription->create_payment(); |
353 | 353 | } |
354 | 354 | |
@@ -360,41 +360,41 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @param WPInv_Invoice $invoice |
362 | 362 | */ |
363 | - public function invoice_paid( $invoice ) { |
|
363 | + public function invoice_paid($invoice) { |
|
364 | 364 | |
365 | 365 | // Abort if not paid by bank transfer. |
366 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
366 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
367 | 367 | return; |
368 | 368 | } |
369 | 369 | |
370 | 370 | // Is it a parent payment? |
371 | - if ( 0 == $invoice->get_parent_id() ) { |
|
371 | + if (0 == $invoice->get_parent_id()) { |
|
372 | 372 | |
373 | 373 | // (Maybe) activate subscriptions. |
374 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
374 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
375 | 375 | |
376 | - if ( ! empty( $subscriptions ) ) { |
|
377 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
376 | + if (!empty($subscriptions)) { |
|
377 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
378 | 378 | |
379 | - foreach ( $subscriptions as $subscription ) { |
|
380 | - if ( $subscription->exists() ) { |
|
381 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
382 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
379 | + foreach ($subscriptions as $subscription) { |
|
380 | + if ($subscription->exists()) { |
|
381 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
382 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
383 | 383 | |
384 | - $subscription->set_next_renewal_date( $expiry ); |
|
385 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
386 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
384 | + $subscription->set_next_renewal_date($expiry); |
|
385 | + $subscription->set_date_created(current_time('mysql')); |
|
386 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
387 | 387 | $subscription->activate(); |
388 | 388 | } |
389 | 389 | } |
390 | 390 | } |
391 | 391 | } else { |
392 | 392 | |
393 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
393 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
394 | 394 | |
395 | 395 | // Renew the subscription. |
396 | - if ( $subscription && $subscription->exists() ) { |
|
397 | - $subscription->add_payment( array(), $invoice ); |
|
396 | + if ($subscription && $subscription->exists()) { |
|
397 | + $subscription->add_payment(array(), $invoice); |
|
398 | 398 | $subscription->renew(); |
399 | 399 | } |
400 | 400 | } |
@@ -13,462 +13,462 @@ 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 | - // Add support for various features. |
|
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | - } |
|
152 | - |
|
153 | - // Invoice addons. |
|
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | - } |
|
157 | - |
|
158 | - // Gateway settings. |
|
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | - |
|
161 | - // Gateway checkout fiellds. |
|
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | - |
|
164 | - // Process payment. |
|
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | - |
|
167 | - // Change the checkout button text. |
|
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | - } |
|
171 | - |
|
172 | - // Check if a gateway is valid for a given currency. |
|
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | - |
|
175 | - // Generate the transaction url. |
|
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | - |
|
178 | - // Generate the subscription url. |
|
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | - |
|
181 | - // Confirm payments. |
|
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | - |
|
184 | - // Verify IPNs. |
|
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Checks if this gateway is a given gateway. |
|
191 | - * |
|
192 | - * @since 1.0.19 |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function is( $gateway ) { |
|
196 | - return $gateway == $this->id; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns a users saved tokens for this gateway. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - public function get_tokens( $sandbox = null ) { |
|
206 | - |
|
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | - |
|
210 | - if ( is_array( $tokens ) ) { |
|
211 | - $this->tokens = $tokens; |
|
212 | - } |
|
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 | + // Add support for various features. |
|
147 | + foreach ( $this->supports as $feature ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | + } |
|
152 | + |
|
153 | + // Invoice addons. |
|
154 | + if ( $this->supports( 'addons' ) ) { |
|
155 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | + } |
|
157 | + |
|
158 | + // Gateway settings. |
|
159 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | + |
|
161 | + // Gateway checkout fiellds. |
|
162 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | + |
|
164 | + // Process payment. |
|
165 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | + |
|
167 | + // Change the checkout button text. |
|
168 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | + } |
|
171 | + |
|
172 | + // Check if a gateway is valid for a given currency. |
|
173 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | + |
|
175 | + // Generate the transaction url. |
|
176 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | + |
|
178 | + // Generate the subscription url. |
|
179 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | + |
|
181 | + // Confirm payments. |
|
182 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | + |
|
184 | + // Verify IPNs. |
|
185 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Checks if this gateway is a given gateway. |
|
191 | + * |
|
192 | + * @since 1.0.19 |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function is( $gateway ) { |
|
196 | + return $gateway == $this->id; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns a users saved tokens for this gateway. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + public function get_tokens( $sandbox = null ) { |
|
206 | + |
|
207 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | + |
|
210 | + if ( is_array( $tokens ) ) { |
|
211 | + $this->tokens = $tokens; |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
216 | - return $this->tokens; |
|
217 | - } |
|
218 | - |
|
219 | - // Filter tokens. |
|
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Saves a token for this gateway. |
|
227 | - * |
|
228 | - * @since 1.0.19 |
|
229 | - */ |
|
230 | - public function save_token( $token ) { |
|
231 | - |
|
232 | - $tokens = $this->get_tokens(); |
|
233 | - $tokens[] = $token; |
|
234 | - |
|
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | - |
|
237 | - $this->tokens = $tokens; |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Return the title for admin screens. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function get_method_title() { |
|
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Return the description for admin screens. |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_method_description() { |
|
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the success url. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice Invoice object. |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_return_url( $invoice ) { |
|
266 | - |
|
267 | - // Payment success url |
|
268 | - $return_url = add_query_arg( |
|
269 | - array( |
|
270 | - 'payment-confirm' => $this->id, |
|
271 | - 'invoice_key' => $invoice->get_key(), |
|
272 | - 'utm_nooverride' => 1, |
|
273 | - ), |
|
274 | - wpinv_get_success_page_uri() |
|
275 | - ); |
|
276 | - |
|
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Confirms payments when rendering the success page. |
|
282 | - * |
|
283 | - * @param string $content Success page content. |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function confirm_payment( $content ) { |
|
287 | - |
|
288 | - // Retrieve the invoice. |
|
289 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | - |
|
292 | - // Ensure that it exists and that it is pending payment. |
|
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | - return $content; |
|
295 | - } |
|
296 | - |
|
297 | - // Can the user view this invoice?? |
|
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Show payment processing indicator. |
|
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Processes ipns and marks payments as complete. |
|
308 | - * |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - public function verify_ipn() {} |
|
312 | - |
|
313 | - /** |
|
314 | - * Processes invoice addons. |
|
315 | - * |
|
316 | - * @param WPInv_Invoice $invoice |
|
317 | - * @param GetPaid_Form_Item[] $items |
|
318 | - * @return WPInv_Invoice |
|
319 | - */ |
|
320 | - public function process_addons( $invoice, $items ) { |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | - * |
|
327 | - * @param string $transaction_url transaction url. |
|
328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
329 | - * @return string transaction URL, or empty string. |
|
330 | - */ |
|
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | - |
|
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
334 | - |
|
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | - } |
|
340 | - |
|
341 | - return $transaction_url; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | - * |
|
347 | - * @param string $subscription_url transaction url. |
|
348 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | - * @return string subscription URL, or empty string. |
|
350 | - */ |
|
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | - |
|
353 | - $profile_id = $subscription->get_profile_id(); |
|
354 | - |
|
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | - |
|
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - return $subscription_url; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Check if the gateway is available for use. |
|
368 | - * |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - public function is_available() { |
|
372 | - return ! empty( $this->enabled ); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Return the gateway's title. |
|
377 | - * |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_title() { |
|
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Return the gateway's description. |
|
386 | - * |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_description() { |
|
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Process Payment. |
|
395 | - * |
|
396 | - * |
|
397 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | - * @param array $submission_data Posted checkout fields. |
|
399 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | - * @return void |
|
401 | - */ |
|
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | - // Process the payment then either redirect to the success page or the gateway. |
|
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Process refund. |
|
409 | - * |
|
410 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | - * a passed in amount. |
|
412 | - * |
|
413 | - * @param WPInv_Invoice $invoice Invoice. |
|
414 | - * @param float $amount Refund amount. |
|
415 | - * @param string $reason Refund reason. |
|
416 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | - */ |
|
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Displays the payment fields, credit cards etc. |
|
424 | - * |
|
425 | - * @param int $invoice_id 0 or invoice id. |
|
426 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | - */ |
|
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Filters the gateway settings. |
|
434 | - * |
|
435 | - * @param array $admin_settings |
|
436 | - */ |
|
437 | - public function admin_settings( $admin_settings ) { |
|
438 | - return $admin_settings; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Retrieves the value of a gateway setting. |
|
443 | - * |
|
444 | - * @param string $option |
|
445 | - */ |
|
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Check if a gateway supports a given feature. |
|
452 | - * |
|
453 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | - * |
|
456 | - * @param string $feature string The name of a feature to test support for. |
|
457 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | - * @since 1.0.19 |
|
459 | - */ |
|
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the credit card form html. |
|
466 | - * |
|
467 | - * @param bool $save whether or not to display the save button. |
|
468 | - */ |
|
215 | + if ( ! is_bool( $sandbox ) ) { |
|
216 | + return $this->tokens; |
|
217 | + } |
|
218 | + |
|
219 | + // Filter tokens. |
|
220 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | + return wp_list_filter( $this->tokens, $args ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Saves a token for this gateway. |
|
227 | + * |
|
228 | + * @since 1.0.19 |
|
229 | + */ |
|
230 | + public function save_token( $token ) { |
|
231 | + |
|
232 | + $tokens = $this->get_tokens(); |
|
233 | + $tokens[] = $token; |
|
234 | + |
|
235 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | + |
|
237 | + $this->tokens = $tokens; |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Return the title for admin screens. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function get_method_title() { |
|
247 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Return the description for admin screens. |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_method_description() { |
|
256 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the success url. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice Invoice object. |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_return_url( $invoice ) { |
|
266 | + |
|
267 | + // Payment success url |
|
268 | + $return_url = add_query_arg( |
|
269 | + array( |
|
270 | + 'payment-confirm' => $this->id, |
|
271 | + 'invoice_key' => $invoice->get_key(), |
|
272 | + 'utm_nooverride' => 1, |
|
273 | + ), |
|
274 | + wpinv_get_success_page_uri() |
|
275 | + ); |
|
276 | + |
|
277 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Confirms payments when rendering the success page. |
|
282 | + * |
|
283 | + * @param string $content Success page content. |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function confirm_payment( $content ) { |
|
287 | + |
|
288 | + // Retrieve the invoice. |
|
289 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | + |
|
292 | + // Ensure that it exists and that it is pending payment. |
|
293 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | + return $content; |
|
295 | + } |
|
296 | + |
|
297 | + // Can the user view this invoice?? |
|
298 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Show payment processing indicator. |
|
303 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Processes ipns and marks payments as complete. |
|
308 | + * |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + public function verify_ipn() {} |
|
312 | + |
|
313 | + /** |
|
314 | + * Processes invoice addons. |
|
315 | + * |
|
316 | + * @param WPInv_Invoice $invoice |
|
317 | + * @param GetPaid_Form_Item[] $items |
|
318 | + * @return WPInv_Invoice |
|
319 | + */ |
|
320 | + public function process_addons( $invoice, $items ) { |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | + * |
|
327 | + * @param string $transaction_url transaction url. |
|
328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
329 | + * @return string transaction URL, or empty string. |
|
330 | + */ |
|
331 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | + |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | + |
|
335 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | + } |
|
340 | + |
|
341 | + return $transaction_url; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | + * |
|
347 | + * @param string $subscription_url transaction url. |
|
348 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | + * @return string subscription URL, or empty string. |
|
350 | + */ |
|
351 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | + |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | + |
|
355 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | + |
|
357 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + return $subscription_url; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Check if the gateway is available for use. |
|
368 | + * |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + public function is_available() { |
|
372 | + return ! empty( $this->enabled ); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Return the gateway's title. |
|
377 | + * |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_title() { |
|
381 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Return the gateway's description. |
|
386 | + * |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_description() { |
|
390 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Process Payment. |
|
395 | + * |
|
396 | + * |
|
397 | + * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param array $submission_data Posted checkout fields. |
|
399 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | + * @return void |
|
401 | + */ |
|
402 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | + // Process the payment then either redirect to the success page or the gateway. |
|
404 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Process refund. |
|
409 | + * |
|
410 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | + * a passed in amount. |
|
412 | + * |
|
413 | + * @param WPInv_Invoice $invoice Invoice. |
|
414 | + * @param float $amount Refund amount. |
|
415 | + * @param string $reason Refund reason. |
|
416 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | + */ |
|
418 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Displays the payment fields, credit cards etc. |
|
424 | + * |
|
425 | + * @param int $invoice_id 0 or invoice id. |
|
426 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | + */ |
|
428 | + public function payment_fields( $invoice_id, $form ) { |
|
429 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Filters the gateway settings. |
|
434 | + * |
|
435 | + * @param array $admin_settings |
|
436 | + */ |
|
437 | + public function admin_settings( $admin_settings ) { |
|
438 | + return $admin_settings; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Retrieves the value of a gateway setting. |
|
443 | + * |
|
444 | + * @param string $option |
|
445 | + */ |
|
446 | + public function get_option( $option, $default = false ) { |
|
447 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Check if a gateway supports a given feature. |
|
452 | + * |
|
453 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | + * |
|
456 | + * @param string $feature string The name of a feature to test support for. |
|
457 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | + * @since 1.0.19 |
|
459 | + */ |
|
460 | + public function supports( $feature ) { |
|
461 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the credit card form html. |
|
466 | + * |
|
467 | + * @param bool $save whether or not to display the save button. |
|
468 | + */ |
|
469 | 469 | public function get_cc_form( $save = false ) { |
470 | 470 | |
471 | - ob_start(); |
|
471 | + ob_start(); |
|
472 | 472 | |
473 | 473 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
474 | 474 | |
@@ -528,9 +528,9 @@ discard block |
||
528 | 528 | |
529 | 529 | <?php |
530 | 530 | foreach ( $months as $key => $month ) { |
531 | - $key = esc_attr( $key ); |
|
532 | - $month = esc_html( $month ); |
|
533 | - echo "<option value='$key'>$month</option>" . PHP_EOL; |
|
531 | + $key = esc_attr( $key ); |
|
532 | + $month = esc_html( $month ); |
|
533 | + echo "<option value='$key'>$month</option>" . PHP_EOL; |
|
534 | 534 | } |
535 | 535 | ?> |
536 | 536 | |
@@ -543,9 +543,9 @@ discard block |
||
543 | 543 | |
544 | 544 | <?php |
545 | 545 | foreach ( $years as $key => $year ) { |
546 | - $key = esc_attr( $key ); |
|
547 | - $year = esc_html( $year ); |
|
548 | - echo "<option value='$key'>$year</option>" . PHP_EOL; |
|
546 | + $key = esc_attr( $key ); |
|
547 | + $year = esc_html( $year ); |
|
548 | + echo "<option value='$key'>$year</option>" . PHP_EOL; |
|
549 | 549 | } |
550 | 550 | ?> |
551 | 551 | |
@@ -563,11 +563,11 @@ discard block |
||
563 | 563 | 'name' => $this->id . '[cc_cvv2]', |
564 | 564 | 'id' => "$id_prefix-cc-cvv2", |
565 | 565 | 'label' => __( 'CCV', 'invoicing' ), |
566 | - 'label_type' => 'vertical', |
|
567 | - 'class' => 'form-control-sm', |
|
568 | - 'extra_attributes' => array( |
|
569 | - 'autocomplete' => 'cc-csc', |
|
570 | - ), |
|
566 | + 'label_type' => 'vertical', |
|
567 | + 'class' => 'form-control-sm', |
|
568 | + 'extra_attributes' => array( |
|
569 | + 'autocomplete' => 'cc-csc', |
|
570 | + ), |
|
571 | 571 | ) |
572 | 572 | ); |
573 | 573 | ?> |
@@ -577,192 +577,192 @@ discard block |
||
577 | 577 | |
578 | 578 | <?php |
579 | 579 | |
580 | - if ( $save ) { |
|
581 | - echo $this->save_payment_method_checkbox(); |
|
582 | - } |
|
580 | + if ( $save ) { |
|
581 | + echo $this->save_payment_method_checkbox(); |
|
582 | + } |
|
583 | 583 | |
584 | - ?> |
|
584 | + ?> |
|
585 | 585 | </div> |
586 | 586 | |
587 | 587 | </div> |
588 | 588 | <?php |
589 | 589 | |
590 | - return ob_get_clean(); |
|
590 | + return ob_get_clean(); |
|
591 | + |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Displays a new payment method entry form. |
|
596 | + * |
|
597 | + * @since 1.0.19 |
|
598 | + */ |
|
599 | + public function new_payment_method_entry( $form ) { |
|
600 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Grab and display our saved payment methods. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + */ |
|
608 | + public function saved_payment_methods() { |
|
609 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | + |
|
611 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
613 | + } |
|
614 | + |
|
615 | + $html .= $this->get_new_payment_method_option_html(); |
|
616 | + $html .= '</ul>'; |
|
591 | 617 | |
618 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
592 | 619 | } |
593 | 620 | |
594 | - /** |
|
595 | - * Displays a new payment method entry form. |
|
596 | - * |
|
597 | - * @since 1.0.19 |
|
598 | - */ |
|
599 | - public function new_payment_method_entry( $form ) { |
|
600 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Grab and display our saved payment methods. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - */ |
|
608 | - public function saved_payment_methods() { |
|
609 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | - |
|
611 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
613 | - } |
|
614 | - |
|
615 | - $html .= $this->get_new_payment_method_option_html(); |
|
616 | - $html .= '</ul>'; |
|
617 | - |
|
618 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Gets saved payment method HTML from a token. |
|
623 | - * |
|
624 | - * @since 1.0.19 |
|
625 | - * @param array $token Payment Token. |
|
626 | - * @return string Generated payment method HTML |
|
627 | - */ |
|
628 | - public function get_saved_payment_method_option_html( $token ) { |
|
629 | - |
|
630 | - return sprintf( |
|
631 | - '<li class="getpaid-payment-method form-group"> |
|
621 | + /** |
|
622 | + * Gets saved payment method HTML from a token. |
|
623 | + * |
|
624 | + * @since 1.0.19 |
|
625 | + * @param array $token Payment Token. |
|
626 | + * @return string Generated payment method HTML |
|
627 | + */ |
|
628 | + public function get_saved_payment_method_option_html( $token ) { |
|
629 | + |
|
630 | + return sprintf( |
|
631 | + '<li class="getpaid-payment-method form-group"> |
|
632 | 632 | <label> |
633 | 633 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
634 | 634 | <span>%3$s</span> |
635 | 635 | </label> |
636 | 636 | </li>', |
637 | - esc_attr( $this->id ), |
|
638 | - esc_attr( $token['id'] ), |
|
639 | - esc_html( $token['name'] ), |
|
640 | - checked( empty( $token['default'] ), false, false ), |
|
641 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
642 | - ); |
|
643 | - |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
648 | - * |
|
649 | - * @since 1.0.19 |
|
650 | - */ |
|
651 | - public function get_new_payment_method_option_html() { |
|
652 | - |
|
653 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
654 | - |
|
655 | - return sprintf( |
|
656 | - '<li class="getpaid-new-payment-method"> |
|
637 | + esc_attr( $this->id ), |
|
638 | + esc_attr( $token['id'] ), |
|
639 | + esc_html( $token['name'] ), |
|
640 | + checked( empty( $token['default'] ), false, false ), |
|
641 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
642 | + ); |
|
643 | + |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
648 | + * |
|
649 | + * @since 1.0.19 |
|
650 | + */ |
|
651 | + public function get_new_payment_method_option_html() { |
|
652 | + |
|
653 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
654 | + |
|
655 | + return sprintf( |
|
656 | + '<li class="getpaid-new-payment-method"> |
|
657 | 657 | <label> |
658 | 658 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
659 | 659 | <span>%2$s</span> |
660 | 660 | </label> |
661 | 661 | </li>', |
662 | - esc_attr( $this->id ), |
|
663 | - esc_html( $label ) |
|
664 | - ); |
|
665 | - |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Outputs a checkbox for saving a new payment method to the database. |
|
670 | - * |
|
671 | - * @since 1.0.19 |
|
672 | - */ |
|
673 | - public function save_payment_method_checkbox() { |
|
674 | - |
|
675 | - return aui()->input( |
|
676 | - array( |
|
677 | - 'type' => 'checkbox', |
|
678 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
679 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
680 | - 'required' => false, |
|
681 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
682 | - 'value' => 'true', |
|
683 | - 'checked' => true, |
|
684 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
685 | - ) |
|
686 | - ); |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Registers the gateway. |
|
692 | - * |
|
693 | - * @return array |
|
694 | - */ |
|
695 | - public function register_gateway( $gateways ) { |
|
696 | - |
|
697 | - $gateways[ $this->id ] = array( |
|
698 | - |
|
699 | - 'admin_label' => $this->method_title, |
|
662 | + esc_attr( $this->id ), |
|
663 | + esc_html( $label ) |
|
664 | + ); |
|
665 | + |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Outputs a checkbox for saving a new payment method to the database. |
|
670 | + * |
|
671 | + * @since 1.0.19 |
|
672 | + */ |
|
673 | + public function save_payment_method_checkbox() { |
|
674 | + |
|
675 | + return aui()->input( |
|
676 | + array( |
|
677 | + 'type' => 'checkbox', |
|
678 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
679 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
680 | + 'required' => false, |
|
681 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
682 | + 'value' => 'true', |
|
683 | + 'checked' => true, |
|
684 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
685 | + ) |
|
686 | + ); |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Registers the gateway. |
|
692 | + * |
|
693 | + * @return array |
|
694 | + */ |
|
695 | + public function register_gateway( $gateways ) { |
|
696 | + |
|
697 | + $gateways[ $this->id ] = array( |
|
698 | + |
|
699 | + 'admin_label' => $this->method_title, |
|
700 | 700 | 'checkout_label' => $this->title, |
701 | - 'ordering' => $this->order, |
|
701 | + 'ordering' => $this->order, |
|
702 | 702 | |
703 | - ); |
|
703 | + ); |
|
704 | 704 | |
705 | - return $gateways; |
|
705 | + return $gateways; |
|
706 | 706 | |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - /** |
|
710 | - * Checks whether or not this is a sandbox request. |
|
711 | - * |
|
712 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | - * @return bool |
|
714 | - */ |
|
715 | - public function is_sandbox( $invoice = null ) { |
|
709 | + /** |
|
710 | + * Checks whether or not this is a sandbox request. |
|
711 | + * |
|
712 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | + public function is_sandbox( $invoice = null ) { |
|
716 | 716 | |
717 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | - return $invoice->get_mode() == 'test'; |
|
719 | - } |
|
717 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | + return $invoice->get_mode() == 'test'; |
|
719 | + } |
|
720 | 720 | |
721 | - return wpinv_is_test_mode( $this->id ); |
|
721 | + return wpinv_is_test_mode( $this->id ); |
|
722 | 722 | |
723 | - } |
|
723 | + } |
|
724 | 724 | |
725 | - /** |
|
726 | - * Renames the checkout button |
|
727 | - * |
|
728 | - * @return string |
|
729 | - */ |
|
730 | - public function rename_checkout_button() { |
|
731 | - return $this->checkout_button_text; |
|
732 | - } |
|
725 | + /** |
|
726 | + * Renames the checkout button |
|
727 | + * |
|
728 | + * @return string |
|
729 | + */ |
|
730 | + public function rename_checkout_button() { |
|
731 | + return $this->checkout_button_text; |
|
732 | + } |
|
733 | 733 | |
734 | - /** |
|
735 | - * Validate gateway currency |
|
736 | - * |
|
737 | - * @return bool |
|
738 | - */ |
|
739 | - public function validate_currency( $validation, $currency ) { |
|
734 | + /** |
|
735 | + * Validate gateway currency |
|
736 | + * |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | + public function validate_currency( $validation, $currency ) { |
|
740 | 740 | |
741 | - // Required currencies. |
|
742 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | - return false; |
|
744 | - } |
|
741 | + // Required currencies. |
|
742 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | + return false; |
|
744 | + } |
|
745 | 745 | |
746 | - // Excluded currencies. |
|
747 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | - return false; |
|
749 | - } |
|
746 | + // Excluded currencies. |
|
747 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | + return false; |
|
749 | + } |
|
750 | 750 | |
751 | - return $validation; |
|
752 | - } |
|
751 | + return $validation; |
|
752 | + } |
|
753 | 753 | |
754 | - /** |
|
755 | - * Displays an error |
|
756 | - * |
|
757 | - */ |
|
758 | - public function show_error( $code, $message, $type ) { |
|
754 | + /** |
|
755 | + * Displays an error |
|
756 | + * |
|
757 | + */ |
|
758 | + public function show_error( $code, $message, $type ) { |
|
759 | 759 | |
760 | - if ( is_admin() ) { |
|
761 | - getpaid_admin()->{"show_$type"}( $message ); |
|
762 | - } |
|
760 | + if ( is_admin() ) { |
|
761 | + getpaid_admin()->{"show_$type"}( $message ); |
|
762 | + } |
|
763 | 763 | |
764 | - wpinv_set_error( $code, $message, $type ); |
|
764 | + wpinv_set_error( $code, $message, $type ); |
|
765 | 765 | |
766 | - } |
|
766 | + } |
|
767 | 767 | |
768 | 768 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Abstaract Payment Gateway class. |
@@ -139,50 +139,50 @@ discard block |
||
139 | 139 | public function __construct() { |
140 | 140 | |
141 | 141 | // Register gateway. |
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
142 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
143 | 143 | |
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
144 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
145 | 145 | |
146 | 146 | // Add support for various features. |
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
147 | + foreach ($this->supports as $feature) { |
|
148 | + add_filter("wpinv_{$this->id}_support_{$feature}", '__return_true'); |
|
149 | + add_filter("getpaid_{$this->id}_support_{$feature}", '__return_true'); |
|
150 | + add_filter("getpaid_{$this->id}_supports_{$feature}", '__return_true'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Invoice addons. |
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
154 | + if ($this->supports('addons')) { |
|
155 | + add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Gateway settings. |
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
159 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
160 | 160 | |
161 | 161 | // Gateway checkout fiellds. |
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
163 | 163 | |
164 | 164 | // Process payment. |
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
165 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
166 | 166 | |
167 | 167 | // Change the checkout button text. |
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | + if (!empty($this->checkout_button_text)) { |
|
169 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Check if a gateway is valid for a given currency. |
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
174 | 174 | |
175 | 175 | // Generate the transaction url. |
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
177 | 177 | |
178 | 178 | // Generate the subscription url. |
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
179 | + add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2); |
|
180 | 180 | |
181 | 181 | // Confirm payments. |
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
183 | 183 | |
184 | 184 | // Verify IPNs. |
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
186 | 186 | |
187 | 187 | } |
188 | 188 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @since 1.0.19 |
193 | 193 | * @return bool |
194 | 194 | */ |
195 | - public function is( $gateway ) { |
|
195 | + public function is($gateway) { |
|
196 | 196 | return $gateway == $this->id; |
197 | 197 | } |
198 | 198 | |
@@ -202,23 +202,23 @@ discard block |
||
202 | 202 | * @since 1.0.19 |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - public function get_tokens( $sandbox = null ) { |
|
205 | + public function get_tokens($sandbox = null) { |
|
206 | 206 | |
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
208 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
209 | 209 | |
210 | - if ( is_array( $tokens ) ) { |
|
210 | + if (is_array($tokens)) { |
|
211 | 211 | $this->tokens = $tokens; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
215 | + if (!is_bool($sandbox)) { |
|
216 | 216 | return $this->tokens; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Filter tokens. |
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
220 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
221 | + return wp_list_filter($this->tokens, $args); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @since 1.0.19 |
229 | 229 | */ |
230 | - public function save_token( $token ) { |
|
230 | + public function save_token($token) { |
|
231 | 231 | |
232 | 232 | $tokens = $this->get_tokens(); |
233 | 233 | $tokens[] = $token; |
234 | 234 | |
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
235 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
236 | 236 | |
237 | 237 | $this->tokens = $tokens; |
238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return string |
245 | 245 | */ |
246 | 246 | public function get_method_title() { |
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
247 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return string |
254 | 254 | */ |
255 | 255 | public function get_method_description() { |
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
256 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param WPInv_Invoice $invoice Invoice object. |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public function get_return_url( $invoice ) { |
|
265 | + public function get_return_url($invoice) { |
|
266 | 266 | |
267 | 267 | // Payment success url |
268 | 268 | $return_url = add_query_arg( |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | wpinv_get_success_page_uri() |
275 | 275 | ); |
276 | 276 | |
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
277 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -283,24 +283,24 @@ discard block |
||
283 | 283 | * @param string $content Success page content. |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - public function confirm_payment( $content ) { |
|
286 | + public function confirm_payment($content) { |
|
287 | 287 | |
288 | 288 | // Retrieve the invoice. |
289 | 289 | $invoice_id = getpaid_get_current_invoice_id(); |
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
290 | + $invoice = wpinv_get_invoice($invoice_id); |
|
291 | 291 | |
292 | 292 | // Ensure that it exists and that it is pending payment. |
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
293 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
294 | 294 | return $content; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Can the user view this invoice?? |
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
298 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
299 | 299 | return $content; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Show payment processing indicator. |
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
303 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @param GetPaid_Form_Item[] $items |
318 | 318 | * @return WPInv_Invoice |
319 | 319 | */ |
320 | - public function process_addons( $invoice, $items ) { |
|
320 | + public function process_addons($invoice, $items) { |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * @param WPInv_Invoice $invoice Invoice object. |
329 | 329 | * @return string transaction URL, or empty string. |
330 | 330 | */ |
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
331 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
332 | 332 | |
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | 334 | |
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
335 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
336 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
337 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $transaction_url; |
@@ -348,15 +348,15 @@ discard block |
||
348 | 348 | * @param WPInv_Subscription $subscription Subscription objectt. |
349 | 349 | * @return string subscription URL, or empty string. |
350 | 350 | */ |
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
351 | + public function generate_subscription_url($subscription_url, $subscription) { |
|
352 | 352 | |
353 | - $profile_id = $subscription->get_profile_id(); |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | 354 | |
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
355 | + if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) { |
|
356 | 356 | |
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
357 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
358 | + $replace = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
360 | 360 | |
361 | 361 | } |
362 | 362 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return bool |
370 | 370 | */ |
371 | 371 | public function is_available() { |
372 | - return ! empty( $this->enabled ); |
|
372 | + return !empty($this->enabled); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @return string |
379 | 379 | */ |
380 | 380 | public function get_title() { |
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
381 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @return string |
388 | 388 | */ |
389 | 389 | public function get_description() { |
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
390 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -399,9 +399,9 @@ discard block |
||
399 | 399 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
400 | 400 | * @return void |
401 | 401 | */ |
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
402 | + public function process_payment($invoice, $submission_data, $submission) { |
|
403 | 403 | // Process the payment then either redirect to the success page or the gateway. |
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
404 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | * @param string $reason Refund reason. |
416 | 416 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
417 | 417 | */ |
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
418 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
419 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | * @param int $invoice_id 0 or invoice id. |
426 | 426 | * @param GetPaid_Payment_Form $form Current payment form. |
427 | 427 | */ |
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
428 | + public function payment_fields($invoice_id, $form) { |
|
429 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @param array $admin_settings |
436 | 436 | */ |
437 | - public function admin_settings( $admin_settings ) { |
|
437 | + public function admin_settings($admin_settings) { |
|
438 | 438 | return $admin_settings; |
439 | 439 | } |
440 | 440 | |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @param string $option |
445 | 445 | */ |
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
446 | + public function get_option($option, $default = false) { |
|
447 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -457,8 +457,8 @@ discard block |
||
457 | 457 | * @return bool True if the gateway supports the feature, false otherwise. |
458 | 458 | * @since 1.0.19 |
459 | 459 | */ |
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
460 | + public function supports($feature) { |
|
461 | + return getpaid_payment_gateway_supports($this->id, $feature); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -466,36 +466,36 @@ discard block |
||
466 | 466 | * |
467 | 467 | * @param bool $save whether or not to display the save button. |
468 | 468 | */ |
469 | - public function get_cc_form( $save = false ) { |
|
469 | + public function get_cc_form($save = false) { |
|
470 | 470 | |
471 | 471 | ob_start(); |
472 | 472 | |
473 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
473 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
474 | 474 | |
475 | 475 | $months = array( |
476 | - '01' => __( 'January', 'invoicing' ), |
|
477 | - '02' => __( 'February', 'invoicing' ), |
|
478 | - '03' => __( 'March', 'invoicing' ), |
|
479 | - '04' => __( 'April', 'invoicing' ), |
|
480 | - '05' => __( 'May', 'invoicing' ), |
|
481 | - '06' => __( 'June', 'invoicing' ), |
|
482 | - '07' => __( 'July', 'invoicing' ), |
|
483 | - '08' => __( 'August', 'invoicing' ), |
|
484 | - '09' => __( 'September', 'invoicing' ), |
|
485 | - '10' => __( 'October', 'invoicing' ), |
|
486 | - '11' => __( 'November', 'invoicing' ), |
|
487 | - '12' => __( 'December', 'invoicing' ), |
|
476 | + '01' => __('January', 'invoicing'), |
|
477 | + '02' => __('February', 'invoicing'), |
|
478 | + '03' => __('March', 'invoicing'), |
|
479 | + '04' => __('April', 'invoicing'), |
|
480 | + '05' => __('May', 'invoicing'), |
|
481 | + '06' => __('June', 'invoicing'), |
|
482 | + '07' => __('July', 'invoicing'), |
|
483 | + '08' => __('August', 'invoicing'), |
|
484 | + '09' => __('September', 'invoicing'), |
|
485 | + '10' => __('October', 'invoicing'), |
|
486 | + '11' => __('November', 'invoicing'), |
|
487 | + '12' => __('December', 'invoicing'), |
|
488 | 488 | ); |
489 | 489 | |
490 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
490 | + $year = (int) date('Y', current_time('timestamp')); |
|
491 | 491 | $years = array(); |
492 | 492 | |
493 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
494 | - $years[ $year + $i ] = $year + $i; |
|
493 | + for ($i = 0; $i <= 10; $i++) { |
|
494 | + $years[$year + $i] = $year + $i; |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | ?> |
498 | - <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
|
498 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1"> |
|
499 | 499 | |
500 | 500 | |
501 | 501 | <div class="getpaid-cc-card-inner"> |
@@ -504,14 +504,14 @@ discard block |
||
504 | 504 | <div class="col-12"> |
505 | 505 | |
506 | 506 | <div class="form-group"> |
507 | - <label for="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>"><?php _e( 'Card number', 'invoicing' ); ?></label> |
|
507 | + <label for="<?php echo esc_attr("$id_prefix-cc-number"); ?>"><?php _e('Card number', 'invoicing'); ?></label> |
|
508 | 508 | <div class="input-group input-group-sm"> |
509 | 509 | <div class="input-group-prepend "> |
510 | 510 | <span class="input-group-text"> |
511 | 511 | <i class="fa fa-credit-card"></i> |
512 | 512 | </span> |
513 | 513 | </div> |
514 | - <input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ); ?>" id="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
514 | + <input type="text" name="<?php echo esc_attr($this->id . '[cc_number]'); ?>" id="<?php echo esc_attr("$id_prefix-cc-number"); ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
515 | 515 | </div> |
516 | 516 | </div> |
517 | 517 | |
@@ -519,17 +519,17 @@ discard block |
||
519 | 519 | |
520 | 520 | <div class="col-12"> |
521 | 521 | <div class="form-group"> |
522 | - <label><?php _e( 'Expiration', 'invoicing' ); ?></label> |
|
522 | + <label><?php _e('Expiration', 'invoicing'); ?></label> |
|
523 | 523 | <div class="form-row"> |
524 | 524 | |
525 | 525 | <div class="col"> |
526 | - <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_month]"> |
|
527 | - <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option> |
|
526 | + <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
527 | + <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option> |
|
528 | 528 | |
529 | 529 | <?php |
530 | - foreach ( $months as $key => $month ) { |
|
531 | - $key = esc_attr( $key ); |
|
532 | - $month = esc_html( $month ); |
|
530 | + foreach ($months as $key => $month) { |
|
531 | + $key = esc_attr($key); |
|
532 | + $month = esc_html($month); |
|
533 | 533 | echo "<option value='$key'>$month</option>" . PHP_EOL; |
534 | 534 | } |
535 | 535 | ?> |
@@ -538,13 +538,13 @@ discard block |
||
538 | 538 | </div> |
539 | 539 | |
540 | 540 | <div class="col"> |
541 | - <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_year]"> |
|
542 | - <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option> |
|
541 | + <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
542 | + <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option> |
|
543 | 543 | |
544 | 544 | <?php |
545 | - foreach ( $years as $key => $year ) { |
|
546 | - $key = esc_attr( $key ); |
|
547 | - $year = esc_html( $year ); |
|
545 | + foreach ($years as $key => $year) { |
|
546 | + $key = esc_attr($key); |
|
547 | + $year = esc_html($year); |
|
548 | 548 | echo "<option value='$key'>$year</option>" . PHP_EOL; |
549 | 549 | } |
550 | 550 | ?> |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | array( |
563 | 563 | 'name' => $this->id . '[cc_cvv2]', |
564 | 564 | 'id' => "$id_prefix-cc-cvv2", |
565 | - 'label' => __( 'CCV', 'invoicing' ), |
|
565 | + 'label' => __('CCV', 'invoicing'), |
|
566 | 566 | 'label_type' => 'vertical', |
567 | 567 | 'class' => 'form-control-sm', |
568 | 568 | 'extra_attributes' => array( |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | |
578 | 578 | <?php |
579 | 579 | |
580 | - if ( $save ) { |
|
580 | + if ($save) { |
|
581 | 581 | echo $this->save_payment_method_checkbox(); |
582 | 582 | } |
583 | 583 | |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * |
597 | 597 | * @since 1.0.19 |
598 | 598 | */ |
599 | - public function new_payment_method_entry( $form ) { |
|
599 | + public function new_payment_method_entry($form) { |
|
600 | 600 | echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
601 | 601 | } |
602 | 602 | |
@@ -606,16 +606,16 @@ discard block |
||
606 | 606 | * @since 1.0.19 |
607 | 607 | */ |
608 | 608 | public function saved_payment_methods() { |
609 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
609 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
610 | 610 | |
611 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
611 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
612 | + $html .= $this->get_saved_payment_method_option_html($token); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | $html .= $this->get_new_payment_method_option_html(); |
616 | 616 | $html .= '</ul>'; |
617 | 617 | |
618 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
618 | + echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | * @param array $token Payment Token. |
626 | 626 | * @return string Generated payment method HTML |
627 | 627 | */ |
628 | - public function get_saved_payment_method_option_html( $token ) { |
|
628 | + public function get_saved_payment_method_option_html($token) { |
|
629 | 629 | |
630 | 630 | return sprintf( |
631 | 631 | '<li class="getpaid-payment-method form-group"> |
@@ -634,11 +634,11 @@ discard block |
||
634 | 634 | <span>%3$s</span> |
635 | 635 | </label> |
636 | 636 | </li>', |
637 | - esc_attr( $this->id ), |
|
638 | - esc_attr( $token['id'] ), |
|
639 | - esc_html( $token['name'] ), |
|
640 | - checked( empty( $token['default'] ), false, false ), |
|
641 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
637 | + esc_attr($this->id), |
|
638 | + esc_attr($token['id']), |
|
639 | + esc_html($token['name']), |
|
640 | + checked(empty($token['default']), false, false), |
|
641 | + empty($token['currency']) ? 'none' : esc_attr($token['currency']) |
|
642 | 642 | ); |
643 | 643 | |
644 | 644 | } |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | */ |
651 | 651 | public function get_new_payment_method_option_html() { |
652 | 652 | |
653 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
653 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
654 | 654 | |
655 | 655 | return sprintf( |
656 | 656 | '<li class="getpaid-new-payment-method"> |
@@ -659,8 +659,8 @@ discard block |
||
659 | 659 | <span>%2$s</span> |
660 | 660 | </label> |
661 | 661 | </li>', |
662 | - esc_attr( $this->id ), |
|
663 | - esc_html( $label ) |
|
662 | + esc_attr($this->id), |
|
663 | + esc_html($label) |
|
664 | 664 | ); |
665 | 665 | |
666 | 666 | } |
@@ -675,10 +675,10 @@ discard block |
||
675 | 675 | return aui()->input( |
676 | 676 | array( |
677 | 677 | 'type' => 'checkbox', |
678 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
679 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
678 | + 'name' => esc_attr("getpaid-$this->id-new-payment-method"), |
|
679 | + 'id' => esc_attr(uniqid($this->id)), |
|
680 | 680 | 'required' => false, |
681 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
681 | + 'label' => esc_html__('Save payment method', 'invoicing'), |
|
682 | 682 | 'value' => 'true', |
683 | 683 | 'checked' => true, |
684 | 684 | 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
@@ -692,9 +692,9 @@ discard block |
||
692 | 692 | * |
693 | 693 | * @return array |
694 | 694 | */ |
695 | - public function register_gateway( $gateways ) { |
|
695 | + public function register_gateway($gateways) { |
|
696 | 696 | |
697 | - $gateways[ $this->id ] = array( |
|
697 | + $gateways[$this->id] = array( |
|
698 | 698 | |
699 | 699 | 'admin_label' => $this->method_title, |
700 | 700 | 'checkout_label' => $this->title, |
@@ -712,13 +712,13 @@ discard block |
||
712 | 712 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
713 | 713 | * @return bool |
714 | 714 | */ |
715 | - public function is_sandbox( $invoice = null ) { |
|
715 | + public function is_sandbox($invoice = null) { |
|
716 | 716 | |
717 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
717 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
718 | 718 | return $invoice->get_mode() == 'test'; |
719 | 719 | } |
720 | 720 | |
721 | - return wpinv_is_test_mode( $this->id ); |
|
721 | + return wpinv_is_test_mode($this->id); |
|
722 | 722 | |
723 | 723 | } |
724 | 724 | |
@@ -736,15 +736,15 @@ discard block |
||
736 | 736 | * |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function validate_currency( $validation, $currency ) { |
|
739 | + public function validate_currency($validation, $currency) { |
|
740 | 740 | |
741 | 741 | // Required currencies. |
742 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
742 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
743 | 743 | return false; |
744 | 744 | } |
745 | 745 | |
746 | 746 | // Excluded currencies. |
747 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
747 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
748 | 748 | return false; |
749 | 749 | } |
750 | 750 | |
@@ -755,13 +755,13 @@ discard block |
||
755 | 755 | * Displays an error |
756 | 756 | * |
757 | 757 | */ |
758 | - public function show_error( $code, $message, $type ) { |
|
758 | + public function show_error($code, $message, $type) { |
|
759 | 759 | |
760 | - if ( is_admin() ) { |
|
761 | - getpaid_admin()->{"show_$type"}( $message ); |
|
760 | + if (is_admin()) { |
|
761 | + getpaid_admin()->{"show_$type"}($message); |
|
762 | 762 | } |
763 | 763 | |
764 | - wpinv_set_error( $code, $message, $type ); |
|
764 | + wpinv_set_error($code, $message, $type); |
|
765 | 765 | |
766 | 766 | } |
767 | 767 |
@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_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 = 'authorizenet'; |
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', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
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 = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Retrieves a customer profile. |
|
186 | - * |
|
187 | - * |
|
188 | - * @param string $profile_id profile id. |
|
189 | - * @return string|WP_Error Profile id. |
|
185 | + * Retrieves a customer profile. |
|
186 | + * |
|
187 | + * |
|
188 | + * @param string $profile_id profile id. |
|
189 | + * @return string|WP_Error Profile id. |
|
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | - */ |
|
192 | - public function get_customer_profile( $profile_id ) { |
|
191 | + */ |
|
192 | + public function get_customer_profile( $profile_id ) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Creates a customer profile. |
|
208 | - * |
|
209 | - * |
|
207 | + * Creates a customer profile. |
|
208 | + * |
|
209 | + * |
|
210 | 210 | * @param string $profile_id profile id. |
211 | - * @param WPInv_Invoice $invoice Invoice. |
|
211 | + * @param WPInv_Invoice $invoice Invoice. |
|
212 | 212 | * @param array $submission_data Posted checkout fields. |
213 | 213 | * @param bool $save Whether or not to save the payment as a token. |
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | - * @return string|WP_Error Profile id. |
|
216 | - */ |
|
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
215 | + * @return string|WP_Error Profile id. |
|
216 | + */ |
|
217 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | 220 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | - * Retrieves payment details from cache. |
|
306 | - * |
|
307 | - * |
|
305 | + * Retrieves payment details from cache. |
|
306 | + * |
|
307 | + * |
|
308 | 308 | * @param array $payment_details. |
309 | - * @return array|false Profile id. |
|
310 | - */ |
|
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
309 | + * @return array|false Profile id. |
|
310 | + */ |
|
311 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
312 | 312 | |
313 | 313 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
314 | 314 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -333,13 +333,13 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Securely adds payment details to cache. |
|
337 | - * |
|
338 | - * |
|
336 | + * Securely adds payment details to cache. |
|
337 | + * |
|
338 | + * |
|
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | - */ |
|
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
341 | + */ |
|
342 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
343 | 343 | |
344 | 344 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
345 | 345 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -351,15 +351,15 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
354 | - * Retrieves a customer payment profile. |
|
355 | - * |
|
356 | - * |
|
357 | - * @param string $customer_profile_id customer profile id. |
|
354 | + * Retrieves a customer payment profile. |
|
355 | + * |
|
356 | + * |
|
357 | + * @param string $customer_profile_id customer profile id. |
|
358 | 358 | * @param string $payment_profile_id payment profile id. |
359 | - * @return string|WP_Error Profile id. |
|
359 | + * @return string|WP_Error Profile id. |
|
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | - */ |
|
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
361 | + */ |
|
362 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -375,15 +375,15 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | - * Charges a customer payment profile. |
|
379 | - * |
|
378 | + * Charges a customer payment profile. |
|
379 | + * |
|
380 | 380 | * @param string $customer_profile_id customer profile id. |
381 | 381 | * @param string $payment_profile_id payment profile id. |
382 | - * @param WPInv_Invoice $invoice Invoice. |
|
382 | + * @param WPInv_Invoice $invoice Invoice. |
|
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | - * @return WP_Error|object |
|
385 | - */ |
|
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
384 | + * @return WP_Error|object |
|
385 | + */ |
|
386 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -429,41 +429,41 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
432 | - * Processes a customer charge. |
|
433 | - * |
|
432 | + * Processes a customer charge. |
|
433 | + * |
|
434 | 434 | * @param stdClass $result Api response. |
435 | - * @param WPInv_Invoice $invoice Invoice. |
|
436 | - */ |
|
437 | - public function process_charge_response( $result, $invoice ) { |
|
435 | + * @param WPInv_Invoice $invoice Invoice. |
|
436 | + */ |
|
437 | + public function process_charge_response( $result, $invoice ) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
440 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
441 | 441 | |
442 | - // Succeeded. |
|
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
442 | + // Succeeded. |
|
443 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
444 | 444 | |
445 | - // Maybe set a transaction id. |
|
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | - } |
|
445 | + // Maybe set a transaction id. |
|
446 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | + } |
|
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
453 | - return $invoice->mark_paid(); |
|
454 | - } |
|
452 | + if ( 1 == $response_code ) { |
|
453 | + return $invoice->mark_paid(); |
|
454 | + } |
|
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
457 | - $invoice->add_note( |
|
456 | + $invoice->set_status( 'wpi-onhold' ); |
|
457 | + $invoice->add_note( |
|
458 | 458 | sprintf( |
459 | 459 | __( 'Held for review: %s', 'invoicing' ), |
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | - ); |
|
462 | + ); |
|
463 | 463 | |
464 | - return $invoice->save(); |
|
464 | + return $invoice->save(); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | 468 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
469 | 469 | |
@@ -475,13 +475,13 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | - * Returns payment information. |
|
479 | - * |
|
480 | - * |
|
481 | - * @param array $card Card details. |
|
482 | - * @return array |
|
483 | - */ |
|
484 | - public function get_payment_information( $card ) { |
|
478 | + * Returns payment information. |
|
479 | + * |
|
480 | + * |
|
481 | + * @param array $card Card details. |
|
482 | + * @return array |
|
483 | + */ |
|
484 | + public function get_payment_information( $card ) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -494,25 +494,25 @@ discard block |
||
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
497 | - * Returns the customer profile meta name. |
|
498 | - * |
|
499 | - * |
|
500 | - * @param WPInv_Invoice $invoice Invoice. |
|
501 | - * @return string |
|
502 | - */ |
|
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
497 | + * Returns the customer profile meta name. |
|
498 | + * |
|
499 | + * |
|
500 | + * @param WPInv_Invoice $invoice Invoice. |
|
501 | + * @return string |
|
502 | + */ |
|
503 | + public function get_customer_profile_meta_name( $invoice ) { |
|
504 | 504 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
508 | - * Validates the submitted data. |
|
509 | - * |
|
510 | - * |
|
511 | - * @param array $submission_data Posted checkout fields. |
|
508 | + * Validates the submitted data. |
|
509 | + * |
|
510 | + * |
|
511 | + * @param array $submission_data Posted checkout fields. |
|
512 | 512 | * @param WPInv_Invoice $invoice |
513 | - * @return WP_Error|string The payment profile id |
|
514 | - */ |
|
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
513 | + * @return WP_Error|string The payment profile id |
|
514 | + */ |
|
515 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
@@ -544,13 +544,13 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Returns invoice line items. |
|
548 | - * |
|
549 | - * |
|
550 | - * @param WPInv_Invoice $invoice Invoice. |
|
551 | - * @return array |
|
552 | - */ |
|
553 | - public function get_line_items( $invoice ) { |
|
547 | + * Returns invoice line items. |
|
548 | + * |
|
549 | + * |
|
550 | + * @param WPInv_Invoice $invoice Invoice. |
|
551 | + * @return array |
|
552 | + */ |
|
553 | + public function get_line_items( $invoice ) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | 556 | foreach ( $invoice->get_items() as $item ) { |
@@ -587,15 +587,15 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
590 | - * Process Payment. |
|
591 | - * |
|
592 | - * |
|
593 | - * @param WPInv_Invoice $invoice Invoice. |
|
594 | - * @param array $submission_data Posted checkout fields. |
|
595 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | - * @return array |
|
597 | - */ |
|
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
590 | + * Process Payment. |
|
591 | + * |
|
592 | + * |
|
593 | + * @param WPInv_Invoice $invoice Invoice. |
|
594 | + * @param array $submission_data Posted checkout fields. |
|
595 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | + * @return array |
|
597 | + */ |
|
598 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | 601 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -628,45 +628,45 @@ discard block |
||
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
631 | - } |
|
631 | + } |
|
632 | 632 | |
633 | - /** |
|
634 | - * Processes the initial payment. |
|
635 | - * |
|
633 | + /** |
|
634 | + * Processes the initial payment. |
|
635 | + * |
|
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | - */ |
|
638 | - protected function process_initial_payment( $invoice ) { |
|
637 | + */ |
|
638 | + protected function process_initial_payment( $invoice ) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
640 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | 641 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
642 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
643 | 643 | |
644 | - // Do we have an error? |
|
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
648 | - } |
|
644 | + // Do we have an error? |
|
645 | + if ( is_wp_error( $result ) ) { |
|
646 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | + wpinv_send_back_to_checkout( $invoice ); |
|
648 | + } |
|
649 | 649 | |
650 | - // Process the response. |
|
651 | - $this->process_charge_response( $result, $invoice ); |
|
650 | + // Process the response. |
|
651 | + $this->process_charge_response( $result, $invoice ); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
655 | - } |
|
653 | + if ( wpinv_get_errors() ) { |
|
654 | + wpinv_send_back_to_checkout( $invoice ); |
|
655 | + } |
|
656 | 656 | |
657 | - } |
|
657 | + } |
|
658 | 658 | |
659 | 659 | /** |
660 | - * Processes recurring payments. |
|
661 | - * |
|
660 | + * Processes recurring payments. |
|
661 | + * |
|
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | - */ |
|
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
664 | + */ |
|
665 | + public function process_subscription( $invoice, $subscriptions ) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | 668 | if ( (float) $invoice->get_total() > 0 ) { |
669 | - $this->process_initial_payment( $invoice ); |
|
669 | + $this->process_initial_payment( $invoice ); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
@@ -684,36 +684,36 @@ discard block |
||
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | - // Redirect to the success page. |
|
687 | + // Redirect to the success page. |
|
688 | 688 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
689 | 689 | |
690 | 690 | } |
691 | 691 | |
692 | - /** |
|
693 | - * (Maybe) renews an authorize.net subscription profile. |
|
694 | - * |
|
695 | - * |
|
692 | + /** |
|
693 | + * (Maybe) renews an authorize.net subscription profile. |
|
694 | + * |
|
695 | + * |
|
696 | 696 | * @param WPInv_Subscription $subscription |
697 | - */ |
|
698 | - public function maybe_renew_subscription( $subscription ) { |
|
697 | + */ |
|
698 | + public function maybe_renew_subscription( $subscription ) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | 701 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
702 | 702 | $this->renew_subscription( $subscription ); |
703 | 703 | } |
704 | 704 | |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | 707 | /** |
708 | - * Renews a subscription. |
|
709 | - * |
|
708 | + * Renews a subscription. |
|
709 | + * |
|
710 | 710 | * @param WPInv_Subscription $subscription |
711 | - */ |
|
712 | - public function renew_subscription( $subscription ) { |
|
711 | + */ |
|
712 | + public function renew_subscription( $subscription ) { |
|
713 | 713 | |
714 | - // Generate the renewal invoice. |
|
715 | - $new_invoice = $subscription->create_payment(); |
|
716 | - $old_invoice = $subscription->get_parent_payment(); |
|
714 | + // Generate the renewal invoice. |
|
715 | + $new_invoice = $subscription->create_payment(); |
|
716 | + $old_invoice = $subscription->get_parent_payment(); |
|
717 | 717 | |
718 | 718 | if ( empty( $new_invoice ) ) { |
719 | 719 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -722,37 +722,37 @@ discard block |
||
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | - |
|
729 | - // Do we have an error? |
|
730 | - if ( is_wp_error( $result ) ) { |
|
731 | - |
|
732 | - $old_invoice->add_note( |
|
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | - true, |
|
735 | - false, |
|
736 | - true |
|
737 | - ); |
|
738 | - $subscription->failing(); |
|
739 | - return; |
|
740 | - |
|
741 | - } |
|
742 | - |
|
743 | - // Process the response. |
|
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
745 | - |
|
746 | - if ( wpinv_get_errors() ) { |
|
747 | - |
|
748 | - $old_invoice->add_note( |
|
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | - true, |
|
751 | - false, |
|
752 | - true |
|
753 | - ); |
|
754 | - $subscription->failing(); |
|
755 | - return; |
|
725 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | + |
|
729 | + // Do we have an error? |
|
730 | + if ( is_wp_error( $result ) ) { |
|
731 | + |
|
732 | + $old_invoice->add_note( |
|
733 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | + true, |
|
735 | + false, |
|
736 | + true |
|
737 | + ); |
|
738 | + $subscription->failing(); |
|
739 | + return; |
|
740 | + |
|
741 | + } |
|
742 | + |
|
743 | + // Process the response. |
|
744 | + $this->process_charge_response( $result, $new_invoice ); |
|
745 | + |
|
746 | + if ( wpinv_get_errors() ) { |
|
747 | + |
|
748 | + $old_invoice->add_note( |
|
749 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | + true, |
|
751 | + false, |
|
752 | + true |
|
753 | + ); |
|
754 | + $subscription->failing(); |
|
755 | + return; |
|
756 | 756 | |
757 | 757 | } |
758 | 758 | |
@@ -761,13 +761,13 @@ discard block |
||
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
764 | - * Processes invoice addons. |
|
765 | - * |
|
766 | - * @param WPInv_Invoice $invoice |
|
767 | - * @param GetPaid_Form_Item[] $items |
|
768 | - * @return WPInv_Invoice |
|
769 | - */ |
|
770 | - public function process_addons( $invoice, $items ) { |
|
764 | + * Processes invoice addons. |
|
765 | + * |
|
766 | + * @param WPInv_Invoice $invoice |
|
767 | + * @param GetPaid_Form_Item[] $items |
|
768 | + * @return WPInv_Invoice |
|
769 | + */ |
|
770 | + public function process_addons( $invoice, $items ) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | 788 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
789 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
790 | 790 | |
791 | 791 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
792 | 792 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -801,11 +801,11 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Processes invoice addons. |
|
805 | - * |
|
804 | + * Processes invoice addons. |
|
805 | + * |
|
806 | 806 | * @param array $args |
807 | - * @return array |
|
808 | - */ |
|
807 | + * @return array |
|
808 | + */ |
|
809 | 809 | public function filter_addons_request( $args ) { |
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
@@ -839,11 +839,11 @@ discard block |
||
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
842 | - * Filters the gateway settings. |
|
843 | - * |
|
844 | - * @param array $admin_settings |
|
845 | - */ |
|
846 | - public function admin_settings( $admin_settings ) { |
|
842 | + * Filters the gateway settings. |
|
843 | + * |
|
844 | + * @param array $admin_settings |
|
845 | + */ |
|
846 | + public function admin_settings( $admin_settings ) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | 849 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
885 | 885 | |
886 | - return $admin_settings; |
|
887 | - } |
|
886 | + return $admin_settings; |
|
887 | + } |
|
888 | 888 | |
889 | 889 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
73 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | echo $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - echo $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + echo $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,79 +100,79 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ), |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ), |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | |
142 | 142 | // In case the payment profile already exists remotely. |
143 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
144 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
145 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
146 | - return strtok( '.' ); |
|
143 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
144 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
145 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
146 | + return strtok('.'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // In case the customer profile already exists remotely. |
150 | - if ( 'E00039' == $response->get_error_code() ) { |
|
151 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
152 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
153 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
150 | + if ('E00039' == $response->get_error_code()) { |
|
151 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
152 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
153 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $response; |
157 | 157 | } |
158 | 158 | |
159 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
159 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
160 | 160 | |
161 | 161 | // Save the payment token. |
162 | - if ( $save ) { |
|
162 | + if ($save) { |
|
163 | 163 | $this->save_token( |
164 | 164 | array( |
165 | 165 | 'id' => $response->customerPaymentProfileIdList[0], |
166 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
166 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
167 | 167 | 'default' => true, |
168 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
168 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Add a note about the validation response. |
174 | 174 | $invoice->add_note( |
175 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
175 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
176 | 176 | false, |
177 | 177 | false, |
178 | 178 | true |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return string|WP_Error Profile id. |
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | 191 | */ |
192 | - public function get_customer_profile( $profile_id ) { |
|
192 | + public function get_customer_profile($profile_id) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ), |
200 | 200 | ); |
201 | 201 | |
202 | - return $this->post( $args, false ); |
|
202 | + return $this->post($args, false); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | 215 | * @return string|WP_Error Profile id. |
216 | 216 | */ |
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
217 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
220 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
221 | 221 | |
222 | 222 | // Prepare card details. |
223 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
223 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
224 | 224 | |
225 | 225 | // Authorize.NET does not support saving the same card twice. |
226 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
226 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
227 | 227 | |
228 | - if ( $cached_information ) { |
|
228 | + if ($cached_information) { |
|
229 | 229 | return $cached_information; |
230 | 230 | } |
231 | 231 | |
@@ -238,34 +238,34 @@ discard block |
||
238 | 238 | |
239 | 239 | // Billing information. |
240 | 240 | 'billTo' => array( |
241 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
242 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
243 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
244 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
245 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
246 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
247 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
241 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
242 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
243 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
244 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
245 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
246 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
247 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
248 | 248 | ), |
249 | 249 | |
250 | 250 | // Payment information. |
251 | 251 | 'payment' => $payment_information, |
252 | 252 | ), |
253 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
253 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
254 | 254 | ), |
255 | 255 | ); |
256 | 256 | |
257 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
257 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
258 | 258 | |
259 | - if ( is_wp_error( $response ) ) { |
|
259 | + if (is_wp_error($response)) { |
|
260 | 260 | |
261 | 261 | // In case the payment profile already exists remotely. |
262 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
263 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
264 | - $payment_profile_id = strtok( '.' ); |
|
265 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
262 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
263 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
264 | + $payment_profile_id = strtok('.'); |
|
265 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
266 | 266 | |
267 | 267 | // Cache payment profile id. |
268 | - $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
268 | + $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
269 | 269 | |
270 | 270 | return $payment_profile_id; |
271 | 271 | } |
@@ -274,29 +274,29 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | // Save the payment token. |
277 | - if ( $save ) { |
|
277 | + if ($save) { |
|
278 | 278 | $this->save_token( |
279 | 279 | array( |
280 | 280 | 'id' => $response->customerPaymentProfileId, |
281 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
281 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
282 | 282 | 'default' => true, |
283 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
283 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
284 | 284 | ) |
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Cache payment profile id. |
289 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
289 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
290 | 290 | |
291 | 291 | // Add a note about the validation response. |
292 | 292 | $invoice->add_note( |
293 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
293 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
294 | 294 | false, |
295 | 295 | false, |
296 | 296 | true |
297 | 297 | ); |
298 | 298 | |
299 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
299 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
300 | 300 | |
301 | 301 | return $response->customerPaymentProfileId; |
302 | 302 | } |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * @param array $payment_details. |
309 | 309 | * @return array|false Profile id. |
310 | 310 | */ |
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
311 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
312 | 312 | |
313 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
314 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
313 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
314 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
315 | 315 | |
316 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
316 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
317 | 317 | return false; |
318 | 318 | } |
319 | 319 | |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | 'getCustomerPaymentProfileRequest' => array( |
323 | 323 | 'merchantAuthentication' => $this->get_auth_params(), |
324 | 324 | 'customerProfileId' => $customer_profile, |
325 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
325 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
326 | 326 | ), |
327 | 327 | ); |
328 | 328 | |
329 | - $response = $this->post( $args, $invoice ); |
|
329 | + $response = $this->post($args, $invoice); |
|
330 | 330 | |
331 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
331 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | 341 | */ |
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
342 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
343 | 343 | |
344 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
345 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
346 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
344 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
345 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
346 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
347 | 347 | |
348 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
349 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
348 | + $cached_information[$payment_details] = $payment_profile_id; |
|
349 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return string|WP_Error Profile id. |
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | 361 | */ |
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
362 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | ), |
371 | 371 | ); |
372 | 372 | |
373 | - return $this->post( $args, false ); |
|
373 | + return $this->post($args, false); |
|
374 | 374 | |
375 | 375 | } |
376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | 384 | * @return WP_Error|object |
385 | 385 | */ |
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
386 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | ), |
404 | 404 | ), |
405 | 405 | 'order' => array( |
406 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
406 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
407 | 407 | ), |
408 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
408 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
409 | 409 | 'tax' => array( |
410 | 410 | 'amount' => $invoice->get_total_tax(), |
411 | - 'name' => __( 'TAX', 'invoicing' ), |
|
411 | + 'name' => __('TAX', 'invoicing'), |
|
412 | 412 | ), |
413 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
413 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
414 | 414 | 'customer' => array( |
415 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
416 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
415 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
416 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
417 | 417 | ), |
418 | 418 | 'customerIP' => $invoice->get_ip(), |
419 | 419 | ), |
420 | 420 | ), |
421 | 421 | ); |
422 | 422 | |
423 | - if ( 0 == $invoice->get_total_tax() ) { |
|
424 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
423 | + if (0 == $invoice->get_total_tax()) { |
|
424 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
425 | 425 | } |
426 | 426 | |
427 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
427 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
428 | 428 | |
429 | 429 | } |
430 | 430 | |
@@ -434,29 +434,29 @@ discard block |
||
434 | 434 | * @param stdClass $result Api response. |
435 | 435 | * @param WPInv_Invoice $invoice Invoice. |
436 | 436 | */ |
437 | - public function process_charge_response( $result, $invoice ) { |
|
437 | + public function process_charge_response($result, $invoice) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | 440 | $response_code = (int) $result->transactionResponse->responseCode; |
441 | 441 | |
442 | 442 | // Succeeded. |
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
443 | + if (1 == $response_code || 4 == $response_code) { |
|
444 | 444 | |
445 | 445 | // Maybe set a transaction id. |
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
446 | + if (!empty($result->transactionResponse->transId)) { |
|
447 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
448 | 448 | } |
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
452 | + if (1 == $response_code) { |
|
453 | 453 | return $invoice->mark_paid(); |
454 | 454 | } |
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
456 | + $invoice->set_status('wpi-onhold'); |
|
457 | 457 | $invoice->add_note( |
458 | 458 | sprintf( |
459 | - __( 'Held for review: %s', 'invoicing' ), |
|
459 | + __('Held for review: %s', 'invoicing'), |
|
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | 462 | ); |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
468 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
469 | 469 | |
470 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
470 | + if (!empty($result->transactionResponse->errors)) { |
|
471 | 471 | $errors = (object) $result->transactionResponse->errors; |
472 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
472 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param array $card Card details. |
482 | 482 | * @return array |
483 | 483 | */ |
484 | - public function get_payment_information( $card ) { |
|
484 | + public function get_payment_information($card) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param WPInv_Invoice $invoice Invoice. |
501 | 501 | * @return string |
502 | 502 | */ |
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
504 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
503 | + public function get_customer_profile_meta_name($invoice) { |
|
504 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -512,34 +512,34 @@ discard block |
||
512 | 512 | * @param WPInv_Invoice $invoice |
513 | 513 | * @return WP_Error|string The payment profile id |
514 | 514 | */ |
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
515 | + public function validate_submission_data($submission_data, $invoice) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
519 | 519 | |
520 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
521 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
520 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
521 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | // Validate the payment method. |
525 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
526 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
525 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
526 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | // Are we adding a new payment method? |
530 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
530 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
531 | 531 | return $submission_data['getpaid-authorizenet-payment-method']; |
532 | 532 | } |
533 | 533 | |
534 | 534 | // Retrieve the customer profile id. |
535 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
535 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
536 | 536 | |
537 | 537 | // Create payment method. |
538 | - if ( empty( $profile_id ) ) { |
|
539 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
538 | + if (empty($profile_id)) { |
|
539 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
540 | 540 | } |
541 | 541 | |
542 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
542 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
543 | 543 | |
544 | 544 | } |
545 | 545 | |
@@ -550,32 +550,32 @@ discard block |
||
550 | 550 | * @param WPInv_Invoice $invoice Invoice. |
551 | 551 | * @return array |
552 | 552 | */ |
553 | - public function get_line_items( $invoice ) { |
|
553 | + public function get_line_items($invoice) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | - foreach ( $invoice->get_items() as $item ) { |
|
556 | + foreach ($invoice->get_items() as $item) { |
|
557 | 557 | |
558 | 558 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
559 | 559 | $items[] = array( |
560 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
561 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
562 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
563 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
560 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
561 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
562 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
563 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
564 | 564 | 'unitPrice' => (float) $amount, |
565 | 565 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
566 | 566 | ); |
567 | 567 | |
568 | 568 | } |
569 | 569 | |
570 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
570 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
571 | 571 | |
572 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
572 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
573 | 573 | |
574 | - if ( $amount > 0 ) { |
|
574 | + if ($amount > 0) { |
|
575 | 575 | $items[] = array( |
576 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
577 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
578 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
576 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
577 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
578 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
579 | 579 | 'quantity' => '1', |
580 | 580 | 'unitPrice' => (float) $amount, |
581 | 581 | 'taxable' => false, |
@@ -595,36 +595,36 @@ discard block |
||
595 | 595 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
596 | 596 | * @return array |
597 | 597 | */ |
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
598 | + public function process_payment($invoice, $submission_data, $submission) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
601 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
602 | 602 | |
603 | 603 | // Do we have an error? |
604 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
605 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
606 | - wpinv_send_back_to_checkout( $invoice ); |
|
604 | + if (is_wp_error($payment_profile_id)) { |
|
605 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
606 | + wpinv_send_back_to_checkout($invoice); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | // Save the payment method to the order. |
610 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
610 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
611 | 611 | |
612 | 612 | // Check if this is a subscription or not. |
613 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
614 | - if ( ! empty( $subscriptions ) ) { |
|
615 | - $this->process_subscription( $invoice, $subscriptions ); |
|
613 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
614 | + if (!empty($subscriptions)) { |
|
615 | + $this->process_subscription($invoice, $subscriptions); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | // If it is free, send to the success page. |
619 | - if ( ! $invoice->needs_payment() ) { |
|
619 | + if (!$invoice->needs_payment()) { |
|
620 | 620 | $invoice->mark_paid(); |
621 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
621 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | // Charge the payment profile. |
625 | - $this->process_initial_payment( $invoice ); |
|
625 | + $this->process_initial_payment($invoice); |
|
626 | 626 | |
627 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
627 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
@@ -635,23 +635,23 @@ discard block |
||
635 | 635 | * |
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | 637 | */ |
638 | - protected function process_initial_payment( $invoice ) { |
|
638 | + protected function process_initial_payment($invoice) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
640 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
641 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
642 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
643 | 643 | |
644 | 644 | // Do we have an error? |
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
645 | + if (is_wp_error($result)) { |
|
646 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
647 | + wpinv_send_back_to_checkout($invoice); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Process the response. |
651 | - $this->process_charge_response( $result, $invoice ); |
|
651 | + $this->process_charge_response($result, $invoice); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
653 | + if (wpinv_get_errors()) { |
|
654 | + wpinv_send_back_to_checkout($invoice); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | } |
@@ -662,30 +662,30 @@ discard block |
||
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | 664 | */ |
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
665 | + public function process_subscription($invoice, $subscriptions) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | - if ( (float) $invoice->get_total() > 0 ) { |
|
669 | - $this->process_initial_payment( $invoice ); |
|
668 | + if ((float) $invoice->get_total() > 0) { |
|
669 | + $this->process_initial_payment($invoice); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
673 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
673 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
674 | 674 | |
675 | - foreach ( $subscriptions as $subscription ) { |
|
676 | - if ( $subscription->exists() ) { |
|
677 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
678 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
675 | + foreach ($subscriptions as $subscription) { |
|
676 | + if ($subscription->exists()) { |
|
677 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
678 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
679 | 679 | |
680 | - $subscription->set_next_renewal_date( $expiry ); |
|
681 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
682 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
680 | + $subscription->set_next_renewal_date($expiry); |
|
681 | + $subscription->set_date_created(current_time('mysql')); |
|
682 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
683 | 683 | $subscription->activate(); |
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Redirect to the success page. |
688 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
688 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
689 | 689 | |
690 | 690 | } |
691 | 691 | |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | * |
696 | 696 | * @param WPInv_Subscription $subscription |
697 | 697 | */ |
698 | - public function maybe_renew_subscription( $subscription ) { |
|
698 | + public function maybe_renew_subscription($subscription) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
702 | - $this->renew_subscription( $subscription ); |
|
701 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
702 | + $this->renew_subscription($subscription); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | } |
@@ -709,28 +709,28 @@ discard block |
||
709 | 709 | * |
710 | 710 | * @param WPInv_Subscription $subscription |
711 | 711 | */ |
712 | - public function renew_subscription( $subscription ) { |
|
712 | + public function renew_subscription($subscription) { |
|
713 | 713 | |
714 | 714 | // Generate the renewal invoice. |
715 | 715 | $new_invoice = $subscription->create_payment(); |
716 | 716 | $old_invoice = $subscription->get_parent_payment(); |
717 | 717 | |
718 | - if ( empty( $new_invoice ) ) { |
|
719 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
718 | + if (empty($new_invoice)) { |
|
719 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
720 | 720 | $subscription->failing(); |
721 | 721 | return; |
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
725 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
726 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
727 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
728 | 728 | |
729 | 729 | // Do we have an error? |
730 | - if ( is_wp_error( $result ) ) { |
|
730 | + if (is_wp_error($result)) { |
|
731 | 731 | |
732 | 732 | $old_invoice->add_note( |
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
733 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
734 | 734 | true, |
735 | 735 | false, |
736 | 736 | true |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | } |
742 | 742 | |
743 | 743 | // Process the response. |
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
744 | + $this->process_charge_response($result, $new_invoice); |
|
745 | 745 | |
746 | - if ( wpinv_get_errors() ) { |
|
746 | + if (wpinv_get_errors()) { |
|
747 | 747 | |
748 | 748 | $old_invoice->add_note( |
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
749 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
750 | 750 | true, |
751 | 751 | false, |
752 | 752 | true |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | |
757 | 757 | } |
758 | 758 | |
759 | - $subscription->add_payment( array(), $new_invoice ); |
|
759 | + $subscription->add_payment(array(), $new_invoice); |
|
760 | 760 | $subscription->renew(); |
761 | 761 | } |
762 | 762 | |
@@ -767,33 +767,33 @@ discard block |
||
767 | 767 | * @param GetPaid_Form_Item[] $items |
768 | 768 | * @return WPInv_Invoice |
769 | 769 | */ |
770 | - public function process_addons( $invoice, $items ) { |
|
770 | + public function process_addons($invoice, $items) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
774 | 774 | $getpaid_authorize_addons = array(); |
775 | - foreach ( $items as $item ) { |
|
775 | + foreach ($items as $item) { |
|
776 | 776 | |
777 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
777 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
778 | 778 | $getpaid_authorize_addons[] = $item; |
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
782 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
782 | + if (empty($getpaid_authorize_addons)) { |
|
783 | 783 | return; |
784 | 784 | } |
785 | 785 | |
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
788 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
789 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
790 | 790 | |
791 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
792 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
793 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
791 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
792 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
793 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
794 | 794 | |
795 | - if ( is_wp_error( $result ) ) { |
|
796 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
795 | + if (is_wp_error($result)) { |
|
796 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
797 | 797 | return; |
798 | 798 | } |
799 | 799 | |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | * @param array $args |
807 | 807 | * @return array |
808 | 808 | */ |
809 | - public function filter_addons_request( $args ) { |
|
809 | + public function filter_addons_request($args) { |
|
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
812 | 812 | $total = 0; |
813 | 813 | |
814 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
814 | + foreach ($getpaid_authorize_addons as $addon) { |
|
815 | 815 | $total += $addon->get_sub_total(); |
816 | 816 | } |
817 | 817 | |
818 | 818 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
819 | 819 | |
820 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
821 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
820 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
821 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | return $args; |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | public function sandbox_notice() { |
832 | 832 | |
833 | 833 | return sprintf( |
834 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
834 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
835 | 835 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
836 | 836 | '</a>' |
837 | 837 | ); |
@@ -843,42 +843,42 @@ discard block |
||
843 | 843 | * |
844 | 844 | * @param array $admin_settings |
845 | 845 | */ |
846 | - public function admin_settings( $admin_settings ) { |
|
846 | + public function admin_settings($admin_settings) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
850 | - implode( ', ', $this->currencies ) |
|
849 | + __('Supported Currencies: %s', 'invoicing'), |
|
850 | + implode(', ', $this->currencies) |
|
851 | 851 | ); |
852 | 852 | |
853 | 853 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
854 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
854 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
855 | 855 | |
856 | 856 | $admin_settings['authorizenet_login_id'] = array( |
857 | 857 | 'type' => 'text', |
858 | 858 | 'id' => 'authorizenet_login_id', |
859 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
860 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
859 | + 'name' => __('API Login ID', 'invoicing'), |
|
860 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
861 | 861 | ); |
862 | 862 | |
863 | 863 | $admin_settings['authorizenet_transaction_key'] = array( |
864 | 864 | 'type' => 'text', |
865 | 865 | 'id' => 'authorizenet_transaction_key', |
866 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
866 | + 'name' => __('Transaction Key', 'invoicing'), |
|
867 | 867 | ); |
868 | 868 | |
869 | 869 | $admin_settings['authorizenet_signature_key'] = array( |
870 | 870 | 'type' => 'text', |
871 | 871 | 'id' => 'authorizenet_signature_key', |
872 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
873 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
872 | + 'name' => __('Signature Key', 'invoicing'), |
|
873 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
874 | 874 | ); |
875 | 875 | |
876 | 876 | $admin_settings['authorizenet_ipn_url'] = array( |
877 | 877 | 'type' => 'ipn_url', |
878 | 878 | 'id' => 'authorizenet_ipn_url', |
879 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
879 | + 'name' => __('Webhook URL', 'invoicing'), |
|
880 | 880 | 'std' => $this->notify_url, |
881 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
881 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
882 | 882 | 'custom' => 'authorizenet', |
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
@@ -13,65 +13,65 @@ discard block |
||
13 | 13 | class GetPaid_Worldpay_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 = 'worldpay'; |
21 | 21 | |
22 | 22 | /** |
23 | - * Payment method order. |
|
24 | - * |
|
25 | - * @var int |
|
26 | - */ |
|
23 | + * Payment method order. |
|
24 | + * |
|
25 | + * @var int |
|
26 | + */ |
|
27 | 27 | public $order = 5; |
28 | 28 | |
29 | 29 | /** |
30 | - * Endpoint for requests from Worldpay. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $notify_url; |
|
35 | - |
|
36 | - /** |
|
37 | - * Endpoint for requests to Worldpay. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
30 | + * Endpoint for requests from Worldpay. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $notify_url; |
|
35 | + |
|
36 | + /** |
|
37 | + * Endpoint for requests to Worldpay. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | 41 | protected $endpoint; |
42 | 42 | |
43 | 43 | /** |
44 | - * An array of features that this gateway supports. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
44 | + * An array of features that this gateway supports. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | 48 | protected $supports = array( 'sandbox' ); |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a subscription. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
65 | + * URL to view a subscription. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
70 | 70 | |
71 | 71 | /** |
72 | - * Class constructor. |
|
73 | - */ |
|
74 | - public function __construct() { |
|
72 | + * Class constructor. |
|
73 | + */ |
|
74 | + public function __construct() { |
|
75 | 75 | |
76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Process Payment. |
|
89 | - * |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice Invoice. |
|
92 | - * @param array $submission_data Posted checkout fields. |
|
93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
88 | + * Process Payment. |
|
89 | + * |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice Invoice. |
|
92 | + * @param array $submission_data Posted checkout fields. |
|
93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | 97 | |
98 | 98 | // Get redirect url. |
99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | - * Get the Worldpay request URL for an invoice. |
|
132 | - * |
|
133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_request_url( $invoice ) { |
|
131 | + * Get the Worldpay request URL for an invoice. |
|
132 | + * |
|
133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_request_url( $invoice ) { |
|
137 | 137 | |
138 | 138 | // Endpoint for this request |
139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
140 | 140 | |
141 | 141 | return $this->endpoint; |
142 | 142 | |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | 145 | /** |
146 | - * Get Worldpay Args for passing to Worldpay. |
|
147 | - * |
|
148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - protected function get_worldpay_args( $invoice ) { |
|
152 | - |
|
153 | - return apply_filters( |
|
154 | - 'getpaid_worldpay_args', |
|
155 | - array( |
|
146 | + * Get Worldpay Args for passing to Worldpay. |
|
147 | + * |
|
148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + protected function get_worldpay_args( $invoice ) { |
|
152 | + |
|
153 | + return apply_filters( |
|
154 | + 'getpaid_worldpay_args', |
|
155 | + array( |
|
156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
179 | 179 | ), |
180 | - $invoice |
|
181 | - ); |
|
180 | + $invoice |
|
181 | + ); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Secures worldpay args with an md5 hash. |
|
187 | - * |
|
188 | - * @param array $args Gateway args. |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - public function hash_args( $args ) { |
|
186 | + * Secures worldpay args with an md5 hash. |
|
187 | + * |
|
188 | + * @param array $args Gateway args. |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + public function hash_args( $args ) { |
|
192 | 192 | |
193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Processes ipns and marks payments as complete. |
|
208 | - * |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function verify_ipn() { |
|
207 | + * Processes ipns and marks payments as complete. |
|
208 | + * |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function verify_ipn() { |
|
212 | 212 | |
213 | 213 | // Validate the IPN. |
214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
216 | - } |
|
215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | // Process the IPN. |
219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
230 | 230 | } |
231 | 231 | |
232 | - // Update the ip address. |
|
233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
232 | + // Update the ip address. |
|
233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
235 | 235 | } |
236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Check Worldpay IPN validity. |
|
261 | - */ |
|
262 | - public function validate_ipn() { |
|
260 | + * Check Worldpay IPN validity. |
|
261 | + */ |
|
262 | + public function validate_ipn() { |
|
263 | 263 | |
264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | - * Filters the gateway settings. |
|
309 | - * |
|
310 | - * @param array $admin_settings |
|
311 | - */ |
|
312 | - public function admin_settings( $admin_settings ) { |
|
308 | + * Filters the gateway settings. |
|
309 | + * |
|
310 | + * @param array $admin_settings |
|
311 | + */ |
|
312 | + public function admin_settings( $admin_settings ) { |
|
313 | 313 | |
314 | 314 | $currencies = sprintf( |
315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | 'readonly' => true, |
351 | 351 | ); |
352 | 352 | |
353 | - return $admin_settings; |
|
354 | - } |
|
353 | + return $admin_settings; |
|
354 | + } |
|
355 | 355 | |
356 | 356 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Worldpay Payment Gateway class. |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @var array |
47 | 47 | */ |
48 | - protected $supports = array( 'sandbox' ); |
|
48 | + protected $supports = array('sandbox'); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Currencies this gateway is allowed for. |
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
55 | + public $currencies = array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function __construct() { |
75 | 75 | |
76 | - $this->method_title = __( 'Worldpay', 'invoicing' ); |
|
77 | - $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
|
78 | - $this->checkout_button_text = __( 'Proceed to Worldpay', 'invoicing' ); |
|
79 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
76 | + $this->method_title = __('Worldpay', 'invoicing'); |
|
77 | + $this->title = __('Worldpay - Credit Card / Debit Card', 'invoicing'); |
|
78 | + $this->checkout_button_text = __('Proceed to Worldpay', 'invoicing'); |
|
79 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
80 | 80 | |
81 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
82 | - add_filter( 'getpaid_worldpay_args', array( $this, 'hash_args' ) ); |
|
81 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
82 | + add_filter('getpaid_worldpay_args', array($this, 'hash_args')); |
|
83 | 83 | |
84 | 84 | parent::__construct(); |
85 | 85 | } |
@@ -93,24 +93,24 @@ discard block |
||
93 | 93 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
94 | 94 | * @return array |
95 | 95 | */ |
96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
96 | + public function process_payment($invoice, $submission_data, $submission) { |
|
97 | 97 | |
98 | 98 | // Get redirect url. |
99 | - $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
|
99 | + $worldpay_redirect = esc_url($this->get_request_url($invoice)); |
|
100 | 100 | |
101 | 101 | // Get submission args. |
102 | - $worldpay_args = $this->get_worldpay_args( $invoice ); |
|
102 | + $worldpay_args = $this->get_worldpay_args($invoice); |
|
103 | 103 | |
104 | 104 | $form = "<form action='$worldpay_redirect' name='wpi_worldpay_form' method='POST'>"; |
105 | 105 | |
106 | - foreach ( $worldpay_args as $key => $value ) { |
|
106 | + foreach ($worldpay_args as $key => $value) { |
|
107 | 107 | |
108 | - if ( false === $value || '' === trim( $value ) ) { |
|
108 | + if (false === $value || '' === trim($value)) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | |
112 | - $value = esc_attr( $value ); |
|
113 | - $key = wpinv_clean( $key ); |
|
112 | + $value = esc_attr($value); |
|
113 | + $key = wpinv_clean($key); |
|
114 | 114 | $form .= "<input type='hidden' name='$key' value='$value'>"; |
115 | 115 | } |
116 | 116 | |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * @param WPInv_Invoice $invoice Invoice object. |
134 | 134 | * @return string |
135 | 135 | */ |
136 | - public function get_request_url( $invoice ) { |
|
136 | + public function get_request_url($invoice) { |
|
137 | 137 | |
138 | 138 | // Endpoint for this request |
139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
139 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
140 | 140 | |
141 | 141 | return $this->endpoint; |
142 | 142 | |
@@ -148,34 +148,34 @@ discard block |
||
148 | 148 | * @param WPInv_Invoice $invoice Invoice object. |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - protected function get_worldpay_args( $invoice ) { |
|
151 | + protected function get_worldpay_args($invoice) { |
|
152 | 152 | |
153 | 153 | return apply_filters( |
154 | 154 | 'getpaid_worldpay_args', |
155 | 155 | array( |
156 | - 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
|
157 | - 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
|
158 | - 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
|
159 | - 'instId' => wpinv_clean( $this->get_option( 'instId', '' ) ), // mandatory |
|
160 | - 'testMode' => $this->is_sandbox( $invoice ) ? 100 : 0, // mandatory |
|
161 | - 'name' => wpinv_clean( $invoice->get_full_name() ), |
|
162 | - 'address' => wpinv_clean( $invoice->get_address() ), |
|
163 | - 'postcode' => wpinv_clean( $invoice->get_zip() ), |
|
164 | - 'tel' => wpinv_clean( $invoice->get_phone() ), |
|
165 | - 'email' => sanitize_email( $invoice->get_email() ), |
|
166 | - 'country' => wpinv_clean( $invoice->get_country() ), |
|
167 | - 'desc' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
168 | - 'MC_description' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
169 | - 'MC_callback' => esc_url_raw( $this->notify_url ), |
|
170 | - 'resultfile' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
171 | - 'MC_key' => wpinv_clean( $invoice->get_key() ), |
|
156 | + 'amount' => wpinv_sanitize_amount($invoice->get_total()), // mandatory |
|
157 | + 'cartId' => wpinv_clean($invoice->get_number()), // mandatory reference for the item purchased |
|
158 | + 'currency' => wpinv_clean($invoice->get_currency()), // mandatory |
|
159 | + 'instId' => wpinv_clean($this->get_option('instId', '')), // mandatory |
|
160 | + 'testMode' => $this->is_sandbox($invoice) ? 100 : 0, // mandatory |
|
161 | + 'name' => wpinv_clean($invoice->get_full_name()), |
|
162 | + 'address' => wpinv_clean($invoice->get_address()), |
|
163 | + 'postcode' => wpinv_clean($invoice->get_zip()), |
|
164 | + 'tel' => wpinv_clean($invoice->get_phone()), |
|
165 | + 'email' => sanitize_email($invoice->get_email()), |
|
166 | + 'country' => wpinv_clean($invoice->get_country()), |
|
167 | + 'desc' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
168 | + 'MC_description' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
169 | + 'MC_callback' => esc_url_raw($this->notify_url), |
|
170 | + 'resultfile' => esc_url_raw($this->get_return_url($invoice)), |
|
171 | + 'MC_key' => wpinv_clean($invoice->get_key()), |
|
172 | 172 | 'MC_invoice_id' => $invoice->get_id(), |
173 | - 'address1' => wpinv_clean( $invoice->get_address() ), |
|
174 | - 'town' => wpinv_clean( $invoice->get_city() ), |
|
175 | - 'region' => wpinv_clean( $invoice->get_state() ), |
|
176 | - 'amountString' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
177 | - 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
|
178 | - 'compName' => wpinv_clean( $invoice->get_company() ), |
|
173 | + 'address1' => wpinv_clean($invoice->get_address()), |
|
174 | + 'town' => wpinv_clean($invoice->get_city()), |
|
175 | + 'region' => wpinv_clean($invoice->get_state()), |
|
176 | + 'amountString' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
177 | + 'countryString' => wpinv_clean(wpinv_country_name($invoice->get_country())), |
|
178 | + 'compName' => wpinv_clean($invoice->get_company()), |
|
179 | 179 | ), |
180 | 180 | $invoice |
181 | 181 | ); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | * @param array $args Gateway args. |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - public function hash_args( $args ) { |
|
191 | + public function hash_args($args) { |
|
192 | 192 | |
193 | - $md5_secret = $this->get_option( 'md5_secret' ); |
|
193 | + $md5_secret = $this->get_option('md5_secret'); |
|
194 | 194 | |
195 | 195 | // Abort if there is no secret. |
196 | - if ( empty( $md5_secret ) ) { |
|
196 | + if (empty($md5_secret)) { |
|
197 | 197 | return $args; |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Hash the args. |
201 | - $args['signature'] = md5( "$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}" ); |
|
201 | + $args['signature'] = md5("$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}"); |
|
202 | 202 | |
203 | 203 | return $args; |
204 | 204 | } |
@@ -211,43 +211,43 @@ discard block |
||
211 | 211 | public function verify_ipn() { |
212 | 212 | |
213 | 213 | // Validate the IPN. |
214 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
214 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
215 | + wp_die('Worldpay IPN Request Failure', 'Worldpay IPN', array('response' => 500)); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | // Process the IPN. |
219 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
220 | - $invoice = wpinv_get_invoice( $posted['MC_invoice_id'] ); |
|
219 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
220 | + $invoice = wpinv_get_invoice($posted['MC_invoice_id']); |
|
221 | 221 | |
222 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
222 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
223 | 223 | |
224 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
225 | - wpinv_error_log( 'Payment status:' . $posted['transStatus'] ); |
|
224 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
225 | + wpinv_error_log('Payment status:' . $posted['transStatus']); |
|
226 | 226 | |
227 | 227 | // Update the transaction id. |
228 | - if ( ! empty( $posted['transId'] ) ) { |
|
229 | - $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
|
228 | + if (!empty($posted['transId'])) { |
|
229 | + $invoice->set_transaction_id(wpinv_clean($posted['transId'])); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | // Update the ip address. |
233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
234 | - $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
|
233 | + if (!empty($posted['ipAddress'])) { |
|
234 | + $invoice->set_ip(wpinv_clean($posted['ipAddress'])); |
|
235 | 235 | } |
236 | 236 | |
237 | - if ( $posted['transStatus'] == 'Y' ) { |
|
238 | - $invoice->set_completed_date( date( 'Y-m-d H:i:s', $posted['transTime'] ) ); |
|
237 | + if ($posted['transStatus'] == 'Y') { |
|
238 | + $invoice->set_completed_date(date('Y-m-d H:i:s', $posted['transTime'])); |
|
239 | 239 | $invoice->mark_paid(); |
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | - if ( $posted['transStatus'] == 'C' ) { |
|
244 | - $invoice->set_status( 'wpi-failed' ); |
|
245 | - $invoice->add_note( __( 'Payment transaction failed while processing Worldpay payment.', 'invoicing' ), false, false, true ); |
|
243 | + if ($posted['transStatus'] == 'C') { |
|
244 | + $invoice->set_status('wpi-failed'); |
|
245 | + $invoice->add_note(__('Payment transaction failed while processing Worldpay payment.', 'invoicing'), false, false, true); |
|
246 | 246 | $invoice->save(); |
247 | 247 | return; |
248 | 248 | } |
249 | 249 | |
250 | - wpinv_error_log( 'Aborting, Invalid transaction status:' . $posted['transStatus'] ); |
|
250 | + wpinv_error_log('Aborting, Invalid transaction status:' . $posted['transStatus']); |
|
251 | 251 | $invoice->save(); |
252 | 252 | |
253 | 253 | } |
@@ -261,27 +261,27 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function validate_ipn() { |
263 | 263 | |
264 | - wpinv_error_log( 'Validating Worldpay IPN response' ); |
|
264 | + wpinv_error_log('Validating Worldpay IPN response'); |
|
265 | 265 | |
266 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
266 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
267 | 267 | |
268 | 268 | // Verify installation. |
269 | - if ( empty( $data['instId'] ) || $data['instId'] != wpinv_clean( $this->get_option( 'instId', '' ) ) ) { |
|
270 | - wpinv_error_log( 'Received invalid installation ID from Worldpay IPN' ); |
|
269 | + if (empty($data['instId']) || $data['instId'] != wpinv_clean($this->get_option('instId', ''))) { |
|
270 | + wpinv_error_log('Received invalid installation ID from Worldpay IPN'); |
|
271 | 271 | return false; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Verify invoice. |
275 | - if ( empty( $data['cartId'] ) || ! wpinv_get_id_by_invoice_number( $data['cartId'] ) ) { |
|
276 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
275 | + if (empty($data['cartId']) || !wpinv_get_id_by_invoice_number($data['cartId'])) { |
|
276 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
277 | 277 | return false; |
278 | 278 | } |
279 | 279 | |
280 | 280 | // (maybe) verify password. |
281 | - $password = $this->get_option( 'callback_password' ); |
|
281 | + $password = $this->get_option('callback_password'); |
|
282 | 282 | |
283 | - if ( ! empty( $password ) && ( empty( $data['callbackPW'] ) || $password != $data['callbackPW'] ) ) { |
|
284 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
283 | + if (!empty($password) && (empty($data['callbackPW']) || $password != $data['callbackPW'])) { |
|
284 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | /** |
293 | 293 | * Displays a notice on the checkout page if sandbox is enabled. |
294 | 294 | */ |
295 | - public function sandbox_notice( $description, $gateway ) { |
|
296 | - if ( 'worldpay' == $gateway && wpinv_is_test_mode( 'worldpay' ) ) { |
|
295 | + public function sandbox_notice($description, $gateway) { |
|
296 | + if ('worldpay' == $gateway && wpinv_is_test_mode('worldpay')) { |
|
297 | 297 | $description .= '<br>' . sprintf( |
298 | - __( 'SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
298 | + __('SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
299 | 299 | '<a href="https://developer.worldpay.com/docs/wpg/directintegration/abouttesting">', |
300 | 300 | '</a>' |
301 | 301 | ); |
@@ -309,43 +309,43 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param array $admin_settings |
311 | 311 | */ |
312 | - public function admin_settings( $admin_settings ) { |
|
312 | + public function admin_settings($admin_settings) { |
|
313 | 313 | |
314 | 314 | $currencies = sprintf( |
315 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
316 | - implode( ', ', $this->currencies ) |
|
315 | + __('Supported Currencies: %s', 'invoicing'), |
|
316 | + implode(', ', $this->currencies) |
|
317 | 317 | ); |
318 | 318 | |
319 | 319 | $admin_settings['worldpay_active']['desc'] = $admin_settings['worldpay_active']['desc'] . " ($currencies)"; |
320 | - $admin_settings['worldpay_desc']['std'] = __( 'Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing' ); |
|
320 | + $admin_settings['worldpay_desc']['std'] = __('Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing'); |
|
321 | 321 | |
322 | 322 | $admin_settings['worldpay_instId'] = array( |
323 | 323 | 'type' => 'text', |
324 | 324 | 'id' => 'worldpay_instId', |
325 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
326 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
325 | + 'name' => __('Installation Id', 'invoicing'), |
|
326 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
327 | 327 | ); |
328 | 328 | |
329 | 329 | $admin_settings['worldpay_md5_secret'] = array( |
330 | 330 | 'type' => 'text', |
331 | 331 | 'id' => 'worldpay_md5_secret', |
332 | - 'name' => __( 'MD5 secret', 'invoicing' ), |
|
333 | - 'desc' => __( 'Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing' ) . '<code>instId:amount:currency:cartId</code>', |
|
332 | + 'name' => __('MD5 secret', 'invoicing'), |
|
333 | + 'desc' => __('Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing') . '<code>instId:amount:currency:cartId</code>', |
|
334 | 334 | ); |
335 | 335 | |
336 | 336 | $admin_settings['worldpay_callbackPW'] = array( |
337 | 337 | 'type' => 'text', |
338 | 338 | 'id' => 'worldpay_callbackPW', |
339 | - 'name' => __( 'Payment Response password', 'invoicing' ), |
|
340 | - 'desc' => __( 'Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing' ), |
|
339 | + 'name' => __('Payment Response password', 'invoicing'), |
|
340 | + 'desc' => __('Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing'), |
|
341 | 341 | ); |
342 | 342 | |
343 | 343 | $admin_settings['worldpay_ipn_url'] = array( |
344 | 344 | 'type' => 'ipn_url', |
345 | 345 | 'id' => 'worldpay_ipn_url', |
346 | - 'name' => __( 'Payment Response URL', 'invoicing' ), |
|
346 | + 'name' => __('Payment Response URL', 'invoicing'), |
|
347 | 347 | 'std' => $this->notify_url, |
348 | - 'desc' => __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing' ), |
|
348 | + 'desc' => __('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing'), |
|
349 | 349 | 'custom' => 'worldpay', |
350 | 350 | 'readonly' => true, |
351 | 351 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
42 | + $this->title = __('Test Gateway', 'invoicing'); |
|
43 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
44 | 44 | |
45 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
45 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,32 +54,32 @@ discard block |
||
54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
61 | 61 | |
62 | 62 | // (Maybe) activate subscriptions. |
63 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
63 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
64 | 64 | |
65 | - if ( ! empty( $subscriptions ) ) { |
|
66 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
65 | + if (!empty($subscriptions)) { |
|
66 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
67 | 67 | |
68 | - foreach ( $subscriptions as $subscription ) { |
|
69 | - if ( $subscription->exists() ) { |
|
70 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
71 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
68 | + foreach ($subscriptions as $subscription) { |
|
69 | + if ($subscription->exists()) { |
|
70 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
71 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
72 | 72 | |
73 | - $subscription->set_next_renewal_date( $expiry ); |
|
74 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
75 | - $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
73 | + $subscription->set_next_renewal_date($expiry); |
|
74 | + $subscription->set_date_created(current_time('mysql')); |
|
75 | + $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
76 | 76 | $subscription->activate(); |
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Send to the success page. |
82 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
82 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
83 | 83 | |
84 | 84 | } |
85 | 85 | |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | */ |
92 | - public function maybe_renew_subscription( $subscription ) { |
|
92 | + public function maybe_renew_subscription($subscription) { |
|
93 | 93 | |
94 | 94 | // Ensure its our subscription && it's active. |
95 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
95 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
96 | 96 | |
97 | 97 | // Renew the subscription. |
98 | 98 | $subscription->add_payment( |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | * @param GetPaid_Form_Item[] $items |
116 | 116 | * @return WPInv_Invoice |
117 | 117 | */ |
118 | - public function process_addons( $invoice, $items ) { |
|
118 | + public function process_addons($invoice, $items) { |
|
119 | 119 | |
120 | - foreach ( $items as $item ) { |
|
121 | - $invoice->add_item( $item ); |
|
120 | + foreach ($items as $item) { |
|
121 | + $invoice->add_item($item); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | $invoice->recalculate_total(); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The Subscriptions DB Class |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | 'transaction_id' => '', |
73 | 73 | 'parent_payment_id' => 0, |
74 | 74 | 'product_id' => 0, |
75 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
76 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
75 | + 'created' => date('Y-m-d H:i:s'), |
|
76 | + 'expiration' => date('Y-m-d H:i:s'), |
|
77 | 77 | 'trial_period' => '', |
78 | 78 | 'status' => '', |
79 | 79 | 'profile_id' => '', |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @access public |
87 | 87 | * @since 1.0.0 |
88 | 88 | */ |
89 | - public function get_subscriptions( $args = array() ) { |
|
90 | - return getpaid_get_subscriptions( $args ); |
|
89 | + public function get_subscriptions($args = array()) { |
|
90 | + return getpaid_get_subscriptions($args); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @access public |
97 | 97 | * @since 1.0.0 |
98 | 98 | */ |
99 | - public function count( $args = array() ) { |
|
100 | - return getpaid_get_subscriptions( $args, 'count' ); |
|
99 | + public function count($args = array()) { |
|
100 | + return getpaid_get_subscriptions($args, 'count'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | KEY customer_and_status ( customer_id, status) |
134 | 134 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
135 | 135 | |
136 | - dbDelta( $sql ); |
|
136 | + dbDelta($sql); |
|
137 | 137 | |
138 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
138 | + update_option($this->table_name . '_db_version', $this->version); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -13,299 +13,299 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | - ) |
|
37 | - ); |
|
38 | - |
|
39 | - $this->init_hooks(); |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | + ) |
|
37 | + ); |
|
38 | + |
|
39 | + $this->init_hooks(); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - // Abort in case the parent invoice does not exist. |
|
156 | - $invoice = $subscription->get_parent_invoice(); |
|
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
162 | - return; |
|
163 | - } |
|
164 | - |
|
165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
166 | - |
|
167 | - $recipients = $this->get_recipients( $invoice ); |
|
168 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
169 | - $merge_tags = $email->get_merge_tags(); |
|
170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
172 | - $attachments = $email->get_attachments(); |
|
173 | - |
|
174 | - $result = $mailer->send( |
|
175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
176 | - $subject, |
|
177 | - $content, |
|
178 | - $attachments |
|
179 | - ); |
|
180 | - |
|
181 | - // Maybe send a copy to the admin. |
|
182 | - if ( $email->include_admin_bcc() ) { |
|
183 | - $mailer->send( |
|
184 | - wpinv_get_admin_email(), |
|
185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
186 | - $content, |
|
187 | - $attachments |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - if ( $result ) { |
|
192 | - $invoice->add_system_note( |
|
193 | - sprintf( |
|
194 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
195 | - sanitize_key( $type ), |
|
196 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
197 | - ) |
|
198 | - ); |
|
199 | - } else { |
|
200 | - $invoice->add_system_note( |
|
201 | - sprintf( |
|
202 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
203 | - sanitize_key( $type ), |
|
204 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
210 | - |
|
211 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
212 | 67 | |
213 | 68 | /** |
214 | - * Sends a new trial notification. |
|
215 | - * |
|
216 | - * @param WPInv_Subscription $subscription |
|
217 | - */ |
|
218 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
219 | 75 | |
220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
222 | 82 | |
223 | - } |
|
83 | + return $merge_tags; |
|
224 | 84 | |
225 | - /** |
|
226 | - * Sends a cancelled subscription notification. |
|
227 | - * |
|
228 | - * @param WPInv_Subscription $subscription |
|
229 | - */ |
|
230 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
231 | 86 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
234 | 113 | |
235 | - } |
|
114 | + } |
|
236 | 115 | |
237 | - /** |
|
238 | - * Sends a subscription expired notification. |
|
239 | - * |
|
240 | - * @param WPInv_Subscription $subscription |
|
241 | - */ |
|
242 | - public function subscription_expired( $subscription ) { |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
243 | 125 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
246 | 134 | |
247 | - } |
|
135 | + $cc = $invoice->get_email_cc(); |
|
248 | 136 | |
249 | - /** |
|
250 | - * Sends a completed subscription notification. |
|
251 | - * |
|
252 | - * @param WPInv_Subscription $subscription |
|
253 | - */ |
|
254 | - public function subscription_complete( $subscription ) { |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
255 | 141 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
142 | + return $recipients; |
|
143 | + } |
|
258 | 144 | |
259 | - } |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + // Abort in case the parent invoice does not exist. |
|
156 | + $invoice = $subscription->get_parent_invoice(); |
|
157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
162 | + return; |
|
163 | + } |
|
164 | + |
|
165 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
166 | + |
|
167 | + $recipients = $this->get_recipients( $invoice ); |
|
168 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
169 | + $merge_tags = $email->get_merge_tags(); |
|
170 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
172 | + $attachments = $email->get_attachments(); |
|
173 | + |
|
174 | + $result = $mailer->send( |
|
175 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
176 | + $subject, |
|
177 | + $content, |
|
178 | + $attachments |
|
179 | + ); |
|
180 | + |
|
181 | + // Maybe send a copy to the admin. |
|
182 | + if ( $email->include_admin_bcc() ) { |
|
183 | + $mailer->send( |
|
184 | + wpinv_get_admin_email(), |
|
185 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
186 | + $content, |
|
187 | + $attachments |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + if ( $result ) { |
|
192 | + $invoice->add_system_note( |
|
193 | + sprintf( |
|
194 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
195 | + sanitize_key( $type ), |
|
196 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
197 | + ) |
|
198 | + ); |
|
199 | + } else { |
|
200 | + $invoice->add_system_note( |
|
201 | + sprintf( |
|
202 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
203 | + sanitize_key( $type ), |
|
204 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
260 | 210 | |
261 | - /** |
|
262 | - * Sends a subscription renewal reminder notification. |
|
263 | - * |
|
264 | - */ |
|
265 | - public function renewal_reminder() { |
|
211 | + } |
|
266 | 212 | |
267 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
213 | + /** |
|
214 | + * Sends a new trial notification. |
|
215 | + * |
|
216 | + * @param WPInv_Subscription $subscription |
|
217 | + */ |
|
218 | + public function subscription_trial( $subscription ) { |
|
268 | 219 | |
269 | - // Fetch reminder days. |
|
270 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
220 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
271 | 222 | |
272 | - // Abort if non is set. |
|
273 | - if ( empty( $reminder_days ) ) { |
|
274 | - return; |
|
275 | - } |
|
223 | + } |
|
276 | 224 | |
277 | - // Fetch matching subscriptions. |
|
225 | + /** |
|
226 | + * Sends a cancelled subscription notification. |
|
227 | + * |
|
228 | + * @param WPInv_Subscription $subscription |
|
229 | + */ |
|
230 | + public function subscription_cancelled( $subscription ) { |
|
231 | + |
|
232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Sends a subscription expired notification. |
|
239 | + * |
|
240 | + * @param WPInv_Subscription $subscription |
|
241 | + */ |
|
242 | + public function subscription_expired( $subscription ) { |
|
243 | + |
|
244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
246 | + |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Sends a completed subscription notification. |
|
251 | + * |
|
252 | + * @param WPInv_Subscription $subscription |
|
253 | + */ |
|
254 | + public function subscription_complete( $subscription ) { |
|
255 | + |
|
256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
258 | + |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Sends a subscription renewal reminder notification. |
|
263 | + * |
|
264 | + */ |
|
265 | + public function renewal_reminder() { |
|
266 | + |
|
267 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
268 | + |
|
269 | + // Fetch reminder days. |
|
270 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
271 | + |
|
272 | + // Abort if non is set. |
|
273 | + if ( empty( $reminder_days ) ) { |
|
274 | + return; |
|
275 | + } |
|
276 | + |
|
277 | + // Fetch matching subscriptions. |
|
278 | 278 | $args = array( |
279 | 279 | 'number' => -1, |
280 | - 'count_total' => false, |
|
281 | - 'status' => 'trialling active', |
|
280 | + 'count_total' => false, |
|
281 | + 'status' => 'trialling active', |
|
282 | 282 | 'date_expires_query' => array( |
283 | - 'relation' => 'OR', |
|
283 | + 'relation' => 'OR', |
|
284 | 284 | ), |
285 | - ); |
|
285 | + ); |
|
286 | 286 | |
287 | - foreach ( $reminder_days as $days ) { |
|
288 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
287 | + foreach ( $reminder_days as $days ) { |
|
288 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
289 | 289 | |
290 | - $args['date_expires_query'][] = array( |
|
291 | - 'year' => $date['year'], |
|
292 | - 'month' => $date['month'], |
|
293 | - 'day' => $date['day'], |
|
294 | - ); |
|
290 | + $args['date_expires_query'][] = array( |
|
291 | + 'year' => $date['year'], |
|
292 | + 'month' => $date['month'], |
|
293 | + 'day' => $date['day'], |
|
294 | + ); |
|
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
298 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
299 | 299 | |
300 | 300 | foreach ( $subscriptions as $subscription ) { |
301 | 301 | |
302 | - // Skip packages. |
|
303 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
304 | - $email->object = $subscription; |
|
305 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
306 | - } |
|
302 | + // Skip packages. |
|
303 | + if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
304 | + $email->object = $subscription; |
|
305 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
306 | + } |
|
307 | 307 | } |
308 | 308 | |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | 311 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles subscription notificaiton emails. |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function init_hooks() { |
47 | 47 | |
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
50 | 50 | |
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
51 | + $email = new GetPaid_Notification_Email($email_type); |
|
52 | 52 | |
53 | - if ( ! $email->is_active() ) { |
|
53 | + if (!$email->is_active()) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
57 | + if (method_exists($this, $email_type)) { |
|
58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
62 | + do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | * @param array $merge_tags |
72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
73 | 73 | */ |
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
75 | 75 | |
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
77 | 77 | $merge_tags = array_merge( |
78 | 78 | $merge_tags, |
79 | - $this->get_subscription_merge_tags( $object ) |
|
79 | + $this->get_subscription_merge_tags($object) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
93 | + public function get_subscription_merge_tags($subscription) { |
|
94 | 94 | |
95 | 95 | // Abort if it does not exist. |
96 | - if ( ! $subscription->get_id() ) { |
|
96 | + if (!$subscription->get_id()) { |
|
97 | 97 | return array(); |
98 | 98 | } |
99 | 99 | |
100 | - $invoice = $subscription->get_parent_invoice(); |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | 101 | return array( |
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function should_send_notification( $invoice ) { |
|
122 | + public function should_send_notification($invoice) { |
|
123 | 123 | return 0 != $invoice->get_id(); |
124 | 124 | } |
125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param WPInv_Invoice $invoice |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
132 | + public function get_recipients($invoice) { |
|
133 | + $recipients = array($invoice->get_email()); |
|
134 | 134 | |
135 | 135 | $cc = $invoice->get_email_cc(); |
136 | 136 | |
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
137 | + if (!empty($cc)) { |
|
138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return $recipients; |
@@ -150,63 +150,63 @@ discard block |
||
150 | 150 | * @param string $type |
151 | 151 | * @param array $extra_args Extra template args. |
152 | 152 | */ |
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
154 | 154 | |
155 | 155 | // Abort in case the parent invoice does not exist. |
156 | 156 | $invoice = $subscription->get_parent_invoice(); |
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
157 | + if (!$this->should_send_notification($invoice)) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | |
161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
161 | + if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) { |
|
162 | 162 | return; |
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
165 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
166 | 166 | |
167 | - $recipients = $this->get_recipients( $invoice ); |
|
167 | + $recipients = $this->get_recipients($invoice); |
|
168 | 168 | $mailer = new GetPaid_Notification_Email_Sender(); |
169 | 169 | $merge_tags = $email->get_merge_tags(); |
170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
170 | + $content = $email->get_content($merge_tags, $extra_args); |
|
171 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
172 | 172 | $attachments = $email->get_attachments(); |
173 | 173 | |
174 | 174 | $result = $mailer->send( |
175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
175 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
176 | 176 | $subject, |
177 | 177 | $content, |
178 | 178 | $attachments |
179 | 179 | ); |
180 | 180 | |
181 | 181 | // Maybe send a copy to the admin. |
182 | - if ( $email->include_admin_bcc() ) { |
|
182 | + if ($email->include_admin_bcc()) { |
|
183 | 183 | $mailer->send( |
184 | 184 | wpinv_get_admin_email(), |
185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
185 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
186 | 186 | $content, |
187 | 187 | $attachments |
188 | 188 | ); |
189 | 189 | } |
190 | 190 | |
191 | - if ( $result ) { |
|
191 | + if ($result) { |
|
192 | 192 | $invoice->add_system_note( |
193 | 193 | sprintf( |
194 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
195 | - sanitize_key( $type ), |
|
196 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
194 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
195 | + sanitize_key($type), |
|
196 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
197 | 197 | ) |
198 | 198 | ); |
199 | 199 | } else { |
200 | 200 | $invoice->add_system_note( |
201 | 201 | sprintf( |
202 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
203 | - sanitize_key( $type ), |
|
204 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
202 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
203 | + sanitize_key($type), |
|
204 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
205 | 205 | ) |
206 | 206 | ); |
207 | 207 | } |
208 | 208 | |
209 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
209 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
210 | 210 | |
211 | 211 | } |
212 | 212 | |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @param WPInv_Subscription $subscription |
217 | 217 | */ |
218 | - public function subscription_trial( $subscription ) { |
|
218 | + public function subscription_trial($subscription) { |
|
219 | 219 | |
220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
220 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
221 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param WPInv_Subscription $subscription |
229 | 229 | */ |
230 | - public function subscription_cancelled( $subscription ) { |
|
230 | + public function subscription_cancelled($subscription) { |
|
231 | 231 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
232 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
233 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 | |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @param WPInv_Subscription $subscription |
241 | 241 | */ |
242 | - public function subscription_expired( $subscription ) { |
|
242 | + public function subscription_expired($subscription) { |
|
243 | 243 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
244 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
245 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
246 | 246 | |
247 | 247 | } |
248 | 248 | |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param WPInv_Subscription $subscription |
253 | 253 | */ |
254 | - public function subscription_complete( $subscription ) { |
|
254 | + public function subscription_complete($subscription) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
256 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
257 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
258 | 258 | |
259 | 259 | } |
260 | 260 | |
@@ -264,18 +264,18 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function renewal_reminder() { |
266 | 266 | |
267 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
267 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
268 | 268 | |
269 | 269 | // Fetch reminder days. |
270 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
270 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
271 | 271 | |
272 | 272 | // Abort if non is set. |
273 | - if ( empty( $reminder_days ) ) { |
|
273 | + if (empty($reminder_days)) { |
|
274 | 274 | return; |
275 | 275 | } |
276 | 276 | |
277 | 277 | // Fetch matching subscriptions. |
278 | - $args = array( |
|
278 | + $args = array( |
|
279 | 279 | 'number' => -1, |
280 | 280 | 'count_total' => false, |
281 | 281 | 'status' => 'trialling active', |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | ), |
285 | 285 | ); |
286 | 286 | |
287 | - foreach ( $reminder_days as $days ) { |
|
288 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
287 | + foreach ($reminder_days as $days) { |
|
288 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
289 | 289 | |
290 | 290 | $args['date_expires_query'][] = array( |
291 | 291 | 'year' => $date['year'], |
@@ -295,14 +295,14 @@ discard block |
||
295 | 295 | |
296 | 296 | } |
297 | 297 | |
298 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
298 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
299 | 299 | |
300 | - foreach ( $subscriptions as $subscription ) { |
|
300 | + foreach ($subscriptions as $subscription) { |
|
301 | 301 | |
302 | 302 | // Skip packages. |
303 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
303 | + if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) { |
|
304 | 304 | $email->object = $subscription; |
305 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
305 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
62 | - 'page' => 1, |
|
63 | - 'exclude' => array(), |
|
64 | - 'orderby' => 'date', |
|
65 | - 'order' => 'DESC', |
|
66 | - 'type' => wpinv_item_types(), |
|
67 | - 'meta_query' => array(), |
|
68 | - 'return' => 'objects', |
|
69 | - 'paginate' => false, |
|
60 | + 'status' => array( 'publish' ), |
|
61 | + 'limit' => get_option( 'posts_per_page' ), |
|
62 | + 'page' => 1, |
|
63 | + 'exclude' => array(), |
|
64 | + 'orderby' => 'date', |
|
65 | + 'order' => 'DESC', |
|
66 | + 'type' => wpinv_item_types(), |
|
67 | + 'meta_query' => array(), |
|
68 | + 'return' => 'objects', |
|
69 | + 'paginate' => false, |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | |
207 | 207 | function wpinv_get_item_types() { |
208 | 208 | $item_types = array( |
209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
211 | - ); |
|
209 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
211 | + ); |
|
212 | 212 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
213 | 213 | } |
214 | 214 | |
@@ -249,17 +249,17 @@ discard block |
||
249 | 249 | function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
250 | 250 | if ( $post_ids ) { |
251 | 251 | $args = array( |
252 | - 'post_type' => 'wpi_item', |
|
253 | - 'orderby' => 'rand', |
|
254 | - 'post_count' => $num, |
|
255 | - 'fields' => 'ids', |
|
256 | - ); |
|
252 | + 'post_type' => 'wpi_item', |
|
253 | + 'orderby' => 'rand', |
|
254 | + 'post_count' => $num, |
|
255 | + 'fields' => 'ids', |
|
256 | + ); |
|
257 | 257 | } else { |
258 | 258 | $args = array( |
259 | - 'post_type' => 'wpi_item', |
|
260 | - 'orderby' => 'rand', |
|
261 | - 'post_count' => $num, |
|
262 | - ); |
|
259 | + 'post_type' => 'wpi_item', |
|
260 | + 'orderby' => 'rand', |
|
261 | + 'post_count' => $num, |
|
262 | + ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $args = apply_filters( 'wpinv_get_random_items', $args ); |
@@ -426,9 +426,9 @@ discard block |
||
426 | 426 | $bill_times = $item->get_recurring_limit(); |
427 | 427 | |
428 | 428 | if ( ! empty( $bill_times ) ) { |
429 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
430 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
431 | - } |
|
429 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
430 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
431 | + } |
|
432 | 432 | |
433 | 433 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
434 | 434 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' == strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $field ); |
|
29 | + if ('id' == strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($field); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return empty($id) ? false : wpinv_get_item($id); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->exists() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
60 | + 'status' => array('publish'), |
|
61 | + 'limit' => get_option('posts_per_page'), |
|
62 | 62 | 'page' => 1, |
63 | 63 | 'exclude' => array(), |
64 | 64 | 'orderby' => 'date', |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'fields' => 'ids', |
79 | 79 | 'orderby' => $args['orderby'], |
80 | 80 | 'order' => $args['order'], |
81 | - 'paged' => absint( $args['page'] ), |
|
81 | + 'paged' => absint($args['page']), |
|
82 | 82 | ); |
83 | 83 | |
84 | - if ( ! empty( $args['exclude'] ) ) { |
|
85 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
84 | + if (!empty($args['exclude'])) { |
|
85 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( ! $args['paginate'] ) { |
|
88 | + if (!$args['paginate']) { |
|
89 | 89 | $wp_query_args['no_found_rows'] = true; |
90 | 90 | } |
91 | 91 | |
92 | - if ( ! empty( $args['search'] ) ) { |
|
92 | + if (!empty($args['search'])) { |
|
93 | 93 | $wp_query_args['s'] = $args['search']; |
94 | 94 | } |
95 | 95 | |
96 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
97 | - $types = wpinv_parse_list( $args['type'] ); |
|
96 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
97 | + $types = wpinv_parse_list($args['type']); |
|
98 | 98 | $wp_query_args['meta_query'][] = array( |
99 | 99 | 'key' => '_wpinv_type', |
100 | - 'value' => implode( ',', $types ), |
|
100 | + 'value' => implode(',', $types), |
|
101 | 101 | 'compare' => 'IN', |
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args ); |
|
105 | + $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
|
106 | 106 | |
107 | 107 | // Get results. |
108 | - $items = new WP_Query( $wp_query_args ); |
|
108 | + $items = new WP_Query($wp_query_args); |
|
109 | 109 | |
110 | - if ( 'objects' === $args['return'] ) { |
|
111 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
112 | - } elseif ( 'self' === $args['return'] ) { |
|
110 | + if ('objects' === $args['return']) { |
|
111 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
112 | + } elseif ('self' === $args['return']) { |
|
113 | 113 | return $items; |
114 | 114 | } else { |
115 | 115 | $return = $items->posts; |
116 | 116 | } |
117 | 117 | |
118 | - if ( $args['paginate'] ) { |
|
118 | + if ($args['paginate']) { |
|
119 | 119 | return (object) array( |
120 | 120 | 'items' => $return, |
121 | 121 | 'total' => $items->found_posts, |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
131 | - if ( empty( $item_id ) ) { |
|
130 | +function wpinv_is_free_item($item_id = 0) { |
|
131 | + if (empty($item_id)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - $item = new WPInv_Item( $item_id ); |
|
135 | + $item = new WPInv_Item($item_id); |
|
136 | 136 | |
137 | 137 | return $item->is_free(); |
138 | 138 | } |
@@ -142,21 +142,21 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
144 | 144 | */ |
145 | -function wpinv_item_is_editable( $item = 0 ) { |
|
145 | +function wpinv_item_is_editable($item = 0) { |
|
146 | 146 | |
147 | 147 | // Fetch the item. |
148 | - $item = new WPInv_Item( $item ); |
|
148 | + $item = new WPInv_Item($item); |
|
149 | 149 | |
150 | 150 | // Check if it is editable. |
151 | 151 | return $item->is_editable(); |
152 | 152 | } |
153 | 153 | |
154 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
155 | - if ( empty( $item_id ) ) { |
|
154 | +function wpinv_get_item_price($item_id = 0) { |
|
155 | + if (empty($item_id)) { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
159 | - $item = new WPInv_Item( $item_id ); |
|
159 | + $item = new WPInv_Item($item_id); |
|
160 | 160 | |
161 | 161 | return $item->get_price(); |
162 | 162 | } |
@@ -166,88 +166,88 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @param WPInv_Item|int $item |
168 | 168 | */ |
169 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
170 | - $item = new WPInv_Item( $item ); |
|
169 | +function wpinv_is_recurring_item($item = 0) { |
|
170 | + $item = new WPInv_Item($item); |
|
171 | 171 | return $item->is_recurring(); |
172 | 172 | } |
173 | 173 | |
174 | -function wpinv_item_price( $item_id = 0 ) { |
|
175 | - if ( empty( $item_id ) ) { |
|
174 | +function wpinv_item_price($item_id = 0) { |
|
175 | + if (empty($item_id)) { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $price = wpinv_get_item_price( $item_id ); |
|
180 | - $price = wpinv_price( $price ); |
|
179 | + $price = wpinv_get_item_price($item_id); |
|
180 | + $price = wpinv_price($price); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
182 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
183 | 183 | } |
184 | 184 | |
185 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
186 | - if ( is_null( $amount_override ) ) { |
|
187 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
185 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
186 | + if (is_null($amount_override)) { |
|
187 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
188 | 188 | } else { |
189 | 189 | $original_price = $amount_override; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $price = $original_price; |
193 | 193 | |
194 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
194 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
198 | - if ( empty( $item_id ) ) { |
|
197 | +function wpinv_item_custom_singular_name($item_id) { |
|
198 | + if (empty($item_id)) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | 201 | |
202 | - $item = new WPInv_Item( $item_id ); |
|
202 | + $item = new WPInv_Item($item_id); |
|
203 | 203 | |
204 | 204 | return $item->get_custom_singular_name(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_get_item_types() { |
208 | 208 | $item_types = array( |
209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
209 | + 'custom' => __('Standard', 'invoicing'), |
|
210 | + 'fee' => __('Fee', 'invoicing'), |
|
211 | 211 | ); |
212 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
212 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | function wpinv_item_types() { |
216 | 216 | $item_types = wpinv_get_item_types(); |
217 | 217 | |
218 | - return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
218 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
219 | 219 | } |
220 | 220 | |
221 | -function wpinv_get_item_type( $item_id ) { |
|
222 | - if ( empty( $item_id ) ) { |
|
221 | +function wpinv_get_item_type($item_id) { |
|
222 | + if (empty($item_id)) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | |
226 | - $item = new WPInv_Item( $item_id ); |
|
226 | + $item = new WPInv_Item($item_id); |
|
227 | 227 | |
228 | 228 | return $item->get_type(); |
229 | 229 | } |
230 | 230 | |
231 | -function wpinv_item_type( $item_id ) { |
|
231 | +function wpinv_item_type($item_id) { |
|
232 | 232 | $item_types = wpinv_get_item_types(); |
233 | 233 | |
234 | - $item_type = wpinv_get_item_type( $item_id ); |
|
234 | + $item_type = wpinv_get_item_type($item_id); |
|
235 | 235 | |
236 | - if ( empty( $item_type ) ) { |
|
236 | + if (empty($item_type)) { |
|
237 | 237 | $item_type = '-'; |
238 | 238 | } |
239 | 239 | |
240 | - $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' ); |
|
240 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
241 | 241 | |
242 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
242 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
243 | 243 | } |
244 | 244 | |
245 | -function wpinv_get_random_item( $post_ids = true ) { |
|
246 | - wpinv_get_random_items( 1, $post_ids ); |
|
245 | +function wpinv_get_random_item($post_ids = true) { |
|
246 | + wpinv_get_random_items(1, $post_ids); |
|
247 | 247 | } |
248 | 248 | |
249 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
250 | - if ( $post_ids ) { |
|
249 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
250 | + if ($post_ids) { |
|
251 | 251 | $args = array( |
252 | 252 | 'post_type' => 'wpi_item', |
253 | 253 | 'orderby' => 'rand', |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
265 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
266 | 266 | |
267 | - return get_posts( $args ); |
|
267 | + return get_posts($args); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | * @param WPInv_Item|int $item |
274 | 274 | * @param bool $html |
275 | 275 | */ |
276 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
276 | +function wpinv_get_item_suffix($item, $html = true) { |
|
277 | 277 | |
278 | - $item = new WPInv_Item( $item ); |
|
279 | - $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : ''; |
|
280 | - $suffix = $html ? $suffix : strip_tags( $suffix ); |
|
278 | + $item = new WPInv_Item($item); |
|
279 | + $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : ''; |
|
280 | + $suffix = $html ? $suffix : strip_tags($suffix); |
|
281 | 281 | |
282 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
282 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | * @param WPInv_Item|int $item |
289 | 289 | * @param bool $force_delete |
290 | 290 | */ |
291 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
292 | - $item = new WPInv_Item( $item ); |
|
293 | - $item->delete( $force_delete ); |
|
291 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
292 | + $item = new WPInv_Item($item); |
|
293 | + $item->delete($force_delete); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -329,44 +329,44 @@ discard block |
||
329 | 329 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
330 | 330 | * @return bool|WP_Error|WPInv_Item |
331 | 331 | */ |
332 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
332 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
333 | 333 | |
334 | 334 | // Prepare the item. |
335 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
336 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
337 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
335 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
336 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
337 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
338 | 338 | |
339 | - if ( ! empty( $item ) ) { |
|
339 | + if (!empty($item)) { |
|
340 | 340 | $args['ID'] = $item->get_id(); |
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Do we have an item? |
345 | - if ( ! empty( $args['ID'] ) ) { |
|
346 | - $item = new WPInv_Item( $args['ID'] ); |
|
345 | + if (!empty($args['ID'])) { |
|
346 | + $item = new WPInv_Item($args['ID']); |
|
347 | 347 | } else { |
348 | 348 | $item = new WPInv_Item(); |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Do we have an error? |
352 | - if ( ! empty( $item->last_error ) ) { |
|
353 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
352 | + if (!empty($item->last_error)) { |
|
353 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Update item props. |
357 | - $item->set_props( $args ); |
|
357 | + $item->set_props($args); |
|
358 | 358 | |
359 | 359 | // Save the item. |
360 | 360 | $item->save(); |
361 | 361 | |
362 | 362 | // Do we have an error? |
363 | - if ( ! empty( $item->last_error ) ) { |
|
364 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
363 | + if (!empty($item->last_error)) { |
|
364 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | // Was the item saved? |
368 | - if ( ! $item->get_id() ) { |
|
369 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
368 | + if (!$item->get_id()) { |
|
369 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $item; |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @see wpinv_create_item() |
380 | 380 | */ |
381 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
382 | - return wpinv_create_item( $args, $wp_error ); |
|
381 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
382 | + return wpinv_create_item($args, $wp_error); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Sanitizes a recurring period |
387 | 387 | */ |
388 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
388 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
389 | 389 | |
390 | 390 | $periods = array( |
391 | 391 | 'D' => 'day', |
@@ -394,16 +394,16 @@ discard block |
||
394 | 394 | 'Y' => 'year', |
395 | 395 | ); |
396 | 396 | |
397 | - if ( ! isset( $periods[ $period ] ) ) { |
|
397 | + if (!isset($periods[$period])) { |
|
398 | 398 | $period = 'D'; |
399 | 399 | } |
400 | 400 | |
401 | - return $full ? $periods[ $period ] : $period; |
|
401 | + return $full ? $periods[$period] : $period; |
|
402 | 402 | |
403 | 403 | } |
404 | 404 | |
405 | -function wpinv_item_max_buyable_quantity( $item_id ) { |
|
406 | - return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id ); |
|
405 | +function wpinv_item_max_buyable_quantity($item_id) { |
|
406 | + return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -411,45 +411,45 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @param WPInv_Item|GetPaid_Form_Item $item |
413 | 413 | */ |
414 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
414 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
415 | 415 | |
416 | 416 | // Abort if it is not recurring. |
417 | - if ( ! $item->is_recurring() ) { |
|
417 | + if (!$item->is_recurring()) { |
|
418 | 418 | return ''; |
419 | 419 | } |
420 | 420 | |
421 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
422 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
423 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
421 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
422 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
423 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
424 | 424 | $initial_class = 'getpaid-item-initial-price'; |
425 | 425 | $recurring_class = 'getpaid-item-recurring-price'; |
426 | 426 | $bill_times = $item->get_recurring_limit(); |
427 | 427 | |
428 | - if ( ! empty( $bill_times ) ) { |
|
428 | + if (!empty($bill_times)) { |
|
429 | 429 | $bill_times = $item->get_recurring_interval() * $bill_times; |
430 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
430 | + $bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times); |
|
431 | 431 | } |
432 | 432 | |
433 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
434 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
435 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
433 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
434 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
435 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
436 | 436 | } |
437 | 437 | |
438 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
439 | - return __( 'Free forever', 'invoicing' ); |
|
438 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
439 | + return __('Free forever', 'invoicing'); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | // For free trial items. |
443 | - if ( $item->has_free_trial() ) { |
|
444 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
443 | + if ($item->has_free_trial()) { |
|
444 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
445 | 445 | |
446 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
446 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
447 | 447 | |
448 | - if ( empty( $bill_times ) ) { |
|
448 | + if (empty($bill_times)) { |
|
449 | 449 | |
450 | 450 | return sprintf( |
451 | 451 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
452 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
452 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
453 | 453 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
454 | 454 | "<span class='$recurring_class'>$recurring_price</span>", |
455 | 455 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | |
460 | 460 | return sprintf( |
461 | 461 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
462 | - _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
462 | + _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
463 | 463 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
464 | 464 | "<span class='$recurring_class'>$recurring_price</span>", |
465 | 465 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -468,11 +468,11 @@ discard block |
||
468 | 468 | |
469 | 469 | } |
470 | 470 | |
471 | - if ( empty( $bill_times ) ) { |
|
471 | + if (empty($bill_times)) { |
|
472 | 472 | |
473 | 473 | return sprintf( |
474 | 474 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
475 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
475 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
476 | 476 | "<span class='$initial_class'>$initial_price</span>", |
477 | 477 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
478 | 478 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | |
484 | 484 | return sprintf( |
485 | 485 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
486 | - _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
|
486 | + _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'), |
|
487 | 487 | "<span class='$initial_class'>$initial_price</span>", |
488 | 488 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
489 | 489 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -493,13 +493,13 @@ discard block |
||
493 | 493 | |
494 | 494 | } |
495 | 495 | |
496 | - if ( $initial_price == $recurring_price ) { |
|
496 | + if ($initial_price == $recurring_price) { |
|
497 | 497 | |
498 | - if ( empty( $bill_times ) ) { |
|
498 | + if (empty($bill_times)) { |
|
499 | 499 | |
500 | 500 | return sprintf( |
501 | 501 | // translators: $1: is the recurring price, $2: is the susbcription period |
502 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
502 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
503 | 503 | "<span class='$recurring_class'>$recurring_price</span>", |
504 | 504 | "<span class='getpaid-item-recurring-period'>$period</span>" |
505 | 505 | ); |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | |
509 | 509 | return sprintf( |
510 | 510 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
511 | - _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
511 | + _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
512 | 512 | "<span class='$recurring_class'>$recurring_price</span>", |
513 | 513 | "<span class='getpaid-item-recurring-period'>$period</span>", |
514 | 514 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -516,13 +516,13 @@ discard block |
||
516 | 516 | |
517 | 517 | } |
518 | 518 | |
519 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
519 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
520 | 520 | |
521 | - if ( empty( $bill_times ) ) { |
|
521 | + if (empty($bill_times)) { |
|
522 | 522 | |
523 | 523 | return sprintf( |
524 | 524 | // translators: $1: is the recurring period, $2: is the recurring price |
525 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
525 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
526 | 526 | "<span class='getpaid-item-recurring-period'>$period</span>", |
527 | 527 | "<span class='$recurring_class'>$recurring_price</span>" |
528 | 528 | ); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | |
532 | 532 | return sprintf( |
533 | 533 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
534 | - _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
|
534 | + _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'), |
|
535 | 535 | "<span class='getpaid-item-recurring-period'>$period</span>", |
536 | 536 | "<span class='$recurring_class'>$recurring_price</span>", |
537 | 537 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -539,11 +539,11 @@ discard block |
||
539 | 539 | |
540 | 540 | } |
541 | 541 | |
542 | - if ( empty( $bill_times ) ) { |
|
542 | + if (empty($bill_times)) { |
|
543 | 543 | |
544 | 544 | return sprintf( |
545 | 545 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
546 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
546 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
547 | 547 | "<span class='$initial_class'>$initial_price</span>", |
548 | 548 | "<span class='$recurring_class'>$recurring_price</span>", |
549 | 549 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | |
554 | 554 | return sprintf( |
555 | 555 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
556 | - _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
|
556 | + _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'), |
|
557 | 557 | "<span class='$initial_class'>$initial_price</span>", |
558 | 558 | "<span class='$recurring_class'>$recurring_price</span>", |
559 | 559 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -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,199 +10,199 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - 'shipping' => array( |
|
54 | - 'initial' => 0, |
|
55 | - 'recurring' => 0, |
|
56 | - ), |
|
57 | - |
|
58 | - ); |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets the associated payment form. |
|
62 | - * |
|
63 | - * @var GetPaid_Payment_Form |
|
64 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + 'shipping' => array( |
|
54 | + 'initial' => 0, |
|
55 | + 'recurring' => 0, |
|
56 | + ), |
|
57 | + |
|
58 | + ); |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets the associated payment form. |
|
62 | + * |
|
63 | + * @var GetPaid_Payment_Form |
|
64 | + */ |
|
65 | 65 | protected $payment_form = null; |
66 | 66 | |
67 | 67 | /** |
68 | - * The country for the submission. |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - public $country = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * The state for the submission. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - public $state = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * The invoice associated with the submission. |
|
84 | - * |
|
85 | - * @var WPInv_Invoice |
|
86 | - */ |
|
87 | - protected $invoice = null; |
|
88 | - |
|
89 | - /** |
|
90 | - * The recurring item for the submission. |
|
91 | - * |
|
92 | - * @var int |
|
93 | - */ |
|
94 | - public $has_recurring = 0; |
|
95 | - |
|
96 | - /** |
|
97 | - * An array of fees for the submission. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - protected $fees = array(); |
|
102 | - |
|
103 | - /** |
|
104 | - * An array of discounts for the submission. |
|
105 | - * |
|
106 | - * @var array |
|
107 | - */ |
|
108 | - protected $discounts = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * An array of taxes for the submission. |
|
112 | - * |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - protected $taxes = array(); |
|
116 | - |
|
117 | - /** |
|
118 | - * An array of items for the submission. |
|
119 | - * |
|
120 | - * @var GetPaid_Form_Item[] |
|
121 | - */ |
|
122 | - protected $items = array(); |
|
123 | - |
|
124 | - /** |
|
125 | - * The last error. |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
129 | - public $last_error = null; |
|
130 | - |
|
131 | - /** |
|
132 | - * The last error code. |
|
133 | - * |
|
134 | - * @var string |
|
135 | - */ |
|
136 | - public $last_error_code = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * Class constructor. |
|
140 | - * |
|
141 | - */ |
|
142 | - public function __construct() { |
|
143 | - |
|
144 | - // Set the state and country to the default state and country. |
|
145 | - $this->country = wpinv_default_billing_country(); |
|
146 | - $this->state = wpinv_get_default_state(); |
|
147 | - |
|
148 | - // Do we have an actual submission? |
|
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Loads submission data. |
|
157 | - * |
|
158 | - * @param array $data |
|
159 | - */ |
|
160 | - public function load_data( $data ) { |
|
161 | - |
|
162 | - // Allow plugins to filter the data. |
|
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
164 | - |
|
165 | - // Cache it... |
|
166 | - $this->data = $data; |
|
167 | - |
|
168 | - // Then generate a unique id from the data. |
|
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
170 | - |
|
171 | - // Finally, process the submission. |
|
172 | - try { |
|
173 | - |
|
174 | - // Each process is passed an instance of the class (with reference) |
|
175 | - // and should throw an Exception whenever it encounters one. |
|
176 | - $processors = apply_filters( |
|
177 | - 'getpaid_payment_form_submission_processors', |
|
178 | - array( |
|
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
185 | - ), |
|
186 | - $this |
|
187 | - ); |
|
188 | - |
|
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
191 | - } |
|
68 | + * The country for the submission. |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + public $country = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * The state for the submission. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + public $state = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * The invoice associated with the submission. |
|
84 | + * |
|
85 | + * @var WPInv_Invoice |
|
86 | + */ |
|
87 | + protected $invoice = null; |
|
88 | + |
|
89 | + /** |
|
90 | + * The recurring item for the submission. |
|
91 | + * |
|
92 | + * @var int |
|
93 | + */ |
|
94 | + public $has_recurring = 0; |
|
95 | + |
|
96 | + /** |
|
97 | + * An array of fees for the submission. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + protected $fees = array(); |
|
102 | + |
|
103 | + /** |
|
104 | + * An array of discounts for the submission. |
|
105 | + * |
|
106 | + * @var array |
|
107 | + */ |
|
108 | + protected $discounts = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * An array of taxes for the submission. |
|
112 | + * |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + protected $taxes = array(); |
|
116 | + |
|
117 | + /** |
|
118 | + * An array of items for the submission. |
|
119 | + * |
|
120 | + * @var GetPaid_Form_Item[] |
|
121 | + */ |
|
122 | + protected $items = array(); |
|
123 | + |
|
124 | + /** |
|
125 | + * The last error. |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | + public $last_error = null; |
|
130 | + |
|
131 | + /** |
|
132 | + * The last error code. |
|
133 | + * |
|
134 | + * @var string |
|
135 | + */ |
|
136 | + public $last_error_code = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * Class constructor. |
|
140 | + * |
|
141 | + */ |
|
142 | + public function __construct() { |
|
143 | + |
|
144 | + // Set the state and country to the default state and country. |
|
145 | + $this->country = wpinv_default_billing_country(); |
|
146 | + $this->state = wpinv_get_default_state(); |
|
147 | + |
|
148 | + // Do we have an actual submission? |
|
149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | + $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Loads submission data. |
|
157 | + * |
|
158 | + * @param array $data |
|
159 | + */ |
|
160 | + public function load_data( $data ) { |
|
161 | + |
|
162 | + // Allow plugins to filter the data. |
|
163 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
164 | + |
|
165 | + // Cache it... |
|
166 | + $this->data = $data; |
|
167 | + |
|
168 | + // Then generate a unique id from the data. |
|
169 | + $this->id = md5( wp_json_encode( $data ) ); |
|
170 | + |
|
171 | + // Finally, process the submission. |
|
172 | + try { |
|
173 | + |
|
174 | + // Each process is passed an instance of the class (with reference) |
|
175 | + // and should throw an Exception whenever it encounters one. |
|
176 | + $processors = apply_filters( |
|
177 | + 'getpaid_payment_form_submission_processors', |
|
178 | + array( |
|
179 | + array( $this, 'process_payment_form' ), |
|
180 | + array( $this, 'process_invoice' ), |
|
181 | + array( $this, 'process_fees' ), |
|
182 | + array( $this, 'process_items' ), |
|
183 | + array( $this, 'process_discount' ), |
|
184 | + array( $this, 'process_taxes' ), |
|
185 | + ), |
|
186 | + $this |
|
187 | + ); |
|
188 | + |
|
189 | + foreach ( $processors as $processor ) { |
|
190 | + call_user_func_array( $processor, array( &$this ) ); |
|
191 | + } |
|
192 | 192 | } catch ( GetPaid_Payment_Exception $e ) { |
193 | - $this->last_error = $e->getMessage(); |
|
194 | - $this->last_error_code = $e->getErrorCode(); |
|
195 | - } catch ( Exception $e ) { |
|
196 | - $this->last_error = $e->getMessage(); |
|
197 | - $this->last_error_code = $e->getCode(); |
|
198 | - } |
|
193 | + $this->last_error = $e->getMessage(); |
|
194 | + $this->last_error_code = $e->getErrorCode(); |
|
195 | + } catch ( Exception $e ) { |
|
196 | + $this->last_error = $e->getMessage(); |
|
197 | + $this->last_error_code = $e->getCode(); |
|
198 | + } |
|
199 | 199 | |
200 | - // Fired when we are done processing a submission. |
|
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
200 | + // Fired when we are done processing a submission. |
|
201 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
202 | 202 | |
203 | - } |
|
203 | + } |
|
204 | 204 | |
205 | - /* |
|
205 | + /* |
|
206 | 206 | |-------------------------------------------------------------------------- |
207 | 207 | | Payment Forms. |
208 | 208 | |-------------------------------------------------------------------------- |
@@ -211,39 +211,39 @@ discard block |
||
211 | 211 | | submission has an active payment form etc. |
212 | 212 | */ |
213 | 213 | |
214 | - /** |
|
215 | - * Prepares the submission's payment form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - */ |
|
219 | - public function process_payment_form() { |
|
214 | + /** |
|
215 | + * Prepares the submission's payment form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + */ |
|
219 | + public function process_payment_form() { |
|
220 | 220 | |
221 | - // Every submission needs an active payment form. |
|
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
224 | - } |
|
221 | + // Every submission needs an active payment form. |
|
222 | + if ( empty( $this->data['form_id'] ) ) { |
|
223 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
224 | + } |
|
225 | 225 | |
226 | - // Fetch the payment form. |
|
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
226 | + // Fetch the payment form. |
|
227 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
231 | - } |
|
229 | + if ( ! $this->payment_form->is_active() ) { |
|
230 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
231 | + } |
|
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
234 | - } |
|
233 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
234 | + } |
|
235 | 235 | |
236 | 236 | /** |
237 | - * Returns the payment form. |
|
238 | - * |
|
239 | - * @since 1.0.19 |
|
240 | - * @return GetPaid_Payment_Form |
|
241 | - */ |
|
242 | - public function get_payment_form() { |
|
243 | - return $this->payment_form; |
|
244 | - } |
|
237 | + * Returns the payment form. |
|
238 | + * |
|
239 | + * @since 1.0.19 |
|
240 | + * @return GetPaid_Payment_Form |
|
241 | + */ |
|
242 | + public function get_payment_form() { |
|
243 | + return $this->payment_form; |
|
244 | + } |
|
245 | 245 | |
246 | - /* |
|
246 | + /* |
|
247 | 247 | |-------------------------------------------------------------------------- |
248 | 248 | | Invoices. |
249 | 249 | |-------------------------------------------------------------------------- |
@@ -252,84 +252,84 @@ discard block |
||
252 | 252 | | might be for an existing invoice. |
253 | 253 | */ |
254 | 254 | |
255 | - /** |
|
256 | - * Prepares the submission's invoice. |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - */ |
|
260 | - public function process_invoice() { |
|
255 | + /** |
|
256 | + * Prepares the submission's invoice. |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + */ |
|
260 | + public function process_invoice() { |
|
261 | 261 | |
262 | - // Abort if there is no invoice. |
|
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
264 | - return; |
|
265 | - } |
|
262 | + // Abort if there is no invoice. |
|
263 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
264 | + return; |
|
265 | + } |
|
266 | 266 | |
267 | - // If the submission is for an existing invoice, ensure that it exists |
|
268 | - // and that it is not paid for. |
|
269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
267 | + // If the submission is for an existing invoice, ensure that it exists |
|
268 | + // and that it is not paid for. |
|
269 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
270 | 270 | |
271 | 271 | if ( empty( $invoice ) ) { |
272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
273 | - } |
|
274 | - |
|
275 | - if ( $invoice->is_paid() ) { |
|
276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
277 | - } |
|
278 | - |
|
279 | - $this->payment_form->invoice = $invoice; |
|
280 | - if ( ! $this->payment_form->is_default() ) { |
|
281 | - |
|
282 | - $items = array(); |
|
283 | - $item_ids = array(); |
|
284 | - |
|
285 | - foreach ( $invoice->get_items() as $item ) { |
|
286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
287 | - $item_ids[] = $item->get_id(); |
|
288 | - $items[] = $item; |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
294 | - $item_ids[] = $item->get_id(); |
|
295 | - $items[] = $item; |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - $this->payment_form->set_items( $items ); |
|
300 | - |
|
301 | - } else { |
|
302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
303 | - } |
|
304 | - |
|
305 | - $this->country = $invoice->get_country(); |
|
306 | - $this->state = $invoice->get_state(); |
|
307 | - $this->invoice = $invoice; |
|
308 | - |
|
309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Returns the associated invoice. |
|
314 | - * |
|
315 | - * @since 1.0.19 |
|
316 | - * @return WPInv_Invoice |
|
317 | - */ |
|
318 | - public function get_invoice() { |
|
319 | - return $this->invoice; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Checks whether there is an invoice associated with this submission. |
|
324 | - * |
|
325 | - * @since 1.0.19 |
|
326 | - * @return bool |
|
327 | - */ |
|
328 | - public function has_invoice() { |
|
329 | - return ! empty( $this->invoice ); |
|
330 | - } |
|
331 | - |
|
332 | - /* |
|
272 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
273 | + } |
|
274 | + |
|
275 | + if ( $invoice->is_paid() ) { |
|
276 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
277 | + } |
|
278 | + |
|
279 | + $this->payment_form->invoice = $invoice; |
|
280 | + if ( ! $this->payment_form->is_default() ) { |
|
281 | + |
|
282 | + $items = array(); |
|
283 | + $item_ids = array(); |
|
284 | + |
|
285 | + foreach ( $invoice->get_items() as $item ) { |
|
286 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
287 | + $item_ids[] = $item->get_id(); |
|
288 | + $items[] = $item; |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
293 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
294 | + $item_ids[] = $item->get_id(); |
|
295 | + $items[] = $item; |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + $this->payment_form->set_items( $items ); |
|
300 | + |
|
301 | + } else { |
|
302 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
303 | + } |
|
304 | + |
|
305 | + $this->country = $invoice->get_country(); |
|
306 | + $this->state = $invoice->get_state(); |
|
307 | + $this->invoice = $invoice; |
|
308 | + |
|
309 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Returns the associated invoice. |
|
314 | + * |
|
315 | + * @since 1.0.19 |
|
316 | + * @return WPInv_Invoice |
|
317 | + */ |
|
318 | + public function get_invoice() { |
|
319 | + return $this->invoice; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Checks whether there is an invoice associated with this submission. |
|
324 | + * |
|
325 | + * @since 1.0.19 |
|
326 | + * @return bool |
|
327 | + */ |
|
328 | + public function has_invoice() { |
|
329 | + return ! empty( $this->invoice ); |
|
330 | + } |
|
331 | + |
|
332 | + /* |
|
333 | 333 | |-------------------------------------------------------------------------- |
334 | 334 | | Items. |
335 | 335 | |-------------------------------------------------------------------------- |
@@ -338,129 +338,129 @@ discard block |
||
338 | 338 | | recurring item. But can have an unlimited number of non-recurring items. |
339 | 339 | */ |
340 | 340 | |
341 | - /** |
|
342 | - * Prepares the submission's items. |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - */ |
|
346 | - public function process_items() { |
|
347 | - |
|
348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
349 | - |
|
350 | - foreach ( $processor->items as $item ) { |
|
351 | - $this->add_item( $item ); |
|
352 | - } |
|
353 | - |
|
354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Adds an item to the submission. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param GetPaid_Form_Item $item |
|
362 | - */ |
|
363 | - public function add_item( $item ) { |
|
364 | - |
|
365 | - // Make sure that it is available for purchase. |
|
366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
367 | - return; |
|
368 | - } |
|
369 | - |
|
370 | - // Each submission can only contain one recurring item. |
|
371 | - if ( $item->is_recurring() ) { |
|
372 | - $this->has_recurring = $item->get_id(); |
|
373 | - } |
|
374 | - |
|
375 | - // Update the items and totals. |
|
376 | - $this->items[ $item->get_id() ] = $item; |
|
377 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
378 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
379 | - |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Removes a specific item. |
|
384 | - * |
|
385 | - * You should not call this method after the discounts and taxes |
|
386 | - * have been calculated. |
|
387 | - * |
|
388 | - * @since 1.0.19 |
|
389 | - */ |
|
390 | - public function remove_item( $item_id ) { |
|
391 | - |
|
392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
395 | - |
|
396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
397 | - $this->has_recurring = 0; |
|
398 | - } |
|
399 | - |
|
400 | - unset( $this->items[ $item_id ] ); |
|
401 | - } |
|
402 | - |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Returns the subtotal. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - */ |
|
410 | - public function get_subtotal() { |
|
411 | - |
|
412 | - if ( wpinv_prices_include_tax() ) { |
|
413 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
414 | - } |
|
415 | - |
|
416 | - return $this->totals['subtotal']['initial']; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Returns the recurring subtotal. |
|
421 | - * |
|
422 | - * @since 1.0.19 |
|
423 | - */ |
|
424 | - public function get_recurring_subtotal() { |
|
425 | - |
|
426 | - if ( wpinv_prices_include_tax() ) { |
|
427 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
428 | - } |
|
429 | - |
|
430 | - return $this->totals['subtotal']['recurring']; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Returns all items. |
|
435 | - * |
|
436 | - * @since 1.0.19 |
|
437 | - * @return GetPaid_Form_Item[] |
|
438 | - */ |
|
439 | - public function get_items() { |
|
440 | - return $this->items; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Checks if there's a single subscription group in the submission. |
|
445 | - * |
|
446 | - * @since 2.3.0 |
|
447 | - * @return bool |
|
448 | - */ |
|
449 | - public function has_subscription_group() { |
|
450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Checks if there are multipe subscription groups in the submission. |
|
455 | - * |
|
456 | - * @since 2.3.0 |
|
457 | - * @return bool |
|
458 | - */ |
|
459 | - public function has_multiple_subscription_groups() { |
|
460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
461 | - } |
|
462 | - |
|
463 | - /* |
|
341 | + /** |
|
342 | + * Prepares the submission's items. |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + */ |
|
346 | + public function process_items() { |
|
347 | + |
|
348 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
349 | + |
|
350 | + foreach ( $processor->items as $item ) { |
|
351 | + $this->add_item( $item ); |
|
352 | + } |
|
353 | + |
|
354 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Adds an item to the submission. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param GetPaid_Form_Item $item |
|
362 | + */ |
|
363 | + public function add_item( $item ) { |
|
364 | + |
|
365 | + // Make sure that it is available for purchase. |
|
366 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
367 | + return; |
|
368 | + } |
|
369 | + |
|
370 | + // Each submission can only contain one recurring item. |
|
371 | + if ( $item->is_recurring() ) { |
|
372 | + $this->has_recurring = $item->get_id(); |
|
373 | + } |
|
374 | + |
|
375 | + // Update the items and totals. |
|
376 | + $this->items[ $item->get_id() ] = $item; |
|
377 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
378 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
379 | + |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Removes a specific item. |
|
384 | + * |
|
385 | + * You should not call this method after the discounts and taxes |
|
386 | + * have been calculated. |
|
387 | + * |
|
388 | + * @since 1.0.19 |
|
389 | + */ |
|
390 | + public function remove_item( $item_id ) { |
|
391 | + |
|
392 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
393 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
394 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
395 | + |
|
396 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
397 | + $this->has_recurring = 0; |
|
398 | + } |
|
399 | + |
|
400 | + unset( $this->items[ $item_id ] ); |
|
401 | + } |
|
402 | + |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Returns the subtotal. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + */ |
|
410 | + public function get_subtotal() { |
|
411 | + |
|
412 | + if ( wpinv_prices_include_tax() ) { |
|
413 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
414 | + } |
|
415 | + |
|
416 | + return $this->totals['subtotal']['initial']; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Returns the recurring subtotal. |
|
421 | + * |
|
422 | + * @since 1.0.19 |
|
423 | + */ |
|
424 | + public function get_recurring_subtotal() { |
|
425 | + |
|
426 | + if ( wpinv_prices_include_tax() ) { |
|
427 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
428 | + } |
|
429 | + |
|
430 | + return $this->totals['subtotal']['recurring']; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Returns all items. |
|
435 | + * |
|
436 | + * @since 1.0.19 |
|
437 | + * @return GetPaid_Form_Item[] |
|
438 | + */ |
|
439 | + public function get_items() { |
|
440 | + return $this->items; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Checks if there's a single subscription group in the submission. |
|
445 | + * |
|
446 | + * @since 2.3.0 |
|
447 | + * @return bool |
|
448 | + */ |
|
449 | + public function has_subscription_group() { |
|
450 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Checks if there are multipe subscription groups in the submission. |
|
455 | + * |
|
456 | + * @since 2.3.0 |
|
457 | + * @return bool |
|
458 | + */ |
|
459 | + public function has_multiple_subscription_groups() { |
|
460 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
461 | + } |
|
462 | + |
|
463 | + /* |
|
464 | 464 | |-------------------------------------------------------------------------- |
465 | 465 | | Taxes |
466 | 466 | |-------------------------------------------------------------------------- |
@@ -469,128 +469,128 @@ discard block |
||
469 | 469 | | or only one-time. |
470 | 470 | */ |
471 | 471 | |
472 | - /** |
|
473 | - * Prepares the submission's taxes. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - */ |
|
477 | - public function process_taxes() { |
|
478 | - |
|
479 | - // Abort if we're not using taxes. |
|
480 | - if ( ! $this->use_taxes() ) { |
|
481 | - return; |
|
482 | - } |
|
483 | - |
|
484 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
486 | - if ( ! empty( $country ) ) { |
|
487 | - $this->country = $country; |
|
488 | - } |
|
489 | - |
|
490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
491 | - if ( ! empty( $state ) ) { |
|
492 | - $this->state = $state; |
|
493 | - } |
|
494 | - |
|
495 | - // Confirm if the provided country and the ip country are similar. |
|
496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
499 | - } |
|
500 | - |
|
501 | - // Abort if the country is not taxable. |
|
502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
503 | - return; |
|
504 | - } |
|
505 | - |
|
506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
507 | - |
|
508 | - foreach ( $processor->taxes as $tax ) { |
|
509 | - $this->add_tax( $tax ); |
|
510 | - } |
|
511 | - |
|
512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * Adds a tax to the submission. |
|
517 | - * |
|
518 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
519 | - * @since 1.0.19 |
|
520 | - */ |
|
521 | - public function add_tax( $tax ) { |
|
522 | - |
|
523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
526 | - } |
|
527 | - |
|
528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
531 | - |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Removes a specific tax. |
|
536 | - * |
|
537 | - * @since 1.0.19 |
|
538 | - */ |
|
539 | - public function remove_tax( $tax_name ) { |
|
540 | - |
|
541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
544 | - unset( $this->taxes[ $tax_name ] ); |
|
545 | - } |
|
546 | - |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * Whether or not we'll use taxes for the submission. |
|
551 | - * |
|
552 | - * @since 1.0.19 |
|
553 | - */ |
|
554 | - public function use_taxes() { |
|
555 | - |
|
556 | - $use_taxes = wpinv_use_taxes(); |
|
557 | - |
|
558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
559 | - $use_taxes = false; |
|
560 | - } |
|
561 | - |
|
562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
563 | - |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Returns the tax. |
|
568 | - * |
|
569 | - * @since 1.0.19 |
|
570 | - */ |
|
571 | - public function get_tax() { |
|
572 | - return $this->totals['taxes']['initial']; |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * Returns the recurring tax. |
|
577 | - * |
|
578 | - * @since 1.0.19 |
|
579 | - */ |
|
580 | - public function get_recurring_tax() { |
|
581 | - return $this->totals['taxes']['recurring']; |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Returns all taxes. |
|
586 | - * |
|
587 | - * @since 1.0.19 |
|
588 | - */ |
|
589 | - public function get_taxes() { |
|
590 | - return $this->taxes; |
|
591 | - } |
|
592 | - |
|
593 | - /* |
|
472 | + /** |
|
473 | + * Prepares the submission's taxes. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + */ |
|
477 | + public function process_taxes() { |
|
478 | + |
|
479 | + // Abort if we're not using taxes. |
|
480 | + if ( ! $this->use_taxes() ) { |
|
481 | + return; |
|
482 | + } |
|
483 | + |
|
484 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
485 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
486 | + if ( ! empty( $country ) ) { |
|
487 | + $this->country = $country; |
|
488 | + } |
|
489 | + |
|
490 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
491 | + if ( ! empty( $state ) ) { |
|
492 | + $this->state = $state; |
|
493 | + } |
|
494 | + |
|
495 | + // Confirm if the provided country and the ip country are similar. |
|
496 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
497 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
498 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
499 | + } |
|
500 | + |
|
501 | + // Abort if the country is not taxable. |
|
502 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
503 | + return; |
|
504 | + } |
|
505 | + |
|
506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
507 | + |
|
508 | + foreach ( $processor->taxes as $tax ) { |
|
509 | + $this->add_tax( $tax ); |
|
510 | + } |
|
511 | + |
|
512 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * Adds a tax to the submission. |
|
517 | + * |
|
518 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
519 | + * @since 1.0.19 |
|
520 | + */ |
|
521 | + public function add_tax( $tax ) { |
|
522 | + |
|
523 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
524 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
525 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
526 | + } |
|
527 | + |
|
528 | + $this->taxes[ $tax['name'] ] = $tax; |
|
529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
531 | + |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * Removes a specific tax. |
|
536 | + * |
|
537 | + * @since 1.0.19 |
|
538 | + */ |
|
539 | + public function remove_tax( $tax_name ) { |
|
540 | + |
|
541 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
542 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
543 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
544 | + unset( $this->taxes[ $tax_name ] ); |
|
545 | + } |
|
546 | + |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * Whether or not we'll use taxes for the submission. |
|
551 | + * |
|
552 | + * @since 1.0.19 |
|
553 | + */ |
|
554 | + public function use_taxes() { |
|
555 | + |
|
556 | + $use_taxes = wpinv_use_taxes(); |
|
557 | + |
|
558 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
559 | + $use_taxes = false; |
|
560 | + } |
|
561 | + |
|
562 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
563 | + |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Returns the tax. |
|
568 | + * |
|
569 | + * @since 1.0.19 |
|
570 | + */ |
|
571 | + public function get_tax() { |
|
572 | + return $this->totals['taxes']['initial']; |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * Returns the recurring tax. |
|
577 | + * |
|
578 | + * @since 1.0.19 |
|
579 | + */ |
|
580 | + public function get_recurring_tax() { |
|
581 | + return $this->totals['taxes']['recurring']; |
|
582 | + } |
|
583 | + |
|
584 | + /** |
|
585 | + * Returns all taxes. |
|
586 | + * |
|
587 | + * @since 1.0.19 |
|
588 | + */ |
|
589 | + public function get_taxes() { |
|
590 | + return $this->taxes; |
|
591 | + } |
|
592 | + |
|
593 | + /* |
|
594 | 594 | |-------------------------------------------------------------------------- |
595 | 595 | | Discounts |
596 | 596 | |-------------------------------------------------------------------------- |
@@ -599,99 +599,99 @@ discard block |
||
599 | 599 | | or only one-time. They also do not have to come from a discount code. |
600 | 600 | */ |
601 | 601 | |
602 | - /** |
|
603 | - * Prepares the submission's discount. |
|
604 | - * |
|
605 | - * @since 1.0.19 |
|
606 | - */ |
|
607 | - public function process_discount() { |
|
608 | - |
|
609 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
610 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
612 | - |
|
613 | - foreach ( $processor->discounts as $discount ) { |
|
614 | - $this->add_discount( $discount ); |
|
615 | - } |
|
616 | - |
|
617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Adds a discount to the submission. |
|
622 | - * |
|
623 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
624 | - * @since 1.0.19 |
|
625 | - */ |
|
626 | - public function add_discount( $discount ) { |
|
627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Removes a discount from the submission. |
|
634 | - * |
|
635 | - * @since 1.0.19 |
|
636 | - */ |
|
637 | - public function remove_discount( $name ) { |
|
638 | - |
|
639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
642 | - unset( $this->discounts[ $name ] ); |
|
643 | - } |
|
644 | - |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Checks whether there is a discount code associated with this submission. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - * @return bool |
|
652 | - */ |
|
653 | - public function has_discount_code() { |
|
654 | - return ! empty( $this->discounts['discount_code'] ); |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Returns the discount code. |
|
659 | - * |
|
660 | - * @since 1.0.19 |
|
661 | - * @return string |
|
662 | - */ |
|
663 | - public function get_discount_code() { |
|
664 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Returns the discount. |
|
669 | - * |
|
670 | - * @since 1.0.19 |
|
671 | - */ |
|
672 | - public function get_discount() { |
|
673 | - return $this->totals['discount']['initial']; |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Returns the recurring discount. |
|
678 | - * |
|
679 | - * @since 1.0.19 |
|
680 | - */ |
|
681 | - public function get_recurring_discount() { |
|
682 | - return $this->totals['discount']['recurring']; |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * Returns all discounts. |
|
687 | - * |
|
688 | - * @since 1.0.19 |
|
689 | - */ |
|
690 | - public function get_discounts() { |
|
691 | - return $this->discounts; |
|
692 | - } |
|
693 | - |
|
694 | - /* |
|
602 | + /** |
|
603 | + * Prepares the submission's discount. |
|
604 | + * |
|
605 | + * @since 1.0.19 |
|
606 | + */ |
|
607 | + public function process_discount() { |
|
608 | + |
|
609 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
610 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
611 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
612 | + |
|
613 | + foreach ( $processor->discounts as $discount ) { |
|
614 | + $this->add_discount( $discount ); |
|
615 | + } |
|
616 | + |
|
617 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * Adds a discount to the submission. |
|
622 | + * |
|
623 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
624 | + * @since 1.0.19 |
|
625 | + */ |
|
626 | + public function add_discount( $discount ) { |
|
627 | + $this->discounts[ $discount['name'] ] = $discount; |
|
628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Removes a discount from the submission. |
|
634 | + * |
|
635 | + * @since 1.0.19 |
|
636 | + */ |
|
637 | + public function remove_discount( $name ) { |
|
638 | + |
|
639 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
640 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
641 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
642 | + unset( $this->discounts[ $name ] ); |
|
643 | + } |
|
644 | + |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Checks whether there is a discount code associated with this submission. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + * @return bool |
|
652 | + */ |
|
653 | + public function has_discount_code() { |
|
654 | + return ! empty( $this->discounts['discount_code'] ); |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Returns the discount code. |
|
659 | + * |
|
660 | + * @since 1.0.19 |
|
661 | + * @return string |
|
662 | + */ |
|
663 | + public function get_discount_code() { |
|
664 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Returns the discount. |
|
669 | + * |
|
670 | + * @since 1.0.19 |
|
671 | + */ |
|
672 | + public function get_discount() { |
|
673 | + return $this->totals['discount']['initial']; |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Returns the recurring discount. |
|
678 | + * |
|
679 | + * @since 1.0.19 |
|
680 | + */ |
|
681 | + public function get_recurring_discount() { |
|
682 | + return $this->totals['discount']['recurring']; |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Returns all discounts. |
|
687 | + * |
|
688 | + * @since 1.0.19 |
|
689 | + */ |
|
690 | + public function get_discounts() { |
|
691 | + return $this->discounts; |
|
692 | + } |
|
693 | + |
|
694 | + /* |
|
695 | 695 | |-------------------------------------------------------------------------- |
696 | 696 | | Fees |
697 | 697 | |-------------------------------------------------------------------------- |
@@ -701,100 +701,100 @@ discard block |
||
701 | 701 | | fees. |
702 | 702 | */ |
703 | 703 | |
704 | - /** |
|
705 | - * Prepares the submission's fees. |
|
706 | - * |
|
707 | - * @since 1.0.19 |
|
708 | - */ |
|
709 | - public function process_fees() { |
|
710 | - |
|
711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
712 | - |
|
713 | - foreach ( $fees_processor->fees as $fee ) { |
|
714 | - $this->add_fee( $fee ); |
|
715 | - } |
|
716 | - |
|
717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Adds a fee to the submission. |
|
722 | - * |
|
723 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
724 | - * @since 1.0.19 |
|
725 | - */ |
|
726 | - public function add_fee( $fee ) { |
|
727 | - |
|
728 | - if ( $fee['name'] == 'shipping' ) { |
|
729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
731 | - return; |
|
732 | - } |
|
733 | - |
|
734 | - $this->fees[ $fee['name'] ] = $fee; |
|
735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
737 | - |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * Removes a fee from the submission. |
|
742 | - * |
|
743 | - * @since 1.0.19 |
|
744 | - */ |
|
745 | - public function remove_fee( $name ) { |
|
746 | - |
|
747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
750 | - unset( $this->fees[ $name ] ); |
|
751 | - } |
|
752 | - |
|
753 | - if ( 'shipping' == $name ) { |
|
754 | - $this->totals['shipping']['initial'] = 0; |
|
755 | - $this->totals['shipping']['recurring'] = 0; |
|
756 | - } |
|
757 | - |
|
758 | - } |
|
759 | - |
|
760 | - /** |
|
761 | - * Returns the fees. |
|
762 | - * |
|
763 | - * @since 1.0.19 |
|
764 | - */ |
|
765 | - public function get_fee() { |
|
766 | - return $this->totals['fees']['initial']; |
|
767 | - } |
|
768 | - |
|
769 | - /** |
|
770 | - * Returns the recurring fees. |
|
771 | - * |
|
772 | - * @since 1.0.19 |
|
773 | - */ |
|
774 | - public function get_recurring_fee() { |
|
775 | - return $this->totals['fees']['recurring']; |
|
776 | - } |
|
777 | - |
|
778 | - /** |
|
779 | - * Returns all fees. |
|
780 | - * |
|
781 | - * @since 1.0.19 |
|
782 | - */ |
|
783 | - public function get_fees() { |
|
784 | - return $this->fees; |
|
785 | - } |
|
786 | - |
|
787 | - /** |
|
788 | - * Checks if there are any fees for the form. |
|
789 | - * |
|
790 | - * @return bool |
|
791 | - * @since 1.0.19 |
|
792 | - */ |
|
793 | - public function has_fees() { |
|
794 | - return count( $this->fees ) !== 0; |
|
795 | - } |
|
796 | - |
|
797 | - /* |
|
704 | + /** |
|
705 | + * Prepares the submission's fees. |
|
706 | + * |
|
707 | + * @since 1.0.19 |
|
708 | + */ |
|
709 | + public function process_fees() { |
|
710 | + |
|
711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
712 | + |
|
713 | + foreach ( $fees_processor->fees as $fee ) { |
|
714 | + $this->add_fee( $fee ); |
|
715 | + } |
|
716 | + |
|
717 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Adds a fee to the submission. |
|
722 | + * |
|
723 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
724 | + * @since 1.0.19 |
|
725 | + */ |
|
726 | + public function add_fee( $fee ) { |
|
727 | + |
|
728 | + if ( $fee['name'] == 'shipping' ) { |
|
729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
731 | + return; |
|
732 | + } |
|
733 | + |
|
734 | + $this->fees[ $fee['name'] ] = $fee; |
|
735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
737 | + |
|
738 | + } |
|
739 | + |
|
740 | + /** |
|
741 | + * Removes a fee from the submission. |
|
742 | + * |
|
743 | + * @since 1.0.19 |
|
744 | + */ |
|
745 | + public function remove_fee( $name ) { |
|
746 | + |
|
747 | + if ( isset( $this->fees[ $name ] ) ) { |
|
748 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
749 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
750 | + unset( $this->fees[ $name ] ); |
|
751 | + } |
|
752 | + |
|
753 | + if ( 'shipping' == $name ) { |
|
754 | + $this->totals['shipping']['initial'] = 0; |
|
755 | + $this->totals['shipping']['recurring'] = 0; |
|
756 | + } |
|
757 | + |
|
758 | + } |
|
759 | + |
|
760 | + /** |
|
761 | + * Returns the fees. |
|
762 | + * |
|
763 | + * @since 1.0.19 |
|
764 | + */ |
|
765 | + public function get_fee() { |
|
766 | + return $this->totals['fees']['initial']; |
|
767 | + } |
|
768 | + |
|
769 | + /** |
|
770 | + * Returns the recurring fees. |
|
771 | + * |
|
772 | + * @since 1.0.19 |
|
773 | + */ |
|
774 | + public function get_recurring_fee() { |
|
775 | + return $this->totals['fees']['recurring']; |
|
776 | + } |
|
777 | + |
|
778 | + /** |
|
779 | + * Returns all fees. |
|
780 | + * |
|
781 | + * @since 1.0.19 |
|
782 | + */ |
|
783 | + public function get_fees() { |
|
784 | + return $this->fees; |
|
785 | + } |
|
786 | + |
|
787 | + /** |
|
788 | + * Checks if there are any fees for the form. |
|
789 | + * |
|
790 | + * @return bool |
|
791 | + * @since 1.0.19 |
|
792 | + */ |
|
793 | + public function has_fees() { |
|
794 | + return count( $this->fees ) !== 0; |
|
795 | + } |
|
796 | + |
|
797 | + /* |
|
798 | 798 | |-------------------------------------------------------------------------- |
799 | 799 | | MISC |
800 | 800 | |-------------------------------------------------------------------------- |
@@ -802,147 +802,147 @@ discard block |
||
802 | 802 | | Extra submission functions. |
803 | 803 | */ |
804 | 804 | |
805 | - /** |
|
806 | - * Returns the shipping amount. |
|
807 | - * |
|
808 | - * @since 1.0.19 |
|
809 | - */ |
|
810 | - public function get_shipping() { |
|
811 | - return $this->totals['shipping']['initial']; |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * Returns the recurring shipping. |
|
816 | - * |
|
817 | - * @since 1.0.19 |
|
818 | - */ |
|
819 | - public function get_recurring_shipping() { |
|
820 | - return $this->totals['shipping']['recurring']; |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Checks if there are any shipping fees for the form. |
|
825 | - * |
|
826 | - * @return bool |
|
827 | - * @since 1.0.19 |
|
828 | - */ |
|
829 | - public function has_shipping() { |
|
830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
831 | - } |
|
832 | - |
|
833 | - /** |
|
834 | - * Checks if this is the initial fetch. |
|
835 | - * |
|
836 | - * @return bool |
|
837 | - * @since 1.0.19 |
|
838 | - */ |
|
839 | - public function is_initial_fetch() { |
|
840 | - return empty( $this->data['initial_state'] ); |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Returns the total amount to collect for this submission. |
|
845 | - * |
|
846 | - * @since 1.0.19 |
|
847 | - */ |
|
848 | - public function get_total() { |
|
849 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
850 | - return max( $total, 0 ); |
|
851 | - } |
|
852 | - |
|
853 | - /** |
|
854 | - * Returns the recurring total amount to collect for this submission. |
|
855 | - * |
|
856 | - * @since 1.0.19 |
|
857 | - */ |
|
858 | - public function get_recurring_total() { |
|
859 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
860 | - return max( $total, 0 ); |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * Whether payment details should be collected for this submission. |
|
865 | - * |
|
866 | - * @since 1.0.19 |
|
867 | - */ |
|
868 | - public function should_collect_payment_details() { |
|
869 | - $initial = $this->get_total(); |
|
870 | - $recurring = $this->get_recurring_total(); |
|
871 | - |
|
872 | - if ( $this->has_recurring == 0 ) { |
|
873 | - $recurring = 0; |
|
874 | - } |
|
875 | - |
|
876 | - $collect = $initial > 0 || $recurring > 0; |
|
877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
878 | - } |
|
879 | - |
|
880 | - /** |
|
881 | - * Returns the billing email of the user. |
|
882 | - * |
|
883 | - * @since 1.0.19 |
|
884 | - */ |
|
885 | - public function get_billing_email() { |
|
886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
887 | - } |
|
888 | - |
|
889 | - /** |
|
890 | - * Checks if the submitter has a billing email. |
|
891 | - * |
|
892 | - * @since 1.0.19 |
|
893 | - */ |
|
894 | - public function has_billing_email() { |
|
895 | - $billing_email = $this->get_billing_email(); |
|
896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
897 | - } |
|
898 | - |
|
899 | - /** |
|
900 | - * Returns the appropriate currency for the submission. |
|
901 | - * |
|
902 | - * @since 1.0.19 |
|
903 | - * @return string |
|
904 | - */ |
|
905 | - public function get_currency() { |
|
906 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
907 | - } |
|
908 | - |
|
909 | - /** |
|
910 | - * Returns the raw submission data. |
|
911 | - * |
|
912 | - * @since 1.0.19 |
|
913 | - * @return array |
|
914 | - */ |
|
915 | - public function get_data() { |
|
916 | - return $this->data; |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * Returns a field from the submission data |
|
921 | - * |
|
922 | - * @param string $field |
|
923 | - * @since 1.0.19 |
|
924 | - * @return mixed|null |
|
925 | - */ |
|
926 | - public function get_field( $field, $sub_array_key = null ) { |
|
927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
928 | - } |
|
929 | - |
|
930 | - /** |
|
931 | - * Checks if a required field is set. |
|
932 | - * |
|
933 | - * @since 1.0.19 |
|
934 | - */ |
|
935 | - public function is_required_field_set( $field ) { |
|
936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
937 | - } |
|
938 | - |
|
939 | - /** |
|
940 | - * Formats an amount |
|
941 | - * |
|
942 | - * @since 1.0.19 |
|
943 | - */ |
|
944 | - public function format_amount( $amount ) { |
|
945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
946 | - } |
|
805 | + /** |
|
806 | + * Returns the shipping amount. |
|
807 | + * |
|
808 | + * @since 1.0.19 |
|
809 | + */ |
|
810 | + public function get_shipping() { |
|
811 | + return $this->totals['shipping']['initial']; |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * Returns the recurring shipping. |
|
816 | + * |
|
817 | + * @since 1.0.19 |
|
818 | + */ |
|
819 | + public function get_recurring_shipping() { |
|
820 | + return $this->totals['shipping']['recurring']; |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Checks if there are any shipping fees for the form. |
|
825 | + * |
|
826 | + * @return bool |
|
827 | + * @since 1.0.19 |
|
828 | + */ |
|
829 | + public function has_shipping() { |
|
830 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
831 | + } |
|
832 | + |
|
833 | + /** |
|
834 | + * Checks if this is the initial fetch. |
|
835 | + * |
|
836 | + * @return bool |
|
837 | + * @since 1.0.19 |
|
838 | + */ |
|
839 | + public function is_initial_fetch() { |
|
840 | + return empty( $this->data['initial_state'] ); |
|
841 | + } |
|
842 | + |
|
843 | + /** |
|
844 | + * Returns the total amount to collect for this submission. |
|
845 | + * |
|
846 | + * @since 1.0.19 |
|
847 | + */ |
|
848 | + public function get_total() { |
|
849 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
850 | + return max( $total, 0 ); |
|
851 | + } |
|
852 | + |
|
853 | + /** |
|
854 | + * Returns the recurring total amount to collect for this submission. |
|
855 | + * |
|
856 | + * @since 1.0.19 |
|
857 | + */ |
|
858 | + public function get_recurring_total() { |
|
859 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
860 | + return max( $total, 0 ); |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * Whether payment details should be collected for this submission. |
|
865 | + * |
|
866 | + * @since 1.0.19 |
|
867 | + */ |
|
868 | + public function should_collect_payment_details() { |
|
869 | + $initial = $this->get_total(); |
|
870 | + $recurring = $this->get_recurring_total(); |
|
871 | + |
|
872 | + if ( $this->has_recurring == 0 ) { |
|
873 | + $recurring = 0; |
|
874 | + } |
|
875 | + |
|
876 | + $collect = $initial > 0 || $recurring > 0; |
|
877 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
878 | + } |
|
879 | + |
|
880 | + /** |
|
881 | + * Returns the billing email of the user. |
|
882 | + * |
|
883 | + * @since 1.0.19 |
|
884 | + */ |
|
885 | + public function get_billing_email() { |
|
886 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
887 | + } |
|
888 | + |
|
889 | + /** |
|
890 | + * Checks if the submitter has a billing email. |
|
891 | + * |
|
892 | + * @since 1.0.19 |
|
893 | + */ |
|
894 | + public function has_billing_email() { |
|
895 | + $billing_email = $this->get_billing_email(); |
|
896 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
897 | + } |
|
898 | + |
|
899 | + /** |
|
900 | + * Returns the appropriate currency for the submission. |
|
901 | + * |
|
902 | + * @since 1.0.19 |
|
903 | + * @return string |
|
904 | + */ |
|
905 | + public function get_currency() { |
|
906 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
907 | + } |
|
908 | + |
|
909 | + /** |
|
910 | + * Returns the raw submission data. |
|
911 | + * |
|
912 | + * @since 1.0.19 |
|
913 | + * @return array |
|
914 | + */ |
|
915 | + public function get_data() { |
|
916 | + return $this->data; |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * Returns a field from the submission data |
|
921 | + * |
|
922 | + * @param string $field |
|
923 | + * @since 1.0.19 |
|
924 | + * @return mixed|null |
|
925 | + */ |
|
926 | + public function get_field( $field, $sub_array_key = null ) { |
|
927 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
928 | + } |
|
929 | + |
|
930 | + /** |
|
931 | + * Checks if a required field is set. |
|
932 | + * |
|
933 | + * @since 1.0.19 |
|
934 | + */ |
|
935 | + public function is_required_field_set( $field ) { |
|
936 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
937 | + } |
|
938 | + |
|
939 | + /** |
|
940 | + * Formats an amount |
|
941 | + * |
|
942 | + * @since 1.0.19 |
|
943 | + */ |
|
944 | + public function format_amount( $amount ) { |
|
945 | + return wpinv_price( $amount, $this->get_currency() ); |
|
946 | + } |
|
947 | 947 | |
948 | 948 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | $this->state = wpinv_get_default_state(); |
147 | 147 | |
148 | 148 | // Do we have an actual submission? |
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param array $data |
159 | 159 | */ |
160 | - public function load_data( $data ) { |
|
160 | + public function load_data($data) { |
|
161 | 161 | |
162 | 162 | // Allow plugins to filter the data. |
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
164 | 164 | |
165 | 165 | // Cache it... |
166 | 166 | $this->data = $data; |
167 | 167 | |
168 | 168 | // Then generate a unique id from the data. |
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
169 | + $this->id = md5(wp_json_encode($data)); |
|
170 | 170 | |
171 | 171 | // Finally, process the submission. |
172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | $processors = apply_filters( |
177 | 177 | 'getpaid_payment_form_submission_processors', |
178 | 178 | array( |
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
179 | + array($this, 'process_payment_form'), |
|
180 | + array($this, 'process_invoice'), |
|
181 | + array($this, 'process_fees'), |
|
182 | + array($this, 'process_items'), |
|
183 | + array($this, 'process_discount'), |
|
184 | + array($this, 'process_taxes'), |
|
185 | 185 | ), |
186 | 186 | $this |
187 | 187 | ); |
188 | 188 | |
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
189 | + foreach ($processors as $processor) { |
|
190 | + call_user_func_array($processor, array(&$this)); |
|
191 | 191 | } |
192 | -} catch ( GetPaid_Payment_Exception $e ) { |
|
192 | +} catch (GetPaid_Payment_Exception $e) { |
|
193 | 193 | $this->last_error = $e->getMessage(); |
194 | 194 | $this->last_error_code = $e->getErrorCode(); |
195 | - } catch ( Exception $e ) { |
|
195 | + } catch (Exception $e) { |
|
196 | 196 | $this->last_error = $e->getMessage(); |
197 | 197 | $this->last_error_code = $e->getCode(); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Fired when we are done processing a submission. |
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
202 | 202 | |
203 | 203 | } |
204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | public function process_payment_form() { |
220 | 220 | |
221 | 221 | // Every submission needs an active payment form. |
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
222 | + if (empty($this->data['form_id'])) { |
|
223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Fetch the payment form. |
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
229 | + if (!$this->payment_form->is_active()) { |
|
230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
231 | 231 | } |
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -260,53 +260,53 @@ discard block |
||
260 | 260 | public function process_invoice() { |
261 | 261 | |
262 | 262 | // Abort if there is no invoice. |
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | + if (empty($this->data['invoice_id'])) { |
|
264 | 264 | return; |
265 | 265 | } |
266 | 266 | |
267 | 267 | // If the submission is for an existing invoice, ensure that it exists |
268 | 268 | // and that it is not paid for. |
269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
269 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
270 | 270 | |
271 | - if ( empty( $invoice ) ) { |
|
272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
271 | + if (empty($invoice)) { |
|
272 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
273 | 273 | } |
274 | 274 | |
275 | - if ( $invoice->is_paid() ) { |
|
276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
275 | + if ($invoice->is_paid()) { |
|
276 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | $this->payment_form->invoice = $invoice; |
280 | - if ( ! $this->payment_form->is_default() ) { |
|
280 | + if (!$this->payment_form->is_default()) { |
|
281 | 281 | |
282 | 282 | $items = array(); |
283 | 283 | $item_ids = array(); |
284 | 284 | |
285 | - foreach ( $invoice->get_items() as $item ) { |
|
286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
285 | + foreach ($invoice->get_items() as $item) { |
|
286 | + if (!in_array($item->get_id(), $item_ids)) { |
|
287 | 287 | $item_ids[] = $item->get_id(); |
288 | 288 | $items[] = $item; |
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
292 | + foreach ($this->payment_form->get_items() as $item) { |
|
293 | + if (!in_array($item->get_id(), $item_ids)) { |
|
294 | 294 | $item_ids[] = $item->get_id(); |
295 | 295 | $items[] = $item; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | - $this->payment_form->set_items( $items ); |
|
299 | + $this->payment_form->set_items($items); |
|
300 | 300 | |
301 | 301 | } else { |
302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
302 | + $this->payment_form->set_items($invoice->get_items()); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $this->country = $invoice->get_country(); |
306 | 306 | $this->state = $invoice->get_state(); |
307 | 307 | $this->invoice = $invoice; |
308 | 308 | |
309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
309 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @return bool |
327 | 327 | */ |
328 | 328 | public function has_invoice() { |
329 | - return ! empty( $this->invoice ); |
|
329 | + return !empty($this->invoice); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /* |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function process_items() { |
347 | 347 | |
348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
348 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
349 | 349 | |
350 | - foreach ( $processor->items as $item ) { |
|
351 | - $this->add_item( $item ); |
|
350 | + foreach ($processor->items as $item) { |
|
351 | + $this->add_item($item); |
|
352 | 352 | } |
353 | 353 | |
354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
354 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -360,20 +360,20 @@ discard block |
||
360 | 360 | * @since 1.0.19 |
361 | 361 | * @param GetPaid_Form_Item $item |
362 | 362 | */ |
363 | - public function add_item( $item ) { |
|
363 | + public function add_item($item) { |
|
364 | 364 | |
365 | 365 | // Make sure that it is available for purchase. |
366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
366 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
367 | 367 | return; |
368 | 368 | } |
369 | 369 | |
370 | 370 | // Each submission can only contain one recurring item. |
371 | - if ( $item->is_recurring() ) { |
|
371 | + if ($item->is_recurring()) { |
|
372 | 372 | $this->has_recurring = $item->get_id(); |
373 | 373 | } |
374 | 374 | |
375 | 375 | // Update the items and totals. |
376 | - $this->items[ $item->get_id() ] = $item; |
|
376 | + $this->items[$item->get_id()] = $item; |
|
377 | 377 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
378 | 378 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
379 | 379 | |
@@ -387,17 +387,17 @@ discard block |
||
387 | 387 | * |
388 | 388 | * @since 1.0.19 |
389 | 389 | */ |
390 | - public function remove_item( $item_id ) { |
|
390 | + public function remove_item($item_id) { |
|
391 | 391 | |
392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
392 | + if (isset($this->items[$item_id])) { |
|
393 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
394 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
395 | 395 | |
396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
396 | + if ($this->items[$item_id]->is_recurring()) { |
|
397 | 397 | $this->has_recurring = 0; |
398 | 398 | } |
399 | 399 | |
400 | - unset( $this->items[ $item_id ] ); |
|
400 | + unset($this->items[$item_id]); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | */ |
410 | 410 | public function get_subtotal() { |
411 | 411 | |
412 | - if ( wpinv_prices_include_tax() ) { |
|
412 | + if (wpinv_prices_include_tax()) { |
|
413 | 413 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
414 | 414 | } |
415 | 415 | |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | */ |
424 | 424 | public function get_recurring_subtotal() { |
425 | 425 | |
426 | - if ( wpinv_prices_include_tax() ) { |
|
426 | + if (wpinv_prices_include_tax()) { |
|
427 | 427 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
428 | 428 | } |
429 | 429 | |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @return bool |
448 | 448 | */ |
449 | 449 | public function has_subscription_group() { |
450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
450 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @return bool |
458 | 458 | */ |
459 | 459 | public function has_multiple_subscription_groups() { |
460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
460 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /* |
@@ -477,39 +477,39 @@ discard block |
||
477 | 477 | public function process_taxes() { |
478 | 478 | |
479 | 479 | // Abort if we're not using taxes. |
480 | - if ( ! $this->use_taxes() ) { |
|
480 | + if (!$this->use_taxes()) { |
|
481 | 481 | return; |
482 | 482 | } |
483 | 483 | |
484 | 484 | // If a custom country && state has been passed in, use it to calculate taxes. |
485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
486 | - if ( ! empty( $country ) ) { |
|
485 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
486 | + if (!empty($country)) { |
|
487 | 487 | $this->country = $country; |
488 | 488 | } |
489 | 489 | |
490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
491 | - if ( ! empty( $state ) ) { |
|
490 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
491 | + if (!empty($state)) { |
|
492 | 492 | $this->state = $state; |
493 | 493 | } |
494 | 494 | |
495 | 495 | // Confirm if the provided country and the ip country are similar. |
496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
496 | + $address_confirmed = $this->get_field('confirm-address'); |
|
497 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
498 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | // Abort if the country is not taxable. |
502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
502 | + if (!wpinv_is_country_taxable($this->country)) { |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
507 | 507 | |
508 | - foreach ( $processor->taxes as $tax ) { |
|
509 | - $this->add_tax( $tax ); |
|
508 | + foreach ($processor->taxes as $tax) { |
|
509 | + $this->add_tax($tax); |
|
510 | 510 | } |
511 | 511 | |
512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
512 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -518,16 +518,16 @@ discard block |
||
518 | 518 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
519 | 519 | * @since 1.0.19 |
520 | 520 | */ |
521 | - public function add_tax( $tax ) { |
|
521 | + public function add_tax($tax) { |
|
522 | 522 | |
523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
523 | + if (wpinv_round_tax_per_tax_rate()) { |
|
524 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
525 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
526 | 526 | } |
527 | 527 | |
528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
528 | + $this->taxes[$tax['name']] = $tax; |
|
529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
531 | 531 | |
532 | 532 | } |
533 | 533 | |
@@ -536,12 +536,12 @@ discard block |
||
536 | 536 | * |
537 | 537 | * @since 1.0.19 |
538 | 538 | */ |
539 | - public function remove_tax( $tax_name ) { |
|
539 | + public function remove_tax($tax_name) { |
|
540 | 540 | |
541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
544 | - unset( $this->taxes[ $tax_name ] ); |
|
541 | + if (isset($this->taxes[$tax_name])) { |
|
542 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
543 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
544 | + unset($this->taxes[$tax_name]); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | } |
@@ -555,11 +555,11 @@ discard block |
||
555 | 555 | |
556 | 556 | $use_taxes = wpinv_use_taxes(); |
557 | 557 | |
558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
558 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
559 | 559 | $use_taxes = false; |
560 | 560 | } |
561 | 561 | |
562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
562 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
563 | 563 | |
564 | 564 | } |
565 | 565 | |
@@ -608,13 +608,13 @@ discard block |
||
608 | 608 | |
609 | 609 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
610 | 610 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
611 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
612 | 612 | |
613 | - foreach ( $processor->discounts as $discount ) { |
|
614 | - $this->add_discount( $discount ); |
|
613 | + foreach ($processor->discounts as $discount) { |
|
614 | + $this->add_discount($discount); |
|
615 | 615 | } |
616 | 616 | |
617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
617 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -623,10 +623,10 @@ discard block |
||
623 | 623 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
624 | 624 | * @since 1.0.19 |
625 | 625 | */ |
626 | - public function add_discount( $discount ) { |
|
627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
626 | + public function add_discount($discount) { |
|
627 | + $this->discounts[$discount['name']] = $discount; |
|
628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | /** |
@@ -634,12 +634,12 @@ discard block |
||
634 | 634 | * |
635 | 635 | * @since 1.0.19 |
636 | 636 | */ |
637 | - public function remove_discount( $name ) { |
|
637 | + public function remove_discount($name) { |
|
638 | 638 | |
639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
642 | - unset( $this->discounts[ $name ] ); |
|
639 | + if (isset($this->discounts[$name])) { |
|
640 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
641 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
642 | + unset($this->discounts[$name]); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | } |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | * @return bool |
652 | 652 | */ |
653 | 653 | public function has_discount_code() { |
654 | - return ! empty( $this->discounts['discount_code'] ); |
|
654 | + return !empty($this->discounts['discount_code']); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | /** |
@@ -708,13 +708,13 @@ discard block |
||
708 | 708 | */ |
709 | 709 | public function process_fees() { |
710 | 710 | |
711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
712 | 712 | |
713 | - foreach ( $fees_processor->fees as $fee ) { |
|
714 | - $this->add_fee( $fee ); |
|
713 | + foreach ($fees_processor->fees as $fee) { |
|
714 | + $this->add_fee($fee); |
|
715 | 715 | } |
716 | 716 | |
717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
717 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -723,17 +723,17 @@ discard block |
||
723 | 723 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
724 | 724 | * @since 1.0.19 |
725 | 725 | */ |
726 | - public function add_fee( $fee ) { |
|
726 | + public function add_fee($fee) { |
|
727 | 727 | |
728 | - if ( $fee['name'] == 'shipping' ) { |
|
729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
728 | + if ($fee['name'] == 'shipping') { |
|
729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
731 | 731 | return; |
732 | 732 | } |
733 | 733 | |
734 | - $this->fees[ $fee['name'] ] = $fee; |
|
735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
734 | + $this->fees[$fee['name']] = $fee; |
|
735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
737 | 737 | |
738 | 738 | } |
739 | 739 | |
@@ -742,15 +742,15 @@ discard block |
||
742 | 742 | * |
743 | 743 | * @since 1.0.19 |
744 | 744 | */ |
745 | - public function remove_fee( $name ) { |
|
745 | + public function remove_fee($name) { |
|
746 | 746 | |
747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
750 | - unset( $this->fees[ $name ] ); |
|
747 | + if (isset($this->fees[$name])) { |
|
748 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
749 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
750 | + unset($this->fees[$name]); |
|
751 | 751 | } |
752 | 752 | |
753 | - if ( 'shipping' == $name ) { |
|
753 | + if ('shipping' == $name) { |
|
754 | 754 | $this->totals['shipping']['initial'] = 0; |
755 | 755 | $this->totals['shipping']['recurring'] = 0; |
756 | 756 | } |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * @since 1.0.19 |
792 | 792 | */ |
793 | 793 | public function has_fees() { |
794 | - return count( $this->fees ) !== 0; |
|
794 | + return count($this->fees) !== 0; |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | /* |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | * @since 1.0.19 |
828 | 828 | */ |
829 | 829 | public function has_shipping() { |
830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
830 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | /** |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | * @since 1.0.19 |
838 | 838 | */ |
839 | 839 | public function is_initial_fetch() { |
840 | - return empty( $this->data['initial_state'] ); |
|
840 | + return empty($this->data['initial_state']); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | */ |
848 | 848 | public function get_total() { |
849 | 849 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
850 | - return max( $total, 0 ); |
|
850 | + return max($total, 0); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | /** |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | */ |
858 | 858 | public function get_recurring_total() { |
859 | 859 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
860 | - return max( $total, 0 ); |
|
860 | + return max($total, 0); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | /** |
@@ -869,12 +869,12 @@ discard block |
||
869 | 869 | $initial = $this->get_total(); |
870 | 870 | $recurring = $this->get_recurring_total(); |
871 | 871 | |
872 | - if ( $this->has_recurring == 0 ) { |
|
872 | + if ($this->has_recurring == 0) { |
|
873 | 873 | $recurring = 0; |
874 | 874 | } |
875 | 875 | |
876 | 876 | $collect = $initial > 0 || $recurring > 0; |
877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
877 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | /** |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | * @since 1.0.19 |
884 | 884 | */ |
885 | 885 | public function get_billing_email() { |
886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
886 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | /** |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | */ |
894 | 894 | public function has_billing_email() { |
895 | 895 | $billing_email = $this->get_billing_email(); |
896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
896 | + return !empty($billing_email) && is_email($billing_email); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | /** |
@@ -923,8 +923,8 @@ discard block |
||
923 | 923 | * @since 1.0.19 |
924 | 924 | * @return mixed|null |
925 | 925 | */ |
926 | - public function get_field( $field, $sub_array_key = null ) { |
|
927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
926 | + public function get_field($field, $sub_array_key = null) { |
|
927 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | /** |
@@ -932,8 +932,8 @@ discard block |
||
932 | 932 | * |
933 | 933 | * @since 1.0.19 |
934 | 934 | */ |
935 | - public function is_required_field_set( $field ) { |
|
936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
935 | + public function is_required_field_set($field) { |
|
936 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | /** |
@@ -941,8 +941,8 @@ discard block |
||
941 | 941 | * |
942 | 942 | * @since 1.0.19 |
943 | 943 | */ |
944 | - public function format_amount( $amount ) { |
|
945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
944 | + public function format_amount($amount) { |
|
945 | + return wpinv_price($amount, $this->get_currency()); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | } |