@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | class WPInv_Subscriptions { |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * Class constructor. |
|
| 16 | - */ |
|
| 15 | + * Class constructor. |
|
| 16 | + */ |
|
| 17 | 17 | public function __construct(){ |
| 18 | 18 | |
| 19 | 19 | // Fire gateway specific hooks when a subscription changes. |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Processes subscription status changes. |
|
| 92 | + * Processes subscription status changes. |
|
| 93 | 93 | * |
| 94 | 94 | * @param WPInv_Subscription $subscription |
| 95 | 95 | * @param string $from |
| 96 | 96 | * @param string $to |
| 97 | - */ |
|
| 97 | + */ |
|
| 98 | 98 | public function process_subscription_status_change( $subscription, $from, $to ) { |
| 99 | 99 | |
| 100 | 100 | $gateway = $subscription->get_gateway(); |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | /** |
| 9 | 9 | * Main Subscriptions class. |
| 10 | 10 | * |
@@ -14,31 +14,31 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * Class constructor. |
| 16 | 16 | */ |
| 17 | - public function __construct(){ |
|
| 17 | + public function __construct() { |
|
| 18 | 18 | |
| 19 | 19 | // Fire gateway specific hooks when a subscription changes. |
| 20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
| 20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
| 21 | 21 | |
| 22 | 22 | // De-activate a subscription whenever the invoice changes payment statuses. |
| 23 | - add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 24 | - add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 25 | - add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 26 | - add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 23 | + add_action('getpaid_invoice_status_wpi-refunded', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 24 | + add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 25 | + add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 26 | + add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 27 | 27 | |
| 28 | 28 | // Handles subscription cancelations. |
| 29 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
| 29 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
| 30 | 30 | |
| 31 | 31 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
| 32 | - add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ), 5 ); |
|
| 33 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ), 5 ); |
|
| 32 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription'), 5); |
|
| 33 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription'), 5); |
|
| 34 | 34 | |
| 35 | 35 | // Handles admin subscription update actions. |
| 36 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
| 37 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
| 38 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
| 36 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
| 37 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
| 38 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
| 39 | 39 | |
| 40 | 40 | // Filter invoice item row actions. |
| 41 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
| 41 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | * @param WPInv_Invoice $invoice |
| 48 | 48 | * @return WPInv_Subscription|bool |
| 49 | 49 | */ |
| 50 | - public function get_invoice_subscription( $invoice ) { |
|
| 50 | + public function get_invoice_subscription($invoice) { |
|
| 51 | 51 | $subscription_id = $invoice->get_subscription_id(); |
| 52 | 52 | |
| 53 | 53 | // Fallback to the parent invoice if the child invoice has no subscription id. |
| 54 | - if ( empty( $subscription_id ) && $invoice->is_renewal() ) { |
|
| 54 | + if (empty($subscription_id) && $invoice->is_renewal()) { |
|
| 55 | 55 | $subscription_id = $invoice->get_parent_payment()->get_subscription_id(); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Fetch the subscription. |
| 59 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
| 59 | + $subscription = new WPInv_Subscription($subscription_id); |
|
| 60 | 60 | |
| 61 | 61 | // Return subscription or use a fallback for backwards compatibility. |
| 62 | - return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription( $invoice ); |
|
| 62 | + return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription($invoice); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,21 +67,21 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param WPInv_Invoice $invoice |
| 69 | 69 | */ |
| 70 | - public function maybe_deactivate_invoice_subscription( $invoice ) { |
|
| 70 | + public function maybe_deactivate_invoice_subscription($invoice) { |
|
| 71 | 71 | |
| 72 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 72 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 73 | 73 | |
| 74 | - if ( empty( $subscriptions ) ) { |
|
| 74 | + if (empty($subscriptions)) { |
|
| 75 | 75 | return; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ( ! is_array( $subscriptions ) ) { |
|
| 79 | - $subscriptions = array( $subscriptions ); |
|
| 78 | + if (!is_array($subscriptions)) { |
|
| 79 | + $subscriptions = array($subscriptions); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - foreach ( $subscriptions as $subscription ) { |
|
| 83 | - if ( $subscription->is_active() ) { |
|
| 84 | - $subscription->set_status( 'pending' ); |
|
| 82 | + foreach ($subscriptions as $subscription) { |
|
| 83 | + if ($subscription->is_active()) { |
|
| 84 | + $subscription->set_status('pending'); |
|
| 85 | 85 | $subscription->save(); |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | * @param string $from |
| 96 | 96 | * @param string $to |
| 97 | 97 | */ |
| 98 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
| 98 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
| 99 | 99 | |
| 100 | 100 | $gateway = $subscription->get_gateway(); |
| 101 | 101 | |
| 102 | - if ( ! empty( $gateway ) ) { |
|
| 103 | - $gateway = sanitize_key( $gateway ); |
|
| 104 | - $from = sanitize_key( $from ); |
|
| 105 | - $to = sanitize_key( $to ); |
|
| 106 | - do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from ); |
|
| 102 | + if (!empty($gateway)) { |
|
| 103 | + $gateway = sanitize_key($gateway); |
|
| 104 | + $from = sanitize_key($from); |
|
| 105 | + $to = sanitize_key($to); |
|
| 106 | + do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | } |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | * @deprecated |
| 117 | 117 | * @return mixed|string|void |
| 118 | 118 | */ |
| 119 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
| 120 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
| 119 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
| 120 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,33 +127,33 @@ discard block |
||
| 127 | 127 | * @since 1.0.0 |
| 128 | 128 | * @return void |
| 129 | 129 | */ |
| 130 | - public function user_cancel_single_subscription( $data ) { |
|
| 130 | + public function user_cancel_single_subscription($data) { |
|
| 131 | 131 | |
| 132 | 132 | // Ensure there is a subscription to cancel. |
| 133 | - if ( empty( $data['subscription'] ) ) { |
|
| 133 | + if (empty($data['subscription'])) { |
|
| 134 | 134 | return; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
| 137 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
| 138 | 138 | |
| 139 | 139 | // Ensure that it exists and that it belongs to the current user. |
| 140 | - if ( ! $subscription->exists() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
| 141 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
| 140 | + if (!$subscription->exists() || $subscription->get_customer_id() != get_current_user_id()) { |
|
| 141 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
| 142 | 142 | |
| 143 | 143 | // Can it be cancelled. |
| 144 | - } else if ( ! $subscription->can_cancel() ) { |
|
| 145 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
| 144 | + } else if (!$subscription->can_cancel()) { |
|
| 145 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
| 146 | 146 | |
| 147 | 147 | // Cancel it. |
| 148 | 148 | } else { |
| 149 | 149 | |
| 150 | 150 | $subscription->cancel(); |
| 151 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
| 151 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce' ) ); |
|
| 154 | + $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce')); |
|
| 155 | 155 | |
| 156 | - wp_safe_redirect( $redirect ); |
|
| 156 | + wp_safe_redirect($redirect); |
|
| 157 | 157 | exit; |
| 158 | 158 | |
| 159 | 159 | } |
@@ -165,41 +165,41 @@ discard block |
||
| 165 | 165 | * @param WPInv_Invoice $invoice |
| 166 | 166 | * @since 1.0.0 |
| 167 | 167 | */ |
| 168 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
| 168 | + public function maybe_create_invoice_subscription($invoice) { |
|
| 169 | 169 | global $getpaid_subscriptions_skip_invoice_update; |
| 170 | 170 | |
| 171 | 171 | // Abort if it is not recurring. |
| 172 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
| 172 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
| 173 | 173 | return; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | // Either group the subscriptions or only process a single suscription. |
| 177 | - if ( getpaid_should_group_subscriptions( $invoice ) ) { |
|
| 177 | + if (getpaid_should_group_subscriptions($invoice)) { |
|
| 178 | 178 | |
| 179 | 179 | $subscription_groups = array(); |
| 180 | 180 | $is_first = true; |
| 181 | 181 | |
| 182 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
| 183 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, 0, $is_first ); |
|
| 182 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
| 183 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, 0, $is_first); |
|
| 184 | 184 | |
| 185 | - if ( $is_first ) { |
|
| 185 | + if ($is_first) { |
|
| 186 | 186 | $getpaid_subscriptions_skip_invoice_update = true; |
| 187 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
| 187 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
| 188 | 188 | $invoice->save(); |
| 189 | 189 | $getpaid_subscriptions_skip_invoice_update = false; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $is_first = false; |
|
| 192 | + $is_first = false; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Cache subscription groups. |
| 196 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
| 196 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
| 197 | 197 | return true; |
| 198 | 198 | |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | $subscription = new WPInv_Subscription(); |
| 202 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
| 202 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
| 203 | 203 | |
| 204 | 204 | } |
| 205 | 205 | |
@@ -214,47 +214,47 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @since 2.3.0 |
| 216 | 216 | */ |
| 217 | - public function create_invoice_subscription_group( $totals, $invoice, $subscription_id = 0, $is_first = false ) { |
|
| 217 | + public function create_invoice_subscription_group($totals, $invoice, $subscription_id = 0, $is_first = false) { |
|
| 218 | 218 | |
| 219 | - $subscription = new WPInv_Subscription( (int) $subscription_id ); |
|
| 219 | + $subscription = new WPInv_Subscription((int) $subscription_id); |
|
| 220 | 220 | $initial_amt = $totals['initial_total']; |
| 221 | 221 | $recurring_amt = $totals['recurring_total']; |
| 222 | 222 | $fees = array(); |
| 223 | 223 | |
| 224 | 224 | // Maybe add recurring fees. |
| 225 | - if ( $is_first ) { |
|
| 225 | + if ($is_first) { |
|
| 226 | 226 | |
| 227 | - foreach ( $invoice->get_fees() as $i => $fee ) { |
|
| 228 | - if ( ! empty( $fee['recurring_fee'] ) ) { |
|
| 229 | - $initial_amt += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 230 | - $recurring_amt += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 227 | + foreach ($invoice->get_fees() as $i => $fee) { |
|
| 228 | + if (!empty($fee['recurring_fee'])) { |
|
| 229 | + $initial_amt += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 230 | + $recurring_amt += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 231 | 231 | $fees[$i] = $fee; |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
| 238 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
| 239 | - $subscription->set_initial_amount( $initial_amt ); |
|
| 240 | - $subscription->set_recurring_amount( $recurring_amt ); |
|
| 241 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 242 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
| 243 | - $subscription->set_product_id( $totals['item_id'] ); |
|
| 244 | - $subscription->set_period( $totals['period'] ); |
|
| 245 | - $subscription->set_frequency( $totals['interval'] ); |
|
| 246 | - $subscription->set_bill_times( $totals['recurring_limit'] ); |
|
| 247 | - $subscription->set_next_renewal_date( $totals['renews_on'] ); |
|
| 237 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
| 238 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
| 239 | + $subscription->set_initial_amount($initial_amt); |
|
| 240 | + $subscription->set_recurring_amount($recurring_amt); |
|
| 241 | + $subscription->set_date_created(current_time('mysql')); |
|
| 242 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
| 243 | + $subscription->set_product_id($totals['item_id']); |
|
| 244 | + $subscription->set_period($totals['period']); |
|
| 245 | + $subscription->set_frequency($totals['interval']); |
|
| 246 | + $subscription->set_bill_times($totals['recurring_limit']); |
|
| 247 | + $subscription->set_next_renewal_date($totals['renews_on']); |
|
| 248 | 248 | |
| 249 | 249 | // Trial periods. |
| 250 | - if ( ! empty( $totals['trialling'] ) ) { |
|
| 251 | - $subscription->set_trial_period( $totals['trialling'] ); |
|
| 252 | - $subscription->set_status( 'trialling' ); |
|
| 250 | + if (!empty($totals['trialling'])) { |
|
| 251 | + $subscription->set_trial_period($totals['trialling']); |
|
| 252 | + $subscription->set_status('trialling'); |
|
| 253 | 253 | |
| 254 | 254 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
| 255 | - } else if ( empty( $initial_amt ) ) { |
|
| 256 | - $subscription->set_trial_period( $totals['interval'] . ' ' . $totals['period'] ); |
|
| 257 | - $subscription->set_status( 'trialling' ); |
|
| 255 | + } else if (empty($initial_amt)) { |
|
| 256 | + $subscription->set_trial_period($totals['interval'] . ' ' . $totals['period']); |
|
| 257 | + $subscription->set_status('trialling'); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $subscription->save(); |
@@ -272,87 +272,87 @@ discard block |
||
| 272 | 272 | * @param WPInv_Invoice $invoice |
| 273 | 273 | * @since 1.0.19 |
| 274 | 274 | */ |
| 275 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
| 275 | + public function maybe_update_invoice_subscription($invoice) { |
|
| 276 | 276 | global $getpaid_subscriptions_skip_invoice_update; |
| 277 | 277 | |
| 278 | 278 | // Avoid infinite loops. |
| 279 | - if ( ! empty( $getpaid_subscriptions_skip_invoice_update ) ) { |
|
| 279 | + if (!empty($getpaid_subscriptions_skip_invoice_update)) { |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Do not process renewals. |
| 284 | - if ( $invoice->is_renewal() ) { |
|
| 284 | + if ($invoice->is_renewal()) { |
|
| 285 | 285 | return; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Delete existing subscriptions if available and the invoice is not recurring. |
| 289 | - if ( ! $invoice->is_recurring() ) { |
|
| 290 | - $this->delete_invoice_subscriptions( $invoice ); |
|
| 289 | + if (!$invoice->is_recurring()) { |
|
| 290 | + $this->delete_invoice_subscriptions($invoice); |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | // Fetch existing subscriptions. |
| 295 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 295 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 296 | 296 | |
| 297 | 297 | // Create new ones if no existing subscriptions. |
| 298 | - if ( empty( $subscriptions ) ) { |
|
| 299 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
| 298 | + if (empty($subscriptions)) { |
|
| 299 | + return $this->maybe_create_invoice_subscription($invoice); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // Abort if an invoice is paid and already has a subscription. |
| 303 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 303 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 304 | 304 | return; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - $is_grouped = is_array( $subscriptions ); |
|
| 308 | - $should_group = getpaid_should_group_subscriptions( $invoice ); |
|
| 307 | + $is_grouped = is_array($subscriptions); |
|
| 308 | + $should_group = getpaid_should_group_subscriptions($invoice); |
|
| 309 | 309 | |
| 310 | 310 | // Ensure that the subscriptions are only grouped if there are more than 1 recurring items. |
| 311 | - if ( $is_grouped != $should_group ) { |
|
| 312 | - $this->delete_invoice_subscriptions( $invoice ); |
|
| 313 | - delete_post_meta( $invoice->get_id(), 'getpaid_subscription_groups' ); |
|
| 314 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
| 311 | + if ($is_grouped != $should_group) { |
|
| 312 | + $this->delete_invoice_subscriptions($invoice); |
|
| 313 | + delete_post_meta($invoice->get_id(), 'getpaid_subscription_groups'); |
|
| 314 | + return $this->maybe_create_invoice_subscription($invoice); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // If there is only one recurring item... |
| 318 | - if ( ! $is_grouped ) { |
|
| 319 | - return $this->update_invoice_subscription( $subscriptions, $invoice ); |
|
| 318 | + if (!$is_grouped) { |
|
| 319 | + return $this->update_invoice_subscription($subscriptions, $invoice); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Process subscription groups. |
| 323 | - $current_groups = getpaid_get_invoice_subscription_groups( $invoice->get_id() ); |
|
| 323 | + $current_groups = getpaid_get_invoice_subscription_groups($invoice->get_id()); |
|
| 324 | 324 | $subscription_groups = array(); |
| 325 | 325 | $is_first = true; |
| 326 | 326 | |
| 327 | 327 | // Create new subscription groups. |
| 328 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
| 329 | - $subscription_id = isset( $current_groups[ $group_key ] ) ? $current_groups[ $group_key ]['subscription_id'] : 0; |
|
| 330 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, $subscription_id, $is_first ); |
|
| 328 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
| 329 | + $subscription_id = isset($current_groups[$group_key]) ? $current_groups[$group_key]['subscription_id'] : 0; |
|
| 330 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, $subscription_id, $is_first); |
|
| 331 | 331 | |
| 332 | - if ( $is_first && $invoice->get_subscription_id() !== $subscription_groups[ $group_key ]['subscription_id'] ) { |
|
| 332 | + if ($is_first && $invoice->get_subscription_id() !== $subscription_groups[$group_key]['subscription_id']) { |
|
| 333 | 333 | $getpaid_subscriptions_skip_invoice_update = true; |
| 334 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
| 334 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
| 335 | 335 | $invoice->save(); |
| 336 | 336 | $getpaid_subscriptions_skip_invoice_update = false; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - $is_first = false; |
|
| 339 | + $is_first = false; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | // Delete non-existent subscription groups. |
| 343 | - foreach ( $current_groups as $group_key => $data ) { |
|
| 344 | - if ( ! isset( $subscription_groups[ $group_key ] ) ) { |
|
| 345 | - $subscription = new WPInv_Subscription( (int) $data['subscription_id'] ); |
|
| 343 | + foreach ($current_groups as $group_key => $data) { |
|
| 344 | + if (!isset($subscription_groups[$group_key])) { |
|
| 345 | + $subscription = new WPInv_Subscription((int) $data['subscription_id']); |
|
| 346 | 346 | |
| 347 | - if ( $subscription->exists() ) { |
|
| 348 | - $subscription->delete( true ); |
|
| 347 | + if ($subscription->exists()) { |
|
| 348 | + $subscription->delete(true); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | // Cache subscription groups. |
| 355 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
| 355 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
| 356 | 356 | return true; |
| 357 | 357 | |
| 358 | 358 | } |
@@ -362,20 +362,20 @@ discard block |
||
| 362 | 362 | * |
| 363 | 363 | * @param WPInv_Invoice $invoice |
| 364 | 364 | */ |
| 365 | - public function delete_invoice_subscriptions( $invoice ) { |
|
| 365 | + public function delete_invoice_subscriptions($invoice) { |
|
| 366 | 366 | |
| 367 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 367 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 368 | 368 | |
| 369 | - if ( empty( $subscriptions ) ) { |
|
| 369 | + if (empty($subscriptions)) { |
|
| 370 | 370 | return; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if ( ! is_array( $subscriptions ) ) { |
|
| 374 | - $subscriptions = array( $subscriptions ); |
|
| 373 | + if (!is_array($subscriptions)) { |
|
| 374 | + $subscriptions = array($subscriptions); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - foreach ( $subscriptions as $subscription ) { |
|
| 378 | - $subscription->delete( true ); |
|
| 377 | + foreach ($subscriptions as $subscription) { |
|
| 378 | + $subscription->delete(true); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | } |
@@ -388,57 +388,57 @@ discard block |
||
| 388 | 388 | * @param WPInv_Invoice $invoice |
| 389 | 389 | * @since 1.0.19 |
| 390 | 390 | */ |
| 391 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
| 391 | + public function update_invoice_subscription($subscription, $invoice) { |
|
| 392 | 392 | |
| 393 | 393 | // Delete the subscription if an invoice is free or nolonger recurring. |
| 394 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
| 394 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) { |
|
| 395 | 395 | return $subscription->delete(); |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
| 399 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
| 400 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
| 401 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
| 402 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 403 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
| 398 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
| 399 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
| 400 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
| 401 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
| 402 | + $subscription->set_date_created(current_time('mysql')); |
|
| 403 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
| 404 | 404 | |
| 405 | 405 | // Get the recurring item and abort if it does not exist. |
| 406 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 407 | - if ( ! $subscription_item->get_id() ) { |
|
| 406 | + $subscription_item = $invoice->get_recurring(true); |
|
| 407 | + if (!$subscription_item->get_id()) { |
|
| 408 | 408 | $invoice->set_subscription_id(0); |
| 409 | 409 | $invoice->save(); |
| 410 | 410 | return $subscription->delete(); |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
| 414 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
| 415 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
| 416 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
| 413 | + $subscription->set_product_id($subscription_item->get_id()); |
|
| 414 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
| 415 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
| 416 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
| 417 | 417 | |
| 418 | 418 | // Calculate the next renewal date. |
| 419 | - $period = $subscription_item->get_recurring_period( true ); |
|
| 419 | + $period = $subscription_item->get_recurring_period(true); |
|
| 420 | 420 | $interval = $subscription_item->get_recurring_interval(); |
| 421 | 421 | |
| 422 | 422 | // If the subscription item has a trial period... |
| 423 | - if ( $subscription_item->has_free_trial() ) { |
|
| 424 | - $period = $subscription_item->get_trial_period( true ); |
|
| 423 | + if ($subscription_item->has_free_trial()) { |
|
| 424 | + $period = $subscription_item->get_trial_period(true); |
|
| 425 | 425 | $interval = $subscription_item->get_trial_interval(); |
| 426 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
| 427 | - $subscription->set_status( 'trialling' ); |
|
| 426 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
| 427 | + $subscription->set_status('trialling'); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
| 431 | - if ( $invoice->has_free_trial() ) { |
|
| 432 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
| 433 | - $subscription->set_status( 'trialling' ); |
|
| 431 | + if ($invoice->has_free_trial()) { |
|
| 432 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
| 433 | + $subscription->set_status('trialling'); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // Calculate the next renewal date. |
| 437 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
| 437 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
| 438 | 438 | |
| 439 | - $subscription->set_next_renewal_date( $expiration ); |
|
| 439 | + $subscription->set_next_renewal_date($expiration); |
|
| 440 | 440 | $subscription->save(); |
| 441 | - $invoice->set_subscription_id( $subscription->get_id() ); |
|
| 441 | + $invoice->set_subscription_id($subscription->get_id()); |
|
| 442 | 442 | return $subscription->get_id(); |
| 443 | 443 | |
| 444 | 444 | } |
@@ -449,27 +449,27 @@ discard block |
||
| 449 | 449 | * @param array $data |
| 450 | 450 | * @since 1.0.19 |
| 451 | 451 | */ |
| 452 | - public function admin_update_single_subscription( $args ) { |
|
| 452 | + public function admin_update_single_subscription($args) { |
|
| 453 | 453 | |
| 454 | 454 | // Ensure the subscription exists and that a status has been given. |
| 455 | - if ( empty( $args['subscription_id'] ) ) { |
|
| 455 | + if (empty($args['subscription_id'])) { |
|
| 456 | 456 | return; |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // Retrieve the subscriptions. |
| 460 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
| 460 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
| 461 | 461 | |
| 462 | - if ( $subscription->get_id() ) { |
|
| 462 | + if ($subscription->get_id()) { |
|
| 463 | 463 | |
| 464 | 464 | $subscription->set_props( |
| 465 | 465 | array( |
| 466 | - 'status' => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null, |
|
| 467 | - 'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null, |
|
| 466 | + 'status' => isset($args['subscription_status']) ? $args['subscription_status'] : null, |
|
| 467 | + 'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null, |
|
| 468 | 468 | ) |
| 469 | 469 | ); |
| 470 | 470 | |
| 471 | 471 | $subscription->save(); |
| 472 | - getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) ); |
|
| 472 | + getpaid_admin()->show_info(__('Subscription updated', 'invoicing')); |
|
| 473 | 473 | |
| 474 | 474 | } |
| 475 | 475 | |
@@ -481,27 +481,27 @@ discard block |
||
| 481 | 481 | * @param array $data |
| 482 | 482 | * @since 1.0.19 |
| 483 | 483 | */ |
| 484 | - public function admin_renew_single_subscription( $args ) { |
|
| 484 | + public function admin_renew_single_subscription($args) { |
|
| 485 | 485 | |
| 486 | 486 | // Ensure the subscription exists and that a status has been given. |
| 487 | - if ( empty( $args['id'] ) ) { |
|
| 487 | + if (empty($args['id'])) { |
|
| 488 | 488 | return; |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | // Retrieve the subscriptions. |
| 492 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
| 492 | + $subscription = new WPInv_Subscription($args['id']); |
|
| 493 | 493 | |
| 494 | - if ( $subscription->get_id() ) { |
|
| 494 | + if ($subscription->get_id()) { |
|
| 495 | 495 | |
| 496 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
| 496 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
| 497 | 497 | |
| 498 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
| 498 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
| 499 | 499 | |
| 500 | - if ( ! $subscription->add_payment( $args ) ) { |
|
| 501 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
| 500 | + if (!$subscription->add_payment($args)) { |
|
| 501 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
| 502 | 502 | } else { |
| 503 | 503 | $subscription->renew(); |
| 504 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
| 504 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | wp_safe_redirect( |
@@ -524,20 +524,20 @@ discard block |
||
| 524 | 524 | * @param array $data |
| 525 | 525 | * @since 1.0.19 |
| 526 | 526 | */ |
| 527 | - public function admin_delete_single_subscription( $args ) { |
|
| 527 | + public function admin_delete_single_subscription($args) { |
|
| 528 | 528 | |
| 529 | 529 | // Ensure the subscription exists and that a status has been given. |
| 530 | - if ( empty( $args['id'] ) ) { |
|
| 530 | + if (empty($args['id'])) { |
|
| 531 | 531 | return; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | // Retrieve the subscriptions. |
| 535 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
| 535 | + $subscription = new WPInv_Subscription($args['id']); |
|
| 536 | 536 | |
| 537 | - if ( $subscription->delete() ) { |
|
| 538 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
| 537 | + if ($subscription->delete()) { |
|
| 538 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
| 539 | 539 | } else { |
| 540 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
| 540 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | $redirected = wp_safe_redirect( |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | ) |
| 551 | 551 | ); |
| 552 | 552 | |
| 553 | - if ( $redirected ) { |
|
| 553 | + if ($redirected) { |
|
| 554 | 554 | exit; |
| 555 | 555 | } |
| 556 | 556 | |
@@ -563,16 +563,16 @@ discard block |
||
| 563 | 563 | * @param WPInv_Item $item |
| 564 | 564 | * @param WPInv_Invoice $invoice |
| 565 | 565 | */ |
| 566 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
| 566 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
| 567 | 567 | |
| 568 | 568 | // Abort if this invoice uses subscription groups. |
| 569 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 570 | - if ( ! $invoice->is_recurring() || ! is_object( $subscriptions ) ) { |
|
| 569 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 570 | + if (!$invoice->is_recurring() || !is_object($subscriptions)) { |
|
| 571 | 571 | return $actions; |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | // Fetch item subscription. |
| 575 | - $args = array( |
|
| 575 | + $args = array( |
|
| 576 | 576 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
| 577 | 577 | 'product_in' => $item->get_id(), |
| 578 | 578 | 'number' => 1, |
@@ -580,13 +580,13 @@ discard block |
||
| 580 | 580 | 'fields' => 'id', |
| 581 | 581 | ); |
| 582 | 582 | |
| 583 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
| 583 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
| 584 | 584 | $subscription = $subscription->get_results(); |
| 585 | 585 | |
| 586 | 586 | // In case we found a match... |
| 587 | - if ( ! empty( $subscription ) ) { |
|
| 588 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
| 589 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 587 | + if (!empty($subscription)) { |
|
| 588 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
| 589 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | return $actions; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,198 +10,198 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Sets the associated payment form. |
|
| 57 | - * |
|
| 58 | - * @var GetPaid_Payment_Form |
|
| 59 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Sets the associated payment form. |
|
| 57 | + * |
|
| 58 | + * @var GetPaid_Payment_Form |
|
| 59 | + */ |
|
| 60 | 60 | protected $payment_form = null; |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * The country for the submission. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - public $country = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The state for the submission. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.19 |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $state = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The invoice associated with the submission. |
|
| 79 | - * |
|
| 80 | - * @var WPInv_Invoice |
|
| 81 | - */ |
|
| 82 | - protected $invoice = null; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The recurring item for the submission. |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - public $has_recurring = 0; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * An array of fees for the submission. |
|
| 93 | - * |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $fees = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * An array of discounts for the submission. |
|
| 100 | - * |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - protected $discounts = array(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of taxes for the submission. |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $taxes = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * An array of items for the submission. |
|
| 114 | - * |
|
| 115 | - * @var GetPaid_Form_Item[] |
|
| 116 | - */ |
|
| 117 | - protected $items = array(); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The last error. |
|
| 121 | - * |
|
| 122 | - * @var string |
|
| 123 | - */ |
|
| 124 | - public $last_error = null; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * The last error code. |
|
| 128 | - * |
|
| 129 | - * @var string |
|
| 130 | - */ |
|
| 131 | - public $last_error_code = null; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Class constructor. |
|
| 135 | - * |
|
| 136 | - */ |
|
| 137 | - public function __construct() { |
|
| 138 | - |
|
| 139 | - // Set the state and country to the default state and country. |
|
| 140 | - $this->country = wpinv_default_billing_country(); |
|
| 141 | - $this->state = wpinv_get_default_state(); |
|
| 142 | - |
|
| 143 | - // Do we have an actual submission? |
|
| 144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 145 | - $this->load_data( $_POST ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Loads submission data. |
|
| 152 | - * |
|
| 153 | - * @param array $data |
|
| 154 | - */ |
|
| 155 | - public function load_data( $data ) { |
|
| 156 | - |
|
| 157 | - // Remove slashes from the submitted data... |
|
| 158 | - $data = wp_unslash( $data ); |
|
| 159 | - |
|
| 160 | - // Allow plugins to filter the data. |
|
| 161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 162 | - |
|
| 163 | - // Cache it... |
|
| 164 | - $this->data = $data; |
|
| 165 | - |
|
| 166 | - // Then generate a unique id from the data. |
|
| 167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 168 | - |
|
| 169 | - // Finally, process the submission. |
|
| 170 | - try { |
|
| 171 | - |
|
| 172 | - // Each process is passed an instance of the class (with reference) |
|
| 173 | - // and should throw an Exception whenever it encounters one. |
|
| 174 | - $processors = apply_filters( |
|
| 175 | - 'getpaid_payment_form_submission_processors', |
|
| 176 | - array( |
|
| 177 | - array( $this, 'process_payment_form' ), |
|
| 178 | - array( $this, 'process_invoice' ), |
|
| 179 | - array( $this, 'process_fees' ), |
|
| 180 | - array( $this, 'process_items' ), |
|
| 181 | - array( $this, 'process_discount' ), |
|
| 182 | - array( $this, 'process_taxes' ), |
|
| 183 | - ), |
|
| 184 | - $this |
|
| 185 | - ); |
|
| 186 | - |
|
| 187 | - foreach ( $processors as $processor ) { |
|
| 188 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
| 192 | - $this->last_error = $e->getMessage(); |
|
| 193 | - $this->last_error_code = $e->getErrorCode(); |
|
| 194 | - } catch ( Exception $e ) { |
|
| 195 | - $this->last_error = $e->getMessage(); |
|
| 196 | - $this->last_error_code = $e->getCode(); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // Fired when we are done processing a submission. |
|
| 200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 201 | - |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /* |
|
| 63 | + * The country for the submission. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + public $country = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The state for the submission. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.19 |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $state = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The invoice associated with the submission. |
|
| 79 | + * |
|
| 80 | + * @var WPInv_Invoice |
|
| 81 | + */ |
|
| 82 | + protected $invoice = null; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The recurring item for the submission. |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + public $has_recurring = 0; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * An array of fees for the submission. |
|
| 93 | + * |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $fees = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * An array of discounts for the submission. |
|
| 100 | + * |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + protected $discounts = array(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of taxes for the submission. |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $taxes = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * An array of items for the submission. |
|
| 114 | + * |
|
| 115 | + * @var GetPaid_Form_Item[] |
|
| 116 | + */ |
|
| 117 | + protected $items = array(); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The last error. |
|
| 121 | + * |
|
| 122 | + * @var string |
|
| 123 | + */ |
|
| 124 | + public $last_error = null; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * The last error code. |
|
| 128 | + * |
|
| 129 | + * @var string |
|
| 130 | + */ |
|
| 131 | + public $last_error_code = null; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Class constructor. |
|
| 135 | + * |
|
| 136 | + */ |
|
| 137 | + public function __construct() { |
|
| 138 | + |
|
| 139 | + // Set the state and country to the default state and country. |
|
| 140 | + $this->country = wpinv_default_billing_country(); |
|
| 141 | + $this->state = wpinv_get_default_state(); |
|
| 142 | + |
|
| 143 | + // Do we have an actual submission? |
|
| 144 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 145 | + $this->load_data( $_POST ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Loads submission data. |
|
| 152 | + * |
|
| 153 | + * @param array $data |
|
| 154 | + */ |
|
| 155 | + public function load_data( $data ) { |
|
| 156 | + |
|
| 157 | + // Remove slashes from the submitted data... |
|
| 158 | + $data = wp_unslash( $data ); |
|
| 159 | + |
|
| 160 | + // Allow plugins to filter the data. |
|
| 161 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 162 | + |
|
| 163 | + // Cache it... |
|
| 164 | + $this->data = $data; |
|
| 165 | + |
|
| 166 | + // Then generate a unique id from the data. |
|
| 167 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 168 | + |
|
| 169 | + // Finally, process the submission. |
|
| 170 | + try { |
|
| 171 | + |
|
| 172 | + // Each process is passed an instance of the class (with reference) |
|
| 173 | + // and should throw an Exception whenever it encounters one. |
|
| 174 | + $processors = apply_filters( |
|
| 175 | + 'getpaid_payment_form_submission_processors', |
|
| 176 | + array( |
|
| 177 | + array( $this, 'process_payment_form' ), |
|
| 178 | + array( $this, 'process_invoice' ), |
|
| 179 | + array( $this, 'process_fees' ), |
|
| 180 | + array( $this, 'process_items' ), |
|
| 181 | + array( $this, 'process_discount' ), |
|
| 182 | + array( $this, 'process_taxes' ), |
|
| 183 | + ), |
|
| 184 | + $this |
|
| 185 | + ); |
|
| 186 | + |
|
| 187 | + foreach ( $processors as $processor ) { |
|
| 188 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + } catch( GetPaid_Payment_Exception $e ) { |
|
| 192 | + $this->last_error = $e->getMessage(); |
|
| 193 | + $this->last_error_code = $e->getErrorCode(); |
|
| 194 | + } catch ( Exception $e ) { |
|
| 195 | + $this->last_error = $e->getMessage(); |
|
| 196 | + $this->last_error_code = $e->getCode(); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // Fired when we are done processing a submission. |
|
| 200 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 201 | + |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /* |
|
| 205 | 205 | |-------------------------------------------------------------------------- |
| 206 | 206 | | Payment Forms. |
| 207 | 207 | |-------------------------------------------------------------------------- |
@@ -210,39 +210,39 @@ discard block |
||
| 210 | 210 | | submission has an active payment form etc. |
| 211 | 211 | */ |
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Prepares the submission's payment form. |
|
| 215 | - * |
|
| 216 | - * @since 1.0.19 |
|
| 217 | - */ |
|
| 218 | - public function process_payment_form() { |
|
| 213 | + /** |
|
| 214 | + * Prepares the submission's payment form. |
|
| 215 | + * |
|
| 216 | + * @since 1.0.19 |
|
| 217 | + */ |
|
| 218 | + public function process_payment_form() { |
|
| 219 | 219 | |
| 220 | - // Every submission needs an active payment form. |
|
| 221 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 223 | - } |
|
| 220 | + // Every submission needs an active payment form. |
|
| 221 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 222 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // Fetch the payment form. |
|
| 226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 225 | + // Fetch the payment form. |
|
| 226 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 227 | 227 | |
| 228 | - if ( ! $this->payment_form->is_active() ) { |
|
| 229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 230 | - } |
|
| 228 | + if ( ! $this->payment_form->is_active() ) { |
|
| 229 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 233 | - } |
|
| 232 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | /** |
| 236 | - * Returns the payment form. |
|
| 237 | - * |
|
| 238 | - * @since 1.0.19 |
|
| 239 | - * @return GetPaid_Payment_Form |
|
| 240 | - */ |
|
| 241 | - public function get_payment_form() { |
|
| 242 | - return $this->payment_form; |
|
| 243 | - } |
|
| 236 | + * Returns the payment form. |
|
| 237 | + * |
|
| 238 | + * @since 1.0.19 |
|
| 239 | + * @return GetPaid_Payment_Form |
|
| 240 | + */ |
|
| 241 | + public function get_payment_form() { |
|
| 242 | + return $this->payment_form; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /* |
|
| 245 | + /* |
|
| 246 | 246 | |-------------------------------------------------------------------------- |
| 247 | 247 | | Invoices. |
| 248 | 248 | |-------------------------------------------------------------------------- |
@@ -251,84 +251,84 @@ discard block |
||
| 251 | 251 | | might be for an existing invoice. |
| 252 | 252 | */ |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Prepares the submission's invoice. |
|
| 256 | - * |
|
| 257 | - * @since 1.0.19 |
|
| 258 | - */ |
|
| 259 | - public function process_invoice() { |
|
| 254 | + /** |
|
| 255 | + * Prepares the submission's invoice. |
|
| 256 | + * |
|
| 257 | + * @since 1.0.19 |
|
| 258 | + */ |
|
| 259 | + public function process_invoice() { |
|
| 260 | 260 | |
| 261 | - // Abort if there is no invoice. |
|
| 262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 261 | + // Abort if there is no invoice. |
|
| 262 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 267 | - // and that it is not paid for. |
|
| 268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 266 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 267 | + // and that it is not paid for. |
|
| 268 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 269 | 269 | |
| 270 | 270 | if ( empty( $invoice ) ) { |
| 271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 272 | - } |
|
| 271 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - if ( $invoice->is_paid() ) { |
|
| 275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 276 | - } |
|
| 274 | + if ( $invoice->is_paid() ) { |
|
| 275 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - $this->payment_form->invoice = $invoice; |
|
| 279 | - if ( ! $this->payment_form->is_default() ) { |
|
| 278 | + $this->payment_form->invoice = $invoice; |
|
| 279 | + if ( ! $this->payment_form->is_default() ) { |
|
| 280 | 280 | |
| 281 | - $items = array(); |
|
| 282 | - $item_ids = array(); |
|
| 281 | + $items = array(); |
|
| 282 | + $item_ids = array(); |
|
| 283 | 283 | |
| 284 | - foreach ( $invoice->get_items() as $item ) { |
|
| 285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 286 | - $item_ids[] = $item->get_id(); |
|
| 287 | - $items[] = $item; |
|
| 288 | - } |
|
| 289 | - } |
|
| 284 | + foreach ( $invoice->get_items() as $item ) { |
|
| 285 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 286 | + $item_ids[] = $item->get_id(); |
|
| 287 | + $items[] = $item; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 293 | - $item_ids[] = $item->get_id(); |
|
| 294 | - $items[] = $item; |
|
| 295 | - } |
|
| 296 | - } |
|
| 291 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
| 292 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 293 | + $item_ids[] = $item->get_id(); |
|
| 294 | + $items[] = $item; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - $this->payment_form->set_items( $items ); |
|
| 298 | + $this->payment_form->set_items( $items ); |
|
| 299 | 299 | |
| 300 | - } else { |
|
| 301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $this->country = $invoice->get_country(); |
|
| 305 | - $this->state = $invoice->get_state(); |
|
| 306 | - $this->invoice = $invoice; |
|
| 307 | - |
|
| 308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Returns the associated invoice. |
|
| 313 | - * |
|
| 314 | - * @since 1.0.19 |
|
| 315 | - * @return WPInv_Invoice |
|
| 316 | - */ |
|
| 317 | - public function get_invoice() { |
|
| 318 | - return $this->invoice; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Checks whether there is an invoice associated with this submission. |
|
| 323 | - * |
|
| 324 | - * @since 1.0.19 |
|
| 325 | - * @return bool |
|
| 326 | - */ |
|
| 327 | - public function has_invoice() { |
|
| 328 | - return ! empty( $this->invoice ); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /* |
|
| 300 | + } else { |
|
| 301 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $this->country = $invoice->get_country(); |
|
| 305 | + $this->state = $invoice->get_state(); |
|
| 306 | + $this->invoice = $invoice; |
|
| 307 | + |
|
| 308 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Returns the associated invoice. |
|
| 313 | + * |
|
| 314 | + * @since 1.0.19 |
|
| 315 | + * @return WPInv_Invoice |
|
| 316 | + */ |
|
| 317 | + public function get_invoice() { |
|
| 318 | + return $this->invoice; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Checks whether there is an invoice associated with this submission. |
|
| 323 | + * |
|
| 324 | + * @since 1.0.19 |
|
| 325 | + * @return bool |
|
| 326 | + */ |
|
| 327 | + public function has_invoice() { |
|
| 328 | + return ! empty( $this->invoice ); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /* |
|
| 332 | 332 | |-------------------------------------------------------------------------- |
| 333 | 333 | | Items. |
| 334 | 334 | |-------------------------------------------------------------------------- |
@@ -337,129 +337,129 @@ discard block |
||
| 337 | 337 | | recurring item. But can have an unlimited number of non-recurring items. |
| 338 | 338 | */ |
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * Prepares the submission's items. |
|
| 342 | - * |
|
| 343 | - * @since 1.0.19 |
|
| 344 | - */ |
|
| 345 | - public function process_items() { |
|
| 346 | - |
|
| 347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 348 | - |
|
| 349 | - foreach ( $processor->items as $item ) { |
|
| 350 | - $this->add_item( $item ); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Adds an item to the submission. |
|
| 358 | - * |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - * @param GetPaid_Form_Item $item |
|
| 361 | - */ |
|
| 362 | - public function add_item( $item ) { |
|
| 363 | - |
|
| 364 | - // Make sure that it is available for purchase. |
|
| 365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 366 | - return; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - // Each submission can only contain one recurring item. |
|
| 370 | - if ( $item->is_recurring() ) { |
|
| 371 | - $this->has_recurring = $item->get_id(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // Update the items and totals. |
|
| 375 | - $this->items[ $item->get_id() ] = $item; |
|
| 376 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 377 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 378 | - |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Removes a specific item. |
|
| 383 | - * |
|
| 384 | - * You should not call this method after the discounts and taxes |
|
| 385 | - * have been calculated. |
|
| 386 | - * |
|
| 387 | - * @since 1.0.19 |
|
| 388 | - */ |
|
| 389 | - public function remove_item( $item_id ) { |
|
| 390 | - |
|
| 391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 394 | - |
|
| 395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 396 | - $this->has_recurring = 0; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - unset( $this->items[ $item_id ] ); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Returns the subtotal. |
|
| 406 | - * |
|
| 407 | - * @since 1.0.19 |
|
| 408 | - */ |
|
| 409 | - public function get_subtotal() { |
|
| 410 | - |
|
| 411 | - if ( wpinv_prices_include_tax() ) { |
|
| 412 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - return $this->totals['subtotal']['initial']; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Returns the recurring subtotal. |
|
| 420 | - * |
|
| 421 | - * @since 1.0.19 |
|
| 422 | - */ |
|
| 423 | - public function get_recurring_subtotal() { |
|
| 424 | - |
|
| 425 | - if ( wpinv_prices_include_tax() ) { |
|
| 426 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return $this->totals['subtotal']['recurring']; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Returns all items. |
|
| 434 | - * |
|
| 435 | - * @since 1.0.19 |
|
| 436 | - * @return GetPaid_Form_Item[] |
|
| 437 | - */ |
|
| 438 | - public function get_items() { |
|
| 439 | - return $this->items; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Checks if there's a single subscription group in the submission. |
|
| 444 | - * |
|
| 445 | - * @since 2.3.0 |
|
| 446 | - * @return bool |
|
| 447 | - */ |
|
| 448 | - public function has_subscription_group() { |
|
| 449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Checks if there are multipe subscription groups in the submission. |
|
| 454 | - * |
|
| 455 | - * @since 2.3.0 |
|
| 456 | - * @return bool |
|
| 457 | - */ |
|
| 458 | - public function has_multiple_subscription_groups() { |
|
| 459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /* |
|
| 340 | + /** |
|
| 341 | + * Prepares the submission's items. |
|
| 342 | + * |
|
| 343 | + * @since 1.0.19 |
|
| 344 | + */ |
|
| 345 | + public function process_items() { |
|
| 346 | + |
|
| 347 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 348 | + |
|
| 349 | + foreach ( $processor->items as $item ) { |
|
| 350 | + $this->add_item( $item ); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Adds an item to the submission. |
|
| 358 | + * |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + * @param GetPaid_Form_Item $item |
|
| 361 | + */ |
|
| 362 | + public function add_item( $item ) { |
|
| 363 | + |
|
| 364 | + // Make sure that it is available for purchase. |
|
| 365 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 366 | + return; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + // Each submission can only contain one recurring item. |
|
| 370 | + if ( $item->is_recurring() ) { |
|
| 371 | + $this->has_recurring = $item->get_id(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // Update the items and totals. |
|
| 375 | + $this->items[ $item->get_id() ] = $item; |
|
| 376 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 377 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 378 | + |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Removes a specific item. |
|
| 383 | + * |
|
| 384 | + * You should not call this method after the discounts and taxes |
|
| 385 | + * have been calculated. |
|
| 386 | + * |
|
| 387 | + * @since 1.0.19 |
|
| 388 | + */ |
|
| 389 | + public function remove_item( $item_id ) { |
|
| 390 | + |
|
| 391 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 392 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 393 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 394 | + |
|
| 395 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 396 | + $this->has_recurring = 0; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + unset( $this->items[ $item_id ] ); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Returns the subtotal. |
|
| 406 | + * |
|
| 407 | + * @since 1.0.19 |
|
| 408 | + */ |
|
| 409 | + public function get_subtotal() { |
|
| 410 | + |
|
| 411 | + if ( wpinv_prices_include_tax() ) { |
|
| 412 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + return $this->totals['subtotal']['initial']; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Returns the recurring subtotal. |
|
| 420 | + * |
|
| 421 | + * @since 1.0.19 |
|
| 422 | + */ |
|
| 423 | + public function get_recurring_subtotal() { |
|
| 424 | + |
|
| 425 | + if ( wpinv_prices_include_tax() ) { |
|
| 426 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return $this->totals['subtotal']['recurring']; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Returns all items. |
|
| 434 | + * |
|
| 435 | + * @since 1.0.19 |
|
| 436 | + * @return GetPaid_Form_Item[] |
|
| 437 | + */ |
|
| 438 | + public function get_items() { |
|
| 439 | + return $this->items; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Checks if there's a single subscription group in the submission. |
|
| 444 | + * |
|
| 445 | + * @since 2.3.0 |
|
| 446 | + * @return bool |
|
| 447 | + */ |
|
| 448 | + public function has_subscription_group() { |
|
| 449 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Checks if there are multipe subscription groups in the submission. |
|
| 454 | + * |
|
| 455 | + * @since 2.3.0 |
|
| 456 | + * @return bool |
|
| 457 | + */ |
|
| 458 | + public function has_multiple_subscription_groups() { |
|
| 459 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /* |
|
| 463 | 463 | |-------------------------------------------------------------------------- |
| 464 | 464 | | Taxes |
| 465 | 465 | |-------------------------------------------------------------------------- |
@@ -468,128 +468,128 @@ discard block |
||
| 468 | 468 | | or only one-time. |
| 469 | 469 | */ |
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * Prepares the submission's taxes. |
|
| 473 | - * |
|
| 474 | - * @since 1.0.19 |
|
| 475 | - */ |
|
| 476 | - public function process_taxes() { |
|
| 477 | - |
|
| 478 | - // Abort if we're not using taxes. |
|
| 479 | - if ( ! $this->use_taxes() ) { |
|
| 480 | - return; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 485 | - if ( ! empty( $country ) ) { |
|
| 486 | - $this->country = $country; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 490 | - if ( ! empty( $state ) ) { |
|
| 491 | - $this->state = $state; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // Confirm if the provided country and the ip country are similar. |
|
| 495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 496 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // Abort if the country is not taxable. |
|
| 501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 502 | - return; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 506 | - |
|
| 507 | - foreach ( $processor->taxes as $tax ) { |
|
| 508 | - $this->add_tax( $tax ); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Adds a tax to the submission. |
|
| 516 | - * |
|
| 517 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 518 | - * @since 1.0.19 |
|
| 519 | - */ |
|
| 520 | - public function add_tax( $tax ) { |
|
| 521 | - |
|
| 522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 530 | - |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Removes a specific tax. |
|
| 535 | - * |
|
| 536 | - * @since 1.0.19 |
|
| 537 | - */ |
|
| 538 | - public function remove_tax( $tax_name ) { |
|
| 539 | - |
|
| 540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 543 | - unset( $this->taxes[ $tax_name ] ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Whether or not we'll use taxes for the submission. |
|
| 550 | - * |
|
| 551 | - * @since 1.0.19 |
|
| 552 | - */ |
|
| 553 | - public function use_taxes() { |
|
| 554 | - |
|
| 555 | - $use_taxes = wpinv_use_taxes(); |
|
| 556 | - |
|
| 557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 558 | - $use_taxes = false; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 562 | - |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Returns the tax. |
|
| 567 | - * |
|
| 568 | - * @since 1.0.19 |
|
| 569 | - */ |
|
| 570 | - public function get_tax() { |
|
| 571 | - return $this->totals['taxes']['initial']; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * Returns the recurring tax. |
|
| 576 | - * |
|
| 577 | - * @since 1.0.19 |
|
| 578 | - */ |
|
| 579 | - public function get_recurring_tax() { |
|
| 580 | - return $this->totals['taxes']['recurring']; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Returns all taxes. |
|
| 585 | - * |
|
| 586 | - * @since 1.0.19 |
|
| 587 | - */ |
|
| 588 | - public function get_taxes() { |
|
| 589 | - return $this->taxes; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /* |
|
| 471 | + /** |
|
| 472 | + * Prepares the submission's taxes. |
|
| 473 | + * |
|
| 474 | + * @since 1.0.19 |
|
| 475 | + */ |
|
| 476 | + public function process_taxes() { |
|
| 477 | + |
|
| 478 | + // Abort if we're not using taxes. |
|
| 479 | + if ( ! $this->use_taxes() ) { |
|
| 480 | + return; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 484 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 485 | + if ( ! empty( $country ) ) { |
|
| 486 | + $this->country = $country; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 490 | + if ( ! empty( $state ) ) { |
|
| 491 | + $this->state = $state; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // Confirm if the provided country and the ip country are similar. |
|
| 495 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 496 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 497 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // Abort if the country is not taxable. |
|
| 501 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 502 | + return; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 506 | + |
|
| 507 | + foreach ( $processor->taxes as $tax ) { |
|
| 508 | + $this->add_tax( $tax ); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Adds a tax to the submission. |
|
| 516 | + * |
|
| 517 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 518 | + * @since 1.0.19 |
|
| 519 | + */ |
|
| 520 | + public function add_tax( $tax ) { |
|
| 521 | + |
|
| 522 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 523 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 524 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 530 | + |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Removes a specific tax. |
|
| 535 | + * |
|
| 536 | + * @since 1.0.19 |
|
| 537 | + */ |
|
| 538 | + public function remove_tax( $tax_name ) { |
|
| 539 | + |
|
| 540 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 541 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 542 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 543 | + unset( $this->taxes[ $tax_name ] ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Whether or not we'll use taxes for the submission. |
|
| 550 | + * |
|
| 551 | + * @since 1.0.19 |
|
| 552 | + */ |
|
| 553 | + public function use_taxes() { |
|
| 554 | + |
|
| 555 | + $use_taxes = wpinv_use_taxes(); |
|
| 556 | + |
|
| 557 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 558 | + $use_taxes = false; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 562 | + |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Returns the tax. |
|
| 567 | + * |
|
| 568 | + * @since 1.0.19 |
|
| 569 | + */ |
|
| 570 | + public function get_tax() { |
|
| 571 | + return $this->totals['taxes']['initial']; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Returns the recurring tax. |
|
| 576 | + * |
|
| 577 | + * @since 1.0.19 |
|
| 578 | + */ |
|
| 579 | + public function get_recurring_tax() { |
|
| 580 | + return $this->totals['taxes']['recurring']; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Returns all taxes. |
|
| 585 | + * |
|
| 586 | + * @since 1.0.19 |
|
| 587 | + */ |
|
| 588 | + public function get_taxes() { |
|
| 589 | + return $this->taxes; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /* |
|
| 593 | 593 | |-------------------------------------------------------------------------- |
| 594 | 594 | | Discounts |
| 595 | 595 | |-------------------------------------------------------------------------- |
@@ -598,99 +598,99 @@ discard block |
||
| 598 | 598 | | or only one-time. They also do not have to come from a discount code. |
| 599 | 599 | */ |
| 600 | 600 | |
| 601 | - /** |
|
| 602 | - * Prepares the submission's discount. |
|
| 603 | - * |
|
| 604 | - * @since 1.0.19 |
|
| 605 | - */ |
|
| 606 | - public function process_discount() { |
|
| 607 | - |
|
| 608 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 609 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 611 | - |
|
| 612 | - foreach ( $processor->discounts as $discount ) { |
|
| 613 | - $this->add_discount( $discount ); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Adds a discount to the submission. |
|
| 621 | - * |
|
| 622 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 623 | - * @since 1.0.19 |
|
| 624 | - */ |
|
| 625 | - public function add_discount( $discount ) { |
|
| 626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * Removes a discount from the submission. |
|
| 633 | - * |
|
| 634 | - * @since 1.0.19 |
|
| 635 | - */ |
|
| 636 | - public function remove_discount( $name ) { |
|
| 637 | - |
|
| 638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 641 | - unset( $this->discounts[ $name ] ); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * Checks whether there is a discount code associated with this submission. |
|
| 648 | - * |
|
| 649 | - * @since 1.0.19 |
|
| 650 | - * @return bool |
|
| 651 | - */ |
|
| 652 | - public function has_discount_code() { |
|
| 653 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Returns the discount code. |
|
| 658 | - * |
|
| 659 | - * @since 1.0.19 |
|
| 660 | - * @return string |
|
| 661 | - */ |
|
| 662 | - public function get_discount_code() { |
|
| 663 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Returns the discount. |
|
| 668 | - * |
|
| 669 | - * @since 1.0.19 |
|
| 670 | - */ |
|
| 671 | - public function get_discount() { |
|
| 672 | - return $this->totals['discount']['initial']; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Returns the recurring discount. |
|
| 677 | - * |
|
| 678 | - * @since 1.0.19 |
|
| 679 | - */ |
|
| 680 | - public function get_recurring_discount() { |
|
| 681 | - return $this->totals['discount']['recurring']; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Returns all discounts. |
|
| 686 | - * |
|
| 687 | - * @since 1.0.19 |
|
| 688 | - */ |
|
| 689 | - public function get_discounts() { |
|
| 690 | - return $this->discounts; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - /* |
|
| 601 | + /** |
|
| 602 | + * Prepares the submission's discount. |
|
| 603 | + * |
|
| 604 | + * @since 1.0.19 |
|
| 605 | + */ |
|
| 606 | + public function process_discount() { |
|
| 607 | + |
|
| 608 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 609 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 610 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 611 | + |
|
| 612 | + foreach ( $processor->discounts as $discount ) { |
|
| 613 | + $this->add_discount( $discount ); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Adds a discount to the submission. |
|
| 621 | + * |
|
| 622 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 623 | + * @since 1.0.19 |
|
| 624 | + */ |
|
| 625 | + public function add_discount( $discount ) { |
|
| 626 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * Removes a discount from the submission. |
|
| 633 | + * |
|
| 634 | + * @since 1.0.19 |
|
| 635 | + */ |
|
| 636 | + public function remove_discount( $name ) { |
|
| 637 | + |
|
| 638 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 639 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 640 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 641 | + unset( $this->discounts[ $name ] ); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * Checks whether there is a discount code associated with this submission. |
|
| 648 | + * |
|
| 649 | + * @since 1.0.19 |
|
| 650 | + * @return bool |
|
| 651 | + */ |
|
| 652 | + public function has_discount_code() { |
|
| 653 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Returns the discount code. |
|
| 658 | + * |
|
| 659 | + * @since 1.0.19 |
|
| 660 | + * @return string |
|
| 661 | + */ |
|
| 662 | + public function get_discount_code() { |
|
| 663 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Returns the discount. |
|
| 668 | + * |
|
| 669 | + * @since 1.0.19 |
|
| 670 | + */ |
|
| 671 | + public function get_discount() { |
|
| 672 | + return $this->totals['discount']['initial']; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Returns the recurring discount. |
|
| 677 | + * |
|
| 678 | + * @since 1.0.19 |
|
| 679 | + */ |
|
| 680 | + public function get_recurring_discount() { |
|
| 681 | + return $this->totals['discount']['recurring']; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Returns all discounts. |
|
| 686 | + * |
|
| 687 | + * @since 1.0.19 |
|
| 688 | + */ |
|
| 689 | + public function get_discounts() { |
|
| 690 | + return $this->discounts; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + /* |
|
| 694 | 694 | |-------------------------------------------------------------------------- |
| 695 | 695 | | Fees |
| 696 | 696 | |-------------------------------------------------------------------------- |
@@ -700,89 +700,89 @@ discard block |
||
| 700 | 700 | | fees. |
| 701 | 701 | */ |
| 702 | 702 | |
| 703 | - /** |
|
| 704 | - * Prepares the submission's fees. |
|
| 705 | - * |
|
| 706 | - * @since 1.0.19 |
|
| 707 | - */ |
|
| 708 | - public function process_fees() { |
|
| 709 | - |
|
| 710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 711 | - |
|
| 712 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 713 | - $this->add_fee( $fee ); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * Adds a fee to the submission. |
|
| 721 | - * |
|
| 722 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 723 | - * @since 1.0.19 |
|
| 724 | - */ |
|
| 725 | - public function add_fee( $fee ) { |
|
| 726 | - |
|
| 727 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 730 | - |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * Removes a fee from the submission. |
|
| 735 | - * |
|
| 736 | - * @since 1.0.19 |
|
| 737 | - */ |
|
| 738 | - public function remove_fee( $name ) { |
|
| 739 | - |
|
| 740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 743 | - unset( $this->fees[ $name ] ); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Returns the fees. |
|
| 750 | - * |
|
| 751 | - * @since 1.0.19 |
|
| 752 | - */ |
|
| 753 | - public function get_fee() { |
|
| 754 | - return $this->totals['fees']['initial']; |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * Returns the recurring fees. |
|
| 759 | - * |
|
| 760 | - * @since 1.0.19 |
|
| 761 | - */ |
|
| 762 | - public function get_recurring_fee() { |
|
| 763 | - return $this->totals['fees']['recurring']; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * Returns all fees. |
|
| 768 | - * |
|
| 769 | - * @since 1.0.19 |
|
| 770 | - */ |
|
| 771 | - public function get_fees() { |
|
| 772 | - return $this->fees; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * Checks if there are any fees for the form. |
|
| 777 | - * |
|
| 778 | - * @return bool |
|
| 779 | - * @since 1.0.19 |
|
| 780 | - */ |
|
| 781 | - public function has_fees() { |
|
| 782 | - return count( $this->fees ) !== 0; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - /* |
|
| 703 | + /** |
|
| 704 | + * Prepares the submission's fees. |
|
| 705 | + * |
|
| 706 | + * @since 1.0.19 |
|
| 707 | + */ |
|
| 708 | + public function process_fees() { |
|
| 709 | + |
|
| 710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 711 | + |
|
| 712 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 713 | + $this->add_fee( $fee ); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * Adds a fee to the submission. |
|
| 721 | + * |
|
| 722 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 723 | + * @since 1.0.19 |
|
| 724 | + */ |
|
| 725 | + public function add_fee( $fee ) { |
|
| 726 | + |
|
| 727 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 730 | + |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * Removes a fee from the submission. |
|
| 735 | + * |
|
| 736 | + * @since 1.0.19 |
|
| 737 | + */ |
|
| 738 | + public function remove_fee( $name ) { |
|
| 739 | + |
|
| 740 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 741 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 742 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 743 | + unset( $this->fees[ $name ] ); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Returns the fees. |
|
| 750 | + * |
|
| 751 | + * @since 1.0.19 |
|
| 752 | + */ |
|
| 753 | + public function get_fee() { |
|
| 754 | + return $this->totals['fees']['initial']; |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * Returns the recurring fees. |
|
| 759 | + * |
|
| 760 | + * @since 1.0.19 |
|
| 761 | + */ |
|
| 762 | + public function get_recurring_fee() { |
|
| 763 | + return $this->totals['fees']['recurring']; |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * Returns all fees. |
|
| 768 | + * |
|
| 769 | + * @since 1.0.19 |
|
| 770 | + */ |
|
| 771 | + public function get_fees() { |
|
| 772 | + return $this->fees; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * Checks if there are any fees for the form. |
|
| 777 | + * |
|
| 778 | + * @return bool |
|
| 779 | + * @since 1.0.19 |
|
| 780 | + */ |
|
| 781 | + public function has_fees() { |
|
| 782 | + return count( $this->fees ) !== 0; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + /* |
|
| 786 | 786 | |-------------------------------------------------------------------------- |
| 787 | 787 | | MISC |
| 788 | 788 | |-------------------------------------------------------------------------- |
@@ -790,119 +790,119 @@ discard block |
||
| 790 | 790 | | Extra submission functions. |
| 791 | 791 | */ |
| 792 | 792 | |
| 793 | - /** |
|
| 794 | - * Checks if this is the initial fetch. |
|
| 795 | - * |
|
| 796 | - * @return bool |
|
| 797 | - * @since 1.0.19 |
|
| 798 | - */ |
|
| 799 | - public function is_initial_fetch() { |
|
| 800 | - return empty( $this->data['initial_state'] ); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * Returns the total amount to collect for this submission. |
|
| 805 | - * |
|
| 806 | - * @since 1.0.19 |
|
| 807 | - */ |
|
| 808 | - public function get_total() { |
|
| 809 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 810 | - return max( $total, 0 ); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * Returns the recurring total amount to collect for this submission. |
|
| 815 | - * |
|
| 816 | - * @since 1.0.19 |
|
| 817 | - */ |
|
| 818 | - public function get_recurring_total() { |
|
| 819 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 820 | - return max( $total, 0 ); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Whether payment details should be collected for this submission. |
|
| 825 | - * |
|
| 826 | - * @since 1.0.19 |
|
| 827 | - */ |
|
| 828 | - public function should_collect_payment_details() { |
|
| 829 | - $initial = $this->get_total(); |
|
| 830 | - $recurring = $this->get_recurring_total(); |
|
| 831 | - |
|
| 832 | - if ( $this->has_recurring == 0 ) { |
|
| 833 | - $recurring = 0; |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - $collect = $initial > 0 || $recurring > 0; |
|
| 837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Returns the billing email of the user. |
|
| 842 | - * |
|
| 843 | - * @since 1.0.19 |
|
| 844 | - */ |
|
| 845 | - public function get_billing_email() { |
|
| 846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * Checks if the submitter has a billing email. |
|
| 851 | - * |
|
| 852 | - * @since 1.0.19 |
|
| 853 | - */ |
|
| 854 | - public function has_billing_email() { |
|
| 855 | - $billing_email = $this->get_billing_email(); |
|
| 856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * Returns the appropriate currency for the submission. |
|
| 861 | - * |
|
| 862 | - * @since 1.0.19 |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - public function get_currency() { |
|
| 866 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * Returns the raw submission data. |
|
| 871 | - * |
|
| 872 | - * @since 1.0.19 |
|
| 873 | - * @return array |
|
| 874 | - */ |
|
| 875 | - public function get_data() { |
|
| 876 | - return $this->data; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * Returns a field from the submission data |
|
| 881 | - * |
|
| 882 | - * @param string $field |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - * @return mixed|null |
|
| 885 | - */ |
|
| 886 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * Checks if a required field is set. |
|
| 892 | - * |
|
| 893 | - * @since 1.0.19 |
|
| 894 | - */ |
|
| 895 | - public function is_required_field_set( $field ) { |
|
| 896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Formats an amount |
|
| 901 | - * |
|
| 902 | - * @since 1.0.19 |
|
| 903 | - */ |
|
| 904 | - public function format_amount( $amount ) { |
|
| 905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 906 | - } |
|
| 793 | + /** |
|
| 794 | + * Checks if this is the initial fetch. |
|
| 795 | + * |
|
| 796 | + * @return bool |
|
| 797 | + * @since 1.0.19 |
|
| 798 | + */ |
|
| 799 | + public function is_initial_fetch() { |
|
| 800 | + return empty( $this->data['initial_state'] ); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * Returns the total amount to collect for this submission. |
|
| 805 | + * |
|
| 806 | + * @since 1.0.19 |
|
| 807 | + */ |
|
| 808 | + public function get_total() { |
|
| 809 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 810 | + return max( $total, 0 ); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * Returns the recurring total amount to collect for this submission. |
|
| 815 | + * |
|
| 816 | + * @since 1.0.19 |
|
| 817 | + */ |
|
| 818 | + public function get_recurring_total() { |
|
| 819 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 820 | + return max( $total, 0 ); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Whether payment details should be collected for this submission. |
|
| 825 | + * |
|
| 826 | + * @since 1.0.19 |
|
| 827 | + */ |
|
| 828 | + public function should_collect_payment_details() { |
|
| 829 | + $initial = $this->get_total(); |
|
| 830 | + $recurring = $this->get_recurring_total(); |
|
| 831 | + |
|
| 832 | + if ( $this->has_recurring == 0 ) { |
|
| 833 | + $recurring = 0; |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + $collect = $initial > 0 || $recurring > 0; |
|
| 837 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Returns the billing email of the user. |
|
| 842 | + * |
|
| 843 | + * @since 1.0.19 |
|
| 844 | + */ |
|
| 845 | + public function get_billing_email() { |
|
| 846 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * Checks if the submitter has a billing email. |
|
| 851 | + * |
|
| 852 | + * @since 1.0.19 |
|
| 853 | + */ |
|
| 854 | + public function has_billing_email() { |
|
| 855 | + $billing_email = $this->get_billing_email(); |
|
| 856 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * Returns the appropriate currency for the submission. |
|
| 861 | + * |
|
| 862 | + * @since 1.0.19 |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + public function get_currency() { |
|
| 866 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * Returns the raw submission data. |
|
| 871 | + * |
|
| 872 | + * @since 1.0.19 |
|
| 873 | + * @return array |
|
| 874 | + */ |
|
| 875 | + public function get_data() { |
|
| 876 | + return $this->data; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * Returns a field from the submission data |
|
| 881 | + * |
|
| 882 | + * @param string $field |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + * @return mixed|null |
|
| 885 | + */ |
|
| 886 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 887 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * Checks if a required field is set. |
|
| 892 | + * |
|
| 893 | + * @since 1.0.19 |
|
| 894 | + */ |
|
| 895 | + public function is_required_field_set( $field ) { |
|
| 896 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Formats an amount |
|
| 901 | + * |
|
| 902 | + * @since 1.0.19 |
|
| 903 | + */ |
|
| 904 | + public function format_amount( $amount ) { |
|
| 905 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 906 | + } |
|
| 907 | 907 | |
| 908 | 908 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | $this->state = wpinv_get_default_state(); |
| 142 | 142 | |
| 143 | 143 | // Do we have an actual submission? |
| 144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 145 | - $this->load_data( $_POST ); |
|
| 144 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 145 | + $this->load_data($_POST); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | } |
@@ -152,19 +152,19 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @param array $data |
| 154 | 154 | */ |
| 155 | - public function load_data( $data ) { |
|
| 155 | + public function load_data($data) { |
|
| 156 | 156 | |
| 157 | 157 | // Remove slashes from the submitted data... |
| 158 | - $data = wp_unslash( $data ); |
|
| 158 | + $data = wp_unslash($data); |
|
| 159 | 159 | |
| 160 | 160 | // Allow plugins to filter the data. |
| 161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 161 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 162 | 162 | |
| 163 | 163 | // Cache it... |
| 164 | 164 | $this->data = $data; |
| 165 | 165 | |
| 166 | 166 | // Then generate a unique id from the data. |
| 167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 167 | + $this->id = md5(wp_json_encode($data)); |
|
| 168 | 168 | |
| 169 | 169 | // Finally, process the submission. |
| 170 | 170 | try { |
@@ -174,30 +174,30 @@ discard block |
||
| 174 | 174 | $processors = apply_filters( |
| 175 | 175 | 'getpaid_payment_form_submission_processors', |
| 176 | 176 | array( |
| 177 | - array( $this, 'process_payment_form' ), |
|
| 178 | - array( $this, 'process_invoice' ), |
|
| 179 | - array( $this, 'process_fees' ), |
|
| 180 | - array( $this, 'process_items' ), |
|
| 181 | - array( $this, 'process_discount' ), |
|
| 182 | - array( $this, 'process_taxes' ), |
|
| 177 | + array($this, 'process_payment_form'), |
|
| 178 | + array($this, 'process_invoice'), |
|
| 179 | + array($this, 'process_fees'), |
|
| 180 | + array($this, 'process_items'), |
|
| 181 | + array($this, 'process_discount'), |
|
| 182 | + array($this, 'process_taxes'), |
|
| 183 | 183 | ), |
| 184 | 184 | $this |
| 185 | 185 | ); |
| 186 | 186 | |
| 187 | - foreach ( $processors as $processor ) { |
|
| 188 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 187 | + foreach ($processors as $processor) { |
|
| 188 | + call_user_func_array($processor, array(&$this)); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
| 191 | + } catch (GetPaid_Payment_Exception $e) { |
|
| 192 | 192 | $this->last_error = $e->getMessage(); |
| 193 | 193 | $this->last_error_code = $e->getErrorCode(); |
| 194 | - } catch ( Exception $e ) { |
|
| 194 | + } catch (Exception $e) { |
|
| 195 | 195 | $this->last_error = $e->getMessage(); |
| 196 | 196 | $this->last_error_code = $e->getCode(); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Fired when we are done processing a submission. |
| 200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 200 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 201 | 201 | |
| 202 | 202 | } |
| 203 | 203 | |
@@ -218,18 +218,18 @@ discard block |
||
| 218 | 218 | public function process_payment_form() { |
| 219 | 219 | |
| 220 | 220 | // Every submission needs an active payment form. |
| 221 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 221 | + if (empty($this->data['form_id'])) { |
|
| 222 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // Fetch the payment form. |
| 226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 226 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 227 | 227 | |
| 228 | - if ( ! $this->payment_form->is_active() ) { |
|
| 229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 228 | + if (!$this->payment_form->is_active()) { |
|
| 229 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 232 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -259,53 +259,53 @@ discard block |
||
| 259 | 259 | public function process_invoice() { |
| 260 | 260 | |
| 261 | 261 | // Abort if there is no invoice. |
| 262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 262 | + if (empty($this->data['invoice_id'])) { |
|
| 263 | 263 | return; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // If the submission is for an existing invoice, ensure that it exists |
| 267 | 267 | // and that it is not paid for. |
| 268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 268 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 269 | 269 | |
| 270 | - if ( empty( $invoice ) ) { |
|
| 271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 270 | + if (empty($invoice)) { |
|
| 271 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if ( $invoice->is_paid() ) { |
|
| 275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 274 | + if ($invoice->is_paid()) { |
|
| 275 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | $this->payment_form->invoice = $invoice; |
| 279 | - if ( ! $this->payment_form->is_default() ) { |
|
| 279 | + if (!$this->payment_form->is_default()) { |
|
| 280 | 280 | |
| 281 | 281 | $items = array(); |
| 282 | 282 | $item_ids = array(); |
| 283 | 283 | |
| 284 | - foreach ( $invoice->get_items() as $item ) { |
|
| 285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 284 | + foreach ($invoice->get_items() as $item) { |
|
| 285 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 286 | 286 | $item_ids[] = $item->get_id(); |
| 287 | 287 | $items[] = $item; |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 291 | + foreach ($this->payment_form->get_items() as $item) { |
|
| 292 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 293 | 293 | $item_ids[] = $item->get_id(); |
| 294 | 294 | $items[] = $item; |
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - $this->payment_form->set_items( $items ); |
|
| 298 | + $this->payment_form->set_items($items); |
|
| 299 | 299 | |
| 300 | 300 | } else { |
| 301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 301 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | $this->country = $invoice->get_country(); |
| 305 | 305 | $this->state = $invoice->get_state(); |
| 306 | 306 | $this->invoice = $invoice; |
| 307 | 307 | |
| 308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 308 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | * @return bool |
| 326 | 326 | */ |
| 327 | 327 | public function has_invoice() { |
| 328 | - return ! empty( $this->invoice ); |
|
| 328 | + return !empty($this->invoice); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /* |
@@ -344,13 +344,13 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | public function process_items() { |
| 346 | 346 | |
| 347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 347 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 348 | 348 | |
| 349 | - foreach ( $processor->items as $item ) { |
|
| 350 | - $this->add_item( $item ); |
|
| 349 | + foreach ($processor->items as $item) { |
|
| 350 | + $this->add_item($item); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 353 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -359,20 +359,20 @@ discard block |
||
| 359 | 359 | * @since 1.0.19 |
| 360 | 360 | * @param GetPaid_Form_Item $item |
| 361 | 361 | */ |
| 362 | - public function add_item( $item ) { |
|
| 362 | + public function add_item($item) { |
|
| 363 | 363 | |
| 364 | 364 | // Make sure that it is available for purchase. |
| 365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 365 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // Each submission can only contain one recurring item. |
| 370 | - if ( $item->is_recurring() ) { |
|
| 370 | + if ($item->is_recurring()) { |
|
| 371 | 371 | $this->has_recurring = $item->get_id(); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // Update the items and totals. |
| 375 | - $this->items[ $item->get_id() ] = $item; |
|
| 375 | + $this->items[$item->get_id()] = $item; |
|
| 376 | 376 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 377 | 377 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 378 | 378 | |
@@ -386,17 +386,17 @@ discard block |
||
| 386 | 386 | * |
| 387 | 387 | * @since 1.0.19 |
| 388 | 388 | */ |
| 389 | - public function remove_item( $item_id ) { |
|
| 389 | + public function remove_item($item_id) { |
|
| 390 | 390 | |
| 391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 391 | + if (isset($this->items[$item_id])) { |
|
| 392 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 393 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 394 | 394 | |
| 395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 395 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 396 | 396 | $this->has_recurring = 0; |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - unset( $this->items[ $item_id ] ); |
|
| 399 | + unset($this->items[$item_id]); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | } |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | public function get_subtotal() { |
| 410 | 410 | |
| 411 | - if ( wpinv_prices_include_tax() ) { |
|
| 411 | + if (wpinv_prices_include_tax()) { |
|
| 412 | 412 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | public function get_recurring_subtotal() { |
| 424 | 424 | |
| 425 | - if ( wpinv_prices_include_tax() ) { |
|
| 425 | + if (wpinv_prices_include_tax()) { |
|
| 426 | 426 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
| 427 | 427 | } |
| 428 | 428 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | * @return bool |
| 447 | 447 | */ |
| 448 | 448 | public function has_subscription_group() { |
| 449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 449 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | * @return bool |
| 457 | 457 | */ |
| 458 | 458 | public function has_multiple_subscription_groups() { |
| 459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 459 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /* |
@@ -476,39 +476,39 @@ discard block |
||
| 476 | 476 | public function process_taxes() { |
| 477 | 477 | |
| 478 | 478 | // Abort if we're not using taxes. |
| 479 | - if ( ! $this->use_taxes() ) { |
|
| 479 | + if (!$this->use_taxes()) { |
|
| 480 | 480 | return; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 485 | - if ( ! empty( $country ) ) { |
|
| 484 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
| 485 | + if (!empty($country)) { |
|
| 486 | 486 | $this->country = $country; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 490 | - if ( ! empty( $state ) ) { |
|
| 489 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
| 490 | + if (!empty($state)) { |
|
| 491 | 491 | $this->state = $state; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | // Confirm if the provided country and the ip country are similar. |
| 495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 496 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 495 | + $address_confirmed = $this->get_field('confirm-address'); |
|
| 496 | + if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
| 497 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | // Abort if the country is not taxable. |
| 501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 501 | + if (!wpinv_is_country_taxable($this->country)) { |
|
| 502 | 502 | return; |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 506 | 506 | |
| 507 | - foreach ( $processor->taxes as $tax ) { |
|
| 508 | - $this->add_tax( $tax ); |
|
| 507 | + foreach ($processor->taxes as $tax) { |
|
| 508 | + $this->add_tax($tax); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 511 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -517,16 +517,16 @@ discard block |
||
| 517 | 517 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 518 | 518 | * @since 1.0.19 |
| 519 | 519 | */ |
| 520 | - public function add_tax( $tax ) { |
|
| 520 | + public function add_tax($tax) { |
|
| 521 | 521 | |
| 522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 522 | + if (wpinv_round_tax_per_tax_rate()) { |
|
| 523 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
| 524 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 527 | + $this->taxes[$tax['name']] = $tax; |
|
| 528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 530 | 530 | |
| 531 | 531 | } |
| 532 | 532 | |
@@ -535,12 +535,12 @@ discard block |
||
| 535 | 535 | * |
| 536 | 536 | * @since 1.0.19 |
| 537 | 537 | */ |
| 538 | - public function remove_tax( $tax_name ) { |
|
| 538 | + public function remove_tax($tax_name) { |
|
| 539 | 539 | |
| 540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 543 | - unset( $this->taxes[ $tax_name ] ); |
|
| 540 | + if (isset($this->taxes[$tax_name])) { |
|
| 541 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 542 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 543 | + unset($this->taxes[$tax_name]); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | } |
@@ -554,11 +554,11 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | $use_taxes = wpinv_use_taxes(); |
| 556 | 556 | |
| 557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 557 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 558 | 558 | $use_taxes = false; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 561 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 562 | 562 | |
| 563 | 563 | } |
| 564 | 564 | |
@@ -607,13 +607,13 @@ discard block |
||
| 607 | 607 | |
| 608 | 608 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 609 | 609 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 610 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 611 | 611 | |
| 612 | - foreach ( $processor->discounts as $discount ) { |
|
| 613 | - $this->add_discount( $discount ); |
|
| 612 | + foreach ($processor->discounts as $discount) { |
|
| 613 | + $this->add_discount($discount); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 616 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -622,10 +622,10 @@ discard block |
||
| 622 | 622 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
| 623 | 623 | * @since 1.0.19 |
| 624 | 624 | */ |
| 625 | - public function add_discount( $discount ) { |
|
| 626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 625 | + public function add_discount($discount) { |
|
| 626 | + $this->discounts[$discount['name']] = $discount; |
|
| 627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -633,12 +633,12 @@ discard block |
||
| 633 | 633 | * |
| 634 | 634 | * @since 1.0.19 |
| 635 | 635 | */ |
| 636 | - public function remove_discount( $name ) { |
|
| 636 | + public function remove_discount($name) { |
|
| 637 | 637 | |
| 638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 641 | - unset( $this->discounts[ $name ] ); |
|
| 638 | + if (isset($this->discounts[$name])) { |
|
| 639 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 640 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 641 | + unset($this->discounts[$name]); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | } |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | * @return bool |
| 651 | 651 | */ |
| 652 | 652 | public function has_discount_code() { |
| 653 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 653 | + return !empty($this->discounts['discount_code']); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -707,13 +707,13 @@ discard block |
||
| 707 | 707 | */ |
| 708 | 708 | public function process_fees() { |
| 709 | 709 | |
| 710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 711 | 711 | |
| 712 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 713 | - $this->add_fee( $fee ); |
|
| 712 | + foreach ($fees_processor->fees as $fee) { |
|
| 713 | + $this->add_fee($fee); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 716 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -722,11 +722,11 @@ discard block |
||
| 722 | 722 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 723 | 723 | * @since 1.0.19 |
| 724 | 724 | */ |
| 725 | - public function add_fee( $fee ) { |
|
| 725 | + public function add_fee($fee) { |
|
| 726 | 726 | |
| 727 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 727 | + $this->fees[$fee['name']] = $fee; |
|
| 728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 730 | 730 | |
| 731 | 731 | } |
| 732 | 732 | |
@@ -735,12 +735,12 @@ discard block |
||
| 735 | 735 | * |
| 736 | 736 | * @since 1.0.19 |
| 737 | 737 | */ |
| 738 | - public function remove_fee( $name ) { |
|
| 738 | + public function remove_fee($name) { |
|
| 739 | 739 | |
| 740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 743 | - unset( $this->fees[ $name ] ); |
|
| 740 | + if (isset($this->fees[$name])) { |
|
| 741 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 742 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 743 | + unset($this->fees[$name]); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | } |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | * @since 1.0.19 |
| 780 | 780 | */ |
| 781 | 781 | public function has_fees() { |
| 782 | - return count( $this->fees ) !== 0; |
|
| 782 | + return count($this->fees) !== 0; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /* |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | * @since 1.0.19 |
| 798 | 798 | */ |
| 799 | 799 | public function is_initial_fetch() { |
| 800 | - return empty( $this->data['initial_state'] ); |
|
| 800 | + return empty($this->data['initial_state']); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | */ |
| 808 | 808 | public function get_total() { |
| 809 | 809 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
| 810 | - return max( $total, 0 ); |
|
| 810 | + return max($total, 0); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | /** |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | */ |
| 818 | 818 | public function get_recurring_total() { |
| 819 | 819 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
| 820 | - return max( $total, 0 ); |
|
| 820 | + return max($total, 0); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | /** |
@@ -829,12 +829,12 @@ discard block |
||
| 829 | 829 | $initial = $this->get_total(); |
| 830 | 830 | $recurring = $this->get_recurring_total(); |
| 831 | 831 | |
| 832 | - if ( $this->has_recurring == 0 ) { |
|
| 832 | + if ($this->has_recurring == 0) { |
|
| 833 | 833 | $recurring = 0; |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | $collect = $initial > 0 || $recurring > 0; |
| 837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 837 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | * @since 1.0.19 |
| 844 | 844 | */ |
| 845 | 845 | public function get_billing_email() { |
| 846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 846 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | */ |
| 854 | 854 | public function has_billing_email() { |
| 855 | 855 | $billing_email = $this->get_billing_email(); |
| 856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 856 | + return !empty($billing_email) && is_email($billing_email); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -883,8 +883,8 @@ discard block |
||
| 883 | 883 | * @since 1.0.19 |
| 884 | 884 | * @return mixed|null |
| 885 | 885 | */ |
| 886 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 886 | + public function get_field($field, $sub_array_key = null) { |
|
| 887 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
@@ -892,8 +892,8 @@ discard block |
||
| 892 | 892 | * |
| 893 | 893 | * @since 1.0.19 |
| 894 | 894 | */ |
| 895 | - public function is_required_field_set( $field ) { |
|
| 896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 895 | + public function is_required_field_set($field) { |
|
| 896 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -901,8 +901,8 @@ discard block |
||
| 901 | 901 | * |
| 902 | 902 | * @since 1.0.19 |
| 903 | 903 | */ |
| 904 | - public function format_amount( $amount ) { |
|
| 905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 904 | + public function format_amount($amount) { |
|
| 905 | + return wpinv_price($amount, $this->get_currency()); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | } |
@@ -7,45 +7,45 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // The payment methods select title. |
| 13 | -if ( empty( $text ) ) { |
|
| 14 | - $text = __( 'Select Payment Method', 'invoicing' ); |
|
| 13 | +if (empty($text)) { |
|
| 14 | + $text = __('Select Payment Method', 'invoicing'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // An array of active payment methods. |
| 18 | -$gateways = wpinv_get_enabled_payment_gateways( true ); |
|
| 18 | +$gateways = wpinv_get_enabled_payment_gateways(true); |
|
| 19 | 19 | |
| 20 | 20 | // The current invoice id. |
| 21 | 21 | $invoice_id = 0; |
| 22 | 22 | $chosen_gateway = wpinv_get_default_gateway(); |
| 23 | 23 | |
| 24 | -if ( ! empty( $form->invoice ) ) { |
|
| 24 | +if (!empty($form->invoice)) { |
|
| 25 | 25 | $invoice_id = $form->invoice->get_id(); |
| 26 | 26 | $chosen_gateway = $form->invoice->get_gateway(); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | ?> |
| 30 | 30 | |
| 31 | - <?php do_action( 'getpaid_before_payment_form_gateway_select', $form ); ?> |
|
| 31 | + <?php do_action('getpaid_before_payment_form_gateway_select', $form); ?> |
|
| 32 | 32 | <div class="mt-4 mb-4 getpaid-gateways"> |
| 33 | 33 | |
| 34 | - <?php do_action( 'wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
| 34 | + <?php do_action('wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
| 35 | 35 | |
| 36 | 36 | <div class="getpaid-select-gateway-title-div"> |
| 37 | - <h6><?php echo sanitize_text_field( $text ); ?></h6> |
|
| 37 | + <h6><?php echo sanitize_text_field($text); ?></h6> |
|
| 38 | 38 | </div> |
| 39 | 39 | |
| 40 | 40 | <div class="getpaid-available-gateways-div"> |
| 41 | 41 | |
| 42 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
| 42 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
| 43 | 43 | |
| 44 | - <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class( $gateway ) ;?>" data-checkout-label='<?php echo esc_attr( apply_filters( "getpaid_gateway_{$gateway}_checkout_button_label", '' ) ); ?>'> |
|
| 44 | + <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class($gateway); ?>" data-checkout-label='<?php echo esc_attr(apply_filters("getpaid_gateway_{$gateway}_checkout_button_label", '')); ?>'> |
|
| 45 | 45 | |
| 46 | 46 | <label class="d-block w-100 getpaid-gateway-radio"> |
| 47 | - <input type="radio" value="<?php echo esc_attr( $gateway ) ;?>" <?php checked( $gateway, $chosen_gateway ) ;?> name="wpi-gateway"> |
|
| 48 | - <span><?php echo sanitize_text_field( wpinv_get_gateway_checkout_label( $gateway ) ); ?></span> |
|
| 47 | + <input type="radio" value="<?php echo esc_attr($gateway); ?>" <?php checked($gateway, $chosen_gateway); ?> name="wpi-gateway"> |
|
| 48 | + <span><?php echo sanitize_text_field(wpinv_get_gateway_checkout_label($gateway)); ?></span> |
|
| 49 | 49 | </label> |
| 50 | 50 | |
| 51 | 51 | </div> |
@@ -56,22 +56,22 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | <div class="getpaid-gateway-descriptions-div"> |
| 58 | 58 | |
| 59 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
| 59 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
| 60 | 60 | |
| 61 | - <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class( $gateway ) ;?>" style="display: none;"> |
|
| 61 | + <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class($gateway); ?>" style="display: none;"> |
|
| 62 | 62 | <?php |
| 63 | 63 | |
| 64 | - $description = wpinv_get_gateway_description( $gateway ); |
|
| 64 | + $description = wpinv_get_gateway_description($gateway); |
|
| 65 | 65 | |
| 66 | - if ( wpinv_is_test_mode( $gateway ) ) { |
|
| 67 | - $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) ); |
|
| 66 | + if (wpinv_is_test_mode($gateway)) { |
|
| 67 | + $sandbox_notice = apply_filters("getpaid_{$gateway}_sandbox_notice", __('SANDBOX ENABLED: No real payments will occur.', 'invoicing')); |
|
| 68 | 68 | $description = "$description $sandbox_notice"; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - echo wpautop( wp_kses_post( $description ) ); |
|
| 71 | + echo wpautop(wp_kses_post($description)); |
|
| 72 | 72 | |
| 73 | - do_action( 'wpinv_' . $gateway . '_checkout_fields', $invoice_id ) ; |
|
| 74 | - do_action( 'wpinv_' . $gateway . '_cc_form', $invoice_id, $form ) ; |
|
| 73 | + do_action('wpinv_' . $gateway . '_checkout_fields', $invoice_id); |
|
| 74 | + do_action('wpinv_' . $gateway . '_cc_form', $invoice_id, $form); |
|
| 75 | 75 | |
| 76 | 76 | ?> |
| 77 | 77 | </div> |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | <?php |
| 85 | 85 | echo aui()->alert( |
| 86 | 86 | array( |
| 87 | - 'content' => __( 'None of the available payment gateways support purchasing recurring items.', 'invoicing' ), |
|
| 87 | + 'content' => __('None of the available payment gateways support purchasing recurring items.', 'invoicing'), |
|
| 88 | 88 | 'type' => 'danger', |
| 89 | 89 | ) |
| 90 | 90 | ); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | <?php |
| 96 | 96 | echo aui()->alert( |
| 97 | 97 | array( |
| 98 | - 'content' => __( 'None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing' ), |
|
| 98 | + 'content' => __('None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing'), |
|
| 99 | 99 | 'type' => 'danger', |
| 100 | 100 | ) |
| 101 | 101 | ); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | <?php |
| 107 | 107 | echo aui()->alert( |
| 108 | 108 | array( |
| 109 | - 'content' => __( 'None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing' ), |
|
| 109 | + 'content' => __('None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing'), |
|
| 110 | 110 | 'type' => 'danger', |
| 111 | 111 | ) |
| 112 | 112 | ); |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | <?php |
| 118 | 118 | echo aui()->alert( |
| 119 | 119 | array( |
| 120 | - 'content' => __( 'There is no active payment gateway available to process your request.', 'invoicing' ), |
|
| 120 | + 'content' => __('There is no active payment gateway available to process your request.', 'invoicing'), |
|
| 121 | 121 | 'type' => 'danger', |
| 122 | 122 | ) |
| 123 | 123 | ); |
| 124 | 124 | ?> |
| 125 | 125 | </div> |
| 126 | 126 | |
| 127 | - <?php do_action( 'wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
| 127 | + <?php do_action('wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
| 128 | 128 | |
| 129 | 129 | </div> |
| 130 | - <?php do_action( 'getpaid_after_payment_form_gateway_select', $form ); ?> |
|
| 130 | + <?php do_action('getpaid_after_payment_form_gateway_select', $form); ?> |
|
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
| 10 | 10 | class WPInv_Item extends GetPaid_Data { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Which data store to load. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 13 | + * Which data store to load. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | 17 | protected $data_store_name = 'item'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'item'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'item'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'parent_id' => 0, |
|
| 34 | - 'status' => 'draft', |
|
| 35 | - 'version' => '', |
|
| 36 | - 'date_created' => null, |
|
| 27 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'parent_id' => 0, |
|
| 34 | + 'status' => 'draft', |
|
| 35 | + 'version' => '', |
|
| 36 | + 'date_created' => null, |
|
| 37 | 37 | 'date_modified' => null, |
| 38 | 38 | 'name' => '', |
| 39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * Stores meta in cache for future reads. |
|
| 62 | - * |
|
| 63 | - * A group must be set to to enable caching. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - protected $cache_group = 'getpaid_items'; |
|
| 61 | + * Stores meta in cache for future reads. |
|
| 62 | + * |
|
| 63 | + * A group must be set to to enable caching. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + protected $cache_group = 'getpaid_items'; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
| 74 | 74 | protected $post = null; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | - * |
|
| 79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | - */ |
|
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 94 | - } else { |
|
| 95 | - $this->set_object_read( true ); |
|
| 96 | - } |
|
| 77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | + * |
|
| 79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | + */ |
|
| 81 | + public function __construct( $item = 0 ) { |
|
| 82 | + parent::__construct( $item ); |
|
| 83 | + |
|
| 84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | + $this->set_id( $item ); |
|
| 86 | + } elseif ( $item instanceof self ) { |
|
| 87 | + $this->set_id( $item->get_id() ); |
|
| 88 | + } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | + $this->set_id( $item->ID ); |
|
| 90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | + $this->set_id( $item_id ); |
|
| 92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | + $this->set_id( $item_id ); |
|
| 94 | + } else { |
|
| 95 | + $this->set_object_read( true ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 101 | + if ( $this->get_id() > 0 ) { |
|
| 102 | 102 | $this->post = get_post( $this->get_id() ); |
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read( $this ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | /* |
| 110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Get parent item ID. |
|
| 126 | - * |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @param string $context View or edit context. |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 125 | + * Get parent item ID. |
|
| 126 | + * |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @param string $context View or edit context. |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + public function get_parent_id( $context = 'view' ) { |
|
| 132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | - * Get item status. |
|
| 137 | - * |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @param string $context View or edit context. |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 136 | + * Get item status. |
|
| 137 | + * |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @param string $context View or edit context. |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function get_status( $context = 'view' ) { |
|
| 143 | + return $this->get_prop( 'status', $context ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | - * Get plugin version when the item was created. |
|
| 148 | - * |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - * @param string $context View or edit context. |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 147 | + * Get plugin version when the item was created. |
|
| 148 | + * |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + * @param string $context View or edit context. |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function get_version( $context = 'view' ) { |
|
| 154 | + return $this->get_prop( 'version', $context ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | - * Get date when the item was created. |
|
| 159 | - * |
|
| 160 | - * @since 1.0.19 |
|
| 161 | - * @param string $context View or edit context. |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 158 | + * Get date when the item was created. |
|
| 159 | + * |
|
| 160 | + * @since 1.0.19 |
|
| 161 | + * @param string $context View or edit context. |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function get_date_created( $context = 'view' ) { |
|
| 165 | + return $this->get_prop( 'date_created', $context ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * Get GMT date when the item was created. |
|
| 170 | - * |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - * @param string $context View or edit context. |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 169 | + * Get GMT date when the item was created. |
|
| 170 | + * |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + * @param string $context View or edit context. |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | 176 | $date = $this->get_date_created( $context ); |
| 177 | 177 | |
| 178 | 178 | if ( $date ) { |
| 179 | 179 | $date = get_gmt_from_date( $date ); |
| 180 | 180 | } |
| 181 | - return $date; |
|
| 181 | + return $date; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Get date when the item was last modified. |
|
| 186 | - * |
|
| 187 | - * @since 1.0.19 |
|
| 188 | - * @param string $context View or edit context. |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 185 | + * Get date when the item was last modified. |
|
| 186 | + * |
|
| 187 | + * @since 1.0.19 |
|
| 188 | + * @param string $context View or edit context. |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + public function get_date_modified( $context = 'view' ) { |
|
| 192 | + return $this->get_prop( 'date_modified', $context ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Get GMT date when the item was last modified. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 196 | + * Get GMT date when the item was last modified. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | 203 | $date = $this->get_date_modified( $context ); |
| 204 | 204 | |
| 205 | 205 | if ( $date ) { |
| 206 | 206 | $date = get_gmt_from_date( $date ); |
| 207 | 207 | } |
| 208 | - return $date; |
|
| 208 | + return $date; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | - * Get the item name. |
|
| 213 | - * |
|
| 214 | - * @since 1.0.19 |
|
| 215 | - * @param string $context View or edit context. |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 212 | + * Get the item name. |
|
| 213 | + * |
|
| 214 | + * @since 1.0.19 |
|
| 215 | + * @param string $context View or edit context. |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function get_name( $context = 'view' ) { |
|
| 219 | + return $this->get_prop( 'name', $context ); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | - * Alias of self::get_name(). |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @param string $context View or edit context. |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 223 | + * Alias of self::get_name(). |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @param string $context View or edit context. |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function get_title( $context = 'view' ) { |
|
| 230 | + return $this->get_name( $context ); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | - * Get the item description. |
|
| 235 | - * |
|
| 236 | - * @since 1.0.19 |
|
| 237 | - * @param string $context View or edit context. |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 234 | + * Get the item description. |
|
| 235 | + * |
|
| 236 | + * @since 1.0.19 |
|
| 237 | + * @param string $context View or edit context. |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function get_description( $context = 'view' ) { |
|
| 241 | + return $this->get_prop( 'description', $context ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Alias of self::get_description(). |
|
| 246 | - * |
|
| 247 | - * @since 1.0.19 |
|
| 248 | - * @param string $context View or edit context. |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 245 | + * Alias of self::get_description(). |
|
| 246 | + * |
|
| 247 | + * @since 1.0.19 |
|
| 248 | + * @param string $context View or edit context. |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function get_excerpt( $context = 'view' ) { |
|
| 252 | + return $this->get_description( $context ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | - * Alias of self::get_description(). |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - * @param string $context View or edit context. |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 256 | + * Alias of self::get_description(). |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + * @param string $context View or edit context. |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function get_summary( $context = 'view' ) { |
|
| 263 | + return $this->get_description( $context ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | - * Get the owner of the item. |
|
| 268 | - * |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @param string $context View or edit context. |
|
| 271 | - * @return int |
|
| 272 | - */ |
|
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 275 | - } |
|
| 267 | + * Get the owner of the item. |
|
| 268 | + * |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @param string $context View or edit context. |
|
| 271 | + * @return int |
|
| 272 | + */ |
|
| 273 | + public function get_author( $context = 'view' ) { |
|
| 274 | + return (int) $this->get_prop( 'author', $context ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Alias of self::get_author(). |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @param string $context View or edit context. |
|
| 282 | - * @return int |
|
| 283 | - */ |
|
| 284 | - public function get_owner( $context = 'view' ) { |
|
| 285 | - return $this->get_author( $context ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Get the price of the item. |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @param string $context View or edit context. |
|
| 293 | - * @return float |
|
| 294 | - */ |
|
| 295 | - public function get_price( $context = 'view' ) { |
|
| 277 | + /** |
|
| 278 | + * Alias of self::get_author(). |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @param string $context View or edit context. |
|
| 282 | + * @return int |
|
| 283 | + */ |
|
| 284 | + public function get_owner( $context = 'view' ) { |
|
| 285 | + return $this->get_author( $context ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Get the price of the item. |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @param string $context View or edit context. |
|
| 293 | + * @return float |
|
| 294 | + */ |
|
| 295 | + public function get_price( $context = 'view' ) { |
|
| 296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
| 297 | - } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Get the inital price of the item. |
|
| 301 | - * |
|
| 302 | - * @since 1.0.19 |
|
| 303 | - * @param string $context View or edit context. |
|
| 304 | - * @return float |
|
| 305 | - */ |
|
| 306 | - public function get_initial_price( $context = 'view' ) { |
|
| 299 | + /** |
|
| 300 | + * Get the inital price of the item. |
|
| 301 | + * |
|
| 302 | + * @since 1.0.19 |
|
| 303 | + * @param string $context View or edit context. |
|
| 304 | + * @return float |
|
| 305 | + */ |
|
| 306 | + public function get_initial_price( $context = 'view' ) { |
|
| 307 | 307 | |
| 308 | - $price = (float) $this->get_price( $context ); |
|
| 308 | + $price = (float) $this->get_price( $context ); |
|
| 309 | 309 | |
| 310 | - if ( $this->has_free_trial() ) { |
|
| 311 | - $price = 0; |
|
| 312 | - } |
|
| 310 | + if ( $this->has_free_trial() ) { |
|
| 311 | + $price = 0; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | - * Returns a formated price. |
|
| 319 | - * |
|
| 320 | - * @since 1.0.19 |
|
| 321 | - * @param string $context View or edit context. |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 318 | + * Returns a formated price. |
|
| 319 | + * |
|
| 320 | + * @since 1.0.19 |
|
| 321 | + * @param string $context View or edit context. |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | 324 | public function get_the_price() { |
| 325 | 325 | return wpinv_price( $this->get_price() ); |
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Returns the formated initial price. |
|
| 330 | - * |
|
| 331 | - * @since 1.0.19 |
|
| 332 | - * @param string $context View or edit context. |
|
| 333 | - * @return string |
|
| 334 | - */ |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Returns the formated initial price. |
|
| 330 | + * |
|
| 331 | + * @since 1.0.19 |
|
| 332 | + * @param string $context View or edit context. |
|
| 333 | + * @return string |
|
| 334 | + */ |
|
| 335 | 335 | public function get_the_initial_price() { |
| 336 | 336 | return wpinv_price( $this->get_initial_price() ); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | - * Get the VAT rule of the item. |
|
| 341 | - * |
|
| 342 | - * @since 1.0.19 |
|
| 343 | - * @param string $context View or edit context. |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function get_vat_rule( $context = 'view' ) { |
|
| 340 | + * Get the VAT rule of the item. |
|
| 341 | + * |
|
| 342 | + * @since 1.0.19 |
|
| 343 | + * @param string $context View or edit context. |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function get_vat_rule( $context = 'view' ) { |
|
| 347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | - * Get the VAT class of the item. |
|
| 352 | - * |
|
| 353 | - * @since 1.0.19 |
|
| 354 | - * @param string $context View or edit context. |
|
| 355 | - * @return string |
|
| 356 | - */ |
|
| 357 | - public function get_vat_class( $context = 'view' ) { |
|
| 351 | + * Get the VAT class of the item. |
|
| 352 | + * |
|
| 353 | + * @since 1.0.19 |
|
| 354 | + * @param string $context View or edit context. |
|
| 355 | + * @return string |
|
| 356 | + */ |
|
| 357 | + public function get_vat_class( $context = 'view' ) { |
|
| 358 | 358 | return $this->get_prop( 'vat_class', $context ); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | - * Get the type of the item. |
|
| 363 | - * |
|
| 364 | - * @since 1.0.19 |
|
| 365 | - * @param string $context View or edit context. |
|
| 366 | - * @return string |
|
| 367 | - */ |
|
| 368 | - public function get_type( $context = 'view' ) { |
|
| 362 | + * Get the type of the item. |
|
| 363 | + * |
|
| 364 | + * @since 1.0.19 |
|
| 365 | + * @param string $context View or edit context. |
|
| 366 | + * @return string |
|
| 367 | + */ |
|
| 368 | + public function get_type( $context = 'view' ) { |
|
| 369 | 369 | return $this->get_prop( 'type', $context ); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Get the custom id of the item. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $context View or edit context. |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_custom_id( $context = 'view' ) { |
|
| 373 | + * Get the custom id of the item. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $context View or edit context. |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_custom_id( $context = 'view' ) { |
|
| 380 | 380 | return $this->get_prop( 'custom_id', $context ); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
| 384 | - * Get the custom name of the item. |
|
| 385 | - * |
|
| 386 | - * @since 1.0.19 |
|
| 387 | - * @param string $context View or edit context. |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public function get_custom_name( $context = 'view' ) { |
|
| 384 | + * Get the custom name of the item. |
|
| 385 | + * |
|
| 386 | + * @since 1.0.19 |
|
| 387 | + * @param string $context View or edit context. |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public function get_custom_name( $context = 'view' ) { |
|
| 391 | 391 | return $this->get_prop( 'custom_name', $context ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
| 395 | - * Get the custom singular name of the item. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.19 |
|
| 398 | - * @param string $context View or edit context. |
|
| 399 | - * @return string |
|
| 400 | - */ |
|
| 401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 395 | + * Get the custom singular name of the item. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.19 |
|
| 398 | + * @param string $context View or edit context. |
|
| 399 | + * @return string |
|
| 400 | + */ |
|
| 401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
| 402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
| 406 | - * Checks if an item is editable.. |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - * @param string $context View or edit context. |
|
| 410 | - * @return int |
|
| 411 | - */ |
|
| 412 | - public function get_is_editable( $context = 'view' ) { |
|
| 406 | + * Checks if an item is editable.. |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + * @param string $context View or edit context. |
|
| 410 | + * @return int |
|
| 411 | + */ |
|
| 412 | + public function get_is_editable( $context = 'view' ) { |
|
| 413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
| 417 | - * Alias of self::get_is_editable(). |
|
| 418 | - * |
|
| 419 | - * @since 1.0.19 |
|
| 420 | - * @param string $context View or edit context. |
|
| 421 | - * @return int |
|
| 422 | - */ |
|
| 423 | - public function get_editable( $context = 'view' ) { |
|
| 424 | - return $this->get_is_editable( $context ); |
|
| 417 | + * Alias of self::get_is_editable(). |
|
| 418 | + * |
|
| 419 | + * @since 1.0.19 |
|
| 420 | + * @param string $context View or edit context. |
|
| 421 | + * @return int |
|
| 422 | + */ |
|
| 423 | + public function get_editable( $context = 'view' ) { |
|
| 424 | + return $this->get_is_editable( $context ); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * Checks if dynamic pricing is enabled. |
|
| 429 | - * |
|
| 430 | - * @since 1.0.19 |
|
| 431 | - * @param string $context View or edit context. |
|
| 432 | - * @return int |
|
| 433 | - */ |
|
| 434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 428 | + * Checks if dynamic pricing is enabled. |
|
| 429 | + * |
|
| 430 | + * @since 1.0.19 |
|
| 431 | + * @param string $context View or edit context. |
|
| 432 | + * @return int |
|
| 433 | + */ |
|
| 434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | - * |
|
| 441 | - * @since 1.0.19 |
|
| 442 | - * @param string $context View or edit context. |
|
| 443 | - * @return float |
|
| 444 | - */ |
|
| 445 | - public function get_minimum_price( $context = 'view' ) { |
|
| 439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | + * |
|
| 441 | + * @since 1.0.19 |
|
| 442 | + * @param string $context View or edit context. |
|
| 443 | + * @return float |
|
| 444 | + */ |
|
| 445 | + public function get_minimum_price( $context = 'view' ) { |
|
| 446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
| 450 | - * Checks if this is a recurring item. |
|
| 451 | - * |
|
| 452 | - * @since 1.0.19 |
|
| 453 | - * @param string $context View or edit context. |
|
| 454 | - * @return int |
|
| 455 | - */ |
|
| 456 | - public function get_is_recurring( $context = 'view' ) { |
|
| 450 | + * Checks if this is a recurring item. |
|
| 451 | + * |
|
| 452 | + * @since 1.0.19 |
|
| 453 | + * @param string $context View or edit context. |
|
| 454 | + * @return int |
|
| 455 | + */ |
|
| 456 | + public function get_is_recurring( $context = 'view' ) { |
|
| 457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - /** |
|
| 461 | - * Get the recurring price of the item. |
|
| 462 | - * |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - * @param string $context View or edit context. |
|
| 465 | - * @return float |
|
| 466 | - */ |
|
| 467 | - public function get_recurring_price( $context = 'view' ) { |
|
| 468 | - $price = $this->get_price( $context ); |
|
| 460 | + /** |
|
| 461 | + * Get the recurring price of the item. |
|
| 462 | + * |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + * @param string $context View or edit context. |
|
| 465 | + * @return float |
|
| 466 | + */ |
|
| 467 | + public function get_recurring_price( $context = 'view' ) { |
|
| 468 | + $price = $this->get_price( $context ); |
|
| 469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Get the formatted recurring price of the item. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - * @param string $context View or edit context. |
|
| 477 | - * @return string |
|
| 478 | - */ |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Get the formatted recurring price of the item. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + * @param string $context View or edit context. |
|
| 477 | + * @return string |
|
| 478 | + */ |
|
| 479 | 479 | public function get_the_recurring_price() { |
| 480 | 480 | return wpinv_price( $this->get_recurring_price() ); |
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Get the first renewal date (in timestamps) of the item. |
|
| 485 | - * |
|
| 486 | - * @since 1.0.19 |
|
| 487 | - * @return int |
|
| 488 | - */ |
|
| 489 | - public function get_first_renewal_date() { |
|
| 490 | - |
|
| 491 | - $periods = array( |
|
| 492 | - 'D' => 'days', |
|
| 493 | - 'W' => 'weeks', |
|
| 494 | - 'M' => 'months', |
|
| 495 | - 'Y' => 'years', |
|
| 496 | - ); |
|
| 497 | - |
|
| 498 | - $period = $this->get_recurring_period(); |
|
| 499 | - $interval = $this->get_recurring_interval(); |
|
| 500 | - |
|
| 501 | - if ( $this->has_free_trial() ) { |
|
| 502 | - $period = $this->get_trial_period(); |
|
| 503 | - $interval = $this->get_trial_interval(); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $period = $periods[ $period ]; |
|
| 507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Get the first renewal date (in timestamps) of the item. |
|
| 485 | + * |
|
| 486 | + * @since 1.0.19 |
|
| 487 | + * @return int |
|
| 488 | + */ |
|
| 489 | + public function get_first_renewal_date() { |
|
| 490 | + |
|
| 491 | + $periods = array( |
|
| 492 | + 'D' => 'days', |
|
| 493 | + 'W' => 'weeks', |
|
| 494 | + 'M' => 'months', |
|
| 495 | + 'Y' => 'years', |
|
| 496 | + ); |
|
| 497 | + |
|
| 498 | + $period = $this->get_recurring_period(); |
|
| 499 | + $interval = $this->get_recurring_interval(); |
|
| 500 | + |
|
| 501 | + if ( $this->has_free_trial() ) { |
|
| 502 | + $period = $this->get_trial_period(); |
|
| 503 | + $interval = $this->get_trial_interval(); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $period = $periods[ $period ]; |
|
| 507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
| 513 | - * Get the recurring period. |
|
| 514 | - * |
|
| 515 | - * @since 1.0.19 |
|
| 516 | - * @param bool $full Return abbreviation or in full. |
|
| 517 | - * @return string |
|
| 518 | - */ |
|
| 519 | - public function get_recurring_period( $full = false ) { |
|
| 513 | + * Get the recurring period. |
|
| 514 | + * |
|
| 515 | + * @since 1.0.19 |
|
| 516 | + * @param bool $full Return abbreviation or in full. |
|
| 517 | + * @return string |
|
| 518 | + */ |
|
| 519 | + public function get_recurring_period( $full = false ) { |
|
| 520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
| 521 | 521 | |
| 522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,58 +527,58 @@ discard block |
||
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
| 530 | - * Get the recurring interval. |
|
| 531 | - * |
|
| 532 | - * @since 1.0.19 |
|
| 533 | - * @param string $context View or edit context. |
|
| 534 | - * @return int |
|
| 535 | - */ |
|
| 536 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 538 | - return max( 1, $interval ); |
|
| 530 | + * Get the recurring interval. |
|
| 531 | + * |
|
| 532 | + * @since 1.0.19 |
|
| 533 | + * @param string $context View or edit context. |
|
| 534 | + * @return int |
|
| 535 | + */ |
|
| 536 | + public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 538 | + return max( 1, $interval ); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
| 542 | - * Get the recurring limit. |
|
| 543 | - * |
|
| 544 | - * @since 1.0.19 |
|
| 545 | - * @param string $context View or edit context. |
|
| 546 | - * @return int |
|
| 547 | - */ |
|
| 548 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 542 | + * Get the recurring limit. |
|
| 543 | + * |
|
| 544 | + * @since 1.0.19 |
|
| 545 | + * @param string $context View or edit context. |
|
| 546 | + * @return int |
|
| 547 | + */ |
|
| 548 | + public function get_recurring_limit( $context = 'view' ) { |
|
| 549 | 549 | return (int) $this->get_prop( 'recurring_limit', $context ); |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
| 553 | - * Checks if we have a free trial. |
|
| 554 | - * |
|
| 555 | - * @since 1.0.19 |
|
| 556 | - * @param string $context View or edit context. |
|
| 557 | - * @return int |
|
| 558 | - */ |
|
| 559 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 553 | + * Checks if we have a free trial. |
|
| 554 | + * |
|
| 555 | + * @since 1.0.19 |
|
| 556 | + * @param string $context View or edit context. |
|
| 557 | + * @return int |
|
| 558 | + */ |
|
| 559 | + public function get_is_free_trial( $context = 'view' ) { |
|
| 560 | 560 | return (int) $this->get_prop( 'is_free_trial', $context ); |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
| 564 | - * Alias for self::get_is_free_trial(). |
|
| 565 | - * |
|
| 566 | - * @since 1.0.19 |
|
| 567 | - * @param string $context View or edit context. |
|
| 568 | - * @return int |
|
| 569 | - */ |
|
| 570 | - public function get_free_trial( $context = 'view' ) { |
|
| 564 | + * Alias for self::get_is_free_trial(). |
|
| 565 | + * |
|
| 566 | + * @since 1.0.19 |
|
| 567 | + * @param string $context View or edit context. |
|
| 568 | + * @return int |
|
| 569 | + */ |
|
| 570 | + public function get_free_trial( $context = 'view' ) { |
|
| 571 | 571 | return $this->get_is_free_trial( $context ); |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
| 575 | - * Get the trial period. |
|
| 576 | - * |
|
| 577 | - * @since 1.0.19 |
|
| 578 | - * @param bool $full Return abbreviation or in full. |
|
| 579 | - * @return string |
|
| 580 | - */ |
|
| 581 | - public function get_trial_period( $full = false ) { |
|
| 575 | + * Get the trial period. |
|
| 576 | + * |
|
| 577 | + * @since 1.0.19 |
|
| 578 | + * @param bool $full Return abbreviation or in full. |
|
| 579 | + * @return string |
|
| 580 | + */ |
|
| 581 | + public function get_trial_period( $full = false ) { |
|
| 582 | 582 | $period = $this->get_prop( 'trial_period', 'view' ); |
| 583 | 583 | |
| 584 | 584 | if ( $full && ! is_bool( $full ) ) { |
@@ -589,104 +589,104 @@ discard block |
||
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
| 592 | - * Get the trial interval. |
|
| 593 | - * |
|
| 594 | - * @since 1.0.19 |
|
| 595 | - * @param string $context View or edit context. |
|
| 596 | - * @return int |
|
| 597 | - */ |
|
| 598 | - public function get_trial_interval( $context = 'view' ) { |
|
| 592 | + * Get the trial interval. |
|
| 593 | + * |
|
| 594 | + * @since 1.0.19 |
|
| 595 | + * @param string $context View or edit context. |
|
| 596 | + * @return int |
|
| 597 | + */ |
|
| 598 | + public function get_trial_interval( $context = 'view' ) { |
|
| 599 | 599 | return (int) $this->get_prop( 'trial_interval', $context ); |
| 600 | - } |
|
| 600 | + } |
|
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * Get the item's edit url. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - * @return string |
|
| 607 | - */ |
|
| 608 | - public function get_edit_url() { |
|
| 602 | + /** |
|
| 603 | + * Get the item's edit url. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + * @return string |
|
| 607 | + */ |
|
| 608 | + public function get_edit_url() { |
|
| 609 | 609 | return get_edit_post_link( $this->get_id(), 'edit' ); |
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * Given an item's name/custom id, it returns its id. |
|
| 614 | - * |
|
| 615 | - * |
|
| 616 | - * @static |
|
| 617 | - * @param string $value The item name or custom id. |
|
| 618 | - * @param string $field Either name or custom_id. |
|
| 619 | - * @param string $type in case you need to search for a given type. |
|
| 620 | - * @since 1.0.15 |
|
| 621 | - * @return int |
|
| 622 | - */ |
|
| 623 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 624 | - |
|
| 625 | - // Trim the value. |
|
| 626 | - $value = sanitize_text_field( $value ); |
|
| 627 | - if ( empty( $value ) ) { |
|
| 628 | - return 0; |
|
| 629 | - } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * Given an item's name/custom id, it returns its id. |
|
| 614 | + * |
|
| 615 | + * |
|
| 616 | + * @static |
|
| 617 | + * @param string $value The item name or custom id. |
|
| 618 | + * @param string $field Either name or custom_id. |
|
| 619 | + * @param string $type in case you need to search for a given type. |
|
| 620 | + * @since 1.0.15 |
|
| 621 | + * @return int |
|
| 622 | + */ |
|
| 623 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 624 | + |
|
| 625 | + // Trim the value. |
|
| 626 | + $value = sanitize_text_field( $value ); |
|
| 627 | + if ( empty( $value ) ) { |
|
| 628 | + return 0; |
|
| 629 | + } |
|
| 630 | 630 | |
| 631 | 631 | // Valid fields. |
| 632 | 632 | $fields = array( 'custom_id', 'name', 'slug' ); |
| 633 | 633 | |
| 634 | - // Ensure a field has been passed. |
|
| 635 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 636 | - return 0; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - if ( $field == 'name' ) { |
|
| 640 | - $field = 'slug'; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - // Maybe retrieve from the cache. |
|
| 644 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 645 | - if ( ! empty( $item_id ) ) { |
|
| 646 | - return $item_id; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - // Fetch from the db. |
|
| 650 | - $items = array(); |
|
| 651 | - if ( $field == 'slug' ) { |
|
| 652 | - $items = get_posts( |
|
| 653 | - array( |
|
| 654 | - 'post_type' => 'wpi_item', |
|
| 655 | - 'name' => $value, |
|
| 656 | - 'posts_per_page' => 1, |
|
| 657 | - 'post_status' => 'any', |
|
| 658 | - ) |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - if ( $field =='custom_id' ) { |
|
| 663 | - $items = get_posts( |
|
| 664 | - array( |
|
| 665 | - 'post_type' => 'wpi_item', |
|
| 666 | - 'posts_per_page' => 1, |
|
| 667 | - 'post_status' => 'any', |
|
| 668 | - 'meta_query' => array( |
|
| 669 | - array( |
|
| 670 | - 'key' => '_wpinv_type', |
|
| 671 | - 'value' => $type, |
|
| 672 | - ), |
|
| 673 | - array( |
|
| 674 | - 'key' => '_wpinv_custom_id', |
|
| 675 | - 'value' => $value, |
|
| 676 | - ) |
|
| 677 | - ) |
|
| 678 | - ) |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - if ( empty( $items ) ) { |
|
| 683 | - return 0; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - // Update the cache with our data |
|
| 687 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 688 | - |
|
| 689 | - return $items[0]->ID; |
|
| 634 | + // Ensure a field has been passed. |
|
| 635 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 636 | + return 0; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + if ( $field == 'name' ) { |
|
| 640 | + $field = 'slug'; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + // Maybe retrieve from the cache. |
|
| 644 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 645 | + if ( ! empty( $item_id ) ) { |
|
| 646 | + return $item_id; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + // Fetch from the db. |
|
| 650 | + $items = array(); |
|
| 651 | + if ( $field == 'slug' ) { |
|
| 652 | + $items = get_posts( |
|
| 653 | + array( |
|
| 654 | + 'post_type' => 'wpi_item', |
|
| 655 | + 'name' => $value, |
|
| 656 | + 'posts_per_page' => 1, |
|
| 657 | + 'post_status' => 'any', |
|
| 658 | + ) |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + if ( $field =='custom_id' ) { |
|
| 663 | + $items = get_posts( |
|
| 664 | + array( |
|
| 665 | + 'post_type' => 'wpi_item', |
|
| 666 | + 'posts_per_page' => 1, |
|
| 667 | + 'post_status' => 'any', |
|
| 668 | + 'meta_query' => array( |
|
| 669 | + array( |
|
| 670 | + 'key' => '_wpinv_type', |
|
| 671 | + 'value' => $type, |
|
| 672 | + ), |
|
| 673 | + array( |
|
| 674 | + 'key' => '_wpinv_custom_id', |
|
| 675 | + 'value' => $value, |
|
| 676 | + ) |
|
| 677 | + ) |
|
| 678 | + ) |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + if ( empty( $items ) ) { |
|
| 683 | + return 0; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + // Update the cache with our data |
|
| 687 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 688 | + |
|
| 689 | + return $items[0]->ID; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -719,52 +719,52 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | |
| 721 | 721 | /** |
| 722 | - * Set parent order ID. |
|
| 723 | - * |
|
| 724 | - * @since 1.0.19 |
|
| 725 | - */ |
|
| 726 | - public function set_parent_id( $value ) { |
|
| 727 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 728 | - return; |
|
| 729 | - } |
|
| 730 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * Sets item status. |
|
| 735 | - * |
|
| 736 | - * @since 1.0.19 |
|
| 737 | - * @param string $status New status. |
|
| 738 | - * @return array details of change. |
|
| 739 | - */ |
|
| 740 | - public function set_status( $status ) { |
|
| 722 | + * Set parent order ID. |
|
| 723 | + * |
|
| 724 | + * @since 1.0.19 |
|
| 725 | + */ |
|
| 726 | + public function set_parent_id( $value ) { |
|
| 727 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 728 | + return; |
|
| 729 | + } |
|
| 730 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * Sets item status. |
|
| 735 | + * |
|
| 736 | + * @since 1.0.19 |
|
| 737 | + * @param string $status New status. |
|
| 738 | + * @return array details of change. |
|
| 739 | + */ |
|
| 740 | + public function set_status( $status ) { |
|
| 741 | 741 | $old_status = $this->get_status(); |
| 742 | 742 | |
| 743 | 743 | $this->set_prop( 'status', $status ); |
| 744 | 744 | |
| 745 | - return array( |
|
| 746 | - 'from' => $old_status, |
|
| 747 | - 'to' => $status, |
|
| 748 | - ); |
|
| 745 | + return array( |
|
| 746 | + 'from' => $old_status, |
|
| 747 | + 'to' => $status, |
|
| 748 | + ); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
| 752 | - * Set plugin version when the item was created. |
|
| 753 | - * |
|
| 754 | - * @since 1.0.19 |
|
| 755 | - */ |
|
| 756 | - public function set_version( $value ) { |
|
| 757 | - $this->set_prop( 'version', $value ); |
|
| 752 | + * Set plugin version when the item was created. |
|
| 753 | + * |
|
| 754 | + * @since 1.0.19 |
|
| 755 | + */ |
|
| 756 | + public function set_version( $value ) { |
|
| 757 | + $this->set_prop( 'version', $value ); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
| 761 | - * Set date when the item was created. |
|
| 762 | - * |
|
| 763 | - * @since 1.0.19 |
|
| 764 | - * @param string $value Value to set. |
|
| 761 | + * Set date when the item was created. |
|
| 762 | + * |
|
| 763 | + * @since 1.0.19 |
|
| 764 | + * @param string $value Value to set. |
|
| 765 | 765 | * @return bool Whether or not the date was set. |
| 766 | - */ |
|
| 767 | - public function set_date_created( $value ) { |
|
| 766 | + */ |
|
| 767 | + public function set_date_created( $value ) { |
|
| 768 | 768 | $date = strtotime( $value ); |
| 769 | 769 | |
| 770 | 770 | if ( $date ) { |
@@ -777,13 +777,13 @@ discard block |
||
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
| 780 | - * Set date when the item was last modified. |
|
| 781 | - * |
|
| 782 | - * @since 1.0.19 |
|
| 783 | - * @param string $value Value to set. |
|
| 780 | + * Set date when the item was last modified. |
|
| 781 | + * |
|
| 782 | + * @since 1.0.19 |
|
| 783 | + * @param string $value Value to set. |
|
| 784 | 784 | * @return bool Whether or not the date was set. |
| 785 | - */ |
|
| 786 | - public function set_date_modified( $value ) { |
|
| 785 | + */ |
|
| 786 | + public function set_date_modified( $value ) { |
|
| 787 | 787 | $date = strtotime( $value ); |
| 788 | 788 | |
| 789 | 789 | if ( $date ) { |
@@ -796,115 +796,115 @@ discard block |
||
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
| 799 | - * Set the item name. |
|
| 800 | - * |
|
| 801 | - * @since 1.0.19 |
|
| 802 | - * @param string $value New name. |
|
| 803 | - */ |
|
| 804 | - public function set_name( $value ) { |
|
| 799 | + * Set the item name. |
|
| 800 | + * |
|
| 801 | + * @since 1.0.19 |
|
| 802 | + * @param string $value New name. |
|
| 803 | + */ |
|
| 804 | + public function set_name( $value ) { |
|
| 805 | 805 | $name = sanitize_text_field( $value ); |
| 806 | - $this->set_prop( 'name', $name ); |
|
| 806 | + $this->set_prop( 'name', $name ); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
| 810 | - * Alias of self::set_name(). |
|
| 811 | - * |
|
| 812 | - * @since 1.0.19 |
|
| 813 | - * @param string $value New name. |
|
| 814 | - */ |
|
| 815 | - public function set_title( $value ) { |
|
| 816 | - $this->set_name( $value ); |
|
| 810 | + * Alias of self::set_name(). |
|
| 811 | + * |
|
| 812 | + * @since 1.0.19 |
|
| 813 | + * @param string $value New name. |
|
| 814 | + */ |
|
| 815 | + public function set_title( $value ) { |
|
| 816 | + $this->set_name( $value ); |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | /** |
| 820 | - * Set the item description. |
|
| 821 | - * |
|
| 822 | - * @since 1.0.19 |
|
| 823 | - * @param string $value New description. |
|
| 824 | - */ |
|
| 825 | - public function set_description( $value ) { |
|
| 826 | - $description = wp_kses_post( $value ); |
|
| 827 | - return $this->set_prop( 'description', $description ); |
|
| 820 | + * Set the item description. |
|
| 821 | + * |
|
| 822 | + * @since 1.0.19 |
|
| 823 | + * @param string $value New description. |
|
| 824 | + */ |
|
| 825 | + public function set_description( $value ) { |
|
| 826 | + $description = wp_kses_post( $value ); |
|
| 827 | + return $this->set_prop( 'description', $description ); |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
| 831 | - * Alias of self::set_description(). |
|
| 832 | - * |
|
| 833 | - * @since 1.0.19 |
|
| 834 | - * @param string $value New description. |
|
| 835 | - */ |
|
| 836 | - public function set_excerpt( $value ) { |
|
| 837 | - $this->set_description( $value ); |
|
| 831 | + * Alias of self::set_description(). |
|
| 832 | + * |
|
| 833 | + * @since 1.0.19 |
|
| 834 | + * @param string $value New description. |
|
| 835 | + */ |
|
| 836 | + public function set_excerpt( $value ) { |
|
| 837 | + $this->set_description( $value ); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
| 841 | - * Alias of self::set_description(). |
|
| 842 | - * |
|
| 843 | - * @since 1.0.19 |
|
| 844 | - * @param string $value New description. |
|
| 845 | - */ |
|
| 846 | - public function set_summary( $value ) { |
|
| 847 | - $this->set_description( $value ); |
|
| 841 | + * Alias of self::set_description(). |
|
| 842 | + * |
|
| 843 | + * @since 1.0.19 |
|
| 844 | + * @param string $value New description. |
|
| 845 | + */ |
|
| 846 | + public function set_summary( $value ) { |
|
| 847 | + $this->set_description( $value ); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | /** |
| 851 | - * Set the owner of the item. |
|
| 852 | - * |
|
| 853 | - * @since 1.0.19 |
|
| 854 | - * @param int $value New author. |
|
| 855 | - */ |
|
| 856 | - public function set_author( $value ) { |
|
| 857 | - $this->set_prop( 'author', (int) $value ); |
|
| 858 | - } |
|
| 851 | + * Set the owner of the item. |
|
| 852 | + * |
|
| 853 | + * @since 1.0.19 |
|
| 854 | + * @param int $value New author. |
|
| 855 | + */ |
|
| 856 | + public function set_author( $value ) { |
|
| 857 | + $this->set_prop( 'author', (int) $value ); |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - /** |
|
| 861 | - * Alias of self::set_author(). |
|
| 862 | - * |
|
| 863 | - * @since 1.0.19 |
|
| 864 | - * @param int $value New author. |
|
| 865 | - */ |
|
| 866 | - public function set_owner( $value ) { |
|
| 867 | - $this->set_author( $value ); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Set the price of the item. |
|
| 872 | - * |
|
| 873 | - * @since 1.0.19 |
|
| 874 | - * @param float $value New price. |
|
| 875 | - */ |
|
| 876 | - public function set_price( $value ) { |
|
| 860 | + /** |
|
| 861 | + * Alias of self::set_author(). |
|
| 862 | + * |
|
| 863 | + * @since 1.0.19 |
|
| 864 | + * @param int $value New author. |
|
| 865 | + */ |
|
| 866 | + public function set_owner( $value ) { |
|
| 867 | + $this->set_author( $value ); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Set the price of the item. |
|
| 872 | + * |
|
| 873 | + * @since 1.0.19 |
|
| 874 | + * @param float $value New price. |
|
| 875 | + */ |
|
| 876 | + public function set_price( $value ) { |
|
| 877 | 877 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
| 881 | - * Set the VAT rule of the item. |
|
| 882 | - * |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - * @param string $value new rule. |
|
| 885 | - */ |
|
| 886 | - public function set_vat_rule( $value ) { |
|
| 881 | + * Set the VAT rule of the item. |
|
| 882 | + * |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + * @param string $value new rule. |
|
| 885 | + */ |
|
| 886 | + public function set_vat_rule( $value ) { |
|
| 887 | 887 | $this->set_prop( 'vat_rule', $value ); |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
| 891 | - * Set the VAT class of the item. |
|
| 892 | - * |
|
| 893 | - * @since 1.0.19 |
|
| 894 | - * @param string $value new class. |
|
| 895 | - */ |
|
| 896 | - public function set_vat_class( $value ) { |
|
| 891 | + * Set the VAT class of the item. |
|
| 892 | + * |
|
| 893 | + * @since 1.0.19 |
|
| 894 | + * @param string $value new class. |
|
| 895 | + */ |
|
| 896 | + public function set_vat_class( $value ) { |
|
| 897 | 897 | $this->set_prop( 'vat_class', $value ); |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
| 901 | - * Set the type of the item. |
|
| 902 | - * |
|
| 903 | - * @since 1.0.19 |
|
| 904 | - * @param string $value new item type. |
|
| 905 | - * @return string |
|
| 906 | - */ |
|
| 907 | - public function set_type( $value ) { |
|
| 901 | + * Set the type of the item. |
|
| 902 | + * |
|
| 903 | + * @since 1.0.19 |
|
| 904 | + * @param string $value new item type. |
|
| 905 | + * @return string |
|
| 906 | + */ |
|
| 907 | + public function set_type( $value ) { |
|
| 908 | 908 | |
| 909 | 909 | if ( empty( $value ) ) { |
| 910 | 910 | $value = 'custom'; |
@@ -914,132 +914,132 @@ discard block |
||
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
| 917 | - * Set the custom id of the item. |
|
| 918 | - * |
|
| 919 | - * @since 1.0.19 |
|
| 920 | - * @param string $value new custom id. |
|
| 921 | - */ |
|
| 922 | - public function set_custom_id( $value ) { |
|
| 917 | + * Set the custom id of the item. |
|
| 918 | + * |
|
| 919 | + * @since 1.0.19 |
|
| 920 | + * @param string $value new custom id. |
|
| 921 | + */ |
|
| 922 | + public function set_custom_id( $value ) { |
|
| 923 | 923 | $this->set_prop( 'custom_id', $value ); |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | /** |
| 927 | - * Set the custom name of the item. |
|
| 928 | - * |
|
| 929 | - * @since 1.0.19 |
|
| 930 | - * @param string $value new custom name. |
|
| 931 | - */ |
|
| 932 | - public function set_custom_name( $value ) { |
|
| 927 | + * Set the custom name of the item. |
|
| 928 | + * |
|
| 929 | + * @since 1.0.19 |
|
| 930 | + * @param string $value new custom name. |
|
| 931 | + */ |
|
| 932 | + public function set_custom_name( $value ) { |
|
| 933 | 933 | $this->set_prop( 'custom_name', $value ); |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
| 937 | - * Set the custom singular name of the item. |
|
| 938 | - * |
|
| 939 | - * @since 1.0.19 |
|
| 940 | - * @param string $value new custom singular name. |
|
| 941 | - */ |
|
| 942 | - public function set_custom_singular_name( $value ) { |
|
| 937 | + * Set the custom singular name of the item. |
|
| 938 | + * |
|
| 939 | + * @since 1.0.19 |
|
| 940 | + * @param string $value new custom singular name. |
|
| 941 | + */ |
|
| 942 | + public function set_custom_singular_name( $value ) { |
|
| 943 | 943 | $this->set_prop( 'custom_singular_name', $value ); |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | /** |
| 947 | - * Sets if an item is editable.. |
|
| 948 | - * |
|
| 949 | - * @since 1.0.19 |
|
| 950 | - * @param int|bool $value whether or not the item is editable. |
|
| 951 | - */ |
|
| 952 | - public function set_is_editable( $value ) { |
|
| 953 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 947 | + * Sets if an item is editable.. |
|
| 948 | + * |
|
| 949 | + * @since 1.0.19 |
|
| 950 | + * @param int|bool $value whether or not the item is editable. |
|
| 951 | + */ |
|
| 952 | + public function set_is_editable( $value ) { |
|
| 953 | + $this->set_prop( 'is_editable', (int) $value ); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
| 957 | - * Sets if dynamic pricing is enabled. |
|
| 958 | - * |
|
| 959 | - * @since 1.0.19 |
|
| 960 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 961 | - */ |
|
| 962 | - public function set_is_dynamic_pricing( $value ) { |
|
| 957 | + * Sets if dynamic pricing is enabled. |
|
| 958 | + * |
|
| 959 | + * @since 1.0.19 |
|
| 960 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 961 | + */ |
|
| 962 | + public function set_is_dynamic_pricing( $value ) { |
|
| 963 | 963 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
| 967 | - * Sets the minimum price if dynamic pricing is enabled. |
|
| 968 | - * |
|
| 969 | - * @since 1.0.19 |
|
| 970 | - * @param float $value minimum price. |
|
| 971 | - */ |
|
| 972 | - public function set_minimum_price( $value ) { |
|
| 967 | + * Sets the minimum price if dynamic pricing is enabled. |
|
| 968 | + * |
|
| 969 | + * @since 1.0.19 |
|
| 970 | + * @param float $value minimum price. |
|
| 971 | + */ |
|
| 972 | + public function set_minimum_price( $value ) { |
|
| 973 | 973 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
| 977 | - * Sets if this is a recurring item. |
|
| 978 | - * |
|
| 979 | - * @since 1.0.19 |
|
| 980 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 981 | - */ |
|
| 982 | - public function set_is_recurring( $value ) { |
|
| 977 | + * Sets if this is a recurring item. |
|
| 978 | + * |
|
| 979 | + * @since 1.0.19 |
|
| 980 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 981 | + */ |
|
| 982 | + public function set_is_recurring( $value ) { |
|
| 983 | 983 | $this->set_prop( 'is_recurring', (int) $value ); |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | /** |
| 987 | - * Set the recurring period. |
|
| 988 | - * |
|
| 989 | - * @since 1.0.19 |
|
| 990 | - * @param string $value new period. |
|
| 991 | - */ |
|
| 992 | - public function set_recurring_period( $value ) { |
|
| 987 | + * Set the recurring period. |
|
| 988 | + * |
|
| 989 | + * @since 1.0.19 |
|
| 990 | + * @param string $value new period. |
|
| 991 | + */ |
|
| 992 | + public function set_recurring_period( $value ) { |
|
| 993 | 993 | $this->set_prop( 'recurring_period', $value ); |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | /** |
| 997 | - * Set the recurring interval. |
|
| 998 | - * |
|
| 999 | - * @since 1.0.19 |
|
| 1000 | - * @param int $value recurring interval. |
|
| 1001 | - */ |
|
| 1002 | - public function set_recurring_interval( $value ) { |
|
| 997 | + * Set the recurring interval. |
|
| 998 | + * |
|
| 999 | + * @since 1.0.19 |
|
| 1000 | + * @param int $value recurring interval. |
|
| 1001 | + */ |
|
| 1002 | + public function set_recurring_interval( $value ) { |
|
| 1003 | 1003 | return $this->set_prop( 'recurring_interval', (int) $value ); |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | /** |
| 1007 | - * Get the recurring limit. |
|
| 1008 | - * @since 1.0.19 |
|
| 1009 | - * @param int $value The recurring limit. |
|
| 1010 | - * @return int |
|
| 1011 | - */ |
|
| 1012 | - public function set_recurring_limit( $value ) { |
|
| 1007 | + * Get the recurring limit. |
|
| 1008 | + * @since 1.0.19 |
|
| 1009 | + * @param int $value The recurring limit. |
|
| 1010 | + * @return int |
|
| 1011 | + */ |
|
| 1012 | + public function set_recurring_limit( $value ) { |
|
| 1013 | 1013 | $this->set_prop( 'recurring_limit', (int) $value ); |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | /** |
| 1017 | - * Checks if we have a free trial. |
|
| 1018 | - * |
|
| 1019 | - * @since 1.0.19 |
|
| 1020 | - * @param int|bool $value whether or not it has a free trial. |
|
| 1021 | - */ |
|
| 1022 | - public function set_is_free_trial( $value ) { |
|
| 1017 | + * Checks if we have a free trial. |
|
| 1018 | + * |
|
| 1019 | + * @since 1.0.19 |
|
| 1020 | + * @param int|bool $value whether or not it has a free trial. |
|
| 1021 | + */ |
|
| 1022 | + public function set_is_free_trial( $value ) { |
|
| 1023 | 1023 | $this->set_prop( 'is_free_trial', (int) $value ); |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
| 1027 | - * Set the trial period. |
|
| 1028 | - * |
|
| 1029 | - * @since 1.0.19 |
|
| 1030 | - * @param string $value trial period. |
|
| 1031 | - */ |
|
| 1032 | - public function set_trial_period( $value ) { |
|
| 1027 | + * Set the trial period. |
|
| 1028 | + * |
|
| 1029 | + * @since 1.0.19 |
|
| 1030 | + * @param string $value trial period. |
|
| 1031 | + */ |
|
| 1032 | + public function set_trial_period( $value ) { |
|
| 1033 | 1033 | $this->set_prop( 'trial_period', $value ); |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /** |
| 1037 | - * Set the trial interval. |
|
| 1038 | - * |
|
| 1039 | - * @since 1.0.19 |
|
| 1040 | - * @param int $value trial interval. |
|
| 1041 | - */ |
|
| 1042 | - public function set_trial_interval( $value ) { |
|
| 1037 | + * Set the trial interval. |
|
| 1038 | + * |
|
| 1039 | + * @since 1.0.19 |
|
| 1040 | + * @param int $value trial interval. |
|
| 1041 | + */ |
|
| 1042 | + public function set_trial_interval( $value ) { |
|
| 1043 | 1043 | $this->set_prop( 'trial_interval', $value ); |
| 1044 | 1044 | } |
| 1045 | 1045 | |
@@ -1047,17 +1047,17 @@ discard block |
||
| 1047 | 1047 | * Create an item. For backwards compatibilty. |
| 1048 | 1048 | * |
| 1049 | 1049 | * @deprecated |
| 1050 | - * @return int item id |
|
| 1050 | + * @return int item id |
|
| 1051 | 1051 | */ |
| 1052 | 1052 | public function create( $data = array() ) { |
| 1053 | 1053 | |
| 1054 | - // Set the properties. |
|
| 1055 | - if ( is_array( $data ) ) { |
|
| 1056 | - $this->set_props( $data ); |
|
| 1057 | - } |
|
| 1054 | + // Set the properties. |
|
| 1055 | + if ( is_array( $data ) ) { |
|
| 1056 | + $this->set_props( $data ); |
|
| 1057 | + } |
|
| 1058 | 1058 | |
| 1059 | - // Save the item. |
|
| 1060 | - return $this->save(); |
|
| 1059 | + // Save the item. |
|
| 1060 | + return $this->save(); |
|
| 1061 | 1061 | |
| 1062 | 1062 | } |
| 1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | * Updates an item. For backwards compatibilty. |
| 1066 | 1066 | * |
| 1067 | 1067 | * @deprecated |
| 1068 | - * @return int item id |
|
| 1068 | + * @return int item id |
|
| 1069 | 1069 | */ |
| 1070 | 1070 | public function update( $data = array() ) { |
| 1071 | 1071 | return $this->create( $data ); |
@@ -1081,93 +1081,93 @@ discard block |
||
| 1081 | 1081 | */ |
| 1082 | 1082 | |
| 1083 | 1083 | /** |
| 1084 | - * Checks whether the item has enabled dynamic pricing. |
|
| 1085 | - * |
|
| 1086 | - * @since 1.0.19 |
|
| 1087 | - * @return bool |
|
| 1088 | - */ |
|
| 1089 | - public function user_can_set_their_price() { |
|
| 1084 | + * Checks whether the item has enabled dynamic pricing. |
|
| 1085 | + * |
|
| 1086 | + * @since 1.0.19 |
|
| 1087 | + * @return bool |
|
| 1088 | + */ |
|
| 1089 | + public function user_can_set_their_price() { |
|
| 1090 | 1090 | return (bool) $this->get_is_dynamic_pricing(); |
| 1091 | - } |
|
| 1091 | + } |
|
| 1092 | 1092 | |
| 1093 | - /** |
|
| 1094 | - * Checks whether the item is recurring. |
|
| 1095 | - * |
|
| 1096 | - * @since 1.0.19 |
|
| 1097 | - * @return bool |
|
| 1098 | - */ |
|
| 1099 | - public function is_recurring() { |
|
| 1093 | + /** |
|
| 1094 | + * Checks whether the item is recurring. |
|
| 1095 | + * |
|
| 1096 | + * @since 1.0.19 |
|
| 1097 | + * @return bool |
|
| 1098 | + */ |
|
| 1099 | + public function is_recurring() { |
|
| 1100 | 1100 | return (bool) $this->get_is_recurring(); |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
| 1104 | - * Checks whether the item has a free trial. |
|
| 1105 | - * |
|
| 1106 | - * @since 1.0.19 |
|
| 1107 | - * @return bool |
|
| 1108 | - */ |
|
| 1104 | + * Checks whether the item has a free trial. |
|
| 1105 | + * |
|
| 1106 | + * @since 1.0.19 |
|
| 1107 | + * @return bool |
|
| 1108 | + */ |
|
| 1109 | 1109 | public function has_free_trial() { |
| 1110 | 1110 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1111 | 1111 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
| 1115 | - * Checks whether the item is free. |
|
| 1116 | - * |
|
| 1117 | - * @since 1.0.19 |
|
| 1118 | - * @return bool |
|
| 1119 | - */ |
|
| 1115 | + * Checks whether the item is free. |
|
| 1116 | + * |
|
| 1117 | + * @since 1.0.19 |
|
| 1118 | + * @return bool |
|
| 1119 | + */ |
|
| 1120 | 1120 | public function is_free() { |
| 1121 | 1121 | $is_free = $this->get_price() == 0; |
| 1122 | 1122 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | /** |
| 1126 | - * Checks the item status against a passed in status. |
|
| 1127 | - * |
|
| 1128 | - * @param array|string $status Status to check. |
|
| 1129 | - * @return bool |
|
| 1130 | - */ |
|
| 1131 | - public function has_status( $status ) { |
|
| 1132 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1133 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1126 | + * Checks the item status against a passed in status. |
|
| 1127 | + * |
|
| 1128 | + * @param array|string $status Status to check. |
|
| 1129 | + * @return bool |
|
| 1130 | + */ |
|
| 1131 | + public function has_status( $status ) { |
|
| 1132 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1133 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
| 1137 | - * Checks the item type against a passed in types. |
|
| 1138 | - * |
|
| 1139 | - * @param array|string $type Type to check. |
|
| 1140 | - * @return bool |
|
| 1141 | - */ |
|
| 1142 | - public function is_type( $type ) { |
|
| 1143 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1144 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1145 | - } |
|
| 1137 | + * Checks the item type against a passed in types. |
|
| 1138 | + * |
|
| 1139 | + * @param array|string $type Type to check. |
|
| 1140 | + * @return bool |
|
| 1141 | + */ |
|
| 1142 | + public function is_type( $type ) { |
|
| 1143 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1144 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1145 | + } |
|
| 1146 | 1146 | |
| 1147 | 1147 | /** |
| 1148 | - * Checks whether the item is editable. |
|
| 1149 | - * |
|
| 1150 | - * @since 1.0.19 |
|
| 1151 | - * @return bool |
|
| 1152 | - */ |
|
| 1148 | + * Checks whether the item is editable. |
|
| 1149 | + * |
|
| 1150 | + * @since 1.0.19 |
|
| 1151 | + * @return bool |
|
| 1152 | + */ |
|
| 1153 | 1153 | public function is_editable() { |
| 1154 | 1154 | $is_editable = $this->get_is_editable(); |
| 1155 | 1155 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
| 1156 | - } |
|
| 1156 | + } |
|
| 1157 | 1157 | |
| 1158 | - /** |
|
| 1159 | - * Returns an array of cart fees. |
|
| 1160 | - */ |
|
| 1161 | - public function get_fees() { |
|
| 1158 | + /** |
|
| 1159 | + * Returns an array of cart fees. |
|
| 1160 | + */ |
|
| 1161 | + public function get_fees() { |
|
| 1162 | 1162 | return array(); |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | /** |
| 1166 | - * Checks whether the item is purchasable. |
|
| 1167 | - * |
|
| 1168 | - * @since 1.0.19 |
|
| 1169 | - * @return bool |
|
| 1170 | - */ |
|
| 1166 | + * Checks whether the item is purchasable. |
|
| 1167 | + * |
|
| 1168 | + * @since 1.0.19 |
|
| 1169 | + * @return bool |
|
| 1170 | + */ |
|
| 1171 | 1171 | public function can_purchase() { |
| 1172 | 1172 | $can_purchase = $this->exists(); |
| 1173 | 1173 | |
@@ -1179,11 +1179,11 @@ discard block |
||
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | /** |
| 1182 | - * Checks whether the item supports dynamic pricing. |
|
| 1183 | - * |
|
| 1184 | - * @since 1.0.19 |
|
| 1185 | - * @return bool |
|
| 1186 | - */ |
|
| 1182 | + * Checks whether the item supports dynamic pricing. |
|
| 1183 | + * |
|
| 1184 | + * @since 1.0.19 |
|
| 1185 | + * @return bool |
|
| 1186 | + */ |
|
| 1187 | 1187 | public function supports_dynamic_pricing() { |
| 1188 | 1188 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
| 1189 | 1189 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -78,30 +78,30 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
| 80 | 80 | */ |
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 81 | + public function __construct($item = 0) { |
|
| 82 | + parent::__construct($item); |
|
| 83 | + |
|
| 84 | + if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) { |
|
| 85 | + $this->set_id($item); |
|
| 86 | + } elseif ($item instanceof self) { |
|
| 87 | + $this->set_id($item->get_id()); |
|
| 88 | + } elseif (!empty($item->ID)) { |
|
| 89 | + $this->set_id($item->ID); |
|
| 90 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) { |
|
| 91 | + $this->set_id($item_id); |
|
| 92 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) { |
|
| 93 | + $this->set_id($item_id); |
|
| 94 | 94 | } else { |
| 95 | - $this->set_object_read( true ); |
|
| 95 | + $this->set_object_read(true); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 102 | - $this->post = get_post( $this->get_id() ); |
|
| 101 | + if ($this->get_id() > 0) { |
|
| 102 | + $this->post = get_post($this->get_id()); |
|
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read($this); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | } |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | * @param string $context View or edit context. |
| 129 | 129 | * @return int |
| 130 | 130 | */ |
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 131 | + public function get_parent_id($context = 'view') { |
|
| 132 | + return (int) $this->get_prop('parent_id', $context); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @param string $context View or edit context. |
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 142 | + public function get_status($context = 'view') { |
|
| 143 | + return $this->get_prop('status', $context); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | * @param string $context View or edit context. |
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 153 | + public function get_version($context = 'view') { |
|
| 154 | + return $this->get_prop('version', $context); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | * @param string $context View or edit context. |
| 162 | 162 | * @return string |
| 163 | 163 | */ |
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 164 | + public function get_date_created($context = 'view') { |
|
| 165 | + return $this->get_prop('date_created', $context); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,11 +172,11 @@ discard block |
||
| 172 | 172 | * @param string $context View or edit context. |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | - $date = $this->get_date_created( $context ); |
|
| 175 | + public function get_date_created_gmt($context = 'view') { |
|
| 176 | + $date = $this->get_date_created($context); |
|
| 177 | 177 | |
| 178 | - if ( $date ) { |
|
| 179 | - $date = get_gmt_from_date( $date ); |
|
| 178 | + if ($date) { |
|
| 179 | + $date = get_gmt_from_date($date); |
|
| 180 | 180 | } |
| 181 | 181 | return $date; |
| 182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @param string $context View or edit context. |
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 191 | + public function get_date_modified($context = 'view') { |
|
| 192 | + return $this->get_prop('date_modified', $context); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * @param string $context View or edit context. |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | - $date = $this->get_date_modified( $context ); |
|
| 202 | + public function get_date_modified_gmt($context = 'view') { |
|
| 203 | + $date = $this->get_date_modified($context); |
|
| 204 | 204 | |
| 205 | - if ( $date ) { |
|
| 206 | - $date = get_gmt_from_date( $date ); |
|
| 205 | + if ($date) { |
|
| 206 | + $date = get_gmt_from_date($date); |
|
| 207 | 207 | } |
| 208 | 208 | return $date; |
| 209 | 209 | } |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | * @param string $context View or edit context. |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 218 | + public function get_name($context = 'view') { |
|
| 219 | + return $this->get_prop('name', $context); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | * @param string $context View or edit context. |
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 229 | + public function get_title($context = 'view') { |
|
| 230 | + return $this->get_name($context); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | * @param string $context View or edit context. |
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 240 | + public function get_description($context = 'view') { |
|
| 241 | + return $this->get_prop('description', $context); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | * @param string $context View or edit context. |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 251 | + public function get_excerpt($context = 'view') { |
|
| 252 | + return $this->get_description($context); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @param string $context View or edit context. |
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 262 | + public function get_summary($context = 'view') { |
|
| 263 | + return $this->get_description($context); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * @param string $context View or edit context. |
| 271 | 271 | * @return int |
| 272 | 272 | */ |
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 273 | + public function get_author($context = 'view') { |
|
| 274 | + return (int) $this->get_prop('author', $context); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * @param string $context View or edit context. |
| 282 | 282 | * @return int |
| 283 | 283 | */ |
| 284 | - public function get_owner( $context = 'view' ) { |
|
| 285 | - return $this->get_author( $context ); |
|
| 284 | + public function get_owner($context = 'view') { |
|
| 285 | + return $this->get_author($context); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | * @param string $context View or edit context. |
| 293 | 293 | * @return float |
| 294 | 294 | */ |
| 295 | - public function get_price( $context = 'view' ) { |
|
| 296 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
| 295 | + public function get_price($context = 'view') { |
|
| 296 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -303,15 +303,15 @@ discard block |
||
| 303 | 303 | * @param string $context View or edit context. |
| 304 | 304 | * @return float |
| 305 | 305 | */ |
| 306 | - public function get_initial_price( $context = 'view' ) { |
|
| 306 | + public function get_initial_price($context = 'view') { |
|
| 307 | 307 | |
| 308 | - $price = (float) $this->get_price( $context ); |
|
| 308 | + $price = (float) $this->get_price($context); |
|
| 309 | 309 | |
| 310 | - if ( $this->has_free_trial() ) { |
|
| 310 | + if ($this->has_free_trial()) { |
|
| 311 | 311 | $price = 0; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
|
| 314 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this)); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | 324 | public function get_the_price() { |
| 325 | - return wpinv_price( $this->get_price() ); |
|
| 325 | + return wpinv_price($this->get_price()); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | 335 | public function get_the_initial_price() { |
| 336 | - return wpinv_price( $this->get_initial_price() ); |
|
| 336 | + return wpinv_price($this->get_initial_price()); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | * @param string $context View or edit context. |
| 344 | 344 | * @return string |
| 345 | 345 | */ |
| 346 | - public function get_vat_rule( $context = 'view' ) { |
|
| 347 | - return $this->get_prop( 'vat_rule', $context ); |
|
| 346 | + public function get_vat_rule($context = 'view') { |
|
| 347 | + return $this->get_prop('vat_rule', $context); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -354,8 +354,8 @@ discard block |
||
| 354 | 354 | * @param string $context View or edit context. |
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | - public function get_vat_class( $context = 'view' ) { |
|
| 358 | - return $this->get_prop( 'vat_class', $context ); |
|
| 357 | + public function get_vat_class($context = 'view') { |
|
| 358 | + return $this->get_prop('vat_class', $context); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | * @param string $context View or edit context. |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public function get_type( $context = 'view' ) { |
|
| 369 | - return $this->get_prop( 'type', $context ); |
|
| 368 | + public function get_type($context = 'view') { |
|
| 369 | + return $this->get_prop('type', $context); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @param string $context View or edit context. |
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | - public function get_custom_id( $context = 'view' ) { |
|
| 380 | - return $this->get_prop( 'custom_id', $context ); |
|
| 379 | + public function get_custom_id($context = 'view') { |
|
| 380 | + return $this->get_prop('custom_id', $context); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -387,8 +387,8 @@ discard block |
||
| 387 | 387 | * @param string $context View or edit context. |
| 388 | 388 | * @return string |
| 389 | 389 | */ |
| 390 | - public function get_custom_name( $context = 'view' ) { |
|
| 391 | - return $this->get_prop( 'custom_name', $context ); |
|
| 390 | + public function get_custom_name($context = 'view') { |
|
| 391 | + return $this->get_prop('custom_name', $context); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * @param string $context View or edit context. |
| 399 | 399 | * @return string |
| 400 | 400 | */ |
| 401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 402 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
| 401 | + public function get_custom_singular_name($context = 'view') { |
|
| 402 | + return $this->get_prop('custom_singular_name', $context); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -409,8 +409,8 @@ discard block |
||
| 409 | 409 | * @param string $context View or edit context. |
| 410 | 410 | * @return int |
| 411 | 411 | */ |
| 412 | - public function get_is_editable( $context = 'view' ) { |
|
| 413 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
| 412 | + public function get_is_editable($context = 'view') { |
|
| 413 | + return (int) $this->get_prop('is_editable', $context); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | * @param string $context View or edit context. |
| 421 | 421 | * @return int |
| 422 | 422 | */ |
| 423 | - public function get_editable( $context = 'view' ) { |
|
| 424 | - return $this->get_is_editable( $context ); |
|
| 423 | + public function get_editable($context = 'view') { |
|
| 424 | + return $this->get_is_editable($context); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
| 431 | 431 | * @param string $context View or edit context. |
| 432 | 432 | * @return int |
| 433 | 433 | */ |
| 434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 435 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
| 434 | + public function get_is_dynamic_pricing($context = 'view') { |
|
| 435 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | * @param string $context View or edit context. |
| 443 | 443 | * @return float |
| 444 | 444 | */ |
| 445 | - public function get_minimum_price( $context = 'view' ) { |
|
| 446 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
| 445 | + public function get_minimum_price($context = 'view') { |
|
| 446 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | * @param string $context View or edit context. |
| 454 | 454 | * @return int |
| 455 | 455 | */ |
| 456 | - public function get_is_recurring( $context = 'view' ) { |
|
| 457 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
| 456 | + public function get_is_recurring($context = 'view') { |
|
| 457 | + return (int) $this->get_prop('is_recurring', $context); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -464,9 +464,9 @@ discard block |
||
| 464 | 464 | * @param string $context View or edit context. |
| 465 | 465 | * @return float |
| 466 | 466 | */ |
| 467 | - public function get_recurring_price( $context = 'view' ) { |
|
| 468 | - $price = $this->get_price( $context ); |
|
| 469 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
| 467 | + public function get_recurring_price($context = 'view') { |
|
| 468 | + $price = $this->get_price($context); |
|
| 469 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * @return string |
| 478 | 478 | */ |
| 479 | 479 | public function get_the_recurring_price() { |
| 480 | - return wpinv_price( $this->get_recurring_price() ); |
|
| 480 | + return wpinv_price($this->get_recurring_price()); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -498,15 +498,15 @@ discard block |
||
| 498 | 498 | $period = $this->get_recurring_period(); |
| 499 | 499 | $interval = $this->get_recurring_interval(); |
| 500 | 500 | |
| 501 | - if ( $this->has_free_trial() ) { |
|
| 501 | + if ($this->has_free_trial()) { |
|
| 502 | 502 | $period = $this->get_trial_period(); |
| 503 | 503 | $interval = $this->get_trial_interval(); |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $period = $periods[ $period ]; |
|
| 507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 509 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
| 506 | + $period = $periods[$period]; |
|
| 507 | + $interval = empty($interval) ? 1 : $interval; |
|
| 508 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
| 509 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -516,14 +516,14 @@ discard block |
||
| 516 | 516 | * @param bool $full Return abbreviation or in full. |
| 517 | 517 | * @return string |
| 518 | 518 | */ |
| 519 | - public function get_recurring_period( $full = false ) { |
|
| 520 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
| 519 | + public function get_recurring_period($full = false) { |
|
| 520 | + $period = $this->get_prop('recurring_period', 'view'); |
|
| 521 | 521 | |
| 522 | - if ( $full && ! is_bool( $full ) ) { |
|
| 522 | + if ($full && !is_bool($full)) { |
|
| 523 | 523 | $full = false; |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
| 526 | + return getpaid_sanitize_recurring_period($period, $full); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -533,9 +533,9 @@ discard block |
||
| 533 | 533 | * @param string $context View or edit context. |
| 534 | 534 | * @return int |
| 535 | 535 | */ |
| 536 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 538 | - return max( 1, $interval ); |
|
| 536 | + public function get_recurring_interval($context = 'view') { |
|
| 537 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
| 538 | + return max(1, $interval); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -545,8 +545,8 @@ discard block |
||
| 545 | 545 | * @param string $context View or edit context. |
| 546 | 546 | * @return int |
| 547 | 547 | */ |
| 548 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 549 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
| 548 | + public function get_recurring_limit($context = 'view') { |
|
| 549 | + return (int) $this->get_prop('recurring_limit', $context); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -556,8 +556,8 @@ discard block |
||
| 556 | 556 | * @param string $context View or edit context. |
| 557 | 557 | * @return int |
| 558 | 558 | */ |
| 559 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 560 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
| 559 | + public function get_is_free_trial($context = 'view') { |
|
| 560 | + return (int) $this->get_prop('is_free_trial', $context); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -567,8 +567,8 @@ discard block |
||
| 567 | 567 | * @param string $context View or edit context. |
| 568 | 568 | * @return int |
| 569 | 569 | */ |
| 570 | - public function get_free_trial( $context = 'view' ) { |
|
| 571 | - return $this->get_is_free_trial( $context ); |
|
| 570 | + public function get_free_trial($context = 'view') { |
|
| 571 | + return $this->get_is_free_trial($context); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -578,14 +578,14 @@ discard block |
||
| 578 | 578 | * @param bool $full Return abbreviation or in full. |
| 579 | 579 | * @return string |
| 580 | 580 | */ |
| 581 | - public function get_trial_period( $full = false ) { |
|
| 582 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
| 581 | + public function get_trial_period($full = false) { |
|
| 582 | + $period = $this->get_prop('trial_period', 'view'); |
|
| 583 | 583 | |
| 584 | - if ( $full && ! is_bool( $full ) ) { |
|
| 584 | + if ($full && !is_bool($full)) { |
|
| 585 | 585 | $full = false; |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
| 588 | + return getpaid_sanitize_recurring_period($period, $full); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -595,8 +595,8 @@ discard block |
||
| 595 | 595 | * @param string $context View or edit context. |
| 596 | 596 | * @return int |
| 597 | 597 | */ |
| 598 | - public function get_trial_interval( $context = 'view' ) { |
|
| 599 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
| 598 | + public function get_trial_interval($context = 'view') { |
|
| 599 | + return (int) $this->get_prop('trial_interval', $context); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | * @return string |
| 607 | 607 | */ |
| 608 | 608 | public function get_edit_url() { |
| 609 | - return get_edit_post_link( $this->get_id(), 'edit' ); |
|
| 609 | + return get_edit_post_link($this->get_id(), 'edit'); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | /** |
@@ -620,35 +620,35 @@ discard block |
||
| 620 | 620 | * @since 1.0.15 |
| 621 | 621 | * @return int |
| 622 | 622 | */ |
| 623 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 623 | + public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') { |
|
| 624 | 624 | |
| 625 | 625 | // Trim the value. |
| 626 | - $value = sanitize_text_field( $value ); |
|
| 627 | - if ( empty( $value ) ) { |
|
| 626 | + $value = sanitize_text_field($value); |
|
| 627 | + if (empty($value)) { |
|
| 628 | 628 | return 0; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | // Valid fields. |
| 632 | - $fields = array( 'custom_id', 'name', 'slug' ); |
|
| 632 | + $fields = array('custom_id', 'name', 'slug'); |
|
| 633 | 633 | |
| 634 | 634 | // Ensure a field has been passed. |
| 635 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 635 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 636 | 636 | return 0; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - if ( $field == 'name' ) { |
|
| 639 | + if ($field == 'name') { |
|
| 640 | 640 | $field = 'slug'; |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // Maybe retrieve from the cache. |
| 644 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 645 | - if ( ! empty( $item_id ) ) { |
|
| 644 | + $item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
| 645 | + if (!empty($item_id)) { |
|
| 646 | 646 | return $item_id; |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | // Fetch from the db. |
| 650 | 650 | $items = array(); |
| 651 | - if ( $field == 'slug' ) { |
|
| 651 | + if ($field == 'slug') { |
|
| 652 | 652 | $items = get_posts( |
| 653 | 653 | array( |
| 654 | 654 | 'post_type' => 'wpi_item', |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | ); |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - if ( $field =='custom_id' ) { |
|
| 662 | + if ($field == 'custom_id') { |
|
| 663 | 663 | $items = get_posts( |
| 664 | 664 | array( |
| 665 | 665 | 'post_type' => 'wpi_item', |
@@ -679,12 +679,12 @@ discard block |
||
| 679 | 679 | ); |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - if ( empty( $items ) ) { |
|
| 682 | + if (empty($items)) { |
|
| 683 | 683 | return 0; |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | // Update the cache with our data |
| 687 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 687 | + wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
| 688 | 688 | |
| 689 | 689 | return $items[0]->ID; |
| 690 | 690 | } |
@@ -692,19 +692,19 @@ discard block |
||
| 692 | 692 | /** |
| 693 | 693 | * Margic method for retrieving a property. |
| 694 | 694 | */ |
| 695 | - public function __get( $key ) { |
|
| 695 | + public function __get($key) { |
|
| 696 | 696 | |
| 697 | 697 | // Check if we have a helper method for that. |
| 698 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 699 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 698 | + if (method_exists($this, 'get_' . $key)) { |
|
| 699 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | // Check if the key is in the associated $post object. |
| 703 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
| 703 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
| 704 | 704 | return $this->post->$key; |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | - return $this->get_prop( $key ); |
|
| 707 | + return $this->get_prop($key); |
|
| 708 | 708 | |
| 709 | 709 | } |
| 710 | 710 | |
@@ -723,11 +723,11 @@ discard block |
||
| 723 | 723 | * |
| 724 | 724 | * @since 1.0.19 |
| 725 | 725 | */ |
| 726 | - public function set_parent_id( $value ) { |
|
| 727 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 726 | + public function set_parent_id($value) { |
|
| 727 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
| 728 | 728 | return; |
| 729 | 729 | } |
| 730 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 730 | + $this->set_prop('parent_id', absint($value)); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -737,10 +737,10 @@ discard block |
||
| 737 | 737 | * @param string $status New status. |
| 738 | 738 | * @return array details of change. |
| 739 | 739 | */ |
| 740 | - public function set_status( $status ) { |
|
| 740 | + public function set_status($status) { |
|
| 741 | 741 | $old_status = $this->get_status(); |
| 742 | 742 | |
| 743 | - $this->set_prop( 'status', $status ); |
|
| 743 | + $this->set_prop('status', $status); |
|
| 744 | 744 | |
| 745 | 745 | return array( |
| 746 | 746 | 'from' => $old_status, |
@@ -753,8 +753,8 @@ discard block |
||
| 753 | 753 | * |
| 754 | 754 | * @since 1.0.19 |
| 755 | 755 | */ |
| 756 | - public function set_version( $value ) { |
|
| 757 | - $this->set_prop( 'version', $value ); |
|
| 756 | + public function set_version($value) { |
|
| 757 | + $this->set_prop('version', $value); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
@@ -764,11 +764,11 @@ discard block |
||
| 764 | 764 | * @param string $value Value to set. |
| 765 | 765 | * @return bool Whether or not the date was set. |
| 766 | 766 | */ |
| 767 | - public function set_date_created( $value ) { |
|
| 768 | - $date = strtotime( $value ); |
|
| 767 | + public function set_date_created($value) { |
|
| 768 | + $date = strtotime($value); |
|
| 769 | 769 | |
| 770 | - if ( $date ) { |
|
| 771 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 770 | + if ($date) { |
|
| 771 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
| 772 | 772 | return true; |
| 773 | 773 | } |
| 774 | 774 | |
@@ -783,11 +783,11 @@ discard block |
||
| 783 | 783 | * @param string $value Value to set. |
| 784 | 784 | * @return bool Whether or not the date was set. |
| 785 | 785 | */ |
| 786 | - public function set_date_modified( $value ) { |
|
| 787 | - $date = strtotime( $value ); |
|
| 786 | + public function set_date_modified($value) { |
|
| 787 | + $date = strtotime($value); |
|
| 788 | 788 | |
| 789 | - if ( $date ) { |
|
| 790 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
| 789 | + if ($date) { |
|
| 790 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
| 791 | 791 | return true; |
| 792 | 792 | } |
| 793 | 793 | |
@@ -801,9 +801,9 @@ discard block |
||
| 801 | 801 | * @since 1.0.19 |
| 802 | 802 | * @param string $value New name. |
| 803 | 803 | */ |
| 804 | - public function set_name( $value ) { |
|
| 805 | - $name = sanitize_text_field( $value ); |
|
| 806 | - $this->set_prop( 'name', $name ); |
|
| 804 | + public function set_name($value) { |
|
| 805 | + $name = sanitize_text_field($value); |
|
| 806 | + $this->set_prop('name', $name); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -812,8 +812,8 @@ discard block |
||
| 812 | 812 | * @since 1.0.19 |
| 813 | 813 | * @param string $value New name. |
| 814 | 814 | */ |
| 815 | - public function set_title( $value ) { |
|
| 816 | - $this->set_name( $value ); |
|
| 815 | + public function set_title($value) { |
|
| 816 | + $this->set_name($value); |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | /** |
@@ -822,9 +822,9 @@ discard block |
||
| 822 | 822 | * @since 1.0.19 |
| 823 | 823 | * @param string $value New description. |
| 824 | 824 | */ |
| 825 | - public function set_description( $value ) { |
|
| 826 | - $description = wp_kses_post( $value ); |
|
| 827 | - return $this->set_prop( 'description', $description ); |
|
| 825 | + public function set_description($value) { |
|
| 826 | + $description = wp_kses_post($value); |
|
| 827 | + return $this->set_prop('description', $description); |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -833,8 +833,8 @@ discard block |
||
| 833 | 833 | * @since 1.0.19 |
| 834 | 834 | * @param string $value New description. |
| 835 | 835 | */ |
| 836 | - public function set_excerpt( $value ) { |
|
| 837 | - $this->set_description( $value ); |
|
| 836 | + public function set_excerpt($value) { |
|
| 837 | + $this->set_description($value); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
@@ -843,8 +843,8 @@ discard block |
||
| 843 | 843 | * @since 1.0.19 |
| 844 | 844 | * @param string $value New description. |
| 845 | 845 | */ |
| 846 | - public function set_summary( $value ) { |
|
| 847 | - $this->set_description( $value ); |
|
| 846 | + public function set_summary($value) { |
|
| 847 | + $this->set_description($value); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | /** |
@@ -853,8 +853,8 @@ discard block |
||
| 853 | 853 | * @since 1.0.19 |
| 854 | 854 | * @param int $value New author. |
| 855 | 855 | */ |
| 856 | - public function set_author( $value ) { |
|
| 857 | - $this->set_prop( 'author', (int) $value ); |
|
| 856 | + public function set_author($value) { |
|
| 857 | + $this->set_prop('author', (int) $value); |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | /** |
@@ -863,8 +863,8 @@ discard block |
||
| 863 | 863 | * @since 1.0.19 |
| 864 | 864 | * @param int $value New author. |
| 865 | 865 | */ |
| 866 | - public function set_owner( $value ) { |
|
| 867 | - $this->set_author( $value ); |
|
| 866 | + public function set_owner($value) { |
|
| 867 | + $this->set_author($value); |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | /** |
@@ -873,8 +873,8 @@ discard block |
||
| 873 | 873 | * @since 1.0.19 |
| 874 | 874 | * @param float $value New price. |
| 875 | 875 | */ |
| 876 | - public function set_price( $value ) { |
|
| 877 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
| 876 | + public function set_price($value) { |
|
| 877 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
@@ -883,8 +883,8 @@ discard block |
||
| 883 | 883 | * @since 1.0.19 |
| 884 | 884 | * @param string $value new rule. |
| 885 | 885 | */ |
| 886 | - public function set_vat_rule( $value ) { |
|
| 887 | - $this->set_prop( 'vat_rule', $value ); |
|
| 886 | + public function set_vat_rule($value) { |
|
| 887 | + $this->set_prop('vat_rule', $value); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
@@ -893,8 +893,8 @@ discard block |
||
| 893 | 893 | * @since 1.0.19 |
| 894 | 894 | * @param string $value new class. |
| 895 | 895 | */ |
| 896 | - public function set_vat_class( $value ) { |
|
| 897 | - $this->set_prop( 'vat_class', $value ); |
|
| 896 | + public function set_vat_class($value) { |
|
| 897 | + $this->set_prop('vat_class', $value); |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
@@ -904,13 +904,13 @@ discard block |
||
| 904 | 904 | * @param string $value new item type. |
| 905 | 905 | * @return string |
| 906 | 906 | */ |
| 907 | - public function set_type( $value ) { |
|
| 907 | + public function set_type($value) { |
|
| 908 | 908 | |
| 909 | - if ( empty( $value ) ) { |
|
| 909 | + if (empty($value)) { |
|
| 910 | 910 | $value = 'custom'; |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | - $this->set_prop( 'type', $value ); |
|
| 913 | + $this->set_prop('type', $value); |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
@@ -919,8 +919,8 @@ discard block |
||
| 919 | 919 | * @since 1.0.19 |
| 920 | 920 | * @param string $value new custom id. |
| 921 | 921 | */ |
| 922 | - public function set_custom_id( $value ) { |
|
| 923 | - $this->set_prop( 'custom_id', $value ); |
|
| 922 | + public function set_custom_id($value) { |
|
| 923 | + $this->set_prop('custom_id', $value); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | /** |
@@ -929,8 +929,8 @@ discard block |
||
| 929 | 929 | * @since 1.0.19 |
| 930 | 930 | * @param string $value new custom name. |
| 931 | 931 | */ |
| 932 | - public function set_custom_name( $value ) { |
|
| 933 | - $this->set_prop( 'custom_name', $value ); |
|
| 932 | + public function set_custom_name($value) { |
|
| 933 | + $this->set_prop('custom_name', $value); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -939,8 +939,8 @@ discard block |
||
| 939 | 939 | * @since 1.0.19 |
| 940 | 940 | * @param string $value new custom singular name. |
| 941 | 941 | */ |
| 942 | - public function set_custom_singular_name( $value ) { |
|
| 943 | - $this->set_prop( 'custom_singular_name', $value ); |
|
| 942 | + public function set_custom_singular_name($value) { |
|
| 943 | + $this->set_prop('custom_singular_name', $value); |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | /** |
@@ -949,8 +949,8 @@ discard block |
||
| 949 | 949 | * @since 1.0.19 |
| 950 | 950 | * @param int|bool $value whether or not the item is editable. |
| 951 | 951 | */ |
| 952 | - public function set_is_editable( $value ) { |
|
| 953 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 952 | + public function set_is_editable($value) { |
|
| 953 | + $this->set_prop('is_editable', (int) $value); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
@@ -959,8 +959,8 @@ discard block |
||
| 959 | 959 | * @since 1.0.19 |
| 960 | 960 | * @param int|bool $value whether or not dynamic pricing is allowed. |
| 961 | 961 | */ |
| 962 | - public function set_is_dynamic_pricing( $value ) { |
|
| 963 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
| 962 | + public function set_is_dynamic_pricing($value) { |
|
| 963 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
@@ -969,8 +969,8 @@ discard block |
||
| 969 | 969 | * @since 1.0.19 |
| 970 | 970 | * @param float $value minimum price. |
| 971 | 971 | */ |
| 972 | - public function set_minimum_price( $value ) { |
|
| 973 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
| 972 | + public function set_minimum_price($value) { |
|
| 973 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
@@ -979,8 +979,8 @@ discard block |
||
| 979 | 979 | * @since 1.0.19 |
| 980 | 980 | * @param int|bool $value whether or not dynamic pricing is allowed. |
| 981 | 981 | */ |
| 982 | - public function set_is_recurring( $value ) { |
|
| 983 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
| 982 | + public function set_is_recurring($value) { |
|
| 983 | + $this->set_prop('is_recurring', (int) $value); |
|
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | /** |
@@ -989,8 +989,8 @@ discard block |
||
| 989 | 989 | * @since 1.0.19 |
| 990 | 990 | * @param string $value new period. |
| 991 | 991 | */ |
| 992 | - public function set_recurring_period( $value ) { |
|
| 993 | - $this->set_prop( 'recurring_period', $value ); |
|
| 992 | + public function set_recurring_period($value) { |
|
| 993 | + $this->set_prop('recurring_period', $value); |
|
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | /** |
@@ -999,8 +999,8 @@ discard block |
||
| 999 | 999 | * @since 1.0.19 |
| 1000 | 1000 | * @param int $value recurring interval. |
| 1001 | 1001 | */ |
| 1002 | - public function set_recurring_interval( $value ) { |
|
| 1003 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
| 1002 | + public function set_recurring_interval($value) { |
|
| 1003 | + return $this->set_prop('recurring_interval', (int) $value); |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | /** |
@@ -1009,8 +1009,8 @@ discard block |
||
| 1009 | 1009 | * @param int $value The recurring limit. |
| 1010 | 1010 | * @return int |
| 1011 | 1011 | */ |
| 1012 | - public function set_recurring_limit( $value ) { |
|
| 1013 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
| 1012 | + public function set_recurring_limit($value) { |
|
| 1013 | + $this->set_prop('recurring_limit', (int) $value); |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | /** |
@@ -1019,8 +1019,8 @@ discard block |
||
| 1019 | 1019 | * @since 1.0.19 |
| 1020 | 1020 | * @param int|bool $value whether or not it has a free trial. |
| 1021 | 1021 | */ |
| 1022 | - public function set_is_free_trial( $value ) { |
|
| 1023 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
| 1022 | + public function set_is_free_trial($value) { |
|
| 1023 | + $this->set_prop('is_free_trial', (int) $value); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
@@ -1029,8 +1029,8 @@ discard block |
||
| 1029 | 1029 | * @since 1.0.19 |
| 1030 | 1030 | * @param string $value trial period. |
| 1031 | 1031 | */ |
| 1032 | - public function set_trial_period( $value ) { |
|
| 1033 | - $this->set_prop( 'trial_period', $value ); |
|
| 1032 | + public function set_trial_period($value) { |
|
| 1033 | + $this->set_prop('trial_period', $value); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /** |
@@ -1039,8 +1039,8 @@ discard block |
||
| 1039 | 1039 | * @since 1.0.19 |
| 1040 | 1040 | * @param int $value trial interval. |
| 1041 | 1041 | */ |
| 1042 | - public function set_trial_interval( $value ) { |
|
| 1043 | - $this->set_prop( 'trial_interval', $value ); |
|
| 1042 | + public function set_trial_interval($value) { |
|
| 1043 | + $this->set_prop('trial_interval', $value); |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1049,11 +1049,11 @@ discard block |
||
| 1049 | 1049 | * @deprecated |
| 1050 | 1050 | * @return int item id |
| 1051 | 1051 | */ |
| 1052 | - public function create( $data = array() ) { |
|
| 1052 | + public function create($data = array()) { |
|
| 1053 | 1053 | |
| 1054 | 1054 | // Set the properties. |
| 1055 | - if ( is_array( $data ) ) { |
|
| 1056 | - $this->set_props( $data ); |
|
| 1055 | + if (is_array($data)) { |
|
| 1056 | + $this->set_props($data); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | // Save the item. |
@@ -1067,8 +1067,8 @@ discard block |
||
| 1067 | 1067 | * @deprecated |
| 1068 | 1068 | * @return int item id |
| 1069 | 1069 | */ |
| 1070 | - public function update( $data = array() ) { |
|
| 1071 | - return $this->create( $data ); |
|
| 1070 | + public function update($data = array()) { |
|
| 1071 | + return $this->create($data); |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | /* |
@@ -1108,7 +1108,7 @@ discard block |
||
| 1108 | 1108 | */ |
| 1109 | 1109 | public function has_free_trial() { |
| 1110 | 1110 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1111 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
| 1111 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
@@ -1118,8 +1118,8 @@ discard block |
||
| 1118 | 1118 | * @return bool |
| 1119 | 1119 | */ |
| 1120 | 1120 | public function is_free() { |
| 1121 | - $is_free = $this->get_price() == 0; |
|
| 1122 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
| 1121 | + $is_free = $this->get_price() == 0; |
|
| 1122 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | /** |
@@ -1128,9 +1128,9 @@ discard block |
||
| 1128 | 1128 | * @param array|string $status Status to check. |
| 1129 | 1129 | * @return bool |
| 1130 | 1130 | */ |
| 1131 | - public function has_status( $status ) { |
|
| 1132 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1133 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1131 | + public function has_status($status) { |
|
| 1132 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
| 1133 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
@@ -1139,9 +1139,9 @@ discard block |
||
| 1139 | 1139 | * @param array|string $type Type to check. |
| 1140 | 1140 | * @return bool |
| 1141 | 1141 | */ |
| 1142 | - public function is_type( $type ) { |
|
| 1143 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1144 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1142 | + public function is_type($type) { |
|
| 1143 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
| 1144 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1152,7 +1152,7 @@ discard block |
||
| 1152 | 1152 | */ |
| 1153 | 1153 | public function is_editable() { |
| 1154 | 1154 | $is_editable = $this->get_is_editable(); |
| 1155 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
| 1155 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | 1158 | /** |
@@ -1171,11 +1171,11 @@ discard block |
||
| 1171 | 1171 | public function can_purchase() { |
| 1172 | 1172 | $can_purchase = $this->exists(); |
| 1173 | 1173 | |
| 1174 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
| 1174 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
| 1175 | 1175 | $can_purchase = false; |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
| 1178 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | /** |
@@ -1185,6 +1185,6 @@ discard block |
||
| 1185 | 1185 | * @return bool |
| 1186 | 1186 | */ |
| 1187 | 1187 | public function supports_dynamic_pricing() { |
| 1188 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
| 1188 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | } |
@@ -7,64 +7,64 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Fetch the invoice. |
| 13 | -$invoice = new WPInv_Invoice( $invoice ); |
|
| 13 | +$invoice = new WPInv_Invoice($invoice); |
|
| 14 | 14 | |
| 15 | 15 | // @deprecated |
| 16 | -do_action( 'wpinv_success_content_before', $invoice ); |
|
| 17 | -do_action( 'wpinv_before_receipt', $invoice ); |
|
| 16 | +do_action('wpinv_success_content_before', $invoice); |
|
| 17 | +do_action('wpinv_before_receipt', $invoice); |
|
| 18 | 18 | |
| 19 | 19 | wpinv_print_errors(); |
| 20 | 20 | |
| 21 | 21 | // Prepare header text. |
| 22 | -if ( $invoice->is_paid() ) { |
|
| 22 | +if ($invoice->is_paid()) { |
|
| 23 | 23 | |
| 24 | 24 | $alert = aui()->alert( |
| 25 | 25 | array( |
| 26 | 26 | 'type' => 'success', |
| 27 | - 'content' => __( 'Thank you for your payment!', 'invoicing' ), |
|
| 27 | + 'content' => __('Thank you for your payment!', 'invoicing'), |
|
| 28 | 28 | ) |
| 29 | 29 | ); |
| 30 | 30 | |
| 31 | -} else if ( $invoice->is_refunded() ) { |
|
| 31 | +} else if ($invoice->is_refunded()) { |
|
| 32 | 32 | |
| 33 | 33 | $alert = aui()->alert( |
| 34 | 34 | array( |
| 35 | 35 | 'type' => 'info', |
| 36 | - 'content' => __( 'This invoice was refunded.', 'invoicing' ), |
|
| 36 | + 'content' => __('This invoice was refunded.', 'invoicing'), |
|
| 37 | 37 | ) |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | -} else if ( $invoice->is_held() ) { |
|
| 40 | +} else if ($invoice->is_held()) { |
|
| 41 | 41 | |
| 42 | 42 | $alert = aui()->alert( |
| 43 | 43 | array( |
| 44 | 44 | 'type' => 'info', |
| 45 | - 'content' => __( 'This invoice will be processed as soon we verify your payment.', 'invoicing' ), |
|
| 45 | + 'content' => __('This invoice will be processed as soon we verify your payment.', 'invoicing'), |
|
| 46 | 46 | ) |
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | -} else if ( $invoice->needs_payment() ) { |
|
| 49 | +} else if ($invoice->needs_payment()) { |
|
| 50 | 50 | |
| 51 | - if ( ! empty( $_GET['token'] ) ) { |
|
| 51 | + if (!empty($_GET['token'])) { |
|
| 52 | 52 | |
| 53 | 53 | $alert = aui()->alert( |
| 54 | 54 | array( |
| 55 | 55 | 'type' => 'info', |
| 56 | - 'content' => __( "Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing' ), |
|
| 56 | + 'content' => __("Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing'), |
|
| 57 | 57 | ) |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - } else if ( $invoice->is_due() ) { |
|
| 60 | + } else if ($invoice->is_due()) { |
|
| 61 | 61 | |
| 62 | 62 | $alert = aui()->alert( |
| 63 | 63 | array( |
| 64 | 64 | 'type' => 'danger', |
| 65 | 65 | 'content' => sprintf( |
| 66 | - __( 'This invoice was due on %.', 'invoicing' ), |
|
| 67 | - getpaid_format_date_value( $invoice->get_due_date() ) |
|
| 66 | + __('This invoice was due on %.', 'invoicing'), |
|
| 67 | + getpaid_format_date_value($invoice->get_due_date()) |
|
| 68 | 68 | ), |
| 69 | 69 | ) |
| 70 | 70 | ); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $alert = aui()->alert( |
| 75 | 75 | array( |
| 76 | 76 | 'type' => 'warning', |
| 77 | - 'content' => __( 'This invoice needs payment.', 'invoicing' ), |
|
| 77 | + 'content' => __('This invoice needs payment.', 'invoicing'), |
|
| 78 | 78 | ) |
| 79 | 79 | ); |
| 80 | 80 | |
@@ -89,19 +89,19 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | 'pay' => array( |
| 91 | 91 | 'url' => $invoice->get_checkout_payment_url(), |
| 92 | - 'name' => __( 'Pay For Invoice', 'invoicing' ), |
|
| 92 | + 'name' => __('Pay For Invoice', 'invoicing'), |
|
| 93 | 93 | 'class' => 'btn-success', |
| 94 | 94 | ), |
| 95 | 95 | |
| 96 | 96 | 'view' => array( |
| 97 | 97 | 'url' => $invoice->get_view_url(), |
| 98 | - 'name' => __( 'View Invoice', 'invoicing' ), |
|
| 98 | + 'name' => __('View Invoice', 'invoicing'), |
|
| 99 | 99 | 'class' => 'btn-primary', |
| 100 | 100 | ), |
| 101 | 101 | |
| 102 | 102 | 'history' => array( |
| 103 | 103 | 'url' => wpinv_get_history_page_uri(), |
| 104 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
| 104 | + 'name' => __('Invoice History', 'invoicing'), |
|
| 105 | 105 | 'class' => 'btn-warning', |
| 106 | 106 | ), |
| 107 | 107 | |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | -if ( ( ! $invoice->needs_payment() || $invoice->is_held() ) && isset( $actions['pay'] ) ) { |
|
| 114 | - unset( $actions['pay'] ); |
|
| 113 | +if ((!$invoice->needs_payment() || $invoice->is_held()) && isset($actions['pay'])) { |
|
| 114 | + unset($actions['pay']); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | -if ( ! is_user_logged_in() && isset( $actions['history'] ) ) { |
|
| 118 | - unset( $actions['history'] ); |
|
| 117 | +if (!is_user_logged_in() && isset($actions['history'])) { |
|
| 118 | + unset($actions['history']); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | ?> |
@@ -124,19 +124,19 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | <?php |
| 126 | 126 | |
| 127 | - do_action( 'wpinv_receipt_start', $invoice ); |
|
| 127 | + do_action('wpinv_receipt_start', $invoice); |
|
| 128 | 128 | |
| 129 | - if ( ! empty( $actions ) ) { |
|
| 129 | + if (!empty($actions)) { |
|
| 130 | 130 | |
| 131 | 131 | echo '<div class="wpinv-receipt-actions text-right mt-1 mb-4">'; |
| 132 | 132 | |
| 133 | - foreach ( $actions as $key => $action ) { |
|
| 133 | + foreach ($actions as $key => $action) { |
|
| 134 | 134 | |
| 135 | - $key = sanitize_html_class( $key ); |
|
| 136 | - $class = empty( $action['class'] ) ? 'btn-dark' : sanitize_html_class( $action['class'] ); |
|
| 137 | - $url = empty( $action['url'] ) ? '#' : esc_url( $action['url'] ); |
|
| 138 | - $attrs = empty( $action['attrs'] ) ? '' : $action['attrs']; |
|
| 139 | - $anchor = sanitize_text_field( $action['name'] ); |
|
| 135 | + $key = sanitize_html_class($key); |
|
| 136 | + $class = empty($action['class']) ? 'btn-dark' : sanitize_html_class($action['class']); |
|
| 137 | + $url = empty($action['url']) ? '#' : esc_url($action['url']); |
|
| 138 | + $attrs = empty($action['attrs']) ? '' : $action['attrs']; |
|
| 139 | + $anchor = sanitize_text_field($action['name']); |
|
| 140 | 140 | |
| 141 | 141 | echo "<a href='$url' class='btn btn-sm ml-1 $class $key' $attrs>$anchor</a>"; |
| 142 | 142 | } |
@@ -152,21 +152,21 @@ discard block |
||
| 152 | 152 | <div class="wpinv-receipt-details"> |
| 153 | 153 | |
| 154 | 154 | <h4 class="wpinv-details-t mb-3 mt-3"> |
| 155 | - <?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?> |
|
| 155 | + <?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing'), $invoice); ?> |
|
| 156 | 156 | </h4> |
| 157 | 157 | |
| 158 | - <?php getpaid_invoice_meta( $invoice ); ?> |
|
| 158 | + <?php getpaid_invoice_meta($invoice); ?> |
|
| 159 | 159 | |
| 160 | 160 | </div> |
| 161 | 161 | |
| 162 | - <?php echo getpaid_display_invoice_subscriptions( $invoice ); ?> |
|
| 162 | + <?php echo getpaid_display_invoice_subscriptions($invoice); ?> |
|
| 163 | 163 | |
| 164 | - <?php do_action( 'wpinv_receipt_end', $invoice ); ?> |
|
| 164 | + <?php do_action('wpinv_receipt_end', $invoice); ?> |
|
| 165 | 165 | |
| 166 | 166 | </div> |
| 167 | 167 | |
| 168 | 168 | <?php |
| 169 | 169 | |
| 170 | 170 | // @deprecated |
| 171 | -do_action( 'wpinv_success_content_after', $invoice ); |
|
| 172 | -do_action( 'wpinv_after_receipt', $invoice ); |
|
| 171 | +do_action('wpinv_success_content_after', $invoice); |
|
| 172 | +do_action('wpinv_after_receipt', $invoice); |
|
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | <?php |
| 5 | 5 | echo |
| 6 | 6 | wp_sprintf( |
| 7 | - __( 'Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing' ), |
|
| 8 | - esc_url_raw( remove_query_arg( 'payment-confirm' ) ) |
|
| 7 | + __('Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing'), |
|
| 8 | + esc_url_raw(remove_query_arg('payment-confirm')) |
|
| 9 | 9 | ); |
| 10 | 10 | ?> |
| 11 | 11 | <i class="fa fa-spin fa-refresh"></i> |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | <script type="text/javascript"> |
| 15 | 15 | setTimeout( |
| 16 | 16 | function(){ |
| 17 | - window.location.href = '<?php echo esc_url_raw( remove_query_arg( 'payment-confirm' ) ) ;?>'; |
|
| 17 | + window.location.href = '<?php echo esc_url_raw(remove_query_arg('payment-confirm')); ?>'; |
|
| 18 | 18 | }, |
| 19 | 19 | 10000 |
| 20 | 20 | ); |
@@ -12,276 +12,276 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Metaboxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Only save metaboxes once. |
|
| 17 | - * |
|
| 18 | - * @var boolean |
|
| 19 | - */ |
|
| 20 | - private static $saved_meta_boxes = false; |
|
| 21 | - |
|
| 22 | 15 | /** |
| 23 | - * Hook in methods. |
|
| 24 | - */ |
|
| 25 | - public static function init() { |
|
| 26 | - |
|
| 27 | - // Register metaboxes. |
|
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 29 | - |
|
| 30 | - // Remove metaboxes. |
|
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 32 | - |
|
| 33 | - // Rename metaboxes. |
|
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 35 | - |
|
| 36 | - // Save metaboxes. |
|
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Register core metaboxes. |
|
| 42 | - */ |
|
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 16 | + * Only save metaboxes once. |
|
| 17 | + * |
|
| 18 | + * @var boolean |
|
| 19 | + */ |
|
| 20 | + private static $saved_meta_boxes = false; |
|
| 44 | 21 | |
| 45 | - // For invoices... |
|
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 47 | - |
|
| 48 | - // For payment forms. |
|
| 49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
| 50 | - |
|
| 51 | - // For invoice items. |
|
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 53 | - |
|
| 54 | - // For invoice discounts. |
|
| 55 | - if ( $post_type == 'wpi_discount' ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - } |
|
| 22 | + /** |
|
| 23 | + * Hook in methods. |
|
| 24 | + */ |
|
| 25 | + public static function init() { |
|
| 60 | 26 | |
| 61 | - /** |
|
| 62 | - * Register core metaboxes. |
|
| 63 | - */ |
|
| 64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
| 27 | + // Register metaboxes. |
|
| 28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 65 | 29 | |
| 66 | - // For payment forms. |
|
| 67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
| 30 | + // Remove metaboxes. |
|
| 31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 68 | 32 | |
| 69 | - // Design payment form. |
|
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 33 | + // Rename metaboxes. |
|
| 34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 71 | 35 | |
| 72 | - // Payment form information. |
|
| 73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 36 | + // Save metaboxes. |
|
| 37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | + } |
|
| 74 | 39 | |
| 75 | - } |
|
| 40 | + /** |
|
| 41 | + * Register core metaboxes. |
|
| 42 | + */ |
|
| 43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
| 76 | 44 | |
| 77 | - } |
|
| 45 | + // For invoices... |
|
| 46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 78 | 47 | |
| 79 | - /** |
|
| 80 | - * Register core metaboxes. |
|
| 81 | - */ |
|
| 82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 48 | + // For payment forms. |
|
| 49 | + self::add_payment_form_meta_boxes( $post_type ); |
|
| 83 | 50 | |
| 84 | - if ( $post_type == 'wpi_item' ) { |
|
| 51 | + // For invoice items. |
|
| 52 | + self::add_item_meta_boxes( $post_type ); |
|
| 85 | 53 | |
| 86 | - // Item details. |
|
| 87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 54 | + // For invoice discounts. |
|
| 55 | + if ( $post_type == 'wpi_discount' ) { |
|
| 56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | + } |
|
| 88 | 58 | |
| 89 | - // If taxes are enabled, register the tax metabox. |
|
| 90 | - if ( wpinv_use_taxes() ) { |
|
| 91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 92 | - } |
|
| 59 | + } |
|
| 93 | 60 | |
| 94 | - // Item info. |
|
| 95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 61 | + /** |
|
| 62 | + * Register core metaboxes. |
|
| 63 | + */ |
|
| 64 | + protected static function add_payment_form_meta_boxes( $post_type ) { |
|
| 96 | 65 | |
| 97 | - } |
|
| 66 | + // For payment forms. |
|
| 67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
| 98 | 68 | |
| 99 | - } |
|
| 69 | + // Design payment form. |
|
| 70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 100 | 71 | |
| 101 | - /** |
|
| 102 | - * Register invoice metaboxes. |
|
| 103 | - */ |
|
| 104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 72 | + // Payment form information. |
|
| 73 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 105 | 74 | |
| 106 | - // For invoices... |
|
| 107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 108 | - $invoice = new WPInv_Invoice( $post ); |
|
| 75 | + } |
|
| 109 | 76 | |
| 110 | - // Resend invoice. |
|
| 111 | - if ( ! $invoice->is_draft() ) { |
|
| 77 | + } |
|
| 112 | 78 | |
| 113 | - add_meta_box( |
|
| 114 | - 'wpinv-mb-resend-invoice', |
|
| 115 | - sprintf( |
|
| 116 | - __( 'Resend %s', 'invoicing' ), |
|
| 117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 118 | - ), |
|
| 119 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 120 | - $post_type, |
|
| 121 | - 'side', |
|
| 122 | - 'low' |
|
| 123 | - ); |
|
| 79 | + /** |
|
| 80 | + * Register core metaboxes. |
|
| 81 | + */ |
|
| 82 | + protected static function add_item_meta_boxes( $post_type ) { |
|
| 124 | 83 | |
| 125 | - } |
|
| 84 | + if ( $post_type == 'wpi_item' ) { |
|
| 126 | 85 | |
| 127 | - // Subscriptions. |
|
| 128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 129 | - if ( ! empty( $subscriptions ) ) { |
|
| 86 | + // Item details. |
|
| 87 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 130 | 88 | |
| 131 | - if ( is_array( $subscriptions ) ) { |
|
| 132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 133 | - } else { |
|
| 134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 135 | - } |
|
| 89 | + // If taxes are enabled, register the tax metabox. |
|
| 90 | + if ( wpinv_use_taxes() ) { |
|
| 91 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 92 | + } |
|
| 136 | 93 | |
| 137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 139 | - } |
|
| 94 | + // Item info. |
|
| 95 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 140 | 96 | |
| 141 | - } |
|
| 97 | + } |
|
| 142 | 98 | |
| 143 | - // Invoice details. |
|
| 144 | - add_meta_box( |
|
| 145 | - 'wpinv-details', |
|
| 146 | - sprintf( |
|
| 147 | - __( '%s Details', 'invoicing' ), |
|
| 148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 149 | - ), |
|
| 150 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 151 | - $post_type, |
|
| 152 | - 'side' |
|
| 153 | - ); |
|
| 154 | - |
|
| 155 | - // Payment details. |
|
| 156 | - if ( ! $invoice->is_draft() ) { |
|
| 157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 158 | - } |
|
| 99 | + } |
|
| 159 | 100 | |
| 160 | - // Billing details. |
|
| 161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 101 | + /** |
|
| 102 | + * Register invoice metaboxes. |
|
| 103 | + */ |
|
| 104 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 105 | + |
|
| 106 | + // For invoices... |
|
| 107 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 108 | + $invoice = new WPInv_Invoice( $post ); |
|
| 109 | + |
|
| 110 | + // Resend invoice. |
|
| 111 | + if ( ! $invoice->is_draft() ) { |
|
| 112 | + |
|
| 113 | + add_meta_box( |
|
| 114 | + 'wpinv-mb-resend-invoice', |
|
| 115 | + sprintf( |
|
| 116 | + __( 'Resend %s', 'invoicing' ), |
|
| 117 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 118 | + ), |
|
| 119 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 120 | + $post_type, |
|
| 121 | + 'side', |
|
| 122 | + 'low' |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Subscriptions. |
|
| 128 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 129 | + if ( ! empty( $subscriptions ) ) { |
|
| 130 | + |
|
| 131 | + if ( is_array( $subscriptions ) ) { |
|
| 132 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 133 | + } else { |
|
| 134 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 138 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // Invoice details. |
|
| 144 | + add_meta_box( |
|
| 145 | + 'wpinv-details', |
|
| 146 | + sprintf( |
|
| 147 | + __( '%s Details', 'invoicing' ), |
|
| 148 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 149 | + ), |
|
| 150 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 151 | + $post_type, |
|
| 152 | + 'side' |
|
| 153 | + ); |
|
| 154 | + |
|
| 155 | + // Payment details. |
|
| 156 | + if ( ! $invoice->is_draft() ) { |
|
| 157 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // Billing details. |
|
| 161 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 162 | 162 | |
| 163 | - // Invoice items. |
|
| 164 | - add_meta_box( |
|
| 165 | - 'wpinv-items', |
|
| 166 | - sprintf( |
|
| 167 | - __( '%s Items', 'invoicing' ), |
|
| 168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 169 | - ), |
|
| 170 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 171 | - $post_type, |
|
| 172 | - 'normal', |
|
| 173 | - 'high' |
|
| 174 | - ); |
|
| 163 | + // Invoice items. |
|
| 164 | + add_meta_box( |
|
| 165 | + 'wpinv-items', |
|
| 166 | + sprintf( |
|
| 167 | + __( '%s Items', 'invoicing' ), |
|
| 168 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 169 | + ), |
|
| 170 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 171 | + $post_type, |
|
| 172 | + 'normal', |
|
| 173 | + 'high' |
|
| 174 | + ); |
|
| 175 | 175 | |
| 176 | - // Invoice notes. |
|
| 177 | - add_meta_box( |
|
| 178 | - 'wpinv-notes', |
|
| 179 | - sprintf( |
|
| 180 | - __( '%s Notes', 'invoicing' ), |
|
| 181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 182 | - ), |
|
| 183 | - 'WPInv_Meta_Box_Notes::output', |
|
| 184 | - $post_type, |
|
| 185 | - 'side', |
|
| 186 | - 'low' |
|
| 187 | - ); |
|
| 188 | - |
|
| 189 | - // Shipping Address. |
|
| 190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // Payment form information. |
|
| 195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Remove some metaboxes. |
|
| 205 | - */ |
|
| 206 | - public static function remove_meta_boxes() { |
|
| 207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Rename other metaboxes. |
|
| 212 | - */ |
|
| 213 | - public static function rename_meta_boxes() { |
|
| 176 | + // Invoice notes. |
|
| 177 | + add_meta_box( |
|
| 178 | + 'wpinv-notes', |
|
| 179 | + sprintf( |
|
| 180 | + __( '%s Notes', 'invoicing' ), |
|
| 181 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 182 | + ), |
|
| 183 | + 'WPInv_Meta_Box_Notes::output', |
|
| 184 | + $post_type, |
|
| 185 | + 'side', |
|
| 186 | + 'low' |
|
| 187 | + ); |
|
| 188 | + |
|
| 189 | + // Shipping Address. |
|
| 190 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // Payment form information. |
|
| 195 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Remove some metaboxes. |
|
| 205 | + */ |
|
| 206 | + public static function remove_meta_boxes() { |
|
| 207 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Rename other metaboxes. |
|
| 212 | + */ |
|
| 213 | + public static function rename_meta_boxes() { |
|
| 214 | 214 | |
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Check if we're saving, then trigger an action based on the post type. |
|
| 219 | - * |
|
| 220 | - * @param int $post_id Post ID. |
|
| 221 | - * @param object $post Post object. |
|
| 222 | - */ |
|
| 223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | - $post_id = absint( $post_id ); |
|
| 225 | - $data = wp_unslash( $_POST ); |
|
| 226 | - |
|
| 227 | - // Do not save for ajax requests. |
|
| 228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 229 | - return; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // $post_id and $post are required |
|
| 233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 234 | - return; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Dont' save meta boxes for revisions or autosaves. |
|
| 238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // Check the nonce. |
|
| 243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 244 | - return; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 249 | - return; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // Check user has permission to edit. |
|
| 253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 254 | - return; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 258 | - |
|
| 259 | - // We need this save event to run once to avoid potential endless loops. |
|
| 260 | - self::$saved_meta_boxes = true; |
|
| 261 | - |
|
| 262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 263 | - |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Ensure this is our post type. |
|
| 267 | - $post_types_map = array( |
|
| 268 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 269 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 270 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 271 | - ); |
|
| 272 | - |
|
| 273 | - // Is this our post type? |
|
| 274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // We need this save event to run once to avoid potential endless loops. |
|
| 279 | - self::$saved_meta_boxes = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Check if we're saving, then trigger an action based on the post type. |
|
| 219 | + * |
|
| 220 | + * @param int $post_id Post ID. |
|
| 221 | + * @param object $post Post object. |
|
| 222 | + */ |
|
| 223 | + public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | + $post_id = absint( $post_id ); |
|
| 225 | + $data = wp_unslash( $_POST ); |
|
| 226 | + |
|
| 227 | + // Do not save for ajax requests. |
|
| 228 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 229 | + return; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // $post_id and $post are required |
|
| 233 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Dont' save meta boxes for revisions or autosaves. |
|
| 238 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // Check the nonce. |
|
| 243 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 244 | + return; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 248 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // Check user has permission to edit. |
|
| 253 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 258 | + |
|
| 259 | + // We need this save event to run once to avoid potential endless loops. |
|
| 260 | + self::$saved_meta_boxes = true; |
|
| 261 | + |
|
| 262 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 263 | + |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Ensure this is our post type. |
|
| 267 | + $post_types_map = array( |
|
| 268 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 269 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 270 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 271 | + ); |
|
| 272 | + |
|
| 273 | + // Is this our post type? |
|
| 274 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // We need this save event to run once to avoid potential endless loops. |
|
| 279 | + self::$saved_meta_boxes = true; |
|
| 280 | 280 | |
| 281 | - // Save the post. |
|
| 282 | - $class = $post_types_map[ $post->post_type ]; |
|
| 283 | - $class::save( $post_id, $_POST, $post ); |
|
| 281 | + // Save the post. |
|
| 282 | + $class = $post_types_map[ $post->post_type ]; |
|
| 283 | + $class::save( $post_id, $_POST, $post ); |
|
| 284 | 284 | |
| 285 | - } |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | 287 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Metaboxes Admin Class |
@@ -25,35 +25,35 @@ discard block |
||
| 25 | 25 | public static function init() { |
| 26 | 26 | |
| 27 | 27 | // Register metaboxes. |
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2); |
|
| 29 | 29 | |
| 30 | 30 | // Remove metaboxes. |
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
| 32 | 32 | |
| 33 | 33 | // Rename metaboxes. |
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
| 35 | 35 | |
| 36 | 36 | // Save metaboxes. |
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Register core metaboxes. |
| 42 | 42 | */ |
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 43 | + public static function add_meta_boxes($post_type, $post) { |
|
| 44 | 44 | |
| 45 | 45 | // For invoices... |
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 46 | + self::add_invoice_meta_boxes($post_type, $post); |
|
| 47 | 47 | |
| 48 | 48 | // For payment forms. |
| 49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
| 49 | + self::add_payment_form_meta_boxes($post_type); |
|
| 50 | 50 | |
| 51 | 51 | // For invoice items. |
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 52 | + self::add_item_meta_boxes($post_type); |
|
| 53 | 53 | |
| 54 | 54 | // For invoice discounts. |
| 55 | - if ( $post_type == 'wpi_discount' ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 55 | + if ($post_type == 'wpi_discount') { |
|
| 56 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } |
@@ -61,16 +61,16 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * Register core metaboxes. |
| 63 | 63 | */ |
| 64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
| 64 | + protected static function add_payment_form_meta_boxes($post_type) { |
|
| 65 | 65 | |
| 66 | 66 | // For payment forms. |
| 67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
| 67 | + if ($post_type == 'wpi_payment_form') { |
|
| 68 | 68 | |
| 69 | 69 | // Design payment form. |
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 70 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
| 71 | 71 | |
| 72 | 72 | // Payment form information. |
| 73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 73 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | /** |
| 80 | 80 | * Register core metaboxes. |
| 81 | 81 | */ |
| 82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 82 | + protected static function add_item_meta_boxes($post_type) { |
|
| 83 | 83 | |
| 84 | - if ( $post_type == 'wpi_item' ) { |
|
| 84 | + if ($post_type == 'wpi_item') { |
|
| 85 | 85 | |
| 86 | 86 | // Item details. |
| 87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 87 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
| 88 | 88 | |
| 89 | 89 | // If taxes are enabled, register the tax metabox. |
| 90 | - if ( wpinv_use_taxes() ) { |
|
| 91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 90 | + if (wpinv_use_taxes()) { |
|
| 91 | + add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // Item info. |
| 95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 95 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | |
@@ -101,20 +101,20 @@ discard block |
||
| 101 | 101 | /** |
| 102 | 102 | * Register invoice metaboxes. |
| 103 | 103 | */ |
| 104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 104 | + protected static function add_invoice_meta_boxes($post_type, $post) { |
|
| 105 | 105 | |
| 106 | 106 | // For invoices... |
| 107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 108 | - $invoice = new WPInv_Invoice( $post ); |
|
| 107 | + if (getpaid_is_invoice_post_type($post_type)) { |
|
| 108 | + $invoice = new WPInv_Invoice($post); |
|
| 109 | 109 | |
| 110 | 110 | // Resend invoice. |
| 111 | - if ( ! $invoice->is_draft() ) { |
|
| 111 | + if (!$invoice->is_draft()) { |
|
| 112 | 112 | |
| 113 | 113 | add_meta_box( |
| 114 | 114 | 'wpinv-mb-resend-invoice', |
| 115 | 115 | sprintf( |
| 116 | - __( 'Resend %s', 'invoicing' ), |
|
| 117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 116 | + __('Resend %s', 'invoicing'), |
|
| 117 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 118 | 118 | ), |
| 119 | 119 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
| 120 | 120 | $post_type, |
@@ -125,17 +125,17 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Subscriptions. |
| 128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 129 | - if ( ! empty( $subscriptions ) ) { |
|
| 128 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 129 | + if (!empty($subscriptions)) { |
|
| 130 | 130 | |
| 131 | - if ( is_array( $subscriptions ) ) { |
|
| 132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 131 | + if (is_array($subscriptions)) { |
|
| 132 | + add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced'); |
|
| 133 | 133 | } else { |
| 134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 134 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 137 | + if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) { |
|
| 138 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced'); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | } |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | add_meta_box( |
| 145 | 145 | 'wpinv-details', |
| 146 | 146 | sprintf( |
| 147 | - __( '%s Details', 'invoicing' ), |
|
| 148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 147 | + __('%s Details', 'invoicing'), |
|
| 148 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 149 | 149 | ), |
| 150 | 150 | 'GetPaid_Meta_Box_Invoice_Details::output', |
| 151 | 151 | $post_type, |
@@ -153,19 +153,19 @@ discard block |
||
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | 155 | // Payment details. |
| 156 | - if ( ! $invoice->is_draft() ) { |
|
| 157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 156 | + if (!$invoice->is_draft()) { |
|
| 157 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default'); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Billing details. |
| 161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 161 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high'); |
|
| 162 | 162 | |
| 163 | 163 | // Invoice items. |
| 164 | 164 | add_meta_box( |
| 165 | 165 | 'wpinv-items', |
| 166 | 166 | sprintf( |
| 167 | - __( '%s Items', 'invoicing' ), |
|
| 168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 167 | + __('%s Items', 'invoicing'), |
|
| 168 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 169 | 169 | ), |
| 170 | 170 | 'GetPaid_Meta_Box_Invoice_Items::output', |
| 171 | 171 | $post_type, |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | add_meta_box( |
| 178 | 178 | 'wpinv-notes', |
| 179 | 179 | sprintf( |
| 180 | - __( '%s Notes', 'invoicing' ), |
|
| 181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 180 | + __('%s Notes', 'invoicing'), |
|
| 181 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 182 | 182 | ), |
| 183 | 183 | 'WPInv_Meta_Box_Notes::output', |
| 184 | 184 | $post_type, |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | 189 | // Shipping Address. |
| 190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 190 | + if (get_post_meta($invoice->get_id(), 'shipping_address', true)) { |
|
| 191 | + add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high'); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Payment form information. |
| 195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 195 | + if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) { |
|
| 196 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high'); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * Remove some metaboxes. |
| 205 | 205 | */ |
| 206 | 206 | public static function remove_meta_boxes() { |
| 207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 207 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -220,46 +220,46 @@ discard block |
||
| 220 | 220 | * @param int $post_id Post ID. |
| 221 | 221 | * @param object $post Post object. |
| 222 | 222 | */ |
| 223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | - $post_id = absint( $post_id ); |
|
| 225 | - $data = wp_unslash( $_POST ); |
|
| 223 | + public static function save_meta_boxes($post_id, $post) { |
|
| 224 | + $post_id = absint($post_id); |
|
| 225 | + $data = wp_unslash($_POST); |
|
| 226 | 226 | |
| 227 | 227 | // Do not save for ajax requests. |
| 228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 228 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
| 229 | 229 | return; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // $post_id and $post are required |
| 233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 233 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
| 234 | 234 | return; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // Dont' save meta boxes for revisions or autosaves. |
| 238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 238 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Check the nonce. |
| 243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 243 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
| 248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 248 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
| 249 | 249 | return; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // Check user has permission to edit. |
| 253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 253 | + if (!current_user_can('edit_post', $post_id)) { |
|
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 257 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
| 258 | 258 | |
| 259 | 259 | // We need this save event to run once to avoid potential endless loops. |
| 260 | 260 | self::$saved_meta_boxes = true; |
| 261 | 261 | |
| 262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 262 | + return GetPaid_Meta_Box_Invoice_Address::save($post_id); |
|
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | ); |
| 272 | 272 | |
| 273 | 273 | // Is this our post type? |
| 274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 274 | + if (!isset($post_types_map[$post->post_type])) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | self::$saved_meta_boxes = true; |
| 280 | 280 | |
| 281 | 281 | // Save the post. |
| 282 | - $class = $post_types_map[ $post->post_type ]; |
|
| 283 | - $class::save( $post_id, $_POST, $post ); |
|
| 282 | + $class = $post_types_map[$post->post_type]; |
|
| 283 | + $class::save($post_id, $_POST, $post); |
|
| 284 | 284 | |
| 285 | 285 | } |
| 286 | 286 | |
@@ -12,472 +12,472 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $id = 'paypal'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Payment method object. |
|
| 24 | - * |
|
| 25 | - * @var GetPaid_Paypal_Gateway |
|
| 26 | - */ |
|
| 27 | - protected $gateway; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Class constructor. |
|
| 31 | - * |
|
| 32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | - */ |
|
| 34 | - public function __construct( $gateway ) { |
|
| 35 | - $this->gateway = $gateway; |
|
| 36 | - $this->verify_ipn(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Processes ipns and marks payments as complete. |
|
| 41 | - * |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function verify_ipn() { |
|
| 45 | - |
|
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 47 | - |
|
| 48 | - // Validate the IPN. |
|
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Process the IPN. |
|
| 54 | - $posted = wp_unslash( $_POST ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | - |
|
| 57 | - // Abort if it was not paid by our gateway. |
|
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | - |
|
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 68 | - |
|
| 69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | - wp_die( 'Processed', 200 ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Retrieves IPN Invoice. |
|
| 82 | - * |
|
| 83 | - * @param array $posted |
|
| 84 | - * @return WPInv_Invoice |
|
| 85 | - */ |
|
| 86 | - protected function get_ipn_invoice( $posted ) { |
|
| 87 | - |
|
| 88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 89 | - |
|
| 90 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | - |
|
| 93 | - if ( $invoice->exists() ) { |
|
| 94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 95 | - return $invoice; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Check PayPal IPN validity. |
|
| 106 | - */ |
|
| 107 | - protected function validate_ipn() { |
|
| 108 | - |
|
| 109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 110 | - |
|
| 111 | - // Retrieve the associated invoice. |
|
| 112 | - $posted = wp_unslash( $_POST ); |
|
| 113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 114 | - |
|
| 115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Validate the IPN. |
|
| 120 | - $posted['cmd'] = '_notify-validate'; |
|
| 121 | - |
|
| 122 | - // Send back post vars to paypal. |
|
| 123 | - $params = array( |
|
| 124 | - 'body' => $posted, |
|
| 125 | - 'timeout' => 60, |
|
| 126 | - 'httpversion' => '1.1', |
|
| 127 | - 'compress' => false, |
|
| 128 | - 'decompress' => false, |
|
| 129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - // Post back to get a response. |
|
| 133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 134 | - |
|
| 135 | - // Check to see if the request was valid. |
|
| 136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 138 | - return true; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if ( is_wp_error( $response ) ) { |
|
| 142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 15 | + /** |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $id = 'paypal'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Payment method object. |
|
| 24 | + * |
|
| 25 | + * @var GetPaid_Paypal_Gateway |
|
| 26 | + */ |
|
| 27 | + protected $gateway; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Class constructor. |
|
| 31 | + * |
|
| 32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | + */ |
|
| 34 | + public function __construct( $gateway ) { |
|
| 35 | + $this->gateway = $gateway; |
|
| 36 | + $this->verify_ipn(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Processes ipns and marks payments as complete. |
|
| 41 | + * |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function verify_ipn() { |
|
| 45 | + |
|
| 46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 47 | + |
|
| 48 | + // Validate the IPN. |
|
| 49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Process the IPN. |
|
| 54 | + $posted = wp_unslash( $_POST ); |
|
| 55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | + |
|
| 57 | + // Abort if it was not paid by our gateway. |
|
| 58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | + |
|
| 66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 68 | + |
|
| 69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | + wp_die( 'Processed', 200 ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Retrieves IPN Invoice. |
|
| 82 | + * |
|
| 83 | + * @param array $posted |
|
| 84 | + * @return WPInv_Invoice |
|
| 85 | + */ |
|
| 86 | + protected function get_ipn_invoice( $posted ) { |
|
| 87 | + |
|
| 88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 89 | + |
|
| 90 | + if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | + |
|
| 93 | + if ( $invoice->exists() ) { |
|
| 94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 95 | + return $invoice; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 101 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Check PayPal IPN validity. |
|
| 106 | + */ |
|
| 107 | + protected function validate_ipn() { |
|
| 108 | + |
|
| 109 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 110 | + |
|
| 111 | + // Retrieve the associated invoice. |
|
| 112 | + $posted = wp_unslash( $_POST ); |
|
| 113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 114 | + |
|
| 115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Validate the IPN. |
|
| 120 | + $posted['cmd'] = '_notify-validate'; |
|
| 121 | + |
|
| 122 | + // Send back post vars to paypal. |
|
| 123 | + $params = array( |
|
| 124 | + 'body' => $posted, |
|
| 125 | + 'timeout' => 60, |
|
| 126 | + 'httpversion' => '1.1', |
|
| 127 | + 'compress' => false, |
|
| 128 | + 'decompress' => false, |
|
| 129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + // Post back to get a response. |
|
| 133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 134 | + |
|
| 135 | + // Check to see if the request was valid. |
|
| 136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ( is_wp_error( $response ) ) { |
|
| 142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | - return false; |
|
| 148 | - |
|
| 149 | - } |
|
| 146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | + return false; |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Check currency from IPN matches the invoice. |
|
| 153 | - * |
|
| 154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | - * @param string $currency currency to validate. |
|
| 156 | - */ |
|
| 157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 151 | + /** |
|
| 152 | + * Check currency from IPN matches the invoice. |
|
| 153 | + * |
|
| 154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | + * @param string $currency currency to validate. |
|
| 156 | + */ |
|
| 157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 158 | 158 | |
| 159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 160 | 160 | |
| 161 | - /* translators: %s: currency code. */ |
|
| 162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 161 | + /* translators: %s: currency code. */ |
|
| 162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 163 | 163 | |
| 164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | - } |
|
| 164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 168 | - } |
|
| 167 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Check payment amount from IPN matches the invoice. |
|
| 172 | - * |
|
| 173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | - * @param float $amount amount to validate. |
|
| 175 | - */ |
|
| 176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 170 | + /** |
|
| 171 | + * Check payment amount from IPN matches the invoice. |
|
| 172 | + * |
|
| 173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | + * @param float $amount amount to validate. |
|
| 175 | + */ |
|
| 176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 178 | 178 | |
| 179 | - /* translators: %s: Amount. */ |
|
| 180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 179 | + /* translators: %s: Amount. */ |
|
| 180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 181 | 181 | |
| 182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | - } |
|
| 182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 186 | - } |
|
| 185 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Verify receiver email from PayPal. |
|
| 190 | - * |
|
| 191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | - * @param string $receiver_email Email to validate. |
|
| 193 | - */ |
|
| 194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 188 | + /** |
|
| 189 | + * Verify receiver email from PayPal. |
|
| 190 | + * |
|
| 191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | + * @param string $receiver_email Email to validate. |
|
| 193 | + */ |
|
| 194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 196 | 196 | |
| 197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 199 | 199 | |
| 200 | - /* translators: %s: email address . */ |
|
| 201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 200 | + /* translators: %s: email address . */ |
|
| 201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 202 | 202 | |
| 203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | - } |
|
| 203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 207 | - } |
|
| 206 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Handles one time payments. |
|
| 211 | - * |
|
| 212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | - * @param array $posted Posted data. |
|
| 214 | - */ |
|
| 215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 209 | + /** |
|
| 210 | + * Handles one time payments. |
|
| 211 | + * |
|
| 212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | + * @param array $posted Posted data. |
|
| 214 | + */ |
|
| 215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 216 | 216 | |
| 217 | - // Collect payment details |
|
| 218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 217 | + // Collect payment details |
|
| 218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 220 | 220 | |
| 221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | - |
|
| 224 | - // Update the transaction id. |
|
| 225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | - $invoice->save(); |
|
| 228 | - } |
|
| 221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | + |
|
| 224 | + // Update the transaction id. |
|
| 225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | + $invoice->save(); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - // Process a refund. |
|
| 231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 230 | + // Process a refund. |
|
| 231 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 232 | 232 | |
| 233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 233 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 234 | 234 | |
| 235 | - if ( ! $invoice->is_refunded() ) { |
|
| 236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | - } |
|
| 235 | + if ( ! $invoice->is_refunded() ) { |
|
| 236 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
| 240 | - } |
|
| 239 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - // Process payments. |
|
| 243 | - if ( $payment_status == 'completed' ) { |
|
| 242 | + // Process payments. |
|
| 243 | + if ( $payment_status == 'completed' ) { |
|
| 244 | 244 | |
| 245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 247 | - } |
|
| 245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 249 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 250 | 250 | |
| 251 | - $note = ''; |
|
| 251 | + $note = ''; |
|
| 252 | 252 | |
| 253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | - } |
|
| 253 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | - } |
|
| 257 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 261 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 263 | 263 | |
| 264 | - } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - // Pending payments. |
|
| 267 | - if ( $payment_status == 'pending' ) { |
|
| 266 | + // Pending payments. |
|
| 267 | + if ( $payment_status == 'pending' ) { |
|
| 268 | 268 | |
| 269 | - /* translators: %s: pending reason. */ |
|
| 270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 269 | + /* translators: %s: pending reason. */ |
|
| 270 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 271 | 271 | |
| 272 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 273 | - } |
|
| 272 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /* translators: %s: payment status. */ |
|
| 276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 275 | + /* translators: %s: payment status. */ |
|
| 276 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 277 | 277 | |
| 278 | - } |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Handles one time payments. |
|
| 282 | - * |
|
| 283 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | - * @param array $posted Posted data. |
|
| 285 | - */ |
|
| 286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | - } |
|
| 280 | + /** |
|
| 281 | + * Handles one time payments. |
|
| 282 | + * |
|
| 283 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | + * @param array $posted Posted data. |
|
| 285 | + */ |
|
| 286 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Handles subscription sign ups. |
|
| 292 | - * |
|
| 293 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | - * @param array $posted Posted data. |
|
| 295 | - */ |
|
| 296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 290 | + /** |
|
| 291 | + * Handles subscription sign ups. |
|
| 292 | + * |
|
| 293 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | + * @param array $posted Posted data. |
|
| 295 | + */ |
|
| 296 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 297 | 297 | |
| 298 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
| 298 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
| 299 | 299 | |
| 300 | - // Make sure the invoice has a subscription. |
|
| 301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 300 | + // Make sure the invoice has a subscription. |
|
| 301 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 302 | 302 | |
| 303 | - if ( empty( $subscription ) ) { |
|
| 304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 305 | - } |
|
| 303 | + if ( empty( $subscription ) ) { |
|
| 304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 307 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 308 | 308 | |
| 309 | - // Validate the IPN. |
|
| 310 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 311 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 312 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 309 | + // Validate the IPN. |
|
| 310 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 311 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 312 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 313 | 313 | |
| 314 | - // Activate the subscription. |
|
| 315 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 316 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 317 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 318 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 319 | - $subscription->activate(); |
|
| 314 | + // Activate the subscription. |
|
| 315 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 316 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 317 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 318 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 319 | + $subscription->activate(); |
|
| 320 | 320 | |
| 321 | - // Set the transaction id. |
|
| 322 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 323 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 324 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 325 | - } |
|
| 321 | + // Set the transaction id. |
|
| 322 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 323 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 324 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - // Update the payment status. |
|
| 328 | - $invoice->mark_paid(); |
|
| 327 | + // Update the payment status. |
|
| 328 | + $invoice->mark_paid(); |
|
| 329 | 329 | |
| 330 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 330 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 331 | 331 | |
| 332 | - wpinv_error_log( 'Subscription started.', false ); |
|
| 333 | - } |
|
| 332 | + wpinv_error_log( 'Subscription started.', false ); |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * Handles subscription renewals. |
|
| 337 | - * |
|
| 338 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 339 | - * @param array $posted Posted data. |
|
| 340 | - */ |
|
| 341 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 335 | + /** |
|
| 336 | + * Handles subscription renewals. |
|
| 337 | + * |
|
| 338 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 339 | + * @param array $posted Posted data. |
|
| 340 | + */ |
|
| 341 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 342 | 342 | |
| 343 | - // Make sure the invoice has a subscription. |
|
| 344 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 343 | + // Make sure the invoice has a subscription. |
|
| 344 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 345 | 345 | |
| 346 | - if ( empty( $subscription ) ) { |
|
| 347 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 348 | - } |
|
| 346 | + if ( empty( $subscription ) ) { |
|
| 347 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 350 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 351 | 351 | |
| 352 | - // PayPal sends a subscr_payment for the first payment too. |
|
| 353 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 354 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 355 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 356 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 357 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 358 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 352 | + // PayPal sends a subscr_payment for the first payment too. |
|
| 353 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 354 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 355 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 356 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 357 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 358 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 359 | 359 | |
| 360 | - foreach( $dates as $date ) { |
|
| 360 | + foreach( $dates as $date ) { |
|
| 361 | 361 | |
| 362 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 363 | - continue; |
|
| 364 | - } |
|
| 362 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 363 | + continue; |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 367 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 368 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 369 | - } |
|
| 366 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 367 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 368 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - return $invoice->mark_paid(); |
|
| 372 | - |
|
| 373 | - } |
|
| 371 | + return $invoice->mark_paid(); |
|
| 372 | + |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 376 | - |
|
| 377 | - // Abort if the payment is already recorded. |
|
| 378 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 379 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $args = array( |
|
| 383 | - 'transaction_id' => $posted['txn_id'], |
|
| 384 | - 'gateway' => $this->id, |
|
| 385 | - ); |
|
| 386 | - |
|
| 387 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 375 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 376 | + |
|
| 377 | + // Abort if the payment is already recorded. |
|
| 378 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 379 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $args = array( |
|
| 383 | + 'transaction_id' => $posted['txn_id'], |
|
| 384 | + 'gateway' => $this->id, |
|
| 385 | + ); |
|
| 386 | + |
|
| 387 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 388 | 388 | |
| 389 | - if ( empty( $invoice ) ) { |
|
| 390 | - return; |
|
| 391 | - } |
|
| 389 | + if ( empty( $invoice ) ) { |
|
| 390 | + return; |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 393 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 395 | 395 | |
| 396 | - $subscription->renew(); |
|
| 397 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
| 396 | + $subscription->renew(); |
|
| 397 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
| 398 | 398 | |
| 399 | - } |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - /** |
|
| 402 | - * Handles subscription cancelations. |
|
| 403 | - * |
|
| 404 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 405 | - */ |
|
| 406 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 401 | + /** |
|
| 402 | + * Handles subscription cancelations. |
|
| 403 | + * |
|
| 404 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 405 | + */ |
|
| 406 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 407 | 407 | |
| 408 | - // Make sure the invoice has a subscription. |
|
| 409 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 410 | - |
|
| 411 | - if ( empty( $subscription ) ) { |
|
| 412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 416 | - $subscription->cancel(); |
|
| 417 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 408 | + // Make sure the invoice has a subscription. |
|
| 409 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 410 | + |
|
| 411 | + if ( empty( $subscription ) ) { |
|
| 412 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 416 | + $subscription->cancel(); |
|
| 417 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 418 | 418 | |
| 419 | - } |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * Handles subscription completions. |
|
| 423 | - * |
|
| 424 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 425 | - * @param array $posted Posted data. |
|
| 426 | - */ |
|
| 427 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 421 | + /** |
|
| 422 | + * Handles subscription completions. |
|
| 423 | + * |
|
| 424 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 425 | + * @param array $posted Posted data. |
|
| 426 | + */ |
|
| 427 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 428 | 428 | |
| 429 | - // Make sure the invoice has a subscription. |
|
| 430 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 429 | + // Make sure the invoice has a subscription. |
|
| 430 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 431 | 431 | |
| 432 | - if ( empty( $subscription ) ) { |
|
| 433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 434 | - } |
|
| 432 | + if ( empty( $subscription ) ) { |
|
| 433 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 437 | - $subscription->complete(); |
|
| 438 | - wpinv_error_log( 'Subscription completed.', false ); |
|
| 436 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 437 | + $subscription->complete(); |
|
| 438 | + wpinv_error_log( 'Subscription completed.', false ); |
|
| 439 | 439 | |
| 440 | - } |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - /** |
|
| 443 | - * Handles subscription fails. |
|
| 444 | - * |
|
| 445 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 446 | - * @param array $posted Posted data. |
|
| 447 | - */ |
|
| 448 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 442 | + /** |
|
| 443 | + * Handles subscription fails. |
|
| 444 | + * |
|
| 445 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 446 | + * @param array $posted Posted data. |
|
| 447 | + */ |
|
| 448 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 449 | 449 | |
| 450 | - // Make sure the invoice has a subscription. |
|
| 451 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 450 | + // Make sure the invoice has a subscription. |
|
| 451 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 452 | 452 | |
| 453 | - if ( empty( $subscription ) ) { |
|
| 454 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 455 | - } |
|
| 453 | + if ( empty( $subscription ) ) { |
|
| 454 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 458 | - $subscription->failing(); |
|
| 459 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 457 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 458 | + $subscription->failing(); |
|
| 459 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 460 | 460 | |
| 461 | - } |
|
| 461 | + } |
|
| 462 | 462 | |
| 463 | - /** |
|
| 464 | - * Handles subscription suspensions. |
|
| 465 | - * |
|
| 466 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 467 | - * @param array $posted Posted data. |
|
| 468 | - */ |
|
| 469 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 463 | + /** |
|
| 464 | + * Handles subscription suspensions. |
|
| 465 | + * |
|
| 466 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 467 | + * @param array $posted Posted data. |
|
| 468 | + */ |
|
| 469 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 470 | 470 | |
| 471 | - // Make sure the invoice has a subscription. |
|
| 472 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 471 | + // Make sure the invoice has a subscription. |
|
| 472 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 473 | 473 | |
| 474 | - if ( empty( $subscription ) ) { |
|
| 475 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 479 | - $subscription->cancel(); |
|
| 480 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 481 | - } |
|
| 474 | + if ( empty( $subscription ) ) { |
|
| 475 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 479 | + $subscription->cancel(); |
|
| 480 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | 483 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
| 33 | 33 | */ |
| 34 | - public function __construct( $gateway ) { |
|
| 34 | + public function __construct($gateway) { |
|
| 35 | 35 | $this->gateway = $gateway; |
| 36 | 36 | $this->verify_ipn(); |
| 37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function verify_ipn() { |
| 45 | 45 | |
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
| 47 | 47 | |
| 48 | 48 | // Validate the IPN. |
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 50 | + wp_die('PayPal IPN Request Failure', 500); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Process the IPN. |
| 54 | - $posted = wp_unslash( $_POST ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 54 | + $posted = wp_unslash($_POST); |
|
| 55 | + $invoice = $this->get_ipn_invoice($posted); |
|
| 56 | 56 | |
| 57 | 57 | // Abort if it was not paid by our gateway. |
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 58 | + if ($this->id != $invoice->get_gateway()) { |
|
| 59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
| 60 | + wp_die('Invoice not paid via PayPal', 200); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
| 64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
| 65 | 65 | |
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
| 67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
| 68 | 68 | |
| 69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | - wp_die( 'Processed', 200 ); |
|
| 69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
| 70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
| 71 | + wpinv_error_log('Done processing IPN', false); |
|
| 72 | + wp_die('Processed', 200); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
| 76 | + wp_die('Unsupported IPN type', 200); |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | |
@@ -83,22 +83,22 @@ discard block |
||
| 83 | 83 | * @param array $posted |
| 84 | 84 | * @return WPInv_Invoice |
| 85 | 85 | */ |
| 86 | - protected function get_ipn_invoice( $posted ) { |
|
| 86 | + protected function get_ipn_invoice($posted) { |
|
| 87 | 87 | |
| 88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
| 89 | 89 | |
| 90 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 90 | + if (!empty($posted['custom'])) { |
|
| 91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
| 92 | 92 | |
| 93 | - if ( $invoice->exists() ) { |
|
| 94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 93 | + if ($invoice->exists()) { |
|
| 94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
| 95 | 95 | return $invoice; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 100 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
| 101 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | protected function validate_ipn() { |
| 108 | 108 | |
| 109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 109 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
| 110 | 110 | |
| 111 | 111 | // Retrieve the associated invoice. |
| 112 | - $posted = wp_unslash( $_POST ); |
|
| 113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 112 | + $posted = wp_unslash($_POST); |
|
| 113 | + $invoice = $this->get_ipn_invoice($posted); |
|
| 114 | 114 | |
| 115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
| 116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // Validate the IPN. |
@@ -130,20 +130,20 @@ discard block |
||
| 130 | 130 | ); |
| 131 | 131 | |
| 132 | 132 | // Post back to get a response. |
| 133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
| 134 | 134 | |
| 135 | 135 | // Check to see if the request was valid. |
| 136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
| 137 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
| 138 | 138 | return true; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( is_wp_error( $response ) ) { |
|
| 142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 141 | + if (is_wp_error($response)) { |
|
| 142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
| 147 | 147 | return false; |
| 148 | 148 | |
| 149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
| 154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
| 155 | 155 | * @param string $currency currency to validate. |
| 156 | 156 | */ |
| 157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
| 158 | 158 | |
| 159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
| 160 | 160 | |
| 161 | 161 | /* translators: %s: currency code. */ |
| 162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
| 163 | 163 | |
| 164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 167 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
| 174 | 174 | * @param float $amount amount to validate. |
| 175 | 175 | */ |
| 176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
| 177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
| 178 | 178 | |
| 179 | 179 | /* translators: %s: Amount. */ |
| 180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
| 181 | 181 | |
| 182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 182 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 185 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
| 191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
| 192 | 192 | * @param string $receiver_email Email to validate. |
| 193 | 193 | */ |
| 194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
| 195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
| 196 | 196 | |
| 197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
| 198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
| 199 | 199 | |
| 200 | 200 | /* translators: %s: email address . */ |
| 201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
| 202 | 202 | |
| 203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 203 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 206 | + wpinv_error_log('Validated PayPal Email', false); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -212,68 +212,68 @@ discard block |
||
| 212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
| 213 | 213 | * @param array $posted Posted data. |
| 214 | 214 | */ |
| 215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
| 216 | 216 | |
| 217 | 217 | // Collect payment details |
| 218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 218 | + $payment_status = strtolower($posted['payment_status']); |
|
| 219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
| 220 | 220 | |
| 221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
| 222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 223 | 223 | |
| 224 | 224 | // Update the transaction id. |
| 225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 225 | + if (!empty($posted['txn_id'])) { |
|
| 226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
| 227 | 227 | $invoice->save(); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // Process a refund. |
| 231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 231 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 232 | 232 | |
| 233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 233 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
| 234 | 234 | |
| 235 | - if ( ! $invoice->is_refunded() ) { |
|
| 236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 235 | + if (!$invoice->is_refunded()) { |
|
| 236 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
| 239 | + return wpinv_error_log($posted['reason_code'], false); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Process payments. |
| 243 | - if ( $payment_status == 'completed' ) { |
|
| 243 | + if ($payment_status == 'completed') { |
|
| 244 | 244 | |
| 245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 245 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
| 246 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 249 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
| 250 | 250 | |
| 251 | 251 | $note = ''; |
| 252 | 252 | |
| 253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 253 | + if (!empty($posted['mc_fee'])) { |
|
| 254 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 257 | + if (!empty($posted['payer_status'])) { |
|
| 258 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 261 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
| 262 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Pending payments. |
| 267 | - if ( $payment_status == 'pending' ) { |
|
| 267 | + if ($payment_status == 'pending') { |
|
| 268 | 268 | |
| 269 | 269 | /* translators: %s: pending reason. */ |
| 270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 270 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
| 271 | 271 | |
| 272 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 272 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /* translators: %s: payment status. */ |
| 276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 276 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
| 277 | 277 | |
| 278 | 278 | } |
| 279 | 279 | |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | * @param WPInv_Invoice $invoice Invoice object. |
| 284 | 284 | * @param array $posted Posted data. |
| 285 | 285 | */ |
| 286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 286 | + protected function ipn_txn_cart($invoice, $posted) { |
|
| 287 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -293,43 +293,43 @@ discard block |
||
| 293 | 293 | * @param WPInv_Invoice $invoice Invoice object. |
| 294 | 294 | * @param array $posted Posted data. |
| 295 | 295 | */ |
| 296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 296 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
| 297 | 297 | |
| 298 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
| 298 | + wpinv_error_log('Processing subscription signup', false); |
|
| 299 | 299 | |
| 300 | 300 | // Make sure the invoice has a subscription. |
| 301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 301 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
| 302 | 302 | |
| 303 | - if ( empty( $subscription ) ) { |
|
| 304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 303 | + if (empty($subscription)) { |
|
| 304 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 307 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
| 308 | 308 | |
| 309 | 309 | // Validate the IPN. |
| 310 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 311 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 312 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 310 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
| 311 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
| 312 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 313 | 313 | |
| 314 | 314 | // Activate the subscription. |
| 315 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 316 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 317 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 318 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 315 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
| 316 | + $subscription->set_date_created(current_time('mysql')); |
|
| 317 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
| 318 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
| 319 | 319 | $subscription->activate(); |
| 320 | 320 | |
| 321 | 321 | // Set the transaction id. |
| 322 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 323 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 324 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 322 | + if (!empty($posted['txn_id'])) { |
|
| 323 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
| 324 | + $invoice->set_transaction_id($posted['txn_id']); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // Update the payment status. |
| 328 | 328 | $invoice->mark_paid(); |
| 329 | 329 | |
| 330 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 330 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 331 | 331 | |
| 332 | - wpinv_error_log( 'Subscription started.', false ); |
|
| 332 | + wpinv_error_log('Subscription started.', false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -338,45 +338,45 @@ discard block |
||
| 338 | 338 | * @param WPInv_Invoice $invoice Invoice object. |
| 339 | 339 | * @param array $posted Posted data. |
| 340 | 340 | */ |
| 341 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 341 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
| 342 | 342 | |
| 343 | 343 | // Make sure the invoice has a subscription. |
| 344 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 344 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 345 | 345 | |
| 346 | - if ( empty( $subscription ) ) { |
|
| 347 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 346 | + if (empty($subscription)) { |
|
| 347 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 350 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
| 351 | 351 | |
| 352 | 352 | // PayPal sends a subscr_payment for the first payment too. |
| 353 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 354 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 355 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 356 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 357 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 358 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 353 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
| 354 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
| 355 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
| 356 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
| 357 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
| 358 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
| 359 | 359 | |
| 360 | - foreach( $dates as $date ) { |
|
| 360 | + foreach ($dates as $date) { |
|
| 361 | 361 | |
| 362 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 362 | + if ($date !== $today_date && $date !== $payment_date) { |
|
| 363 | 363 | continue; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 367 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 368 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 366 | + if (!empty($posted['txn_id'])) { |
|
| 367 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
| 368 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | return $invoice->mark_paid(); |
| 372 | 372 | |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 375 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
| 376 | 376 | |
| 377 | 377 | // Abort if the payment is already recorded. |
| 378 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 379 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
| 378 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
| 379 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | $args = array( |
@@ -384,17 +384,17 @@ discard block |
||
| 384 | 384 | 'gateway' => $this->id, |
| 385 | 385 | ); |
| 386 | 386 | |
| 387 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 387 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
| 388 | 388 | |
| 389 | - if ( empty( $invoice ) ) { |
|
| 389 | + if (empty($invoice)) { |
|
| 390 | 390 | return; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 393 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
| 394 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 395 | 395 | |
| 396 | 396 | $subscription->renew(); |
| 397 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
| 397 | + wpinv_error_log('Subscription renewed.', false); |
|
| 398 | 398 | |
| 399 | 399 | } |
| 400 | 400 | |
@@ -403,18 +403,18 @@ discard block |
||
| 403 | 403 | * |
| 404 | 404 | * @param WPInv_Invoice $invoice Invoice object. |
| 405 | 405 | */ |
| 406 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 406 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
| 407 | 407 | |
| 408 | 408 | // Make sure the invoice has a subscription. |
| 409 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 409 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 410 | 410 | |
| 411 | - if ( empty( $subscription ) ) { |
|
| 412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 411 | + if (empty($subscription)) { |
|
| 412 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 415 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
| 416 | 416 | $subscription->cancel(); |
| 417 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 417 | + wpinv_error_log('Subscription cancelled.', false); |
|
| 418 | 418 | |
| 419 | 419 | } |
| 420 | 420 | |
@@ -424,18 +424,18 @@ discard block |
||
| 424 | 424 | * @param WPInv_Invoice $invoice Invoice object. |
| 425 | 425 | * @param array $posted Posted data. |
| 426 | 426 | */ |
| 427 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 427 | + protected function ipn_txn_subscr_eot($invoice) { |
|
| 428 | 428 | |
| 429 | 429 | // Make sure the invoice has a subscription. |
| 430 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 430 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 431 | 431 | |
| 432 | - if ( empty( $subscription ) ) { |
|
| 433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 432 | + if (empty($subscription)) { |
|
| 433 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 436 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
| 437 | 437 | $subscription->complete(); |
| 438 | - wpinv_error_log( 'Subscription completed.', false ); |
|
| 438 | + wpinv_error_log('Subscription completed.', false); |
|
| 439 | 439 | |
| 440 | 440 | } |
| 441 | 441 | |
@@ -445,18 +445,18 @@ discard block |
||
| 445 | 445 | * @param WPInv_Invoice $invoice Invoice object. |
| 446 | 446 | * @param array $posted Posted data. |
| 447 | 447 | */ |
| 448 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 448 | + protected function ipn_txn_subscr_failed($invoice) { |
|
| 449 | 449 | |
| 450 | 450 | // Make sure the invoice has a subscription. |
| 451 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 451 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 452 | 452 | |
| 453 | - if ( empty( $subscription ) ) { |
|
| 454 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 453 | + if (empty($subscription)) { |
|
| 454 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 457 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
| 458 | 458 | $subscription->failing(); |
| 459 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 459 | + wpinv_error_log('Subscription marked as failing.', false); |
|
| 460 | 460 | |
| 461 | 461 | } |
| 462 | 462 | |
@@ -466,18 +466,18 @@ discard block |
||
| 466 | 466 | * @param WPInv_Invoice $invoice Invoice object. |
| 467 | 467 | * @param array $posted Posted data. |
| 468 | 468 | */ |
| 469 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 469 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
| 470 | 470 | |
| 471 | 471 | // Make sure the invoice has a subscription. |
| 472 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 472 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 473 | 473 | |
| 474 | - if ( empty( $subscription ) ) { |
|
| 475 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 474 | + if (empty($subscription)) { |
|
| 475 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 478 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
| 479 | 479 | $subscription->cancel(); |
| 480 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 480 | + wpinv_error_log('Subscription cancelled.', false); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | } |
@@ -15,125 +15,125 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $data_store_name = 'subscription'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'subscription'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'customer_id' => 0, |
|
| 40 | - 'frequency' => 1, |
|
| 41 | - 'period' => 'D', |
|
| 42 | - 'initial_amount' => null, |
|
| 43 | - 'recurring_amount' => null, |
|
| 44 | - 'bill_times' => 0, |
|
| 45 | - 'transaction_id' => '', |
|
| 46 | - 'parent_payment_id' => null, |
|
| 47 | - 'product_id' => 0, |
|
| 48 | - 'created' => '0000-00-00 00:00:00', |
|
| 49 | - 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | - 'trial_period' => '', |
|
| 51 | - 'status' => 'pending', |
|
| 52 | - 'profile_id' => '', |
|
| 53 | - 'gateway' => '', |
|
| 54 | - 'customer' => '', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Stores the status transition information. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - protected $status_transition = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | - * |
|
| 68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | - * @param bool $deprecated |
|
| 70 | - */ |
|
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | - |
|
| 73 | - parent::__construct( $subscription ); |
|
| 74 | - |
|
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 83 | - } else { |
|
| 84 | - $this->set_object_read( true ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Load the datastore. |
|
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | - |
|
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @static |
|
| 101 | - * @param string $value |
|
| 102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | - * @since 1.0.19 |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $data_store_name = 'subscription'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'subscription'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'customer_id' => 0, |
|
| 40 | + 'frequency' => 1, |
|
| 41 | + 'period' => 'D', |
|
| 42 | + 'initial_amount' => null, |
|
| 43 | + 'recurring_amount' => null, |
|
| 44 | + 'bill_times' => 0, |
|
| 45 | + 'transaction_id' => '', |
|
| 46 | + 'parent_payment_id' => null, |
|
| 47 | + 'product_id' => 0, |
|
| 48 | + 'created' => '0000-00-00 00:00:00', |
|
| 49 | + 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | + 'trial_period' => '', |
|
| 51 | + 'status' => 'pending', |
|
| 52 | + 'profile_id' => '', |
|
| 53 | + 'gateway' => '', |
|
| 54 | + 'customer' => '', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Stores the status transition information. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + protected $status_transition = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | + * |
|
| 68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | + * @param bool $deprecated |
|
| 70 | + */ |
|
| 71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | + |
|
| 73 | + parent::__construct( $subscription ); |
|
| 74 | + |
|
| 75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | + $this->set_id( $subscription ); |
|
| 77 | + } elseif ( $subscription instanceof self ) { |
|
| 78 | + $this->set_id( $subscription->get_id() ); |
|
| 79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | + $this->set_id( $subscription_id ); |
|
| 81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | + $this->set_id( $subscription->id ); |
|
| 83 | + } else { |
|
| 84 | + $this->set_object_read( true ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Load the datastore. |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | + |
|
| 90 | + if ( $this->get_id() > 0 ) { |
|
| 91 | + $this->data_store->read( $this ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @static |
|
| 101 | + * @param string $value |
|
| 102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | + * @since 1.0.19 |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - // Trim the value. |
|
| 110 | - $value = trim( $value ); |
|
| 109 | + // Trim the value. |
|
| 110 | + $value = trim( $value ); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 113 | - return 0; |
|
| 114 | - } |
|
| 112 | + if ( empty( $value ) ) { |
|
| 113 | + return 0; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 117 | - $field = 'parent_payment_id'; |
|
| 118 | - } |
|
| 116 | + if ( 'invoice_id' == $field ) { |
|
| 117 | + $field = 'parent_payment_id'; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | // Valid fields. |
| 121 | 121 | $fields = array( |
| 122 | - 'parent_payment_id', |
|
| 123 | - 'transaction_id', |
|
| 124 | - 'profile_id' |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Ensure a field has been passed. |
|
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Maybe retrieve from the cache. |
|
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 135 | - return $subscription_id; |
|
| 136 | - } |
|
| 122 | + 'parent_payment_id', |
|
| 123 | + 'transaction_id', |
|
| 124 | + 'profile_id' |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Ensure a field has been passed. |
|
| 128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Maybe retrieve from the cache. |
|
| 133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | + if ( ! empty( $subscription_id ) ) { |
|
| 135 | + return $subscription_id; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
| 141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 145 | - return 0; |
|
| 146 | - } |
|
| 144 | + if ( empty( $subscription_id ) ) { |
|
| 145 | + return 0; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - // Update the cache with our data. |
|
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 148 | + // Update the cache with our data. |
|
| 149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 150 | 150 | |
| 151 | - return $subscription_id; |
|
| 152 | - } |
|
| 151 | + return $subscription_id; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | + /** |
|
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | - } |
|
| 158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | + /** |
|
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | 167 | public function _isset( $key ) { |
| 168 | 168 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /* |
|
| 171 | + /* |
|
| 172 | 172 | |-------------------------------------------------------------------------- |
| 173 | 173 | | CRUD methods |
| 174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,545 +177,545 @@ discard block |
||
| 177 | 177 | | |
| 178 | 178 | */ |
| 179 | 179 | |
| 180 | - /* |
|
| 181 | - |-------------------------------------------------------------------------- |
|
| 182 | - | Getters |
|
| 183 | - |-------------------------------------------------------------------------- |
|
| 184 | - */ |
|
| 180 | + /* |
|
| 181 | + |-------------------------------------------------------------------------- |
|
| 182 | + | Getters |
|
| 183 | + |-------------------------------------------------------------------------- |
|
| 184 | + */ |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Get customer id. |
|
| 188 | + * |
|
| 189 | + * @since 1.0.19 |
|
| 190 | + * @param string $context View or edit context. |
|
| 191 | + * @return int |
|
| 192 | + */ |
|
| 193 | + public function get_customer_id( $context = 'view' ) { |
|
| 194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Get customer information. |
|
| 199 | + * |
|
| 200 | + * @since 1.0.19 |
|
| 201 | + * @param string $context View or edit context. |
|
| 202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | + */ |
|
| 204 | + public function get_customer( $context = 'view' ) { |
|
| 205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get parent invoice id. |
|
| 210 | + * |
|
| 211 | + * @since 1.0.19 |
|
| 212 | + * @param string $context View or edit context. |
|
| 213 | + * @return int |
|
| 214 | + */ |
|
| 215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Alias for self::get_parent_invoice_id(). |
|
| 221 | + * |
|
| 222 | + * @since 1.0.19 |
|
| 223 | + * @param string $context View or edit context. |
|
| 224 | + * @return int |
|
| 225 | + */ |
|
| 226 | + public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | + return $this->get_parent_invoice_id( $context ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Alias for self::get_parent_invoice_id(). |
|
| 232 | + * |
|
| 233 | + * @since 1.0.0 |
|
| 234 | + * @return int |
|
| 235 | + */ |
|
| 236 | + public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | + return $this->get_parent_invoice_id( $context ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Get parent invoice. |
|
| 242 | + * |
|
| 243 | + * @since 1.0.19 |
|
| 244 | + * @param string $context View or edit context. |
|
| 245 | + * @return WPInv_Invoice |
|
| 246 | + */ |
|
| 247 | + public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Alias for self::get_parent_invoice(). |
|
| 253 | + * |
|
| 254 | + * @since 1.0.19 |
|
| 255 | + * @param string $context View or edit context. |
|
| 256 | + * @return WPInv_Invoice |
|
| 257 | + */ |
|
| 258 | + public function get_parent_payment( $context = 'view' ) { |
|
| 259 | + return $this->get_parent_invoice( $context ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Get subscription's product id. |
|
| 264 | + * |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @param string $context View or edit context. |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function get_product_id( $context = 'view' ) { |
|
| 270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Get the subscription product. |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @param string $context View or edit context. |
|
| 278 | + * @return WPInv_Item |
|
| 279 | + */ |
|
| 280 | + public function get_product( $context = 'view' ) { |
|
| 281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Get parent invoice's gateway. |
|
| 286 | + * |
|
| 287 | + * Here for backwards compatibility. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @param string $context View or edit context. |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function get_gateway( $context = 'view' ) { |
|
| 294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Get the period of a renewal. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @param string $context View or edit context. |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function get_period( $context = 'view' ) { |
|
| 305 | + return $this->get_prop( 'period', $context ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Get number of periods each renewal is valid for. |
|
| 310 | + * |
|
| 311 | + * @since 1.0.19 |
|
| 312 | + * @param string $context View or edit context. |
|
| 313 | + * @return int |
|
| 314 | + */ |
|
| 315 | + public function get_frequency( $context = 'view' ) { |
|
| 316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the initial amount for the subscription. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @param string $context View or edit context. |
|
| 324 | + * @return float |
|
| 325 | + */ |
|
| 326 | + public function get_initial_amount( $context = 'view' ) { |
|
| 327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get the recurring amount for the subscription. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return float |
|
| 336 | + */ |
|
| 337 | + public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Get number of times that this subscription can be renewed. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + * @param string $context View or edit context. |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function get_bill_times( $context = 'view' ) { |
|
| 349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Get transaction id of this subscription's parent invoice. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param string $context View or edit context. |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + public function get_transaction_id( $context = 'view' ) { |
|
| 360 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Get the date that the subscription was created. |
|
| 365 | + * |
|
| 366 | + * @since 1.0.19 |
|
| 367 | + * @param string $context View or edit context. |
|
| 368 | + * @return string |
|
| 369 | + */ |
|
| 370 | + public function get_created( $context = 'view' ) { |
|
| 371 | + return $this->get_prop( 'created', $context ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Alias for self::get_created(). |
|
| 376 | + * |
|
| 377 | + * @since 1.0.19 |
|
| 378 | + * @param string $context View or edit context. |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function get_date_created( $context = 'view' ) { |
|
| 382 | + return $this->get_created( $context ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Retrieves the creation date in a timestamp |
|
| 387 | + * |
|
| 388 | + * @since 1.0.0 |
|
| 389 | + * @return int |
|
| 390 | + */ |
|
| 391 | + public function get_time_created() { |
|
| 392 | + $created = $this->get_date_created(); |
|
| 393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get GMT date when the subscription was created. |
|
| 398 | + * |
|
| 399 | + * @since 1.0.19 |
|
| 400 | + * @param string $context View or edit context. |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | + $date = $this->get_date_created( $context ); |
|
| 405 | + |
|
| 406 | + if ( $date ) { |
|
| 407 | + $date = get_gmt_from_date( $date ); |
|
| 408 | + } |
|
| 409 | + return $date; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get the date that the subscription will renew. |
|
| 414 | + * |
|
| 415 | + * @since 1.0.19 |
|
| 416 | + * @param string $context View or edit context. |
|
| 417 | + * @return string |
|
| 418 | + */ |
|
| 419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | + return $this->get_prop( 'expiration', $context ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Alias for self::get_next_renewal_date(). |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + * @param string $context View or edit context. |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function get_expiration( $context = 'view' ) { |
|
| 431 | + return $this->get_next_renewal_date( $context ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Retrieves the expiration date in a timestamp |
|
| 436 | + * |
|
| 437 | + * @since 1.0.0 |
|
| 438 | + * @return int |
|
| 439 | + */ |
|
| 440 | + public function get_expiration_time() { |
|
| 441 | + $expiration = $this->get_expiration(); |
|
| 442 | + |
|
| 443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | + return current_time( 'timestamp' ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Get GMT date when the subscription will renew. |
|
| 453 | + * |
|
| 454 | + * @since 1.0.19 |
|
| 455 | + * @param string $context View or edit context. |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | + $date = $this->get_next_renewal_date( $context ); |
|
| 460 | + |
|
| 461 | + if ( $date ) { |
|
| 462 | + $date = get_gmt_from_date( $date ); |
|
| 463 | + } |
|
| 464 | + return $date; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Get the subscription's trial period. |
|
| 469 | + * |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + * @param string $context View or edit context. |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function get_trial_period( $context = 'view' ) { |
|
| 475 | + return $this->get_prop( 'trial_period', $context ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Get the subscription's status. |
|
| 480 | + * |
|
| 481 | + * @since 1.0.19 |
|
| 482 | + * @param string $context View or edit context. |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + public function get_status( $context = 'view' ) { |
|
| 486 | + return $this->get_prop( 'status', $context ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Get the subscription's profile id. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $context View or edit context. |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + public function get_profile_id( $context = 'view' ) { |
|
| 497 | + return $this->get_prop( 'profile_id', $context ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /* |
|
| 501 | + |-------------------------------------------------------------------------- |
|
| 502 | + | Setters |
|
| 503 | + |-------------------------------------------------------------------------- |
|
| 504 | + */ |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Set customer id. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param int $value The customer's id. |
|
| 511 | + */ |
|
| 512 | + public function set_customer_id( $value ) { |
|
| 513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Set parent invoice id. |
|
| 518 | + * |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + * @param int $value The parent invoice id. |
|
| 521 | + */ |
|
| 522 | + public function set_parent_invoice_id( $value ) { |
|
| 523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Alias for self::set_parent_invoice_id(). |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + * @param int $value The parent invoice id. |
|
| 531 | + */ |
|
| 532 | + public function set_parent_payment_id( $value ) { |
|
| 533 | + $this->set_parent_invoice_id( $value ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Alias for self::set_parent_invoice_id(). |
|
| 538 | + * |
|
| 539 | + * @since 1.0.19 |
|
| 540 | + * @param int $value The parent invoice id. |
|
| 541 | + */ |
|
| 542 | + public function set_original_payment_id( $value ) { |
|
| 543 | + $this->set_parent_invoice_id( $value ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Set subscription's product id. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param int $value The subscription product id. |
|
| 551 | + */ |
|
| 552 | + public function set_product_id( $value ) { |
|
| 553 | + $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Set the period of a renewal. |
|
| 558 | + * |
|
| 559 | + * @since 1.0.19 |
|
| 560 | + * @param string $value The renewal period. |
|
| 561 | + */ |
|
| 562 | + public function set_period( $value ) { |
|
| 563 | + $this->set_prop( 'period', $value ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Set number of periods each renewal is valid for. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + * @param int $value The subscription frequency. |
|
| 571 | + */ |
|
| 572 | + public function set_frequency( $value ) { |
|
| 573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Set the initial amount for the subscription. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @param float $value The initial subcription amount. |
|
| 582 | + */ |
|
| 583 | + public function set_initial_amount( $value ) { |
|
| 584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Set the recurring amount for the subscription. |
|
| 589 | + * |
|
| 590 | + * @since 1.0.19 |
|
| 591 | + * @param float $value The recurring subcription amount. |
|
| 592 | + */ |
|
| 593 | + public function set_recurring_amount( $value ) { |
|
| 594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Set number of times that this subscription can be renewed. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + * @param int $value Bill times. |
|
| 602 | + */ |
|
| 603 | + public function set_bill_times( $value ) { |
|
| 604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Get transaction id of this subscription's parent invoice. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param string $value Bill times. |
|
| 612 | + */ |
|
| 613 | + public function set_transaction_id( $value ) { |
|
| 614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Set date when this subscription started. |
|
| 619 | + * |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + * @param string $value strtotime compliant date. |
|
| 622 | + */ |
|
| 623 | + public function set_created( $value ) { |
|
| 624 | + $date = strtotime( $value ); |
|
| 625 | + |
|
| 626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | + return; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + $this->set_prop( 'created', '' ); |
|
| 185 | 632 | |
| 186 | - /** |
|
| 187 | - * Get customer id. |
|
| 188 | - * |
|
| 189 | - * @since 1.0.19 |
|
| 190 | - * @param string $context View or edit context. |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Get customer information. |
|
| 199 | - * |
|
| 200 | - * @since 1.0.19 |
|
| 201 | - * @param string $context View or edit context. |
|
| 202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | - */ |
|
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get parent invoice id. |
|
| 210 | - * |
|
| 211 | - * @since 1.0.19 |
|
| 212 | - * @param string $context View or edit context. |
|
| 213 | - * @return int |
|
| 214 | - */ |
|
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Alias for self::get_parent_invoice_id(). |
|
| 221 | - * |
|
| 222 | - * @since 1.0.19 |
|
| 223 | - * @param string $context View or edit context. |
|
| 224 | - * @return int |
|
| 225 | - */ |
|
| 226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | - return $this->get_parent_invoice_id( $context ); |
|
| 228 | - } |
|
| 633 | + } |
|
| 229 | 634 | |
| 230 | - /** |
|
| 231 | - * Alias for self::get_parent_invoice_id(). |
|
| 635 | + /** |
|
| 636 | + * Alias for self::set_created(). |
|
| 232 | 637 | * |
| 233 | - * @since 1.0.0 |
|
| 234 | - * @return int |
|
| 638 | + * @since 1.0.19 |
|
| 639 | + * @param string $value strtotime compliant date. |
|
| 235 | 640 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 641 | + public function set_date_created( $value ) { |
|
| 642 | + $this->set_created( $value ); |
|
| 238 | 643 | } |
| 239 | 644 | |
| 240 | - /** |
|
| 241 | - * Get parent invoice. |
|
| 242 | - * |
|
| 243 | - * @since 1.0.19 |
|
| 244 | - * @param string $context View or edit context. |
|
| 245 | - * @return WPInv_Invoice |
|
| 246 | - */ |
|
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Alias for self::get_parent_invoice(). |
|
| 253 | - * |
|
| 254 | - * @since 1.0.19 |
|
| 255 | - * @param string $context View or edit context. |
|
| 256 | - * @return WPInv_Invoice |
|
| 257 | - */ |
|
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Get subscription's product id. |
|
| 264 | - * |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @param string $context View or edit context. |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Get the subscription product. |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @param string $context View or edit context. |
|
| 278 | - * @return WPInv_Item |
|
| 279 | - */ |
|
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Get parent invoice's gateway. |
|
| 286 | - * |
|
| 287 | - * Here for backwards compatibility. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @param string $context View or edit context. |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Get the period of a renewal. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @param string $context View or edit context. |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Get number of periods each renewal is valid for. |
|
| 310 | - * |
|
| 311 | - * @since 1.0.19 |
|
| 312 | - * @param string $context View or edit context. |
|
| 313 | - * @return int |
|
| 314 | - */ |
|
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the initial amount for the subscription. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @param string $context View or edit context. |
|
| 324 | - * @return float |
|
| 325 | - */ |
|
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get the recurring amount for the subscription. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return float |
|
| 336 | - */ |
|
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Get number of times that this subscription can be renewed. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - * @param string $context View or edit context. |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Get transaction id of this subscription's parent invoice. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param string $context View or edit context. |
|
| 357 | - * @return string |
|
| 358 | - */ |
|
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Get the date that the subscription was created. |
|
| 365 | - * |
|
| 366 | - * @since 1.0.19 |
|
| 367 | - * @param string $context View or edit context. |
|
| 368 | - * @return string |
|
| 369 | - */ |
|
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Alias for self::get_created(). |
|
| 376 | - * |
|
| 377 | - * @since 1.0.19 |
|
| 378 | - * @param string $context View or edit context. |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Retrieves the creation date in a timestamp |
|
| 387 | - * |
|
| 388 | - * @since 1.0.0 |
|
| 389 | - * @return int |
|
| 390 | - */ |
|
| 391 | - public function get_time_created() { |
|
| 392 | - $created = $this->get_date_created(); |
|
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get GMT date when the subscription was created. |
|
| 398 | - * |
|
| 399 | - * @since 1.0.19 |
|
| 400 | - * @param string $context View or edit context. |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 645 | + /** |
|
| 646 | + * Set the date that the subscription will renew. |
|
| 647 | + * |
|
| 648 | + * @since 1.0.19 |
|
| 649 | + * @param string $value strtotime compliant date. |
|
| 650 | + */ |
|
| 651 | + public function set_next_renewal_date( $value ) { |
|
| 652 | + $date = strtotime( $value ); |
|
| 405 | 653 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 654 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 656 | + return; |
|
| 408 | 657 | } |
| 409 | - return $date; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get the date that the subscription will renew. |
|
| 414 | - * |
|
| 415 | - * @since 1.0.19 |
|
| 416 | - * @param string $context View or edit context. |
|
| 417 | - * @return string |
|
| 418 | - */ |
|
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Alias for self::get_next_renewal_date(). |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - * @param string $context View or edit context. |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Retrieves the expiration date in a timestamp |
|
| 436 | - * |
|
| 437 | - * @since 1.0.0 |
|
| 438 | - * @return int |
|
| 439 | - */ |
|
| 440 | - public function get_expiration_time() { |
|
| 441 | - $expiration = $this->get_expiration(); |
|
| 442 | - |
|
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Get GMT date when the subscription will renew. |
|
| 453 | - * |
|
| 454 | - * @since 1.0.19 |
|
| 455 | - * @param string $context View or edit context. |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 460 | 658 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 463 | - } |
|
| 464 | - return $date; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Get the subscription's trial period. |
|
| 469 | - * |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - * @param string $context View or edit context. |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Get the subscription's status. |
|
| 480 | - * |
|
| 481 | - * @since 1.0.19 |
|
| 482 | - * @param string $context View or edit context. |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Get the subscription's profile id. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $context View or edit context. |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /* |
|
| 501 | - |-------------------------------------------------------------------------- |
|
| 502 | - | Setters |
|
| 503 | - |-------------------------------------------------------------------------- |
|
| 504 | - */ |
|
| 659 | + $this->set_prop( 'expiration', '' ); |
|
| 505 | 660 | |
| 506 | - /** |
|
| 507 | - * Set customer id. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param int $value The customer's id. |
|
| 511 | - */ |
|
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Set parent invoice id. |
|
| 518 | - * |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - * @param int $value The parent invoice id. |
|
| 521 | - */ |
|
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Alias for self::set_parent_invoice_id(). |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - * @param int $value The parent invoice id. |
|
| 531 | - */ |
|
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 534 | - } |
|
| 661 | + } |
|
| 535 | 662 | |
| 536 | - /** |
|
| 537 | - * Alias for self::set_parent_invoice_id(). |
|
| 663 | + /** |
|
| 664 | + * Alias for self::set_next_renewal_date(). |
|
| 538 | 665 | * |
| 539 | 666 | * @since 1.0.19 |
| 540 | - * @param int $value The parent invoice id. |
|
| 667 | + * @param string $value strtotime compliant date. |
|
| 541 | 668 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Set subscription's product id. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param int $value The subscription product id. |
|
| 551 | - */ |
|
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Set the period of a renewal. |
|
| 558 | - * |
|
| 559 | - * @since 1.0.19 |
|
| 560 | - * @param string $value The renewal period. |
|
| 561 | - */ |
|
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Set number of periods each renewal is valid for. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - * @param int $value The subscription frequency. |
|
| 571 | - */ |
|
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Set the initial amount for the subscription. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @param float $value The initial subcription amount. |
|
| 582 | - */ |
|
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Set the recurring amount for the subscription. |
|
| 589 | - * |
|
| 590 | - * @since 1.0.19 |
|
| 591 | - * @param float $value The recurring subcription amount. |
|
| 592 | - */ |
|
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Set number of times that this subscription can be renewed. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - * @param int $value Bill times. |
|
| 602 | - */ |
|
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get transaction id of this subscription's parent invoice. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param string $value Bill times. |
|
| 612 | - */ |
|
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set date when this subscription started. |
|
| 619 | - * |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - * @param string $value strtotime compliant date. |
|
| 622 | - */ |
|
| 623 | - public function set_created( $value ) { |
|
| 624 | - $date = strtotime( $value ); |
|
| 669 | + public function set_expiration( $value ) { |
|
| 670 | + $this->set_next_renewal_date( $value ); |
|
| 671 | + } |
|
| 625 | 672 | |
| 626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 673 | + /** |
|
| 674 | + * Set the subscription's trial period. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @param string $value trial period e.g 1 year. |
|
| 678 | + */ |
|
| 679 | + public function set_trial_period( $value ) { |
|
| 680 | + $this->set_prop( 'trial_period', $value ); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Set the subscription's status. |
|
| 685 | + * |
|
| 686 | + * @since 1.0.19 |
|
| 687 | + * @param string $new_status New subscription status. |
|
| 688 | + */ |
|
| 689 | + public function set_status( $new_status ) { |
|
| 690 | + |
|
| 691 | + // Abort if this is not a valid status; |
|
| 692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 628 | 693 | return; |
| 629 | 694 | } |
| 630 | 695 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 696 | + $old_status = $this->get_status(); |
|
| 697 | + $this->set_prop( 'status', $new_status ); |
|
| 632 | 698 | |
| 633 | - } |
|
| 699 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | + $this->status_transition = array( |
|
| 701 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | + 'to' => $new_status, |
|
| 703 | + ); |
|
| 704 | + } |
|
| 634 | 705 | |
| 635 | - /** |
|
| 636 | - * Alias for self::set_created(). |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $value strtotime compliant date. |
|
| 640 | - */ |
|
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 643 | 706 | } |
| 644 | 707 | |
| 645 | - /** |
|
| 646 | - * Set the date that the subscription will renew. |
|
| 647 | - * |
|
| 648 | - * @since 1.0.19 |
|
| 649 | - * @param string $value strtotime compliant date. |
|
| 650 | - */ |
|
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 708 | + /** |
|
| 709 | + * Set the subscription's (remote) profile id. |
|
| 710 | + * |
|
| 711 | + * @since 1.0.19 |
|
| 712 | + * @param string $value the remote profile id. |
|
| 713 | + */ |
|
| 714 | + public function set_profile_id( $value ) { |
|
| 715 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | + } |
|
| 653 | 717 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 656 | - return; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 660 | - |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Alias for self::set_next_renewal_date(). |
|
| 665 | - * |
|
| 666 | - * @since 1.0.19 |
|
| 667 | - * @param string $value strtotime compliant date. |
|
| 668 | - */ |
|
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Set the subscription's trial period. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @param string $value trial period e.g 1 year. |
|
| 678 | - */ |
|
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Set the subscription's status. |
|
| 685 | - * |
|
| 686 | - * @since 1.0.19 |
|
| 687 | - * @param string $new_status New subscription status. |
|
| 688 | - */ |
|
| 689 | - public function set_status( $new_status ) { |
|
| 690 | - |
|
| 691 | - // Abort if this is not a valid status; |
|
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $old_status = $this->get_status(); |
|
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 698 | - |
|
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | - $this->status_transition = array( |
|
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | - 'to' => $new_status, |
|
| 703 | - ); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Set the subscription's (remote) profile id. |
|
| 710 | - * |
|
| 711 | - * @since 1.0.19 |
|
| 712 | - * @param string $value the remote profile id. |
|
| 713 | - */ |
|
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /* |
|
| 718 | + /* |
|
| 719 | 719 | |-------------------------------------------------------------------------- |
| 720 | 720 | | Boolean methods |
| 721 | 721 | |-------------------------------------------------------------------------- |
@@ -724,55 +724,55 @@ discard block |
||
| 724 | 724 | | |
| 725 | 725 | */ |
| 726 | 726 | |
| 727 | - /** |
|
| 727 | + /** |
|
| 728 | 728 | * Checks if the subscription has a given status. |
| 729 | - * |
|
| 730 | - * @param string|array String or array of strings to check for. |
|
| 731 | - * @return bool |
|
| 729 | + * |
|
| 730 | + * @param string|array String or array of strings to check for. |
|
| 731 | + * @return bool |
|
| 732 | 732 | */ |
| 733 | 733 | public function has_status( $status ) { |
| 734 | 734 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
| 735 | - } |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - /** |
|
| 737 | + /** |
|
| 738 | 738 | * Checks if the subscription has a trial period. |
| 739 | - * |
|
| 740 | - * @return bool |
|
| 739 | + * |
|
| 740 | + * @return bool |
|
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | - $period = $this->get_trial_period(); |
|
| 743 | + $period = $this->get_trial_period(); |
|
| 744 | 744 | return ! empty( $period ); |
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Is the subscription active? |
|
| 749 | - * |
|
| 750 | - * @return bool |
|
| 751 | - */ |
|
| 752 | - public function is_active() { |
|
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * Is the subscription expired? |
|
| 758 | - * |
|
| 759 | - * @return bool |
|
| 760 | - */ |
|
| 761 | - public function is_expired() { |
|
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Is this the last renewals? |
|
| 767 | - * |
|
| 768 | - * @return bool |
|
| 769 | - */ |
|
| 770 | - public function is_last_renewal() { |
|
| 771 | - $max_bills = $this->get_bill_times(); |
|
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /* |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Is the subscription active? |
|
| 749 | + * |
|
| 750 | + * @return bool |
|
| 751 | + */ |
|
| 752 | + public function is_active() { |
|
| 753 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * Is the subscription expired? |
|
| 758 | + * |
|
| 759 | + * @return bool |
|
| 760 | + */ |
|
| 761 | + public function is_expired() { |
|
| 762 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Is this the last renewals? |
|
| 767 | + * |
|
| 768 | + * @return bool |
|
| 769 | + */ |
|
| 770 | + public function is_last_renewal() { |
|
| 771 | + $max_bills = $this->get_bill_times(); |
|
| 772 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /* |
|
| 776 | 776 | |-------------------------------------------------------------------------- |
| 777 | 777 | | Additional methods |
| 778 | 778 | |-------------------------------------------------------------------------- |
@@ -781,27 +781,27 @@ discard block |
||
| 781 | 781 | | |
| 782 | 782 | */ |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * Backwards compatibilty. |
|
| 786 | - */ |
|
| 787 | - public function create( $data = array() ) { |
|
| 784 | + /** |
|
| 785 | + * Backwards compatibilty. |
|
| 786 | + */ |
|
| 787 | + public function create( $data = array() ) { |
|
| 788 | 788 | |
| 789 | - // Set the properties. |
|
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 792 | - } |
|
| 789 | + // Set the properties. |
|
| 790 | + if ( is_array( $data ) ) { |
|
| 791 | + $this->set_props( $data ); |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - // Save the item. |
|
| 795 | - return $this->save(); |
|
| 794 | + // Save the item. |
|
| 795 | + return $this->save(); |
|
| 796 | 796 | |
| 797 | - } |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - /** |
|
| 800 | - * Backwards compatibilty. |
|
| 801 | - */ |
|
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 804 | - } |
|
| 799 | + /** |
|
| 800 | + * Backwards compatibilty. |
|
| 801 | + */ |
|
| 802 | + public function update( $args = array() ) { |
|
| 803 | + return $this->create( $args ); |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | 806 | /** |
| 807 | 807 | * Retrieve renewal payments for a subscription |
@@ -811,22 +811,22 @@ discard block |
||
| 811 | 811 | */ |
| 812 | 812 | public function get_child_payments( $hide_pending = true ) { |
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | - } |
|
| 816 | + if ( ! $hide_pending ) { |
|
| 817 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | return get_posts( |
| 821 | - array( |
|
| 822 | - 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | - 'numberposts' => -1, |
|
| 824 | - 'post_status' => $statuses, |
|
| 825 | - 'orderby' => 'ID', |
|
| 826 | - 'order' => 'ASC', |
|
| 827 | - 'post_type' => 'wpi_invoice' |
|
| 828 | - ) |
|
| 829 | - ); |
|
| 821 | + array( |
|
| 822 | + 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | + 'numberposts' => -1, |
|
| 824 | + 'post_status' => $statuses, |
|
| 825 | + 'orderby' => 'ID', |
|
| 826 | + 'order' => 'ASC', |
|
| 827 | + 'post_type' => 'wpi_invoice' |
|
| 828 | + ) |
|
| 829 | + ); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | * @return int |
| 837 | 837 | */ |
| 838 | 838 | public function get_total_payments() { |
| 839 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
| 839 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -860,57 +860,57 @@ discard block |
||
| 860 | 860 | * |
| 861 | 861 | * @since 2.4 |
| 862 | 862 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 863 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 863 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 864 | 864 | * @return bool |
| 865 | 865 | */ |
| 866 | 866 | public function add_payment( $args = array(), $invoice = false ) { |
| 867 | 867 | |
| 868 | - // Process each payment once. |
|
| 868 | + // Process each payment once. |
|
| 869 | 869 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 870 | 870 | return false; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | - // Are we creating a new invoice? |
|
| 874 | - if ( empty( $invoice ) ) { |
|
| 875 | - $invoice = $this->create_payment(); |
|
| 873 | + // Are we creating a new invoice? |
|
| 874 | + if ( empty( $invoice ) ) { |
|
| 875 | + $invoice = $this->create_payment(); |
|
| 876 | 876 | |
| 877 | - if ( empty( $invoice ) ) { |
|
| 878 | - return false; |
|
| 879 | - } |
|
| 877 | + if ( empty( $invoice ) ) { |
|
| 878 | + return false; |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - } |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 883 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 884 | 884 | |
| 885 | - // Maybe set a transaction id. |
|
| 886 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 887 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 888 | - } |
|
| 885 | + // Maybe set a transaction id. |
|
| 886 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 887 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - // Set the completed date. |
|
| 891 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 890 | + // Set the completed date. |
|
| 891 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 892 | 892 | |
| 893 | - // And the gateway. |
|
| 894 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 895 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 896 | - } |
|
| 893 | + // And the gateway. |
|
| 894 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 895 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | - $invoice->save(); |
|
| 898 | + $invoice->save(); |
|
| 899 | 899 | |
| 900 | - if ( ! $invoice->exists() ) { |
|
| 901 | - return false; |
|
| 902 | - } |
|
| 900 | + if ( ! $invoice->exists() ) { |
|
| 901 | + return false; |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 905 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 904 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 905 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 906 | 906 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 907 | 907 | |
| 908 | 908 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 909 | 909 | |
| 910 | 910 | return $invoice->get_id(); |
| 911 | - } |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | - /** |
|
| 913 | + /** |
|
| 914 | 914 | * Creates a new invoice and returns it. |
| 915 | 915 | * |
| 916 | 916 | * @since 1.0.19 |
@@ -918,124 +918,124 @@ discard block |
||
| 918 | 918 | */ |
| 919 | 919 | public function create_payment() { |
| 920 | 920 | |
| 921 | - $parent_invoice = $this->get_parent_payment(); |
|
| 922 | - |
|
| 923 | - if ( ! $parent_invoice->exists() ) { |
|
| 924 | - return false; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - // Duplicate the parent invoice. |
|
| 928 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 929 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 930 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 931 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 932 | - |
|
| 933 | - // Set invoice items. |
|
| 934 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 935 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 936 | - $invoice_items = array(); |
|
| 937 | - |
|
| 938 | - foreach ( $invoice->get_items() as $item ) { |
|
| 939 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 940 | - $invoice_items[] = $item; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - $invoice->set_items( $invoice_items ); |
|
| 945 | - |
|
| 946 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 947 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 951 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 952 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 953 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - $invoice->recalculate_total(); |
|
| 957 | - $invoice->set_status( 'wpi-pending' ); |
|
| 958 | - $invoice->save(); |
|
| 959 | - |
|
| 960 | - return $invoice->exists() ? $invoice : false; |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * Renews or completes a subscription |
|
| 965 | - * |
|
| 966 | - * @since 1.0.0 |
|
| 967 | - * @return int The subscription's id |
|
| 968 | - */ |
|
| 969 | - public function renew() { |
|
| 970 | - |
|
| 971 | - // Complete subscription if applicable |
|
| 972 | - if ( $this->is_last_renewal() ) { |
|
| 973 | - return $this->complete(); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - // Calculate new expiration |
|
| 977 | - $frequency = $this->get_frequency(); |
|
| 978 | - $period = $this->get_period(); |
|
| 979 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 980 | - |
|
| 981 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 982 | - $this->set_status( 'active' ); |
|
| 983 | - $this->save(); |
|
| 984 | - |
|
| 985 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 986 | - |
|
| 987 | - return $this->get_id(); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * Marks a subscription as completed |
|
| 992 | - * |
|
| 993 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 994 | - * |
|
| 995 | - * @since 1.0.0 |
|
| 996 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 997 | - */ |
|
| 998 | - public function complete() { |
|
| 999 | - |
|
| 1000 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 1001 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1002 | - return false; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - $this->set_status( 'completed' ); |
|
| 1006 | - return $this->save(); |
|
| 1007 | - |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * Marks a subscription as expired |
|
| 1012 | - * |
|
| 1013 | - * @since 1.0.0 |
|
| 1014 | - * @param bool $check_expiration |
|
| 1015 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1016 | - */ |
|
| 1017 | - public function expire( $check_expiration = false ) { |
|
| 1018 | - |
|
| 1019 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1020 | - // Do not mark as expired since real expiration date is in the future |
|
| 1021 | - return false; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - $this->set_status( 'expired' ); |
|
| 1025 | - return $this->save(); |
|
| 1026 | - |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - /** |
|
| 1030 | - * Marks a subscription as failing |
|
| 1031 | - * |
|
| 1032 | - * @since 2.4.2 |
|
| 1033 | - * @return int Subscription id. |
|
| 1034 | - */ |
|
| 1035 | - public function failing() { |
|
| 1036 | - $this->set_status( 'failing' ); |
|
| 1037 | - return $this->save(); |
|
| 1038 | - } |
|
| 921 | + $parent_invoice = $this->get_parent_payment(); |
|
| 922 | + |
|
| 923 | + if ( ! $parent_invoice->exists() ) { |
|
| 924 | + return false; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + // Duplicate the parent invoice. |
|
| 928 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 929 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 930 | + $invoice->set_subscription_id( $this->get_id() ); |
|
| 931 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 932 | + |
|
| 933 | + // Set invoice items. |
|
| 934 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 935 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 936 | + $invoice_items = array(); |
|
| 937 | + |
|
| 938 | + foreach ( $invoice->get_items() as $item ) { |
|
| 939 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 940 | + $invoice_items[] = $item; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + $invoice->set_items( $invoice_items ); |
|
| 945 | + |
|
| 946 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 947 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 951 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 952 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 953 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + $invoice->recalculate_total(); |
|
| 957 | + $invoice->set_status( 'wpi-pending' ); |
|
| 958 | + $invoice->save(); |
|
| 959 | + |
|
| 960 | + return $invoice->exists() ? $invoice : false; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * Renews or completes a subscription |
|
| 965 | + * |
|
| 966 | + * @since 1.0.0 |
|
| 967 | + * @return int The subscription's id |
|
| 968 | + */ |
|
| 969 | + public function renew() { |
|
| 970 | + |
|
| 971 | + // Complete subscription if applicable |
|
| 972 | + if ( $this->is_last_renewal() ) { |
|
| 973 | + return $this->complete(); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + // Calculate new expiration |
|
| 977 | + $frequency = $this->get_frequency(); |
|
| 978 | + $period = $this->get_period(); |
|
| 979 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 980 | + |
|
| 981 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 982 | + $this->set_status( 'active' ); |
|
| 983 | + $this->save(); |
|
| 984 | + |
|
| 985 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 986 | + |
|
| 987 | + return $this->get_id(); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * Marks a subscription as completed |
|
| 992 | + * |
|
| 993 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 994 | + * |
|
| 995 | + * @since 1.0.0 |
|
| 996 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 997 | + */ |
|
| 998 | + public function complete() { |
|
| 999 | + |
|
| 1000 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 1001 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 1002 | + return false; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + $this->set_status( 'completed' ); |
|
| 1006 | + return $this->save(); |
|
| 1007 | + |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * Marks a subscription as expired |
|
| 1012 | + * |
|
| 1013 | + * @since 1.0.0 |
|
| 1014 | + * @param bool $check_expiration |
|
| 1015 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1016 | + */ |
|
| 1017 | + public function expire( $check_expiration = false ) { |
|
| 1018 | + |
|
| 1019 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1020 | + // Do not mark as expired since real expiration date is in the future |
|
| 1021 | + return false; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + $this->set_status( 'expired' ); |
|
| 1025 | + return $this->save(); |
|
| 1026 | + |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + /** |
|
| 1030 | + * Marks a subscription as failing |
|
| 1031 | + * |
|
| 1032 | + * @since 2.4.2 |
|
| 1033 | + * @return int Subscription id. |
|
| 1034 | + */ |
|
| 1035 | + public function failing() { |
|
| 1036 | + $this->set_status( 'failing' ); |
|
| 1037 | + return $this->save(); |
|
| 1038 | + } |
|
| 1039 | 1039 | |
| 1040 | 1040 | /** |
| 1041 | 1041 | * Marks a subscription as cancelled |
@@ -1044,19 +1044,19 @@ discard block |
||
| 1044 | 1044 | * @return int Subscription id. |
| 1045 | 1045 | */ |
| 1046 | 1046 | public function cancel() { |
| 1047 | - $this->set_status( 'cancelled' ); |
|
| 1048 | - return $this->save(); |
|
| 1047 | + $this->set_status( 'cancelled' ); |
|
| 1048 | + return $this->save(); |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1053 | - * |
|
| 1054 | - * @since 1.0.0 |
|
| 1055 | - * @return bool |
|
| 1056 | - */ |
|
| 1057 | - public function can_cancel() { |
|
| 1058 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1059 | - } |
|
| 1051 | + /** |
|
| 1052 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1053 | + * |
|
| 1054 | + * @since 1.0.0 |
|
| 1055 | + * @return bool |
|
| 1056 | + */ |
|
| 1057 | + public function can_cancel() { |
|
| 1058 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1059 | + } |
|
| 1060 | 1060 | |
| 1061 | 1061 | /** |
| 1062 | 1062 | * Returns an array of subscription statuses that can be cancelled |
@@ -1069,96 +1069,96 @@ discard block |
||
| 1069 | 1069 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | - /** |
|
| 1073 | - * Retrieves the URL to cancel subscription |
|
| 1074 | - * |
|
| 1075 | - * @since 1.0.0 |
|
| 1076 | - * @return string |
|
| 1077 | - */ |
|
| 1078 | - public function get_cancel_url() { |
|
| 1079 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1080 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * Retrieves the URL to view a subscription |
|
| 1085 | - * |
|
| 1086 | - * @since 1.0.19 |
|
| 1087 | - * @return string |
|
| 1088 | - */ |
|
| 1089 | - public function get_view_url() { |
|
| 1090 | - |
|
| 1091 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1092 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1093 | - |
|
| 1094 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * Determines if subscription can be manually renewed |
|
| 1099 | - * |
|
| 1100 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1101 | - * that can be renewed manually |
|
| 1102 | - * |
|
| 1103 | - * @since 2.5 |
|
| 1104 | - * @return bool |
|
| 1105 | - */ |
|
| 1106 | - public function can_renew() { |
|
| 1107 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * Retrieves the URL to renew a subscription |
|
| 1112 | - * |
|
| 1113 | - * @since 2.5 |
|
| 1114 | - * @return string |
|
| 1115 | - */ |
|
| 1116 | - public function get_renew_url() { |
|
| 1117 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1118 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - /** |
|
| 1122 | - * Determines if subscription can have their payment method updated |
|
| 1123 | - * |
|
| 1124 | - * @since 1.0.0 |
|
| 1125 | - * @return bool |
|
| 1126 | - */ |
|
| 1127 | - public function can_update() { |
|
| 1128 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - /** |
|
| 1132 | - * Retrieves the URL to update subscription |
|
| 1133 | - * |
|
| 1134 | - * @since 1.0.0 |
|
| 1135 | - * @return string |
|
| 1136 | - */ |
|
| 1137 | - public function get_update_url() { |
|
| 1138 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1139 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * Retrieves the subscription status label |
|
| 1144 | - * |
|
| 1145 | - * @since 1.0.0 |
|
| 1146 | - * @return string |
|
| 1147 | - */ |
|
| 1148 | - public function get_status_label() { |
|
| 1149 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * Retrieves the subscription status class |
|
| 1154 | - * |
|
| 1155 | - * @since 1.0.19 |
|
| 1156 | - * @return string |
|
| 1157 | - */ |
|
| 1158 | - public function get_status_class() { |
|
| 1159 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1160 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1161 | - } |
|
| 1072 | + /** |
|
| 1073 | + * Retrieves the URL to cancel subscription |
|
| 1074 | + * |
|
| 1075 | + * @since 1.0.0 |
|
| 1076 | + * @return string |
|
| 1077 | + */ |
|
| 1078 | + public function get_cancel_url() { |
|
| 1079 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1080 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * Retrieves the URL to view a subscription |
|
| 1085 | + * |
|
| 1086 | + * @since 1.0.19 |
|
| 1087 | + * @return string |
|
| 1088 | + */ |
|
| 1089 | + public function get_view_url() { |
|
| 1090 | + |
|
| 1091 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1092 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1093 | + |
|
| 1094 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * Determines if subscription can be manually renewed |
|
| 1099 | + * |
|
| 1100 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1101 | + * that can be renewed manually |
|
| 1102 | + * |
|
| 1103 | + * @since 2.5 |
|
| 1104 | + * @return bool |
|
| 1105 | + */ |
|
| 1106 | + public function can_renew() { |
|
| 1107 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * Retrieves the URL to renew a subscription |
|
| 1112 | + * |
|
| 1113 | + * @since 2.5 |
|
| 1114 | + * @return string |
|
| 1115 | + */ |
|
| 1116 | + public function get_renew_url() { |
|
| 1117 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1118 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + /** |
|
| 1122 | + * Determines if subscription can have their payment method updated |
|
| 1123 | + * |
|
| 1124 | + * @since 1.0.0 |
|
| 1125 | + * @return bool |
|
| 1126 | + */ |
|
| 1127 | + public function can_update() { |
|
| 1128 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + /** |
|
| 1132 | + * Retrieves the URL to update subscription |
|
| 1133 | + * |
|
| 1134 | + * @since 1.0.0 |
|
| 1135 | + * @return string |
|
| 1136 | + */ |
|
| 1137 | + public function get_update_url() { |
|
| 1138 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1139 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * Retrieves the subscription status label |
|
| 1144 | + * |
|
| 1145 | + * @since 1.0.0 |
|
| 1146 | + * @return string |
|
| 1147 | + */ |
|
| 1148 | + public function get_status_label() { |
|
| 1149 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * Retrieves the subscription status class |
|
| 1154 | + * |
|
| 1155 | + * @since 1.0.19 |
|
| 1156 | + * @return string |
|
| 1157 | + */ |
|
| 1158 | + public function get_status_class() { |
|
| 1159 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1160 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | 1163 | /** |
| 1164 | 1164 | * Retrieves the subscription status label |
@@ -1168,11 +1168,11 @@ discard block |
||
| 1168 | 1168 | */ |
| 1169 | 1169 | public function get_status_label_html() { |
| 1170 | 1170 | |
| 1171 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1172 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1173 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1171 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1172 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1173 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 1174 | 1174 | |
| 1175 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1175 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | /** |
@@ -1183,75 +1183,75 @@ discard block |
||
| 1183 | 1183 | * @return bool |
| 1184 | 1184 | */ |
| 1185 | 1185 | public function payment_exists( $txn_id = '' ) { |
| 1186 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1186 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1187 | 1187 | return ! empty( $invoice_id ); |
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - /** |
|
| 1191 | - * Handle the status transition. |
|
| 1192 | - */ |
|
| 1193 | - protected function status_transition() { |
|
| 1194 | - $status_transition = $this->status_transition; |
|
| 1195 | - |
|
| 1196 | - // Reset status transition variable. |
|
| 1197 | - $this->status_transition = false; |
|
| 1198 | - |
|
| 1199 | - if ( $status_transition ) { |
|
| 1200 | - try { |
|
| 1201 | - |
|
| 1202 | - // Fire a hook for the status change. |
|
| 1203 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1204 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1205 | - |
|
| 1206 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1207 | - |
|
| 1208 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1209 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1210 | - |
|
| 1211 | - // Note the transition occurred. |
|
| 1212 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1213 | - |
|
| 1214 | - // Fire another hook. |
|
| 1215 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1216 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1217 | - |
|
| 1218 | - } else { |
|
| 1219 | - /* translators: %s: new invoice status */ |
|
| 1220 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1221 | - |
|
| 1222 | - // Note the transition occurred. |
|
| 1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1224 | - |
|
| 1225 | - } |
|
| 1226 | - } catch ( Exception $e ) { |
|
| 1227 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - /** |
|
| 1234 | - * Save data to the database. |
|
| 1235 | - * |
|
| 1236 | - * @since 1.0.19 |
|
| 1237 | - * @return int subscription ID |
|
| 1238 | - */ |
|
| 1239 | - public function save() { |
|
| 1240 | - parent::save(); |
|
| 1241 | - $this->status_transition(); |
|
| 1242 | - return $this->get_id(); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * Activates a subscription. |
|
| 1247 | - * |
|
| 1248 | - * @since 1.0.19 |
|
| 1249 | - * @return int subscription ID |
|
| 1250 | - */ |
|
| 1251 | - public function activate() { |
|
| 1252 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1253 | - $this->set_status( $status ); |
|
| 1254 | - return $this->save(); |
|
| 1255 | - } |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + /** |
|
| 1191 | + * Handle the status transition. |
|
| 1192 | + */ |
|
| 1193 | + protected function status_transition() { |
|
| 1194 | + $status_transition = $this->status_transition; |
|
| 1195 | + |
|
| 1196 | + // Reset status transition variable. |
|
| 1197 | + $this->status_transition = false; |
|
| 1198 | + |
|
| 1199 | + if ( $status_transition ) { |
|
| 1200 | + try { |
|
| 1201 | + |
|
| 1202 | + // Fire a hook for the status change. |
|
| 1203 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1204 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1205 | + |
|
| 1206 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1207 | + |
|
| 1208 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1209 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1210 | + |
|
| 1211 | + // Note the transition occurred. |
|
| 1212 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1213 | + |
|
| 1214 | + // Fire another hook. |
|
| 1215 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1216 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1217 | + |
|
| 1218 | + } else { |
|
| 1219 | + /* translators: %s: new invoice status */ |
|
| 1220 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1221 | + |
|
| 1222 | + // Note the transition occurred. |
|
| 1223 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1224 | + |
|
| 1225 | + } |
|
| 1226 | + } catch ( Exception $e ) { |
|
| 1227 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + /** |
|
| 1234 | + * Save data to the database. |
|
| 1235 | + * |
|
| 1236 | + * @since 1.0.19 |
|
| 1237 | + * @return int subscription ID |
|
| 1238 | + */ |
|
| 1239 | + public function save() { |
|
| 1240 | + parent::save(); |
|
| 1241 | + $this->status_transition(); |
|
| 1242 | + return $this->get_id(); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * Activates a subscription. |
|
| 1247 | + * |
|
| 1248 | + * @since 1.0.19 |
|
| 1249 | + * @return int subscription ID |
|
| 1250 | + */ |
|
| 1251 | + public function activate() { |
|
| 1252 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1253 | + $this->set_status( $status ); |
|
| 1254 | + return $this->save(); |
|
| 1255 | + } |
|
| 1256 | 1256 | |
| 1257 | 1257 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
| 68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
| 69 | 69 | * @param bool $deprecated |
| 70 | 70 | */ |
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 71 | + function __construct($subscription = 0, $deprecated = false) { |
|
| 72 | 72 | |
| 73 | - parent::__construct( $subscription ); |
|
| 73 | + parent::__construct($subscription); |
|
| 74 | 74 | |
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 75 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
| 76 | + $this->set_id($subscription); |
|
| 77 | + } elseif ($subscription instanceof self) { |
|
| 78 | + $this->set_id($subscription->get_id()); |
|
| 79 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
| 80 | + $this->set_id($subscription_id); |
|
| 81 | + } elseif (!empty($subscription->id)) { |
|
| 82 | + $this->set_id($subscription->id); |
|
| 83 | 83 | } else { |
| 84 | - $this->set_object_read( true ); |
|
| 84 | + $this->set_object_read(true); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Load the datastore. |
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 89 | 89 | |
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 90 | + if ($this->get_id() > 0) { |
|
| 91 | + $this->data_store->read($this); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
| 103 | 103 | * @since 1.0.19 |
| 104 | 104 | * @return int |
| 105 | 105 | */ |
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | 109 | // Trim the value. |
| 110 | - $value = trim( $value ); |
|
| 110 | + $value = trim($value); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 112 | + if (empty($value)) { |
|
| 113 | 113 | return 0; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 116 | + if ('invoice_id' == $field) { |
|
| 117 | 117 | $field = 'parent_payment_id'; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | // Ensure a field has been passed. |
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 128 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 129 | 129 | return 0; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Maybe retrieve from the cache. |
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 134 | + if (!empty($subscription_id)) { |
|
| 135 | 135 | return $subscription_id; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
| 140 | 140 | $subscription_id = (int) $wpdb->get_var( |
| 141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
| 141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 144 | + if (empty($subscription_id)) { |
|
| 145 | 145 | return 0; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Update the cache with our data. |
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 150 | 150 | |
| 151 | 151 | return $subscription_id; |
| 152 | 152 | } |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 158 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
| 159 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
| 160 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
| 161 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | - public function _isset( $key ) { |
|
| 168 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
| 167 | + public function _isset($key) { |
|
| 168 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /* |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | * @param string $context View or edit context. |
| 191 | 191 | * @return int |
| 192 | 192 | */ |
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 193 | + public function get_customer_id($context = 'view') { |
|
| 194 | + return (int) $this->get_prop('customer_id', $context); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | * @param string $context View or edit context. |
| 202 | 202 | * @return WP_User|false WP_User object on success, false on failure. |
| 203 | 203 | */ |
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 204 | + public function get_customer($context = 'view') { |
|
| 205 | + return get_userdata($this->get_customer_id($context)); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @param string $context View or edit context. |
| 213 | 213 | * @return int |
| 214 | 214 | */ |
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 215 | + public function get_parent_invoice_id($context = 'view') { |
|
| 216 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $context View or edit context. |
| 224 | 224 | * @return int |
| 225 | 225 | */ |
| 226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | - return $this->get_parent_invoice_id( $context ); |
|
| 226 | + public function get_parent_payment_id($context = 'view') { |
|
| 227 | + return $this->get_parent_invoice_id($context); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @since 1.0.0 |
| 234 | 234 | * @return int |
| 235 | 235 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 236 | + public function get_original_payment_id($context = 'view') { |
|
| 237 | + return $this->get_parent_invoice_id($context); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | * @param string $context View or edit context. |
| 245 | 245 | * @return WPInv_Invoice |
| 246 | 246 | */ |
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 247 | + public function get_parent_invoice($context = 'view') { |
|
| 248 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | * @param string $context View or edit context. |
| 256 | 256 | * @return WPInv_Invoice |
| 257 | 257 | */ |
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 258 | + public function get_parent_payment($context = 'view') { |
|
| 259 | + return $this->get_parent_invoice($context); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | * @param string $context View or edit context. |
| 267 | 267 | * @return int |
| 268 | 268 | */ |
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 269 | + public function get_product_id($context = 'view') { |
|
| 270 | + return (int) $this->get_prop('product_id', $context); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | * @param string $context View or edit context. |
| 278 | 278 | * @return WPInv_Item |
| 279 | 279 | */ |
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 280 | + public function get_product($context = 'view') { |
|
| 281 | + return new WPInv_Item($this->get_product_id($context)); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param string $context View or edit context. |
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 293 | + public function get_gateway($context = 'view') { |
|
| 294 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | * @param string $context View or edit context. |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 304 | + public function get_period($context = 'view') { |
|
| 305 | + return $this->get_prop('period', $context); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | * @param string $context View or edit context. |
| 313 | 313 | * @return int |
| 314 | 314 | */ |
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 315 | + public function get_frequency($context = 'view') { |
|
| 316 | + return (int) $this->get_prop('frequency', $context); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | * @param string $context View or edit context. |
| 324 | 324 | * @return float |
| 325 | 325 | */ |
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 326 | + public function get_initial_amount($context = 'view') { |
|
| 327 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * @param string $context View or edit context. |
| 335 | 335 | * @return float |
| 336 | 336 | */ |
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 337 | + public function get_recurring_amount($context = 'view') { |
|
| 338 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @param string $context View or edit context. |
| 346 | 346 | * @return int |
| 347 | 347 | */ |
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 348 | + public function get_bill_times($context = 'view') { |
|
| 349 | + return (int) $this->get_prop('bill_times', $context); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
| 356 | 356 | * @param string $context View or edit context. |
| 357 | 357 | * @return string |
| 358 | 358 | */ |
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 359 | + public function get_transaction_id($context = 'view') { |
|
| 360 | + return $this->get_prop('transaction_id', $context); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * @param string $context View or edit context. |
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 370 | + public function get_created($context = 'view') { |
|
| 371 | + return $this->get_prop('created', $context); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | * @param string $context View or edit context. |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 381 | + public function get_date_created($context = 'view') { |
|
| 382 | + return $this->get_created($context); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | public function get_time_created() { |
| 392 | 392 | $created = $this->get_date_created(); |
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 393 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | * @param string $context View or edit context. |
| 401 | 401 | * @return string |
| 402 | 402 | */ |
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 403 | + public function get_date_created_gmt($context = 'view') { |
|
| 404 | + $date = $this->get_date_created($context); |
|
| 405 | 405 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 406 | + if ($date) { |
|
| 407 | + $date = get_gmt_from_date($date); |
|
| 408 | 408 | } |
| 409 | 409 | return $date; |
| 410 | 410 | } |
@@ -416,8 +416,8 @@ discard block |
||
| 416 | 416 | * @param string $context View or edit context. |
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 419 | + public function get_next_renewal_date($context = 'view') { |
|
| 420 | + return $this->get_prop('expiration', $context); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
| 427 | 427 | * @param string $context View or edit context. |
| 428 | 428 | * @return string |
| 429 | 429 | */ |
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 430 | + public function get_expiration($context = 'view') { |
|
| 431 | + return $this->get_next_renewal_date($context); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
| 440 | 440 | public function get_expiration_time() { |
| 441 | 441 | $expiration = $this->get_expiration(); |
| 442 | 442 | |
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 443 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
| 444 | + return current_time('timestamp'); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 447 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
| 448 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -455,11 +455,11 @@ discard block |
||
| 455 | 455 | * @param string $context View or edit context. |
| 456 | 456 | * @return string |
| 457 | 457 | */ |
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 458 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
| 459 | + $date = $this->get_next_renewal_date($context); |
|
| 460 | 460 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 461 | + if ($date) { |
|
| 462 | + $date = get_gmt_from_date($date); |
|
| 463 | 463 | } |
| 464 | 464 | return $date; |
| 465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * @param string $context View or edit context. |
| 472 | 472 | * @return string |
| 473 | 473 | */ |
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 474 | + public function get_trial_period($context = 'view') { |
|
| 475 | + return $this->get_prop('trial_period', $context); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param string $context View or edit context. |
| 483 | 483 | * @return string |
| 484 | 484 | */ |
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 485 | + public function get_status($context = 'view') { |
|
| 486 | + return $this->get_prop('status', $context); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -493,8 +493,8 @@ discard block |
||
| 493 | 493 | * @param string $context View or edit context. |
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 496 | + public function get_profile_id($context = 'view') { |
|
| 497 | + return $this->get_prop('profile_id', $context); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /* |
@@ -509,8 +509,8 @@ discard block |
||
| 509 | 509 | * @since 1.0.19 |
| 510 | 510 | * @param int $value The customer's id. |
| 511 | 511 | */ |
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 512 | + public function set_customer_id($value) { |
|
| 513 | + $this->set_prop('customer_id', (int) $value); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @since 1.0.19 |
| 520 | 520 | * @param int $value The parent invoice id. |
| 521 | 521 | */ |
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 522 | + public function set_parent_invoice_id($value) { |
|
| 523 | + $this->set_prop('parent_payment_id', (int) $value); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | * @since 1.0.19 |
| 530 | 530 | * @param int $value The parent invoice id. |
| 531 | 531 | */ |
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 532 | + public function set_parent_payment_id($value) { |
|
| 533 | + $this->set_parent_invoice_id($value); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | * @since 1.0.19 |
| 540 | 540 | * @param int $value The parent invoice id. |
| 541 | 541 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 542 | + public function set_original_payment_id($value) { |
|
| 543 | + $this->set_parent_invoice_id($value); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
| 549 | 549 | * @since 1.0.19 |
| 550 | 550 | * @param int $value The subscription product id. |
| 551 | 551 | */ |
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 552 | + public function set_product_id($value) { |
|
| 553 | + $this->set_prop('product_id', (int) $value); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @since 1.0.19 |
| 560 | 560 | * @param string $value The renewal period. |
| 561 | 561 | */ |
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 562 | + public function set_period($value) { |
|
| 563 | + $this->set_prop('period', $value); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,9 +569,9 @@ discard block |
||
| 569 | 569 | * @since 1.0.19 |
| 570 | 570 | * @param int $value The subscription frequency. |
| 571 | 571 | */ |
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 572 | + public function set_frequency($value) { |
|
| 573 | + $value = empty($value) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop('frequency', absint($value)); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | * @since 1.0.19 |
| 581 | 581 | * @param float $value The initial subcription amount. |
| 582 | 582 | */ |
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 583 | + public function set_initial_amount($value) { |
|
| 584 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * @since 1.0.19 |
| 591 | 591 | * @param float $value The recurring subcription amount. |
| 592 | 592 | */ |
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 593 | + public function set_recurring_amount($value) { |
|
| 594 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -600,8 +600,8 @@ discard block |
||
| 600 | 600 | * @since 1.0.19 |
| 601 | 601 | * @param int $value Bill times. |
| 602 | 602 | */ |
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 603 | + public function set_bill_times($value) { |
|
| 604 | + $this->set_prop('bill_times', (int) $value); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -610,8 +610,8 @@ discard block |
||
| 610 | 610 | * @since 1.0.19 |
| 611 | 611 | * @param string $value Bill times. |
| 612 | 612 | */ |
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 613 | + public function set_transaction_id($value) { |
|
| 614 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -620,15 +620,15 @@ discard block |
||
| 620 | 620 | * @since 1.0.19 |
| 621 | 621 | * @param string $value strtotime compliant date. |
| 622 | 622 | */ |
| 623 | - public function set_created( $value ) { |
|
| 624 | - $date = strtotime( $value ); |
|
| 623 | + public function set_created($value) { |
|
| 624 | + $date = strtotime($value); |
|
| 625 | 625 | |
| 626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 626 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 627 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
| 628 | 628 | return; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 631 | + $this->set_prop('created', ''); |
|
| 632 | 632 | |
| 633 | 633 | } |
| 634 | 634 | |
@@ -638,8 +638,8 @@ discard block |
||
| 638 | 638 | * @since 1.0.19 |
| 639 | 639 | * @param string $value strtotime compliant date. |
| 640 | 640 | */ |
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 641 | + public function set_date_created($value) { |
|
| 642 | + $this->set_created($value); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | /** |
@@ -648,15 +648,15 @@ discard block |
||
| 648 | 648 | * @since 1.0.19 |
| 649 | 649 | * @param string $value strtotime compliant date. |
| 650 | 650 | */ |
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 651 | + public function set_next_renewal_date($value) { |
|
| 652 | + $date = strtotime($value); |
|
| 653 | 653 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 654 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 655 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
| 656 | 656 | return; |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 659 | + $this->set_prop('expiration', ''); |
|
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
@@ -666,8 +666,8 @@ discard block |
||
| 666 | 666 | * @since 1.0.19 |
| 667 | 667 | * @param string $value strtotime compliant date. |
| 668 | 668 | */ |
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 669 | + public function set_expiration($value) { |
|
| 670 | + $this->set_next_renewal_date($value); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | * @since 1.0.19 |
| 677 | 677 | * @param string $value trial period e.g 1 year. |
| 678 | 678 | */ |
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 679 | + public function set_trial_period($value) { |
|
| 680 | + $this->set_prop('trial_period', $value); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -686,19 +686,19 @@ discard block |
||
| 686 | 686 | * @since 1.0.19 |
| 687 | 687 | * @param string $new_status New subscription status. |
| 688 | 688 | */ |
| 689 | - public function set_status( $new_status ) { |
|
| 689 | + public function set_status($new_status) { |
|
| 690 | 690 | |
| 691 | 691 | // Abort if this is not a valid status; |
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 692 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
| 693 | 693 | return; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | $old_status = $this->get_status(); |
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 697 | + $this->set_prop('status', $new_status); |
|
| 698 | 698 | |
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 699 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
| 700 | 700 | $this->status_transition = array( |
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 701 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
| 702 | 702 | 'to' => $new_status, |
| 703 | 703 | ); |
| 704 | 704 | } |
@@ -711,8 +711,8 @@ discard block |
||
| 711 | 711 | * @since 1.0.19 |
| 712 | 712 | * @param string $value the remote profile id. |
| 713 | 713 | */ |
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 714 | + public function set_profile_id($value) { |
|
| 715 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /* |
@@ -730,8 +730,8 @@ discard block |
||
| 730 | 730 | * @param string|array String or array of strings to check for. |
| 731 | 731 | * @return bool |
| 732 | 732 | */ |
| 733 | - public function has_status( $status ) { |
|
| 734 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
| 733 | + public function has_status($status) { |
|
| 734 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | 743 | $period = $this->get_trial_period(); |
| 744 | - return ! empty( $period ); |
|
| 744 | + return !empty($period); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * @return bool |
| 751 | 751 | */ |
| 752 | 752 | public function is_active() { |
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 753 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | /** |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | * @return bool |
| 760 | 760 | */ |
| 761 | 761 | public function is_expired() { |
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 762 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql')); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | */ |
| 770 | 770 | public function is_last_renewal() { |
| 771 | 771 | $max_bills = $this->get_bill_times(); |
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 772 | + return !empty($max_bills) && $max_bills <= $this->get_times_billed(); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /* |
@@ -784,11 +784,11 @@ discard block |
||
| 784 | 784 | /** |
| 785 | 785 | * Backwards compatibilty. |
| 786 | 786 | */ |
| 787 | - public function create( $data = array() ) { |
|
| 787 | + public function create($data = array()) { |
|
| 788 | 788 | |
| 789 | 789 | // Set the properties. |
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 790 | + if (is_array($data)) { |
|
| 791 | + $this->set_props($data); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | // Save the item. |
@@ -799,8 +799,8 @@ discard block |
||
| 799 | 799 | /** |
| 800 | 800 | * Backwards compatibilty. |
| 801 | 801 | */ |
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 802 | + public function update($args = array()) { |
|
| 803 | + return $this->create($args); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -809,12 +809,12 @@ discard block |
||
| 809 | 809 | * @since 1.0.0 |
| 810 | 810 | * @return WP_Post[] |
| 811 | 811 | */ |
| 812 | - public function get_child_payments( $hide_pending = true ) { |
|
| 812 | + public function get_child_payments($hide_pending = true) { |
|
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array('publish', 'wpi-processing', 'wpi-renewal'); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 816 | + if (!$hide_pending) { |
|
| 817 | + $statuses = array_keys(wpinv_get_invoice_statuses()); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | return get_posts( |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | * @return int |
| 837 | 837 | */ |
| 838 | 838 | public function get_total_payments() { |
| 839 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
| 839 | + return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id()); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | public function get_times_billed() { |
| 849 | 849 | $times_billed = $this->get_total_payments(); |
| 850 | 850 | |
| 851 | - if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) { |
|
| 851 | + if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) { |
|
| 852 | 852 | $times_billed--; |
| 853 | 853 | } |
| 854 | 854 | |
@@ -863,49 +863,49 @@ discard block |
||
| 863 | 863 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
| 864 | 864 | * @return bool |
| 865 | 865 | */ |
| 866 | - public function add_payment( $args = array(), $invoice = false ) { |
|
| 866 | + public function add_payment($args = array(), $invoice = false) { |
|
| 867 | 867 | |
| 868 | 868 | // Process each payment once. |
| 869 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 869 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
| 870 | 870 | return false; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | // Are we creating a new invoice? |
| 874 | - if ( empty( $invoice ) ) { |
|
| 874 | + if (empty($invoice)) { |
|
| 875 | 875 | $invoice = $this->create_payment(); |
| 876 | 876 | |
| 877 | - if ( empty( $invoice ) ) { |
|
| 877 | + if (empty($invoice)) { |
|
| 878 | 878 | return false; |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | } |
| 882 | 882 | |
| 883 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 883 | + $invoice->set_status('wpi-renewal'); |
|
| 884 | 884 | |
| 885 | 885 | // Maybe set a transaction id. |
| 886 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 887 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 886 | + if (!empty($args['transaction_id'])) { |
|
| 887 | + $invoice->set_transaction_id($args['transaction_id']); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | // Set the completed date. |
| 891 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 891 | + $invoice->set_completed_date(current_time('mysql')); |
|
| 892 | 892 | |
| 893 | 893 | // And the gateway. |
| 894 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 895 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 894 | + if (!empty($args['gateway'])) { |
|
| 895 | + $invoice->set_gateway($args['gateway']); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | $invoice->save(); |
| 899 | 899 | |
| 900 | - if ( ! $invoice->exists() ) { |
|
| 900 | + if (!$invoice->exists()) { |
|
| 901 | 901 | return false; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 905 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 906 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
| 904 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
| 905 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 906 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
| 907 | 907 | |
| 908 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
| 908 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
| 909 | 909 | |
| 910 | 910 | return $invoice->get_id(); |
| 911 | 911 | } |
@@ -920,41 +920,41 @@ discard block |
||
| 920 | 920 | |
| 921 | 921 | $parent_invoice = $this->get_parent_payment(); |
| 922 | 922 | |
| 923 | - if ( ! $parent_invoice->exists() ) { |
|
| 923 | + if (!$parent_invoice->exists()) { |
|
| 924 | 924 | return false; |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | // Duplicate the parent invoice. |
| 928 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 929 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 930 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 931 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 928 | + $invoice = getpaid_duplicate_invoice($parent_invoice); |
|
| 929 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
| 930 | + $invoice->set_subscription_id($this->get_id()); |
|
| 931 | + $invoice->set_remote_subscription_id($this->get_profile_id()); |
|
| 932 | 932 | |
| 933 | 933 | // Set invoice items. |
| 934 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 935 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 934 | + $subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id()); |
|
| 935 | + $allowed_items = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']); |
|
| 936 | 936 | $invoice_items = array(); |
| 937 | 937 | |
| 938 | - foreach ( $invoice->get_items() as $item ) { |
|
| 939 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 938 | + foreach ($invoice->get_items() as $item) { |
|
| 939 | + if (in_array($item->get_id(), $allowed_items)) { |
|
| 940 | 940 | $invoice_items[] = $item; |
| 941 | 941 | } |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | - $invoice->set_items( $invoice_items ); |
|
| 944 | + $invoice->set_items($invoice_items); |
|
| 945 | 945 | |
| 946 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 947 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 946 | + if (!empty($subscription_group['fees'])) { |
|
| 947 | + $invoice->set_fees($subscription_group['fees']); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | // Maybe recalculate discount (Pre-GetPaid Fix). |
| 951 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 952 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 953 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 951 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 952 | + if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) { |
|
| 953 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | $invoice->recalculate_total(); |
| 957 | - $invoice->set_status( 'wpi-pending' ); |
|
| 957 | + $invoice->set_status('wpi-pending'); |
|
| 958 | 958 | $invoice->save(); |
| 959 | 959 | |
| 960 | 960 | return $invoice->exists() ? $invoice : false; |
@@ -969,20 +969,20 @@ discard block |
||
| 969 | 969 | public function renew() { |
| 970 | 970 | |
| 971 | 971 | // Complete subscription if applicable |
| 972 | - if ( $this->is_last_renewal() ) { |
|
| 972 | + if ($this->is_last_renewal()) { |
|
| 973 | 973 | return $this->complete(); |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | // Calculate new expiration |
| 977 | 977 | $frequency = $this->get_frequency(); |
| 978 | 978 | $period = $this->get_period(); |
| 979 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 979 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
| 980 | 980 | |
| 981 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 982 | - $this->set_status( 'active' ); |
|
| 981 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
| 982 | + $this->set_status('active'); |
|
| 983 | 983 | $this->save(); |
| 984 | 984 | |
| 985 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 985 | + do_action('getpaid_subscription_renewed', $this); |
|
| 986 | 986 | |
| 987 | 987 | return $this->get_id(); |
| 988 | 988 | } |
@@ -998,11 +998,11 @@ discard block |
||
| 998 | 998 | public function complete() { |
| 999 | 999 | |
| 1000 | 1000 | // Only mark a subscription as complete if it's not already cancelled. |
| 1001 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1001 | + if ($this->has_status('cancelled')) { |
|
| 1002 | 1002 | return false; |
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | - $this->set_status( 'completed' ); |
|
| 1005 | + $this->set_status('completed'); |
|
| 1006 | 1006 | return $this->save(); |
| 1007 | 1007 | |
| 1008 | 1008 | } |
@@ -1014,14 +1014,14 @@ discard block |
||
| 1014 | 1014 | * @param bool $check_expiration |
| 1015 | 1015 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
| 1016 | 1016 | */ |
| 1017 | - public function expire( $check_expiration = false ) { |
|
| 1017 | + public function expire($check_expiration = false) { |
|
| 1018 | 1018 | |
| 1019 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1019 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
| 1020 | 1020 | // Do not mark as expired since real expiration date is in the future |
| 1021 | 1021 | return false; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | - $this->set_status( 'expired' ); |
|
| 1024 | + $this->set_status('expired'); |
|
| 1025 | 1025 | return $this->save(); |
| 1026 | 1026 | |
| 1027 | 1027 | } |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | * @return int Subscription id. |
| 1034 | 1034 | */ |
| 1035 | 1035 | public function failing() { |
| 1036 | - $this->set_status( 'failing' ); |
|
| 1036 | + $this->set_status('failing'); |
|
| 1037 | 1037 | return $this->save(); |
| 1038 | 1038 | } |
| 1039 | 1039 | |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | * @return int Subscription id. |
| 1045 | 1045 | */ |
| 1046 | 1046 | public function cancel() { |
| 1047 | - $this->set_status( 'cancelled' ); |
|
| 1047 | + $this->set_status('cancelled'); |
|
| 1048 | 1048 | return $this->save(); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | * @return bool |
| 1056 | 1056 | */ |
| 1057 | 1057 | public function can_cancel() { |
| 1058 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1058 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
@@ -1066,7 +1066,7 @@ discard block |
||
| 1066 | 1066 | * @return array |
| 1067 | 1067 | */ |
| 1068 | 1068 | public function get_cancellable_statuses() { |
| 1069 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 1069 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | /** |
@@ -1076,8 +1076,8 @@ discard block |
||
| 1076 | 1076 | * @return string |
| 1077 | 1077 | */ |
| 1078 | 1078 | public function get_cancel_url() { |
| 1079 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1080 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1079 | + $url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url()); |
|
| 1080 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | /** |
@@ -1088,10 +1088,10 @@ discard block |
||
| 1088 | 1088 | */ |
| 1089 | 1089 | public function get_view_url() { |
| 1090 | 1090 | |
| 1091 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1092 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1091 | + $url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
| 1092 | + $url = add_query_arg('subscription', $this->get_id(), $url); |
|
| 1093 | 1093 | |
| 1094 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1094 | + return apply_filters('getpaid_get_subscription_view_url', $url, $this); |
|
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | /** |
@@ -1104,7 +1104,7 @@ discard block |
||
| 1104 | 1104 | * @return bool |
| 1105 | 1105 | */ |
| 1106 | 1106 | public function can_renew() { |
| 1107 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1107 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | /** |
@@ -1114,8 +1114,8 @@ discard block |
||
| 1114 | 1114 | * @return string |
| 1115 | 1115 | */ |
| 1116 | 1116 | public function get_renew_url() { |
| 1117 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1118 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1117 | + $url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce'); |
|
| 1118 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | /** |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | * @return bool |
| 1126 | 1126 | */ |
| 1127 | 1127 | public function can_update() { |
| 1128 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1128 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | /** |
@@ -1135,8 +1135,8 @@ discard block |
||
| 1135 | 1135 | * @return string |
| 1136 | 1136 | */ |
| 1137 | 1137 | public function get_update_url() { |
| 1138 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1139 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1138 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id())); |
|
| 1139 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | /** |
@@ -1146,7 +1146,7 @@ discard block |
||
| 1146 | 1146 | * @return string |
| 1147 | 1147 | */ |
| 1148 | 1148 | public function get_status_label() { |
| 1149 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1149 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | */ |
| 1158 | 1158 | public function get_status_class() { |
| 1159 | 1159 | $statuses = getpaid_get_subscription_status_classes(); |
| 1160 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1160 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark'; |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | /** |
@@ -1168,9 +1168,9 @@ discard block |
||
| 1168 | 1168 | */ |
| 1169 | 1169 | public function get_status_label_html() { |
| 1170 | 1170 | |
| 1171 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1172 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1173 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1171 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
| 1172 | + $class = esc_attr($this->get_status_class()); |
|
| 1173 | + $status = sanitize_html_class($this->get_status()); |
|
| 1174 | 1174 | |
| 1175 | 1175 | return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
| 1176 | 1176 | } |
@@ -1182,9 +1182,9 @@ discard block |
||
| 1182 | 1182 | * @param string $txn_id The transaction ID from the merchant processor |
| 1183 | 1183 | * @return bool |
| 1184 | 1184 | */ |
| 1185 | - public function payment_exists( $txn_id = '' ) { |
|
| 1186 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1187 | - return ! empty( $invoice_id ); |
|
| 1185 | + public function payment_exists($txn_id = '') { |
|
| 1186 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
| 1187 | + return !empty($invoice_id); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | /** |
@@ -1196,35 +1196,35 @@ discard block |
||
| 1196 | 1196 | // Reset status transition variable. |
| 1197 | 1197 | $this->status_transition = false; |
| 1198 | 1198 | |
| 1199 | - if ( $status_transition ) { |
|
| 1199 | + if ($status_transition) { |
|
| 1200 | 1200 | try { |
| 1201 | 1201 | |
| 1202 | 1202 | // Fire a hook for the status change. |
| 1203 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1204 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1203 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
| 1204 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
| 1205 | 1205 | |
| 1206 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1206 | + if (!empty($status_transition['from'])) { |
|
| 1207 | 1207 | |
| 1208 | 1208 | /* translators: 1: old subscription status 2: new subscription status */ |
| 1209 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1209 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1210 | 1210 | |
| 1211 | 1211 | // Note the transition occurred. |
| 1212 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1212 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1213 | 1213 | |
| 1214 | 1214 | // Fire another hook. |
| 1215 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1216 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1215 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
| 1216 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
| 1217 | 1217 | |
| 1218 | 1218 | } else { |
| 1219 | 1219 | /* translators: %s: new invoice status */ |
| 1220 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1220 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1221 | 1221 | |
| 1222 | 1222 | // Note the transition occurred. |
| 1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1223 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1224 | 1224 | |
| 1225 | 1225 | } |
| 1226 | - } catch ( Exception $e ) { |
|
| 1227 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1226 | + } catch (Exception $e) { |
|
| 1227 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 1228 | 1228 | } |
| 1229 | 1229 | } |
| 1230 | 1230 | |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | */ |
| 1251 | 1251 | public function activate() { |
| 1252 | 1252 | $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
| 1253 | - $this->set_status( $status ); |
|
| 1253 | + $this->set_status($status); |
|
| 1254 | 1254 | return $this->save(); |
| 1255 | 1255 | } |
| 1256 | 1256 | |