Passed
Push — master ( 6086f2...9dee83 )
by Kiran
09:50 queued 20s
created
includes/class-getpaid-daily-maintenance.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -12,144 +12,144 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
-
33
-	}
34
-
35
-	/**
36
-	 * Schedules a cron to run every day at 7 a.m
37
-	 *
38
-	 */
39
-	public function maybe_create_scheduled_event() {
40
-
41
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
-		}
45
-
46
-	}
47
-
48
-	/**
49
-	 * Clears deprecated events.
50
-	 *
51
-	 */
52
-	public function maybe_clear_deprecated_events() {
53
-
54
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
-			update_option( 'wpinv_cleared_old_events', 1 );
58
-		}
59
-
60
-	}
61
-
62
-	/**
63
-	 * Fires the old hook for backwards compatibility.
64
-	 *
65
-	 */
66
-	public function backwards_compat() {
67
-		do_action( 'wpinv_register_schedule_event_daily' );
68
-	}
69
-
70
-	/**
71
-	 * Checks for subscriptions that are scheduled to renew.
72
-	 *
73
-	 */
74
-	public function check_renewing_subscriptions() {
75
-
76
-		// Fetch subscriptions that expire today.
77
-		$args  = array(
78
-			'number'             => -1,
79
-			'count_total'        => false,
80
-			'status'             => 'trialling active',
81
-			'date_expires_query' => array(
82
-				array(
83
-					'year'    => gmdate( 'Y' ),
84
-					'month'   => gmdate( 'n' ),
85
-					'day'     => gmdate( 'j' ),
86
-					'compare' => '=',
87
-				),
88
-			),
89
-		);
90
-
91
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
92
-
93
-		foreach ( $subscriptions->get_results() as $subscription ) {
94
-
95
-			/** @var WPInv_Subscription $subscription */
96
-			if ( $subscription->is_last_renewal() ) {
97
-				$subscription->complete();
98
-			} else {
99
-				do_action( 'getpaid_should_renew_subscription', $subscription );
100
-			}
101
-		}
102
-
103
-	}
104
-
105
-	/**
106
-	 * Expires expired subscriptions.
107
-	 *
108
-	 */
109
-	public function maybe_expire_subscriptions() {
110
-
111
-		// Fetch expired subscriptions (skips those that expire today).
112
-		$args  = array(
113
-			'number'             => -1,
114
-			'count_total'        => false,
115
-			'status'             => 'trialling active failing cancelled',
116
-			'date_expires_query' => array(
117
-				'before'    => 'yesterday',
118
-				'inclusive' => false,
119
-			),
120
-		);
121
-
122
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
123
-
124
-		foreach ( $subscriptions->get_results() as $subscription ) {
125
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
126
-				$subscription->set_status( 'expired' );
127
-				$subscription->save();
128
-			}
129
-		}
130
-
131
-	}
132
-
133
-	/**
134
-	 * Logs cron runs.
135
-	 *
136
-	 */
137
-	public function log_cron_run() {
138
-		wpinv_error_log( 'GetPaid Daily Cron', false );
139
-	}
140
-
141
-	/**
142
-	 * Updates GeoIP databases.
143
-	 *
144
-	 */
145
-	public function maybe_update_geoip_databases() {
146
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
147
-
148
-		if ( false === $updated ) {
149
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
150
-			do_action( 'getpaid_update_geoip_databases' );
151
-		}
152
-
153
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
+
33
+    }
34
+
35
+    /**
36
+     * Schedules a cron to run every day at 7 a.m
37
+     *
38
+     */
39
+    public function maybe_create_scheduled_event() {
40
+
41
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
+        }
45
+
46
+    }
47
+
48
+    /**
49
+     * Clears deprecated events.
50
+     *
51
+     */
52
+    public function maybe_clear_deprecated_events() {
53
+
54
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
+            update_option( 'wpinv_cleared_old_events', 1 );
58
+        }
59
+
60
+    }
61
+
62
+    /**
63
+     * Fires the old hook for backwards compatibility.
64
+     *
65
+     */
66
+    public function backwards_compat() {
67
+        do_action( 'wpinv_register_schedule_event_daily' );
68
+    }
69
+
70
+    /**
71
+     * Checks for subscriptions that are scheduled to renew.
72
+     *
73
+     */
74
+    public function check_renewing_subscriptions() {
75
+
76
+        // Fetch subscriptions that expire today.
77
+        $args  = array(
78
+            'number'             => -1,
79
+            'count_total'        => false,
80
+            'status'             => 'trialling active',
81
+            'date_expires_query' => array(
82
+                array(
83
+                    'year'    => gmdate( 'Y' ),
84
+                    'month'   => gmdate( 'n' ),
85
+                    'day'     => gmdate( 'j' ),
86
+                    'compare' => '=',
87
+                ),
88
+            ),
89
+        );
90
+
91
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
92
+
93
+        foreach ( $subscriptions->get_results() as $subscription ) {
94
+
95
+            /** @var WPInv_Subscription $subscription */
96
+            if ( $subscription->is_last_renewal() ) {
97
+                $subscription->complete();
98
+            } else {
99
+                do_action( 'getpaid_should_renew_subscription', $subscription );
100
+            }
101
+        }
102
+
103
+    }
104
+
105
+    /**
106
+     * Expires expired subscriptions.
107
+     *
108
+     */
109
+    public function maybe_expire_subscriptions() {
110
+
111
+        // Fetch expired subscriptions (skips those that expire today).
112
+        $args  = array(
113
+            'number'             => -1,
114
+            'count_total'        => false,
115
+            'status'             => 'trialling active failing cancelled',
116
+            'date_expires_query' => array(
117
+                'before'    => 'yesterday',
118
+                'inclusive' => false,
119
+            ),
120
+        );
121
+
122
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
123
+
124
+        foreach ( $subscriptions->get_results() as $subscription ) {
125
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
126
+                $subscription->set_status( 'expired' );
127
+                $subscription->save();
128
+            }
129
+        }
130
+
131
+    }
132
+
133
+    /**
134
+     * Logs cron runs.
135
+     *
136
+     */
137
+    public function log_cron_run() {
138
+        wpinv_error_log( 'GetPaid Daily Cron', false );
139
+    }
140
+
141
+    /**
142
+     * Updates GeoIP databases.
143
+     *
144
+     */
145
+    public function maybe_update_geoip_databases() {
146
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
147
+
148
+        if ( false === $updated ) {
149
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
150
+            do_action( 'getpaid_update_geoip_databases' );
151
+        }
152
+
153
+    }
154 154
 
155 155
 }
Please login to merge, or discard this patch.
templates/subscriptions/subscription-details.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -39,62 +39,62 @@  discard block
 block discarded – undo
39 39
 				<td style="width: 65%">
40 40
 					<?php
41 41
 
42
-						switch ( $key ) {
42
+                        switch ( $key ) {
43 43
 
44
-						case 'status':
45
-							echo esc_html( $subscription->get_status_label() );
46
-							break;
44
+                        case 'status':
45
+                            echo esc_html( $subscription->get_status_label() );
46
+                            break;
47 47
 
48
-						case 'start_date':
49
-							echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) );
50
-							break;
48
+                        case 'start_date':
49
+                            echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) );
50
+                            break;
51 51
 
52
-						case 'expiry_date':
53
-							echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
54
-							break;
52
+                        case 'expiry_date':
53
+                            echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
54
+                            break;
55 55
 
56
-						case 'initial_amount':
57
-							echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) );
56
+                        case 'initial_amount':
57
+                            echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) );
58 58
 
59
-							if ( $subscription->has_trial_period() ) {
59
+                            if ( $subscription->has_trial_period() ) {
60 60
 
61
-								echo "<small class='text-muted'>&nbsp;";
62
-								printf(
63
-									esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
64
-									esc_html( $subscription->get_trial_period() )
65
-								);
66
-								echo '</small>';
61
+                                echo "<small class='text-muted'>&nbsp;";
62
+                                printf(
63
+                                    esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
64
+                                    esc_html( $subscription->get_trial_period() )
65
+                                );
66
+                                echo '</small>';
67 67
 
68
-							}
68
+                            }
69 69
 
70
-							break;
70
+                            break;
71 71
 
72
-						case 'recurring_amount':
73
-							$frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
74
-							$amount    = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
75
-							echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) );
76
-							break;
72
+                        case 'recurring_amount':
73
+                            $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
74
+                            $amount    = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
75
+                            echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) );
76
+                            break;
77 77
 
78
-						case 'item':
79
-							if ( empty( $subscription_group ) ) {
80
-								echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) );
81
-							} else {
82
-								$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
83
-								echo wp_kses_post( implode( ' | ', $markup ) );
84
-							}
78
+                        case 'item':
79
+                            if ( empty( $subscription_group ) ) {
80
+                                echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) );
81
+                            } else {
82
+                                $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
83
+                                echo wp_kses_post( implode( ' | ', $markup ) );
84
+                            }
85 85
 
86
-							break;
86
+                            break;
87 87
 
88
-						case 'payments':
89
-							$max_activations = (int) $subscription->get_bill_times();
90
-							echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '&infin;' : (int) $max_activations );
88
+                        case 'payments':
89
+                            $max_activations = (int) $subscription->get_bill_times();
90
+                            echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '&infin;' : (int) $max_activations );
91 91
 
92
-							break;
92
+                            break;
93 93
 
94
-						}
95
-						do_action( "getpaid_render_single_subscription_column_$key", $subscription );
94
+                        }
95
+                        do_action( "getpaid_render_single_subscription_column_$key", $subscription );
96 96
 
97
-					?>
97
+                    ?>
98 98
 				</td>
99 99
 
100 100
 			</tr>
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
 <span class="form-text">
122 122
 
123 123
 	<?php
124
-		if ( $subscription->can_cancel() ) {
125
-		printf(
124
+        if ( $subscription->can_cancel() ) {
125
+        printf(
126 126
             '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a>&nbsp;&nbsp;',
127 127
             esc_url( $subscription->get_cancel_url() ),
128 128
             esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ),
129 129
             esc_html__( 'Cancel Subscription', 'invoicing' )
130 130
         );
131
-		}
131
+        }
132 132
 
133
-		do_action( 'getpaid-single-subscription-page-actions', $subscription );
134
-	?>
133
+        do_action( 'getpaid-single-subscription-page-actions', $subscription );
134
+    ?>
135 135
 
136 136
 	<a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a>
