@@ -13,23 +13,23 @@ 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 | 22 | /** |
23 | - * Payment method order. |
|
24 | - * |
|
25 | - * @var int |
|
26 | - */ |
|
27 | - public $order = 8; |
|
23 | + * Payment method order. |
|
24 | + * |
|
25 | + * @var int |
|
26 | + */ |
|
27 | + public $order = 8; |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Class constructor. |
|
31 | - */ |
|
32 | - public function __construct() { |
|
30 | + * Class constructor. |
|
31 | + */ |
|
32 | + public function __construct() { |
|
33 | 33 | parent::__construct(); |
34 | 34 | |
35 | 35 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -37,22 +37,22 @@ discard block |
||
37 | 37 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
38 | 38 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
39 | 39 | |
40 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
41 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
42 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
40 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
41 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
42 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
43 | 43 | |
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | - * Process Payment. |
|
48 | - * |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice Invoice. |
|
51 | - * @param array $submission_data Posted checkout fields. |
|
52 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
47 | + * Process Payment. |
|
48 | + * |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice Invoice. |
|
51 | + * @param array $submission_data Posted checkout fields. |
|
52 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
56 | 56 | |
57 | 57 | // Add a transaction id. |
58 | 58 | $invoice->set_transaction_id( $invoice->generate_key('trans_') ); |
@@ -73,66 +73,66 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | - * Output for the order received page. |
|
77 | - * |
|
78 | - * @param WPInv_Invoice $invoice Invoice. |
|
79 | - */ |
|
80 | - public function thankyou_page( $invoice ) { |
|
76 | + * Output for the order received page. |
|
77 | + * |
|
78 | + * @param WPInv_Invoice $invoice Invoice. |
|
79 | + */ |
|
80 | + public function thankyou_page( $invoice ) { |
|
81 | 81 | |
82 | 82 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
83 | 83 | |
84 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
84 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
85 | 85 | |
86 | 86 | if ( ! empty( $this->instructions ) ) { |
87 | 87 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - $this->bank_details( $invoice ); |
|
90 | + $this->bank_details( $invoice ); |
|
91 | 91 | |
92 | - echo '</div>'; |
|
92 | + echo '</div>'; |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | /** |
99 | - * Add content to the WPI emails. |
|
100 | - * |
|
101 | - * @param WPInv_Invoice $invoice Invoice. |
|
102 | - * @param string $email_type Email format: plain text or HTML. |
|
103 | - * @param bool $sent_to_admin Sent to admin. |
|
104 | - */ |
|
105 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
99 | + * Add content to the WPI emails. |
|
100 | + * |
|
101 | + * @param WPInv_Invoice $invoice Invoice. |
|
102 | + * @param string $email_type Email format: plain text or HTML. |
|
103 | + * @param bool $sent_to_admin Sent to admin. |
|
104 | + */ |
|
105 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
106 | 106 | |
107 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
107 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
108 | 108 | |
109 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
109 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
110 | 110 | |
111 | - if ( $this->instructions ) { |
|
112 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
111 | + if ( $this->instructions ) { |
|
112 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
113 | 113 | } |
114 | 114 | |
115 | - $this->bank_details( $invoice ); |
|
115 | + $this->bank_details( $invoice ); |
|
116 | 116 | |
117 | - echo '</div>'; |
|
117 | + echo '</div>'; |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Get bank details and place into a list format. |
|
125 | - * |
|
126 | - * @param WPInv_Invoice $invoice Invoice. |
|
127 | - */ |
|
128 | - protected function bank_details( $invoice ) { |
|
124 | + * Get bank details and place into a list format. |
|
125 | + * |
|
126 | + * @param WPInv_Invoice $invoice Invoice. |
|
127 | + */ |
|
128 | + protected function bank_details( $invoice ) { |
|
129 | 129 | |
130 | - // Get the invoice country and country $locale. |
|
131 | - $country = $invoice->get_country(); |
|
132 | - $locale = $this->get_country_locale(); |
|
130 | + // Get the invoice country and country $locale. |
|
131 | + $country = $invoice->get_country(); |
|
132 | + $locale = $this->get_country_locale(); |
|
133 | 133 | |
134 | - // Get sortcode label in the $locale array and use appropriate one. |
|
135 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
134 | + // Get sortcode label in the $locale array and use appropriate one. |
|
135 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
136 | 136 | |
137 | 137 | $bank_fields = array( |
138 | 138 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -161,144 +161,144 @@ discard block |
||
161 | 161 | return; |
162 | 162 | } |
163 | 163 | |
164 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
164 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
165 | 165 | |
166 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
166 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
167 | 167 | |
168 | - foreach ( $bank_info as $key => $data ) { |
|
168 | + foreach ( $bank_info as $key => $data ) { |
|
169 | 169 | |
170 | - $key = sanitize_html_class( $key ); |
|
171 | - $label = wp_kses_post( $data['label'] ); |
|
172 | - $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
170 | + $key = sanitize_html_class( $key ); |
|
171 | + $label = wp_kses_post( $data['label'] ); |
|
172 | + $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
173 | 173 | |
174 | - echo "<tr class='getpaid-bank-transfer-$key'><th>$label</th><td>$value</td></tr>" . PHP_EOL; |
|
175 | - } |
|
174 | + echo "<tr class='getpaid-bank-transfer-$key'><th>$label</th><td>$value</td></tr>" . PHP_EOL; |
|
175 | + } |
|
176 | 176 | |
177 | - echo '</table>'; |
|
177 | + echo '</table>'; |
|
178 | 178 | |
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get country locale if localized. |
|
183 | - * |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function get_country_locale() { |
|
187 | - |
|
188 | - if ( empty( $this->locale ) ) { |
|
189 | - |
|
190 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
191 | - $this->locale = apply_filters( |
|
192 | - 'getpaid_get_bank_transfer_locale', |
|
193 | - array( |
|
194 | - 'AU' => array( |
|
195 | - 'sortcode' => array( |
|
196 | - 'label' => __( 'BSB', 'invoicing' ), |
|
197 | - ), |
|
198 | - ), |
|
199 | - 'CA' => array( |
|
200 | - 'sortcode' => array( |
|
201 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
202 | - ), |
|
203 | - ), |
|
204 | - 'IN' => array( |
|
205 | - 'sortcode' => array( |
|
206 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
207 | - ), |
|
208 | - ), |
|
209 | - 'IT' => array( |
|
210 | - 'sortcode' => array( |
|
211 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
212 | - ), |
|
213 | - ), |
|
214 | - 'NZ' => array( |
|
215 | - 'sortcode' => array( |
|
216 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
217 | - ), |
|
218 | - ), |
|
219 | - 'SE' => array( |
|
220 | - 'sortcode' => array( |
|
221 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | - ), |
|
223 | - ), |
|
224 | - 'US' => array( |
|
225 | - 'sortcode' => array( |
|
226 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
227 | - ), |
|
228 | - ), |
|
229 | - 'ZA' => array( |
|
230 | - 'sortcode' => array( |
|
231 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
232 | - ), |
|
233 | - ), |
|
234 | - ) |
|
235 | - ); |
|
236 | - |
|
237 | - } |
|
238 | - |
|
239 | - return $this->locale; |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Filters the gateway settings. |
|
245 | - * |
|
246 | - * @param array $admin_settings |
|
247 | - */ |
|
248 | - public function admin_settings( $admin_settings ) { |
|
182 | + * Get country locale if localized. |
|
183 | + * |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function get_country_locale() { |
|
187 | + |
|
188 | + if ( empty( $this->locale ) ) { |
|
189 | + |
|
190 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
191 | + $this->locale = apply_filters( |
|
192 | + 'getpaid_get_bank_transfer_locale', |
|
193 | + array( |
|
194 | + 'AU' => array( |
|
195 | + 'sortcode' => array( |
|
196 | + 'label' => __( 'BSB', 'invoicing' ), |
|
197 | + ), |
|
198 | + ), |
|
199 | + 'CA' => array( |
|
200 | + 'sortcode' => array( |
|
201 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
202 | + ), |
|
203 | + ), |
|
204 | + 'IN' => array( |
|
205 | + 'sortcode' => array( |
|
206 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
207 | + ), |
|
208 | + ), |
|
209 | + 'IT' => array( |
|
210 | + 'sortcode' => array( |
|
211 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
212 | + ), |
|
213 | + ), |
|
214 | + 'NZ' => array( |
|
215 | + 'sortcode' => array( |
|
216 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
217 | + ), |
|
218 | + ), |
|
219 | + 'SE' => array( |
|
220 | + 'sortcode' => array( |
|
221 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | + ), |
|
223 | + ), |
|
224 | + 'US' => array( |
|
225 | + 'sortcode' => array( |
|
226 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
227 | + ), |
|
228 | + ), |
|
229 | + 'ZA' => array( |
|
230 | + 'sortcode' => array( |
|
231 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
232 | + ), |
|
233 | + ), |
|
234 | + ) |
|
235 | + ); |
|
236 | + |
|
237 | + } |
|
238 | + |
|
239 | + return $this->locale; |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Filters the gateway settings. |
|
245 | + * |
|
246 | + * @param array $admin_settings |
|
247 | + */ |
|
248 | + public function admin_settings( $admin_settings ) { |
|
249 | 249 | |
250 | 250 | $admin_settings['worldpay_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' ); |
251 | - $admin_settings['worldpay_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
251 | + $admin_settings['worldpay_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
252 | 252 | |
253 | - $locale = $this->get_country_locale(); |
|
253 | + $locale = $this->get_country_locale(); |
|
254 | 254 | |
255 | - // Get sortcode label in the $locale array and use appropriate one. |
|
256 | - $country = wpinv_default_billing_country(); |
|
257 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
255 | + // Get sortcode label in the $locale array and use appropriate one. |
|
256 | + $country = wpinv_default_billing_country(); |
|
257 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
258 | 258 | |
259 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
259 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
260 | 260 | 'type' => 'text', |
261 | 261 | 'id' => 'bank_transfer_ac_name', |
262 | 262 | 'name' => __( 'Account Name', 'invoicing' ), |
263 | - ); |
|
263 | + ); |
|
264 | 264 | |
265 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
265 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_no', |
268 | 268 | 'name' => __( 'Account Number', 'invoicing' ), |
269 | - ); |
|
269 | + ); |
|
270 | 270 | |
271 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
271 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_bank_name', |
274 | 274 | 'name' => __( 'Bank Name', 'invoicing' ), |
275 | - ); |
|
275 | + ); |
|
276 | 276 | |
277 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
277 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_ifsc', |
280 | 280 | 'name' => __( 'IFSC Code', 'invoicing' ), |
281 | - ); |
|
281 | + ); |
|
282 | 282 | |
283 | - $admin_settings['bank_transfer_iban'] = array( |
|
283 | + $admin_settings['bank_transfer_iban'] = array( |
|
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_iban', |
286 | 286 | 'name' => __( 'IBAN', 'invoicing' ), |
287 | - ); |
|
287 | + ); |
|
288 | 288 | |
289 | - $admin_settings['bank_transfer_bic'] = array( |
|
289 | + $admin_settings['bank_transfer_bic'] = array( |
|
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_bic', |
292 | 292 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
293 | - ); |
|
293 | + ); |
|
294 | 294 | |
295 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
296 | - 'type' => 'text', |
|
297 | - 'id' => 'bank_transfer_sort_code', |
|
298 | - 'name' => $sortcode, |
|
299 | - ); |
|
295 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
296 | + 'type' => 'text', |
|
297 | + 'id' => 'bank_transfer_sort_code', |
|
298 | + 'name' => $sortcode, |
|
299 | + ); |
|
300 | 300 | |
301 | - $admin_settings['bank_transfer_info'] = array( |
|
301 | + $admin_settings['bank_transfer_info'] = array( |
|
302 | 302 | 'id' => 'bank_transfer_info', |
303 | 303 | 'name' => __( 'Instructions', 'invoicing' ), |
304 | 304 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | 'rows' => 5 |
309 | 309 | ); |
310 | 310 | |
311 | - return $admin_settings; |
|
312 | - } |
|
311 | + return $admin_settings; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | } |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | $css = getpaid_get_email_css(); |
111 | 111 | |
112 | 112 | // include css inliner |
113 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
114 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
113 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
114 | + include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | // Inline the css. |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $message = wpinv_email_style_body( $message ); |
191 | 191 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
192 | 192 | |
193 | - return $mailer->send( |
|
193 | + return $mailer->send( |
|
194 | 194 | $to, |
195 | 195 | $subject, |
196 | 196 | $message, |
@@ -117,14 +117,14 @@ |
||
117 | 117 | */ |
118 | 118 | function getpaid_doing_it_wrong( $function, $message, $version ) { |
119 | 119 | |
120 | - $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
121 | - |
|
122 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
123 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
124 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
125 | - } else { |
|
126 | - _doing_it_wrong( $function, $message, $version ); |
|
127 | - } |
|
120 | + $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
121 | + |
|
122 | + if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
123 | + do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
124 | + error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
125 | + } else { |
|
126 | + _doing_it_wrong( $function, $message, $version ); |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
130 | 130 |
@@ -36,36 +36,36 @@ discard block |
||
36 | 36 | 'desc_tip' => true, |
37 | 37 | 'default' => '', |
38 | 38 | 'advanced' => false |
39 | - ), |
|
39 | + ), |
|
40 | 40 | |
41 | 41 | 'form' => array( |
42 | - 'title' => __( 'Form', 'invoicing' ), |
|
43 | - 'desc' => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ), |
|
44 | - 'type' => 'text', |
|
45 | - 'desc_tip' => true, |
|
46 | - 'default' => '', |
|
47 | - 'placeholder' => __('1','invoicing'), |
|
48 | - 'advanced' => false |
|
49 | - ), |
|
50 | - |
|
51 | - 'item' => array( |
|
52 | - 'title' => __( 'Items', 'invoicing' ), |
|
53 | - 'desc' => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ), |
|
54 | - 'type' => 'text', |
|
55 | - 'desc_tip' => true, |
|
56 | - 'default' => '', |
|
57 | - 'placeholder' => __('1','invoicing'), |
|
58 | - 'advanced' => false |
|
59 | - ), |
|
42 | + 'title' => __( 'Form', 'invoicing' ), |
|
43 | + 'desc' => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ), |
|
44 | + 'type' => 'text', |
|
45 | + 'desc_tip' => true, |
|
46 | + 'default' => '', |
|
47 | + 'placeholder' => __('1','invoicing'), |
|
48 | + 'advanced' => false |
|
49 | + ), |
|
50 | + |
|
51 | + 'item' => array( |
|
52 | + 'title' => __( 'Items', 'invoicing' ), |
|
53 | + 'desc' => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ), |
|
54 | + 'type' => 'text', |
|
55 | + 'desc_tip' => true, |
|
56 | + 'default' => '', |
|
57 | + 'placeholder' => __('1','invoicing'), |
|
58 | + 'advanced' => false |
|
59 | + ), |
|
60 | 60 | |
61 | 61 | 'button' => array( |
62 | - 'title' => __( 'Button', 'invoicing' ), |
|
63 | - 'desc' => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ), |
|
64 | - 'type' => 'text', |
|
65 | - 'desc_tip' => true, |
|
66 | - 'default' => '', |
|
67 | - 'advanced' => false |
|
68 | - ) |
|
62 | + 'title' => __( 'Button', 'invoicing' ), |
|
63 | + 'desc' => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ), |
|
64 | + 'type' => 'text', |
|
65 | + 'desc_tip' => true, |
|
66 | + 'default' => '', |
|
67 | + 'advanced' => false |
|
68 | + ) |
|
69 | 69 | |
70 | 70 | ) |
71 | 71 | |
@@ -75,95 +75,95 @@ discard block |
||
75 | 75 | parent::__construct( $options ); |
76 | 76 | } |
77 | 77 | |
78 | - /** |
|
79 | - * The Super block output function. |
|
80 | - * |
|
81 | - * @param array $args |
|
82 | - * @param array $widget_args |
|
83 | - * @param string $content |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
78 | + /** |
|
79 | + * The Super block output function. |
|
80 | + * |
|
81 | + * @param array $args |
|
82 | + * @param array $widget_args |
|
83 | + * @param string $content |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | 87 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
88 | 88 | |
89 | - // Is the shortcode set up correctly? |
|
90 | - if ( empty( $args['form'] ) && empty( $args['item'] ) ) { |
|
91 | - return aui()->alert( |
|
92 | - array( |
|
93 | - 'type' => 'warning', |
|
94 | - 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
95 | - ) |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - // Payment form or button? |
|
100 | - if ( ! empty( $args['form'] ) ) { |
|
101 | - return $this->handle_payment_form( $args ); |
|
102 | - } else { |
|
103 | - return $this->handle_buy_item( $args ); |
|
104 | - } |
|
105 | - |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Displaying a payment form |
|
110 | - * |
|
111 | - * @return string |
|
112 | - */ |
|
89 | + // Is the shortcode set up correctly? |
|
90 | + if ( empty( $args['form'] ) && empty( $args['item'] ) ) { |
|
91 | + return aui()->alert( |
|
92 | + array( |
|
93 | + 'type' => 'warning', |
|
94 | + 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
95 | + ) |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + // Payment form or button? |
|
100 | + if ( ! empty( $args['form'] ) ) { |
|
101 | + return $this->handle_payment_form( $args ); |
|
102 | + } else { |
|
103 | + return $this->handle_buy_item( $args ); |
|
104 | + } |
|
105 | + |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Displaying a payment form |
|
110 | + * |
|
111 | + * @return string |
|
112 | + */ |
|
113 | 113 | protected function handle_payment_form( $args = array() ) { |
114 | 114 | |
115 | - if ( empty( $args['button'] ) ) { |
|
116 | - ob_start(); |
|
117 | - getpaid_display_payment_form( $args['form'] ); |
|
118 | - return ob_get_clean(); |
|
119 | - } |
|
115 | + if ( empty( $args['button'] ) ) { |
|
116 | + ob_start(); |
|
117 | + getpaid_display_payment_form( $args['form'] ); |
|
118 | + return ob_get_clean(); |
|
119 | + } |
|
120 | 120 | |
121 | - return $this->payment_form_button( $args['form'], $args['button'] ); |
|
122 | - } |
|
121 | + return $this->payment_form_button( $args['form'], $args['button'] ); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Displays a payment form button. |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
124 | + /** |
|
125 | + * Displays a payment form button. |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | 129 | protected function payment_form_button( $form, $button ) { |
130 | - return getpaid_get_payment_button( $button, $form ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Selling an item |
|
135 | - * |
|
136 | - * @return string |
|
137 | - */ |
|
130 | + return getpaid_get_payment_button( $button, $form ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Selling an item |
|
135 | + * |
|
136 | + * @return string |
|
137 | + */ |
|
138 | 138 | protected function handle_buy_item( $args = array() ) { |
139 | 139 | |
140 | - if ( empty( $args['button'] ) ) { |
|
141 | - return $this->buy_item_form( $args['item'] ); |
|
142 | - } |
|
140 | + if ( empty( $args['button'] ) ) { |
|
141 | + return $this->buy_item_form( $args['item'] ); |
|
142 | + } |
|
143 | 143 | |
144 | - return $this->buy_item_button( $args['item'], $args['button'] ); |
|
144 | + return $this->buy_item_button( $args['item'], $args['button'] ); |
|
145 | 145 | |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Displays a buy item form. |
|
150 | - * |
|
151 | - * @return string |
|
152 | - */ |
|
148 | + /** |
|
149 | + * Displays a buy item form. |
|
150 | + * |
|
151 | + * @return string |
|
152 | + */ |
|
153 | 153 | protected function buy_item_form( $item ) { |
154 | - $items = getpaid_convert_items_to_array( $item ); |
|
155 | - ob_start(); |
|
156 | - getpaid_display_item_payment_form( $items ); |
|
157 | - return ob_get_clean(); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Displays a buy item button. |
|
162 | - * |
|
163 | - * @return string |
|
164 | - */ |
|
154 | + $items = getpaid_convert_items_to_array( $item ); |
|
155 | + ob_start(); |
|
156 | + getpaid_display_item_payment_form( $items ); |
|
157 | + return ob_get_clean(); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Displays a buy item button. |
|
162 | + * |
|
163 | + * @return string |
|
164 | + */ |
|
165 | 165 | protected function buy_item_button( $item, $button ) { |
166 | - return getpaid_get_payment_button( $button, null, $item ); |
|
166 | + return getpaid_get_payment_button( $button, null, $item ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | } |
@@ -13,128 +13,128 @@ |
||
13 | 13 | class GetPaid_Payment_Forms { |
14 | 14 | |
15 | 15 | /** |
16 | - * Class constructor |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | - |
|
25 | - // Sync form amount whenever invoice statuses change. |
|
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | - |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Increments a form's revenue whenever there is a payment. |
|
34 | - * |
|
35 | - * @param WPInv_Invoice $invoice |
|
36 | - */ |
|
37 | - public function increment_form_revenue( $invoice ) { |
|
38 | - |
|
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | - $form->save(); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Decreases form revenue whenever invoice payment changes. |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice |
|
51 | - */ |
|
52 | - public function decrease_form_revenue( $invoice ) { |
|
53 | - |
|
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | - $form->save(); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates a form's failed amount. |
|
64 | - * |
|
65 | - * @param WPInv_Invoice $invoice |
|
66 | - * @param string $from |
|
67 | - * @param string $to |
|
68 | - */ |
|
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | - |
|
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | - $form->save(); |
|
79 | - } |
|
80 | - |
|
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | - $form->save(); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Updates a form's refunded amount. |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice |
|
92 | - * @param string $from |
|
93 | - * @param string $to |
|
94 | - */ |
|
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | - |
|
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | - $form->save(); |
|
105 | - } |
|
106 | - |
|
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | - $form->save(); |
|
110 | - } |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Updates a form's cancelled amount. |
|
116 | - * |
|
117 | - * @param WPInv_Invoice $invoice |
|
118 | - * @param string $from |
|
119 | - * @param string $to |
|
120 | - */ |
|
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | - |
|
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | - $form->save(); |
|
131 | - } |
|
132 | - |
|
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | - $form->save(); |
|
136 | - } |
|
137 | - |
|
138 | - } |
|
16 | + * Class constructor |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | + |
|
25 | + // Sync form amount whenever invoice statuses change. |
|
26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | + |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Increments a form's revenue whenever there is a payment. |
|
34 | + * |
|
35 | + * @param WPInv_Invoice $invoice |
|
36 | + */ |
|
37 | + public function increment_form_revenue( $invoice ) { |
|
38 | + |
|
39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | + if ( $form->get_id() ) { |
|
41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | + $form->save(); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Decreases form revenue whenever invoice payment changes. |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice |
|
51 | + */ |
|
52 | + public function decrease_form_revenue( $invoice ) { |
|
53 | + |
|
54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | + if ( $form->get_id() ) { |
|
56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | + $form->save(); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates a form's failed amount. |
|
64 | + * |
|
65 | + * @param WPInv_Invoice $invoice |
|
66 | + * @param string $from |
|
67 | + * @param string $to |
|
68 | + */ |
|
69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | + |
|
71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | + if ( $form->get_id() ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if ( 'wpi-failed' == $from ) { |
|
77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | + $form->save(); |
|
79 | + } |
|
80 | + |
|
81 | + if ( 'wpi-failed' == $to ) { |
|
82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | + $form->save(); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Updates a form's refunded amount. |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice |
|
92 | + * @param string $from |
|
93 | + * @param string $to |
|
94 | + */ |
|
95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | + |
|
97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | + if ( $form->get_id() ) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + if ( 'wpi-refunded' == $from ) { |
|
103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | + $form->save(); |
|
105 | + } |
|
106 | + |
|
107 | + if ( 'wpi-refunded' == $to ) { |
|
108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | + $form->save(); |
|
110 | + } |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Updates a form's cancelled amount. |
|
116 | + * |
|
117 | + * @param WPInv_Invoice $invoice |
|
118 | + * @param string $from |
|
119 | + * @param string $to |
|
120 | + */ |
|
121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | + |
|
123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | + if ( $form->get_id() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( 'wpi-cancelled' == $from ) { |
|
129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | + $form->save(); |
|
131 | + } |
|
132 | + |
|
133 | + if ( 'wpi-cancelled' == $to ) { |
|
134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | + $form->save(); |
|
136 | + } |
|
137 | + |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
17 | 17 | |
18 | 18 | /** |
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | 23 | public static function output( $post ) { |
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Save meta box data. |
|
90 | - * |
|
91 | - * @param int $post_id |
|
92 | - */ |
|
93 | - public static function save( $post_id ) { |
|
89 | + * Save meta box data. |
|
90 | + * |
|
91 | + * @param int $post_id |
|
92 | + */ |
|
93 | + public static function save( $post_id ) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Converts an array fo form items to objects. |
|
125 | - * |
|
126 | - * @param array $items |
|
127 | - */ |
|
128 | - public static function item_to_objects( $items ) { |
|
124 | + * Converts an array fo form items to objects. |
|
125 | + * |
|
126 | + * @param array $items |
|
127 | + */ |
|
128 | + public static function item_to_objects( $items ) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | 378 | $discount = new WPInv_Discount( $post_id ); |
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | - array( |
|
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
382 | + array( |
|
383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | - ) |
|
389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | + ) |
|
396 | 396 | ); |
397 | 397 | |
398 | - $discount->save(); |
|
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | - } |
|
398 | + $discount->save(); |
|
399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | + } |
|
401 | 401 | } |
@@ -12,108 +12,108 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
14 | 14 | |
15 | - /** |
|
16 | - * The fee validation error. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $fee_error; |
|
20 | - |
|
21 | - /** |
|
22 | - * Submission fees. |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $fees = array(); |
|
15 | + /** |
|
16 | + * The fee validation error. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $fee_error; |
|
20 | + |
|
21 | + /** |
|
22 | + * Submission fees. |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $fees = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Process any existing invoice fees. |
|
35 | + if ( $submission->has_invoice() ) { |
|
36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | + } |
|
38 | + |
|
39 | + // Process price fields. |
|
40 | + $data = $submission->get_data(); |
|
41 | + $payment_form = $submission->get_payment_form(); |
|
42 | + |
|
43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
44 | + |
|
45 | + if ( 'price_input' == $element['type'] ) { |
|
46 | + $this->process_price_input( $element, $data ); |
|
47 | + } |
|
48 | + |
|
49 | + if ( 'price_select' == $element['type'] ) { |
|
50 | + $this->process_price_select( $element, $data ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Process a price input field. |
|
59 | + * |
|
60 | + * @param array $element |
|
61 | + * @param array $data |
|
62 | + */ |
|
63 | + public function process_price_input( $element, $data ) { |
|
64 | + |
|
65 | + // Abort if not passed. |
|
66 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
72 | + |
|
73 | + if ( $amount < $minimum ) { |
|
74 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
75 | + } |
|
76 | + |
|
77 | + $this->fees[ $element['label'] ] = array( |
|
78 | + 'name' => $element['label'], |
|
79 | + 'initial_fee' => $amount, |
|
80 | + 'recurring_fee' => 0, |
|
81 | + ); |
|
82 | + |
|
83 | + } |
|
26 | 84 | |
27 | 85 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Process any existing invoice fees. |
|
35 | - if ( $submission->has_invoice() ) { |
|
36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | - } |
|
38 | - |
|
39 | - // Process price fields. |
|
40 | - $data = $submission->get_data(); |
|
41 | - $payment_form = $submission->get_payment_form(); |
|
42 | - |
|
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
44 | - |
|
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data ); |
|
47 | - } |
|
48 | - |
|
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Process a price input field. |
|
59 | - * |
|
60 | - * @param array $element |
|
61 | - * @param array $data |
|
62 | - */ |
|
63 | - public function process_price_input( $element, $data ) { |
|
64 | - |
|
65 | - // Abort if not passed. |
|
66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
72 | - |
|
73 | - if ( $amount < $minimum ) { |
|
74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
75 | - } |
|
76 | - |
|
77 | - $this->fees[ $element['label'] ] = array( |
|
78 | - 'name' => $element['label'], |
|
79 | - 'initial_fee' => $amount, |
|
80 | - 'recurring_fee' => 0, |
|
81 | - ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Process a price select field. |
|
87 | - * |
|
88 | - * @param array $element |
|
89 | - * @param array $data |
|
90 | - */ |
|
91 | - public function process_price_select( $element, $data ) { |
|
92 | - |
|
93 | - // Abort if not passed. |
|
94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | - return; |
|
96 | - } |
|
97 | - |
|
98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
100 | - $total = 0; |
|
101 | - |
|
102 | - foreach ( $selected as $price ) { |
|
103 | - |
|
104 | - if ( ! isset( $options[ $price ] ) ) { |
|
105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | - } |
|
107 | - |
|
108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
109 | - } |
|
110 | - |
|
111 | - $this->fees[ $element['label'] ] = array( |
|
112 | - 'name' => $element['label'], |
|
113 | - 'initial_fee' => $total, |
|
114 | - 'recurring_fee' => 0, |
|
115 | - ); |
|
116 | - |
|
117 | - } |
|
86 | + * Process a price select field. |
|
87 | + * |
|
88 | + * @param array $element |
|
89 | + * @param array $data |
|
90 | + */ |
|
91 | + public function process_price_select( $element, $data ) { |
|
92 | + |
|
93 | + // Abort if not passed. |
|
94 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | + return; |
|
96 | + } |
|
97 | + |
|
98 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | + $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
100 | + $total = 0; |
|
101 | + |
|
102 | + foreach ( $selected as $price ) { |
|
103 | + |
|
104 | + if ( ! isset( $options[ $price ] ) ) { |
|
105 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | + } |
|
107 | + |
|
108 | + $total += (float) wpinv_sanitize_amount( $price ); |
|
109 | + } |
|
110 | + |
|
111 | + $this->fees[ $element['label'] ] = array( |
|
112 | + 'name' => $element['label'], |
|
113 | + 'initial_fee' => $total, |
|
114 | + 'recurring_fee' => 0, |
|
115 | + ); |
|
116 | + |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -12,189 +12,189 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Discount { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission discounts. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $discounts = array(); |
|
15 | + /** |
|
16 | + * Submission discounts. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $discounts = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + * @param float $initial_total |
|
26 | + * @param float $recurring_total |
|
27 | + */ |
|
28 | + public function __construct( $submission, $initial_total, $recurring_total ) { |
|
29 | + |
|
30 | + // Process any existing invoice discounts. |
|
31 | + if ( $submission->has_invoice() ) { |
|
32 | + $this->discounts = $submission->get_invoice()->get_discounts(); |
|
33 | + } |
|
34 | + |
|
35 | + // Do we have a discount? |
|
36 | + $discount = $submission->get_field( 'discount' ); |
|
37 | + |
|
38 | + if ( empty( $discount ) ) { |
|
39 | + |
|
40 | + if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | + unset( $this->discounts['discount_code'] ); |
|
42 | + } |
|
43 | + |
|
44 | + return; |
|
45 | + } |
|
46 | + |
|
47 | + // Processes the discount code. |
|
48 | + $amount = max( $initial_total, $recurring_total ); |
|
49 | + $this->process_discount( $submission, $discount, $amount ); |
|
50 | + |
|
51 | + } |
|
20 | 52 | |
21 | 53 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - * @param float $initial_total |
|
26 | - * @param float $recurring_total |
|
27 | - */ |
|
28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
29 | - |
|
30 | - // Process any existing invoice discounts. |
|
31 | - if ( $submission->has_invoice() ) { |
|
32 | - $this->discounts = $submission->get_invoice()->get_discounts(); |
|
33 | - } |
|
34 | - |
|
35 | - // Do we have a discount? |
|
36 | - $discount = $submission->get_field( 'discount' ); |
|
37 | - |
|
38 | - if ( empty( $discount ) ) { |
|
39 | - |
|
40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | - unset( $this->discounts['discount_code'] ); |
|
42 | - } |
|
43 | - |
|
44 | - return; |
|
45 | - } |
|
46 | - |
|
47 | - // Processes the discount code. |
|
48 | - $amount = max( $initial_total, $recurring_total ); |
|
49 | - $this->process_discount( $submission, $discount, $amount ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Processes a submission discount. |
|
55 | - * |
|
56 | - * @param GetPaid_Payment_Form_Submission $submission |
|
57 | - * @param string $discount |
|
58 | - * @param float $amount |
|
59 | - */ |
|
60 | - public function process_discount( $submission, $discount, $amount ) { |
|
61 | - |
|
62 | - // Fetch the discount. |
|
63 | - $discount = new WPInv_Discount( $discount ); |
|
64 | - |
|
65 | - // Ensure it is active. |
|
54 | + * Processes a submission discount. |
|
55 | + * |
|
56 | + * @param GetPaid_Payment_Form_Submission $submission |
|
57 | + * @param string $discount |
|
58 | + * @param float $amount |
|
59 | + */ |
|
60 | + public function process_discount( $submission, $discount, $amount ) { |
|
61 | + |
|
62 | + // Fetch the discount. |
|
63 | + $discount = new WPInv_Discount( $discount ); |
|
64 | + |
|
65 | + // Ensure it is active. |
|
66 | 66 | if ( ! $this->is_discount_active( $discount ) ) { |
67 | - throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
68 | - } |
|
69 | - |
|
70 | - // Exceeded limit. |
|
71 | - if ( $discount->has_exceeded_limit() ) { |
|
72 | - throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
73 | - } |
|
74 | - |
|
75 | - // Validate usages. |
|
76 | - $this->validate_single_use_discount( $submission, $discount ); |
|
77 | - |
|
78 | - // Validate amount. |
|
79 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
80 | - |
|
81 | - // Save the discount. |
|
82 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Validates a single use discount. |
|
87 | - * |
|
88 | - * @param WPInv_Discount $discount |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function is_discount_active( $discount ) { |
|
92 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Returns a user's id or email. |
|
97 | - * |
|
98 | - * @param string $email |
|
99 | - * @return int|string|false |
|
100 | - */ |
|
101 | - public function get_user_id_or_email( $email ) { |
|
102 | - |
|
103 | - if ( is_user_logged_in() ) { |
|
104 | - return get_current_user_id(); |
|
105 | - } |
|
106 | - |
|
107 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Validates a single use discount. |
|
112 | - * |
|
113 | - * @param GetPaid_Payment_Form_Submission $submission |
|
114 | - * @param WPInv_Discount $discount |
|
115 | - */ |
|
116 | - public function validate_single_use_discount( $submission, $discount ) { |
|
117 | - |
|
118 | - // Abort if it is not a single use discount. |
|
119 | - if ( ! $discount->is_single_use() ) { |
|
120 | - return; |
|
121 | - } |
|
122 | - |
|
123 | - // Ensure there is a valid billing email. |
|
124 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
125 | - |
|
126 | - if ( empty( $user ) ) { |
|
127 | - throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
128 | - } |
|
129 | - |
|
130 | - // Has the user used this discount code before? |
|
131 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
132 | - throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
133 | - } |
|
134 | - |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Validates the discount's amount. |
|
139 | - * |
|
140 | - * @param GetPaid_Payment_Form_Submission $submission |
|
141 | - * @param WPInv_Discount $discount |
|
142 | - * @param float $amount |
|
143 | - */ |
|
144 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
145 | - |
|
146 | - // Validate minimum amount. |
|
147 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
148 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
149 | - throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
150 | - } |
|
151 | - |
|
152 | - // Validate the maximum amount. |
|
153 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
154 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
155 | - throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
156 | - } |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Calculates the discount code's amount. |
|
162 | - * |
|
163 | - * Ensure that the discount exists and has been validated before calling this method. |
|
164 | - * |
|
165 | - * @param GetPaid_Payment_Form_Submission $submission |
|
166 | - * @param WPInv_Discount $discount |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - public function calculate_discount( $submission, $discount ) { |
|
170 | - |
|
171 | - $initial_discount = 0; |
|
172 | - $recurring_discount = 0; |
|
173 | - |
|
174 | - foreach ( $submission->get_items() as $item ) { |
|
175 | - |
|
176 | - // Abort if it is not valid for this item. |
|
177 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
178 | - continue; |
|
179 | - } |
|
180 | - |
|
181 | - // Calculate the initial amount... |
|
182 | - $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
183 | - |
|
184 | - // ... and maybe the recurring amount. |
|
185 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
186 | - $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
187 | - } |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - return array( |
|
192 | - 'name' => 'discount_code', |
|
193 | - 'discount_code' => $discount->get_code(), |
|
194 | - 'initial_discount' => $initial_discount, |
|
195 | - 'recurring_discount' => $recurring_discount, |
|
196 | - ); |
|
197 | - |
|
198 | - } |
|
67 | + throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
68 | + } |
|
69 | + |
|
70 | + // Exceeded limit. |
|
71 | + if ( $discount->has_exceeded_limit() ) { |
|
72 | + throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
73 | + } |
|
74 | + |
|
75 | + // Validate usages. |
|
76 | + $this->validate_single_use_discount( $submission, $discount ); |
|
77 | + |
|
78 | + // Validate amount. |
|
79 | + $this->validate_discount_amount( $submission, $discount, $amount ); |
|
80 | + |
|
81 | + // Save the discount. |
|
82 | + $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Validates a single use discount. |
|
87 | + * |
|
88 | + * @param WPInv_Discount $discount |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function is_discount_active( $discount ) { |
|
92 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Returns a user's id or email. |
|
97 | + * |
|
98 | + * @param string $email |
|
99 | + * @return int|string|false |
|
100 | + */ |
|
101 | + public function get_user_id_or_email( $email ) { |
|
102 | + |
|
103 | + if ( is_user_logged_in() ) { |
|
104 | + return get_current_user_id(); |
|
105 | + } |
|
106 | + |
|
107 | + return empty( $email ) ? false : sanitize_email( $email ); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Validates a single use discount. |
|
112 | + * |
|
113 | + * @param GetPaid_Payment_Form_Submission $submission |
|
114 | + * @param WPInv_Discount $discount |
|
115 | + */ |
|
116 | + public function validate_single_use_discount( $submission, $discount ) { |
|
117 | + |
|
118 | + // Abort if it is not a single use discount. |
|
119 | + if ( ! $discount->is_single_use() ) { |
|
120 | + return; |
|
121 | + } |
|
122 | + |
|
123 | + // Ensure there is a valid billing email. |
|
124 | + $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
125 | + |
|
126 | + if ( empty( $user ) ) { |
|
127 | + throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
128 | + } |
|
129 | + |
|
130 | + // Has the user used this discount code before? |
|
131 | + if ( ! $discount->is_valid_for_user( $user ) ) { |
|
132 | + throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
133 | + } |
|
134 | + |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Validates the discount's amount. |
|
139 | + * |
|
140 | + * @param GetPaid_Payment_Form_Submission $submission |
|
141 | + * @param WPInv_Discount $discount |
|
142 | + * @param float $amount |
|
143 | + */ |
|
144 | + public function validate_discount_amount( $submission, $discount, $amount ) { |
|
145 | + |
|
146 | + // Validate minimum amount. |
|
147 | + if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
148 | + $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
149 | + throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
150 | + } |
|
151 | + |
|
152 | + // Validate the maximum amount. |
|
153 | + if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
154 | + $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
155 | + throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
156 | + } |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Calculates the discount code's amount. |
|
162 | + * |
|
163 | + * Ensure that the discount exists and has been validated before calling this method. |
|
164 | + * |
|
165 | + * @param GetPaid_Payment_Form_Submission $submission |
|
166 | + * @param WPInv_Discount $discount |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + public function calculate_discount( $submission, $discount ) { |
|
170 | + |
|
171 | + $initial_discount = 0; |
|
172 | + $recurring_discount = 0; |
|
173 | + |
|
174 | + foreach ( $submission->get_items() as $item ) { |
|
175 | + |
|
176 | + // Abort if it is not valid for this item. |
|
177 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
178 | + continue; |
|
179 | + } |
|
180 | + |
|
181 | + // Calculate the initial amount... |
|
182 | + $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
183 | + |
|
184 | + // ... and maybe the recurring amount. |
|
185 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
186 | + $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
187 | + } |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + return array( |
|
192 | + 'name' => 'discount_code', |
|
193 | + 'discount_code' => $discount->get_code(), |
|
194 | + 'initial_discount' => $initial_discount, |
|
195 | + 'recurring_discount' => $recurring_discount, |
|
196 | + ); |
|
197 | + |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |