@@ -5,7 +5,7 @@ discard block |
||
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 |
||
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 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Customer_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param GetPaid_Customer $customer customer object. |
28 | 28 | */ |
29 | - public function create( &$customer ) { |
|
29 | + public function create(&$customer) { |
|
30 | 30 | global $wpdb; |
31 | 31 | |
32 | 32 | $values = array(); |
33 | 33 | $formats = array(); |
34 | 34 | |
35 | 35 | $fields = self::get_database_fields(); |
36 | - unset( $fields['id'] ); |
|
36 | + unset($fields['id']); |
|
37 | 37 | |
38 | - foreach ( $fields as $key => $format ) { |
|
39 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
38 | + foreach ($fields as $key => $format) { |
|
39 | + $values[$key] = $customer->get($key, 'edit'); |
|
40 | 40 | $formats[] = $format; |
41 | 41 | } |
42 | 42 | |
43 | - $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
43 | + $result = $wpdb->insert($wpdb->prefix . 'getpaid_customers', $values, $formats); |
|
44 | 44 | |
45 | - if ( $result ) { |
|
46 | - $customer->set_id( $wpdb->insert_id ); |
|
45 | + if ($result) { |
|
46 | + $customer->set_id($wpdb->insert_id); |
|
47 | 47 | $customer->apply_changes(); |
48 | 48 | $customer->clear_cache(); |
49 | - do_action( 'getpaid_new_customer', $customer ); |
|
49 | + do_action('getpaid_new_customer', $customer); |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | |
@@ -59,22 +59,22 @@ discard block |
||
59 | 59 | * @param GetPaid_Customer $customer customer object. |
60 | 60 | * |
61 | 61 | */ |
62 | - public function read( &$customer ) { |
|
62 | + public function read(&$customer) { |
|
63 | 63 | global $wpdb; |
64 | 64 | |
65 | 65 | $customer->set_defaults(); |
66 | 66 | |
67 | - if ( ! $customer->get_id() ) { |
|
67 | + if (!$customer->get_id()) { |
|
68 | 68 | $customer->last_error = 'Invalid customer.'; |
69 | - $customer->set_id( 0 ); |
|
69 | + $customer->set_id(0); |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | 73 | // Maybe retrieve from the cache. |
74 | - $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
74 | + $raw_customer = wp_cache_get($customer->get_id(), 'getpaid_customers'); |
|
75 | 75 | |
76 | 76 | // If not found, retrieve from the db. |
77 | - if ( false === $raw_customer ) { |
|
77 | + if (false === $raw_customer) { |
|
78 | 78 | |
79 | 79 | $raw_customer = $wpdb->get_row( |
80 | 80 | $wpdb->prepare( |
@@ -84,22 +84,22 @@ discard block |
||
84 | 84 | ); |
85 | 85 | |
86 | 86 | // Update the cache with our data |
87 | - wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
87 | + wp_cache_set($customer->get_id(), $raw_customer, 'getpaid_customers'); |
|
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | - if ( ! $raw_customer ) { |
|
91 | + if (!$raw_customer) { |
|
92 | 92 | $raw_customer->last_error = 'Invalid customer.'; |
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Loop through raw customer fields. |
97 | - foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | - $customer->set( $key, $value ); |
|
97 | + foreach ((array) $raw_customer as $key => $value) { |
|
98 | + $customer->set($key, $value); |
|
99 | 99 | } |
100 | 100 | |
101 | - $customer->set_object_read( true ); |
|
102 | - do_action( 'getpaid_read_customer', $customer ); |
|
101 | + $customer->set_object_read(true); |
|
102 | + do_action('getpaid_read_customer', $customer); |
|
103 | 103 | |
104 | 104 | } |
105 | 105 | |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @param GetPaid_Customer $customer Customer object. |
110 | 110 | */ |
111 | - public function update( &$customer ) { |
|
111 | + public function update(&$customer) { |
|
112 | 112 | global $wpdb; |
113 | 113 | |
114 | - do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
114 | + do_action('getpaid_before_update_customer', $customer, $customer->get_changes()); |
|
115 | 115 | |
116 | 116 | $changes = $customer->get_changes(); |
117 | 117 | $values = array(); |
118 | 118 | $format = array(); |
119 | 119 | |
120 | - foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | - if ( array_key_exists( $key, $changes ) ) { |
|
122 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
120 | + foreach (self::get_database_fields() as $key => $format) { |
|
121 | + if (array_key_exists($key, $changes)) { |
|
122 | + $values[$key] = $customer->get($key, 'edit'); |
|
123 | 123 | $formats[] = $format; |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - if ( empty( $values ) ) { |
|
127 | + if (empty($values)) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $customer->clear_cache(); |
146 | 146 | |
147 | 147 | // Fire a hook. |
148 | - do_action( 'getpaid_update_customer', $customer ); |
|
148 | + do_action('getpaid_update_customer', $customer); |
|
149 | 149 | |
150 | 150 | } |
151 | 151 | |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @param GetPaid_Customer $customer |
156 | 156 | */ |
157 | - public function delete( &$customer ) { |
|
157 | + public function delete(&$customer) { |
|
158 | 158 | global $wpdb; |
159 | 159 | |
160 | - do_action( 'getpaid_before_delete_customer', $customer ); |
|
160 | + do_action('getpaid_before_delete_customer', $customer); |
|
161 | 161 | |
162 | 162 | $wpdb->delete( |
163 | 163 | $wpdb->prefix . 'getpaid_customers', |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | $customer->clear_cache(); |
172 | 172 | |
173 | 173 | // Fire a hook. |
174 | - do_action( 'getpaid_delete_customer', $customer ); |
|
174 | + do_action('getpaid_delete_customer', $customer); |
|
175 | 175 | |
176 | - $customer->set_id( 0 ); |
|
176 | + $customer->set_id(0); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /* |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | ); |
198 | 198 | |
199 | 199 | // Add address fields. |
200 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
200 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
201 | 201 | |
202 | 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'; |
|
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 | 205 | } |
206 | 206 | } |
207 | 207 |
@@ -15,69 +15,69 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Customer extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'customer'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'customer'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | - * |
|
35 | - * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
|
36 | - */ |
|
37 | - public function __construct( $customer = 0 ) { |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'customer'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | + * |
|
35 | + * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
|
36 | + */ |
|
37 | + public function __construct( $customer = 0 ) { |
|
38 | 38 | |
39 | 39 | // Setup default customer data. |
40 | 40 | $this->setup_default_data(); |
41 | 41 | |
42 | - if ( is_numeric( $customer ) ) { |
|
43 | - $this->set_id( $customer ); |
|
44 | - } elseif ( $customer instanceof self ) { |
|
45 | - $this->set_id( $customer->get_id() ); |
|
46 | - } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | - $this->set_id( $customer_id ); |
|
48 | - } elseif ( ! empty( $customer->id ) ) { |
|
49 | - $this->set_id( $customer->id ); |
|
50 | - } |
|
42 | + if ( is_numeric( $customer ) ) { |
|
43 | + $this->set_id( $customer ); |
|
44 | + } elseif ( $customer instanceof self ) { |
|
45 | + $this->set_id( $customer->get_id() ); |
|
46 | + } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | + $this->set_id( $customer_id ); |
|
48 | + } elseif ( ! empty( $customer->id ) ) { |
|
49 | + $this->set_id( $customer->id ); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | // Load the datastore. |
53 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
53 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
54 | 54 | |
55 | - if ( $this->get_id() > 0 ) { |
|
56 | - $this->data_store->read( $this ); |
|
55 | + if ( $this->get_id() > 0 ) { |
|
56 | + $this->data_store->read( $this ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->set_object_read( true ); |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | 62 | /** |
63 | - * Sets up default customer data. |
|
64 | - */ |
|
65 | - private function setup_default_data() { |
|
63 | + * Sets up default customer data. |
|
64 | + */ |
|
65 | + private function setup_default_data() { |
|
66 | 66 | |
67 | 67 | $this->data = array( |
68 | - 'user_id' => 0, |
|
69 | - 'email' => '', |
|
70 | - 'email_cc' => '', |
|
71 | - 'status' => 'active', |
|
72 | - 'purchase_value' => 0, |
|
73 | - 'purchase_count' => 0, |
|
74 | - 'date_created' => current_time( 'mysql' ), |
|
75 | - 'date_modified' => current_time( 'mysql' ), |
|
76 | - 'uuid' => wp_generate_uuid4(), |
|
77 | - ); |
|
68 | + 'user_id' => 0, |
|
69 | + 'email' => '', |
|
70 | + 'email_cc' => '', |
|
71 | + 'status' => 'active', |
|
72 | + 'purchase_value' => 0, |
|
73 | + 'purchase_count' => 0, |
|
74 | + 'date_created' => current_time( 'mysql' ), |
|
75 | + 'date_modified' => current_time( 'mysql' ), |
|
76 | + 'uuid' => wp_generate_uuid4(), |
|
77 | + ); |
|
78 | 78 | |
79 | 79 | // Add address fields. |
80 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
80 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
81 | 81 | |
82 | 82 | if ( isset( $this->data[ $field ] ) ) { |
83 | 83 | continue; |
@@ -95,22 +95,22 @@ discard block |
||
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - $this->data[ $field ] = ''; |
|
99 | - } |
|
98 | + $this->data[ $field ] = ''; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | $this->default_data = $this->data; |
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Given a customer email or user id, it returns a customer id. |
|
106 | - * |
|
107 | - * @static |
|
108 | - * @param string $value |
|
109 | - * @since 1.0.15 |
|
110 | - * @return int |
|
111 | - */ |
|
112 | - public static function get_customer_id_by( $value, $by = 'email' ) { |
|
113 | - global $wpdb; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Given a customer email or user id, it returns a customer id. |
|
106 | + * |
|
107 | + * @static |
|
108 | + * @param string $value |
|
109 | + * @since 1.0.15 |
|
110 | + * @return int |
|
111 | + */ |
|
112 | + public static function get_customer_id_by( $value, $by = 'email' ) { |
|
113 | + global $wpdb; |
|
114 | 114 | |
115 | 115 | // Prepare value. |
116 | 116 | if ( 'email' === $by ) { |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | return 0; |
126 | 126 | } |
127 | 127 | |
128 | - // Maybe retrieve from the cache. |
|
128 | + // Maybe retrieve from the cache. |
|
129 | 129 | $cache_key = 'getpaid_customer_ids_by_' . $by; |
130 | - $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | - if ( false !== $customer_id ) { |
|
132 | - return $customer_id; |
|
133 | - } |
|
130 | + $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | + if ( false !== $customer_id ) { |
|
132 | + return $customer_id; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | if ( 'email' === $by ) { |
136 | 136 | $customer_id = (int) $wpdb->get_var( |
@@ -142,23 +142,23 @@ discard block |
||
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | - // Update the cache with our data |
|
146 | - wp_cache_set( $value, $customer_id, $cache_key ); |
|
145 | + // Update the cache with our data |
|
146 | + wp_cache_set( $value, $customer_id, $cache_key ); |
|
147 | 147 | |
148 | - return $customer_id; |
|
148 | + return $customer_id; |
|
149 | 149 | |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
152 | + /** |
|
153 | 153 | * Clears the customer's cache. |
154 | 154 | */ |
155 | 155 | public function clear_cache() { |
156 | 156 | wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' ); |
157 | 157 | wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' ); |
158 | - wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
159 | - } |
|
158 | + wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
159 | + } |
|
160 | 160 | |
161 | - /* |
|
161 | + /* |
|
162 | 162 | |-------------------------------------------------------------------------- |
163 | 163 | | CRUD methods |
164 | 164 | |-------------------------------------------------------------------------- |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | return call_user_func( array( $this, 'get_' . $key ), $context ); |
190 | 190 | } |
191 | 191 | |
192 | - return $this->get_prop( $key, $context ); |
|
192 | + return $this->get_prop( $key, $context ); |
|
193 | 193 | |
194 | 194 | } |
195 | 195 | |
196 | - /* |
|
196 | + /* |
|
197 | 197 | |-------------------------------------------------------------------------- |
198 | 198 | | Setters |
199 | 199 | |-------------------------------------------------------------------------- |
@@ -216,114 +216,114 @@ discard block |
||
216 | 216 | return call_user_func( array( $this, 'set_' . $key ), $value ); |
217 | 217 | } |
218 | 218 | |
219 | - return $this->set_prop( $key, $value ); |
|
219 | + return $this->set_prop( $key, $value ); |
|
220 | 220 | |
221 | 221 | } |
222 | 222 | |
223 | - /** |
|
224 | - * Sets customer status. |
|
225 | - * |
|
226 | - * @since 1.0.0 |
|
227 | - * @param string $status New status. |
|
228 | - */ |
|
229 | - public function set_status( $status ) { |
|
230 | - |
|
231 | - if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | - return $this->set_prop( 'status', $status ); |
|
233 | - } |
|
234 | - |
|
235 | - $this->set_prop( 'status', 'inactive' ); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Sets the purchase value. |
|
240 | - * |
|
241 | - * @since 1.0.0 |
|
242 | - * @param float $purchase_value. |
|
243 | - */ |
|
244 | - public function set_purchase_value( $purchase_value ) { |
|
245 | - $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
246 | - } |
|
223 | + /** |
|
224 | + * Sets customer status. |
|
225 | + * |
|
226 | + * @since 1.0.0 |
|
227 | + * @param string $status New status. |
|
228 | + */ |
|
229 | + public function set_status( $status ) { |
|
230 | + |
|
231 | + if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | + return $this->set_prop( 'status', $status ); |
|
233 | + } |
|
234 | + |
|
235 | + $this->set_prop( 'status', 'inactive' ); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Sets the purchase value. |
|
240 | + * |
|
241 | + * @since 1.0.0 |
|
242 | + * @param float $purchase_value. |
|
243 | + */ |
|
244 | + public function set_purchase_value( $purchase_value ) { |
|
245 | + $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | /** |
249 | - * Sets the purchase count. |
|
250 | - * |
|
251 | - * @since 1.0.0 |
|
252 | - * @param int $purchase_count. |
|
253 | - */ |
|
254 | - public function set_purchase_count( $purchase_count ) { |
|
255 | - $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
256 | - } |
|
249 | + * Sets the purchase count. |
|
250 | + * |
|
251 | + * @since 1.0.0 |
|
252 | + * @param int $purchase_count. |
|
253 | + */ |
|
254 | + public function set_purchase_count( $purchase_count ) { |
|
255 | + $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | /** |
259 | - * Sets the user id. |
|
260 | - * |
|
261 | - * @since 1.0.0 |
|
262 | - * @param int $user_id. |
|
263 | - */ |
|
264 | - public function set_user_id( $user_id ) { |
|
265 | - $this->set_prop( 'user_id', absint( $user_id ) ); |
|
266 | - } |
|
259 | + * Sets the user id. |
|
260 | + * |
|
261 | + * @since 1.0.0 |
|
262 | + * @param int $user_id. |
|
263 | + */ |
|
264 | + public function set_user_id( $user_id ) { |
|
265 | + $this->set_prop( 'user_id', absint( $user_id ) ); |
|
266 | + } |
|
267 | 267 | |
268 | 268 | /** |
269 | - * Sets the email. |
|
270 | - * |
|
271 | - * @since 1.0.0 |
|
272 | - * @param string $email. |
|
273 | - */ |
|
274 | - public function set_email( $email ) { |
|
269 | + * Sets the email. |
|
270 | + * |
|
271 | + * @since 1.0.0 |
|
272 | + * @param string $email. |
|
273 | + */ |
|
274 | + public function set_email( $email ) { |
|
275 | 275 | $email = is_string( $email ) ? sanitize_email( $email ) : ''; |
276 | - $this->set_prop( 'email', $email ); |
|
277 | - } |
|
276 | + $this->set_prop( 'email', $email ); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | /** |
280 | - * Sets the email cc. |
|
281 | - * |
|
282 | - * @since 1.0.0 |
|
283 | - * @param string $email_cc. |
|
284 | - */ |
|
285 | - public function set_email_cc( $email_cc ) { |
|
280 | + * Sets the email cc. |
|
281 | + * |
|
282 | + * @since 1.0.0 |
|
283 | + * @param string $email_cc. |
|
284 | + */ |
|
285 | + public function set_email_cc( $email_cc ) { |
|
286 | 286 | $email_cc = implode( ', ', wp_parse_list( $email_cc ) ); |
287 | - $this->set_prop( 'email_cc', $email_cc ); |
|
288 | - } |
|
287 | + $this->set_prop( 'email_cc', $email_cc ); |
|
288 | + } |
|
289 | 289 | |
290 | 290 | /** |
291 | - * Sets the created date. |
|
292 | - * |
|
293 | - * @since 1.0.0 |
|
294 | - * @param string $date_created date created. |
|
295 | - */ |
|
296 | - public function set_date_created( $date_created ) { |
|
291 | + * Sets the created date. |
|
292 | + * |
|
293 | + * @since 1.0.0 |
|
294 | + * @param string $date_created date created. |
|
295 | + */ |
|
296 | + public function set_date_created( $date_created ) { |
|
297 | 297 | |
298 | - $date = strtotime( $date_created ); |
|
298 | + $date = strtotime( $date_created ); |
|
299 | 299 | |
300 | 300 | if ( $date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00' ) { |
301 | 301 | $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) ); |
302 | 302 | return; |
303 | - } |
|
303 | + } |
|
304 | 304 | |
305 | - $this->set_prop( 'date_created', null ); |
|
306 | - } |
|
305 | + $this->set_prop( 'date_created', null ); |
|
306 | + } |
|
307 | 307 | |
308 | 308 | /** |
309 | - * Sets the created date. |
|
310 | - * |
|
311 | - * @since 1.0.0 |
|
312 | - * @param string $date_modified date created. |
|
313 | - */ |
|
314 | - public function set_date_modified( $date_modified ) { |
|
309 | + * Sets the created date. |
|
310 | + * |
|
311 | + * @since 1.0.0 |
|
312 | + * @param string $date_modified date created. |
|
313 | + */ |
|
314 | + public function set_date_modified( $date_modified ) { |
|
315 | 315 | |
316 | - $date = strtotime( $date_modified ); |
|
316 | + $date = strtotime( $date_modified ); |
|
317 | 317 | |
318 | 318 | if ( $date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00' ) { |
319 | 319 | $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) ); |
320 | 320 | return; |
321 | - } |
|
321 | + } |
|
322 | 322 | |
323 | - $this->set_prop( 'date_modified', null ); |
|
324 | - } |
|
323 | + $this->set_prop( 'date_modified', null ); |
|
324 | + } |
|
325 | 325 | |
326 | - /* |
|
326 | + /* |
|
327 | 327 | |-------------------------------------------------------------------------- |
328 | 328 | | Additional methods |
329 | 329 | |-------------------------------------------------------------------------- |
@@ -332,12 +332,12 @@ discard block |
||
332 | 332 | | |
333 | 333 | */ |
334 | 334 | |
335 | - /** |
|
336 | - * Saves the customer. |
|
337 | - * |
|
338 | - * @since 1.0.0 |
|
339 | - */ |
|
340 | - public function save() { |
|
335 | + /** |
|
336 | + * Saves the customer. |
|
337 | + * |
|
338 | + * @since 1.0.0 |
|
339 | + */ |
|
340 | + public function save() { |
|
341 | 341 | |
342 | 342 | $maybe_set = array( |
343 | 343 | 'uuid' => wp_generate_uuid4(), |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | |
355 | 355 | $this->set( 'date_modified', current_time( 'mysql' ) ); |
356 | 356 | |
357 | - return parent::save(); |
|
358 | - } |
|
357 | + return parent::save(); |
|
358 | + } |
|
359 | 359 | |
360 | 360 | /** |
361 | - * Helper method to clone a customer from a user ID. |
|
362 | - * |
|
363 | - * @since 1.0.0 |
|
364 | - * @param int $user_id. |
|
365 | - */ |
|
366 | - public function clone_user( $user_id ) { |
|
361 | + * Helper method to clone a customer from a user ID. |
|
362 | + * |
|
363 | + * @since 1.0.0 |
|
364 | + * @param int $user_id. |
|
365 | + */ |
|
366 | + public function clone_user( $user_id ) { |
|
367 | 367 | $user = get_userdata( $user_id ); |
368 | 368 | |
369 | 369 | if ( empty( $user ) ) { |
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - $this->set_user_id( $user->ID ); |
|
373 | + $this->set_user_id( $user->ID ); |
|
374 | 374 | $this->set_email( $user->user_email ); |
375 | 375 | $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) ); |
376 | 376 | $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) ); |
377 | 377 | $this->set( 'first_name', $user->first_name ); |
378 | 378 | $this->set( 'last_name', $user->last_name ); |
379 | - $this->set_date_created( $user->user_registered ); |
|
379 | + $this->set_date_created( $user->user_registered ); |
|
380 | 380 | |
381 | 381 | // Fetch extra data from WC or old GetPaid. |
382 | 382 | $prefixes = array( |
@@ -400,18 +400,18 @@ discard block |
||
400 | 400 | continue; |
401 | 401 | } |
402 | 402 | } |
403 | - } |
|
404 | - } |
|
403 | + } |
|
404 | + } |
|
405 | 405 | |
406 | 406 | /** |
407 | - * Helper method to migrate an existing user ID to the new customers table. |
|
408 | - * |
|
409 | - * @since 1.0.0 |
|
410 | - * @param int $user_id. |
|
411 | - */ |
|
412 | - public function migrate_from_user( $user_id ) { |
|
407 | + * Helper method to migrate an existing user ID to the new customers table. |
|
408 | + * |
|
409 | + * @since 1.0.0 |
|
410 | + * @param int $user_id. |
|
411 | + */ |
|
412 | + public function migrate_from_user( $user_id ) { |
|
413 | 413 | $this->clone_user( $user_id ); |
414 | 414 | do_action( 'getpaid_customer_migrated_from_user', $this, $user_id ); |
415 | 415 | $this->save(); |
416 | - } |
|
416 | + } |
|
417 | 417 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @since 1.0.15 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Customer class. |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
36 | 36 | */ |
37 | - public function __construct( $customer = 0 ) { |
|
37 | + public function __construct($customer = 0) { |
|
38 | 38 | |
39 | 39 | // Setup default customer data. |
40 | 40 | $this->setup_default_data(); |
41 | 41 | |
42 | - if ( is_numeric( $customer ) ) { |
|
43 | - $this->set_id( $customer ); |
|
44 | - } elseif ( $customer instanceof self ) { |
|
45 | - $this->set_id( $customer->get_id() ); |
|
46 | - } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | - $this->set_id( $customer_id ); |
|
48 | - } elseif ( ! empty( $customer->id ) ) { |
|
49 | - $this->set_id( $customer->id ); |
|
42 | + if (is_numeric($customer)) { |
|
43 | + $this->set_id($customer); |
|
44 | + } elseif ($customer instanceof self) { |
|
45 | + $this->set_id($customer->get_id()); |
|
46 | + } elseif (is_string($customer) && $customer_id = self::get_customer_id_by($customer, 'email')) { |
|
47 | + $this->set_id($customer_id); |
|
48 | + } elseif (!empty($customer->id)) { |
|
49 | + $this->set_id($customer->id); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // Load the datastore. |
53 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
53 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
54 | 54 | |
55 | - if ( $this->get_id() > 0 ) { |
|
56 | - $this->data_store->read( $this ); |
|
55 | + if ($this->get_id() > 0) { |
|
56 | + $this->data_store->read($this); |
|
57 | 57 | } |
58 | 58 | |
59 | - $this->set_object_read( true ); |
|
59 | + $this->set_object_read(true); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -71,31 +71,31 @@ discard block |
||
71 | 71 | 'status' => 'active', |
72 | 72 | 'purchase_value' => 0, |
73 | 73 | 'purchase_count' => 0, |
74 | - 'date_created' => current_time( 'mysql' ), |
|
75 | - 'date_modified' => current_time( 'mysql' ), |
|
74 | + 'date_created' => current_time('mysql'), |
|
75 | + 'date_modified' => current_time('mysql'), |
|
76 | 76 | 'uuid' => wp_generate_uuid4(), |
77 | 77 | ); |
78 | 78 | |
79 | 79 | // Add address fields. |
80 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
80 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
81 | 81 | |
82 | - if ( isset( $this->data[ $field ] ) ) { |
|
82 | + if (isset($this->data[$field])) { |
|
83 | 83 | continue; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Country. |
87 | - if ( 'country' === $field ) { |
|
88 | - $this->data[ $field ] = wpinv_get_default_country(); |
|
87 | + if ('country' === $field) { |
|
88 | + $this->data[$field] = wpinv_get_default_country(); |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | 92 | // State. |
93 | - if ( 'state' === $field ) { |
|
94 | - $this->data[ $field ] = wpinv_get_default_state(); |
|
93 | + if ('state' === $field) { |
|
94 | + $this->data[$field] = wpinv_get_default_state(); |
|
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - $this->data[ $field ] = ''; |
|
98 | + $this->data[$field] = ''; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | $this->default_data = $this->data; |
@@ -109,41 +109,41 @@ discard block |
||
109 | 109 | * @since 1.0.15 |
110 | 110 | * @return int |
111 | 111 | */ |
112 | - public static function get_customer_id_by( $value, $by = 'email' ) { |
|
112 | + public static function get_customer_id_by($value, $by = 'email') { |
|
113 | 113 | global $wpdb; |
114 | 114 | |
115 | 115 | // Prepare value. |
116 | - if ( 'email' === $by ) { |
|
117 | - $value = sanitize_email( $value ); |
|
118 | - } elseif ( 'user_id' === $by ) { |
|
119 | - $value = absint( $value ); |
|
116 | + if ('email' === $by) { |
|
117 | + $value = sanitize_email($value); |
|
118 | + } elseif ('user_id' === $by) { |
|
119 | + $value = absint($value); |
|
120 | 120 | } else { |
121 | 121 | return 0; |
122 | 122 | } |
123 | 123 | |
124 | - if ( empty( $value ) ) { |
|
124 | + if (empty($value)) { |
|
125 | 125 | return 0; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // Maybe retrieve from the cache. |
129 | - $cache_key = 'getpaid_customer_ids_by_' . $by; |
|
130 | - $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | - if ( false !== $customer_id ) { |
|
129 | + $cache_key = 'getpaid_customer_ids_by_' . $by; |
|
130 | + $customer_id = wp_cache_get($value, $cache_key); |
|
131 | + if (false !== $customer_id) { |
|
132 | 132 | return $customer_id; |
133 | 133 | } |
134 | 134 | |
135 | - if ( 'email' === $by ) { |
|
135 | + if ('email' === $by) { |
|
136 | 136 | $customer_id = (int) $wpdb->get_var( |
137 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value ) |
|
137 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value) |
|
138 | 138 | ); |
139 | - } elseif ( 'user_id' === $by ) { |
|
139 | + } elseif ('user_id' === $by) { |
|
140 | 140 | $customer_id = (int) $wpdb->get_var( |
141 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value ) |
|
141 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | 145 | // Update the cache with our data |
146 | - wp_cache_set( $value, $customer_id, $cache_key ); |
|
146 | + wp_cache_set($value, $customer_id, $cache_key); |
|
147 | 147 | |
148 | 148 | return $customer_id; |
149 | 149 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | * Clears the customer's cache. |
154 | 154 | */ |
155 | 155 | public function clear_cache() { |
156 | - wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' ); |
|
157 | - wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' ); |
|
158 | - wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
156 | + wp_cache_delete($this->get('email'), 'getpaid_customer_ids_by_email'); |
|
157 | + wp_cache_delete($this->get('user_id'), 'getpaid_customer_ids_by_user_id'); |
|
158 | + wp_cache_delete($this->get_id(), 'getpaid_customers'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /* |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | * @param string $key The key to fetch. |
180 | 180 | * @param string $context View or edit context. |
181 | 181 | */ |
182 | - public function get( $key, $context = 'view' ) { |
|
182 | + public function get($key, $context = 'view') { |
|
183 | 183 | |
184 | 184 | // Maybe strip _wpinv_ prefix from key. |
185 | - $key = str_replace( '_wpinv_', '', $key ); |
|
185 | + $key = str_replace('_wpinv_', '', $key); |
|
186 | 186 | |
187 | 187 | // Check if we have a helper method for that. |
188 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
189 | - return call_user_func( array( $this, 'get_' . $key ), $context ); |
|
188 | + if (method_exists($this, 'get_' . $key)) { |
|
189 | + return call_user_func(array($this, 'get_' . $key), $context); |
|
190 | 190 | } |
191 | 191 | |
192 | - return $this->get_prop( $key, $context ); |
|
192 | + return $this->get_prop($key, $context); |
|
193 | 193 | |
194 | 194 | } |
195 | 195 | |
@@ -209,14 +209,14 @@ discard block |
||
209 | 209 | * @param string $key The key to fetch. |
210 | 210 | * @param mixed $value The new value. |
211 | 211 | */ |
212 | - public function set( $key, $value ) { |
|
212 | + public function set($key, $value) { |
|
213 | 213 | |
214 | 214 | // Check if we have a helper method for that. |
215 | - if ( method_exists( $this, 'set_' . $key ) ) { |
|
216 | - return call_user_func( array( $this, 'set_' . $key ), $value ); |
|
215 | + if (method_exists($this, 'set_' . $key)) { |
|
216 | + return call_user_func(array($this, 'set_' . $key), $value); |
|
217 | 217 | } |
218 | 218 | |
219 | - return $this->set_prop( $key, $value ); |
|
219 | + return $this->set_prop($key, $value); |
|
220 | 220 | |
221 | 221 | } |
222 | 222 | |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | * @since 1.0.0 |
227 | 227 | * @param string $status New status. |
228 | 228 | */ |
229 | - public function set_status( $status ) { |
|
229 | + public function set_status($status) { |
|
230 | 230 | |
231 | - if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | - return $this->set_prop( 'status', $status ); |
|
231 | + if (in_array($status, array('active', 'inactive', 'blocked'), true)) { |
|
232 | + return $this->set_prop('status', $status); |
|
233 | 233 | } |
234 | 234 | |
235 | - $this->set_prop( 'status', 'inactive' ); |
|
235 | + $this->set_prop('status', 'inactive'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * @since 1.0.0 |
242 | 242 | * @param float $purchase_value. |
243 | 243 | */ |
244 | - public function set_purchase_value( $purchase_value ) { |
|
245 | - $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
244 | + public function set_purchase_value($purchase_value) { |
|
245 | + $this->set_prop('purchase_value', (float) $purchase_value); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @since 1.0.0 |
252 | 252 | * @param int $purchase_count. |
253 | 253 | */ |
254 | - public function set_purchase_count( $purchase_count ) { |
|
255 | - $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
254 | + public function set_purchase_count($purchase_count) { |
|
255 | + $this->set_prop('purchase_count', absint($purchase_count)); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * @since 1.0.0 |
262 | 262 | * @param int $user_id. |
263 | 263 | */ |
264 | - public function set_user_id( $user_id ) { |
|
265 | - $this->set_prop( 'user_id', absint( $user_id ) ); |
|
264 | + public function set_user_id($user_id) { |
|
265 | + $this->set_prop('user_id', absint($user_id)); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -271,9 +271,9 @@ discard block |
||
271 | 271 | * @since 1.0.0 |
272 | 272 | * @param string $email. |
273 | 273 | */ |
274 | - public function set_email( $email ) { |
|
275 | - $email = is_string( $email ) ? sanitize_email( $email ) : ''; |
|
276 | - $this->set_prop( 'email', $email ); |
|
274 | + public function set_email($email) { |
|
275 | + $email = is_string($email) ? sanitize_email($email) : ''; |
|
276 | + $this->set_prop('email', $email); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | * @since 1.0.0 |
283 | 283 | * @param string $email_cc. |
284 | 284 | */ |
285 | - public function set_email_cc( $email_cc ) { |
|
286 | - $email_cc = implode( ', ', wp_parse_list( $email_cc ) ); |
|
287 | - $this->set_prop( 'email_cc', $email_cc ); |
|
285 | + public function set_email_cc($email_cc) { |
|
286 | + $email_cc = implode(', ', wp_parse_list($email_cc)); |
|
287 | + $this->set_prop('email_cc', $email_cc); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -293,16 +293,16 @@ discard block |
||
293 | 293 | * @since 1.0.0 |
294 | 294 | * @param string $date_created date created. |
295 | 295 | */ |
296 | - public function set_date_created( $date_created ) { |
|
296 | + public function set_date_created($date_created) { |
|
297 | 297 | |
298 | - $date = strtotime( $date_created ); |
|
298 | + $date = strtotime($date_created); |
|
299 | 299 | |
300 | - if ( $date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00' ) { |
|
301 | - $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
300 | + if ($date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00') { |
|
301 | + $this->set_prop('date_created', gmdate('Y-m-d H:i:s', $date)); |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | - $this->set_prop( 'date_created', null ); |
|
305 | + $this->set_prop('date_created', null); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -311,16 +311,16 @@ discard block |
||
311 | 311 | * @since 1.0.0 |
312 | 312 | * @param string $date_modified date created. |
313 | 313 | */ |
314 | - public function set_date_modified( $date_modified ) { |
|
314 | + public function set_date_modified($date_modified) { |
|
315 | 315 | |
316 | - $date = strtotime( $date_modified ); |
|
316 | + $date = strtotime($date_modified); |
|
317 | 317 | |
318 | - if ( $date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00' ) { |
|
319 | - $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
318 | + if ($date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00') { |
|
319 | + $this->set_prop('date_modified', gmdate('Y-m-d H:i:s', $date)); |
|
320 | 320 | return; |
321 | 321 | } |
322 | 322 | |
323 | - $this->set_prop( 'date_modified', null ); |
|
323 | + $this->set_prop('date_modified', null); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /* |
@@ -341,18 +341,18 @@ discard block |
||
341 | 341 | |
342 | 342 | $maybe_set = array( |
343 | 343 | 'uuid' => wp_generate_uuid4(), |
344 | - 'date_created' => current_time( 'mysql' ), |
|
344 | + 'date_created' => current_time('mysql'), |
|
345 | 345 | ); |
346 | 346 | |
347 | - foreach ( $maybe_set as $key => $value ) { |
|
348 | - $current_value = $this->get( $key ); |
|
347 | + foreach ($maybe_set as $key => $value) { |
|
348 | + $current_value = $this->get($key); |
|
349 | 349 | |
350 | - if ( empty( $current_value ) ) { |
|
351 | - $this->set( $key, $value ); |
|
350 | + if (empty($current_value)) { |
|
351 | + $this->set($key, $value); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - $this->set( 'date_modified', current_time( 'mysql' ) ); |
|
355 | + $this->set('date_modified', current_time('mysql')); |
|
356 | 356 | |
357 | 357 | return parent::save(); |
358 | 358 | } |
@@ -363,20 +363,20 @@ discard block |
||
363 | 363 | * @since 1.0.0 |
364 | 364 | * @param int $user_id. |
365 | 365 | */ |
366 | - public function clone_user( $user_id ) { |
|
367 | - $user = get_userdata( $user_id ); |
|
366 | + public function clone_user($user_id) { |
|
367 | + $user = get_userdata($user_id); |
|
368 | 368 | |
369 | - if ( empty( $user ) ) { |
|
369 | + if (empty($user)) { |
|
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - $this->set_user_id( $user->ID ); |
|
374 | - $this->set_email( $user->user_email ); |
|
375 | - $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) ); |
|
376 | - $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) ); |
|
377 | - $this->set( 'first_name', $user->first_name ); |
|
378 | - $this->set( 'last_name', $user->last_name ); |
|
379 | - $this->set_date_created( $user->user_registered ); |
|
373 | + $this->set_user_id($user->ID); |
|
374 | + $this->set_email($user->user_email); |
|
375 | + $this->set_purchase_value(getpaid_get_user_total_spend($user->ID)); |
|
376 | + $this->set_purchase_count(getpaid_count_user_invoices($user->ID)); |
|
377 | + $this->set('first_name', $user->first_name); |
|
378 | + $this->set('last_name', $user->last_name); |
|
379 | + $this->set_date_created($user->user_registered); |
|
380 | 380 | |
381 | 381 | // Fetch extra data from WC or old GetPaid. |
382 | 382 | $prefixes = array( |
@@ -385,18 +385,18 @@ discard block |
||
385 | 385 | '', |
386 | 386 | ); |
387 | 387 | |
388 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
388 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
389 | 389 | |
390 | - foreach ( $prefixes as $prefix ) { |
|
390 | + foreach ($prefixes as $prefix) { |
|
391 | 391 | |
392 | 392 | // Meta table. |
393 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
393 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
394 | 394 | |
395 | 395 | // UWP table. |
396 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
396 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
397 | 397 | |
398 | - if ( ! empty( $value ) ) { |
|
399 | - $this->set( $field, $value ); |
|
398 | + if (!empty($value)) { |
|
399 | + $this->set($field, $value); |
|
400 | 400 | continue; |
401 | 401 | } |
402 | 402 | } |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | * @since 1.0.0 |
410 | 410 | * @param int $user_id. |
411 | 411 | */ |
412 | - public function migrate_from_user( $user_id ) { |
|
413 | - $this->clone_user( $user_id ); |
|
414 | - do_action( 'getpaid_customer_migrated_from_user', $this, $user_id ); |
|
412 | + public function migrate_from_user($user_id) { |
|
413 | + $this->clone_user($user_id); |
|
414 | + do_action('getpaid_customer_migrated_from_user', $this, $user_id); |
|
415 | 415 | $this->save(); |
416 | 416 | } |
417 | 417 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | $class .= ' wpi-recurring'; |
76 | 76 | } |
77 | 77 | |
78 | - $refund_url = wp_nonce_url( |
|
79 | - add_query_arg( |
|
80 | - array( |
|
81 | - 'getpaid-admin-action' => 'refund_invoice', |
|
82 | - 'invoice_id' => $invoice->get_id(), |
|
83 | - ) |
|
84 | - ), |
|
85 | - 'getpaid-nonce', |
|
86 | - 'getpaid-nonce' |
|
87 | - ); |
|
78 | + $refund_url = wp_nonce_url( |
|
79 | + add_query_arg( |
|
80 | + array( |
|
81 | + 'getpaid-admin-action' => 'refund_invoice', |
|
82 | + 'invoice_id' => $invoice->get_id(), |
|
83 | + ) |
|
84 | + ), |
|
85 | + 'getpaid-nonce', |
|
86 | + 'getpaid-nonce' |
|
87 | + ); |
|
88 | 88 | ?> |
89 | 89 | |
90 | 90 | <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>"> |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | <th class=" |
97 | 97 | <?php |
98 | 98 | echo esc_attr( $key ); |
99 | - echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
|
100 | - ?> |
|
99 | + echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
|
100 | + ?> |
|
101 | 101 | "><?php echo wp_kses_post( $label ); ?></th> |
102 | 102 | <?php endforeach; ?> |
103 | 103 | </tr> |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | <tbody class="wpinv-line-items"> |
107 | 107 | <?php |
108 | 108 | foreach ( $invoice->get_items() as $int => $item ) { |
109 | - self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
109 | + self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
110 | 110 | } |
111 | 111 | ?> |
112 | 112 | </tbody> |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | <?php |
152 | 152 | wpinv_html_select( |
153 | 153 | array( |
154 | - 'options' => $item_types, |
|
155 | - 'name' => '_wpinv_quick[type]', |
|
156 | - 'id' => '_wpinv_quick_type', |
|
157 | - 'selected' => 'custom', |
|
158 | - 'show_option_all' => false, |
|
159 | - 'show_option_none' => false, |
|
160 | - 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
|
154 | + 'options' => $item_types, |
|
155 | + 'name' => '_wpinv_quick[type]', |
|
156 | + 'id' => '_wpinv_quick_type', |
|
157 | + 'selected' => 'custom', |
|
158 | + 'show_option_all' => false, |
|
159 | + 'show_option_none' => false, |
|
160 | + 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
|
161 | 161 | ) |
162 | 162 | ); |
163 | 163 | ?> |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | <?php |
173 | 173 | wpinv_html_select( |
174 | 174 | array( |
175 | - 'options' => array_merge( |
|
176 | - array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
177 | - getpaid_get_tax_rules() |
|
178 | - ), |
|
179 | - 'name' => '_wpinv_quick[vat_rule]', |
|
180 | - 'id' => '_wpinv_quick_vat_rule', |
|
181 | - 'show_option_all' => false, |
|
182 | - 'show_option_none' => false, |
|
183 | - 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
|
184 | - 'selected' => 'digital', |
|
175 | + 'options' => array_merge( |
|
176 | + array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
177 | + getpaid_get_tax_rules() |
|
178 | + ), |
|
179 | + 'name' => '_wpinv_quick[vat_rule]', |
|
180 | + 'id' => '_wpinv_quick_vat_rule', |
|
181 | + 'show_option_all' => false, |
|
182 | + 'show_option_none' => false, |
|
183 | + 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
|
184 | + 'selected' => 'digital', |
|
185 | 185 | ) |
186 | 186 | ); |
187 | 187 | ?> |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | <?php |
195 | 195 | wpinv_html_select( |
196 | 196 | array( |
197 | - 'options' => array_merge( |
|
198 | - array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
199 | - getpaid_get_tax_classes() |
|
200 | - ), |
|
201 | - 'name' => '_wpinv_quick[vat_class]', |
|
202 | - 'id' => '_wpinv_quick_vat_class', |
|
203 | - 'show_option_all' => false, |
|
204 | - 'show_option_none' => false, |
|
205 | - 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
|
206 | - 'selected' => '_standard', |
|
197 | + 'options' => array_merge( |
|
198 | + array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
199 | + getpaid_get_tax_classes() |
|
200 | + ), |
|
201 | + 'name' => '_wpinv_quick[vat_class]', |
|
202 | + 'id' => '_wpinv_quick_vat_class', |
|
203 | + 'show_option_all' => false, |
|
204 | + 'show_option_none' => false, |
|
205 | + 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
|
206 | + 'selected' => '_standard', |
|
207 | 207 | ) |
208 | 208 | ); |
209 | 209 | ?> |
@@ -294,37 +294,37 @@ discard block |
||
294 | 294 | </p> |
295 | 295 | <?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?> |
296 | 296 | <?php |
297 | - aui()->input( |
|
298 | - array( |
|
299 | - 'type' => 'checkbox', |
|
300 | - 'name' => 'getpaid_refund_remote', |
|
301 | - 'id' => 'getpaid_refund_remote', |
|
302 | - 'label' => sprintf( |
|
303 | - 'Refund payment in %s', |
|
304 | - wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
305 | - ), |
|
306 | - 'value' => 1, |
|
307 | - 'class' => 'getpaid-refund-field', |
|
308 | - ), |
|
309 | - true |
|
310 | - ); |
|
311 | - ?> |
|
297 | + aui()->input( |
|
298 | + array( |
|
299 | + 'type' => 'checkbox', |
|
300 | + 'name' => 'getpaid_refund_remote', |
|
301 | + 'id' => 'getpaid_refund_remote', |
|
302 | + 'label' => sprintf( |
|
303 | + 'Refund payment in %s', |
|
304 | + wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
305 | + ), |
|
306 | + 'value' => 1, |
|
307 | + 'class' => 'getpaid-refund-field', |
|
308 | + ), |
|
309 | + true |
|
310 | + ); |
|
311 | + ?> |
|
312 | 312 | <?php endif; ?> |
313 | 313 | |
314 | 314 | <?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?> |
315 | 315 | <?php |
316 | - aui()->input( |
|
317 | - array( |
|
318 | - 'type' => 'checkbox', |
|
319 | - 'name' => 'getpaid_cancel_subscription', |
|
320 | - 'id' => 'getpaid_cancel_subscription', |
|
321 | - 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
322 | - 'value' => 1, |
|
323 | - 'class' => 'getpaid-refund-field', |
|
324 | - ), |
|
325 | - true |
|
326 | - ); |
|
327 | - ?> |
|
316 | + aui()->input( |
|
317 | + array( |
|
318 | + 'type' => 'checkbox', |
|
319 | + 'name' => 'getpaid_cancel_subscription', |
|
320 | + 'id' => 'getpaid_cancel_subscription', |
|
321 | + 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
322 | + 'value' => 1, |
|
323 | + 'class' => 'getpaid-refund-field', |
|
324 | + ), |
|
325 | + true |
|
326 | + ); |
|
327 | + ?> |
|
328 | 328 | <?php endif; ?> |
329 | 329 | </div> |
330 | 330 | <div class="modal-footer"> |
@@ -364,23 +364,23 @@ discard block |
||
364 | 364 | <?php |
365 | 365 | if ( $invoice->is_paid() ) { |
366 | 366 | |
367 | - printf( |
|
368 | - '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
|
369 | - esc_html__( 'Refund', 'invoicing' ) |
|
370 | - ); |
|
367 | + printf( |
|
368 | + '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
|
369 | + esc_html__( 'Refund', 'invoicing' ) |
|
370 | + ); |
|
371 | 371 | } elseif ( ! $invoice->is_refunded() ) { |
372 | - wpinv_item_dropdown( |
|
373 | - array( |
|
374 | - 'name' => 'wpinv_invoice_item', |
|
375 | - 'id' => 'wpinv_invoice_item', |
|
376 | - 'show_recurring' => true, |
|
377 | - 'class' => 'wpi_select2', |
|
378 | - ) |
|
379 | - ); |
|
380 | - |
|
381 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
382 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
383 | - echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
372 | + wpinv_item_dropdown( |
|
373 | + array( |
|
374 | + 'name' => 'wpinv_invoice_item', |
|
375 | + 'id' => 'wpinv_invoice_item', |
|
376 | + 'show_recurring' => true, |
|
377 | + 'class' => 'wpi_select2', |
|
378 | + ) |
|
379 | + ); |
|
380 | + |
|
381 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
382 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
383 | + echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
384 | 384 | |
385 | 385 | } |
386 | 386 | ?> |
@@ -397,72 +397,72 @@ discard block |
||
397 | 397 | <?php foreach ( array_keys( $columns ) as $column ) : ?> |
398 | 398 | <td class=" |
399 | 399 | <?php |
400 | - echo esc_attr( $column ); |
|
401 | - echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
|
402 | - ?> |
|
400 | + echo esc_attr( $column ); |
|
401 | + echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
|
402 | + ?> |
|
403 | 403 | "> |
404 | 404 | <?php |
405 | 405 | switch ( $column ) { |
406 | - case 'id': |
|
407 | - echo (int) $item->get_id(); |
|
408 | - break; |
|
409 | - case 'title': |
|
410 | - printf( |
|
411 | - '<a href="%s" target="_blank">%s</a>', |
|
412 | - esc_url( get_edit_post_link( $item->get_id() ) ), |
|
413 | - esc_html( $item->get_raw_name() ) |
|
414 | - ); |
|
415 | - |
|
416 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
417 | - if ( $summary !== '' ) { |
|
418 | - printf( |
|
419 | - '<span class="meta">%s</span>', |
|
420 | - wp_kses_post( wpautop( $summary ) ) |
|
421 | - ); |
|
422 | - } |
|
423 | - |
|
424 | - printf( |
|
425 | - '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
|
426 | - esc_attr( $item->get_raw_name() ), |
|
427 | - (int) $item->get_id() |
|
428 | - ); |
|
429 | - |
|
430 | - printf( |
|
431 | - '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
|
432 | - (int) $item->get_id(), |
|
433 | - esc_attr( $item->get_description() ) |
|
434 | - ); |
|
435 | - |
|
436 | - break; |
|
437 | - case 'price': |
|
438 | - printf( |
|
439 | - '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
|
440 | - esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
441 | - (int) $item->get_id() |
|
442 | - ); |
|
443 | - |
|
444 | - break; |
|
445 | - case 'qty': |
|
446 | - printf( |
|
447 | - '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
|
448 | - floatval( $item->get_quantity() ), |
|
449 | - (int) $item->get_id() |
|
450 | - ); |
|
451 | - |
|
452 | - break; |
|
453 | - case 'total': |
|
454 | - wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
455 | - |
|
456 | - break; |
|
457 | - case 'tax': |
|
458 | - echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
459 | - |
|
460 | - break; |
|
461 | - case 'action': |
|
462 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
463 | - echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
|
406 | + case 'id': |
|
407 | + echo (int) $item->get_id(); |
|
408 | + break; |
|
409 | + case 'title': |
|
410 | + printf( |
|
411 | + '<a href="%s" target="_blank">%s</a>', |
|
412 | + esc_url( get_edit_post_link( $item->get_id() ) ), |
|
413 | + esc_html( $item->get_raw_name() ) |
|
414 | + ); |
|
415 | + |
|
416 | + $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
417 | + if ( $summary !== '' ) { |
|
418 | + printf( |
|
419 | + '<span class="meta">%s</span>', |
|
420 | + wp_kses_post( wpautop( $summary ) ) |
|
421 | + ); |
|
422 | + } |
|
423 | + |
|
424 | + printf( |
|
425 | + '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
|
426 | + esc_attr( $item->get_raw_name() ), |
|
427 | + (int) $item->get_id() |
|
428 | + ); |
|
429 | + |
|
430 | + printf( |
|
431 | + '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
|
432 | + (int) $item->get_id(), |
|
433 | + esc_attr( $item->get_description() ) |
|
434 | + ); |
|
435 | + |
|
436 | + break; |
|
437 | + case 'price': |
|
438 | + printf( |
|
439 | + '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
|
440 | + esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
441 | + (int) $item->get_id() |
|
442 | + ); |
|
443 | + |
|
444 | + break; |
|
445 | + case 'qty': |
|
446 | + printf( |
|
447 | + '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
|
448 | + floatval( $item->get_quantity() ), |
|
449 | + (int) $item->get_id() |
|
450 | + ); |
|
451 | + |
|
452 | + break; |
|
453 | + case 'total': |
|
454 | + wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
455 | + |
|
456 | + break; |
|
457 | + case 'tax': |
|
458 | + echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
459 | + |
|
460 | + break; |
|
461 | + case 'action': |
|
462 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
463 | + echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
|
464 | 464 | } |
465 | - break; |
|
465 | + break; |
|
466 | 466 | } |
467 | 467 | do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice ); |
468 | 468 | ?> |
@@ -473,10 +473,10 @@ discard block |
||
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
476 | - * Output the metabox. |
|
477 | - * |
|
478 | - * @param WP_Post $post |
|
479 | - */ |
|
476 | + * Output the metabox. |
|
477 | + * |
|
478 | + * @param WP_Post $post |
|
479 | + */ |
|
480 | 480 | public static function output2( $post ) { |
481 | 481 | |
482 | 482 | // Prepare the invoice. |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -16,62 +16,62 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Meta_Box_Invoice_Items { |
18 | 18 | |
19 | - public static function get_columns( $invoice ) { |
|
19 | + public static function get_columns($invoice) { |
|
20 | 20 | $use_taxes = $invoice->is_taxable() && wpinv_use_taxes(); |
21 | 21 | $columns = array( |
22 | - 'id' => __( 'ID', 'invoicing' ), |
|
23 | - 'title' => __( 'Item', 'invoicing' ), |
|
22 | + 'id' => __('ID', 'invoicing'), |
|
23 | + 'title' => __('Item', 'invoicing'), |
|
24 | 24 | 'price' => sprintf( |
25 | 25 | '<span class="getpaid-hide-if-hours getpaid-hide-if-quantity">%s</span> |
26 | 26 | <span class="getpaid-hide-if-hours hide-if-amount">%s</span> |
27 | 27 | <span class="getpaid-hide-if-quantity hide-if-amount">%s</span>', |
28 | - __( 'Amount', 'invoicing' ), |
|
29 | - __( 'Price', 'invoicing' ), |
|
30 | - __( 'Rate', 'invoicing' ) |
|
28 | + __('Amount', 'invoicing'), |
|
29 | + __('Price', 'invoicing'), |
|
30 | + __('Rate', 'invoicing') |
|
31 | 31 | ), |
32 | 32 | 'qty' => sprintf( |
33 | 33 | '<span class="getpaid-hide-if-hours">%s</span><span class="getpaid-hide-if-quantity">%s</span>', |
34 | - __( 'Quantity', 'invoicing' ), |
|
35 | - __( 'Hours', 'invoicing' ) |
|
34 | + __('Quantity', 'invoicing'), |
|
35 | + __('Hours', 'invoicing') |
|
36 | 36 | ), |
37 | - 'total' => __( 'Total', 'invoicing' ), |
|
37 | + 'total' => __('Total', 'invoicing'), |
|
38 | 38 | 'tax' => $invoice->get_item_tax_name(), |
39 | 39 | 'action' => '', |
40 | 40 | ); |
41 | 41 | |
42 | - if ( ! $use_taxes ) { |
|
43 | - unset( $columns['tax'] ); |
|
42 | + if (!$use_taxes) { |
|
43 | + unset($columns['tax']); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return $columns; |
47 | 47 | } |
48 | 48 | |
49 | - public static function output( $post, $invoice = false ) { |
|
49 | + public static function output($post, $invoice = false) { |
|
50 | 50 | |
51 | - if ( apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) { |
|
52 | - return self::output2( $post ); |
|
51 | + if (apply_filters('getpaid_use_new_invoice_items_metabox', false)) { |
|
52 | + return self::output2($post); |
|
53 | 53 | } |
54 | 54 | |
55 | - $post_id = ! empty( $post->ID ) ? $post->ID : 0; |
|
56 | - $invoice = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice( $post_id ); |
|
55 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
56 | + $invoice = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice($post_id); |
|
57 | 57 | $use_taxes = $invoice->is_taxable() && wpinv_use_taxes(); |
58 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
59 | - $columns = self::get_columns( $invoice ); |
|
60 | - $cols = count( $columns ); |
|
58 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
59 | + $columns = self::get_columns($invoice); |
|
60 | + $cols = count($columns); |
|
61 | 61 | $class = ''; |
62 | 62 | |
63 | - unset( $item_types['adv'] ); |
|
64 | - unset( $item_types['package'] ); |
|
63 | + unset($item_types['adv']); |
|
64 | + unset($item_types['package']); |
|
65 | 65 | |
66 | - if ( $invoice->is_paid() ) { |
|
66 | + if ($invoice->is_paid()) { |
|
67 | 67 | $class .= ' wpinv-paid'; |
68 | 68 | } |
69 | 69 | |
70 | - if ( $invoice->is_refunded() ) { |
|
70 | + if ($invoice->is_refunded()) { |
|
71 | 71 | $class .= ' wpinv-refunded'; |
72 | 72 | } |
73 | 73 | |
74 | - if ( $invoice->is_recurring() ) { |
|
74 | + if ($invoice->is_recurring()) { |
|
75 | 75 | $class .= ' wpi-recurring'; |
76 | 76 | } |
77 | 77 | |
@@ -87,26 +87,26 @@ discard block |
||
87 | 87 | ); |
88 | 88 | ?> |
89 | 89 | |
90 | - <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>"> |
|
90 | + <div class="wpinv-items-wrap<?php echo esc_attr($class); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr($invoice->get_status()); ?>"> |
|
91 | 91 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
92 | 92 | |
93 | 93 | <thead> |
94 | 94 | <tr> |
95 | - <?php foreach ( $columns as $key => $label ) : ?> |
|
95 | + <?php foreach ($columns as $key => $label) : ?> |
|
96 | 96 | <th class=" |
97 | 97 | <?php |
98 | - echo esc_attr( $key ); |
|
98 | + echo esc_attr($key); |
|
99 | 99 | echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
100 | 100 | ?> |
101 | - "><?php echo wp_kses_post( $label ); ?></th> |
|
101 | + "><?php echo wp_kses_post($label); ?></th> |
|
102 | 102 | <?php endforeach; ?> |
103 | 103 | </tr> |
104 | 104 | </thead> |
105 | 105 | |
106 | 106 | <tbody class="wpinv-line-items"> |
107 | 107 | <?php |
108 | - foreach ( $invoice->get_items() as $int => $item ) { |
|
109 | - self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
108 | + foreach ($invoice->get_items() as $int => $item) { |
|
109 | + self::output_row($columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd'); |
|
110 | 110 | } |
111 | 111 | ?> |
112 | 112 | </tbody> |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | <div class="wp-clearfix"> |
124 | 124 | <label class="wpi-item-name"> |
125 | 125 | <span class="input-text-wrap"> |
126 | - <input type="text" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]"> |
|
126 | + <input type="text" style="width: 100%" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]"> |
|
127 | 127 | </span> |
128 | 128 | </label> |
129 | 129 | </div> |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | <div class="wp-clearfix"> |
132 | 132 | <label class="wpi-item-price"> |
133 | 133 | <span class="input-text-wrap"> |
134 | - <input type="text" style="width: 200px" placeholder="<?php esc_attr_e( 'Item Price', 'invoicing' ); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]"> |
|
135 | - × <input type="text" style="width: 140px" placeholder="<?php esc_attr_e( 'Item Quantity', 'invoicing' ); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]"> |
|
134 | + <input type="text" style="width: 200px" placeholder="<?php esc_attr_e('Item Price', 'invoicing'); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]"> |
|
135 | + × <input type="text" style="width: 140px" placeholder="<?php esc_attr_e('Item Quantity', 'invoicing'); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]"> |
|
136 | 136 | </span> |
137 | 137 | </label> |
138 | 138 | </div> |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | <div class="wp-clearfix"> |
141 | 141 | <label class="wpi-item-name"> |
142 | 142 | <span class="input-text-wrap"> |
143 | - <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Description', 'invoicing' ); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea> |
|
143 | + <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e('Item Description', 'invoicing'); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea> |
|
144 | 144 | </span> |
145 | 145 | </label> |
146 | 146 | </div> |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | </label> |
166 | 166 | </div> |
167 | 167 | |
168 | - <?php if ( $use_taxes ) : ?> |
|
168 | + <?php if ($use_taxes) : ?> |
|
169 | 169 | <div class="wp-clearfix"> |
170 | 170 | <label class="wpi-vat-rule"> |
171 | 171 | <span class="input-text-wrap"> |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | wpinv_html_select( |
174 | 174 | array( |
175 | 175 | 'options' => array_merge( |
176 | - array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
176 | + array('' => __('Select VAT Rule', 'invoicing')), |
|
177 | 177 | getpaid_get_tax_rules() |
178 | 178 | ), |
179 | 179 | 'name' => '_wpinv_quick[vat_rule]', |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | wpinv_html_select( |
196 | 196 | array( |
197 | 197 | 'options' => array_merge( |
198 | - array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
198 | + array('' => __('Select VAT Class', 'invoicing')), |
|
199 | 199 | getpaid_get_tax_classes() |
200 | 200 | ), |
201 | 201 | 'name' => '_wpinv_quick[vat_class]', |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | 'type' => 'checkbox', |
220 | 220 | 'name' => '_wpinv_quick[one-time]', |
221 | 221 | 'id' => '_wpinv_quick-one-time', |
222 | - 'label' => __( "One time item (won't be saved to regular items list)", 'invoicing' ), |
|
222 | + 'label' => __("One time item (won't be saved to regular items list)", 'invoicing'), |
|
223 | 223 | 'value' => 1, |
224 | 224 | 'no_wrap' => true, |
225 | 225 | 'checked' => false, |
@@ -243,39 +243,39 @@ discard block |
||
243 | 243 | </td> |
244 | 244 | </tr> |
245 | 245 | <tr class="totals"> |
246 | - <td colspan="<?php echo ( (int) $cols - 4 ); ?>"></td> |
|
246 | + <td colspan="<?php echo ((int) $cols - 4); ?>"></td> |
|
247 | 247 | <td colspan="4"> |
248 | 248 | <table cellspacing="0" cellpadding="0"> |
249 | 249 | <tr class="subtotal"> |
250 | - <td class="name"><?php esc_html_e( 'Sub Total:', 'invoicing' ); ?></td> |
|
251 | - <td class="total"><?php wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); ?></td> |
|
250 | + <td class="name"><?php esc_html_e('Sub Total:', 'invoicing'); ?></td> |
|
251 | + <td class="total"><?php wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); ?></td> |
|
252 | 252 | <td class="action"></td> |
253 | 253 | </tr> |
254 | 254 | <tr class="discount"> |
255 | - <td class="name"><?php esc_html_e( 'Discount:', 'invoicing' ); ?></td> |
|
256 | - <td class="total"><?php wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); ?></td> |
|
255 | + <td class="name"><?php esc_html_e('Discount:', 'invoicing'); ?></td> |
|
256 | + <td class="total"><?php wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); ?></td> |
|
257 | 257 | <td class="action"></td> |
258 | 258 | </tr> |
259 | - <?php if ( $use_taxes ) : ?> |
|
260 | - <?php if ( is_array( $taxes = $invoice->get_taxes() ) && wpinv_display_individual_tax_rates() ) { ?> |
|
261 | - <?php foreach ( $taxes as $tax_key => $tax_item ) { ?> |
|
259 | + <?php if ($use_taxes) : ?> |
|
260 | + <?php if (is_array($taxes = $invoice->get_taxes()) && wpinv_display_individual_tax_rates()) { ?> |
|
261 | + <?php foreach ($taxes as $tax_key => $tax_item) { ?> |
|
262 | 262 | <tr class="tax"> |
263 | - <td class="name"><?php echo esc_html( $invoice->get_tax_item_name( $tax_key, $tax_item, ':' ) ); ?></td> |
|
264 | - <td class="total"><?php wpinv_the_price( $invoice->get_tax_item_amount( $tax_key, $tax_item ), $invoice->get_currency() ); ?></td> |
|
263 | + <td class="name"><?php echo esc_html($invoice->get_tax_item_name($tax_key, $tax_item, ':')); ?></td> |
|
264 | + <td class="total"><?php wpinv_the_price($invoice->get_tax_item_amount($tax_key, $tax_item), $invoice->get_currency()); ?></td> |
|
265 | 265 | <td class="action"></td> |
266 | 266 | </tr> |
267 | 267 | <?php } ?> |
268 | 268 | <?php } else { ?> |
269 | 269 | <tr class="tax"> |
270 | - <td class="name"><?php esc_html_e( 'Tax:', 'invoicing' ); ?></td> |
|
271 | - <td class="total"><?php wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); ?></td> |
|
270 | + <td class="name"><?php esc_html_e('Tax:', 'invoicing'); ?></td> |
|
271 | + <td class="total"><?php wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); ?></td> |
|
272 | 272 | <td class="action"></td> |
273 | 273 | </tr> |
274 | 274 | <?php } ?> |
275 | 275 | <?php endif; ?> |
276 | 276 | <tr class="total"> |
277 | - <td class="name"><?php esc_html_e( 'Total:', 'invoicing' ); ?></td> |
|
278 | - <td class="total"><?php wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); ?></td> |
|
277 | + <td class="name"><?php esc_html_e('Total:', 'invoicing'); ?></td> |
|
278 | + <td class="total"><?php wpinv_the_price($invoice->get_total(), $invoice->get_currency()); ?></td> |
|
279 | 279 | <td class="action"></td> |
280 | 280 | </tr> |
281 | 281 | </table> |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | <div class="modal-dialog modal-dialog-centered" role="document"> |
292 | 292 | <div class="modal-content"> |
293 | 293 | <div class="modal-header"> |
294 | - <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e( 'Refund Payment', 'invoicing' ); ?></h5> |
|
295 | - <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
296 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
294 | + <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e('Refund Payment', 'invoicing'); ?></h5> |
|
295 | + <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
296 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
297 | 297 | <span aria-hidden="true">×</span> |
298 | 298 | <?php endif; ?> |
299 | 299 | </button> |
300 | 300 | </div> |
301 | 301 | <div class="modal-body"> |
302 | 302 | <p> |
303 | - <?php esc_html_e( 'Are you sure you want to refund this payment?', 'invoicing' ); ?> |
|
303 | + <?php esc_html_e('Are you sure you want to refund this payment?', 'invoicing'); ?> |
|
304 | 304 | </p> |
305 | - <?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?> |
|
305 | + <?php if (getpaid_payment_gateway_supports($invoice->get_gateway(), 'refunds')) : ?> |
|
306 | 306 | <?php |
307 | 307 | aui()->input( |
308 | 308 | array( |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | 'id' => 'getpaid_refund_remote', |
312 | 312 | 'label' => sprintf( |
313 | 313 | 'Refund payment in %s', |
314 | - wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
314 | + wpinv_get_gateway_admin_label($invoice->get_gateway()) |
|
315 | 315 | ), |
316 | 316 | 'value' => 1, |
317 | 317 | 'class' => 'getpaid-refund-field', |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | ?> |
322 | 322 | <?php endif; ?> |
323 | 323 | |
324 | - <?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?> |
|
324 | + <?php if (getpaid_get_invoice_subscriptions($invoice)) : ?> |
|
325 | 325 | <?php |
326 | 326 | aui()->input( |
327 | 327 | array( |
328 | 328 | 'type' => 'checkbox', |
329 | 329 | 'name' => 'getpaid_cancel_subscription', |
330 | 330 | 'id' => 'getpaid_cancel_subscription', |
331 | - 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
331 | + 'label' => __('Cancel subscription', 'invoicing'), |
|
332 | 332 | 'value' => 1, |
333 | 333 | 'class' => 'getpaid-refund-field', |
334 | 334 | ), |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | <?php endif; ?> |
339 | 339 | </div> |
340 | 340 | <div class="modal-footer"> |
341 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
341 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
342 | 342 | <a |
343 | - href="<?php echo esc_url_raw( $refund_url ); ?>" |
|
344 | - data-href="<?php echo esc_url_raw( $refund_url ); ?>" |
|
343 | + href="<?php echo esc_url_raw($refund_url); ?>" |
|
344 | + data-href="<?php echo esc_url_raw($refund_url); ?>" |
|
345 | 345 | class="btn btn-primary getpaid-refund-payment-button" |
346 | - ><?php esc_html_e( 'Refund', 'invoicing' ); ?></a> |
|
346 | + ><?php esc_html_e('Refund', 'invoicing'); ?></a> |
|
347 | 347 | <script> |
348 | 348 | // Update the refund URL when the user changes the refund options. |
349 | 349 | jQuery( function( $ ) { |
@@ -369,13 +369,13 @@ discard block |
||
369 | 369 | |
370 | 370 | <div class="wpinv-actions"> |
371 | 371 | <?php |
372 | - if ( $invoice->is_paid() ) { |
|
372 | + if ($invoice->is_paid()) { |
|
373 | 373 | |
374 | 374 | printf( |
375 | 375 | '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
376 | - esc_html__( 'Refund', 'invoicing' ) |
|
376 | + esc_html__('Refund', 'invoicing') |
|
377 | 377 | ); |
378 | - } elseif ( ! $invoice->is_refunded() ) { |
|
378 | + } elseif (!$invoice->is_refunded()) { |
|
379 | 379 | wpinv_item_dropdown( |
380 | 380 | array( |
381 | 381 | 'name' => 'wpinv_invoice_item', |
@@ -385,66 +385,66 @@ discard block |
||
385 | 385 | ) |
386 | 386 | ); |
387 | 387 | |
388 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
389 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
390 | - echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
388 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf(esc_html__('Add item to %s', 'invoicing'), esc_html($invoice->get_label())) . '</button>'; |
|
389 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__('Create new item', 'invoicing') . '</button>'; |
|
390 | + echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__('Recalculate Totals', 'invoicing') . '</button>'; |
|
391 | 391 | |
392 | 392 | } |
393 | 393 | ?> |
394 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
394 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
395 | 395 | </div> |
396 | 396 | </div> |
397 | 397 | <?php |
398 | 398 | } |
399 | 399 | |
400 | - public static function output_row( $columns, $item, $invoice, $class = 'even' ) { |
|
400 | + public static function output_row($columns, $item, $invoice, $class = 'even') { |
|
401 | 401 | |
402 | 402 | ?> |
403 | - <tr class="item item-<?php echo esc_attr( $class ); ?>" data-item-id="<?php echo esc_attr( $item->get_id() ); ?>"> |
|
404 | - <?php foreach ( array_keys( $columns ) as $column ) : ?> |
|
403 | + <tr class="item item-<?php echo esc_attr($class); ?>" data-item-id="<?php echo esc_attr($item->get_id()); ?>"> |
|
404 | + <?php foreach (array_keys($columns) as $column) : ?> |
|
405 | 405 | <td class=" |
406 | 406 | <?php |
407 | - echo esc_attr( $column ); |
|
407 | + echo esc_attr($column); |
|
408 | 408 | echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
409 | 409 | ?> |
410 | 410 | "> |
411 | 411 | <?php |
412 | - switch ( $column ) { |
|
412 | + switch ($column) { |
|
413 | 413 | case 'id': |
414 | 414 | echo (int) $item->get_id(); |
415 | 415 | break; |
416 | 416 | case 'title': |
417 | 417 | printf( |
418 | 418 | '<a href="%s" target="_blank">%s</a>', |
419 | - esc_url( get_edit_post_link( $item->get_id() ) ), |
|
420 | - esc_html( $item->get_raw_name() ) |
|
419 | + esc_url(get_edit_post_link($item->get_id())), |
|
420 | + esc_html($item->get_raw_name()) |
|
421 | 421 | ); |
422 | 422 | |
423 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
424 | - if ( $summary !== '' ) { |
|
423 | + $summary = apply_filters('getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice); |
|
424 | + if ($summary !== '') { |
|
425 | 425 | printf( |
426 | 426 | '<span class="meta">%s</span>', |
427 | - wp_kses_post( wpautop( $summary ) ) |
|
427 | + wp_kses_post(wpautop($summary)) |
|
428 | 428 | ); |
429 | 429 | } |
430 | 430 | |
431 | 431 | printf( |
432 | 432 | '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
433 | - esc_attr( $item->get_raw_name() ), |
|
433 | + esc_attr($item->get_raw_name()), |
|
434 | 434 | (int) $item->get_id() |
435 | 435 | ); |
436 | 436 | |
437 | 437 | printf( |
438 | 438 | '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
439 | 439 | (int) $item->get_id(), |
440 | - esc_attr( $item->get_description() ) |
|
440 | + esc_attr($item->get_description()) |
|
441 | 441 | ); |
442 | 442 | |
443 | 443 | break; |
444 | 444 | case 'price': |
445 | 445 | printf( |
446 | 446 | '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
447 | - esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
447 | + esc_attr(getpaid_unstandardize_amount($item->get_price())), |
|
448 | 448 | (int) $item->get_id() |
449 | 449 | ); |
450 | 450 | |
@@ -452,26 +452,26 @@ discard block |
||
452 | 452 | case 'qty': |
453 | 453 | printf( |
454 | 454 | '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
455 | - floatval( $item->get_quantity() ), |
|
455 | + floatval($item->get_quantity()), |
|
456 | 456 | (int) $item->get_id() |
457 | 457 | ); |
458 | 458 | |
459 | 459 | break; |
460 | 460 | case 'total': |
461 | - wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
461 | + wpinv_the_price($item->get_sub_total(), $invoice->get_currency()); |
|
462 | 462 | |
463 | 463 | break; |
464 | 464 | case 'tax': |
465 | - echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
465 | + echo floatval(wpinv_round_amount(getpaid_get_invoice_tax_rate($invoice, $item), 2)) . '%'; |
|
466 | 466 | |
467 | 467 | break; |
468 | 468 | case 'action': |
469 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
469 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
470 | 470 | echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
471 | 471 | } |
472 | 472 | break; |
473 | 473 | } |
474 | - do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice ); |
|
474 | + do_action('getpaid_admin_edit_invoice_item_' . $column, $item, $invoice); |
|
475 | 475 | ?> |
476 | 476 | </td> |
477 | 477 | <?php endforeach; ?> |
@@ -484,10 +484,10 @@ discard block |
||
484 | 484 | * |
485 | 485 | * @param WP_Post $post |
486 | 486 | */ |
487 | - public static function output2( $post ) { |
|
487 | + public static function output2($post) { |
|
488 | 488 | |
489 | 489 | // Prepare the invoice. |
490 | - $invoice = new WPInv_Invoice( $post ); |
|
490 | + $invoice = new WPInv_Invoice($post); |
|
491 | 491 | |
492 | 492 | // Invoice items. |
493 | 493 | $items = $invoice->get_items(); |
@@ -495,28 +495,28 @@ discard block |
||
495 | 495 | $totals = array( |
496 | 496 | |
497 | 497 | 'subtotal' => array( |
498 | - 'label' => __( 'Items Subtotal', 'invoicing' ), |
|
499 | - 'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
498 | + 'label' => __('Items Subtotal', 'invoicing'), |
|
499 | + 'value' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
500 | 500 | ), |
501 | 501 | |
502 | 502 | 'discount' => array( |
503 | - 'label' => __( 'Total Discount', 'invoicing' ), |
|
504 | - 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
503 | + 'label' => __('Total Discount', 'invoicing'), |
|
504 | + 'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
505 | 505 | ), |
506 | 506 | |
507 | 507 | 'tax' => array( |
508 | - 'label' => __( 'Total Tax', 'invoicing' ), |
|
509 | - 'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
508 | + 'label' => __('Total Tax', 'invoicing'), |
|
509 | + 'value' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
510 | 510 | ), |
511 | 511 | |
512 | 512 | 'total' => array( |
513 | - 'label' => __( 'Invoice Total', 'invoicing' ), |
|
514 | - 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
513 | + 'label' => __('Invoice Total', 'invoicing'), |
|
514 | + 'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
515 | 515 | ), |
516 | 516 | ); |
517 | 517 | |
518 | - if ( ! wpinv_use_taxes() ) { |
|
519 | - unset( $totals['tax'] ); |
|
518 | + if (!wpinv_use_taxes()) { |
|
519 | + unset($totals['tax']); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | $item_args = array( |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | 'orderby' => 'title', |
525 | 525 | 'order' => 'ASC', |
526 | 526 | 'posts_per_page' => -1, |
527 | - 'post_status' => array( 'publish' ), |
|
527 | + 'post_status' => array('publish'), |
|
528 | 528 | 'meta_query' => array( |
529 | 529 | array( |
530 | 530 | 'key' => '_wpinv_type', |
@@ -552,10 +552,10 @@ discard block |
||
552 | 552 | } |
553 | 553 | </style> |
554 | 554 | |
555 | - <div class="bsui getpaid-invoice-items-inner <?php echo empty( $items ) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;"> |
|
555 | + <div class="bsui getpaid-invoice-items-inner <?php echo empty($items) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;"> |
|
556 | 556 | |
557 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
558 | - <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
|
557 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
558 | + <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?> |
|
559 | 559 | |
560 | 560 | <div class="row"> |
561 | 561 | <div class="col-12 col-sm-6"> |
@@ -564,15 +564,15 @@ discard block |
||
564 | 564 | array( |
565 | 565 | 'id' => 'wpinv_template', |
566 | 566 | 'name' => 'wpinv_template', |
567 | - 'label' => __( 'Template', 'invoicing' ), |
|
567 | + 'label' => __('Template', 'invoicing'), |
|
568 | 568 | 'label_type' => 'vertical', |
569 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
569 | + 'placeholder' => __('Choose a template', 'invoicing'), |
|
570 | 570 | 'class' => 'form-control-sm', |
571 | - 'value' => $invoice->get_template( 'edit' ), |
|
571 | + 'value' => $invoice->get_template('edit'), |
|
572 | 572 | 'options' => array( |
573 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
574 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
575 | - 'amount' => __( 'Amount Only', 'invoicing' ), |
|
573 | + 'quantity' => __('Quantity', 'invoicing'), |
|
574 | + 'hours' => __('Hours', 'invoicing'), |
|
575 | + 'amount' => __('Amount Only', 'invoicing'), |
|
576 | 576 | ), |
577 | 577 | 'data-allow-clear' => 'false', |
578 | 578 | 'select2' => true, |
@@ -589,11 +589,11 @@ discard block |
||
589 | 589 | array( |
590 | 590 | 'id' => 'wpinv_currency', |
591 | 591 | 'name' => 'wpinv_currency', |
592 | - 'label' => __( 'Currency', 'invoicing' ), |
|
592 | + 'label' => __('Currency', 'invoicing'), |
|
593 | 593 | 'label_type' => 'vertical', |
594 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
594 | + 'placeholder' => __('Select Invoice Currency', 'invoicing'), |
|
595 | 595 | 'class' => 'form-control-sm', |
596 | - 'value' => $invoice->get_currency( 'edit' ), |
|
596 | + 'value' => $invoice->get_currency('edit'), |
|
597 | 597 | 'required' => false, |
598 | 598 | 'data-allow-clear' => 'false', |
599 | 599 | 'select2' => true, |
@@ -606,24 +606,24 @@ discard block |
||
606 | 606 | </div> |
607 | 607 | </div> |
608 | 608 | |
609 | - <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
|
609 | + <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?> |
|
610 | 610 | <?php endif; ?> |
611 | 611 | |
612 | 612 | <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items"> |
613 | 613 | <thead> |
614 | 614 | <tr> |
615 | - <th class="getpaid-item" colspan="2"><?php esc_html_e( 'Item', 'invoicing' ); ?></th> |
|
615 | + <th class="getpaid-item" colspan="2"><?php esc_html_e('Item', 'invoicing'); ?></th> |
|
616 | 616 | <th class="getpaid-quantity hide-if-amount text-right"> |
617 | - <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
618 | - <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span> |
|
617 | + <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
618 | + <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span> |
|
619 | 619 | </th> |
620 | 620 | <th class="getpaid-price hide-if-amount text-right"> |
621 | - <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
|
622 | - <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Rate', 'invoicing' ); ?></span> |
|
621 | + <span class="getpaid-hide-if-hours"><?php esc_html_e('Price', 'invoicing'); ?></span> |
|
622 | + <span class="getpaid-hide-if-quantity"><?php esc_html_e('Rate', 'invoicing'); ?></span> |
|
623 | 623 | </th> |
624 | 624 | <th class="getpaid-item-subtotal text-right"> |
625 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
|
626 | - <span class="hide-if-amount"><?php esc_html_e( 'Total', 'invoicing' ); ?></span> |
|
625 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e('Amount', 'invoicing'); ?></span> |
|
626 | + <span class="hide-if-amount"><?php esc_html_e('Total', 'invoicing'); ?></span> |
|
627 | 627 | </th> |
628 | 628 | <th class="getpaid-item-actions hide-if-not-editable" width="70px"> </th> |
629 | 629 | </tr> |
@@ -631,8 +631,8 @@ discard block |
||
631 | 631 | <tbody class="getpaid_invoice_line_items"> |
632 | 632 | <tr class="hide-if-has-items hide-if-not-editable"> |
633 | 633 | <td colspan="2" class="pt-4 pb-4"> |
634 | - <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Items', 'invoicing' ); ?></button> |
|
635 | - <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button> |
|
634 | + <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Items', 'invoicing'); ?></button> |
|
635 | + <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button> |
|
636 | 636 | </td> |
637 | 637 | <td class="hide-if-amount"> </th> |
638 | 638 | <td class="hide-if-amount"> </th> |
@@ -664,11 +664,11 @@ discard block |
||
664 | 664 | <div class="col-12 col-sm-6 offset-sm-6"> |
665 | 665 | <table class="getpaid-invoice-totals text-right w-100"> |
666 | 666 | <tbody> |
667 | - <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?> |
|
668 | - <tr class="getpaid-totals-<?php echo esc_attr( $key ); ?>"> |
|
669 | - <td class="label"><?php echo esc_html( $data['label'] ); ?>:</td> |
|
667 | + <?php foreach (apply_filters('getpaid_invoice_subtotal_rows', $totals, $invoice) as $key => $data) : ?> |
|
668 | + <tr class="getpaid-totals-<?php echo esc_attr($key); ?>"> |
|
669 | + <td class="label"><?php echo esc_html($data['label']); ?>:</td> |
|
670 | 670 | <td width="1%"></td> |
671 | - <td class="value"><?php echo wp_kses_post( $data['value'] ); ?></td> |
|
671 | + <td class="value"><?php echo wp_kses_post($data['value']); ?></td> |
|
672 | 672 | </tr> |
673 | 673 | <?php endforeach; ?> |
674 | 674 | </tbody> |
@@ -681,18 +681,18 @@ discard block |
||
681 | 681 | <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable"> |
682 | 682 | <div class="row"> |
683 | 683 | <div class="text-left col-12 col-sm-8"> |
684 | - <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Item', 'invoicing' ); ?></button> |
|
685 | - <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button> |
|
686 | - <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?> |
|
684 | + <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Item', 'invoicing'); ?></button> |
|
685 | + <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button> |
|
686 | + <?php do_action('getpaid-invoice-items-actions', $invoice); ?> |
|
687 | 687 | </div> |
688 | 688 | <div class="text-right col-12 col-sm-4"> |
689 | - <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e( 'Recalculate Totals', 'invoicing' ); ?></button> |
|
689 | + <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e('Recalculate Totals', 'invoicing'); ?></button> |
|
690 | 690 | </div> |
691 | 691 | </div> |
692 | 692 | </div> |
693 | 693 | |
694 | 694 | <div class="getpaid-invoice-item-actions hide-if-editable"> |
695 | - <p class="description m-2 text-right text-muted"><?php esc_html_e( 'This invoice is no longer editable', 'invoicing' ); ?></p> |
|
695 | + <p class="description m-2 text-right text-muted"><?php esc_html_e('This invoice is no longer editable', 'invoicing'); ?></p> |
|
696 | 696 | </div> |
697 | 697 | |
698 | 698 | <!-- Add items to an invoice --> |
@@ -700,9 +700,9 @@ discard block |
||
700 | 700 | <div class="modal-dialog modal-dialog-centered" role="document"> |
701 | 701 | <div class="modal-content"> |
702 | 702 | <div class="modal-header"> |
703 | - <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e( 'Add Item(s)', 'invoicing' ); ?></h5> |
|
704 | - <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
705 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
703 | + <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e('Add Item(s)', 'invoicing'); ?></h5> |
|
704 | + <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
705 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
706 | 706 | <span aria-hidden="true">×</span> |
707 | 707 | <?php endif; ?> |
708 | 708 | </button> |
@@ -711,10 +711,10 @@ discard block |
||
711 | 711 | <table class="widefat"> |
712 | 712 | <thead> |
713 | 713 | <tr> |
714 | - <th class="pl-0 text-left"><?php esc_html_e( 'Item', 'invoicing' ); ?></th> |
|
714 | + <th class="pl-0 text-left"><?php esc_html_e('Item', 'invoicing'); ?></th> |
|
715 | 715 | <th class="pr-0 text-right hide-if-amount"> |
716 | - <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
717 | - <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span> |
|
716 | + <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
717 | + <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span> |
|
718 | 718 | </th> |
719 | 719 | </tr> |
720 | 720 | </thead> |
@@ -722,9 +722,9 @@ discard block |
||
722 | 722 | <tr> |
723 | 723 | <td class="pl-0 text-left"> |
724 | 724 | <select class="regular-text getpaid-add-invoice-item-select"> |
725 | - <option value="" selected="selected" disabled><?php esc_html_e( 'Select an item…', 'invoicing' ); ?></option> |
|
726 | - <?php foreach ( get_posts( $item_args ) as $item ) : ?> |
|
727 | - <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html( $item->post_title ); ?></option> |
|
725 | + <option value="" selected="selected" disabled><?php esc_html_e('Select an item…', 'invoicing'); ?></option> |
|
726 | + <?php foreach (get_posts($item_args) as $item) : ?> |
|
727 | + <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html($item->post_title); ?></option> |
|
728 | 728 | <?php endforeach; ?> |
729 | 729 | </select> |
730 | 730 | </td> |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | </table> |
737 | 737 | </div> |
738 | 738 | <div class="modal-footer"> |
739 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
740 | - <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e( 'Add', 'invoicing' ); ?></button> |
|
739 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
740 | + <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e('Add', 'invoicing'); ?></button> |
|
741 | 741 | </div> |
742 | 742 | </div> |
743 | 743 | </div> |
@@ -748,9 +748,9 @@ discard block |
||
748 | 748 | <div class="modal-dialog modal-dialog-centered" role="document"> |
749 | 749 | <div class="modal-content"> |
750 | 750 | <div class="modal-header"> |
751 | - <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e( 'Create Item', 'invoicing' ); ?></h5> |
|
752 | - <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
753 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
751 | + <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e('Create Item', 'invoicing'); ?></h5> |
|
752 | + <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
753 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
754 | 754 | <span aria-hidden="true">×</span> |
755 | 755 | <?php endif; ?> |
756 | 756 | </button> |
@@ -759,27 +759,27 @@ discard block |
||
759 | 759 | <div class="getpaid-create-item-div"> |
760 | 760 | <input type="hidden" name="id" value="new" class="form-control form-control-sm item-id"> |
761 | 761 | <label class="form-group mb-3 w-100"> |
762 | - <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span> |
|
763 | - <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
|
762 | + <span><?php esc_html_e('Name', 'invoicing'); ?></span> |
|
763 | + <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name"> |
|
764 | 764 | </label> |
765 | 765 | <label class="form-group mb-3 w-100"> |
766 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
|
767 | - <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
|
768 | - <input type="text" name="price" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control form-control-sm item-price"> |
|
766 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span> |
|
767 | + <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span> |
|
768 | + <input type="text" name="price" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control form-control-sm item-price"> |
|
769 | 769 | </label> |
770 | 770 | <label class="form-group mb-3 w-100 hide-if-amount"> |
771 | - <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
771 | + <span><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
772 | 772 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
773 | 773 | </label> |
774 | 774 | <label class="form-group mb-3 w-100"> |
775 | - <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span> |
|
776 | - <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
|
775 | + <span><?php esc_html_e('Item Description', 'invoicing'); ?></span> |
|
776 | + <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea> |
|
777 | 777 | </label> |
778 | 778 | </div> |
779 | 779 | </div> |
780 | 780 | <div class="modal-footer"> |
781 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
782 | - <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Create', 'invoicing' ); ?></button> |
|
781 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
782 | + <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Create', 'invoicing'); ?></button> |
|
783 | 783 | </div> |
784 | 784 | </div> |
785 | 785 | </div> |
@@ -790,9 +790,9 @@ discard block |
||
790 | 790 | <div class="modal-dialog modal-dialog-centered" role="document"> |
791 | 791 | <div class="modal-content"> |
792 | 792 | <div class="modal-header"> |
793 | - <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e( 'Edit Item', 'invoicing' ); ?></h5> |
|
794 | - <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
795 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
793 | + <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e('Edit Item', 'invoicing'); ?></h5> |
|
794 | + <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
795 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
796 | 796 | <span aria-hidden="true">×</span> |
797 | 797 | <?php endif; ?> |
798 | 798 | </button> |
@@ -801,27 +801,27 @@ discard block |
||
801 | 801 | <div class="getpaid-edit-item-div"> |
802 | 802 | <input type="hidden" name="id" class="form-control form-control-sm item-id"> |
803 | 803 | <label class="form-group mb-3 w-100"> |
804 | - <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span> |
|
805 | - <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
|
804 | + <span><?php esc_html_e('Name', 'invoicing'); ?></span> |
|
805 | + <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name"> |
|
806 | 806 | </label> |
807 | 807 | <label class="form-group mb-3 w-100"> |
808 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
|
809 | - <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
|
810 | - <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
|
808 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span> |
|
809 | + <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span> |
|
810 | + <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount(0); ?>" class="form-control form-control-sm item-price"> |
|
811 | 811 | </label> |
812 | 812 | <label class="form-group mb-3 w-100 hide-if-amount"> |
813 | - <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
813 | + <span><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
814 | 814 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
815 | 815 | </label> |
816 | 816 | <label class="form-group mb-3 w-100"> |
817 | - <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span> |
|
818 | - <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
|
817 | + <span><?php esc_html_e('Item Description', 'invoicing'); ?></span> |
|
818 | + <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea> |
|
819 | 819 | </label> |
820 | 820 | </div> |
821 | 821 | </div> |
822 | 822 | <div class="modal-footer"> |
823 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
824 | - <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Save', 'invoicing' ); ?></button> |
|
823 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
824 | + <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Save', 'invoicing'); ?></button> |
|
825 | 825 | </div> |
826 | 826 | </div> |
827 | 827 | </div> |
@@ -10,211 +10,211 @@ |
||
10 | 10 | */ |
11 | 11 | class GetPaid_PayPal_API { |
12 | 12 | |
13 | - /** |
|
14 | - * Retrieves the bearer token. |
|
15 | - * |
|
13 | + /** |
|
14 | + * Retrieves the bearer token. |
|
15 | + * |
|
16 | 16 | * @return string|\WP_Error |
17 | - */ |
|
18 | - public static function get_token( $mode = 'live' ) { |
|
17 | + */ |
|
18 | + public static function get_token( $mode = 'live' ) { |
|
19 | 19 | |
20 | - $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
20 | + $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
21 | 21 | |
22 | - if ( $token ) { |
|
23 | - return $token; |
|
24 | - } |
|
22 | + if ( $token ) { |
|
23 | + return $token; |
|
24 | + } |
|
25 | 25 | |
26 | - $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | - $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret_key' ) : wpinv_get_option( 'paypal_sandbox_secret_key' ); |
|
28 | - $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
26 | + $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | + $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret_key' ) : wpinv_get_option( 'paypal_sandbox_secret_key' ); |
|
28 | + $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
29 | 29 | |
30 | 30 | if ( empty( $client_id ) || empty( $secret_key ) ) { |
31 | 31 | return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) ); |
32 | 32 | } |
33 | 33 | |
34 | - $args = array( |
|
35 | - 'method' => 'POST', |
|
36 | - 'timeout' => 30, |
|
37 | - 'headers' => array( |
|
38 | - 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | - 'Accept' => 'application/json', |
|
40 | - 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | - ), |
|
42 | - ); |
|
43 | - |
|
44 | - $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | - |
|
46 | - if ( is_wp_error( $response ) ) { |
|
47 | - return $response; |
|
48 | - } |
|
49 | - |
|
50 | - if ( ! isset( $response->access_token ) ) { |
|
51 | - return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | - } |
|
53 | - |
|
54 | - set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | - return $response->access_token; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Retrieves the PayPal API URL. |
|
60 | - * |
|
61 | - * @param string $endpoint |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | - $endpoint = ltrim( $endpoint, '/' ); |
|
66 | - return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Handles a post request. |
|
71 | - * |
|
72 | - * @param string $path The path to the endpoint. |
|
73 | - * @param mixed $data The data to send. |
|
74 | - * @param string $method The method to use. |
|
75 | - * |
|
76 | - * @return true|\WP_Error |
|
77 | - */ |
|
78 | - public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | - |
|
80 | - $access_token = self::get_token( $mode ); |
|
81 | - |
|
82 | - if ( is_wp_error( $access_token ) ) { |
|
83 | - return $access_token; |
|
84 | - } |
|
85 | - |
|
86 | - $url = self::get_api_url( $path, $mode ); |
|
87 | - $args = array( |
|
88 | - 'method' => $method, |
|
89 | - 'headers' => array( |
|
90 | - 'Authorization' => 'Bearer ' . $access_token, |
|
91 | - 'Content-Type' => 'application/json', |
|
92 | - ), |
|
93 | - 'body' => wp_json_encode( $data ), |
|
94 | - ); |
|
95 | - |
|
96 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Handles a get request. |
|
101 | - * |
|
102 | - * @param string $path The path to the endpoint. |
|
103 | - * @param string $method |
|
104 | - * @return object|\WP_Error |
|
105 | - */ |
|
106 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
107 | - |
|
108 | - $access_token = self::get_token( $mode ); |
|
109 | - |
|
110 | - if ( is_wp_error( $access_token ) ) { |
|
111 | - return $access_token; |
|
112 | - } |
|
113 | - |
|
114 | - $url = self::get_api_url( $path, $mode ); |
|
115 | - $args = array( |
|
116 | - 'method' => $method, |
|
117 | - 'headers' => array( |
|
118 | - 'Authorization' => 'Bearer ' . $access_token, |
|
119 | - ), |
|
120 | - ); |
|
121 | - |
|
122 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns the response body |
|
127 | - * |
|
128 | - * @since 1.0.0 |
|
129 | - * @version 1.0.0 |
|
130 | - * @param \WP_Error|array $response |
|
131 | - * @return \WP_Error|object |
|
132 | - */ |
|
133 | - public static function response_or_error( $response ) { |
|
134 | - |
|
135 | - if ( is_wp_error( $response ) ) { |
|
136 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
137 | - } |
|
138 | - |
|
139 | - if ( empty( $response['body'] ) ) { |
|
140 | - return true; |
|
141 | - } |
|
142 | - |
|
143 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
144 | - |
|
145 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
146 | - |
|
147 | - // Normal errors. |
|
148 | - if ( $response_body && isset( $response_body->message ) ) { |
|
149 | - $error_message = $response_body->message; |
|
150 | - |
|
151 | - // Identity errors. |
|
152 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
153 | - $error_message = $response_body->error_description; |
|
154 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
155 | - } else { |
|
156 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
157 | - } |
|
158 | - |
|
159 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
160 | - } |
|
161 | - |
|
162 | - return $response_body; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Fetches an order. |
|
167 | - * |
|
168 | - * @since 1.0.0 |
|
169 | - * @version 1.0.0 |
|
170 | - * @param string $order_id |
|
171 | - * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
172 | - * @return \WP_Error|object |
|
173 | - */ |
|
174 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
175 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Fetches a subscription. |
|
180 | - * |
|
181 | - * @since 1.0.0 |
|
182 | - * @version 1.0.0 |
|
183 | - * @param string $subscription_id |
|
184 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
185 | - * @return \WP_Error|object |
|
186 | - */ |
|
187 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
188 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Fetches a subscription's latest transactions (limits search to last one day). |
|
193 | - * |
|
194 | - * @since 1.0.0 |
|
195 | - * @version 1.0.0 |
|
196 | - * @param string $subscription_id |
|
197 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
198 | - * @return \WP_Error|object |
|
199 | - */ |
|
200 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
201 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
202 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
203 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Refunds a capture. |
|
208 | - * |
|
209 | - * @since 1.0.0 |
|
210 | - * @version 1.0.0 |
|
211 | - * @param string $capture_id |
|
212 | - * @param array $args |
|
213 | - * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
214 | - * @return \WP_Error|object |
|
215 | - */ |
|
216 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
217 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
218 | - } |
|
34 | + $args = array( |
|
35 | + 'method' => 'POST', |
|
36 | + 'timeout' => 30, |
|
37 | + 'headers' => array( |
|
38 | + 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | + 'Accept' => 'application/json', |
|
40 | + 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | + ), |
|
42 | + ); |
|
43 | + |
|
44 | + $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | + |
|
46 | + if ( is_wp_error( $response ) ) { |
|
47 | + return $response; |
|
48 | + } |
|
49 | + |
|
50 | + if ( ! isset( $response->access_token ) ) { |
|
51 | + return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | + } |
|
53 | + |
|
54 | + set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | + return $response->access_token; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Retrieves the PayPal API URL. |
|
60 | + * |
|
61 | + * @param string $endpoint |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | + $endpoint = ltrim( $endpoint, '/' ); |
|
66 | + return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Handles a post request. |
|
71 | + * |
|
72 | + * @param string $path The path to the endpoint. |
|
73 | + * @param mixed $data The data to send. |
|
74 | + * @param string $method The method to use. |
|
75 | + * |
|
76 | + * @return true|\WP_Error |
|
77 | + */ |
|
78 | + public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | + |
|
80 | + $access_token = self::get_token( $mode ); |
|
81 | + |
|
82 | + if ( is_wp_error( $access_token ) ) { |
|
83 | + return $access_token; |
|
84 | + } |
|
85 | + |
|
86 | + $url = self::get_api_url( $path, $mode ); |
|
87 | + $args = array( |
|
88 | + 'method' => $method, |
|
89 | + 'headers' => array( |
|
90 | + 'Authorization' => 'Bearer ' . $access_token, |
|
91 | + 'Content-Type' => 'application/json', |
|
92 | + ), |
|
93 | + 'body' => wp_json_encode( $data ), |
|
94 | + ); |
|
95 | + |
|
96 | + return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Handles a get request. |
|
101 | + * |
|
102 | + * @param string $path The path to the endpoint. |
|
103 | + * @param string $method |
|
104 | + * @return object|\WP_Error |
|
105 | + */ |
|
106 | + public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
107 | + |
|
108 | + $access_token = self::get_token( $mode ); |
|
109 | + |
|
110 | + if ( is_wp_error( $access_token ) ) { |
|
111 | + return $access_token; |
|
112 | + } |
|
113 | + |
|
114 | + $url = self::get_api_url( $path, $mode ); |
|
115 | + $args = array( |
|
116 | + 'method' => $method, |
|
117 | + 'headers' => array( |
|
118 | + 'Authorization' => 'Bearer ' . $access_token, |
|
119 | + ), |
|
120 | + ); |
|
121 | + |
|
122 | + return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns the response body |
|
127 | + * |
|
128 | + * @since 1.0.0 |
|
129 | + * @version 1.0.0 |
|
130 | + * @param \WP_Error|array $response |
|
131 | + * @return \WP_Error|object |
|
132 | + */ |
|
133 | + public static function response_or_error( $response ) { |
|
134 | + |
|
135 | + if ( is_wp_error( $response ) ) { |
|
136 | + return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
137 | + } |
|
138 | + |
|
139 | + if ( empty( $response['body'] ) ) { |
|
140 | + return true; |
|
141 | + } |
|
142 | + |
|
143 | + $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
144 | + |
|
145 | + if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
146 | + |
|
147 | + // Normal errors. |
|
148 | + if ( $response_body && isset( $response_body->message ) ) { |
|
149 | + $error_message = $response_body->message; |
|
150 | + |
|
151 | + // Identity errors. |
|
152 | + } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
153 | + $error_message = $response_body->error_description; |
|
154 | + return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
155 | + } else { |
|
156 | + $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
157 | + } |
|
158 | + |
|
159 | + return new \WP_Error( 'paypal_error', $error_message ); |
|
160 | + } |
|
161 | + |
|
162 | + return $response_body; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Fetches an order. |
|
167 | + * |
|
168 | + * @since 1.0.0 |
|
169 | + * @version 1.0.0 |
|
170 | + * @param string $order_id |
|
171 | + * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
172 | + * @return \WP_Error|object |
|
173 | + */ |
|
174 | + public static function get_order( $order_id, $mode = 'live' ) { |
|
175 | + return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Fetches a subscription. |
|
180 | + * |
|
181 | + * @since 1.0.0 |
|
182 | + * @version 1.0.0 |
|
183 | + * @param string $subscription_id |
|
184 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
185 | + * @return \WP_Error|object |
|
186 | + */ |
|
187 | + public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
188 | + return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Fetches a subscription's latest transactions (limits search to last one day). |
|
193 | + * |
|
194 | + * @since 1.0.0 |
|
195 | + * @version 1.0.0 |
|
196 | + * @param string $subscription_id |
|
197 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
198 | + * @return \WP_Error|object |
|
199 | + */ |
|
200 | + public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
201 | + $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
202 | + $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
203 | + return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Refunds a capture. |
|
208 | + * |
|
209 | + * @since 1.0.0 |
|
210 | + * @version 1.0.0 |
|
211 | + * @param string $capture_id |
|
212 | + * @param array $args |
|
213 | + * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
214 | + * @return \WP_Error|object |
|
215 | + */ |
|
216 | + public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
217 | + return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
218 | + } |
|
219 | 219 | |
220 | 220 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly. |
4 | -defined( 'ABSPATH' ) || exit; |
|
4 | +defined('ABSPATH') || exit; |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * PayPal API handler. |
@@ -15,43 +15,43 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return string|\WP_Error |
17 | 17 | */ |
18 | - public static function get_token( $mode = 'live' ) { |
|
18 | + public static function get_token($mode = 'live') { |
|
19 | 19 | |
20 | - $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
20 | + $token = get_transient('getpaid_paypal_' . $mode . '_token'); |
|
21 | 21 | |
22 | - if ( $token ) { |
|
22 | + if ($token) { |
|
23 | 23 | return $token; |
24 | 24 | } |
25 | 25 | |
26 | - $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | - $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret_key' ) : wpinv_get_option( 'paypal_sandbox_secret_key' ); |
|
28 | - $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
26 | + $client_id = 'live' === $mode ? wpinv_get_option('paypal_client_id') : wpinv_get_option('paypal_sandbox_client_id'); |
|
27 | + $secret_key = 'live' === $mode ? wpinv_get_option('paypal_secret_key') : wpinv_get_option('paypal_sandbox_secret_key'); |
|
28 | + $url = self::get_api_url('v1/oauth2/token?grant_type=client_credentials', $mode); |
|
29 | 29 | |
30 | - if ( empty( $client_id ) || empty( $secret_key ) ) { |
|
31 | - return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) ); |
|
30 | + if (empty($client_id) || empty($secret_key)) { |
|
31 | + return new \WP_Error('invalid_request', 'Missing client id or secret key.', array('status' => 400)); |
|
32 | 32 | } |
33 | 33 | |
34 | - $args = array( |
|
34 | + $args = array( |
|
35 | 35 | 'method' => 'POST', |
36 | 36 | 'timeout' => 30, |
37 | 37 | 'headers' => array( |
38 | - 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
38 | + 'Authorization' => 'Basic ' . base64_encode($client_id . ':' . $secret_key), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | 39 | 'Accept' => 'application/json', |
40 | 40 | 'Content-Type' => 'application/x-www-form-urlencoded', |
41 | 41 | ), |
42 | 42 | ); |
43 | 43 | |
44 | - $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
44 | + $response = self::response_or_error(wp_remote_post($url, $args)); |
|
45 | 45 | |
46 | - if ( is_wp_error( $response ) ) { |
|
46 | + if (is_wp_error($response)) { |
|
47 | 47 | return $response; |
48 | 48 | } |
49 | 49 | |
50 | - if ( ! isset( $response->access_token ) ) { |
|
51 | - return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
50 | + if (!isset($response->access_token)) { |
|
51 | + return new \WP_Error('invalid_request', 'Could not create token.', array('status' => 400)); |
|
52 | 52 | } |
53 | 53 | |
54 | - set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
54 | + set_transient('getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600); |
|
55 | 55 | return $response->access_token; |
56 | 56 | } |
57 | 57 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param string $endpoint |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | - $endpoint = ltrim( $endpoint, '/' ); |
|
64 | + public static function get_api_url($endpoint = '', $mode = 'live') { |
|
65 | + $endpoint = ltrim($endpoint, '/'); |
|
66 | 66 | return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
67 | 67 | } |
68 | 68 | |
@@ -75,25 +75,25 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return true|\WP_Error |
77 | 77 | */ |
78 | - public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
78 | + public static function post($path, $data, $mode = 'live', $method = 'POST') { |
|
79 | 79 | |
80 | - $access_token = self::get_token( $mode ); |
|
80 | + $access_token = self::get_token($mode); |
|
81 | 81 | |
82 | - if ( is_wp_error( $access_token ) ) { |
|
82 | + if (is_wp_error($access_token)) { |
|
83 | 83 | return $access_token; |
84 | 84 | } |
85 | 85 | |
86 | - $url = self::get_api_url( $path, $mode ); |
|
86 | + $url = self::get_api_url($path, $mode); |
|
87 | 87 | $args = array( |
88 | 88 | 'method' => $method, |
89 | 89 | 'headers' => array( |
90 | 90 | 'Authorization' => 'Bearer ' . $access_token, |
91 | 91 | 'Content-Type' => 'application/json', |
92 | 92 | ), |
93 | - 'body' => wp_json_encode( $data ), |
|
93 | + 'body' => wp_json_encode($data), |
|
94 | 94 | ); |
95 | 95 | |
96 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
96 | + return self::response_or_error(wp_remote_post($url, $args)); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @param string $method |
104 | 104 | * @return object|\WP_Error |
105 | 105 | */ |
106 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
106 | + public static function get($path, $mode = 'live', $method = 'GET') { |
|
107 | 107 | |
108 | - $access_token = self::get_token( $mode ); |
|
108 | + $access_token = self::get_token($mode); |
|
109 | 109 | |
110 | - if ( is_wp_error( $access_token ) ) { |
|
110 | + if (is_wp_error($access_token)) { |
|
111 | 111 | return $access_token; |
112 | 112 | } |
113 | 113 | |
114 | - $url = self::get_api_url( $path, $mode ); |
|
114 | + $url = self::get_api_url($path, $mode); |
|
115 | 115 | $args = array( |
116 | 116 | 'method' => $method, |
117 | 117 | 'headers' => array( |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ), |
120 | 120 | ); |
121 | 121 | |
122 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
122 | + return self::response_or_error(wp_remote_get($url, $args)); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -130,33 +130,33 @@ discard block |
||
130 | 130 | * @param \WP_Error|array $response |
131 | 131 | * @return \WP_Error|object |
132 | 132 | */ |
133 | - public static function response_or_error( $response ) { |
|
133 | + public static function response_or_error($response) { |
|
134 | 134 | |
135 | - if ( is_wp_error( $response ) ) { |
|
136 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
135 | + if (is_wp_error($response)) { |
|
136 | + return new \WP_Error('paypal_error', __('There was a problem connecting to the PayPal API endpoint.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | - if ( empty( $response['body'] ) ) { |
|
139 | + if (empty($response['body'])) { |
|
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | |
143 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
143 | + $response_body = json_decode(wp_remote_retrieve_body($response)); |
|
144 | 144 | |
145 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
145 | + if (wp_remote_retrieve_response_code($response) > 299) { |
|
146 | 146 | |
147 | 147 | // Normal errors. |
148 | - if ( $response_body && isset( $response_body->message ) ) { |
|
148 | + if ($response_body && isset($response_body->message)) { |
|
149 | 149 | $error_message = $response_body->message; |
150 | 150 | |
151 | 151 | // Identity errors. |
152 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
152 | + } elseif ($response_body && isset($response_body->error_description)) { |
|
153 | 153 | $error_message = $response_body->error_description; |
154 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
154 | + return new \WP_Error('paypal_error', wp_kses_post($response_body->error_description)); |
|
155 | 155 | } else { |
156 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
156 | + $error_message = __('There was an error connecting to the PayPal API endpoint.', 'invoicing'); |
|
157 | 157 | } |
158 | 158 | |
159 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
159 | + return new \WP_Error('paypal_error', $error_message); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return $response_body; |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
172 | 172 | * @return \WP_Error|object |
173 | 173 | */ |
174 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
175 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
174 | + public static function get_order($order_id, $mode = 'live') { |
|
175 | + return self::get('/v2/checkout/orders/' . $order_id, $mode); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
185 | 185 | * @return \WP_Error|object |
186 | 186 | */ |
187 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
188 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
187 | + public static function get_subscription($subscription_id, $mode = 'live') { |
|
188 | + return self::get('/v1/billing/subscriptions/' . $subscription_id, $mode); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
198 | 198 | * @return \WP_Error|object |
199 | 199 | */ |
200 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
201 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
202 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
203 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
200 | + public static function get_subscription_transaction($subscription_id, $mode = 'live') { |
|
201 | + $start_time = gmdate('Y-m-d\TH:i:s\Z', strtotime('-1 day')); |
|
202 | + $end_time = gmdate('Y-m-d\TH:i:s\Z'); |
|
203 | + return self::get("/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
214 | 214 | * @return \WP_Error|object |
215 | 215 | */ |
216 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
217 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
216 | + public static function refund_capture($capture_id, $args = array(), $mode = 'live') { |
|
217 | + return self::post('/v2/payments/captures/' . $capture_id . '/refund', $args, $mode); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | } |
@@ -13,199 +13,199 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_Tax { |
15 | 15 | |
16 | - /** |
|
17 | - * Calculates tax for a line item. |
|
18 | - * |
|
19 | - * @param float $price The price to calc tax on. |
|
20 | - * @param array $rates The rates to apply. |
|
21 | - * @param boolean $price_includes_tax Whether the passed price has taxes included. |
|
22 | - * @return array Array of tax name => tax amount. |
|
23 | - */ |
|
24 | - public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
25 | - |
|
26 | - if ( $price_includes_tax ) { |
|
27 | - $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
28 | - } else { |
|
29 | - $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
30 | - } |
|
31 | - |
|
32 | - return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
33 | - |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Calc tax from inclusive price. |
|
38 | - * |
|
39 | - * @param float $price Price to calculate tax for. |
|
40 | - * @param array $rates Array of tax rates. |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public static function calc_inclusive_tax( $price, $rates ) { |
|
44 | - $taxes = array(); |
|
45 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
46 | - |
|
47 | - // Add tax rates. |
|
48 | - $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
49 | - |
|
50 | - foreach ( $tax_rates as $name => $rate ) { |
|
51 | - $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | - $net_price = $price - ( $the_rate * $price ); |
|
53 | - $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | - $taxes[ $name ] = $tax_amount; |
|
55 | - } |
|
56 | - |
|
57 | - // Round all taxes to precision (4DP) before passing them back. |
|
58 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
59 | - |
|
60 | - return $taxes; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Calc tax from exclusive price. |
|
65 | - * |
|
66 | - * @param float $price Price to calculate tax for. |
|
67 | - * @param array $rates Array of tax rates. |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public static function calc_exclusive_tax( $price, $rates ) { |
|
71 | - $taxes = array(); |
|
72 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
73 | - |
|
74 | - foreach ( $tax_rates as $name => $rate ) { |
|
75 | - |
|
76 | - $tax_amount = $price * ( $rate / 100 ); |
|
77 | - $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
78 | - |
|
79 | - } |
|
80 | - |
|
81 | - // Round all taxes to precision (4DP) before passing them back. |
|
82 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
83 | - |
|
84 | - return $taxes; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Get's an array of all tax rates. |
|
89 | - * |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public static function get_all_tax_rates() { |
|
93 | - |
|
94 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
95 | - |
|
96 | - return apply_filters( |
|
97 | - 'getpaid_get_all_tax_rates', |
|
98 | - array_filter( wpinv_parse_list( $rates ) ) |
|
99 | - ); |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Get's an array of default tax rates. |
|
105 | - * |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public static function get_default_tax_rates() { |
|
109 | - |
|
110 | - return apply_filters( |
|
111 | - 'getpaid_get_default_tax_rates', |
|
112 | - array( |
|
113 | - array( |
|
114 | - 'country' => wpinv_get_default_country(), |
|
115 | - 'state' => wpinv_get_default_state(), |
|
116 | - 'global' => true, |
|
117 | - 'rate' => wpinv_get_default_tax_rate(), |
|
118 | - 'name' => __( 'Tax', 'invoicing' ), |
|
119 | - ), |
|
120 | - ) |
|
121 | - ); |
|
122 | - |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Get's an array of all tax rules. |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public static function get_all_tax_rules() { |
|
131 | - |
|
132 | - $rules = get_option( |
|
133 | - 'wpinv_tax_rules', |
|
134 | - array( |
|
135 | - array( |
|
136 | - 'key' => 'physical', |
|
137 | - 'label' => __( 'Physical Item', 'invoicing' ), |
|
138 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
139 | - 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
140 | - ), |
|
141 | - array( |
|
142 | - 'key' => 'digital', |
|
143 | - 'label' => __( 'Digital Item', 'invoicing' ), |
|
144 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
145 | - 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
146 | - ), |
|
147 | - ) |
|
148 | - ); |
|
149 | - |
|
150 | - return apply_filters( |
|
151 | - 'getpaid_tax_rules', |
|
152 | - array_filter( array_values( wpinv_parse_list( $rules ) ) ) |
|
153 | - ); |
|
154 | - |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Get's an array of tax rates for a given address. |
|
159 | - * |
|
160 | - * @param string $country |
|
161 | - * @param string $state |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public static function get_address_tax_rates( $country, $state ) { |
|
165 | - |
|
166 | - $all_tax_rates = self::get_all_tax_rates(); |
|
167 | - $matching_rates = array_merge( |
|
168 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
169 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
170 | - ); |
|
171 | - |
|
172 | - foreach ( $matching_rates as $i => $rate ) { |
|
173 | - |
|
174 | - $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) ); |
|
175 | - if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) { |
|
176 | - unset( $matching_rates[ $i ] ); |
|
177 | - } |
|
16 | + /** |
|
17 | + * Calculates tax for a line item. |
|
18 | + * |
|
19 | + * @param float $price The price to calc tax on. |
|
20 | + * @param array $rates The rates to apply. |
|
21 | + * @param boolean $price_includes_tax Whether the passed price has taxes included. |
|
22 | + * @return array Array of tax name => tax amount. |
|
23 | + */ |
|
24 | + public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
25 | + |
|
26 | + if ( $price_includes_tax ) { |
|
27 | + $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
28 | + } else { |
|
29 | + $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
30 | + } |
|
31 | + |
|
32 | + return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
33 | + |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Calc tax from inclusive price. |
|
38 | + * |
|
39 | + * @param float $price Price to calculate tax for. |
|
40 | + * @param array $rates Array of tax rates. |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public static function calc_inclusive_tax( $price, $rates ) { |
|
44 | + $taxes = array(); |
|
45 | + $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
46 | + |
|
47 | + // Add tax rates. |
|
48 | + $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
49 | + |
|
50 | + foreach ( $tax_rates as $name => $rate ) { |
|
51 | + $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | + $net_price = $price - ( $the_rate * $price ); |
|
53 | + $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | + $taxes[ $name ] = $tax_amount; |
|
55 | + } |
|
56 | + |
|
57 | + // Round all taxes to precision (4DP) before passing them back. |
|
58 | + $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
59 | + |
|
60 | + return $taxes; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Calc tax from exclusive price. |
|
65 | + * |
|
66 | + * @param float $price Price to calculate tax for. |
|
67 | + * @param array $rates Array of tax rates. |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public static function calc_exclusive_tax( $price, $rates ) { |
|
71 | + $taxes = array(); |
|
72 | + $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
73 | + |
|
74 | + foreach ( $tax_rates as $name => $rate ) { |
|
75 | + |
|
76 | + $tax_amount = $price * ( $rate / 100 ); |
|
77 | + $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
78 | + |
|
79 | + } |
|
80 | + |
|
81 | + // Round all taxes to precision (4DP) before passing them back. |
|
82 | + $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
83 | + |
|
84 | + return $taxes; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Get's an array of all tax rates. |
|
89 | + * |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public static function get_all_tax_rates() { |
|
93 | + |
|
94 | + $rates = get_option( 'wpinv_tax_rates', array() ); |
|
95 | + |
|
96 | + return apply_filters( |
|
97 | + 'getpaid_get_all_tax_rates', |
|
98 | + array_filter( wpinv_parse_list( $rates ) ) |
|
99 | + ); |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Get's an array of default tax rates. |
|
105 | + * |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public static function get_default_tax_rates() { |
|
109 | + |
|
110 | + return apply_filters( |
|
111 | + 'getpaid_get_default_tax_rates', |
|
112 | + array( |
|
113 | + array( |
|
114 | + 'country' => wpinv_get_default_country(), |
|
115 | + 'state' => wpinv_get_default_state(), |
|
116 | + 'global' => true, |
|
117 | + 'rate' => wpinv_get_default_tax_rate(), |
|
118 | + 'name' => __( 'Tax', 'invoicing' ), |
|
119 | + ), |
|
120 | + ) |
|
121 | + ); |
|
122 | + |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Get's an array of all tax rules. |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public static function get_all_tax_rules() { |
|
131 | + |
|
132 | + $rules = get_option( |
|
133 | + 'wpinv_tax_rules', |
|
134 | + array( |
|
135 | + array( |
|
136 | + 'key' => 'physical', |
|
137 | + 'label' => __( 'Physical Item', 'invoicing' ), |
|
138 | + 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
139 | + 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
140 | + ), |
|
141 | + array( |
|
142 | + 'key' => 'digital', |
|
143 | + 'label' => __( 'Digital Item', 'invoicing' ), |
|
144 | + 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
145 | + 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
146 | + ), |
|
147 | + ) |
|
148 | + ); |
|
149 | + |
|
150 | + return apply_filters( |
|
151 | + 'getpaid_tax_rules', |
|
152 | + array_filter( array_values( wpinv_parse_list( $rules ) ) ) |
|
153 | + ); |
|
154 | + |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Get's an array of tax rates for a given address. |
|
159 | + * |
|
160 | + * @param string $country |
|
161 | + * @param string $state |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public static function get_address_tax_rates( $country, $state ) { |
|
165 | + |
|
166 | + $all_tax_rates = self::get_all_tax_rates(); |
|
167 | + $matching_rates = array_merge( |
|
168 | + wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
169 | + wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
170 | + ); |
|
171 | + |
|
172 | + foreach ( $matching_rates as $i => $rate ) { |
|
173 | + |
|
174 | + $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) ); |
|
175 | + if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) { |
|
176 | + unset( $matching_rates[ $i ] ); |
|
177 | + } |
|
178 | 178 | } |
179 | 179 | |
180 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
181 | - |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
186 | - * |
|
187 | - * @param array $taxes Array of taxes. |
|
188 | - * @return float |
|
189 | - */ |
|
190 | - public static function get_tax_total( $taxes ) { |
|
191 | - return self::round( array_sum( $taxes ) ); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Round to precision. |
|
196 | - * |
|
197 | - * Filter example: to return rounding to .5 cents you'd use: |
|
198 | - * |
|
199 | - * function euro_5cent_rounding( $in ) { |
|
200 | - * return round( $in / 5, 2 ) * 5; |
|
201 | - * } |
|
202 | - * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
203 | - * |
|
204 | - * @param float|int $in Value to round. |
|
205 | - * @return float |
|
206 | - */ |
|
207 | - public static function round( $in ) { |
|
208 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
209 | - } |
|
180 | + return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
181 | + |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
186 | + * |
|
187 | + * @param array $taxes Array of taxes. |
|
188 | + * @return float |
|
189 | + */ |
|
190 | + public static function get_tax_total( $taxes ) { |
|
191 | + return self::round( array_sum( $taxes ) ); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Round to precision. |
|
196 | + * |
|
197 | + * Filter example: to return rounding to .5 cents you'd use: |
|
198 | + * |
|
199 | + * function euro_5cent_rounding( $in ) { |
|
200 | + * return round( $in / 5, 2 ) * 5; |
|
201 | + * } |
|
202 | + * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
203 | + * |
|
204 | + * @param float|int $in Value to round. |
|
205 | + * @return float |
|
206 | + */ |
|
207 | + public static function round( $in ) { |
|
208 | + return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
209 | + } |
|
210 | 210 | |
211 | 211 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Class GetPaid_Tax |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | * @param boolean $price_includes_tax Whether the passed price has taxes included. |
22 | 22 | * @return array Array of tax name => tax amount. |
23 | 23 | */ |
24 | - public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
24 | + public static function calc_tax($price, $rates, $price_includes_tax = false) { |
|
25 | 25 | |
26 | - if ( $price_includes_tax ) { |
|
27 | - $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
26 | + if ($price_includes_tax) { |
|
27 | + $taxes = self::calc_inclusive_tax($price, $rates); |
|
28 | 28 | } else { |
29 | - $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
29 | + $taxes = self::calc_exclusive_tax($price, $rates); |
|
30 | 30 | } |
31 | 31 | |
32 | - return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
32 | + return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | |
@@ -40,22 +40,22 @@ discard block |
||
40 | 40 | * @param array $rates Array of tax rates. |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - public static function calc_inclusive_tax( $price, $rates ) { |
|
43 | + public static function calc_inclusive_tax($price, $rates) { |
|
44 | 44 | $taxes = array(); |
45 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
45 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
46 | 46 | |
47 | 47 | // Add tax rates. |
48 | - $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
48 | + $tax_rate = 1 + (array_sum($tax_rates) / 100); |
|
49 | 49 | |
50 | - foreach ( $tax_rates as $name => $rate ) { |
|
51 | - $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | - $net_price = $price - ( $the_rate * $price ); |
|
53 | - $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | - $taxes[ $name ] = $tax_amount; |
|
50 | + foreach ($tax_rates as $name => $rate) { |
|
51 | + $the_rate = ($rate / 100) / $tax_rate; |
|
52 | + $net_price = $price - ($the_rate * $price); |
|
53 | + $tax_amount = apply_filters('getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price); |
|
54 | + $taxes[$name] = $tax_amount; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | // Round all taxes to precision (4DP) before passing them back. |
58 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
58 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
59 | 59 | |
60 | 60 | return $taxes; |
61 | 61 | } |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | * @param array $rates Array of tax rates. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public static function calc_exclusive_tax( $price, $rates ) { |
|
70 | + public static function calc_exclusive_tax($price, $rates) { |
|
71 | 71 | $taxes = array(); |
72 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
72 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
73 | 73 | |
74 | - foreach ( $tax_rates as $name => $rate ) { |
|
74 | + foreach ($tax_rates as $name => $rate) { |
|
75 | 75 | |
76 | - $tax_amount = $price * ( $rate / 100 ); |
|
77 | - $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
76 | + $tax_amount = $price * ($rate / 100); |
|
77 | + $taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Round all taxes to precision (4DP) before passing them back. |
82 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
82 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
83 | 83 | |
84 | 84 | return $taxes; |
85 | 85 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public static function get_all_tax_rates() { |
93 | 93 | |
94 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
94 | + $rates = get_option('wpinv_tax_rates', array()); |
|
95 | 95 | |
96 | 96 | return apply_filters( |
97 | 97 | 'getpaid_get_all_tax_rates', |
98 | - array_filter( wpinv_parse_list( $rates ) ) |
|
98 | + array_filter(wpinv_parse_list($rates)) |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'state' => wpinv_get_default_state(), |
116 | 116 | 'global' => true, |
117 | 117 | 'rate' => wpinv_get_default_tax_rate(), |
118 | - 'name' => __( 'Tax', 'invoicing' ), |
|
118 | + 'name' => __('Tax', 'invoicing'), |
|
119 | 119 | ), |
120 | 120 | ) |
121 | 121 | ); |
@@ -134,22 +134,22 @@ discard block |
||
134 | 134 | array( |
135 | 135 | array( |
136 | 136 | 'key' => 'physical', |
137 | - 'label' => __( 'Physical Item', 'invoicing' ), |
|
138 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
139 | - 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
137 | + 'label' => __('Physical Item', 'invoicing'), |
|
138 | + 'tax_base' => wpinv_get_option('tax_base', 'billing'), |
|
139 | + 'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'), |
|
140 | 140 | ), |
141 | 141 | array( |
142 | 142 | 'key' => 'digital', |
143 | - 'label' => __( 'Digital Item', 'invoicing' ), |
|
144 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
145 | - 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
143 | + 'label' => __('Digital Item', 'invoicing'), |
|
144 | + 'tax_base' => wpinv_get_option('tax_base', 'billing'), |
|
145 | + 'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'), |
|
146 | 146 | ), |
147 | 147 | ) |
148 | 148 | ); |
149 | 149 | |
150 | 150 | return apply_filters( |
151 | 151 | 'getpaid_tax_rules', |
152 | - array_filter( array_values( wpinv_parse_list( $rules ) ) ) |
|
152 | + array_filter(array_values(wpinv_parse_list($rules))) |
|
153 | 153 | ); |
154 | 154 | |
155 | 155 | } |
@@ -161,23 +161,23 @@ discard block |
||
161 | 161 | * @param string $state |
162 | 162 | * @return array |
163 | 163 | */ |
164 | - public static function get_address_tax_rates( $country, $state ) { |
|
164 | + public static function get_address_tax_rates($country, $state) { |
|
165 | 165 | |
166 | 166 | $all_tax_rates = self::get_all_tax_rates(); |
167 | 167 | $matching_rates = array_merge( |
168 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
169 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
168 | + wp_list_filter($all_tax_rates, array('country' => $country)), |
|
169 | + wp_list_filter($all_tax_rates, array('country' => '')) |
|
170 | 170 | ); |
171 | 171 | |
172 | - foreach ( $matching_rates as $i => $rate ) { |
|
172 | + foreach ($matching_rates as $i => $rate) { |
|
173 | 173 | |
174 | - $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) ); |
|
175 | - if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) { |
|
176 | - unset( $matching_rates[ $i ] ); |
|
174 | + $states = array_filter(wpinv_clean(explode(',', strtolower($rate['state'])))); |
|
175 | + if (empty($rate['global']) && !in_array(strtolower($state), $states)) { |
|
176 | + unset($matching_rates[$i]); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
180 | + return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state); |
|
181 | 181 | |
182 | 182 | } |
183 | 183 | |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @param array $taxes Array of taxes. |
188 | 188 | * @return float |
189 | 189 | */ |
190 | - public static function get_tax_total( $taxes ) { |
|
191 | - return self::round( array_sum( $taxes ) ); |
|
190 | + public static function get_tax_total($taxes) { |
|
191 | + return self::round(array_sum($taxes)); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @param float|int $in Value to round. |
205 | 205 | * @return float |
206 | 206 | */ |
207 | - public static function round( $in ) { |
|
208 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
207 | + public static function round($in) { |
|
208 | + return apply_filters('getpaid_tax_round', round($in, 4), $in); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | } |
@@ -8,22 +8,22 @@ discard block |
||
8 | 8 | * @var WPInv_Invoice $invoice |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | // Totals rows. |
14 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
14 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
15 | 15 | |
16 | -do_action( 'getpaid_before_email_line_totals', $invoice, $totals ); |
|
16 | +do_action('getpaid_before_email_line_totals', $invoice, $totals); |
|
17 | 17 | |
18 | 18 | ?> |
19 | 19 | |
20 | 20 | |
21 | -<?php if ( has_action( 'wpinv_email_footer_buttons' ) ) : ?> |
|
21 | +<?php if (has_action('wpinv_email_footer_buttons')) : ?> |
|
22 | 22 | |
23 | 23 | <tr class="wpinv_cart_footer_row"> |
24 | 24 | |
25 | - <td colspan="<?php echo ( (int) $column_count ); ?>"> |
|
26 | - <?php do_action( 'wpinv_email_footer_buttons' ); ?> |
|
25 | + <td colspan="<?php echo ((int) $column_count); ?>"> |
|
26 | + <?php do_action('wpinv_email_footer_buttons'); ?> |
|
27 | 27 | </td> |
28 | 28 | |
29 | 29 | </tr> |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | <?php endif; ?> |
32 | 32 | |
33 | 33 | |
34 | -<?php foreach ( $totals as $key => $label ) : ?> |
|
34 | +<?php foreach ($totals as $key => $label) : ?> |
|
35 | 35 | |
36 | - <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html( $key ); ?>_row"> |
|
36 | + <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html($key); ?>_row"> |
|
37 | 37 | |
38 | - <td colspan="<?php echo absint( ( $column_count - 1 ) ); ?>" class="wpinv_cart_<?php echo esc_html( $key ); ?>_label text-right"> |
|
39 | - <strong><?php echo esc_html( $label ); ?>:</strong> |
|
38 | + <td colspan="<?php echo absint(($column_count - 1)); ?>" class="wpinv_cart_<?php echo esc_html($key); ?>_label text-right"> |
|
39 | + <strong><?php echo esc_html($label); ?>:</strong> |
|
40 | 40 | </td> |
41 | 41 | |
42 | - <td class="wpinv_cart_<?php echo esc_html( $key ); ?> text-right"> |
|
42 | + <td class="wpinv_cart_<?php echo esc_html($key); ?> text-right"> |
|
43 | 43 | |
44 | 44 | <?php |
45 | 45 | |
46 | 46 | // Total tax. |
47 | - if ( 'tax' == $key ) { |
|
48 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
47 | + if ('tax' == $key) { |
|
48 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // Individual taxes. |
52 | - if ( 0 === strpos( $key, 'tax__' ) ) { |
|
53 | - wpinv_the_price( $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ), $invoice->get_currency() ); |
|
52 | + if (0 === strpos($key, 'tax__')) { |
|
53 | + wpinv_the_price($invoice->get_tax_total_by_name(str_replace('tax__', '', $key)), $invoice->get_currency()); |
|
54 | 54 | } |
55 | 55 | |
56 | - if ( 'fee' == $key ) { |
|
57 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
56 | + if ('fee' == $key) { |
|
57 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Total discount. |
61 | - if ( 'discount' == $key ) { |
|
62 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
61 | + if ('discount' == $key) { |
|
62 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // Sub total. |
66 | - if ( 'subtotal' == $key ) { |
|
67 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
66 | + if ('subtotal' == $key) { |
|
67 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Total. |
71 | - if ( 'total' == $key ) { |
|
72 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
71 | + if ('total' == $key) { |
|
72 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Fires when printing a cart total in an email. |
76 | - do_action( "getpaid_email_cart_totals_$key", $invoice ); |
|
76 | + do_action("getpaid_email_cart_totals_$key", $invoice); |
|
77 | 77 | |
78 | 78 | ?> |
79 | 79 | |
@@ -85,4 +85,4 @@ discard block |
||
85 | 85 | |
86 | 86 | <?php |
87 | 87 | |
88 | - do_action( 'getpaid_after_email_line_totals', $invoice, $totals ); |
|
88 | + do_action('getpaid_after_email_line_totals', $invoice, $totals); |
@@ -12,301 +12,301 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
34 | - ); |
|
35 | - |
|
36 | - $payment_form = $submission->get_payment_form(); |
|
37 | - if ( ! empty( $payment_form->invoice ) ) { |
|
38 | - $this->response['invoice'] = $payment_form->invoice->get_id(); |
|
39 | - } |
|
40 | - |
|
41 | - $this->add_totals( $submission ); |
|
42 | - $this->add_texts( $submission ); |
|
43 | - $this->add_items( $submission ); |
|
44 | - $this->add_fees( $submission ); |
|
45 | - $this->add_discounts( $submission ); |
|
46 | - $this->add_taxes( $submission ); |
|
47 | - $this->add_gateways( $submission ); |
|
48 | - $this->add_data( $submission ); |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Adds totals to a response for submission refresh prices. |
|
54 | - * |
|
55 | - * @param GetPaid_Payment_Form_Submission $submission |
|
56 | - */ |
|
57 | - public function add_totals( $submission ) { |
|
58 | - |
|
59 | - $this->response = array_merge( |
|
60 | - $this->response, |
|
61 | - array( |
|
62 | - |
|
63 | - 'totals' => array( |
|
64 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
65 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
66 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
67 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
68 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
69 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
70 | - ), |
|
71 | - |
|
72 | - 'recurring' => array( |
|
73 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
74 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
75 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
76 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
77 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
78 | - ), |
|
79 | - |
|
80 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
81 | - 'currency' => $submission->get_currency(), |
|
82 | - |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Adds texts to a response for submission refresh prices. |
|
90 | - * |
|
91 | - * @param GetPaid_Payment_Form_Submission $submission |
|
92 | - */ |
|
93 | - public function add_texts( $submission ) { |
|
94 | - |
|
95 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
96 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
97 | - |
|
98 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
99 | - |
|
100 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
101 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
102 | - $main_item = reset( $groups ); |
|
103 | - |
|
104 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
105 | - $payable = "$payable / $period"; |
|
106 | - } elseif ( $main_item ) { |
|
107 | - |
|
108 | - $main_item = reset( $main_item ); |
|
109 | - |
|
110 | - // Calculate the next renewal date. |
|
111 | - $_period = $main_item->get_recurring_period( true ); |
|
112 | - $_interval = $main_item->get_recurring_interval(); |
|
113 | - |
|
114 | - // If the subscription item has a trial period... |
|
115 | - if ( $main_item->has_free_trial() ) { |
|
116 | - $_period = $main_item->get_trial_period( true ); |
|
117 | - $_interval = $main_item->get_trial_interval(); |
|
118 | - } |
|
119 | - |
|
120 | - $payable = sprintf( |
|
121 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
122 | - $submission->format_amount( $submission->get_total() ), |
|
123 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
124 | - $period |
|
125 | - ); |
|
126 | - |
|
127 | - $payable .= sprintf( |
|
128 | - '<small class="text-muted form-text">%s</small>', |
|
129 | - sprintf( |
|
130 | - __( 'First renewal on %s', 'invoicing' ), |
|
131 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
132 | - ) |
|
133 | - ); |
|
134 | - |
|
135 | - } else { |
|
136 | - $payable = sprintf( |
|
137 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
138 | - $submission->format_amount( $submission->get_total() ), |
|
139 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
140 | - $period |
|
141 | - ); |
|
142 | - } |
|
143 | -} |
|
34 | + ); |
|
35 | + |
|
36 | + $payment_form = $submission->get_payment_form(); |
|
37 | + if ( ! empty( $payment_form->invoice ) ) { |
|
38 | + $this->response['invoice'] = $payment_form->invoice->get_id(); |
|
39 | + } |
|
40 | + |
|
41 | + $this->add_totals( $submission ); |
|
42 | + $this->add_texts( $submission ); |
|
43 | + $this->add_items( $submission ); |
|
44 | + $this->add_fees( $submission ); |
|
45 | + $this->add_discounts( $submission ); |
|
46 | + $this->add_taxes( $submission ); |
|
47 | + $this->add_gateways( $submission ); |
|
48 | + $this->add_data( $submission ); |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Adds totals to a response for submission refresh prices. |
|
54 | + * |
|
55 | + * @param GetPaid_Payment_Form_Submission $submission |
|
56 | + */ |
|
57 | + public function add_totals( $submission ) { |
|
58 | + |
|
59 | + $this->response = array_merge( |
|
60 | + $this->response, |
|
61 | + array( |
|
62 | + |
|
63 | + 'totals' => array( |
|
64 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
65 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
66 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
67 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
68 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
69 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
70 | + ), |
|
71 | + |
|
72 | + 'recurring' => array( |
|
73 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
74 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
75 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
76 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
77 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
78 | + ), |
|
79 | + |
|
80 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
81 | + 'currency' => $submission->get_currency(), |
|
82 | + |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + } |
|
144 | 87 | |
145 | - $texts = array( |
|
146 | - '.getpaid-checkout-total-payable' => $payable, |
|
147 | - ); |
|
88 | + /** |
|
89 | + * Adds texts to a response for submission refresh prices. |
|
90 | + * |
|
91 | + * @param GetPaid_Payment_Form_Submission $submission |
|
92 | + */ |
|
93 | + public function add_texts( $submission ) { |
|
94 | + |
|
95 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
96 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
97 | + |
|
98 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
99 | + |
|
100 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
101 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
102 | + $main_item = reset( $groups ); |
|
103 | + |
|
104 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
105 | + $payable = "$payable / $period"; |
|
106 | + } elseif ( $main_item ) { |
|
107 | + |
|
108 | + $main_item = reset( $main_item ); |
|
109 | + |
|
110 | + // Calculate the next renewal date. |
|
111 | + $_period = $main_item->get_recurring_period( true ); |
|
112 | + $_interval = $main_item->get_recurring_interval(); |
|
113 | + |
|
114 | + // If the subscription item has a trial period... |
|
115 | + if ( $main_item->has_free_trial() ) { |
|
116 | + $_period = $main_item->get_trial_period( true ); |
|
117 | + $_interval = $main_item->get_trial_interval(); |
|
118 | + } |
|
119 | + |
|
120 | + $payable = sprintf( |
|
121 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
122 | + $submission->format_amount( $submission->get_total() ), |
|
123 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
124 | + $period |
|
125 | + ); |
|
126 | + |
|
127 | + $payable .= sprintf( |
|
128 | + '<small class="text-muted form-text">%s</small>', |
|
129 | + sprintf( |
|
130 | + __( 'First renewal on %s', 'invoicing' ), |
|
131 | + getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
132 | + ) |
|
133 | + ); |
|
134 | + |
|
135 | + } else { |
|
136 | + $payable = sprintf( |
|
137 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
138 | + $submission->format_amount( $submission->get_total() ), |
|
139 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
140 | + $period |
|
141 | + ); |
|
142 | + } |
|
143 | +} |
|
148 | 144 | |
149 | - foreach ( $submission->get_items() as $item ) { |
|
150 | - $item_id = $item->get_id(); |
|
151 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
152 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
153 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
154 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
145 | + $texts = array( |
|
146 | + '.getpaid-checkout-total-payable' => $payable, |
|
147 | + ); |
|
155 | 148 | |
156 | - if ( $item->get_quantity() == 1 ) { |
|
157 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
158 | - } |
|
149 | + foreach ( $submission->get_items() as $item ) { |
|
150 | + $item_id = $item->get_id(); |
|
151 | + $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
152 | + $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
153 | + $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
154 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
155 | + |
|
156 | + if ( $item->get_quantity() == 1 ) { |
|
157 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | |
161 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
161 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
162 | 162 | |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Adds items to a response for submission refresh prices. |
|
167 | - * |
|
168 | - * @param GetPaid_Payment_Form_Submission $submission |
|
169 | - */ |
|
170 | - public function add_items( $submission ) { |
|
165 | + /** |
|
166 | + * Adds items to a response for submission refresh prices. |
|
167 | + * |
|
168 | + * @param GetPaid_Payment_Form_Submission $submission |
|
169 | + */ |
|
170 | + public function add_items( $submission ) { |
|
171 | 171 | |
172 | - // Add items. |
|
173 | - $items = array(); |
|
174 | - $selected_items = array(); |
|
172 | + // Add items. |
|
173 | + $items = array(); |
|
174 | + $selected_items = array(); |
|
175 | 175 | |
176 | 176 | foreach ( $submission->get_items() as $item ) { |
177 | - $item_id = $item->get_id(); |
|
178 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
179 | - |
|
180 | - $selected_items[ "$item_id" ] = array( |
|
181 | - 'quantity' => $item->get_quantity(), |
|
182 | - 'price' => $item->get_price(), |
|
183 | - 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - $this->response = array_merge( |
|
188 | - $this->response, |
|
189 | - array( |
|
190 | - 'items' => $items, |
|
191 | - 'selected_items' => $selected_items, |
|
192 | - ) |
|
193 | - ); |
|
194 | - |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Adds fees to a response for submission refresh prices. |
|
199 | - * |
|
200 | - * @param GetPaid_Payment_Form_Submission $submission |
|
201 | - */ |
|
202 | - public function add_fees( $submission ) { |
|
203 | - |
|
204 | - $fees = array(); |
|
177 | + $item_id = $item->get_id(); |
|
178 | + $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
179 | + |
|
180 | + $selected_items[ "$item_id" ] = array( |
|
181 | + 'quantity' => $item->get_quantity(), |
|
182 | + 'price' => $item->get_price(), |
|
183 | + 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + $this->response = array_merge( |
|
188 | + $this->response, |
|
189 | + array( |
|
190 | + 'items' => $items, |
|
191 | + 'selected_items' => $selected_items, |
|
192 | + ) |
|
193 | + ); |
|
194 | + |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Adds fees to a response for submission refresh prices. |
|
199 | + * |
|
200 | + * @param GetPaid_Payment_Form_Submission $submission |
|
201 | + */ |
|
202 | + public function add_fees( $submission ) { |
|
203 | + |
|
204 | + $fees = array(); |
|
205 | 205 | |
206 | 206 | foreach ( $submission->get_fees() as $name => $data ) { |
207 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
208 | - } |
|
207 | + $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
208 | + } |
|
209 | 209 | |
210 | - $this->response = array_merge( |
|
211 | - $this->response, |
|
212 | - array( 'fees' => $fees ) |
|
213 | - ); |
|
210 | + $this->response = array_merge( |
|
211 | + $this->response, |
|
212 | + array( 'fees' => $fees ) |
|
213 | + ); |
|
214 | 214 | |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * Adds discounts to a response for submission refresh prices. |
|
219 | - * |
|
220 | - * @param GetPaid_Payment_Form_Submission $submission |
|
221 | - */ |
|
222 | - public function add_discounts( $submission ) { |
|
217 | + /** |
|
218 | + * Adds discounts to a response for submission refresh prices. |
|
219 | + * |
|
220 | + * @param GetPaid_Payment_Form_Submission $submission |
|
221 | + */ |
|
222 | + public function add_discounts( $submission ) { |
|
223 | 223 | |
224 | - $discounts = array(); |
|
224 | + $discounts = array(); |
|
225 | 225 | |
226 | 226 | foreach ( $submission->get_discounts() as $name => $data ) { |
227 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
228 | - } |
|
229 | - |
|
230 | - $this->response = array_merge( |
|
231 | - $this->response, |
|
232 | - array( 'discounts' => $discounts ) |
|
233 | - ); |
|
227 | + $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
228 | + } |
|
234 | 229 | |
235 | - } |
|
230 | + $this->response = array_merge( |
|
231 | + $this->response, |
|
232 | + array( 'discounts' => $discounts ) |
|
233 | + ); |
|
236 | 234 | |
237 | - /** |
|
238 | - * Adds taxes to a response for submission refresh prices. |
|
239 | - * |
|
240 | - * @param GetPaid_Payment_Form_Submission $submission |
|
241 | - */ |
|
242 | - public function add_taxes( $submission ) { |
|
235 | + } |
|
243 | 236 | |
244 | - $taxes = array(); |
|
245 | - $markup = ''; |
|
237 | + /** |
|
238 | + * Adds taxes to a response for submission refresh prices. |
|
239 | + * |
|
240 | + * @param GetPaid_Payment_Form_Submission $submission |
|
241 | + */ |
|
242 | + public function add_taxes( $submission ) { |
|
243 | + |
|
244 | + $taxes = array(); |
|
245 | + $markup = ''; |
|
246 | 246 | foreach ( $submission->get_taxes() as $name => $data ) { |
247 | - $name = sanitize_text_field( $name ); |
|
248 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
249 | - $taxes[ $name ] = $amount; |
|
250 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
251 | - } |
|
252 | - |
|
253 | - $this->response = array_merge( |
|
254 | - $this->response, |
|
255 | - array( 'taxes' => $taxes ) |
|
256 | - ); |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Adds gateways to a response for submission refresh prices. |
|
262 | - * |
|
263 | - * @param GetPaid_Payment_Form_Submission $submission |
|
264 | - */ |
|
265 | - public function add_gateways( $submission ) { |
|
266 | - |
|
267 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
268 | - |
|
269 | - if ( $this->response['has_recurring'] ) { |
|
270 | - |
|
271 | - foreach ( $gateways as $i => $gateway ) { |
|
272 | - |
|
273 | - if ( |
|
274 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
275 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
276 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
277 | - unset( $gateways[ $i ] ); |
|
278 | - } |
|
247 | + $name = sanitize_text_field( $name ); |
|
248 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
249 | + $taxes[ $name ] = $amount; |
|
250 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
251 | + } |
|
252 | + |
|
253 | + $this->response = array_merge( |
|
254 | + $this->response, |
|
255 | + array( 'taxes' => $taxes ) |
|
256 | + ); |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Adds gateways to a response for submission refresh prices. |
|
262 | + * |
|
263 | + * @param GetPaid_Payment_Form_Submission $submission |
|
264 | + */ |
|
265 | + public function add_gateways( $submission ) { |
|
266 | + |
|
267 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
268 | + |
|
269 | + if ( $this->response['has_recurring'] ) { |
|
270 | + |
|
271 | + foreach ( $gateways as $i => $gateway ) { |
|
272 | + |
|
273 | + if ( |
|
274 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
275 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
276 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
277 | + unset( $gateways[ $i ] ); |
|
278 | + } |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
283 | - $this->response = array_merge( |
|
284 | - $this->response, |
|
285 | - array( 'gateways' => $gateways ) |
|
286 | - ); |
|
287 | - |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Adds data to a response for submission refresh prices. |
|
292 | - * |
|
293 | - * @param GetPaid_Payment_Form_Submission $submission |
|
294 | - */ |
|
295 | - public function add_data( $submission ) { |
|
296 | - |
|
297 | - $this->response = array_merge( |
|
298 | - $this->response, |
|
299 | - array( |
|
300 | - 'js_data' => apply_filters( |
|
301 | - 'getpaid_submission_js_data', |
|
302 | - array( |
|
303 | - 'is_recurring' => $this->response['has_recurring'], |
|
304 | - ), |
|
305 | - $submission |
|
306 | - ), |
|
307 | - ) |
|
308 | - ); |
|
309 | - |
|
310 | - } |
|
282 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
283 | + $this->response = array_merge( |
|
284 | + $this->response, |
|
285 | + array( 'gateways' => $gateways ) |
|
286 | + ); |
|
287 | + |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Adds data to a response for submission refresh prices. |
|
292 | + * |
|
293 | + * @param GetPaid_Payment_Form_Submission $submission |
|
294 | + */ |
|
295 | + public function add_data( $submission ) { |
|
296 | + |
|
297 | + $this->response = array_merge( |
|
298 | + $this->response, |
|
299 | + array( |
|
300 | + 'js_data' => apply_filters( |
|
301 | + 'getpaid_submission_js_data', |
|
302 | + array( |
|
303 | + 'is_recurring' => $this->response['has_recurring'], |
|
304 | + ), |
|
305 | + $submission |
|
306 | + ), |
|
307 | + ) |
|
308 | + ); |
|
309 | + |
|
310 | + } |
|
311 | 311 | |
312 | 312 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission refresh prices class |
@@ -23,29 +23,29 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'has_subscription_group' => $submission->has_subscription_group(), |
32 | 32 | 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
33 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
33 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
34 | 34 | ); |
35 | 35 | |
36 | 36 | $payment_form = $submission->get_payment_form(); |
37 | - if ( ! empty( $payment_form->invoice ) ) { |
|
37 | + if (!empty($payment_form->invoice)) { |
|
38 | 38 | $this->response['invoice'] = $payment_form->invoice->get_id(); |
39 | 39 | } |
40 | 40 | |
41 | - $this->add_totals( $submission ); |
|
42 | - $this->add_texts( $submission ); |
|
43 | - $this->add_items( $submission ); |
|
44 | - $this->add_fees( $submission ); |
|
45 | - $this->add_discounts( $submission ); |
|
46 | - $this->add_taxes( $submission ); |
|
47 | - $this->add_gateways( $submission ); |
|
48 | - $this->add_data( $submission ); |
|
41 | + $this->add_totals($submission); |
|
42 | + $this->add_texts($submission); |
|
43 | + $this->add_items($submission); |
|
44 | + $this->add_fees($submission); |
|
45 | + $this->add_discounts($submission); |
|
46 | + $this->add_taxes($submission); |
|
47 | + $this->add_gateways($submission); |
|
48 | + $this->add_data($submission); |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | |
@@ -54,30 +54,30 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @param GetPaid_Payment_Form_Submission $submission |
56 | 56 | */ |
57 | - public function add_totals( $submission ) { |
|
57 | + public function add_totals($submission) { |
|
58 | 58 | |
59 | 59 | $this->response = array_merge( |
60 | 60 | $this->response, |
61 | 61 | array( |
62 | 62 | |
63 | 63 | 'totals' => array( |
64 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
65 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
66 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
67 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
68 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
69 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
64 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
65 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
66 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
67 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
68 | + 'total' => $submission->format_amount($submission->get_total()), |
|
69 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
70 | 70 | ), |
71 | 71 | |
72 | 72 | 'recurring' => array( |
73 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
74 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
75 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
76 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
77 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
74 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
75 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
76 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
77 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
78 | 78 | ), |
79 | 79 | |
80 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
80 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
81 | 81 | 'currency' => $submission->get_currency(), |
82 | 82 | |
83 | 83 | ) |
@@ -90,53 +90,53 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @param GetPaid_Payment_Form_Submission $submission |
92 | 92 | */ |
93 | - public function add_texts( $submission ) { |
|
93 | + public function add_texts($submission) { |
|
94 | 94 | |
95 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
96 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
95 | + $payable = $submission->format_amount($submission->get_total()); |
|
96 | + $groups = getpaid_get_subscription_groups($submission); |
|
97 | 97 | |
98 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
98 | + if ($submission->has_recurring && 2 > count($groups)) { |
|
99 | 99 | |
100 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
101 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
102 | - $main_item = reset( $groups ); |
|
100 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
101 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
102 | + $main_item = reset($groups); |
|
103 | 103 | |
104 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
104 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
105 | 105 | $payable = "$payable / $period"; |
106 | - } elseif ( $main_item ) { |
|
106 | + } elseif ($main_item) { |
|
107 | 107 | |
108 | - $main_item = reset( $main_item ); |
|
108 | + $main_item = reset($main_item); |
|
109 | 109 | |
110 | 110 | // Calculate the next renewal date. |
111 | - $_period = $main_item->get_recurring_period( true ); |
|
111 | + $_period = $main_item->get_recurring_period(true); |
|
112 | 112 | $_interval = $main_item->get_recurring_interval(); |
113 | 113 | |
114 | 114 | // If the subscription item has a trial period... |
115 | - if ( $main_item->has_free_trial() ) { |
|
116 | - $_period = $main_item->get_trial_period( true ); |
|
115 | + if ($main_item->has_free_trial()) { |
|
116 | + $_period = $main_item->get_trial_period(true); |
|
117 | 117 | $_interval = $main_item->get_trial_interval(); |
118 | 118 | } |
119 | 119 | |
120 | 120 | $payable = sprintf( |
121 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
122 | - $submission->format_amount( $submission->get_total() ), |
|
123 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
121 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
122 | + $submission->format_amount($submission->get_total()), |
|
123 | + $submission->format_amount($submission->get_recurring_total()), |
|
124 | 124 | $period |
125 | 125 | ); |
126 | 126 | |
127 | 127 | $payable .= sprintf( |
128 | 128 | '<small class="text-muted form-text">%s</small>', |
129 | 129 | sprintf( |
130 | - __( 'First renewal on %s', 'invoicing' ), |
|
131 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
130 | + __('First renewal on %s', 'invoicing'), |
|
131 | + getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp')))) |
|
132 | 132 | ) |
133 | 133 | ); |
134 | 134 | |
135 | 135 | } else { |
136 | 136 | $payable = sprintf( |
137 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
138 | - $submission->format_amount( $submission->get_total() ), |
|
139 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
137 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
138 | + $submission->format_amount($submission->get_total()), |
|
139 | + $submission->format_amount($submission->get_recurring_total()), |
|
140 | 140 | $period |
141 | 141 | ); |
142 | 142 | } |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | '.getpaid-checkout-total-payable' => $payable, |
147 | 147 | ); |
148 | 148 | |
149 | - foreach ( $submission->get_items() as $item ) { |
|
149 | + foreach ($submission->get_items() as $item) { |
|
150 | 150 | $item_id = $item->get_id(); |
151 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
152 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
153 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
154 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
151 | + $initial_price = $submission->format_amount($item->get_sub_total() - $item->item_discount); |
|
152 | + $recurring_price = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount); |
|
153 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
154 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total())); |
|
155 | 155 | |
156 | - if ( $item->get_quantity() == 1 ) { |
|
157 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
156 | + if ($item->get_quantity() == 1) { |
|
157 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
161 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
162 | 162 | |
163 | 163 | } |
164 | 164 | |
@@ -167,20 +167,20 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param GetPaid_Payment_Form_Submission $submission |
169 | 169 | */ |
170 | - public function add_items( $submission ) { |
|
170 | + public function add_items($submission) { |
|
171 | 171 | |
172 | 172 | // Add items. |
173 | 173 | $items = array(); |
174 | 174 | $selected_items = array(); |
175 | 175 | |
176 | - foreach ( $submission->get_items() as $item ) { |
|
176 | + foreach ($submission->get_items() as $item) { |
|
177 | 177 | $item_id = $item->get_id(); |
178 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
178 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
179 | 179 | |
180 | - $selected_items[ "$item_id" ] = array( |
|
180 | + $selected_items["$item_id"] = array( |
|
181 | 181 | 'quantity' => $item->get_quantity(), |
182 | 182 | 'price' => $item->get_price(), |
183 | - 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
183 | + 'price_fmt' => $submission->format_amount($item->get_price()), |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @param GetPaid_Payment_Form_Submission $submission |
201 | 201 | */ |
202 | - public function add_fees( $submission ) { |
|
202 | + public function add_fees($submission) { |
|
203 | 203 | |
204 | 204 | $fees = array(); |
205 | 205 | |
206 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
207 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
206 | + foreach ($submission->get_fees() as $name => $data) { |
|
207 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | $this->response = array_merge( |
211 | 211 | $this->response, |
212 | - array( 'fees' => $fees ) |
|
212 | + array('fees' => $fees) |
|
213 | 213 | ); |
214 | 214 | |
215 | 215 | } |
@@ -219,17 +219,17 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @param GetPaid_Payment_Form_Submission $submission |
221 | 221 | */ |
222 | - public function add_discounts( $submission ) { |
|
222 | + public function add_discounts($submission) { |
|
223 | 223 | |
224 | 224 | $discounts = array(); |
225 | 225 | |
226 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
227 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
226 | + foreach ($submission->get_discounts() as $name => $data) { |
|
227 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | $this->response = array_merge( |
231 | 231 | $this->response, |
232 | - array( 'discounts' => $discounts ) |
|
232 | + array('discounts' => $discounts) |
|
233 | 233 | ); |
234 | 234 | |
235 | 235 | } |
@@ -239,20 +239,20 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @param GetPaid_Payment_Form_Submission $submission |
241 | 241 | */ |
242 | - public function add_taxes( $submission ) { |
|
242 | + public function add_taxes($submission) { |
|
243 | 243 | |
244 | 244 | $taxes = array(); |
245 | 245 | $markup = ''; |
246 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
247 | - $name = sanitize_text_field( $name ); |
|
248 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
249 | - $taxes[ $name ] = $amount; |
|
246 | + foreach ($submission->get_taxes() as $name => $data) { |
|
247 | + $name = sanitize_text_field($name); |
|
248 | + $amount = $submission->format_amount($data['initial_tax']); |
|
249 | + $taxes[$name] = $amount; |
|
250 | 250 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
251 | 251 | } |
252 | 252 | |
253 | 253 | $this->response = array_merge( |
254 | 254 | $this->response, |
255 | - array( 'taxes' => $taxes ) |
|
255 | + array('taxes' => $taxes) |
|
256 | 256 | ); |
257 | 257 | |
258 | 258 | } |
@@ -262,27 +262,27 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @param GetPaid_Payment_Form_Submission $submission |
264 | 264 | */ |
265 | - public function add_gateways( $submission ) { |
|
265 | + public function add_gateways($submission) { |
|
266 | 266 | |
267 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
267 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
268 | 268 | |
269 | - if ( $this->response['has_recurring'] ) { |
|
269 | + if ($this->response['has_recurring']) { |
|
270 | 270 | |
271 | - foreach ( $gateways as $i => $gateway ) { |
|
271 | + foreach ($gateways as $i => $gateway) { |
|
272 | 272 | |
273 | 273 | if ( |
274 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
275 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
276 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
277 | - unset( $gateways[ $i ] ); |
|
274 | + !getpaid_payment_gateway_supports($gateway, 'subscription') |
|
275 | + || ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group')) |
|
276 | + || ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) { |
|
277 | + unset($gateways[$i]); |
|
278 | 278 | } |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
282 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
283 | 283 | $this->response = array_merge( |
284 | 284 | $this->response, |
285 | - array( 'gateways' => $gateways ) |
|
285 | + array('gateways' => $gateways) |
|
286 | 286 | ); |
287 | 287 | |
288 | 288 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @param GetPaid_Payment_Form_Submission $submission |
294 | 294 | */ |
295 | - public function add_data( $submission ) { |
|
295 | + public function add_data($submission) { |
|
296 | 296 | |
297 | 297 | $this->response = array_merge( |
298 | 298 | $this->response, |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @var WPInv_Invoice $invoice |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | ?> |
14 | 14 | |
@@ -16,48 +16,48 @@ discard block |
||
16 | 16 | |
17 | 17 | <?php |
18 | 18 | |
19 | - $actions = array(); |
|
19 | + $actions = array(); |
|
20 | 20 | |
21 | 21 | echo sprintf( |
22 | 22 | '<a href="javascript:void(0)" class="btn btn-sm m-1 d-inline-block btn-secondary text-white invoice-action-print d-none d-lg-inline-block" onclick="window.print();">%s</a>', |
23 | 23 | sprintf( |
24 | - esc_html__( 'Print %s', 'invoicing' ), |
|
25 | - esc_html( ucfirst( $invoice->get_invoice_quote_type() ) ) |
|
24 | + esc_html__('Print %s', 'invoicing'), |
|
25 | + esc_html(ucfirst($invoice->get_invoice_quote_type())) |
|
26 | 26 | ) |
27 | 27 | ); |
28 | 28 | |
29 | - if ( is_user_logged_in() ) { |
|
29 | + if (is_user_logged_in()) { |
|
30 | 30 | |
31 | 31 | $actions[] = sprintf( |
32 | 32 | '<a href="%s" class="btn btn-sm btn-secondary text-white m-1 d-inline-block invoice-action-history">%s</a>', |
33 | - esc_url( wpinv_get_history_page_uri( $invoice->get_post_type() ) ), |
|
33 | + esc_url(wpinv_get_history_page_uri($invoice->get_post_type())), |
|
34 | 34 | sprintf( |
35 | - __( '%s History', 'invoicing' ), |
|
36 | - esc_html( ucfirst( $invoice->get_invoice_quote_type() ) ) |
|
35 | + __('%s History', 'invoicing'), |
|
36 | + esc_html(ucfirst($invoice->get_invoice_quote_type())) |
|
37 | 37 | ) |
38 | 38 | ); |
39 | 39 | |
40 | 40 | } |
41 | 41 | |
42 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
42 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
43 | 43 | |
44 | 44 | $actions[] = sprintf( |
45 | 45 | '<a href="%s" class="btn btn-sm btn-secondary text-white m-1 d-inline-block invoice-action-edit">%s</a>', |
46 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
46 | + esc_url(get_edit_post_link($invoice->get_id())), |
|
47 | 47 | sprintf( |
48 | - __( 'Edit %s', 'invoicing' ), |
|
49 | - esc_html( ucfirst( $invoice->get_invoice_quote_type() ) ) |
|
48 | + __('Edit %s', 'invoicing'), |
|
49 | + esc_html(ucfirst($invoice->get_invoice_quote_type())) |
|
50 | 50 | ) |
51 | 51 | ); |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | - $actions = apply_filters( 'getpaid_invoice_header_right_actions_array', $actions, $invoice ); |
|
56 | - echo wp_kses_post( implode( '', $actions ) ); |
|
55 | + $actions = apply_filters('getpaid_invoice_header_right_actions_array', $actions, $invoice); |
|
56 | + echo wp_kses_post(implode('', $actions)); |
|
57 | 57 | |
58 | 58 | ?> |
59 | 59 | |
60 | - <?php do_action( 'wpinv_invoice_display_right_actions', $invoice ); ?> |
|
60 | + <?php do_action('wpinv_invoice_display_right_actions', $invoice); ?> |
|
61 | 61 | </div> |
62 | 62 | |
63 | 63 | <?php |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | <?php |
19 | 19 | |
20 | 20 | // Fires when printing the header. |
21 | - do_action( 'getpaid_invoice_header', $invoice ); |
|
21 | + do_action('getpaid_invoice_header', $invoice); |
|
22 | 22 | |
23 | 23 | // Print the opening wrapper. |
24 | 24 | echo '<div class="container bg-white getpaid-print-no-border border mt-4 mb-4 p-4 position-relative flex-grow-1">'; |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | wpinv_print_errors(); |
28 | 28 | |
29 | 29 | // Fires when printing the invoice details. |
30 | - do_action( 'getpaid_invoice_details', $invoice ); |
|
30 | + do_action('getpaid_invoice_details', $invoice); |
|
31 | 31 | |
32 | 32 | // Fires when printing the invoice line items. |
33 | - do_action( 'getpaid_invoice_line_items', $invoice ); |
|
33 | + do_action('getpaid_invoice_line_items', $invoice); |
|
34 | 34 | |
35 | 35 | // Print the closing wrapper. |
36 | 36 | echo '</div>'; |
37 | 37 | |
38 | 38 | // Fires when printing the invoice footer. |
39 | - do_action( 'getpaid_invoice_footer', $invoice ); |
|
39 | + do_action('getpaid_invoice_footer', $invoice); |
|
40 | 40 | |
41 | 41 | ?> |
42 | 42 |