137 137
 </span>
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-address.php 1 patch
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -16,85 +16,85 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Meta_Box_Invoice_Address {
18 18
 
19
-	/**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
24
-	public static function output( $post ) {
25
-
26
-		// Prepare the invoice.
27
-		$invoice  = new WPInv_Invoice( $post );
28
-		$customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
-		$customer = new WP_User( $customer );
30
-		$display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
-		wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
32
-
33
-		// Address fields.
34
-		$address_fields = array(
35
-			'first_name' => array(
36
-				'label' => __( 'First Name', 'invoicing' ),
37
-				'type'  => 'text',
38
-			),
39
-			'last_name'  => array(
40
-				'label' => __( 'Last Name', 'invoicing' ),
41
-				'type'  => 'text',
42
-			),
43
-			'company'    => array(
44
-				'label' => __( 'Company', 'invoicing' ),
45
-				'type'  => 'text',
46
-				'class' => 'getpaid-recalculate-prices-on-change',
47
-			),
48
-			'vat_number' => array(
49
-				'label' => __( 'VAT Number', 'invoicing' ),
50
-				'type'  => 'text',
51
-				'class' => 'getpaid-recalculate-prices-on-change',
52
-			),
53
-			'address'    => array(
54
-				'label' => __( 'Address', 'invoicing' ),
55
-				'type'  => 'text',
56
-			),
57
-			'city'       => array(
58
-				'label' => __( 'City', 'invoicing' ),
59
-				'type'  => 'text',
60
-			),
61
-			'country'    => array(
62
-				'label'       => __( 'Country', 'invoicing' ),
63
-				'type'        => 'select',
64
-				'class'       => 'getpaid-recalculate-prices-on-change',
65
-				'options'     => wpinv_get_country_list(),
66
-				'placeholder' => __( 'Choose a country', 'invoicing' ),
67
-			),
68
-			'state'      => array(
69
-				'label' => __( 'State', 'invoicing' ),
70
-				'type'  => 'text',
71
-				'class' => 'getpaid-recalculate-prices-on-change',
72
-			),
73
-			'zip'        => array(
74
-				'label' => __( 'Zip', 'invoicing' ),
75
-				'type'  => 'text',
76
-			),
77
-			'phone'      => array(
78
-				'label' => __( 'Phone', 'invoicing' ),
79
-				'type'  => 'text',
80
-			),
81
-		);
82
-
83
-		$states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
84
-
85
-		if ( ! empty( $states ) ) {
86
-			$address_fields['state']['type']        = 'select';
87
-			$address_fields['state']['options']     = $states;
88
-			$address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
89
-		}
90
-
91
-		// Maybe remove the VAT field.
92
-		if ( ! wpinv_use_taxes() ) {
93
-			unset( $address_fields['vat_number'] );
94
-		}
95
-
96
-		$address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
97
-		?>
19
+    /**
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24
+    public static function output( $post ) {
25
+
26
+        // Prepare the invoice.
27
+        $invoice  = new WPInv_Invoice( $post );
28
+        $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
+        $customer = new WP_User( $customer );
30
+        $display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
+        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
32
+
33
+        // Address fields.
34
+        $address_fields = array(
35
+            'first_name' => array(
36
+                'label' => __( 'First Name', 'invoicing' ),
37
+                'type'  => 'text',
38
+            ),
39
+            'last_name'  => array(
40
+                'label' => __( 'Last Name', 'invoicing' ),
41
+                'type'  => 'text',
42
+            ),
43
+            'company'    => array(
44
+                'label' => __( 'Company', 'invoicing' ),
45
+                'type'  => 'text',
46
+                'class' => 'getpaid-recalculate-prices-on-change',
47
+            ),
48
+            'vat_number' => array(
49
+                'label' => __( 'VAT Number', 'invoicing' ),
50
+                'type'  => 'text',
51
+                'class' => 'getpaid-recalculate-prices-on-change',
52
+            ),
53
+            'address'    => array(
54
+                'label' => __( 'Address', 'invoicing' ),
55
+                'type'  => 'text',
56
+            ),
57
+            'city'       => array(
58
+                'label' => __( 'City', 'invoicing' ),
59
+                'type'  => 'text',
60
+            ),
61
+            'country'    => array(
62
+                'label'       => __( 'Country', 'invoicing' ),
63
+                'type'        => 'select',
64
+                'class'       => 'getpaid-recalculate-prices-on-change',
65
+                'options'     => wpinv_get_country_list(),
66
+                'placeholder' => __( 'Choose a country', 'invoicing' ),
67
+            ),
68
+            'state'      => array(
69
+                'label' => __( 'State', 'invoicing' ),
70
+                'type'  => 'text',
71
+                'class' => 'getpaid-recalculate-prices-on-change',
72
+            ),
73
+            'zip'        => array(
74
+                'label' => __( 'Zip', 'invoicing' ),
75
+                'type'  => 'text',
76
+            ),
77
+            'phone'      => array(
78
+                'label' => __( 'Phone', 'invoicing' ),
79
+                'type'  => 'text',
80
+            ),
81
+        );
82
+
83
+        $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
84
+
85
+        if ( ! empty( $states ) ) {
86
+            $address_fields['state']['type']        = 'select';
87
+            $address_fields['state']['options']     = $states;
88
+            $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
89
+        }
90
+
91
+        // Maybe remove the VAT field.
92
+        if ( ! wpinv_use_taxes() ) {
93
+            unset( $address_fields['vat_number'] );
94
+        }
95
+
96
+        $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
97
+        ?>
98 98
 
99 99
 		<style>
100 100
 			#wpinv-address label {
@@ -119,19 +119,19 @@  discard block
 block discarded – undo
119 119
 							<div id="getpaid-invoice-email-wrapper" class="d-none">
120 120
 								<input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" />
121 121
 								<?php
122
-									aui()->input(
123
-										array(
124
-											'type'        => 'text',
125
-											'id'          => 'getpaid-invoice-new-user-email',
126
-											'name'        => 'wpinv_email',
127
-											'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
128
-											'label_type'  => 'vertical',
129
-											'placeholder' => '[email protected]',
130
-											'class'       => 'form-control-sm',
131
-										),
132
-										true
133
-									);
134
-								?>
122
+                                    aui()->input(
123
+                                        array(
124
+                                            'type'        => 'text',
125
+                                            'id'          => 'getpaid-invoice-new-user-email',
126
+                                            'name'        => 'wpinv_email',
127
+                                            'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
128
+                                            'label_type'  => 'vertical',
129
+                                            'placeholder' => '[email protected]',
130
+                                            'class'       => 'form-control-sm',
131
+                                        ),
132
+                                        true
133
+                                    );
134
+                                ?>
135 135
 							</div>
136 136
 						</div>
137 137
 						<div class="col-12 col-sm-6 form-group mb-3 mt-sm-4">
@@ -155,39 +155,39 @@  discard block
 block discarded – undo
155 155
 							<div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper">
156 156
 								<?php
157 157
 
158
-									if ( 'select' === $field['type'] ) {
159
-										aui()->select(
160
-											array(
161
-												'id'               => 'wpinv_' . $key,
162
-												'name'             => 'wpinv_' . $key,
163
-												'label'            => $field['label'],
164
-												'label_type'       => 'vertical',
165
-												'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
166
-												'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
167
-												'value'            => $invoice->get( $key, 'edit' ),
168
-												'options'          => $field['options'],
169
-												'data-allow-clear' => 'false',
170
-												'select2'          => true,
171
-											),
172
-											true
173
-										);
174
-									} else {
175
-										aui()->input(
176
-											array(
177
-												'type'        => $field['type'],
178
-												'id'          => 'wpinv_' . $key,
179
-												'name'        => 'wpinv_' . $key,
180
-												'label'       => $field['label'],
181
-												'label_type'  => 'vertical',
182
-												'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
183
-												'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
184
-												'value'       => $invoice->get( $key, 'edit' ),
185
-											),
186
-											true
187
-										);
188
-									}
189
-
190
-								?>
158
+                                    if ( 'select' === $field['type'] ) {
159
+                                        aui()->select(
160
+                                            array(
161
+                                                'id'               => 'wpinv_' . $key,
162
+                                                'name'             => 'wpinv_' . $key,
163
+                                                'label'            => $field['label'],
164
+                                                'label_type'       => 'vertical',
165
+                                                'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
166
+                                                'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
167
+                                                'value'            => $invoice->get( $key, 'edit' ),
168
+                                                'options'          => $field['options'],
169
+                                                'data-allow-clear' => 'false',
170
+                                                'select2'          => true,
171
+                                            ),
172
+                                            true
173
+                                        );
174
+                                    } else {
175
+                                        aui()->input(
176
+                                            array(
177
+                                                'type'        => $field['type'],
178
+                                                'id'          => 'wpinv_' . $key,
179
+                                                'name'        => 'wpinv_' . $key,
180
+                                                'label'       => $field['label'],
181
+                                                'label_type'  => 'vertical',
182
+                                                'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
183
+                                                'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
184
+                                                'value'       => $invoice->get( $key, 'edit' ),
185
+                                            ),
186
+                                            true
187
+                                        );
188
+                                    }
189
+
190
+                                ?>
191 191
 							</div>
192 192
 						<?php endforeach; ?>
193 193
 					</div>
@@ -198,48 +198,48 @@  discard block
 block discarded – undo
198 198
 						<div class="row">
199 199
 							<div class="col-12 col-sm-6">
200 200
 								<?php
201
-									aui()->select(
202
-										array(
203
-											'id'          => 'wpinv_template',
204
-											'name'        => 'wpinv_template',
205
-											'label'       => __( 'Template', 'invoicing' ),
206
-											'label_type'  => 'vertical',
207
-											'placeholder' => __( 'Choose a template', 'invoicing' ),
208
-											'class'       => 'form-control-sm',
209
-											'value'       => $invoice->get_template( 'edit' ),
210
-											'options'     => array(
211
-												'quantity' => __( 'Quantity', 'invoicing' ),
212
-												'hours'    => __( 'Hours', 'invoicing' ),
213
-											),
214
-											'data-allow-clear' => 'false',
215
-											'select2'     => true,
216
-										),
217
-										true
218
-									);
219
-								?>
201
+                                    aui()->select(
202
+                                        array(
203
+                                            'id'          => 'wpinv_template',
204
+                                            'name'        => 'wpinv_template',
205
+                                            'label'       => __( 'Template', 'invoicing' ),
206
+                                            'label_type'  => 'vertical',
207
+                                            'placeholder' => __( 'Choose a template', 'invoicing' ),
208
+                                            'class'       => 'form-control-sm',
209
+                                            'value'       => $invoice->get_template( 'edit' ),
210
+                                            'options'     => array(
211
+                                                'quantity' => __( 'Quantity', 'invoicing' ),
212
+                                                'hours'    => __( 'Hours', 'invoicing' ),
213
+                                            ),
214
+                                            'data-allow-clear' => 'false',
215
+                                            'select2'     => true,
216
+                                        ),
217
+                                        true
218
+                                    );
219
+                                ?>
220 220
 							</div>
221 221
 							<div class="col-12 col-sm-6">
222 222
 								<?php
223 223
 
224
-									// Set currency.
225
-									aui()->select(
226
-										array(
227
-											'id'          => 'wpinv_currency',
228
-											'name'        => 'wpinv_currency',
229
-											'label'       => __( 'Currency', 'invoicing' ),
230
-											'label_type'  => 'vertical',
231
-											'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
232
-											'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
-											'value'       => $invoice->get_currency( 'edit' ),
234
-											'required'    => false,
235
-											'data-allow-clear' => 'false',
236
-											'select2'     => true,
237
-											'options'     => wpinv_get_currencies(),
238
-										),
239
-										true
240
-									);
241
-
242
-								?>
224
+                                    // Set currency.
225
+                                    aui()->select(
226
+                                        array(
227
+                                            'id'          => 'wpinv_currency',
228
+                                            'name'        => 'wpinv_currency',
229
+                                            'label'       => __( 'Currency', 'invoicing' ),
230
+                                            'label_type'  => 'vertical',
231
+                                            'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
232
+                                            'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
+                                            'value'       => $invoice->get_currency( 'edit' ),
234
+                                            'required'    => false,
235
+                                            'data-allow-clear' => 'false',
236
+                                            'select2'     => true,
237
+                                            'options'     => wpinv_get_currencies(),
238
+                                        ),
239
+                                        true
240
+                                    );
241
+
242
+                                ?>
243 243
 							</div>
244 244
 						</div>
245 245
 
@@ -249,123 +249,123 @@  discard block
 block discarded – undo
249 249
 					<div class="row">
250 250
 						<div class="col-12 col-sm-6">
251 251
 							<?php
252
-								aui()->input(
253
-									array(
254
-										'type'        => 'text',
255
-										'id'          => 'wpinv_company_id',
256
-										'name'        => 'wpinv_company_id',
257
-										'label'       => __( 'Company ID', 'invoicing' ),
258
-										'label_type'  => 'vertical',
259
-										'placeholder' => '',
260
-										'class'       => 'form-control-sm',
261
-										'value'       => $invoice->get_company_id( 'edit' ),
262
-									),
263
-									true
264
-								);
265
-							?>
252
+                                aui()->input(
253
+                                    array(
254
+                                        'type'        => 'text',
255
+                                        'id'          => 'wpinv_company_id',
256
+                                        'name'        => 'wpinv_company_id',
257
+                                        'label'       => __( 'Company ID', 'invoicing' ),
258
+                                        'label_type'  => 'vertical',
259
+                                        'placeholder' => '',
260
+                                        'class'       => 'form-control-sm',
261
+                                        'value'       => $invoice->get_company_id( 'edit' ),
262
+                                    ),
263
+                                    true
264
+                                );
265
+                            ?>
266 266
 						</div>
267 267
 					</div>
268 268
 
269 269
 					<?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?>
270 270
 			</div>
271 271
 		<?php
272
-	}
273
-
274
-	/**
275
-	 * Save meta box data.
276
-	 *
277
-	 * @param int $post_id
278
-	 * @param array $posted the posted data.
279
-	 */
280
-	public static function save( $post_id, $posted ) {
281
-
282
-		// Prepare the invoice.
283
-		$invoice = new WPInv_Invoice( $post_id );
284
-
285
-		// Load new data.
286
-		$invoice->set_props(
287
-			array(
288
-				'template'       => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null,
289
-				'email_cc'       => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null,
290
-				'disable_taxes'  => ! empty( $posted['disable_taxes'] ),
291
-				'currency'       => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null,
292
-				'gateway'        => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null,
293
-				'address'        => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null,
294
-				'vat_number'     => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null,
295
-				'company'        => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null,
296
-				'company_id'     => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null,
297
-				'zip'            => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null,
298
-				'state'          => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null,
299
-				'city'           => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null,
300
-				'country'        => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null,
301
-				'phone'          => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null,
302
-				'first_name'     => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null,
303
-				'last_name'      => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null,
304
-				'author'         => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null,
305
-				'date_created'   => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null,
306
-				'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null,
307
-				'due_date'       => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null,
308
-				'number'         => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null,
309
-				'status'         => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null,
310
-			)
311
-		);
312
-
313
-		// Discount code.
314
-		if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
315
-
316
-			if ( isset( $posted['wpinv_discount_code'] ) ) {
317
-				$invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) );
318
-			}
319
-
320
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
321
-			if ( $discount->exists() ) {
322
-				$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
323
-			} else {
324
-				$invoice->remove_discount( 'discount_code' );
325
-			}
326
-
327
-			// Recalculate totals.
328
-			$invoice->recalculate_total();
329
-
330
-		}
331
-
332
-		// If we're creating a new user...
333
-		if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) {
334
-
335
-			// Attempt to create the user.
336
-			$user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
337
-
338
-			// If successful, update the invoice author.
339
-			if ( is_numeric( $user ) ) {
340
-				$invoice->set_author( $user );
341
-			} else {
342
-				wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
343
-			}
344
-		}
345
-
346
-		// Do not send new invoice notifications.
347
-		$GLOBALS['wpinv_skip_invoice_notification'] = true;
348
-
349
-		// Save the invoice.
350
-		$invoice->save();
351
-
352
-		// Save the user address.
353
-		getpaid_save_invoice_user_address( $invoice );
354
-
355
-		// Undo do not send new invoice notifications.
356
-		$GLOBALS['wpinv_skip_invoice_notification'] = false;
357
-
358
-		// (Maybe) send new user notification.
359
-		$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
360
-		if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
361
-			wp_send_new_user_notifications( $user, 'user' );
362
-		}
363
-
364
-		if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) {
365
-			getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
366
-		}
367
-
368
-		// Fires after an invoice is saved.
369
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
370
-	}
272
+    }
273
+
274
+    /**
275
+     * Save meta box data.
276
+     *
277
+     * @param int $post_id
278
+     * @param array $posted the posted data.
279
+     */
280
+    public static function save( $post_id, $posted ) {
281
+
282
+        // Prepare the invoice.
283
+        $invoice = new WPInv_Invoice( $post_id );
284
+
285
+        // Load new data.
286
+        $invoice->set_props(
287
+            array(
288
+                'template'       => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null,
289
+                'email_cc'       => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null,
290
+                'disable_taxes'  => ! empty( $posted['disable_taxes'] ),
291
+                'currency'       => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null,
292
+                'gateway'        => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null,
293
+                'address'        => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null,
294
+                'vat_number'     => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null,
295
+                'company'        => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null,
296
+                'company_id'     => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null,
297
+                'zip'            => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null,
298
+                'state'          => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null,
299
+                'city'           => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null,
300
+                'country'        => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null,
301
+                'phone'          => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null,
302
+                'first_name'     => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null,
303
+                'last_name'      => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null,
304
+                'author'         => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null,
305
+                'date_created'   => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null,
306
+                'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null,
307
+                'due_date'       => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null,
308
+                'number'         => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null,
309
+                'status'         => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null,
310
+            )
311
+        );
312
+
313
+        // Discount code.
314
+        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
315
+
316
+            if ( isset( $posted['wpinv_discount_code'] ) ) {
317
+                $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) );
318
+            }
319
+
320
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
321
+            if ( $discount->exists() ) {
322
+                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
323
+            } else {
324
+                $invoice->remove_discount( 'discount_code' );
325
+            }
326
+
327
+            // Recalculate totals.
328
+            $invoice->recalculate_total();
329
+
330
+        }
331
+
332
+        // If we're creating a new user...
333
+        if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) {
334
+
335
+            // Attempt to create the user.
336
+            $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
337
+
338
+            // If successful, update the invoice author.
339
+            if ( is_numeric( $user ) ) {
340
+                $invoice->set_author( $user );
341
+            } else {
342
+                wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
343
+            }
344
+        }
345
+
346
+        // Do not send new invoice notifications.
347
+        $GLOBALS['wpinv_skip_invoice_notification'] = true;
348
+
349
+        // Save the invoice.
350
+        $invoice->save();
351
+
352
+        // Save the user address.
353
+        getpaid_save_invoice_user_address( $invoice );
354
+
355
+        // Undo do not send new invoice notifications.
356
+        $GLOBALS['wpinv_skip_invoice_notification'] = false;
357
+
358
+        // (Maybe) send new user notification.
359
+        $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
360
+        if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
361
+            wp_send_new_user_notifications( $user, 'user' );
362
+        }
363
+
364
+        if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) {
365
+            getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
366
+        }
367
+
368
+        // Fires after an invoice is saved.
369
+        do_action( 'wpinv_invoice_metabox_saved', $invoice );
370
+    }
371 371
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'manual';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array(
28 28
         'subscription',
29 29
         'addons',
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
     );
