@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
| 3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
| 2 | +function wpinv_get_subscriptions($args = array()) { |
|
| 3 | + if (empty($args['parent_invoice_id'])) { |
|
| 4 | 4 | return false; |
| 5 | 5 | } |
| 6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
| 17 | - $args = wp_parse_args( $args, $defaults ); |
|
| 17 | + $args = wp_parse_args($args, $defaults); |
|
| 18 | 18 | |
| 19 | - if( $args['numberposts'] < 1 ) { |
|
| 19 | + if ($args['numberposts'] < 1) { |
|
| 20 | 20 | $args['numberposts'] = 999999999999; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - $posts = get_posts( $args ); |
|
| 23 | + $posts = get_posts($args); |
|
| 24 | 24 | $subscriptions = array(); |
| 25 | - if ( !empty( $posts ) ) { |
|
| 26 | - foreach ( $posts as $post ) { |
|
| 27 | - if ( !empty( $post->ID ) ) { |
|
| 28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
| 25 | + if (!empty($posts)) { |
|
| 26 | + foreach ($posts as $post) { |
|
| 27 | + if (!empty($post->ID)) { |
|
| 28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | return $subscriptions; |
| 35 | 35 | } |
| 36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
| 36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
| 37 | 37 | global $wpdb; |
| 38 | 38 | |
| 39 | - if ( empty( $id ) ) { |
|
| 39 | + if (empty($id)) { |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - $id = esc_sql( $id ); |
|
| 43 | + $id = esc_sql($id); |
|
| 44 | 44 | |
| 45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
| 45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
| 46 | 46 | |
| 47 | - if ( $invoice_id != null ) { |
|
| 48 | - return wpinv_get_invoice( $invoice_id ); |
|
| 47 | + if ($invoice_id != null) { |
|
| 48 | + return wpinv_get_invoice($invoice_id); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return false; |
@@ -55,46 +55,46 @@ discard block |
||
| 55 | 55 | * Records a new payment on the subscription |
| 56 | 56 | * |
| 57 | 57 | */ |
| 58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
| 59 | - $args = wp_parse_args( $subscription_args, array( |
|
| 58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
| 59 | + $args = wp_parse_args($subscription_args, array( |
|
| 60 | 60 | 'amount' => '', |
| 61 | 61 | 'transaction_id' => '', |
| 62 | 62 | 'gateway' => '' |
| 63 | - ) ); |
|
| 63 | + )); |
|
| 64 | 64 | |
| 65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
| 65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
| 66 | 66 | return false; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 70 | - if ( empty( $parent_invoice ) ) { |
|
| 69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 70 | + if (empty($parent_invoice)) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $invoice = new WPInv_Invoice(); |
| 75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
| 76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
| 77 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
| 78 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
| 79 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
| 80 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
| 81 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
| 82 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
| 83 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
| 84 | - $invoice->set( 'address', $parent_invoice->address ); |
|
| 85 | - $invoice->set( 'city', $parent_invoice->city ); |
|
| 86 | - $invoice->set( 'country', $parent_invoice->country ); |
|
| 87 | - $invoice->set( 'state', $parent_invoice->state ); |
|
| 88 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
| 89 | - $invoice->set( 'company', $parent_invoice->company ); |
|
| 90 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
| 91 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
| 92 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
| 93 | - |
|
| 94 | - if ( empty( $args['gateway'] ) ) { |
|
| 95 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
| 75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
| 76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
| 77 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
| 78 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
| 79 | + $invoice->set('ip', $parent_invoice->ip); |
|
| 80 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
| 81 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
| 82 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
| 83 | + $invoice->set('phone', $parent_invoice->phone); |
|
| 84 | + $invoice->set('address', $parent_invoice->address); |
|
| 85 | + $invoice->set('city', $parent_invoice->city); |
|
| 86 | + $invoice->set('country', $parent_invoice->country); |
|
| 87 | + $invoice->set('state', $parent_invoice->state); |
|
| 88 | + $invoice->set('zip', $parent_invoice->zip); |
|
| 89 | + $invoice->set('company', $parent_invoice->company); |
|
| 90 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
| 91 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
| 92 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
| 93 | + |
|
| 94 | + if (empty($args['gateway'])) { |
|
| 95 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
| 96 | 96 | } else { |
| 97 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
| 97 | + $invoice->set('gateway', $args['gateway']); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | // increase the earnings for each item in the subscription |
| 103 | 103 | $items = $recurring_details['cart_details']; |
| 104 | 104 | |
| 105 | - if ( $items ) { |
|
| 105 | + if ($items) { |
|
| 106 | 106 | $add_items = array(); |
| 107 | 107 | $cart_details = array(); |
| 108 | 108 | |
| 109 | - foreach ( $items as $item ) { |
|
| 109 | + foreach ($items as $item) { |
|
| 110 | 110 | $add_item = array(); |
| 111 | 111 | $add_item['id'] = $item['id']; |
| 112 | 112 | $add_item['quantity'] = $item['quantity']; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | break; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $invoice->set( 'items', $add_items ); |
|
| 119 | + $invoice->set('items', $add_items); |
|
| 120 | 120 | $invoice->cart_details = $cart_details; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -126,277 +126,277 @@ discard block |
||
| 126 | 126 | $tax = $recurring_details['tax']; |
| 127 | 127 | $discount = $recurring_details['discount']; |
| 128 | 128 | |
| 129 | - if ( $discount > 0 ) { |
|
| 130 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
| 129 | + if ($discount > 0) { |
|
| 130 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
| 134 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
| 135 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
| 136 | - $invoice->total = wpinv_round_amount( $total ); |
|
| 133 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
| 134 | + $invoice->tax = wpinv_round_amount($tax); |
|
| 135 | + $invoice->discount = wpinv_round_amount($discount); |
|
| 136 | + $invoice->total = wpinv_round_amount($total); |
|
| 137 | 137 | $invoice->save(); |
| 138 | 138 | |
| 139 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
| 139 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
| 140 | 140 | sleep(1); |
| 141 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
| 141 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
| 142 | 142 | |
| 143 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
| 143 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
| 144 | 144 | |
| 145 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
| 145 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
| 146 | 146 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
| 147 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
| 148 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
| 147 | + $subscription_data['created'] = current_time('mysql', 0); |
|
| 148 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
| 149 | 149 | |
| 150 | 150 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
| 151 | - $invoice->update_subscription( $subscription_data ); |
|
| 151 | + $invoice->update_subscription($subscription_data); |
|
| 152 | 152 | |
| 153 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
| 154 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
| 153 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
| 154 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
| 155 | 155 | |
| 156 | 156 | return $invoice; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
| 159 | +function wpinv_payment_exists($txn_id = '') { |
|
| 160 | 160 | global $wpdb; |
| 161 | 161 | |
| 162 | - if ( empty( $txn_id ) ) { |
|
| 162 | + if (empty($txn_id)) { |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $txn_id = esc_sql( $txn_id ); |
|
| 166 | + $txn_id = esc_sql($txn_id); |
|
| 167 | 167 | |
| 168 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
| 168 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
| 169 | 169 | |
| 170 | - if ( $invoice != null ) { |
|
| 170 | + if ($invoice != null) { |
|
| 171 | 171 | return true; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
| 178 | - if ( empty( $invoice ) ) { |
|
| 177 | +function wpinv_is_subscription_payment($invoice = '') { |
|
| 178 | + if (empty($invoice)) { |
|
| 179 | 179 | return false; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 183 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 182 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
| 183 | + $invoice = wpinv_get_invoice($invoice); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - if ( empty( $invoice ) ) { |
|
| 186 | + if (empty($invoice)) { |
|
| 187 | 187 | return false; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ( $invoice->is_renewal() ) { |
|
| 190 | + if ($invoice->is_renewal()) { |
|
| 191 | 191 | return true; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return false; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
| 198 | - if ( empty( $invoice ) ) { |
|
| 197 | +function wpinv_payment_subscription_data($invoice = '') { |
|
| 198 | + if (empty($invoice)) { |
|
| 199 | 199 | return false; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 203 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 202 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
| 203 | + $invoice = wpinv_get_invoice($invoice); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if ( empty( $invoice ) ) { |
|
| 206 | + if (empty($invoice)) { |
|
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | return $invoice->get_subscription_data(); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
| 214 | - if ( empty( $invoice ) ) { |
|
| 213 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
| 214 | + if (empty($invoice)) { |
|
| 215 | 215 | return false; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 219 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 218 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
| 219 | + $invoice = wpinv_get_invoice($invoice); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( empty( $invoice ) ) { |
|
| 222 | + if (empty($invoice)) { |
|
| 223 | 223 | return false; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
| 226 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
| 229 | +function wpinv_get_pretty_subscription_period($period) { |
|
| 230 | 230 | $frequency = ''; |
| 231 | 231 | //Format period details |
| 232 | - switch ( $period ) { |
|
| 232 | + switch ($period) { |
|
| 233 | 233 | case 'D' : |
| 234 | 234 | case 'day' : |
| 235 | - $frequency = __( 'Daily', 'invoicing' ); |
|
| 235 | + $frequency = __('Daily', 'invoicing'); |
|
| 236 | 236 | break; |
| 237 | 237 | case 'W' : |
| 238 | 238 | case 'week' : |
| 239 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
| 239 | + $frequency = __('Weekly', 'invoicing'); |
|
| 240 | 240 | break; |
| 241 | 241 | case 'M' : |
| 242 | 242 | case 'month' : |
| 243 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
| 243 | + $frequency = __('Monthly', 'invoicing'); |
|
| 244 | 244 | break; |
| 245 | 245 | case 'Y' : |
| 246 | 246 | case 'year' : |
| 247 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
| 247 | + $frequency = __('Yearly', 'invoicing'); |
|
| 248 | 248 | break; |
| 249 | 249 | default : |
| 250 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
| 250 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
| 251 | 251 | break; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | return $frequency; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
| 257 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
| 258 | 258 | $frequency = ''; |
| 259 | 259 | //Format period details |
| 260 | - switch ( $period ) { |
|
| 260 | + switch ($period) { |
|
| 261 | 261 | case 'D' : |
| 262 | 262 | case 'day' : |
| 263 | - $frequency = __( 'Day', 'invoicing' ); |
|
| 263 | + $frequency = __('Day', 'invoicing'); |
|
| 264 | 264 | break; |
| 265 | 265 | case 'W' : |
| 266 | 266 | case 'week' : |
| 267 | - $frequency = __( 'Week', 'invoicing' ); |
|
| 267 | + $frequency = __('Week', 'invoicing'); |
|
| 268 | 268 | break; |
| 269 | 269 | case 'M' : |
| 270 | 270 | case 'month' : |
| 271 | - $frequency = __( 'Month', 'invoicing' ); |
|
| 271 | + $frequency = __('Month', 'invoicing'); |
|
| 272 | 272 | break; |
| 273 | 273 | case 'Y' : |
| 274 | 274 | case 'year' : |
| 275 | - $frequency = __( 'Year', 'invoicing' ); |
|
| 275 | + $frequency = __('Year', 'invoicing'); |
|
| 276 | 276 | break; |
| 277 | 277 | default : |
| 278 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
| 278 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
| 279 | 279 | break; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | return $frequency; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
| 285 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
| 286 | 286 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
| 287 | 287 | |
| 288 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
| 289 | - $amount = __( 'Free', 'invoicing' ); |
|
| 288 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
| 289 | + $amount = __('Free', 'invoicing'); |
|
| 290 | 290 | $interval = $trial_interval; |
| 291 | 291 | $period = $trial_period; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $description = ''; |
| 295 | - switch ( $period ) { |
|
| 295 | + switch ($period) { |
|
| 296 | 296 | case 'D' : |
| 297 | 297 | case 'day' : |
| 298 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 298 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
| 299 | 299 | break; |
| 300 | 300 | case 'W' : |
| 301 | 301 | case 'week' : |
| 302 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 302 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
| 303 | 303 | break; |
| 304 | 304 | case 'M' : |
| 305 | 305 | case 'month' : |
| 306 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 306 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
| 307 | 307 | break; |
| 308 | 308 | case 'Y' : |
| 309 | 309 | case 'year' : |
| 310 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 310 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
| 311 | 311 | break; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
| 314 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
| 317 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
| 318 | 318 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
| 319 | 319 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
| 320 | 320 | |
| 321 | 321 | $description = ''; |
| 322 | - switch ( $period ) { |
|
| 322 | + switch ($period) { |
|
| 323 | 323 | case 'D' : |
| 324 | 324 | case 'day' : |
| 325 | - if ( (int)$bill_times > 0 ) { |
|
| 326 | - if ( $interval > 1 ) { |
|
| 327 | - if ( $bill_times > 1 ) { |
|
| 328 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 325 | + if ((int)$bill_times > 0) { |
|
| 326 | + if ($interval > 1) { |
|
| 327 | + if ($bill_times > 1) { |
|
| 328 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
| 329 | 329 | } else { |
| 330 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
| 330 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
| 331 | 331 | } |
| 332 | 332 | } else { |
| 333 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 333 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
| 334 | 334 | } |
| 335 | 335 | } else { |
| 336 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
| 336 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
| 337 | 337 | } |
| 338 | 338 | break; |
| 339 | 339 | case 'W' : |
| 340 | 340 | case 'week' : |
| 341 | - if ( (int)$bill_times > 0 ) { |
|
| 342 | - if ( $interval > 1 ) { |
|
| 343 | - if ( $bill_times > 1 ) { |
|
| 344 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 341 | + if ((int)$bill_times > 0) { |
|
| 342 | + if ($interval > 1) { |
|
| 343 | + if ($bill_times > 1) { |
|
| 344 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
| 345 | 345 | } else { |
| 346 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
| 346 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
| 347 | 347 | } |
| 348 | 348 | } else { |
| 349 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 349 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
| 350 | 350 | } |
| 351 | 351 | } else { |
| 352 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 352 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
| 353 | 353 | } |
| 354 | 354 | break; |
| 355 | 355 | case 'M' : |
| 356 | 356 | case 'month' : |
| 357 | - if ( (int)$bill_times > 0 ) { |
|
| 358 | - if ( $interval > 1 ) { |
|
| 359 | - if ( $bill_times > 1 ) { |
|
| 360 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 357 | + if ((int)$bill_times > 0) { |
|
| 358 | + if ($interval > 1) { |
|
| 359 | + if ($bill_times > 1) { |
|
| 360 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
| 361 | 361 | } else { |
| 362 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
| 362 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
| 363 | 363 | } |
| 364 | 364 | } else { |
| 365 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 365 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
| 366 | 366 | } |
| 367 | 367 | } else { |
| 368 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 368 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
| 369 | 369 | } |
| 370 | 370 | break; |
| 371 | 371 | case 'Y' : |
| 372 | 372 | case 'year' : |
| 373 | - if ( (int)$bill_times > 0 ) { |
|
| 374 | - if ( $interval > 1 ) { |
|
| 375 | - if ( $bill_times > 1 ) { |
|
| 376 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 373 | + if ((int)$bill_times > 0) { |
|
| 374 | + if ($interval > 1) { |
|
| 375 | + if ($bill_times > 1) { |
|
| 376 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
| 377 | 377 | } else { |
| 378 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
| 378 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
| 379 | 379 | } |
| 380 | 380 | } else { |
| 381 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 381 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
| 382 | 382 | } |
| 383 | 383 | } else { |
| 384 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 384 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
| 385 | 385 | } |
| 386 | 386 | break; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
| 389 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
| 393 | - if ( empty( $invoice ) ) { |
|
| 392 | +function wpinv_subscription_payment_desc($invoice) { |
|
| 393 | + if (empty($invoice)) { |
|
| 394 | 394 | return NULL; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | $description = ''; |
| 398 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
| 399 | - if ( $item->has_free_trial() ) { |
|
| 398 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
| 399 | + if ($item->has_free_trial()) { |
|
| 400 | 400 | $trial_period = $item->get_trial_period(); |
| 401 | 401 | $trial_interval = $item->get_trial_interval(); |
| 402 | 402 | } else { |
@@ -404,45 +404,45 @@ discard block |
||
| 404 | 404 | $trial_interval = 0; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
| 407 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
| 410 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
| 414 | - $initial_total = wpinv_round_amount( $initial ); |
|
| 415 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
| 413 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
| 414 | + $initial_total = wpinv_round_amount($initial); |
|
| 415 | + $recurring_total = wpinv_round_amount($recurring); |
|
| 416 | 416 | |
| 417 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
| 417 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
| 418 | 418 | // Free trial |
| 419 | 419 | } else { |
| 420 | - if ( $bill_times == 1 ) { |
|
| 420 | + if ($bill_times == 1) { |
|
| 421 | 421 | $recurring_total = $initial_total; |
| 422 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
| 422 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
| 423 | 423 | $bill_times--; |
| 424 | 424 | } |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency ); |
|
| 428 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency ); |
|
| 427 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency); |
|
| 428 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency); |
|
| 429 | 429 | |
| 430 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
| 430 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
| 431 | 431 | |
| 432 | - if ( $initial_total != $recurring_total ) { |
|
| 433 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
| 432 | + if ($initial_total != $recurring_total) { |
|
| 433 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
| 434 | 434 | |
| 435 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
| 435 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
| 436 | 436 | } else { |
| 437 | 437 | $description = $recurring; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
| 440 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
| 444 | - if ( !empty( $invoice->ID ) ) { |
|
| 445 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
| 443 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
| 444 | + if (!empty($invoice->ID)) { |
|
| 445 | + wpinv_failed_invoice_notification($invoice->ID); |
|
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
| 449 | 448 | \ No newline at end of file |
| 449 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
| 450 | 450 | \ No newline at end of file |