35 35
 
36 36
     /**
37
-	 * Payment method order.
38
-	 *
39
-	 * @var int
40
-	 */
41
-	public $order = 11;
37
+     * Payment method order.
38
+     *
39
+     * @var int
40
+     */
41
+    public $order = 11;
42 42
 
43 43
     /**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47 47
         parent::__construct();
48 48
 
49 49
         $this->title        = __( 'Test Gateway', 'invoicing' );
@@ -53,15 +53,15 @@  discard block
 block discarded – undo
53 53
     }
54 54
 
55 55
     /**
56
-	 * Process Payment.
57
-	 *
58
-	 *
59
-	 * @param WPInv_Invoice $invoice Invoice.
60
-	 * @param array $submission_data Posted checkout fields.
61
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
-	 * @return array
63
-	 */
64
-	public function process_payment( $invoice, $submission_data, $submission ) {
56
+     * Process Payment.
57
+     *
58
+     *
59
+     * @param WPInv_Invoice $invoice Invoice.
60
+     * @param array $submission_data Posted checkout fields.
61
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
+     * @return array
63
+     */
64
+    public function process_payment( $invoice, $submission_data, $submission ) {
65 65
 
66 66
         // Mark it as paid.
67 67
         $invoice->mark_paid();
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * (Maybe) renews a manual subscription profile.
95
-	 *
96
-	 *
94
+     * (Maybe) renews a manual subscription profile.
95
+     *
96
+     *
97 97
      * @param WPInv_Subscription $subscription
98
-	 */
99
-	public function maybe_renew_subscription( $subscription ) {
98
+     */
99
+    public function maybe_renew_subscription( $subscription ) {
100 100
 
101 101
         // Ensure its our subscription && it's active.
102 102
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
     }
117 117
 
118 118
     /**
119
-	 * Processes invoice addons.
120
-	 *
121
-	 * @param WPInv_Invoice $invoice
122
-	 * @param GetPaid_Form_Item[] $items
123
-	 * @return WPInv_Invoice
124
-	 */
125
-	public function process_addons( $invoice, $items ) {
119
+     * Processes invoice addons.
120
+     *
121
+     * @param WPInv_Invoice $invoice
122
+     * @param GetPaid_Form_Item[] $items
123
+     * @return WPInv_Invoice
124
+     */
125
+    public function process_addons( $invoice, $items ) {
126 126
 
127 127
         foreach ( $items as $item ) {
128 128
             $invoice->add_item( $item );
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+        $anchor = __( 'Deactivate', 'invoicing' );
61
+        $title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64 64
     } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) {
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+        $anchor = __( 'Activate', 'invoicing' );
77
+        $title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
             $types = wpinv_get_discount_types();
122 122
 
123 123
             foreach ( $types as $name => $type ) {
124
-			echo '<option value="' . esc_attr( $name ) . '"';
124
+            echo '<option value="' . esc_attr( $name ) . '"';
125 125
 
126
-			if ( isset( $_GET['discount_type'] ) ) {
127
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
126
+            if ( isset( $_GET['discount_type'] ) ) {
127
+                selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
128 128
                 }
129 129
 
130
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
130
+            echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
131 131
             }
132 132
         ?>
133 133
     </select>
@@ -154,15 +154,15 @@  discard block
 block discarded – undo
154 154
         // Filter vat rule type
155 155
         if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
156 156
             $meta_query[] = array(
157
-				'key'     => '_wpi_discount_type',
158
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
159
-				'compare' => '=',
160
-			);
161
-			}
157
+                'key'     => '_wpi_discount_type',
158
+                'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
159
+                'compare' => '=',
160
+            );
161
+            }
162 162
 
163 163
         if ( ! empty( $meta_query ) ) {
164 164
             $vars['meta_query'] = $meta_query;
165
-			}
165
+            }
166 166
     }
167 167
 
168 168
     return $vars;
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array(
28 28
         'subscription',
29 29
         'sandbox',
@@ -36,44 +36,44 @@  discard block
 block discarded – undo
36 36
     );
37 37
 
38 38
     /**
39
-	 * Payment method order.
40
-	 *
41
-	 * @var int
42
-	 */
39
+     * Payment method order.
40
+     *
41
+     * @var int
42
+     */
43 43
     public $order = 4;
44 44
 
45 45
     /**
46
-	 * Endpoint for requests from Authorize.net.
47
-	 *
48
-	 * @var string
49
-	 */
50
-	protected $notify_url;
51
-
52
-	/**
53
-	 * Endpoint for requests to Authorize.net.
54
-	 *
55
-	 * @var string
56
-	 */
46
+     * Endpoint for requests from Authorize.net.
47
+     *
48
+     * @var string
49
+     */
50
+    protected $notify_url;
51
+
52
+    /**
53
+     * Endpoint for requests to Authorize.net.
54
+     *
55
+     * @var string
56
+     */
57 57
     protected $endpoint;
58 58
 
59 59
     /**
60
-	 * Currencies this gateway is allowed for.
61
-	 *
62
-	 * @var array
63
-	 */
64
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
60
+     * Currencies this gateway is allowed for.
61
+     *
62
+     * @var array
63
+     */
64
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
65 65
 
66 66
     /**
67
-	 * URL to view a transaction.
68
-	 *
69
-	 * @var string
70
-	 */
67
+     * URL to view a transaction.
68
+     *
69
+     * @var string
70
+     */
71 71
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
72 72
 
73 73
     /**
74
-	 * Class constructor.
75
-	 */
76
-	public function __construct() {
74
+     * Class constructor.
75
+     */
76
+    public function __construct() {
77 77
 
78 78
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
79 79
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * Displays the payment method select field.
89
-	 *
90
-	 * @param int $invoice_id 0 or invoice id.
91
-	 * @param GetPaid_Payment_Form $form Current payment form.
92
-	 */
88
+     * Displays the payment method select field.
89
+     *
90
+     * @param int $invoice_id 0 or invoice id.
91
+     * @param GetPaid_Payment_Form $form Current payment form.
92
+     */
93 93
     public function payment_fields( $invoice_id, $form ) {
94 94
 
95 95
         // Let the user select a payment method.
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
     }
101 101
 
102 102
     /**
103
-	 * Creates a customer profile.
104
-	 *
105
-	 *
106
-	 * @param WPInv_Invoice $invoice Invoice.
103
+     * Creates a customer profile.
104
+     *
105
+     *
106
+     * @param WPInv_Invoice $invoice Invoice.
107 107
      * @param array $submission_data Posted checkout fields.
108 108
      * @param bool $save Whether or not to save the payment as a token.
109 109
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
110
-	 * @return string|WP_Error Payment profile id.
111
-	 */
112
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
110
+     * @return string|WP_Error Payment profile id.
111
+     */
112
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
113 113
 
114 114
         // Remove non-digits from the number
115 115
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Retrieves a customer profile.
195
-	 *
196
-	 *
197
-	 * @param string $profile_id profile id.
198
-	 * @return string|WP_Error Profile id.
194
+     * Retrieves a customer profile.
195
+     *
196
+     *
197
+     * @param string $profile_id profile id.
198
+     * @return string|WP_Error Profile id.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
200
-	 */
201
-	public function get_customer_profile( $profile_id ) {
200
+     */
201
+    public function get_customer_profile( $profile_id ) {
202 202
 
203 203
         // Generate args.
204 204
         $args = array(
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
     }
214 214
 
215 215
     /**
216
-	 * Creates a customer profile.
217
-	 *
218
-	 *
216
+     * Creates a customer profile.
217
+     *
218
+     *
219 219
      * @param string $profile_id profile id.
220
-	 * @param WPInv_Invoice $invoice Invoice.
220
+     * @param WPInv_Invoice $invoice Invoice.
221 221
      * @param array $submission_data Posted checkout fields.
222 222
      * @param bool $save Whether or not to save the payment as a token.
223 223
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
224
-	 * @return string|WP_Error Profile id.
225
-	 */
226
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
224
+     * @return string|WP_Error Profile id.
225
+     */
226
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
227 227
 
228 228
         // Remove non-digits from the number
229 229
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
     }
312 312
 
313 313
     /**
314
-	 * Retrieves payment details from cache.
315
-	 *
316
-	 *
314
+     * Retrieves payment details from cache.
315
+     *
316
+     *
317 317
      * @param array $payment_details.
318
-	 * @return array|false Profile id.
319
-	 */
320
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
318
+     * @return array|false Profile id.
319
+     */
320
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
321 321
 
322 322
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
323 323
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
     }
343 343
 
344 344
     /**
345
-	 * Securely adds payment details to cache.
346
-	 *
347
-	 *
345
+     * Securely adds payment details to cache.
346
+     *
347
+     *
348 348
      * @param array $payment_details.
349 349
      * @param string $payment_profile_id.
350
-	 */
351
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
350
+     */
351
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
352 352
 
353 353
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
354 354
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -360,15 +360,15 @@  discard block
 block discarded – undo
360 360
     }
361 361
 
362 362
     /**
363
-	 * Retrieves a customer payment profile.
364
-	 *
365
-	 *
366
-	 * @param string $customer_profile_id customer profile id.
363
+     * Retrieves a customer payment profile.
364
+     *
365
+     *
366
+     * @param string $customer_profile_id customer profile id.
367 367
      * @param string $payment_profile_id payment profile id.
368
-	 * @return string|WP_Error Profile id.
368
+     * @return string|WP_Error Profile id.
369 369
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
370
-	 */
371
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
370
+     */
371
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
372 372
 
373 373
         // Generate args.
374 374
         $args = array(
@@ -384,15 +384,15 @@  discard block
 block discarded – undo
384 384
     }
385 385
 
386 386
     /**
387
-	 * Charges a customer payment profile.
388
-	 *
387
+     * Charges a customer payment profile.
388
+     *
389 389
      * @param string $customer_profile_id customer profile id.
390 390
      * @param string $payment_profile_id payment profile id.
391
-	 * @param WPInv_Invoice $invoice Invoice.
391
+     * @param WPInv_Invoice $invoice Invoice.
392 392
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
393
-	 * @return WP_Error|object
394
-	 */
395
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
393
+     * @return WP_Error|object
394
+     */
395
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
396 396
 
397 397
         // Generate args.
398 398
         $args = array(
@@ -438,43 +438,43 @@  discard block
 block discarded – undo
438 438
     }
439 439
 
440 440
     /**
441
-	 * Processes a customer charge.
442
-	 *
441
+     * Processes a customer charge.
442
+     *
443 443
      * @param stdClass $result Api response.
444
-	 * @param WPInv_Invoice $invoice Invoice.
445
-	 */
446
-	public function process_charge_response( $result, $invoice ) {
444
+     * @param WPInv_Invoice $invoice Invoice.
445
+     */
446
+    public function process_charge_response( $result, $invoice ) {
447 447
 
448 448
         wpinv_clear_errors();
449
-		$response_code = (int) $result->transactionResponse->responseCode;
449
+        $response_code = (int) $result->transactionResponse->responseCode;
450 450
 
451 451
         $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true );
452 452
 
453
-		// Succeeded.
454
-		if ( 1 == $response_code || 4 == $response_code ) {
453
+        // Succeeded.
454
+        if ( 1 == $response_code || 4 == $response_code ) {
455 455
 
456
-			// Maybe set a transaction id.
457
-			if ( ! empty( $result->transactionResponse->transId ) ) {
458
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
459
-			}
456
+            // Maybe set a transaction id.
457
+            if ( ! empty( $result->transactionResponse->transId ) ) {
458
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
459
+            }
460 460
 
461
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
461
+            $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
462 462
 
463
-			if ( 1 == $response_code ) {
464
-				return $invoice->mark_paid();
465
-			}
463
+            if ( 1 == $response_code ) {
464
+                return $invoice->mark_paid();
465
+            }
466 466
 
467
-			$invoice->set_status( 'wpi-onhold' );
468
-        	$invoice->add_note(
467
+            $invoice->set_status( 'wpi-onhold' );
468
+            $invoice->add_note(
469 469
                 sprintf(
470 470
                     __( 'Held for review: %s', 'invoicing' ),
471 471
                     $result->transactionResponse->messages->message[0]->description
472 472
                 )
473
-			);
473
+            );
474 474
 
475
-			return $invoice->save();
475
+            return $invoice->save();
476 476
 
477
-		}
477
+        }
478 478
 
479 479
         wpinv_set_error( 'card_declined' );
480 480
 
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
     }
487 487
 
488 488
     /**
489
-	 * Returns payment information.
490
-	 *
491
-	 *
492
-	 * @param array $card Card details.
493
-	 * @return array
494
-	 */
495
-	public function get_payment_information( $card ) {
489
+     * Returns payment information.
490
+     *
491
+     *
492
+     * @param array $card Card details.
493
+     * @return array
494
+     */
495
+    public function get_payment_information( $card ) {
496 496
         return array(
497 497
 
498 498
             'creditCard' => array(
@@ -505,25 +505,25 @@  discard block
 block discarded – undo
505 505
     }
506 506
 
507 507
     /**
508
-	 * Returns the customer profile meta name.
509
-	 *
510
-	 *
511
-	 * @param WPInv_Invoice $invoice Invoice.
512
-	 * @return string
513
-	 */
514
-	public function get_customer_profile_meta_name( $invoice ) {
508
+     * Returns the customer profile meta name.
509
+     *
510
+     *
511
+     * @param WPInv_Invoice $invoice Invoice.
512
+     * @return string
513
+     */
514
+    public function get_customer_profile_meta_name( $invoice ) {
515 515
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
516 516
     }
517 517
 
518 518
     /**
519
-	 * Validates the submitted data.
520
-	 *
521
-	 *
522
-	 * @param array $submission_data Posted checkout fields.
519
+     * Validates the submitted data.
520
+     *
521
+     *
522
+     * @param array $submission_data Posted checkout fields.
523 523
      * @param WPInv_Invoice $invoice
524
-	 * @return WP_Error|string The payment profile id
525
-	 */
526
-	public function validate_submission_data( $submission_data, $invoice ) {
524
+     * @return WP_Error|string The payment profile id
525
+     */
526
+    public function validate_submission_data( $submission_data, $invoice ) {
527 527
 
528 528
         // Validate authentication details.
529 529
         $auth = $this->get_auth_params();
@@ -555,13 +555,13 @@  discard block
 block discarded – undo
555 555
     }
556 556
 
557 557
     /**
558
-	 * Returns invoice line items.
559
-	 *
560
-	 *
561
-	 * @param WPInv_Invoice $invoice Invoice.
562
-	 * @return array
563
-	 */
564
-	public function get_line_items( $invoice ) {
558
+     * Returns invoice line items.
559
+     *
560
+     *
561
+     * @param WPInv_Invoice $invoice Invoice.
562
+     * @return array
563
+     */
564
+    public function get_line_items( $invoice ) {
565 565
         $items = array();
566 566
 
567 567
         foreach ( $invoice->get_items() as $item ) {
@@ -598,15 +598,15 @@  discard block
 block discarded – undo
598 598
     }
599 599
 
600 600
     /**
601
-	 * Process Payment.
602
-	 *
603
-	 *
604
-	 * @param WPInv_Invoice $invoice Invoice.
605
-	 * @param array $submission_data Posted checkout fields.
606
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
-	 * @return array
608
-	 */
609
-	public function process_payment( $invoice, $submission_data, $submission ) {
601
+     * Process Payment.
602
+     *
603
+     *
604
+     * @param WPInv_Invoice $invoice Invoice.
605
+     * @param array $submission_data Posted checkout fields.
606
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
+     * @return array
608
+     */
609
+    public function process_payment( $invoice, $submission_data, $submission ) {
610 610
 
611 611
         // Validate the submitted data.
612 612
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -639,45 +639,45 @@  discard block
 block discarded – undo
639 639
 
640 640
         exit;
641 641
 
642
-	}
642
+    }
643 643
 
644
-	/**
645
-	 * Processes the initial payment.
646
-	 *
644
+    /**
645
+     * Processes the initial payment.
646
+     *
647 647
      * @param WPInv_Invoice $invoice Invoice.
648
-	 */
649
-	protected function process_initial_payment( $invoice ) {
648
+     */
649
+    protected function process_initial_payment( $invoice ) {
650 650
 
651
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
651
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
652 652
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
653
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
653
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
654 654
 
655
-		// Do we have an error?
656
-		if ( is_wp_error( $result ) ) {
657
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
-			wpinv_send_back_to_checkout( $invoice );
659
-		}
655
+        // Do we have an error?
656
+        if ( is_wp_error( $result ) ) {
657
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
+            wpinv_send_back_to_checkout( $invoice );
659
+        }
660 660
 
661
-		// Process the response.
662
-		$this->process_charge_response( $result, $invoice );
661
+        // Process the response.
662
+        $this->process_charge_response( $result, $invoice );
663 663
 
664
-		if ( wpinv_get_errors() ) {
665
-			wpinv_send_back_to_checkout( $invoice );
666
-		}
664
+        if ( wpinv_get_errors() ) {
665
+            wpinv_send_back_to_checkout( $invoice );
666
+        }
667 667
 
668
-	}
668
+    }
669 669
 
670 670
     /**
671
-	 * Processes recurring payments.
672
-	 *
671
+     * Processes recurring payments.
672
+     *
673 673
      * @param WPInv_Invoice $invoice Invoice.
674 674
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
675
-	 */
676
-	public function process_subscription( $invoice, $subscriptions ) {
675
+     */
676
+    public function process_subscription( $invoice, $subscriptions ) {
677 677
 
678 678
         // Check if there is an initial amount to charge.
679 679
         if ( (float) $invoice->get_total() > 0 ) {
680
-			$this->process_initial_payment( $invoice );
680
+            $this->process_initial_payment( $invoice );
681 681
         }
682 682
 
683 683
         // Activate the subscriptions.
@@ -695,36 +695,36 @@  discard block
 block discarded – undo
695 695
             }
696 696
         }
697 697
 
698
-		// Redirect to the success page.
698
+        // Redirect to the success page.
699 699
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
700 700
 
701 701
     }
702 702
 
703
-	/**
704
-	 * (Maybe) renews an authorize.net subscription profile.
705
-	 *
706
-	 *
703
+    /**
704
+     * (Maybe) renews an authorize.net subscription profile.
705
+     *
706
+     *
707 707
      * @param WPInv_Subscription $subscription
708
-	 */
709
-	public function maybe_renew_subscription( $subscription ) {
708
+     */
709
+    public function maybe_renew_subscription( $subscription ) {
710 710
 
711 711
         // Ensure its our subscription && it's active.
712 712
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
713 713
             $this->renew_subscription( $subscription );
714 714
         }
715 715
 
716
-	}
716
+    }
717 717
 
718 718
     /**
719
-	 * Renews a subscription.
720
-	 *
719
+     * Renews a subscription.
720
+     *
721 721
      * @param WPInv_Subscription $subscription
722
-	 */
723
-	public function renew_subscription( $subscription ) {
722
+     */
723
+    public function renew_subscription( $subscription ) {
724 724
 
725
-		// Generate the renewal invoice.
726
-		$new_invoice = $subscription->create_payment();
727
-		$old_invoice = $subscription->get_parent_payment();
725
+        // Generate the renewal invoice.
726
+        $new_invoice = $subscription->create_payment();
727
+        $old_invoice = $subscription->get_parent_payment();
728 728
 
729 729
         if ( empty( $new_invoice ) ) {
730 730
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -733,37 +733,37 @@  discard block
 block discarded – undo
733 733
         }
734 734
 
735 735
         // Charge the payment method.
736
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
-
740
-		// Do we have an error?
741
-		if ( is_wp_error( $result ) ) {
742
-
743
-			$old_invoice->add_note(
744
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
-				true,
746
-				false,
747
-				true
748
-			);
749
-			$subscription->failing();
750
-			return;
751
-
752
-		}
753
-
754
-		// Process the response.
755
-		$this->process_charge_response( $result, $new_invoice );
756
-
757
-		if ( wpinv_get_errors() ) {
758
-
759
-			$old_invoice->add_note(
760
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
-				true,
762
-				false,
763
-				true
764
-			);
765
-			$subscription->failing();
766
-			return;
736
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
+
740
+        // Do we have an error?
741
+        if ( is_wp_error( $result ) ) {
742
+
743
+            $old_invoice->add_note(
744
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
+                true,
746
+                false,
747
+                true
748
+            );
749
+            $subscription->failing();
750
+            return;
751
+
752
+        }
753
+
754
+        // Process the response.
755
+        $this->process_charge_response( $result, $new_invoice );
756
+
757
+        if ( wpinv_get_errors() ) {
758
+
759
+            $old_invoice->add_note(
760
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
+                true,
762
+                false,
763
+                true
764
+            );
765
+            $subscription->failing();
766
+            return;
767 767
 
768 768
         }
769 769
 
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
     }
777 777
 
778 778
     /**
779
-	 * Processes invoice addons.
780
-	 *
781
-	 * @param WPInv_Invoice $invoice
782
-	 * @param GetPaid_Form_Item[] $items
783
-	 * @return WPInv_Invoice
784
-	 */
785
-	public function process_addons( $invoice, $items ) {
779
+     * Processes invoice addons.
780
+     *
781
+     * @param WPInv_Invoice $invoice
782
+     * @param GetPaid_Form_Item[] $items
783
+     * @return WPInv_Invoice
784
+     */
785
+    public function process_addons( $invoice, $items ) {
786 786
 
787 787
         global $getpaid_authorize_addons;
788 788
 
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
         $invoice->recalculate_total();
802 802
 
803 803
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
804
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
804
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
805 805
 
806 806
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
807 807
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
     }
817 817
 
818 818
     /**
819
-	 * Processes invoice addons.
820
-	 *
819
+     * Processes invoice addons.
820
+     *
821 821
      * @param array $args
822
-	 * @return array
823
-	 */
822
+     * @return array
823
+     */
824 824
     public function filter_addons_request( $args ) {
825 825
 
826 826
         global $getpaid_authorize_addons;
@@ -854,11 +854,11 @@  discard block
 block discarded – undo
854 854
     }
855 855
 
856 856
     /**
857
-	 * Filters the gateway settings.
858
-	 *
859
-	 * @param array $admin_settings
860
-	 */
861
-	public function admin_settings( $admin_settings ) {
857
+     * Filters the gateway settings.
858
+     *
859
+     * @param array $admin_settings
860
+     */
861
+    public function admin_settings( $admin_settings ) {
862 862
 
863 863
         $currencies = sprintf(
864 864
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
             'readonly' => true,
899 899
         );
900 900
 
901
-		return $admin_settings;
902
-	}
901
+        return $admin_settings;
902
+    }
903 903
 
904 904
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -11,187 +11,187 @@
 block discarded – undo
11 11
  */
12 12
 class GetPaid_Data_Store {
13 13
 
14
-	/**
15
-	 * Contains an instance of the data store class that we are working with.
16
-	 *
17
-	 * @var GetPaid_Data_Store
18
-	 */
19
-	private $instance = null;
20
-
21
-	/**
22
-	 * Contains an array of default supported data stores.
23
-	 * Format of object name => class name.
24
-	 * Example: 'item' => 'GetPaid_Item_Data_Store'
25
-	 * You can also pass something like item-<type> for item stores and
26
-	 * that type will be used first when available, if a store is requested like
27
-	 * this and doesn't exist, then the store would fall back to 'item'.
28
-	 * Ran through `getpaid_data_stores`.
29
-	 *
30
-	 * @var array
31
-	 */
32
-	private $stores = array(
33
-		'item'         => 'GetPaid_Item_Data_Store',
34
-		'payment_form' => 'GetPaid_Payment_Form_Data_Store',
35
-		'discount'     => 'GetPaid_Discount_Data_Store',
36
-		'invoice'      => 'GetPaid_Invoice_Data_Store',
37
-		'subscription' => 'GetPaid_Subscription_Data_Store',
38
-		'customer'     => 'GetPaid_Customer_Data_Store',
39
-	);
40
-
41
-	/**
42
-	 * Contains the name of the current data store's class name.
43
-	 *
44
-	 * @var string
45
-	 */
46
-	private $current_class_name = '';
47
-
48
-	/**
49
-	 * The object type this store works with.
50
-	 *
51
-	 * @var string
52
-	 */
53
-	private $object_type = '';
54
-
55
-	/**
56
-	 * Tells GetPaid_Data_Store which object
57
-	 * store we want to work with.
58
-	 *
59
-	 * @param string $object_type Name of object.
60
-	 */
61
-	public function __construct( $object_type ) {
62
-		$this->object_type = $object_type;
63
-		$this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
64
-
65
-		// If this object type can't be found, check to see if we can load one
66
-		// level up (so if item-type isn't found, we try item).
67
-		if ( ! array_key_exists( $object_type, $this->stores ) ) {
68
-			$pieces      = explode( '-', $object_type );
69
-			$object_type = $pieces[0];
70
-		}
71
-
72
-		if ( array_key_exists( $object_type, $this->stores ) ) {
73
-			$store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
74
-			if ( is_object( $store ) ) {
75
-				$this->current_class_name = get_class( $store );
76
-				$this->instance           = $store;
77
-			} else {
78
-				if ( ! class_exists( $store ) ) {
79
-					throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) );
80
-				}
81
-				$this->current_class_name = $store;
82
-				$this->instance           = new $store();
83
-			}
84
-		} else {
85
-			throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
86
-		}
87
-	}
88
-
89
-	/**
90
-	 * Only store the object type to avoid serializing the data store instance.
91
-	 *
92
-	 * @return array
93
-	 */
94
-	public function __sleep() {
95
-		return array( 'object_type' );
96
-	}
97
-
98
-	/**
99
-	 * Re-run the constructor with the object type.
100
-	 *
101
-	 * @throws Exception When validation fails.
102
-	 */
103
-	public function __wakeup() {
104
-		$this->__construct( $this->object_type );
105
-	}
106
-
107
-	/**
108
-	 * Loads a data store.
109
-	 *
110
-	 * @param string $object_type Name of object.
111
-	 *
112
-	 * @since 1.0.19
113
-	 * @throws Exception When validation fails.
114
-	 * @return GetPaid_Data_Store
115
-	 */
116
-	public static function load( $object_type ) {
117
-		return new GetPaid_Data_Store( $object_type );
118
-	}
119
-
120
-	/**
121
-	 * Returns the class name of the current data store.
122
-	 *
123
-	 * @since 1.0.19
124
-	 * @return string
125
-	 */
126
-	public function get_current_class_name() {
127
-		return $this->current_class_name;
128
-	}
129
-
130
-	/**
131
-	 * Returns the object type of the current data store.
132
-	 *
133
-	 * @since 1.0.19
134
-	 * @return string
135
-	 */
136
-	public function get_object_type() {
137
-		return $this->object_type;
138
-	}
139
-
140
-	/**
141
-	 * Reads an object from the data store.
142
-	 *
143
-	 * @since 1.0.19
144
-	 * @param GetPaid_Data $data GetPaid data instance.
145
-	 */
146
-	public function read( &$data ) {
147
-		$this->instance->read( $data );
148
-	}
149
-
150
-	/**
151
-	 * Create an object in the data store.
152
-	 *
153
-	 * @since 1.0.19
154
-	 * @param GetPaid_Data $data GetPaid data instance.
155
-	 */
156
-	public function create( &$data ) {
157
-		$this->instance->create( $data );
158
-	}
159
-
160
-	/**
161
-	 * Update an object in the data store.
162
-	 *
163
-	 * @since 1.0.19
164
-	 * @param GetPaid_Data $data GetPaid data instance.
165
-	 */
166
-	public function update( &$data ) {
167
-		$this->instance->update( $data );
168
-	}
169
-
170
-	/**
171
-	 * Delete an object from the data store.
172
-	 *
173
-	 * @since 1.0.19
174
-	 * @param GetPaid_Data $data GetPaid data instance.
175
-	 * @param array   $args Array of args to pass to the delete method.
176
-	 */
177
-	public function delete( &$data, $args = array() ) {
178
-		$this->instance->delete( $data, $args );
179
-	}
180
-
181
-	/**
182
-	 * Data stores can define additional function. This passes
183
-	 * through to the instance if that function exists.
184
-	 *
185
-	 * @since 1.0.19
186
-	 * @param string $method     Method.
187
-	 * @return mixed
188
-	 */
189
-	public function __call( $method, $parameters ) {
190
-		if ( is_callable( array( $this->instance, $method ) ) ) {
191
-			$object     = array_shift( $parameters );
192
-			$parameters = array_merge( array( &$object ), $parameters );
193
-			return call_user_func_array( array( $this->instance, $method ), $parameters );
194
-		}
195
-	}
14
+    /**
15
+     * Contains an instance of the data store class that we are working with.
16
+     *
17
+     * @var GetPaid_Data_Store
18
+     */
19
+    private $instance = null;
20
+
21
+    /**
22
+     * Contains an array of default supported data stores.
23
+     * Format of object name => class name.
24
+     * Example: 'item' => 'GetPaid_Item_Data_Store'
25
+     * You can also pass something like item-<type> for item stores and
26
+     * that type will be used first when available, if a store is requested like
27
+     * this and doesn't exist, then the store would fall back to 'item'.
28
+     * Ran through `getpaid_data_stores`.
29
+     *
30
+     * @var array
31
+     */
32
+    private $stores = array(
33
+        'item'         => 'GetPaid_Item_Data_Store',
34
+        'payment_form' => 'GetPaid_Payment_Form_Data_Store',
35
+        'discount'     => 'GetPaid_Discount_Data_Store',
36
+        'invoice'      => 'GetPaid_Invoice_Data_Store',
37
+        'subscription' => 'GetPaid_Subscription_Data_Store',
38
+        'customer'     => 'GetPaid_Customer_Data_Store',
39
+    );
40
+
41
+    /**
42
+     * Contains the name of the current data store's class name.
43
+     *
44
+     * @var string
45
+     */
46
+    private $current_class_name = '';
47
+
48
+    /**
49
+     * The object type this store works with.
50
+     *
51
+     * @var string
52
+     */
53
+    private $object_type = '';
54
+
55
+    /**
56
+     * Tells GetPaid_Data_Store which object
57
+     * store we want to work with.
58
+     *
59
+     * @param string $object_type Name of object.
60
+     */
61
+    public function __construct( $object_type ) {
62
+        $this->object_type = $object_type;
63
+        $this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
64
+
65
+        // If this object type can't be found, check to see if we can load one
66
+        // level up (so if item-type isn't found, we try item).
67
+        if ( ! array_key_exists( $object_type, $this->stores ) ) {
68
+            $pieces      = explode( '-', $object_type );
69
+            $object_type = $pieces[0];
70
+        }
71
+
72
+        if ( array_key_exists( $object_type, $this->stores ) ) {
73
+            $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
74
+            if ( is_object( $store ) ) {
75
+                $this->current_class_name = get_class( $store );
76
+                $this->instance           = $store;
77
+            } else {
78
+                if ( ! class_exists( $store ) ) {
79
+                    throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) );
80
+                }
81
+                $this->current_class_name = $store;
82
+                $this->instance           = new $store();
83
+            }
84
+        } else {
85
+            throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
86
+        }
87
+    }
88
+
89
+    /**
90
+     * Only store the object type to avoid serializing the data store instance.
91
+     *
92
+     * @return array
93
+     */
94
+    public function __sleep() {
95
+        return array( 'object_type' );
96
+    }
97
+
98
+    /**
99
+     * Re-run the constructor with the object type.
100
+     *
101
+     * @throws Exception When validation fails.
102
+     */
103
+    public function __wakeup() {
104
+        $this->__construct( $this->object_type );
105
+    }
106
+
107
+    /**
108
+     * Loads a data store.
109
+     *
110
+     * @param string $object_type Name of object.
111
+     *
112
+     * @since 1.0.19
113
+     * @throws Exception When validation fails.
114
+     * @return GetPaid_Data_Store
115
+     */
116
+    public static function load( $object_type ) {
117
+        return new GetPaid_Data_Store( $object_type );
118
+    }
119
+
120
+    /**
121
+     * Returns the class name of the current data store.
122
+     *
123
+     * @since 1.0.19
124
+     * @return string
125
+     */
126
+    public function get_current_class_name() {
127
+        return $this->current_class_name;
128
+    }
129
+
130
+    /**
131
+     * Returns the object type of the current data store.
132
+     *
133
+     * @since 1.0.19
134
+     * @return string
135
+     */
136
+    public function get_object_type() {
137
+        return $this->object_type;
138
+    }
139
+
140
+    /**
141
+     * Reads an object from the data store.
142
+     *
143
+     * @since 1.0.19
144
+     * @param GetPaid_Data $data GetPaid data instance.
145
+     */
146
+    public function read( &$data ) {
147
+        $this->instance->read( $data );
148
+    }
149
+
150
+    /**
151
+     * Create an object in the data store.
152
+     *
153
+     * @since 1.0.19
154
+     * @param GetPaid_Data $data GetPaid data instance.
155
+     */
156
+    public function create( &$data ) {
157
+        $this->instance->create( $data );
158
+    }
159
+
160
+    /**
161
+     * Update an object in the data store.
162
+     *
163
+     * @since 1.0.19
164
+     * @param GetPaid_Data $data GetPaid data instance.
165
+     */
166
+    public function update( &$data ) {
167
+        $this->instance->update( $data );
168
+    }
169
+
170
+    /**
171
+     * Delete an object from the data store.
172
+     *
173
+     * @since 1.0.19
174
+     * @param GetPaid_Data $data GetPaid data instance.
175
+     * @param array   $args Array of args to pass to the delete method.
176
+     */
177
+    public function delete( &$data, $args = array() ) {
178
+        $this->instance->delete( $data, $args );
179
+    }
180
+
181
+    /**
182
+     * Data stores can define additional function. This passes
183
+     * through to the instance if that function exists.
184
+     *
185
+     * @since 1.0.19
186
+     * @param string $method     Method.
187
+     * @return mixed
188
+     */
189
+    public function __call( $method, $parameters ) {
190
+        if ( is_callable( array( $this->instance, $method ) ) ) {
191
+            $object     = array_shift( $parameters );
192
+            $parameters = array_merge( array( &$object ), $parameters );
193
+            return call_user_func_array( array( $this->instance, $method ), $parameters );
194
+        }
195
+    }
196 196
 
197 197
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-customer-data-store.php 1 patch
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,196 +15,196 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Customer_Data_Store {
17 17
 
18
-	/*
18
+    /*
19 19
 	|--------------------------------------------------------------------------
20 20
 	| CRUD Methods
21 21
 	|--------------------------------------------------------------------------
22 22
 	*/
23 23
 
24
-	/**
25
-	 * Method to create a new customer in the database.
26
-	 *
27
-	 * @param GetPaid_Customer $customer customer object.
28
-	 */
29
-	public function create( &$customer ) {
30
-		global $wpdb;
31
-
32
-		$values  = array();
33
-		$formats = array();
34
-
35
-		$fields = self::get_database_fields();
36
-		unset( $fields['id'] );
37
-
38
-		foreach ( $fields as $key => $format ) {
39
-			$values[ $key ] = $customer->get( $key, 'edit' );
40
-			$formats[]      = $format;
41
-		}
42
-
43
-		$result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
44
-
45
-		if ( $result ) {
46
-			$customer->set_id( $wpdb->insert_id );
47
-			$customer->apply_changes();
48
-			$customer->clear_cache();
49
-			do_action( 'getpaid_new_customer', $customer );
50
-			return true;
51
-		}
52
-
53
-		return false;
54
-	}
55
-
56
-	/**
57
-	 * Method to read a customer from the database.
58
-	 *
59
-	 * @param GetPaid_Customer $customer customer object.
60
-	 *
61
-	 */
62
-	public function read( &$customer ) {
63
-		global $wpdb;
64
-
65
-		$customer->set_defaults();
66
-
67
-		if ( ! $customer->get_id() ) {
68
-			$customer->last_error = 'Invalid customer.';
69
-			$customer->set_id( 0 );
70
-			return false;
71
-		}
72
-
73
-		// Maybe retrieve from the cache.
74
-		$raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
75
-
76
-		// If not found, retrieve from the db.
77
-		if ( false === $raw_customer ) {
78
-
79
-			$raw_customer = $wpdb->get_row(
80
-				$wpdb->prepare(
81
-					"SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d",
82
-					$customer->get_id()
83
-				)
84
-			);
85
-
86
-			// Update the cache with our data
87
-			wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
88
-
89
-		}
90
-
91
-		if ( ! $raw_customer ) {
92
-			$raw_customer->last_error = 'Invalid customer.';
93
-			return false;
94
-		}
95
-
96
-		// Loop through raw customer fields.
97
-		foreach ( (array) $raw_customer as $key => $value ) {
98
-			$customer->set( $key, $value );
99
-		}
100
-
101
-		$customer->set_object_read( true );
102
-		do_action( 'getpaid_read_customer', $customer );
103
-
104
-	}
105
-
106
-	/**
107
-	 * Method to update a customer in the database.
108
-	 *
109
-	 * @param GetPaid_Customer $customer Customer object.
110
-	 */
111
-	public function update( &$customer ) {
112
-		global $wpdb;
113
-
114
-		do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
115
-
116
-		$changes = $customer->get_changes();
117
-		$values  = array();
118
-		$format  = array();
119
-
120
-		foreach ( self::get_database_fields() as $key => $format ) {
121
-			if ( array_key_exists( $key, $changes ) ) {
122
-				$values[ $key ] = $customer->get( $key, 'edit' );
123
-				$formats[]      = $format;
124
-			}
125
-		}
126
-
127
-		if ( empty( $values ) ) {
128
-			return;
129
-		}
130
-
131
-		$wpdb->update(
132
-			$wpdb->prefix . 'getpaid_customers',
133
-			$values,
134
-			array(
135
-				'id' => $customer->get_id(),
136
-			),
137
-			$formats,
138
-			'%d'
139
-		);
140
-
141
-		// Apply the changes.
142
-		$customer->apply_changes();
143
-
144
-		// Delete cache.
145
-		$customer->clear_cache();
146
-
147
-		// Fire a hook.
148
-		do_action( 'getpaid_update_customer', $customer );
149
-
150
-	}
151
-
152
-	/**
153
-	 * Method to delete a customer from the database.
154
-	 *
155
-	 * @param GetPaid_Customer $customer
156
-	 */
157
-	public function delete( &$customer ) {
158
-		global $wpdb;
159
-
160
-		do_action( 'getpaid_before_delete_customer', $customer );
161
-
162
-		$wpdb->delete(
163
-			$wpdb->prefix . 'getpaid_customers',
164
-			array(
165
-				'id' => $customer->get_id(),
166
-			),
167
-			'%d'
168
-		);
169
-
170
-		// Delete cache.
171
-		$customer->clear_cache();
172
-
173
-		// Fire a hook.
174
-		do_action( 'getpaid_delete_customer', $customer );
175
-
176
-		$customer->set_id( 0 );
177
-	}
178
-
179
-	/*
24
+    /**
25
+     * Method to create a new customer in the database.
26
+     *
27
+     * @param GetPaid_Customer $customer customer object.
28
+     */
29
+    public function create( &$customer ) {
30
+        global $wpdb;
31
+
32
+        $values  = array();
33
+        $formats = array();
34
+
35
+        $fields = self::get_database_fields();
36
+        unset( $fields['id'] );
37
+
38
+        foreach ( $fields as $key => $format ) {
39
+            $values[ $key ] = $customer->get( $key, 'edit' );
40
+            $formats[]      = $format;
41
+        }
42
+
43
+        $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
44
+
45
+        if ( $result ) {
46
+            $customer->set_id( $wpdb->insert_id );
47
+            $customer->apply_changes();
48
+            $customer->clear_cache();
49
+            do_action( 'getpaid_new_customer', $customer );
50
+            return true;
51
+        }
52
+
53
+        return false;
54
+    }
55
+
56
+    /**
57
+     * Method to read a customer from the database.
58
+     *
59
+     * @param GetPaid_Customer $customer customer object.
60
+     *
61
+     */
62
+    public function read( &$customer ) {
63
+        global $wpdb;
64
+
65
+        $customer->set_defaults();
66
+
67
+        if ( ! $customer->get_id() ) {
68
+            $customer->last_error = 'Invalid customer.';
69
+            $customer->set_id( 0 );
70
+            return false;
71
+        }
72
+
73
+        // Maybe retrieve from the cache.
74
+        $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
75
+
76
+        // If not found, retrieve from the db.
77
+        if ( false === $raw_customer ) {
78
+
79
+            $raw_customer = $wpdb->get_row(
80
+                $wpdb->prepare(
81
+                    "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d",
82
+                    $customer->get_id()
83
+                )
84
+            );
85
+
86
+            // Update the cache with our data
87
+            wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
88
+
89
+        }
90
+
91
+        if ( ! $raw_customer ) {
92
+            $raw_customer->last_error = 'Invalid customer.';
93
+            return false;
94
+        }
95
+
96
+        // Loop through raw customer fields.
97
+        foreach ( (array) $raw_customer as $key => $value ) {
98
+            $customer->set( $key, $value );
99
+        }
100
+
101
+        $customer->set_object_read( true );
102
+        do_action( 'getpaid_read_customer', $customer );
103
+
104
+    }
105
+
106
+    /**
107
+     * Method to update a customer in the database.
108
+     *
109
+     * @param GetPaid_Customer $customer Customer object.
110
+     */
111
+    public function update( &$customer ) {
112
+        global $wpdb;
113
+
114
+        do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
115
+
116
+        $changes = $customer->get_changes();
117
+        $values  = array();
118
+        $format  = array();
119
+
120
+        foreach ( self::get_database_fields() as $key => $format ) {
121
+            if ( array_key_exists( $key, $changes ) ) {
122
+                $values[ $key ] = $customer->get( $key, 'edit' );
123
+                $formats[]      = $format;
124
+            }
125
+        }
126
+
127
+        if ( empty( $values ) ) {
128
+            return;
129
+        }
130
+
131
+        $wpdb->update(
132
+            $wpdb->prefix . 'getpaid_customers',
133
+            $values,
134
+            array(
135
+                'id' => $customer->get_id(),
136
+            ),
137
+            $formats,
138
+            '%d'
139
+        );
140
+
141
+        // Apply the changes.
142
+        $customer->apply_changes();
143
+
144
+        // Delete cache.
145
+        $customer->clear_cache();
146
+
147
+        // Fire a hook.
148
+        do_action( 'getpaid_update_customer', $customer );
149
+
150
+    }
151
+
152
+    /**
153
+     * Method to delete a customer from the database.
154
+     *
155
+     * @param GetPaid_Customer $customer
156
+     */
157
+    public function delete( &$customer ) {
158
+        global $wpdb;
159
+
160
+        do_action( 'getpaid_before_delete_customer', $customer );
161
+
162
+        $wpdb->delete(
163
+            $wpdb->prefix . 'getpaid_customers',
164
+            array(
165
+                'id' => $customer->get_id(),
166
+            ),
167
+            '%d'
168
+        );
169
+
170
+        // Delete cache.
171
+        $customer->clear_cache();
172
+
173
+        // Fire a hook.
174
+        do_action( 'getpaid_delete_customer', $customer );
175
+
176
+        $customer->set_id( 0 );
177
+    }
178
+
179
+    /*
180 180
 	|--------------------------------------------------------------------------
181 181
 	| Additional Methods
182 182
 	|--------------------------------------------------------------------------
183 183
 	*/
184
-	public static function get_database_fields() {
185
-
186
-		$fields = array(
187
-			'id'             => '%d',
188
-			'user_id'        => '%d',
189
-			'email'          => '%s',
190
-			'email_cc'       => '%s',
191
-			'status'         => '%s',
192
-			'purchase_value' => '%f',
193
-			'purchase_count' => '%d',
194
-			'date_created'   => '%s',
195
-			'date_modified'  => '%s',
196
-			'uuid'           => '%s',
197
-		);
198
-
199
-		// Add address fields.
200
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
201
-
202
-			// Skip id, user_id and email.
203
-			if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
-				$fields[ $field ] = '%s';
205
-			}
206
-		}
207
-
208
-		return $fields;
209
-	}
184
+    public static function get_database_fields() {
185
+
186
+        $fields = array(
187
+            'id'             => '%d',
188
+            'user_id'        => '%d',
189
+            'email'          => '%s',
190
+            'email_cc'       => '%s',
191
+            'status'         => '%s',
192
+            'purchase_value' => '%f',
193
+            'purchase_count' => '%d',
194
+            'date_created'   => '%s',
195
+            'date_modified'  => '%s',
196
+            'uuid'           => '%s',
197
+        );
198
+
199
+        // Add address fields.
200
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
201
+
202
+            // Skip id, user_id and email.
203
+            if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
+                $fields[ $field ] = '%s';
205
+            }
206
+        }
207
+
208
+        return $fields;
209
+    }
210 210
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +490 added lines, -490 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,545 +15,545 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'_wpinv_phone',
34
-		'_wpinv_company_id',
35
-		'wpinv_shipping',
36
-		'wpinv_email_cc',
37
-		'wpinv_template',
38
-		'wpinv_created_via',
39
-	);
40
-
41
-	/**
42
-	 * A map of meta keys to data props.
43
-	 *
44
-	 * @since 1.0.19
45
-	 *
46
-	 * @var array
47
-	 */
48
-	protected $meta_key_to_props = array(
49
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
-		'_wpinv_subscription_id'   => 'subscription_id',
51
-		'_wpinv_taxes'             => 'taxes',
52
-		'_wpinv_fees'              => 'fees',
53
-		'_wpinv_discounts'         => 'discounts',
54
-		'_wpinv_submission_id'     => 'submission_id',
55
-		'_wpinv_payment_form'      => 'payment_form',
56
-		'_wpinv_is_viewed'         => 'is_viewed',
57
-		'wpinv_email_cc'           => 'email_cc',
58
-		'wpinv_template'           => 'template',
59
-		'wpinv_created_via'        => 'created_via',
60
-		'_wpinv_phone'             => 'phone',
61
-		'_wpinv_company_id'        => 'company_id',
62
-		'wpinv_shipping'           => 'shipping',
63
-	);
64
-
65
-	/**
66
-	 * A map of database fields to data props.
67
-	 *
68
-	 * @since 1.0.19
69
-	 *
70
-	 * @var array
71
-	 */
72
-	protected $database_fields_to_props = array(
73
-		'post_id'            => 'id',
74
-		'number'             => 'number',
75
-		'currency'           => 'currency',
76
-		'invoice_key'        => 'key',
77
-		'type'               => 'type',
78
-		'mode'               => 'mode',
79
-		'user_ip'            => 'user_ip',
80
-		'first_name'         => 'first_name',
81
-		'last_name'          => 'last_name',
82
-		'address'            => 'address',
83
-		'city'               => 'city',
84
-		'state'              => 'state',
85
-		'country'            => 'country',
86
-		'zip'                => 'zip',
87
-		'zip'                => 'zip',
88
-		'adddress_confirmed' => 'address_confirmed',
89
-		'gateway'            => 'gateway',
90
-		'transaction_id'     => 'transaction_id',
91
-		'currency'           => 'currency',
92
-		'subtotal'           => 'subtotal',
93
-		'tax'                => 'total_tax',
94
-		'fees_total'         => 'total_fees',
95
-		'discount'           => 'total_discount',
96
-		'total'              => 'total',
97
-		'discount_code'      => 'discount_code',
98
-		'disable_taxes'      => 'disable_taxes',
99
-		'due_date'           => 'due_date',
100
-		'completed_date'     => 'completed_date',
101
-		'company'            => 'company',
102
-		'vat_number'         => 'vat_number',
103
-		'vat_rate'           => 'vat_rate',
104
-		'customer_id'        => 'customer_id',
105
-	);
106
-
107
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        '_wpinv_phone',
34
+        '_wpinv_company_id',
35
+        'wpinv_shipping',
36
+        'wpinv_email_cc',
37
+        'wpinv_template',
38
+        'wpinv_created_via',
39
+    );
40
+
41
+    /**
42
+     * A map of meta keys to data props.
43
+     *
44
+     * @since 1.0.19
45
+     *
46
+     * @var array
47
+     */
48
+    protected $meta_key_to_props = array(
49
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
+        '_wpinv_subscription_id'   => 'subscription_id',
51
+        '_wpinv_taxes'             => 'taxes',
52
+        '_wpinv_fees'              => 'fees',
53
+        '_wpinv_discounts'         => 'discounts',
54
+        '_wpinv_submission_id'     => 'submission_id',
55
+        '_wpinv_payment_form'      => 'payment_form',
56
+        '_wpinv_is_viewed'         => 'is_viewed',
57
+        'wpinv_email_cc'           => 'email_cc',
58
+        'wpinv_template'           => 'template',
59
+        'wpinv_created_via'        => 'created_via',
60
+        '_wpinv_phone'             => 'phone',
61
+        '_wpinv_company_id'        => 'company_id',
62
+        'wpinv_shipping'           => 'shipping',
63
+    );
64
+
65
+    /**
66
+     * A map of database fields to data props.
67
+     *
68
+     * @since 1.0.19
69
+     *
70
+     * @var array
71
+     */
72
+    protected $database_fields_to_props = array(
73
+        'post_id'            => 'id',
74
+        'number'             => 'number',
75
+        'currency'           => 'currency',
76
+        'invoice_key'        => 'key',
77
+        'type'               => 'type',
78
+        'mode'               => 'mode',
79
+        'user_ip'            => 'user_ip',
80
+        'first_name'         => 'first_name',
81
+        'last_name'          => 'last_name',
82
+        'address'            => 'address',
83
+        'city'               => 'city',
84
+        'state'              => 'state',
85
+        'country'            => 'country',
86
+        'zip'                => 'zip',
87
+        'zip'                => 'zip',
88
+        'adddress_confirmed' => 'address_confirmed',
89
+        'gateway'            => 'gateway',
90
+        'transaction_id'     => 'transaction_id',
91
+        'currency'           => 'currency',
92
+        'subtotal'           => 'subtotal',
93
+        'tax'                => 'total_tax',
94
+        'fees_total'         => 'total_fees',
95
+        'discount'           => 'total_discount',
96
+        'total'              => 'total',
97
+        'discount_code'      => 'discount_code',
98
+        'disable_taxes'      => 'disable_taxes',
99
+        'due_date'           => 'due_date',
100
+        'completed_date'     => 'completed_date',
101
+        'company'            => 'company',
102
+        'vat_number'         => 'vat_number',
103
+        'vat_rate'           => 'vat_rate',
104
+        'customer_id'        => 'customer_id',
105
+    );
106
+
107
+    /*
108 108
 	|--------------------------------------------------------------------------
109 109
 	| CRUD Methods
110 110
 	|--------------------------------------------------------------------------
111 111
 	*/
112 112
 
113
-	/**
114
-	 * Method to create a new invoice in the database.
115
-	 *
116
-	 * @param WPInv_Invoice $invoice Invoice object.
117
-	 */
118
-	public function create( &$invoice ) {
119
-		$invoice->set_version( WPINV_VERSION );
120
-		$invoice->set_date_created( current_time( 'mysql' ) );
121
-
122
-		// Create a new post.
123
-		$id = wp_insert_post(
124
-			apply_filters(
125
-				'getpaid_new_invoice_data',
126
-				array(
127
-					'post_date'    => $invoice->get_date_created( 'edit' ),
128
-					'post_type'    => $invoice->get_post_type( 'edit' ),
129
-					'post_status'  => $this->get_post_status( $invoice ),
130
-					'ping_status'  => 'closed',
131
-					'post_author'  => $invoice->get_user_id( 'edit' ),
132
-					'post_title'   => $invoice->get_title( 'edit' ),
133
-					'post_excerpt' => $invoice->get_description( 'edit' ),
134
-					'post_parent'  => $invoice->get_parent_id( 'edit' ),
135
-				)
136
-			),
137
-			true
138
-		);
139
-
140
-		if ( $id && ! is_wp_error( $id ) ) {
141
-
142
-			// Update the new id and regenerate a title.
143
-			$invoice->set_id( $id );
144
-
145
-			$invoice->maybe_set_number();
146
-
147
-			wp_update_post(
148
-				array(
149
-					'ID'         => $invoice->get_id(),
150
-					'post_title' => $invoice->get_number( 'edit' ),
151
-					'post_name'  => $invoice->get_path( 'edit' ),
152
-				)
153
-			);
154
-
155
-			// Save special fields and items.
156
-			$this->save_special_fields( $invoice );
157
-			$this->save_items( $invoice );
158
-
159
-			// Update meta data.
160
-			$this->update_post_meta( $invoice );
161
-			$invoice->save_meta_data();
162
-
163
-			// Apply changes.
164
-			$invoice->apply_changes();
165
-			$this->clear_caches( $invoice );
166
-
167
-			// Fires after a new invoice is created.
168
-			do_action( 'getpaid_new_invoice', $invoice );
169
-			return true;
170
-		}
171
-
172
-		if ( is_wp_error( $id ) ) {
173
-			$invoice->last_error = $id->get_error_message();
174
-		}
175
-
176
-		return false;
177
-	}
178
-
179
-	/**
180
-	 * Method to read an invoice from the database.
181
-	 *
182
-	 * @param WPInv_Invoice $invoice Invoice object.
183
-	 *
184
-	 */
185
-	public function read( &$invoice ) {
186
-
187
-		$invoice->set_defaults();
188
-		$invoice_object = get_post( $invoice->get_id() );
189
-
190
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
191
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
192
-			$invoice->set_id( 0 );
193
-			return false;
194
-		}
195
-
196
-		$invoice->set_props(
197
-			array(
198
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
199
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
200
-				'status'        => $invoice_object->post_status,
201
-				'author'        => $invoice_object->post_author,
202
-				'description'   => $invoice_object->post_excerpt,
203
-				'parent_id'     => $invoice_object->post_parent,
204
-				'name'          => $invoice_object->post_title,
205
-				'path'          => $invoice_object->post_name,
206
-				'post_type'     => $invoice_object->post_type,
207
-			)
208
-		);
209
-
210
-		$invoice->set_type( $invoice_object->post_type );
211
-
212
-		$this->read_object_data( $invoice, $invoice_object );
213
-		$this->add_special_fields( $invoice );
214
-		$this->add_items( $invoice );
215
-		$invoice->read_meta_data();
216
-		$invoice->set_object_read( true );
217
-		do_action( 'getpaid_read_invoice', $invoice );
218
-
219
-	}
220
-
221
-	/**
222
-	 * Method to update an invoice in the database.
223
-	 *
224
-	 * @param WPInv_Invoice $invoice Invoice object.
225
-	 */
226
-	public function update( &$invoice ) {
227
-		$invoice->save_meta_data();
228
-		$invoice->set_version( WPINV_VERSION );
229
-
230
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
231
-			$invoice->set_date_created( current_time( 'mysql' ) );
232
-		}
233
-
234
-		// Ensure both the key and number are set.
235
-		$invoice->get_path();
236
-
237
-		// Grab the current status so we can compare.
238
-		$previous_status = get_post_status( $invoice->get_id() );
239
-
240
-		$changes = $invoice->get_changes();
241
-
242
-		// Only update the post when the post data changes.
243
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
244
-			$post_data = array(
245
-				'post_date'     => $invoice->get_date_created( 'edit' ),
246
-				'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ),
247
-				'post_status'   => $invoice->get_status( 'edit' ),
248
-				'post_title'    => $invoice->get_name( 'edit' ),
249
-				'post_author'   => $invoice->get_user_id( 'edit' ),
250
-				'post_modified' => $invoice->get_date_modified( 'edit' ),
251
-				'post_excerpt'  => $invoice->get_description( 'edit' ),
252
-				'post_parent'   => $invoice->get_parent_id( 'edit' ),
253
-				'post_name'     => $invoice->get_path( 'edit' ),
254
-				'post_type'     => $invoice->get_post_type( 'edit' ),
255
-			);
256
-
257
-			/**
258
-			 * When updating this object, to prevent infinite loops, use $wpdb
259
-			 * to update data, since wp_update_post spawns more calls to the
260
-			 * save_post action.
261
-			 *
262
-			 * This ensures hooks are fired by either WP itself (admin screen save),
263
-			 * or an update purely from CRUD.
264
-			 */
265
-			if ( doing_action( 'save_post' ) ) {
266
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
267
-				clean_post_cache( $invoice->get_id() );
268
-			} else {
269
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
270
-			}
271
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
272
-		}
273
-
274
-		// Update meta data.
275
-		$this->update_post_meta( $invoice );
276
-
277
-		// Save special fields and items.
278
-		$this->save_special_fields( $invoice );
279
-		$this->save_items( $invoice );
280
-
281
-		// Apply the changes.
282
-		$invoice->apply_changes();
283
-
284
-		// Clear caches.
285
-		$this->clear_caches( $invoice );
286
-
287
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
288
-		$new_status = $invoice->get_status( 'edit' );
289
-
290
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
291
-			do_action( 'getpaid_new_invoice', $invoice );
292
-		} else {
293
-			do_action( 'getpaid_update_invoice', $invoice );
294
-		}
295
-
296
-	}
297
-
298
-	/*
113
+    /**
114
+     * Method to create a new invoice in the database.
115
+     *
116
+     * @param WPInv_Invoice $invoice Invoice object.
117
+     */
118
+    public function create( &$invoice ) {
119
+        $invoice->set_version( WPINV_VERSION );
120
+        $invoice->set_date_created( current_time( 'mysql' ) );
121
+
122
+        // Create a new post.
123
+        $id = wp_insert_post(
124
+            apply_filters(
125
+                'getpaid_new_invoice_data',
126
+                array(
127
+                    'post_date'    => $invoice->get_date_created( 'edit' ),
128
+                    'post_type'    => $invoice->get_post_type( 'edit' ),
129
+                    'post_status'  => $this->get_post_status( $invoice ),
130
+                    'ping_status'  => 'closed',
131
+                    'post_author'  => $invoice->get_user_id( 'edit' ),
132
+                    'post_title'   => $invoice->get_title( 'edit' ),
133
+                    'post_excerpt' => $invoice->get_description( 'edit' ),
134
+                    'post_parent'  => $invoice->get_parent_id( 'edit' ),
135
+                )
136
+            ),
137
+            true
138
+        );
139
+
140
+        if ( $id && ! is_wp_error( $id ) ) {
141
+
142
+            // Update the new id and regenerate a title.
143
+            $invoice->set_id( $id );
144
+
145
+            $invoice->maybe_set_number();
146
+
147
+            wp_update_post(
148
+                array(
149
+                    'ID'         => $invoice->get_id(),
150
+                    'post_title' => $invoice->get_number( 'edit' ),
151
+                    'post_name'  => $invoice->get_path( 'edit' ),
152
+                )
153
+            );
154
+
155
+            // Save special fields and items.
156
+            $this->save_special_fields( $invoice );
157
+            $this->save_items( $invoice );
158
+
159
+            // Update meta data.
160
+            $this->update_post_meta( $invoice );
161
+            $invoice->save_meta_data();
162
+
163
+            // Apply changes.
164
+            $invoice->apply_changes();
165
+            $this->clear_caches( $invoice );
166
+
167
+            // Fires after a new invoice is created.
168
+            do_action( 'getpaid_new_invoice', $invoice );
169
+            return true;
170
+        }
171
+
172
+        if ( is_wp_error( $id ) ) {
173
+            $invoice->last_error = $id->get_error_message();
174
+        }
175
+
176
+        return false;
177
+    }
178
+
179
+    /**
180
+     * Method to read an invoice from the database.
181
+     *
182
+     * @param WPInv_Invoice $invoice Invoice object.
183
+     *
184
+     */
185
+    public function read( &$invoice ) {
186
+
187
+        $invoice->set_defaults();
188
+        $invoice_object = get_post( $invoice->get_id() );
189
+
190
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
191
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
192
+            $invoice->set_id( 0 );
193
+            return false;
194
+        }
195
+
196
+        $invoice->set_props(
197
+            array(
198
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
199
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
200
+                'status'        => $invoice_object->post_status,
201
+                'author'        => $invoice_object->post_author,
202
+                'description'   => $invoice_object->post_excerpt,
203
+                'parent_id'     => $invoice_object->post_parent,
204
+                'name'          => $invoice_object->post_title,
205
+                'path'          => $invoice_object->post_name,
206
+                'post_type'     => $invoice_object->post_type,
207
+            )
208
+        );
209
+
210
+        $invoice->set_type( $invoice_object->post_type );
211
+
212
+        $this->read_object_data( $invoice, $invoice_object );
213
+        $this->add_special_fields( $invoice );
214
+        $this->add_items( $invoice );
215
+        $invoice->read_meta_data();
216
+        $invoice->set_object_read( true );
217
+        do_action( 'getpaid_read_invoice', $invoice );
218
+
219
+    }
220
+
221
+    /**
222
+     * Method to update an invoice in the database.
223
+     *
224
+     * @param WPInv_Invoice $invoice Invoice object.
225
+     */
226
+    public function update( &$invoice ) {
227
+        $invoice->save_meta_data();
228
+        $invoice->set_version( WPINV_VERSION );
229
+
230
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
231
+            $invoice->set_date_created( current_time( 'mysql' ) );
232
+        }
233
+
234
+        // Ensure both the key and number are set.
235
+        $invoice->get_path();
236
+
237
+        // Grab the current status so we can compare.
238
+        $previous_status = get_post_status( $invoice->get_id() );
239
+
240
+        $changes = $invoice->get_changes();
241
+
242
+        // Only update the post when the post data changes.
243
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
244
+            $post_data = array(
245
+                'post_date'     => $invoice->get_date_created( 'edit' ),
246
+                'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ),
247
+                'post_status'   => $invoice->get_status( 'edit' ),
248
+                'post_title'    => $invoice->get_name( 'edit' ),
249
+                'post_author'   => $invoice->get_user_id( 'edit' ),
250
+                'post_modified' => $invoice->get_date_modified( 'edit' ),
251
+                'post_excerpt'  => $invoice->get_description( 'edit' ),
252
+                'post_parent'   => $invoice->get_parent_id( 'edit' ),
253
+                'post_name'     => $invoice->get_path( 'edit' ),
254
+                'post_type'     => $invoice->get_post_type( 'edit' ),
255
+            );
256
+
257
+            /**
258
+             * When updating this object, to prevent infinite loops, use $wpdb
259
+             * to update data, since wp_update_post spawns more calls to the
260
+             * save_post action.
261
+             *
262
+             * This ensures hooks are fired by either WP itself (admin screen save),
263
+             * or an update purely from CRUD.
264
+             */
265
+            if ( doing_action( 'save_post' ) ) {
266
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
267
+                clean_post_cache( $invoice->get_id() );
268
+            } else {
269
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
270
+            }
271
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
272
+        }
273
+
274
+        // Update meta data.
275
+        $this->update_post_meta( $invoice );
276
+
277
+        // Save special fields and items.
278
+        $this->save_special_fields( $invoice );
279
+        $this->save_items( $invoice );
280
+
281
+        // Apply the changes.
282
+        $invoice->apply_changes();
283
+
284
+        // Clear caches.
285
+        $this->clear_caches( $invoice );
286
+
287
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
288
+        $new_status = $invoice->get_status( 'edit' );
289
+
290
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
291
+            do_action( 'getpaid_new_invoice', $invoice );
292
+        } else {
293
+            do_action( 'getpaid_update_invoice', $invoice );
294
+        }
295
+
296
+    }
297
+
298
+    /*
299 299
 	|--------------------------------------------------------------------------
300 300
 	| Additional Methods
301 301
 	|--------------------------------------------------------------------------
302 302
 	*/
303 303
 
304
-	/**
304
+    /**
305 305
      * Retrieves special fields and adds to the invoice.
306
-	 *
307
-	 * @param WPInv_Invoice $invoice Invoice object.
306
+     *
307
+     * @param WPInv_Invoice $invoice Invoice object.
308 308
      */
309 309
     public function add_special_fields( &$invoice ) {
310
-		global $wpdb;
311
-
312
-		// Maybe retrieve from the cache.
313
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
314
-
315
-		// If not found, retrieve from the db.
316
-		if ( false === $data ) {
317
-			$table = $wpdb->prefix . 'getpaid_invoices';
318
-
319
-			$data  = $wpdb->get_row(
320
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
321
-				ARRAY_A
322
-			);
323
-
324
-			// Update the cache with our data
325
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
326
-
327
-		}
328
-
329
-		// Abort if the data does not exist.
330
-		if ( empty( $data ) ) {
331
-			$invoice->set_object_read( true );
332
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
333
-			return;
334
-		}
335
-
336
-		$props = array();
337
-
338
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
339
-
340
-			if ( $db_field == 'post_id' ) {
341
-				continue;
342
-			}
343
-
344
-			$props[ $prop ] = $data[ $db_field ];
345
-		}
346
-
347
-		$invoice->set_props( $props );
348
-
349
-	}
350
-
351
-	/**
352
-	 * Gets a list of special fields that need updated based on change state
353
-	 * or if they are present in the database or not.
354
-	 *
355
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
356
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
357
-	 */
358
-	protected function get_special_fields_to_update( $invoice ) {
359
-		$fields_to_update = array();
360
-		$changed_props   = $invoice->get_changes();
361
-
362
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
363
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
364
-			if ( array_key_exists( $prop, $changed_props ) ) {
365
-				$fields_to_update[ $database_field ] = $prop;
366
-			}
367
-		}
368
-
369
-		return $fields_to_update;
370
-	}
371
-
372
-	/**
373
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
374
-	 *
375
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
376
-	 * @since 1.0.19
377
-	 */
378
-	protected function update_special_fields( &$invoice ) {
379
-		global $wpdb;
380
-
381
-		$updated_props    = array();
382
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
383
-
384
-		foreach ( $fields_to_update as $database_field => $prop ) {
385
-			$value = $invoice->{"get_$prop"}( 'edit' );
386
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
387
-			$value = is_bool( $value ) ? (int) $value : $value;
388
-			$updated_props[ $database_field ] = maybe_serialize( $value );
389
-		}
390
-
391
-		if ( ! empty( $updated_props ) ) {
392
-
393
-			$table = $wpdb->prefix . 'getpaid_invoices';
394
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
395
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
396
-			do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props );
397
-
398
-		}
399
-
400
-	}
401
-
402
-	/**
403
-	 * Helper method that inserts special fields to the database.
404
-	 *
405
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
406
-	 * @since 1.0.19
407
-	 */
408
-	protected function insert_special_fields( &$invoice ) {
409
-		global $wpdb;
410
-
411
-		$updated_props   = array();
412
-
413
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
414
-			$value = $invoice->{"get_$prop"}( 'edit' );
415
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
416
-			$value = is_bool( $value ) ? (int) $value : $value;
417
-			$updated_props[ $database_field ] = maybe_serialize( $value );
418
-		}
419
-
420
-		$table = $wpdb->prefix . 'getpaid_invoices';
421
-		$wpdb->insert( $table, $updated_props );
422
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
423
-		do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props );
424
-
425
-	}
426
-
427
-	/**
310
+        global $wpdb;
311
+
312
+        // Maybe retrieve from the cache.
313
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
314
+
315
+        // If not found, retrieve from the db.
316
+        if ( false === $data ) {
317
+            $table = $wpdb->prefix . 'getpaid_invoices';
318
+
319
+            $data  = $wpdb->get_row(
320
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
321
+                ARRAY_A
322
+            );
323
+
324
+            // Update the cache with our data
325
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
326
+
327
+        }
328
+
329
+        // Abort if the data does not exist.
330
+        if ( empty( $data ) ) {
331
+            $invoice->set_object_read( true );
332
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
333
+            return;
334
+        }
335
+
336
+        $props = array();
337
+
338
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
339
+
340
+            if ( $db_field == 'post_id' ) {
341
+                continue;
342
+            }
343
+
344
+            $props[ $prop ] = $data[ $db_field ];
345
+        }
346
+
347
+        $invoice->set_props( $props );
348
+
349
+    }
350
+
351
+    /**
352
+     * Gets a list of special fields that need updated based on change state
353
+     * or if they are present in the database or not.
354
+     *
355
+     * @param  WPInv_Invoice $invoice       The Invoice object.
356
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
357
+     */
358
+    protected function get_special_fields_to_update( $invoice ) {
359
+        $fields_to_update = array();
360
+        $changed_props   = $invoice->get_changes();
361
+
362
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
363
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
364
+            if ( array_key_exists( $prop, $changed_props ) ) {
365
+                $fields_to_update[ $database_field ] = $prop;
366
+            }
367
+        }
368
+
369
+        return $fields_to_update;
370
+    }
371
+
372
+    /**
373
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
374
+     *
375
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
376
+     * @since 1.0.19
377
+     */
378
+    protected function update_special_fields( &$invoice ) {
379
+        global $wpdb;
380
+
381
+        $updated_props    = array();
382
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
383
+
384
+        foreach ( $fields_to_update as $database_field => $prop ) {
385
+            $value = $invoice->{"get_$prop"}( 'edit' );
386
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
387
+            $value = is_bool( $value ) ? (int) $value : $value;
388
+            $updated_props[ $database_field ] = maybe_serialize( $value );
389
+        }
390
+
391
+        if ( ! empty( $updated_props ) ) {
392
+
393
+            $table = $wpdb->prefix . 'getpaid_invoices';
394
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
395
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
396
+            do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props );
397
+
398
+        }
399
+
400
+    }
401
+
402
+    /**
403
+     * Helper method that inserts special fields to the database.
404
+     *
405
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
406
+     * @since 1.0.19
407
+     */
408
+    protected function insert_special_fields( &$invoice ) {
409
+        global $wpdb;
410
+
411
+        $updated_props   = array();
412
+
413
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
414
+            $value = $invoice->{"get_$prop"}( 'edit' );
415
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
416
+            $value = is_bool( $value ) ? (int) $value : $value;
417
+            $updated_props[ $database_field ] = maybe_serialize( $value );
418
+        }
419
+
420
+        $table = $wpdb->prefix . 'getpaid_invoices';
421
+        $wpdb->insert( $table, $updated_props );
422
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
423
+        do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props );
424
+
425
+    }
426
+
427
+    /**
428 428
      * Saves all special fields.
429
-	 *
430
-	 * @param WPInv_Invoice $invoice Invoice object.
429
+     *
430
+     * @param WPInv_Invoice $invoice Invoice object.
431 431
      */
432 432
     public function save_special_fields( &$invoice ) {
433
-		global $wpdb;
433
+        global $wpdb;
434 434
 
435
-		// The invoices table.
436
-		$table = $wpdb->prefix . 'getpaid_invoices';
437
-		$id    = (int) $invoice->get_id();
438
-		$invoice->maybe_set_key();
435
+        // The invoices table.
436
+        $table = $wpdb->prefix . 'getpaid_invoices';
437
+        $id    = (int) $invoice->get_id();
438
+        $invoice->maybe_set_key();
439 439
 
440
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
440
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
441 441
 
442
-			$this->update_special_fields( $invoice );
442
+            $this->update_special_fields( $invoice );
443 443
 
444
-		} else {
444
+        } else {
445 445
 
446
-			$this->insert_special_fields( $invoice );
446
+            $this->insert_special_fields( $invoice );
447 447
 
448
-		}
448
+        }
449 449
 
450
-	}
450
+    }
451 451
 
452
-	/**
452
+    /**
453 453
      * Set's up cart details.
454
-	 *
455
-	 * @param WPInv_Invoice $invoice Invoice object.
454
+     *
455
+     * @param WPInv_Invoice $invoice Invoice object.
456 456
      */
457 457
     public function add_items( &$invoice ) {
458
-		global $wpdb;
458
+        global $wpdb;
459 459
 
460
-		// Maybe retrieve from the cache.
461
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
460
+        // Maybe retrieve from the cache.
461
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
462 462
 
463
-		// If not found, retrieve from the db.
464
-		if ( false === $items ) {
465
-			$table = $wpdb->prefix . 'getpaid_invoice_items';
463
+        // If not found, retrieve from the db.
464
+        if ( false === $items ) {
465
+            $table = $wpdb->prefix . 'getpaid_invoice_items';
466 466
 
467
-			$items = $wpdb->get_results(
468
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
469
-			);
467
+            $items = $wpdb->get_results(
468
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
469
+            );
470 470
 
471
-			// Update the cache with our data
472
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
471
+            // Update the cache with our data
472
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
473 473
 
474
-		}
474
+        }
475 475
 
476
-		// Abort if no items found.
476
+        // Abort if no items found.
477 477
         if ( empty( $items ) ) {
478 478
             return;
479
-		}
480
-
481
-		$_items = array();
482
-		foreach ( $items as $item_data ) {
483
-			$item = new GetPaid_Form_Item( $item_data->item_id );
484
-
485
-			// Set item data.
486
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
487
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
488
-			$item->set_name( $item_data->item_name );
489
-			$item->set_description( $item_data->item_description );
490
-			$item->set_price( $item_data->item_price );
491
-			$item->set_quantity( $item_data->quantity );
492
-			$item->set_item_meta( $item_data->meta );
493
-			$_items[] = $item;
494
-		}
495
-
496
-		$invoice->set_items( $_items );
497
-	}
498
-
499
-	/**
479
+        }
480
+
481
+        $_items = array();
482
+        foreach ( $items as $item_data ) {
483
+            $item = new GetPaid_Form_Item( $item_data->item_id );
484
+
485
+            // Set item data.
486
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
487
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
488
+            $item->set_name( $item_data->item_name );
489
+            $item->set_description( $item_data->item_description );
490
+            $item->set_price( $item_data->item_price );
491
+            $item->set_quantity( $item_data->quantity );
492
+            $item->set_item_meta( $item_data->meta );
493
+            $_items[] = $item;
494
+        }
495
+
496
+        $invoice->set_items( $_items );
497
+    }
498
+
499
+    /**
500 500
      * Saves cart details.
501
-	 *
502
-	 * @param WPInv_Invoice $invoice Invoice object.
501
+     *
502
+     * @param WPInv_Invoice $invoice Invoice object.
503 503
      */
504 504
     public function save_items( $invoice ) {
505 505
 
506
-		// Delete previously existing items.
507
-		$this->delete_items( $invoice );
506
+        // Delete previously existing items.
507
+        $this->delete_items( $invoice );
508 508
 
509
-		$table   = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
509
+        $table   = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
510 510
 
511
-		foreach ( $invoice->get_cart_details() as $item_data ) {
512
-			$item_data = array_map( 'maybe_serialize', $item_data );
513
-			$GLOBALS['wpdb']->insert( $table, $item_data );
514
-		}
511
+        foreach ( $invoice->get_cart_details() as $item_data ) {
512
+            $item_data = array_map( 'maybe_serialize', $item_data );
513
+            $GLOBALS['wpdb']->insert( $table, $item_data );
514
+        }
515 515
 
516
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
517
-		do_action( 'getpaid_invoice_save_items', $invoice );
516
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
517
+        do_action( 'getpaid_invoice_save_items', $invoice );
518 518
 
519
-	}
519
+    }
520 520
 
521
-	/**
521
+    /**
522 522
      * Deletes an invoice's cart details from the database.
523
-	 *
524
-	 * @param WPInv_Invoice $invoice Invoice object.
523
+     *
524
+     * @param WPInv_Invoice $invoice Invoice object.
525 525
      */
526 526
     public function delete_items( $invoice ) {
527
-		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
528
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
529
-	}
527
+        $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
528
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
529
+    }
530 530
 
531
-	/**
531
+    /**
532 532
      * Deletes an invoice's special fields from the database.
533
-	 *
534
-	 * @param WPInv_Invoice $invoice Invoice object.
533
+     *
534
+     * @param WPInv_Invoice $invoice Invoice object.
535 535
      */
536 536
     public function delete_special_fields( $invoice ) {
537
-		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
538
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
539
-	}
540
-
541
-	/**
542
-	 * Get the status to save to the post object.
543
-	 *
544
-	 *
545
-	 * @since 1.0.19
546
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
547
-	 * @return string
548
-	 */
549
-	protected function get_post_status( $object ) {
550
-		$object_status = $object->get_status( 'edit' );
551
-
552
-		if ( ! $object_status ) {
553
-			$object_status = $object->get_default_status();
554
-		}
555
-
556
-		return $object_status;
557
-	}
537
+        $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
538
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
539
+    }
540
+
541
+    /**
542
+     * Get the status to save to the post object.
543
+     *
544
+     *
545
+     * @since 1.0.19
546
+     * @param  WPInv_Invoice $object GetPaid_Data object.
547
+     * @return string
548
+     */
549
+    protected function get_post_status( $object ) {
550
+        $object_status = $object->get_status( 'edit' );
551
+
552
+        if ( ! $object_status ) {
553
+            $object_status = $object->get_default_status();
554
+        }
555
+
556
+        return $object_status;
557
+    }
558 558
 
559 559
 }
Please login to merge, or discard this patch.