@@ -14,617 +14,617 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array An array of payment gateways. |
|
| 40 | - */ |
|
| 41 | - public $gateways; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() { |
|
| 47 | - $this->define_constants(); |
|
| 48 | - $this->includes(); |
|
| 49 | - $this->init_hooks(); |
|
| 50 | - $this->set_properties(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets a custom data property. |
|
| 55 | - * |
|
| 56 | - * @param string $prop The prop to set. |
|
| 57 | - * @param mixed $value The value to retrieve. |
|
| 58 | - */ |
|
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets a custom data property. |
|
| 65 | - * |
|
| 66 | - * @param string $prop The prop to set. |
|
| 67 | - * @return mixed The value. |
|
| 68 | - */ |
|
| 69 | - public function get( $prop ) { |
|
| 70 | - |
|
| 71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | - return $this->data[ $prop ]; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return null; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Define class properties. |
|
| 80 | - */ |
|
| 81 | - public function set_properties() { |
|
| 82 | - |
|
| 83 | - // Sessions. |
|
| 84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | - |
|
| 88 | - // Init other objects. |
|
| 89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | - $this->set( 'api', new WPInv_API() ); |
|
| 92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Define plugin constants. |
|
| 106 | - */ |
|
| 107 | - public function define_constants() { |
|
| 108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | - $this->version = WPINV_VERSION; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Hook into actions and filters. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - */ |
|
| 118 | - protected function init_hooks() { |
|
| 119 | - /* Internationalize the text strings used. */ |
|
| 120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | - |
|
| 122 | - // Init the plugin after WordPress inits. |
|
| 123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 130 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | - |
|
| 134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array An array of payment gateways. |
|
| 40 | + */ |
|
| 41 | + public $gateways; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->define_constants(); |
|
| 48 | + $this->includes(); |
|
| 49 | + $this->init_hooks(); |
|
| 50 | + $this->set_properties(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets a custom data property. |
|
| 55 | + * |
|
| 56 | + * @param string $prop The prop to set. |
|
| 57 | + * @param mixed $value The value to retrieve. |
|
| 58 | + */ |
|
| 59 | + public function set( $prop, $value ) { |
|
| 60 | + $this->data[ $prop ] = $value; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets a custom data property. |
|
| 65 | + * |
|
| 66 | + * @param string $prop The prop to set. |
|
| 67 | + * @return mixed The value. |
|
| 68 | + */ |
|
| 69 | + public function get( $prop ) { |
|
| 70 | + |
|
| 71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | + return $this->data[ $prop ]; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return null; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Define class properties. |
|
| 80 | + */ |
|
| 81 | + public function set_properties() { |
|
| 82 | + |
|
| 83 | + // Sessions. |
|
| 84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | + |
|
| 88 | + // Init other objects. |
|
| 89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | + $this->set( 'api', new WPInv_API() ); |
|
| 92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Define plugin constants. |
|
| 106 | + */ |
|
| 107 | + public function define_constants() { |
|
| 108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | + $this->version = WPINV_VERSION; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Hook into actions and filters. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + */ |
|
| 118 | + protected function init_hooks() { |
|
| 119 | + /* Internationalize the text strings used. */ |
|
| 120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | + |
|
| 122 | + // Init the plugin after WordPress inits. |
|
| 123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 130 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | + |
|
| 134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
| 136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | - |
|
| 138 | - // Fires after registering actions. |
|
| 139 | - do_action( 'wpinv_actions', $this ); |
|
| 140 | - do_action( 'getpaid_actions', $this ); |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function plugins_loaded() { |
|
| 145 | - /* Internationalize the text strings used. */ |
|
| 146 | - $this->load_textdomain(); |
|
| 147 | - |
|
| 148 | - do_action( 'wpinv_loaded' ); |
|
| 149 | - |
|
| 150 | - // Fix oxygen page builder conflict |
|
| 151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | - wpinv_oxygen_fix_conflict(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Load Localisation files. |
|
| 158 | - * |
|
| 159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 160 | - * |
|
| 161 | - * Locales found in: |
|
| 162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 164 | - * |
|
| 165 | - * @since 1.0.0 |
|
| 166 | - */ |
|
| 167 | - public function load_textdomain() { |
|
| 168 | - |
|
| 169 | - load_plugin_textdomain( |
|
| 170 | - 'invoicing', |
|
| 171 | - false, |
|
| 172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Include required core files used in admin and on the frontend. |
|
| 179 | - */ |
|
| 180 | - public function includes() { |
|
| 181 | - |
|
| 182 | - // Start with the settings. |
|
| 183 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 184 | - |
|
| 185 | - // Packages/libraries. |
|
| 186 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 187 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 188 | - |
|
| 189 | - // Load functions. |
|
| 190 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 191 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 192 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 193 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 194 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 195 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 197 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 198 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 203 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 204 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 205 | - |
|
| 206 | - // Register autoloader. |
|
| 207 | - try { |
|
| 208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 209 | - } catch ( Exception $e ) { |
|
| 210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 214 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 215 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 216 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 217 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 218 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 219 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 221 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 222 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 224 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 226 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 227 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 228 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 229 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 230 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 231 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 232 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 234 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 235 | - |
|
| 236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | - GetPaid_Post_Types_Admin::init(); |
|
| 238 | - |
|
| 239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 241 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 242 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 243 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 245 | - // load the user class only on the users.php page |
|
| 246 | - global $pagenow; |
|
| 247 | - if ( $pagenow == 'users.php' ) { |
|
| 248 | - new WPInv_Admin_Users(); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // Register cli commands |
|
| 253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Class autoloader |
|
| 262 | - * |
|
| 263 | - * @param string $class_name The name of the class to load. |
|
| 264 | - * @access public |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @return void |
|
| 267 | - */ |
|
| 268 | - public function autoload( $class_name ) { |
|
| 269 | - |
|
| 270 | - // Normalize the class name... |
|
| 271 | - $class_name = strtolower( $class_name ); |
|
| 272 | - |
|
| 273 | - // ... and make sure it is our class. |
|
| 274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // Next, prepare the file name from the class. |
|
| 279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | - |
|
| 281 | - // Base path of the classes. |
|
| 282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | - |
|
| 284 | - // And an array of possible locations in order of importance. |
|
| 285 | - $locations = array( |
|
| 286 | - "$plugin_path/includes", |
|
| 287 | - "$plugin_path/includes/data-stores", |
|
| 288 | - "$plugin_path/includes/gateways", |
|
| 289 | - "$plugin_path/includes/payments", |
|
| 290 | - "$plugin_path/includes/geolocation", |
|
| 291 | - "$plugin_path/includes/reports", |
|
| 292 | - "$plugin_path/includes/api", |
|
| 293 | - "$plugin_path/includes/admin", |
|
| 294 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | - ); |
|
| 296 | - |
|
| 297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | - |
|
| 299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | - include trailingslashit( $location ) . $file_name; |
|
| 301 | - break; |
|
| 302 | - } |
|
| 136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | + |
|
| 138 | + // Fires after registering actions. |
|
| 139 | + do_action( 'wpinv_actions', $this ); |
|
| 140 | + do_action( 'getpaid_actions', $this ); |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function plugins_loaded() { |
|
| 145 | + /* Internationalize the text strings used. */ |
|
| 146 | + $this->load_textdomain(); |
|
| 147 | + |
|
| 148 | + do_action( 'wpinv_loaded' ); |
|
| 149 | + |
|
| 150 | + // Fix oxygen page builder conflict |
|
| 151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | + wpinv_oxygen_fix_conflict(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Load Localisation files. |
|
| 158 | + * |
|
| 159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 160 | + * |
|
| 161 | + * Locales found in: |
|
| 162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 164 | + * |
|
| 165 | + * @since 1.0.0 |
|
| 166 | + */ |
|
| 167 | + public function load_textdomain() { |
|
| 168 | + |
|
| 169 | + load_plugin_textdomain( |
|
| 170 | + 'invoicing', |
|
| 171 | + false, |
|
| 172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Include required core files used in admin and on the frontend. |
|
| 179 | + */ |
|
| 180 | + public function includes() { |
|
| 181 | + |
|
| 182 | + // Start with the settings. |
|
| 183 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 184 | + |
|
| 185 | + // Packages/libraries. |
|
| 186 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 187 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 188 | + |
|
| 189 | + // Load functions. |
|
| 190 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 191 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 192 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 193 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 194 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 195 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 197 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 198 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 203 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 204 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 205 | + |
|
| 206 | + // Register autoloader. |
|
| 207 | + try { |
|
| 208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 209 | + } catch ( Exception $e ) { |
|
| 210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 214 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 215 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 216 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 217 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 218 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 219 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 221 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 222 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 224 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 226 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 227 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 228 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 229 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 230 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 231 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 232 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 234 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 235 | + |
|
| 236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | + GetPaid_Post_Types_Admin::init(); |
|
| 238 | + |
|
| 239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 241 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 242 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 243 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 245 | + // load the user class only on the users.php page |
|
| 246 | + global $pagenow; |
|
| 247 | + if ( $pagenow == 'users.php' ) { |
|
| 248 | + new WPInv_Admin_Users(); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // Register cli commands |
|
| 253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Class autoloader |
|
| 262 | + * |
|
| 263 | + * @param string $class_name The name of the class to load. |
|
| 264 | + * @access public |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @return void |
|
| 267 | + */ |
|
| 268 | + public function autoload( $class_name ) { |
|
| 269 | + |
|
| 270 | + // Normalize the class name... |
|
| 271 | + $class_name = strtolower( $class_name ); |
|
| 272 | + |
|
| 273 | + // ... and make sure it is our class. |
|
| 274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // Next, prepare the file name from the class. |
|
| 279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | + |
|
| 281 | + // Base path of the classes. |
|
| 282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | + |
|
| 284 | + // And an array of possible locations in order of importance. |
|
| 285 | + $locations = array( |
|
| 286 | + "$plugin_path/includes", |
|
| 287 | + "$plugin_path/includes/data-stores", |
|
| 288 | + "$plugin_path/includes/gateways", |
|
| 289 | + "$plugin_path/includes/payments", |
|
| 290 | + "$plugin_path/includes/geolocation", |
|
| 291 | + "$plugin_path/includes/reports", |
|
| 292 | + "$plugin_path/includes/api", |
|
| 293 | + "$plugin_path/includes/admin", |
|
| 294 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | + ); |
|
| 296 | + |
|
| 297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | + |
|
| 299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | + include trailingslashit( $location ) . $file_name; |
|
| 301 | + break; |
|
| 302 | + } |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Inits hooks etc. |
|
| 309 | - */ |
|
| 310 | - public function init() { |
|
| 311 | - |
|
| 312 | - // Fires before getpaid inits. |
|
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 314 | - |
|
| 315 | - // Maybe upgrade. |
|
| 316 | - $this->maybe_upgrade_database(); |
|
| 317 | - |
|
| 318 | - // Load default gateways. |
|
| 319 | - $gateways = apply_filters( |
|
| 320 | - 'getpaid_default_gateways', |
|
| 321 | - array( |
|
| 322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - |
|
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | - GetPaid_Installer::rename_gateways_label(); |
|
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Fires after getpaid inits. |
|
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 341 | - |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Checks if this is an IPN request and processes it. |
|
| 346 | - */ |
|
| 347 | - public function maybe_process_ipn() { |
|
| 348 | - |
|
| 349 | - // Ensure that this is an IPN request. |
|
| 350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 351 | - return; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 355 | - |
|
| 356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 358 | - exit; |
|
| 359 | - |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - public function enqueue_scripts() { |
|
| 363 | - |
|
| 364 | - // Fires before adding scripts. |
|
| 365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 366 | - |
|
| 367 | - $localize = array(); |
|
| 368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 377 | - |
|
| 378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 379 | - |
|
| 380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - public function wpinv_actions() { |
|
| 386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 391 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Inits hooks etc. |
|
| 309 | + */ |
|
| 310 | + public function init() { |
|
| 311 | + |
|
| 312 | + // Fires before getpaid inits. |
|
| 313 | + do_action( 'before_getpaid_init', $this ); |
|
| 314 | + |
|
| 315 | + // Maybe upgrade. |
|
| 316 | + $this->maybe_upgrade_database(); |
|
| 317 | + |
|
| 318 | + // Load default gateways. |
|
| 319 | + $gateways = apply_filters( |
|
| 320 | + 'getpaid_default_gateways', |
|
| 321 | + array( |
|
| 322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + |
|
| 330 | + foreach ( $gateways as $id => $class ) { |
|
| 331 | + $this->gateways[ $id ] = new $class(); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | + GetPaid_Installer::rename_gateways_label(); |
|
| 336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Fires after getpaid inits. |
|
| 340 | + do_action( 'getpaid_init', $this ); |
|
| 341 | + |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Checks if this is an IPN request and processes it. |
|
| 346 | + */ |
|
| 347 | + public function maybe_process_ipn() { |
|
| 348 | + |
|
| 349 | + // Ensure that this is an IPN request. |
|
| 350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 351 | + return; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 355 | + |
|
| 356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 358 | + exit; |
|
| 359 | + |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + public function enqueue_scripts() { |
|
| 363 | + |
|
| 364 | + // Fires before adding scripts. |
|
| 365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 366 | + |
|
| 367 | + $localize = array(); |
|
| 368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 377 | + |
|
| 378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 379 | + |
|
| 380 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 381 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 382 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + public function wpinv_actions() { |
|
| 386 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 387 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 391 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | 396 | * Fires an action after verifying that a user can fire them. |
| 397 | - * |
|
| 398 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 399 | - * current user owns the invoice/subscription. |
|
| 397 | + * |
|
| 398 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 399 | + * current user owns the invoice/subscription. |
|
| 400 | 400 | */ |
| 401 | 401 | public function maybe_do_authenticated_action() { |
| 402 | 402 | |
| 403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 403 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 404 | 404 | |
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 407 | - if ( is_user_logged_in() ) { |
|
| 408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 409 | - } |
|
| 405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | + $data = wp_unslash( $_REQUEST ); |
|
| 407 | + if ( is_user_logged_in() ) { |
|
| 408 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 411 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 412 | 412 | |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - public function pre_get_posts( $wp_query ) { |
|
| 418 | - |
|
| 419 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 420 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $wp_query; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Register widgets |
|
| 428 | - * |
|
| 429 | - */ |
|
| 430 | - public function register_widgets() { |
|
| 431 | - global $pagenow; |
|
| 432 | - |
|
| 433 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 434 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 435 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 436 | - return; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 440 | - |
|
| 441 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 442 | - // don't initiate in these conditions. |
|
| 443 | - } else { |
|
| 444 | - |
|
| 445 | - // Only load allowed widgets. |
|
| 446 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 447 | - $widgets = apply_filters( |
|
| 448 | - 'getpaid_widget_classes', |
|
| 449 | - array( |
|
| 450 | - 'WPInv_Checkout_Widget', |
|
| 451 | - 'WPInv_History_Widget', |
|
| 452 | - 'WPInv_Receipt_Widget', |
|
| 453 | - 'WPInv_Subscriptions_Widget', |
|
| 454 | - 'WPInv_Buy_Item_Widget', |
|
| 455 | - 'WPInv_Messages_Widget', |
|
| 456 | - 'WPInv_GetPaid_Widget', |
|
| 457 | - 'WPInv_Invoice_Widget', |
|
| 458 | - ) |
|
| 459 | - ); |
|
| 460 | - |
|
| 461 | - // For each widget... |
|
| 462 | - foreach ( $widgets as $widget ) { |
|
| 463 | - |
|
| 464 | - // Abort early if it is excluded for this page. |
|
| 465 | - if ( in_array( $widget, $exclude ) ) { |
|
| 466 | - continue; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 470 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 471 | - register_widget( $widget ); |
|
| 472 | - } else { |
|
| 473 | - new $widget(); |
|
| 474 | - } |
|
| 417 | + public function pre_get_posts( $wp_query ) { |
|
| 418 | + |
|
| 419 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 420 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $wp_query; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Register widgets |
|
| 428 | + * |
|
| 429 | + */ |
|
| 430 | + public function register_widgets() { |
|
| 431 | + global $pagenow; |
|
| 432 | + |
|
| 433 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 434 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 435 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 436 | + return; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 440 | + |
|
| 441 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 442 | + // don't initiate in these conditions. |
|
| 443 | + } else { |
|
| 444 | + |
|
| 445 | + // Only load allowed widgets. |
|
| 446 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 447 | + $widgets = apply_filters( |
|
| 448 | + 'getpaid_widget_classes', |
|
| 449 | + array( |
|
| 450 | + 'WPInv_Checkout_Widget', |
|
| 451 | + 'WPInv_History_Widget', |
|
| 452 | + 'WPInv_Receipt_Widget', |
|
| 453 | + 'WPInv_Subscriptions_Widget', |
|
| 454 | + 'WPInv_Buy_Item_Widget', |
|
| 455 | + 'WPInv_Messages_Widget', |
|
| 456 | + 'WPInv_GetPaid_Widget', |
|
| 457 | + 'WPInv_Invoice_Widget', |
|
| 458 | + ) |
|
| 459 | + ); |
|
| 460 | + |
|
| 461 | + // For each widget... |
|
| 462 | + foreach ( $widgets as $widget ) { |
|
| 463 | + |
|
| 464 | + // Abort early if it is excluded for this page. |
|
| 465 | + if ( in_array( $widget, $exclude ) ) { |
|
| 466 | + continue; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 470 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 471 | + register_widget( $widget ); |
|
| 472 | + } else { |
|
| 473 | + new $widget(); |
|
| 474 | + } |
|
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - } |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - /** |
|
| 481 | - * Upgrades the database. |
|
| 482 | - * |
|
| 483 | - * @since 2.0.2 |
|
| 484 | - */ |
|
| 485 | - public function maybe_upgrade_database() { |
|
| 480 | + /** |
|
| 481 | + * Upgrades the database. |
|
| 482 | + * |
|
| 483 | + * @since 2.0.2 |
|
| 484 | + */ |
|
| 485 | + public function maybe_upgrade_database() { |
|
| 486 | 486 | |
| 487 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 487 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 488 | 488 | |
| 489 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 490 | - return; |
|
| 491 | - } |
|
| 489 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 490 | + return; |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | - $installer = new GetPaid_Installer(); |
|
| 493 | + $installer = new GetPaid_Installer(); |
|
| 494 | 494 | |
| 495 | - if ( empty( $wpi_version ) ) { |
|
| 496 | - return $installer->upgrade_db( 0 ); |
|
| 497 | - } |
|
| 495 | + if ( empty( $wpi_version ) ) { |
|
| 496 | + return $installer->upgrade_db( 0 ); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - $upgrades = array( |
|
| 500 | - '0.0.5' => '004', |
|
| 501 | - '1.0.3' => '102', |
|
| 502 | - '2.0.0' => '118', |
|
| 503 | - '2.0.8' => '207', |
|
| 504 | - ); |
|
| 499 | + $upgrades = array( |
|
| 500 | + '0.0.5' => '004', |
|
| 501 | + '1.0.3' => '102', |
|
| 502 | + '2.0.0' => '118', |
|
| 503 | + '2.0.8' => '207', |
|
| 504 | + ); |
|
| 505 | 505 | |
| 506 | - foreach ( $upgrades as $key => $method ) { |
|
| 506 | + foreach ( $upgrades as $key => $method ) { |
|
| 507 | 507 | |
| 508 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 509 | - return $installer->upgrade_db( $method ); |
|
| 510 | - } |
|
| 508 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 509 | + return $installer->upgrade_db( $method ); |
|
| 510 | + } |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Flushes the permalinks if needed. |
|
| 517 | - * |
|
| 518 | - * @since 2.0.8 |
|
| 519 | - */ |
|
| 520 | - public function maybe_flush_permalinks() { |
|
| 521 | - |
|
| 522 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 523 | - |
|
| 524 | - if ( ! empty( $flush ) ) { |
|
| 525 | - flush_rewrite_rules(); |
|
| 526 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Remove our pages from yoast sitemaps. |
|
| 533 | - * |
|
| 534 | - * @since 1.0.19 |
|
| 535 | - * @param int[] $excluded_posts_ids |
|
| 536 | - */ |
|
| 537 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 538 | - |
|
| 539 | - // Ensure that we have an array. |
|
| 540 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 541 | - $excluded_posts_ids = array(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Prepare our pages. |
|
| 545 | - $our_pages = array(); |
|
| 546 | - |
|
| 547 | - // Checkout page. |
|
| 548 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 549 | - |
|
| 550 | - // Success page. |
|
| 551 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 552 | - |
|
| 553 | - // Failure page. |
|
| 554 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 555 | - |
|
| 556 | - // History page. |
|
| 557 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 558 | - |
|
| 559 | - // Subscriptions page. |
|
| 560 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 561 | - |
|
| 562 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 563 | - |
|
| 564 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 565 | - return array_unique( $excluded_posts_ids ); |
|
| 566 | - |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Displays additional footer code. |
|
| 571 | - * |
|
| 572 | - * @since 2.0.0 |
|
| 573 | - */ |
|
| 574 | - public function wp_footer() { |
|
| 575 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Displays additional header code. |
|
| 580 | - * |
|
| 581 | - * @since 2.0.0 |
|
| 582 | - */ |
|
| 583 | - public function wp_head() { |
|
| 584 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Custom query vars. |
|
| 589 | - * |
|
| 590 | - */ |
|
| 591 | - public function custom_query_vars( $vars ) { |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Flushes the permalinks if needed. |
|
| 517 | + * |
|
| 518 | + * @since 2.0.8 |
|
| 519 | + */ |
|
| 520 | + public function maybe_flush_permalinks() { |
|
| 521 | + |
|
| 522 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 523 | + |
|
| 524 | + if ( ! empty( $flush ) ) { |
|
| 525 | + flush_rewrite_rules(); |
|
| 526 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Remove our pages from yoast sitemaps. |
|
| 533 | + * |
|
| 534 | + * @since 1.0.19 |
|
| 535 | + * @param int[] $excluded_posts_ids |
|
| 536 | + */ |
|
| 537 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 538 | + |
|
| 539 | + // Ensure that we have an array. |
|
| 540 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 541 | + $excluded_posts_ids = array(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Prepare our pages. |
|
| 545 | + $our_pages = array(); |
|
| 546 | + |
|
| 547 | + // Checkout page. |
|
| 548 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 549 | + |
|
| 550 | + // Success page. |
|
| 551 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 552 | + |
|
| 553 | + // Failure page. |
|
| 554 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 555 | + |
|
| 556 | + // History page. |
|
| 557 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 558 | + |
|
| 559 | + // Subscriptions page. |
|
| 560 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 561 | + |
|
| 562 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 563 | + |
|
| 564 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 565 | + return array_unique( $excluded_posts_ids ); |
|
| 566 | + |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Displays additional footer code. |
|
| 571 | + * |
|
| 572 | + * @since 2.0.0 |
|
| 573 | + */ |
|
| 574 | + public function wp_footer() { |
|
| 575 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Displays additional header code. |
|
| 580 | + * |
|
| 581 | + * @since 2.0.0 |
|
| 582 | + */ |
|
| 583 | + public function wp_head() { |
|
| 584 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Custom query vars. |
|
| 589 | + * |
|
| 590 | + */ |
|
| 591 | + public function custom_query_vars( $vars ) { |
|
| 592 | 592 | $vars[] = 'getpaid-ipn'; |
| 593 | 593 | return $vars; |
| 594 | - } |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - /** |
|
| 597 | - * Add rewrite tags and rules. |
|
| 598 | - * |
|
| 599 | - */ |
|
| 600 | - public function add_rewrite_rule() { |
|
| 596 | + /** |
|
| 597 | + * Add rewrite tags and rules. |
|
| 598 | + * |
|
| 599 | + */ |
|
| 600 | + public function add_rewrite_rule() { |
|
| 601 | 601 | $tag = 'getpaid-ipn'; |
| 602 | 602 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
| 603 | 603 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
| 604 | - } |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * Processes non-query string ipns. |
|
| 608 | - * |
|
| 609 | - */ |
|
| 610 | - public function maybe_process_new_ipn( $query ) { |
|
| 606 | + /** |
|
| 607 | + * Processes non-query string ipns. |
|
| 608 | + * |
|
| 609 | + */ |
|
| 610 | + public function maybe_process_new_ipn( $query ) { |
|
| 611 | 611 | |
| 612 | 612 | if ( is_admin() || ! $query->is_main_query() ) { |
| 613 | 613 | return; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 616 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 617 | 617 | |
| 618 | 618 | if ( ! empty( $gateway ) ) { |
| 619 | 619 | |
| 620 | - $gateway = sanitize_text_field( $gateway ); |
|
| 621 | - nocache_headers(); |
|
| 622 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 623 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 624 | - exit; |
|
| 620 | + $gateway = sanitize_text_field( $gateway ); |
|
| 621 | + nocache_headers(); |
|
| 622 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 623 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 624 | + exit; |
|
| 625 | 625 | |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - } |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | 630 | } |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | function wpinv_can_checkout() { |
| 34 | - $can_checkout = true; // Always true for now |
|
| 34 | + $can_checkout = true; // Always true for now |
|
| 35 | 35 | |
| 36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 36 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | function wpinv_get_success_page_uri() { |
| 40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 41 | - $page_id = absint( $page_id ); |
|
| 40 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 41 | + $page_id = absint( $page_id ); |
|
| 42 | 42 | |
| 43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 43 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -51,22 +51,22 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
| 53 | 53 | $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
| 54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
| 55 | - $page_id = absint( $page_id ); |
|
| 56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
| 54 | + $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
| 55 | + $page_id = absint( $page_id ); |
|
| 56 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function wpinv_is_success_page() { |
| 60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 60 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 61 | + $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 62 | 62 | |
| 63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 63 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function wpinv_is_invoice_history_page() { |
| 67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 68 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 67 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 68 | + $ret = $ret ? is_page( $ret ) : false; |
|
| 69 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function wpinv_is_subscriptions_history_page() { |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | function wpinv_send_to_failed_page( $args = null ) { |
| 95 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
| 95 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
| 96 | 96 | |
| 97 | 97 | if ( ! empty( $args ) ) { |
| 98 | 98 | // Check for backward compatibility |
@@ -113,58 +113,58 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | function wpinv_get_checkout_uri( $args = array() ) { |
| 116 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 117 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
| 116 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 117 | + $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
| 118 | 118 | |
| 119 | - if ( ! empty( $args ) ) { |
|
| 120 | - // Check for backward compatibility |
|
| 121 | - if ( is_string( $args ) ) { |
|
| 122 | - $args = str_replace( '?', '', $args ); |
|
| 119 | + if ( ! empty( $args ) ) { |
|
| 120 | + // Check for backward compatibility |
|
| 121 | + if ( is_string( $args ) ) { |
|
| 122 | + $args = str_replace( '?', '', $args ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $args = wp_parse_args( $args ); |
|
| 125 | + $args = wp_parse_args( $args ); |
|
| 126 | 126 | |
| 127 | - $uri = add_query_arg( $args, $uri ); |
|
| 128 | - } |
|
| 127 | + $uri = add_query_arg( $args, $uri ); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 130 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 131 | 131 | |
| 132 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 132 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 133 | 133 | |
| 134 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 135 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 136 | - } |
|
| 134 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 135 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 138 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function wpinv_get_success_page_url( $query_string = null ) { |
| 142 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 143 | - $success_page = get_permalink( $success_page ); |
|
| 142 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 143 | + $success_page = get_permalink( $success_page ); |
|
| 144 | 144 | |
| 145 | - if ( $query_string ) { |
|
| 146 | - $success_page .= $query_string; |
|
| 145 | + if ( $query_string ) { |
|
| 146 | + $success_page .= $query_string; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 149 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
| 153 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 154 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 153 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 154 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 155 | 155 | |
| 156 | - if ( $extras ) { |
|
| 157 | - $uri .= $extras; |
|
| 156 | + if ( $extras ) { |
|
| 157 | + $uri .= $extras; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 160 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function wpinv_is_failed_transaction_page() { |
| 164 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
| 165 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 164 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
| 165 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 166 | 166 | |
| 167 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 167 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -244,36 +244,36 @@ discard block |
||
| 244 | 244 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
| 245 | 245 | |
| 246 | 246 | if ( $require_billing_details ) { |
| 247 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 248 | - $required_fields['first_name'] = array( |
|
| 249 | - 'error_id' => 'invalid_first_name', |
|
| 250 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
| 251 | - ); |
|
| 252 | - } |
|
| 253 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 254 | - $required_fields['address'] = array( |
|
| 255 | - 'error_id' => 'invalid_address', |
|
| 256 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
| 257 | - ); |
|
| 258 | - } |
|
| 259 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 260 | - $required_fields['city'] = array( |
|
| 261 | - 'error_id' => 'invalid_city', |
|
| 262 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 266 | - $required_fields['state'] = array( |
|
| 267 | - 'error_id' => 'invalid_state', |
|
| 268 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 272 | - $required_fields['country'] = array( |
|
| 273 | - 'error_id' => 'invalid_country', |
|
| 274 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
| 275 | - ); |
|
| 276 | - } |
|
| 247 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 248 | + $required_fields['first_name'] = array( |
|
| 249 | + 'error_id' => 'invalid_first_name', |
|
| 250 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
| 251 | + ); |
|
| 252 | + } |
|
| 253 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 254 | + $required_fields['address'] = array( |
|
| 255 | + 'error_id' => 'invalid_address', |
|
| 256 | + 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
| 257 | + ); |
|
| 258 | + } |
|
| 259 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 260 | + $required_fields['city'] = array( |
|
| 261 | + 'error_id' => 'invalid_city', |
|
| 262 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 266 | + $required_fields['state'] = array( |
|
| 267 | + 'error_id' => 'invalid_state', |
|
| 268 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 272 | + $required_fields['country'] = array( |
|
| 273 | + 'error_id' => 'invalid_country', |
|
| 274 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -160,50 +160,50 @@ |
||
| 160 | 160 | */ |
| 161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
| 162 | 162 | |
| 163 | - $initial_discount = 0; |
|
| 164 | - $recurring_discount = 0; |
|
| 163 | + $initial_discount = 0; |
|
| 164 | + $recurring_discount = 0; |
|
| 165 | 165 | |
| 166 | - foreach ( $invoice->get_items() as $item ) { |
|
| 166 | + foreach ( $invoice->get_items() as $item ) { |
|
| 167 | 167 | |
| 168 | - // Abort if it is not valid for this item. |
|
| 169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | - continue; |
|
| 171 | - } |
|
| 168 | + // Abort if it is not valid for this item. |
|
| 169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | + continue; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - // Calculate the initial amount... |
|
| 174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | - $recurring_item_discount = 0; |
|
| 173 | + // Calculate the initial amount... |
|
| 174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | + $recurring_item_discount = 0; |
|
| 176 | 176 | |
| 177 | - // ... and maybe the recurring amount. |
|
| 178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | - } |
|
| 177 | + // ... and maybe the recurring amount. |
|
| 178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - // Discount should not exceed discounted amount. |
|
| 183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
| 182 | + // Discount should not exceed discounted amount. |
|
| 183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
| 184 | 184 | |
| 185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | - } |
|
| 185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | - } |
|
| 189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | + } |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $initial_discount += $item_discount; |
|
| 195 | - $recurring_discount += $recurring_item_discount; |
|
| 196 | - $item->item_discount = $item_discount; |
|
| 197 | - $item->recurring_item_discount = $recurring_item_discount; |
|
| 194 | + $initial_discount += $item_discount; |
|
| 195 | + $recurring_discount += $recurring_item_discount; |
|
| 196 | + $item->item_discount = $item_discount; |
|
| 197 | + $item->recurring_item_discount = $recurring_item_discount; |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return array( |
|
| 202 | - 'name' => 'discount_code', |
|
| 203 | - 'discount_code' => $discount->get_code(), |
|
| 204 | - 'initial_discount' => $initial_discount, |
|
| 205 | - 'recurring_discount' => $recurring_discount, |
|
| 206 | - ); |
|
| 201 | + return array( |
|
| 202 | + 'name' => 'discount_code', |
|
| 203 | + 'discount_code' => $discount->get_code(), |
|
| 204 | + 'initial_discount' => $initial_discount, |
|
| 205 | + 'recurring_discount' => $recurring_discount, |
|
| 206 | + ); |
|
| 207 | 207 | |
| 208 | 208 | } |
| 209 | 209 | |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | - include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 112 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | + include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $message = wpinv_email_style_body( $message ); |
| 190 | 190 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
| 191 | 191 | |
| 192 | - return $mailer->send( |
|
| 192 | + return $mailer->send( |
|
| 193 | 193 | $to, |
| 194 | 194 | $subject, |
| 195 | 195 | $message, |
@@ -12,207 +12,207 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Notes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() { |
|
| 19 | - |
|
| 20 | - // Filter inovice notes. |
|
| 21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | - |
|
| 24 | - // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | - |
|
| 28 | - // Count comments. |
|
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | - |
|
| 31 | - // Fires after notes are loaded. |
|
| 32 | - do_action( 'wpinv_notes_init', $this ); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Filters invoice notes query to only include our notes. |
|
| 37 | - * |
|
| 38 | - * @param WP_Comment_Query $query |
|
| 39 | - */ |
|
| 40 | - public function set_invoice_note_type( $query ) { |
|
| 41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | - |
|
| 43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | - $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | - } else { |
|
| 46 | - |
|
| 47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | - $query->query_vars['type__not_in'] = array(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $query; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Exclude notes from the comments feed. |
|
| 60 | - */ |
|
| 61 | - function wpinv_comment_feed_where( $where ) { |
|
| 62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Delete comments count cache whenever there is |
|
| 67 | - * new comment or the status of a comment changes. Cache |
|
| 68 | - * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | - * is called. |
|
| 70 | - */ |
|
| 71 | - public function delete_comments_count_cache() { |
|
| 72 | - delete_transient( 'getpaid_count_comments' ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Remove invoice notes from wp_count_comments(). |
|
| 77 | - * |
|
| 78 | - * @since 2.2 |
|
| 79 | - * @param object $stats Comment stats. |
|
| 80 | - * @param int $post_id Post ID. |
|
| 81 | - * @return object |
|
| 82 | - */ |
|
| 83 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | - global $wpdb; |
|
| 85 | - |
|
| 86 | - if ( empty( $post_id ) ) { |
|
| 87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | - |
|
| 89 | - if ( ! $stats ) { |
|
| 90 | - $stats = array( |
|
| 91 | - 'total_comments' => 0, |
|
| 92 | - 'all' => 0, |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $count = $wpdb->get_results( |
|
| 96 | - " |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() { |
|
| 19 | + |
|
| 20 | + // Filter inovice notes. |
|
| 21 | + add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | + add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | + |
|
| 24 | + // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | + add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | + add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | + |
|
| 28 | + // Count comments. |
|
| 29 | + add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | + |
|
| 31 | + // Fires after notes are loaded. |
|
| 32 | + do_action( 'wpinv_notes_init', $this ); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Filters invoice notes query to only include our notes. |
|
| 37 | + * |
|
| 38 | + * @param WP_Comment_Query $query |
|
| 39 | + */ |
|
| 40 | + public function set_invoice_note_type( $query ) { |
|
| 41 | + $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | + |
|
| 43 | + if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | + $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | + } else { |
|
| 46 | + |
|
| 47 | + if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | + $query->query_vars['type__not_in'] = array(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | + $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $query; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Exclude notes from the comments feed. |
|
| 60 | + */ |
|
| 61 | + function wpinv_comment_feed_where( $where ) { |
|
| 62 | + return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Delete comments count cache whenever there is |
|
| 67 | + * new comment or the status of a comment changes. Cache |
|
| 68 | + * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | + * is called. |
|
| 70 | + */ |
|
| 71 | + public function delete_comments_count_cache() { |
|
| 72 | + delete_transient( 'getpaid_count_comments' ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Remove invoice notes from wp_count_comments(). |
|
| 77 | + * |
|
| 78 | + * @since 2.2 |
|
| 79 | + * @param object $stats Comment stats. |
|
| 80 | + * @param int $post_id Post ID. |
|
| 81 | + * @return object |
|
| 82 | + */ |
|
| 83 | + public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | + global $wpdb; |
|
| 85 | + |
|
| 86 | + if ( empty( $post_id ) ) { |
|
| 87 | + $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | + |
|
| 89 | + if ( ! $stats ) { |
|
| 90 | + $stats = array( |
|
| 91 | + 'total_comments' => 0, |
|
| 92 | + 'all' => 0, |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $count = $wpdb->get_results( |
|
| 96 | + " |
|
| 97 | 97 | SELECT comment_approved, COUNT(*) AS num_comments |
| 98 | 98 | FROM {$wpdb->comments} |
| 99 | 99 | WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note') |
| 100 | 100 | GROUP BY comment_approved |
| 101 | 101 | ", |
| 102 | - ARRAY_A |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $approved = array( |
|
| 106 | - '0' => 'moderated', |
|
| 107 | - '1' => 'approved', |
|
| 108 | - 'spam' => 'spam', |
|
| 109 | - 'trash' => 'trash', |
|
| 110 | - 'post-trashed' => 'post-trashed', |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - foreach ( (array) $count as $row ) { |
|
| 114 | - // Don't count post-trashed toward totals. |
|
| 115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | - $stats['all'] += $row['num_comments']; |
|
| 117 | - $stats['total_comments'] += $row['num_comments']; |
|
| 118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | - $stats['total_comments'] += $row['num_comments']; |
|
| 120 | - } |
|
| 121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - foreach ( $approved as $key ) { |
|
| 127 | - if ( empty( $stats[ $key ] ) ) { |
|
| 128 | - $stats[ $key ] = 0; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $stats = (object) $stats; |
|
| 133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | - } |
|
| 102 | + ARRAY_A |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $approved = array( |
|
| 106 | + '0' => 'moderated', |
|
| 107 | + '1' => 'approved', |
|
| 108 | + 'spam' => 'spam', |
|
| 109 | + 'trash' => 'trash', |
|
| 110 | + 'post-trashed' => 'post-trashed', |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + foreach ( (array) $count as $row ) { |
|
| 114 | + // Don't count post-trashed toward totals. |
|
| 115 | + if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | + $stats['all'] += $row['num_comments']; |
|
| 117 | + $stats['total_comments'] += $row['num_comments']; |
|
| 118 | + } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | + $stats['total_comments'] += $row['num_comments']; |
|
| 120 | + } |
|
| 121 | + if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | + $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + foreach ( $approved as $key ) { |
|
| 127 | + if ( empty( $stats[ $key ] ) ) { |
|
| 128 | + $stats[ $key ] = 0; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $stats = (object) $stats; |
|
| 133 | + set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return $stats; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an array of invoice notes. |
|
| 142 | - * |
|
| 143 | - * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | - * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | - * @return WP_Comment[] |
|
| 146 | - */ |
|
| 147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | - |
|
| 149 | - // Default comment args. |
|
| 150 | - $args = array( |
|
| 151 | - 'post_id' => $invoice_id, |
|
| 152 | - 'orderby' => 'comment_ID', |
|
| 153 | - 'order' => 'ASC', |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - // Maybe only show customer comments. |
|
| 157 | - if ( $type == 'customer' ) { |
|
| 158 | - $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | - $args['meta_value'] = 1; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | - |
|
| 164 | - return get_comments( $args ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Saves an invoice comment. |
|
| 169 | - * |
|
| 170 | - * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | - * @param string $note The note content. |
|
| 172 | - * @param string $note_author The name of the author of the note. |
|
| 173 | - * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | - * @return int|false The new note's ID on success, false on failure. |
|
| 175 | - */ |
|
| 176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | - |
|
| 178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Insert the comment. |
|
| 182 | - */ |
|
| 183 | - $note_id = wp_insert_comment( |
|
| 184 | - wp_filter_comment( |
|
| 185 | - array( |
|
| 186 | - 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | - 'comment_content' => $note, |
|
| 188 | - 'comment_agent' => 'Invoicing', |
|
| 189 | - 'user_id' => get_current_user_id(), |
|
| 190 | - 'comment_author' => $note_author, |
|
| 191 | - 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | - 'comment_author_email' => $author_email, |
|
| 193 | - 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | - 'comment_type' => 'wpinv_note', |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | - |
|
| 201 | - // Are we notifying the customer? |
|
| 202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | - return $note_id; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | - do_action( |
|
| 137 | + return $stats; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an array of invoice notes. |
|
| 142 | + * |
|
| 143 | + * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | + * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | + * @return WP_Comment[] |
|
| 146 | + */ |
|
| 147 | + public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | + |
|
| 149 | + // Default comment args. |
|
| 150 | + $args = array( |
|
| 151 | + 'post_id' => $invoice_id, |
|
| 152 | + 'orderby' => 'comment_ID', |
|
| 153 | + 'order' => 'ASC', |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + // Maybe only show customer comments. |
|
| 157 | + if ( $type == 'customer' ) { |
|
| 158 | + $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | + $args['meta_value'] = 1; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | + |
|
| 164 | + return get_comments( $args ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Saves an invoice comment. |
|
| 169 | + * |
|
| 170 | + * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | + * @param string $note The note content. |
|
| 172 | + * @param string $note_author The name of the author of the note. |
|
| 173 | + * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | + * @return int|false The new note's ID on success, false on failure. |
|
| 175 | + */ |
|
| 176 | + function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | + |
|
| 178 | + do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Insert the comment. |
|
| 182 | + */ |
|
| 183 | + $note_id = wp_insert_comment( |
|
| 184 | + wp_filter_comment( |
|
| 185 | + array( |
|
| 186 | + 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | + 'comment_content' => $note, |
|
| 188 | + 'comment_agent' => 'Invoicing', |
|
| 189 | + 'user_id' => get_current_user_id(), |
|
| 190 | + 'comment_author' => $note_author, |
|
| 191 | + 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | + 'comment_author_email' => $author_email, |
|
| 193 | + 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | + 'comment_type' => 'wpinv_note', |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | + |
|
| 201 | + // Are we notifying the customer? |
|
| 202 | + if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | + return $note_id; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | + do_action( |
|
| 208 | 208 | 'wpinv_new_customer_note', |
| 209 | 209 | array( |
| 210 | - 'invoice_id' => $invoice->get_id(), |
|
| 211 | - 'user_note' => $note, |
|
| 210 | + 'invoice_id' => $invoice->get_id(), |
|
| 211 | + 'user_note' => $note, |
|
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | - return $note_id; |
|
| 216 | - } |
|
| 214 | + do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | + return $note_id; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | } |
@@ -15,31 +15,31 @@ discard block |
||
| 15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Class constructor. |
|
| 19 | - */ |
|
| 20 | - public function __construct() { |
|
| 18 | + * Class constructor. |
|
| 19 | + */ |
|
| 20 | + public function __construct() { |
|
| 21 | 21 | parent::__construct(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * Returns the API URL. |
|
| 26 | - * |
|
| 27 | - * |
|
| 28 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function get_api_url( $invoice ) { |
|
| 25 | + * Returns the API URL. |
|
| 26 | + * |
|
| 27 | + * |
|
| 28 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function get_api_url( $invoice ) { |
|
| 32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * Communicates with authorize.net |
|
| 37 | - * |
|
| 38 | - * |
|
| 39 | - * @param array $post Data to post. |
|
| 36 | + * Communicates with authorize.net |
|
| 37 | + * |
|
| 38 | + * |
|
| 39 | + * @param array $post Data to post. |
|
| 40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
| 41 | - * @return stdClass|WP_Error |
|
| 42 | - */ |
|
| 41 | + * @return stdClass|WP_Error |
|
| 42 | + */ |
|
| 43 | 43 | public function post( $post, $invoice ) { |
| 44 | 44 | |
| 45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Returns the API authentication params. |
|
| 93 | - * |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function get_auth_params() { |
|
| 92 | + * Returns the API authentication params. |
|
| 93 | + * |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function get_auth_params() { |
|
| 98 | 98 | |
| 99 | 99 | return array( |
| 100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Cancels a subscription remotely |
|
| 108 | - * |
|
| 109 | - * |
|
| 110 | - * @param WPInv_Subscription $subscription Subscription. |
|
| 107 | + * Cancels a subscription remotely |
|
| 108 | + * |
|
| 109 | + * |
|
| 110 | + * @param WPInv_Subscription $subscription Subscription. |
|
| 111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
| 112 | - */ |
|
| 113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
| 112 | + */ |
|
| 113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
| 114 | 114 | |
| 115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
| 116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | - * Processes ipns. |
|
| 130 | - * |
|
| 131 | - * @return void |
|
| 132 | - */ |
|
| 133 | - public function verify_ipn() { |
|
| 129 | + * Processes ipns. |
|
| 130 | + * |
|
| 131 | + * @return void |
|
| 132 | + */ |
|
| 133 | + public function verify_ipn() { |
|
| 134 | 134 | |
| 135 | 135 | $this->maybe_process_old_ipn(); |
| 136 | 136 | |
| 137 | 137 | // Validate the IPN. |
| 138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | - * Validates IPN invoices. |
|
| 179 | - * |
|
| 178 | + * Validates IPN invoices. |
|
| 179 | + * |
|
| 180 | 180 | * @param WPInv_Invoice $invoice |
| 181 | 181 | * @param object $payload |
| 182 | - * @return void |
|
| 183 | - */ |
|
| 184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 182 | + * @return void |
|
| 183 | + */ |
|
| 184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
| 186 | 186 | exit; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | - * Process subscriptio IPNS. |
|
| 192 | - * |
|
| 193 | - * @return void |
|
| 194 | - */ |
|
| 195 | - public function maybe_process_old_ipn() { |
|
| 191 | + * Process subscriptio IPNS. |
|
| 192 | + * |
|
| 193 | + * @return void |
|
| 194 | + */ |
|
| 195 | + public function maybe_process_old_ipn() { |
|
| 196 | 196 | |
| 197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
| 198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Validates the old IPN signature. |
|
| 237 | + * Validates the old IPN signature. |
|
| 238 | 238 | * |
| 239 | 239 | * @param array $posted |
| 240 | - */ |
|
| 241 | - public function validate_old_ipn_signature( $posted ) { |
|
| 240 | + */ |
|
| 241 | + public function validate_old_ipn_signature( $posted ) { |
|
| 242 | 242 | |
| 243 | 243 | $signature = $this->get_option( 'signature_key' ); |
| 244 | 244 | if ( ! empty( $signature ) ) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Check Authorize.NET IPN validity. |
|
| 260 | - */ |
|
| 261 | - public function validate_ipn() { |
|
| 259 | + * Check Authorize.NET IPN validity. |
|
| 260 | + */ |
|
| 261 | + public function validate_ipn() { |
|
| 262 | 262 | |
| 263 | 263 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
| 264 | 264 | |
@@ -13,65 +13,65 @@ discard block |
||
| 13 | 13 | class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'worldpay'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Payment method order. |
|
| 24 | - * |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 23 | + * Payment method order. |
|
| 24 | + * |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | 27 | public $order = 5; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Endpoint for requests from Worldpay. |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $notify_url; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Endpoint for requests to Worldpay. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 30 | + * Endpoint for requests from Worldpay. |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $notify_url; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Endpoint for requests to Worldpay. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | 41 | protected $endpoint; |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * An array of features that this gateway supports. |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 44 | + * An array of features that this gateway supports. |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | 48 | protected $supports = array( 'sandbox' ); |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a subscription. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 65 | + * URL to view a subscription. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Class constructor. |
|
| 73 | - */ |
|
| 74 | - public function __construct() { |
|
| 72 | + * Class constructor. |
|
| 73 | + */ |
|
| 74 | + public function __construct() { |
|
| 75 | 75 | |
| 76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
| 77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | - * Process Payment. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | - * @param array $submission_data Posted checkout fields. |
|
| 93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 88 | + * Process Payment. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | + * @param array $submission_data Posted checkout fields. |
|
| 93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 97 | 97 | |
| 98 | 98 | // Get redirect url. |
| 99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * Get the Worldpay request URL for an invoice. |
|
| 132 | - * |
|
| 133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function get_request_url( $invoice ) { |
|
| 131 | + * Get the Worldpay request URL for an invoice. |
|
| 132 | + * |
|
| 133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function get_request_url( $invoice ) { |
|
| 137 | 137 | |
| 138 | 138 | // Endpoint for this request |
| 139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 140 | 140 | |
| 141 | 141 | return $this->endpoint; |
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Get Worldpay Args for passing to Worldpay. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - protected function get_worldpay_args( $invoice ) { |
|
| 152 | - |
|
| 153 | - return apply_filters( |
|
| 154 | - 'getpaid_worldpay_args', |
|
| 155 | - array( |
|
| 146 | + * Get Worldpay Args for passing to Worldpay. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + protected function get_worldpay_args( $invoice ) { |
|
| 152 | + |
|
| 153 | + return apply_filters( |
|
| 154 | + 'getpaid_worldpay_args', |
|
| 155 | + array( |
|
| 156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
| 157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
| 158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
| 178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
| 179 | 179 | ), |
| 180 | - $invoice |
|
| 181 | - ); |
|
| 180 | + $invoice |
|
| 181 | + ); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * Secures worldpay args with an md5 hash. |
|
| 187 | - * |
|
| 188 | - * @param array $args Gateway args. |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - public function hash_args( $args ) { |
|
| 186 | + * Secures worldpay args with an md5 hash. |
|
| 187 | + * |
|
| 188 | + * @param array $args Gateway args. |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + public function hash_args( $args ) { |
|
| 192 | 192 | |
| 193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
| 194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Processes ipns and marks payments as complete. |
|
| 208 | - * |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function verify_ipn() { |
|
| 207 | + * Processes ipns and marks payments as complete. |
|
| 208 | + * |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function verify_ipn() { |
|
| 212 | 212 | |
| 213 | 213 | // Validate the IPN. |
| 214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | - } |
|
| 215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | // Process the IPN. |
| 219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - // Update the ip address. |
|
| 233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 232 | + // Update the ip address. |
|
| 233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | - * Check Worldpay IPN validity. |
|
| 261 | - */ |
|
| 262 | - public function validate_ipn() { |
|
| 260 | + * Check Worldpay IPN validity. |
|
| 261 | + */ |
|
| 262 | + public function validate_ipn() { |
|
| 263 | 263 | |
| 264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
| 265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * Filters the gateway settings. |
|
| 309 | - * |
|
| 310 | - * @param array $admin_settings |
|
| 311 | - */ |
|
| 312 | - public function admin_settings( $admin_settings ) { |
|
| 308 | + * Filters the gateway settings. |
|
| 309 | + * |
|
| 310 | + * @param array $admin_settings |
|
| 311 | + */ |
|
| 312 | + public function admin_settings( $admin_settings ) { |
|
| 313 | 313 | |
| 314 | 314 | $currencies = sprintf( |
| 315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | 'readonly' => true, |
| 351 | 351 | ); |
| 352 | 352 | |
| 353 | - return $admin_settings; |
|
| 354 | - } |
|
| 353 | + return $admin_settings; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | } |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | $args = wp_parse_args( |
| 58 | 58 | $args, |
| 59 | 59 | array( |
| 60 | - 'status' => array( 'publish' ), |
|
| 61 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | - 'page' => 1, |
|
| 63 | - 'exclude' => array(), |
|
| 64 | - 'orderby' => 'date', |
|
| 65 | - 'order' => 'DESC', |
|
| 66 | - 'type' => wpinv_item_types(), |
|
| 67 | - 'meta_query' => array(), |
|
| 68 | - 'return' => 'objects', |
|
| 69 | - 'paginate' => false, |
|
| 60 | + 'status' => array( 'publish' ), |
|
| 61 | + 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | + 'page' => 1, |
|
| 63 | + 'exclude' => array(), |
|
| 64 | + 'orderby' => 'date', |
|
| 65 | + 'order' => 'DESC', |
|
| 66 | + 'type' => wpinv_item_types(), |
|
| 67 | + 'meta_query' => array(), |
|
| 68 | + 'return' => 'objects', |
|
| 69 | + 'paginate' => false, |
|
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | function wpinv_get_item_types() { |
| 208 | 208 | $item_types = array( |
| 209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 211 | - ); |
|
| 209 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
| 210 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
| 211 | + ); |
|
| 212 | 212 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
| 250 | 250 | if ( $post_ids ) { |
| 251 | 251 | $args = array( |
| 252 | - 'post_type' => 'wpi_item', |
|
| 253 | - 'orderby' => 'rand', |
|
| 254 | - 'post_count' => $num, |
|
| 255 | - 'fields' => 'ids', |
|
| 256 | - ); |
|
| 252 | + 'post_type' => 'wpi_item', |
|
| 253 | + 'orderby' => 'rand', |
|
| 254 | + 'post_count' => $num, |
|
| 255 | + 'fields' => 'ids', |
|
| 256 | + ); |
|
| 257 | 257 | } else { |
| 258 | 258 | $args = array( |
| 259 | - 'post_type' => 'wpi_item', |
|
| 260 | - 'orderby' => 'rand', |
|
| 261 | - 'post_count' => $num, |
|
| 262 | - ); |
|
| 259 | + 'post_type' => 'wpi_item', |
|
| 260 | + 'orderby' => 'rand', |
|
| 261 | + 'post_count' => $num, |
|
| 262 | + ); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $args = apply_filters( 'wpinv_get_random_items', $args ); |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | $bill_times = $item->get_recurring_limit(); |
| 427 | 427 | |
| 428 | 428 | if ( ! empty( $bill_times ) ) { |
| 429 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 430 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 431 | - } |
|
| 429 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 430 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 431 | + } |
|
| 432 | 432 | |
| 433 | 433 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
| 434 | 434 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,199 +10,199 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - 'shipping' => array( |
|
| 54 | - 'initial' => 0, |
|
| 55 | - 'recurring' => 0, |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Sets the associated payment form. |
|
| 62 | - * |
|
| 63 | - * @var GetPaid_Payment_Form |
|
| 64 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + 'shipping' => array( |
|
| 54 | + 'initial' => 0, |
|
| 55 | + 'recurring' => 0, |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Sets the associated payment form. |
|
| 62 | + * |
|
| 63 | + * @var GetPaid_Payment_Form |
|
| 64 | + */ |
|
| 65 | 65 | protected $payment_form = null; |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * The country for the submission. |
|
| 69 | - * |
|
| 70 | - * @var string |
|
| 71 | - */ |
|
| 72 | - public $country = null; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * The state for the submission. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.19 |
|
| 78 | - * @var string |
|
| 79 | - */ |
|
| 80 | - public $state = null; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The invoice associated with the submission. |
|
| 84 | - * |
|
| 85 | - * @var WPInv_Invoice |
|
| 86 | - */ |
|
| 87 | - protected $invoice = null; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The recurring item for the submission. |
|
| 91 | - * |
|
| 92 | - * @var int |
|
| 93 | - */ |
|
| 94 | - public $has_recurring = 0; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * An array of fees for the submission. |
|
| 98 | - * |
|
| 99 | - * @var array |
|
| 100 | - */ |
|
| 101 | - protected $fees = array(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * An array of discounts for the submission. |
|
| 105 | - * |
|
| 106 | - * @var array |
|
| 107 | - */ |
|
| 108 | - protected $discounts = array(); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * An array of taxes for the submission. |
|
| 112 | - * |
|
| 113 | - * @var array |
|
| 114 | - */ |
|
| 115 | - protected $taxes = array(); |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * An array of items for the submission. |
|
| 119 | - * |
|
| 120 | - * @var GetPaid_Form_Item[] |
|
| 121 | - */ |
|
| 122 | - protected $items = array(); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * The last error. |
|
| 126 | - * |
|
| 127 | - * @var string |
|
| 128 | - */ |
|
| 129 | - public $last_error = null; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * The last error code. |
|
| 133 | - * |
|
| 134 | - * @var string |
|
| 135 | - */ |
|
| 136 | - public $last_error_code = null; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Class constructor. |
|
| 140 | - * |
|
| 141 | - */ |
|
| 142 | - public function __construct() { |
|
| 143 | - |
|
| 144 | - // Set the state and country to the default state and country. |
|
| 145 | - $this->country = wpinv_default_billing_country(); |
|
| 146 | - $this->state = wpinv_get_default_state(); |
|
| 147 | - |
|
| 148 | - // Do we have an actual submission? |
|
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Loads submission data. |
|
| 157 | - * |
|
| 158 | - * @param array $data |
|
| 159 | - */ |
|
| 160 | - public function load_data( $data ) { |
|
| 161 | - |
|
| 162 | - // Allow plugins to filter the data. |
|
| 163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 164 | - |
|
| 165 | - // Cache it... |
|
| 166 | - $this->data = $data; |
|
| 167 | - |
|
| 168 | - // Then generate a unique id from the data. |
|
| 169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 170 | - |
|
| 171 | - // Finally, process the submission. |
|
| 172 | - try { |
|
| 173 | - |
|
| 174 | - // Each process is passed an instance of the class (with reference) |
|
| 175 | - // and should throw an Exception whenever it encounters one. |
|
| 176 | - $processors = apply_filters( |
|
| 177 | - 'getpaid_payment_form_submission_processors', |
|
| 178 | - array( |
|
| 179 | - array( $this, 'process_payment_form' ), |
|
| 180 | - array( $this, 'process_invoice' ), |
|
| 181 | - array( $this, 'process_fees' ), |
|
| 182 | - array( $this, 'process_items' ), |
|
| 183 | - array( $this, 'process_discount' ), |
|
| 184 | - array( $this, 'process_taxes' ), |
|
| 185 | - ), |
|
| 186 | - $this |
|
| 187 | - ); |
|
| 188 | - |
|
| 189 | - foreach ( $processors as $processor ) { |
|
| 190 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 191 | - } |
|
| 68 | + * The country for the submission. |
|
| 69 | + * |
|
| 70 | + * @var string |
|
| 71 | + */ |
|
| 72 | + public $country = null; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * The state for the submission. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.19 |
|
| 78 | + * @var string |
|
| 79 | + */ |
|
| 80 | + public $state = null; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The invoice associated with the submission. |
|
| 84 | + * |
|
| 85 | + * @var WPInv_Invoice |
|
| 86 | + */ |
|
| 87 | + protected $invoice = null; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The recurring item for the submission. |
|
| 91 | + * |
|
| 92 | + * @var int |
|
| 93 | + */ |
|
| 94 | + public $has_recurring = 0; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * An array of fees for the submission. |
|
| 98 | + * |
|
| 99 | + * @var array |
|
| 100 | + */ |
|
| 101 | + protected $fees = array(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * An array of discounts for the submission. |
|
| 105 | + * |
|
| 106 | + * @var array |
|
| 107 | + */ |
|
| 108 | + protected $discounts = array(); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * An array of taxes for the submission. |
|
| 112 | + * |
|
| 113 | + * @var array |
|
| 114 | + */ |
|
| 115 | + protected $taxes = array(); |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * An array of items for the submission. |
|
| 119 | + * |
|
| 120 | + * @var GetPaid_Form_Item[] |
|
| 121 | + */ |
|
| 122 | + protected $items = array(); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * The last error. |
|
| 126 | + * |
|
| 127 | + * @var string |
|
| 128 | + */ |
|
| 129 | + public $last_error = null; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * The last error code. |
|
| 133 | + * |
|
| 134 | + * @var string |
|
| 135 | + */ |
|
| 136 | + public $last_error_code = null; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Class constructor. |
|
| 140 | + * |
|
| 141 | + */ |
|
| 142 | + public function __construct() { |
|
| 143 | + |
|
| 144 | + // Set the state and country to the default state and country. |
|
| 145 | + $this->country = wpinv_default_billing_country(); |
|
| 146 | + $this->state = wpinv_get_default_state(); |
|
| 147 | + |
|
| 148 | + // Do we have an actual submission? |
|
| 149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | + $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Loads submission data. |
|
| 157 | + * |
|
| 158 | + * @param array $data |
|
| 159 | + */ |
|
| 160 | + public function load_data( $data ) { |
|
| 161 | + |
|
| 162 | + // Allow plugins to filter the data. |
|
| 163 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 164 | + |
|
| 165 | + // Cache it... |
|
| 166 | + $this->data = $data; |
|
| 167 | + |
|
| 168 | + // Then generate a unique id from the data. |
|
| 169 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 170 | + |
|
| 171 | + // Finally, process the submission. |
|
| 172 | + try { |
|
| 173 | + |
|
| 174 | + // Each process is passed an instance of the class (with reference) |
|
| 175 | + // and should throw an Exception whenever it encounters one. |
|
| 176 | + $processors = apply_filters( |
|
| 177 | + 'getpaid_payment_form_submission_processors', |
|
| 178 | + array( |
|
| 179 | + array( $this, 'process_payment_form' ), |
|
| 180 | + array( $this, 'process_invoice' ), |
|
| 181 | + array( $this, 'process_fees' ), |
|
| 182 | + array( $this, 'process_items' ), |
|
| 183 | + array( $this, 'process_discount' ), |
|
| 184 | + array( $this, 'process_taxes' ), |
|
| 185 | + ), |
|
| 186 | + $this |
|
| 187 | + ); |
|
| 188 | + |
|
| 189 | + foreach ( $processors as $processor ) { |
|
| 190 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 191 | + } |
|
| 192 | 192 | } catch ( GetPaid_Payment_Exception $e ) { |
| 193 | - $this->last_error = $e->getMessage(); |
|
| 194 | - $this->last_error_code = $e->getErrorCode(); |
|
| 195 | - } catch ( Exception $e ) { |
|
| 196 | - $this->last_error = $e->getMessage(); |
|
| 197 | - $this->last_error_code = $e->getCode(); |
|
| 198 | - } |
|
| 193 | + $this->last_error = $e->getMessage(); |
|
| 194 | + $this->last_error_code = $e->getErrorCode(); |
|
| 195 | + } catch ( Exception $e ) { |
|
| 196 | + $this->last_error = $e->getMessage(); |
|
| 197 | + $this->last_error_code = $e->getCode(); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - // Fired when we are done processing a submission. |
|
| 201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 200 | + // Fired when we are done processing a submission. |
|
| 201 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 202 | 202 | |
| 203 | - } |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /* |
|
| 205 | + /* |
|
| 206 | 206 | |-------------------------------------------------------------------------- |
| 207 | 207 | | Payment Forms. |
| 208 | 208 | |-------------------------------------------------------------------------- |
@@ -211,39 +211,39 @@ discard block |
||
| 211 | 211 | | submission has an active payment form etc. |
| 212 | 212 | */ |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Prepares the submission's payment form. |
|
| 216 | - * |
|
| 217 | - * @since 1.0.19 |
|
| 218 | - */ |
|
| 219 | - public function process_payment_form() { |
|
| 214 | + /** |
|
| 215 | + * Prepares the submission's payment form. |
|
| 216 | + * |
|
| 217 | + * @since 1.0.19 |
|
| 218 | + */ |
|
| 219 | + public function process_payment_form() { |
|
| 220 | 220 | |
| 221 | - // Every submission needs an active payment form. |
|
| 222 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 224 | - } |
|
| 221 | + // Every submission needs an active payment form. |
|
| 222 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - // Fetch the payment form. |
|
| 227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 226 | + // Fetch the payment form. |
|
| 227 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 228 | 228 | |
| 229 | - if ( ! $this->payment_form->is_active() ) { |
|
| 230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 231 | - } |
|
| 229 | + if ( ! $this->payment_form->is_active() ) { |
|
| 230 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 234 | - } |
|
| 233 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Returns the payment form. |
|
| 238 | - * |
|
| 239 | - * @since 1.0.19 |
|
| 240 | - * @return GetPaid_Payment_Form |
|
| 241 | - */ |
|
| 242 | - public function get_payment_form() { |
|
| 243 | - return $this->payment_form; |
|
| 244 | - } |
|
| 237 | + * Returns the payment form. |
|
| 238 | + * |
|
| 239 | + * @since 1.0.19 |
|
| 240 | + * @return GetPaid_Payment_Form |
|
| 241 | + */ |
|
| 242 | + public function get_payment_form() { |
|
| 243 | + return $this->payment_form; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /* |
|
| 246 | + /* |
|
| 247 | 247 | |-------------------------------------------------------------------------- |
| 248 | 248 | | Invoices. |
| 249 | 249 | |-------------------------------------------------------------------------- |
@@ -252,84 +252,84 @@ discard block |
||
| 252 | 252 | | might be for an existing invoice. |
| 253 | 253 | */ |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Prepares the submission's invoice. |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - */ |
|
| 260 | - public function process_invoice() { |
|
| 255 | + /** |
|
| 256 | + * Prepares the submission's invoice. |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + */ |
|
| 260 | + public function process_invoice() { |
|
| 261 | 261 | |
| 262 | - // Abort if there is no invoice. |
|
| 263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 264 | - return; |
|
| 265 | - } |
|
| 262 | + // Abort if there is no invoice. |
|
| 263 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 268 | - // and that it is not paid for. |
|
| 269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 267 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 268 | + // and that it is not paid for. |
|
| 269 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 270 | 270 | |
| 271 | 271 | if ( empty( $invoice ) ) { |
| 272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - if ( $invoice->is_paid() ) { |
|
| 276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $this->payment_form->invoice = $invoice; |
|
| 280 | - if ( ! $this->payment_form->is_default() ) { |
|
| 281 | - |
|
| 282 | - $items = array(); |
|
| 283 | - $item_ids = array(); |
|
| 284 | - |
|
| 285 | - foreach ( $invoice->get_items() as $item ) { |
|
| 286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 287 | - $item_ids[] = $item->get_id(); |
|
| 288 | - $items[] = $item; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | - $item_ids[] = $item->get_id(); |
|
| 295 | - $items[] = $item; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->payment_form->set_items( $items ); |
|
| 300 | - |
|
| 301 | - } else { |
|
| 302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $this->country = $invoice->get_country(); |
|
| 306 | - $this->state = $invoice->get_state(); |
|
| 307 | - $this->invoice = $invoice; |
|
| 308 | - |
|
| 309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Returns the associated invoice. |
|
| 314 | - * |
|
| 315 | - * @since 1.0.19 |
|
| 316 | - * @return WPInv_Invoice |
|
| 317 | - */ |
|
| 318 | - public function get_invoice() { |
|
| 319 | - return $this->invoice; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Checks whether there is an invoice associated with this submission. |
|
| 324 | - * |
|
| 325 | - * @since 1.0.19 |
|
| 326 | - * @return bool |
|
| 327 | - */ |
|
| 328 | - public function has_invoice() { |
|
| 329 | - return ! empty( $this->invoice ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /* |
|
| 272 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + if ( $invoice->is_paid() ) { |
|
| 276 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $this->payment_form->invoice = $invoice; |
|
| 280 | + if ( ! $this->payment_form->is_default() ) { |
|
| 281 | + |
|
| 282 | + $items = array(); |
|
| 283 | + $item_ids = array(); |
|
| 284 | + |
|
| 285 | + foreach ( $invoice->get_items() as $item ) { |
|
| 286 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 287 | + $item_ids[] = $item->get_id(); |
|
| 288 | + $items[] = $item; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | + $item_ids[] = $item->get_id(); |
|
| 295 | + $items[] = $item; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->payment_form->set_items( $items ); |
|
| 300 | + |
|
| 301 | + } else { |
|
| 302 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $this->country = $invoice->get_country(); |
|
| 306 | + $this->state = $invoice->get_state(); |
|
| 307 | + $this->invoice = $invoice; |
|
| 308 | + |
|
| 309 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Returns the associated invoice. |
|
| 314 | + * |
|
| 315 | + * @since 1.0.19 |
|
| 316 | + * @return WPInv_Invoice |
|
| 317 | + */ |
|
| 318 | + public function get_invoice() { |
|
| 319 | + return $this->invoice; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Checks whether there is an invoice associated with this submission. |
|
| 324 | + * |
|
| 325 | + * @since 1.0.19 |
|
| 326 | + * @return bool |
|
| 327 | + */ |
|
| 328 | + public function has_invoice() { |
|
| 329 | + return ! empty( $this->invoice ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /* |
|
| 333 | 333 | |-------------------------------------------------------------------------- |
| 334 | 334 | | Items. |
| 335 | 335 | |-------------------------------------------------------------------------- |
@@ -338,129 +338,129 @@ discard block |
||
| 338 | 338 | | recurring item. But can have an unlimited number of non-recurring items. |
| 339 | 339 | */ |
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Prepares the submission's items. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - */ |
|
| 346 | - public function process_items() { |
|
| 347 | - |
|
| 348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 349 | - |
|
| 350 | - foreach ( $processor->items as $item ) { |
|
| 351 | - $this->add_item( $item ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Adds an item to the submission. |
|
| 359 | - * |
|
| 360 | - * @since 1.0.19 |
|
| 361 | - * @param GetPaid_Form_Item $item |
|
| 362 | - */ |
|
| 363 | - public function add_item( $item ) { |
|
| 364 | - |
|
| 365 | - // Make sure that it is available for purchase. |
|
| 366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 367 | - return; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // Each submission can only contain one recurring item. |
|
| 371 | - if ( $item->is_recurring() ) { |
|
| 372 | - $this->has_recurring = $item->get_id(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // Update the items and totals. |
|
| 376 | - $this->items[ $item->get_id() ] = $item; |
|
| 377 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 378 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 379 | - |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Removes a specific item. |
|
| 384 | - * |
|
| 385 | - * You should not call this method after the discounts and taxes |
|
| 386 | - * have been calculated. |
|
| 387 | - * |
|
| 388 | - * @since 1.0.19 |
|
| 389 | - */ |
|
| 390 | - public function remove_item( $item_id ) { |
|
| 391 | - |
|
| 392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 395 | - |
|
| 396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 397 | - $this->has_recurring = 0; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - unset( $this->items[ $item_id ] ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Returns the subtotal. |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - */ |
|
| 410 | - public function get_subtotal() { |
|
| 411 | - |
|
| 412 | - if ( wpinv_prices_include_tax() ) { |
|
| 413 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - return $this->totals['subtotal']['initial']; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Returns the recurring subtotal. |
|
| 421 | - * |
|
| 422 | - * @since 1.0.19 |
|
| 423 | - */ |
|
| 424 | - public function get_recurring_subtotal() { |
|
| 425 | - |
|
| 426 | - if ( wpinv_prices_include_tax() ) { |
|
| 427 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return $this->totals['subtotal']['recurring']; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Returns all items. |
|
| 435 | - * |
|
| 436 | - * @since 1.0.19 |
|
| 437 | - * @return GetPaid_Form_Item[] |
|
| 438 | - */ |
|
| 439 | - public function get_items() { |
|
| 440 | - return $this->items; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Checks if there's a single subscription group in the submission. |
|
| 445 | - * |
|
| 446 | - * @since 2.3.0 |
|
| 447 | - * @return bool |
|
| 448 | - */ |
|
| 449 | - public function has_subscription_group() { |
|
| 450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Checks if there are multipe subscription groups in the submission. |
|
| 455 | - * |
|
| 456 | - * @since 2.3.0 |
|
| 457 | - * @return bool |
|
| 458 | - */ |
|
| 459 | - public function has_multiple_subscription_groups() { |
|
| 460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /* |
|
| 341 | + /** |
|
| 342 | + * Prepares the submission's items. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + */ |
|
| 346 | + public function process_items() { |
|
| 347 | + |
|
| 348 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 349 | + |
|
| 350 | + foreach ( $processor->items as $item ) { |
|
| 351 | + $this->add_item( $item ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Adds an item to the submission. |
|
| 359 | + * |
|
| 360 | + * @since 1.0.19 |
|
| 361 | + * @param GetPaid_Form_Item $item |
|
| 362 | + */ |
|
| 363 | + public function add_item( $item ) { |
|
| 364 | + |
|
| 365 | + // Make sure that it is available for purchase. |
|
| 366 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 367 | + return; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // Each submission can only contain one recurring item. |
|
| 371 | + if ( $item->is_recurring() ) { |
|
| 372 | + $this->has_recurring = $item->get_id(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // Update the items and totals. |
|
| 376 | + $this->items[ $item->get_id() ] = $item; |
|
| 377 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 378 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 379 | + |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Removes a specific item. |
|
| 384 | + * |
|
| 385 | + * You should not call this method after the discounts and taxes |
|
| 386 | + * have been calculated. |
|
| 387 | + * |
|
| 388 | + * @since 1.0.19 |
|
| 389 | + */ |
|
| 390 | + public function remove_item( $item_id ) { |
|
| 391 | + |
|
| 392 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 395 | + |
|
| 396 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 397 | + $this->has_recurring = 0; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + unset( $this->items[ $item_id ] ); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Returns the subtotal. |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + */ |
|
| 410 | + public function get_subtotal() { |
|
| 411 | + |
|
| 412 | + if ( wpinv_prices_include_tax() ) { |
|
| 413 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + return $this->totals['subtotal']['initial']; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Returns the recurring subtotal. |
|
| 421 | + * |
|
| 422 | + * @since 1.0.19 |
|
| 423 | + */ |
|
| 424 | + public function get_recurring_subtotal() { |
|
| 425 | + |
|
| 426 | + if ( wpinv_prices_include_tax() ) { |
|
| 427 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return $this->totals['subtotal']['recurring']; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Returns all items. |
|
| 435 | + * |
|
| 436 | + * @since 1.0.19 |
|
| 437 | + * @return GetPaid_Form_Item[] |
|
| 438 | + */ |
|
| 439 | + public function get_items() { |
|
| 440 | + return $this->items; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Checks if there's a single subscription group in the submission. |
|
| 445 | + * |
|
| 446 | + * @since 2.3.0 |
|
| 447 | + * @return bool |
|
| 448 | + */ |
|
| 449 | + public function has_subscription_group() { |
|
| 450 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Checks if there are multipe subscription groups in the submission. |
|
| 455 | + * |
|
| 456 | + * @since 2.3.0 |
|
| 457 | + * @return bool |
|
| 458 | + */ |
|
| 459 | + public function has_multiple_subscription_groups() { |
|
| 460 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /* |
|
| 464 | 464 | |-------------------------------------------------------------------------- |
| 465 | 465 | | Taxes |
| 466 | 466 | |-------------------------------------------------------------------------- |
@@ -469,128 +469,128 @@ discard block |
||
| 469 | 469 | | or only one-time. |
| 470 | 470 | */ |
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * Prepares the submission's taxes. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - */ |
|
| 477 | - public function process_taxes() { |
|
| 478 | - |
|
| 479 | - // Abort if we're not using taxes. |
|
| 480 | - if ( ! $this->use_taxes() ) { |
|
| 481 | - return; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | - if ( ! empty( $country ) ) { |
|
| 487 | - $this->country = $country; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | - if ( ! empty( $state ) ) { |
|
| 492 | - $this->state = $state; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // Confirm if the provided country and the ip country are similar. |
|
| 496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // Abort if the country is not taxable. |
|
| 502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 503 | - return; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 507 | - |
|
| 508 | - foreach ( $processor->taxes as $tax ) { |
|
| 509 | - $this->add_tax( $tax ); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Adds a tax to the submission. |
|
| 517 | - * |
|
| 518 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - */ |
|
| 521 | - public function add_tax( $tax ) { |
|
| 522 | - |
|
| 523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 531 | - |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * Removes a specific tax. |
|
| 536 | - * |
|
| 537 | - * @since 1.0.19 |
|
| 538 | - */ |
|
| 539 | - public function remove_tax( $tax_name ) { |
|
| 540 | - |
|
| 541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | - unset( $this->taxes[ $tax_name ] ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Whether or not we'll use taxes for the submission. |
|
| 551 | - * |
|
| 552 | - * @since 1.0.19 |
|
| 553 | - */ |
|
| 554 | - public function use_taxes() { |
|
| 555 | - |
|
| 556 | - $use_taxes = wpinv_use_taxes(); |
|
| 557 | - |
|
| 558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 559 | - $use_taxes = false; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 563 | - |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Returns the tax. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - */ |
|
| 571 | - public function get_tax() { |
|
| 572 | - return $this->totals['taxes']['initial']; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Returns the recurring tax. |
|
| 577 | - * |
|
| 578 | - * @since 1.0.19 |
|
| 579 | - */ |
|
| 580 | - public function get_recurring_tax() { |
|
| 581 | - return $this->totals['taxes']['recurring']; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Returns all taxes. |
|
| 586 | - * |
|
| 587 | - * @since 1.0.19 |
|
| 588 | - */ |
|
| 589 | - public function get_taxes() { |
|
| 590 | - return $this->taxes; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /* |
|
| 472 | + /** |
|
| 473 | + * Prepares the submission's taxes. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + */ |
|
| 477 | + public function process_taxes() { |
|
| 478 | + |
|
| 479 | + // Abort if we're not using taxes. |
|
| 480 | + if ( ! $this->use_taxes() ) { |
|
| 481 | + return; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 485 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | + if ( ! empty( $country ) ) { |
|
| 487 | + $this->country = $country; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | + if ( ! empty( $state ) ) { |
|
| 492 | + $this->state = $state; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // Confirm if the provided country and the ip country are similar. |
|
| 496 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // Abort if the country is not taxable. |
|
| 502 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 503 | + return; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 507 | + |
|
| 508 | + foreach ( $processor->taxes as $tax ) { |
|
| 509 | + $this->add_tax( $tax ); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Adds a tax to the submission. |
|
| 517 | + * |
|
| 518 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + */ |
|
| 521 | + public function add_tax( $tax ) { |
|
| 522 | + |
|
| 523 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 531 | + |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * Removes a specific tax. |
|
| 536 | + * |
|
| 537 | + * @since 1.0.19 |
|
| 538 | + */ |
|
| 539 | + public function remove_tax( $tax_name ) { |
|
| 540 | + |
|
| 541 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | + unset( $this->taxes[ $tax_name ] ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Whether or not we'll use taxes for the submission. |
|
| 551 | + * |
|
| 552 | + * @since 1.0.19 |
|
| 553 | + */ |
|
| 554 | + public function use_taxes() { |
|
| 555 | + |
|
| 556 | + $use_taxes = wpinv_use_taxes(); |
|
| 557 | + |
|
| 558 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 559 | + $use_taxes = false; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 563 | + |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Returns the tax. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + */ |
|
| 571 | + public function get_tax() { |
|
| 572 | + return $this->totals['taxes']['initial']; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Returns the recurring tax. |
|
| 577 | + * |
|
| 578 | + * @since 1.0.19 |
|
| 579 | + */ |
|
| 580 | + public function get_recurring_tax() { |
|
| 581 | + return $this->totals['taxes']['recurring']; |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Returns all taxes. |
|
| 586 | + * |
|
| 587 | + * @since 1.0.19 |
|
| 588 | + */ |
|
| 589 | + public function get_taxes() { |
|
| 590 | + return $this->taxes; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /* |
|
| 594 | 594 | |-------------------------------------------------------------------------- |
| 595 | 595 | | Discounts |
| 596 | 596 | |-------------------------------------------------------------------------- |
@@ -599,99 +599,99 @@ discard block |
||
| 599 | 599 | | or only one-time. They also do not have to come from a discount code. |
| 600 | 600 | */ |
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * Prepares the submission's discount. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - */ |
|
| 607 | - public function process_discount() { |
|
| 608 | - |
|
| 609 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 610 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 612 | - |
|
| 613 | - foreach ( $processor->discounts as $discount ) { |
|
| 614 | - $this->add_discount( $discount ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Adds a discount to the submission. |
|
| 622 | - * |
|
| 623 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 624 | - * @since 1.0.19 |
|
| 625 | - */ |
|
| 626 | - public function add_discount( $discount ) { |
|
| 627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Removes a discount from the submission. |
|
| 634 | - * |
|
| 635 | - * @since 1.0.19 |
|
| 636 | - */ |
|
| 637 | - public function remove_discount( $name ) { |
|
| 638 | - |
|
| 639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | - unset( $this->discounts[ $name ] ); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Checks whether there is a discount code associated with this submission. |
|
| 649 | - * |
|
| 650 | - * @since 1.0.19 |
|
| 651 | - * @return bool |
|
| 652 | - */ |
|
| 653 | - public function has_discount_code() { |
|
| 654 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Returns the discount code. |
|
| 659 | - * |
|
| 660 | - * @since 1.0.19 |
|
| 661 | - * @return string |
|
| 662 | - */ |
|
| 663 | - public function get_discount_code() { |
|
| 664 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Returns the discount. |
|
| 669 | - * |
|
| 670 | - * @since 1.0.19 |
|
| 671 | - */ |
|
| 672 | - public function get_discount() { |
|
| 673 | - return $this->totals['discount']['initial']; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * Returns the recurring discount. |
|
| 678 | - * |
|
| 679 | - * @since 1.0.19 |
|
| 680 | - */ |
|
| 681 | - public function get_recurring_discount() { |
|
| 682 | - return $this->totals['discount']['recurring']; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Returns all discounts. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - */ |
|
| 690 | - public function get_discounts() { |
|
| 691 | - return $this->discounts; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /* |
|
| 602 | + /** |
|
| 603 | + * Prepares the submission's discount. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + */ |
|
| 607 | + public function process_discount() { |
|
| 608 | + |
|
| 609 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 610 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 611 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 612 | + |
|
| 613 | + foreach ( $processor->discounts as $discount ) { |
|
| 614 | + $this->add_discount( $discount ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Adds a discount to the submission. |
|
| 622 | + * |
|
| 623 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 624 | + * @since 1.0.19 |
|
| 625 | + */ |
|
| 626 | + public function add_discount( $discount ) { |
|
| 627 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Removes a discount from the submission. |
|
| 634 | + * |
|
| 635 | + * @since 1.0.19 |
|
| 636 | + */ |
|
| 637 | + public function remove_discount( $name ) { |
|
| 638 | + |
|
| 639 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | + unset( $this->discounts[ $name ] ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Checks whether there is a discount code associated with this submission. |
|
| 649 | + * |
|
| 650 | + * @since 1.0.19 |
|
| 651 | + * @return bool |
|
| 652 | + */ |
|
| 653 | + public function has_discount_code() { |
|
| 654 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Returns the discount code. |
|
| 659 | + * |
|
| 660 | + * @since 1.0.19 |
|
| 661 | + * @return string |
|
| 662 | + */ |
|
| 663 | + public function get_discount_code() { |
|
| 664 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Returns the discount. |
|
| 669 | + * |
|
| 670 | + * @since 1.0.19 |
|
| 671 | + */ |
|
| 672 | + public function get_discount() { |
|
| 673 | + return $this->totals['discount']['initial']; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * Returns the recurring discount. |
|
| 678 | + * |
|
| 679 | + * @since 1.0.19 |
|
| 680 | + */ |
|
| 681 | + public function get_recurring_discount() { |
|
| 682 | + return $this->totals['discount']['recurring']; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Returns all discounts. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + */ |
|
| 690 | + public function get_discounts() { |
|
| 691 | + return $this->discounts; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /* |
|
| 695 | 695 | |-------------------------------------------------------------------------- |
| 696 | 696 | | Fees |
| 697 | 697 | |-------------------------------------------------------------------------- |
@@ -701,100 +701,100 @@ discard block |
||
| 701 | 701 | | fees. |
| 702 | 702 | */ |
| 703 | 703 | |
| 704 | - /** |
|
| 705 | - * Prepares the submission's fees. |
|
| 706 | - * |
|
| 707 | - * @since 1.0.19 |
|
| 708 | - */ |
|
| 709 | - public function process_fees() { |
|
| 710 | - |
|
| 711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 712 | - |
|
| 713 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | - $this->add_fee( $fee ); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * Adds a fee to the submission. |
|
| 722 | - * |
|
| 723 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 724 | - * @since 1.0.19 |
|
| 725 | - */ |
|
| 726 | - public function add_fee( $fee ) { |
|
| 727 | - |
|
| 728 | - if ( $fee['name'] == 'shipping' ) { |
|
| 729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 731 | - return; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 737 | - |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Removes a fee from the submission. |
|
| 742 | - * |
|
| 743 | - * @since 1.0.19 |
|
| 744 | - */ |
|
| 745 | - public function remove_fee( $name ) { |
|
| 746 | - |
|
| 747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | - unset( $this->fees[ $name ] ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - if ( 'shipping' == $name ) { |
|
| 754 | - $this->totals['shipping']['initial'] = 0; |
|
| 755 | - $this->totals['shipping']['recurring'] = 0; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * Returns the fees. |
|
| 762 | - * |
|
| 763 | - * @since 1.0.19 |
|
| 764 | - */ |
|
| 765 | - public function get_fee() { |
|
| 766 | - return $this->totals['fees']['initial']; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Returns the recurring fees. |
|
| 771 | - * |
|
| 772 | - * @since 1.0.19 |
|
| 773 | - */ |
|
| 774 | - public function get_recurring_fee() { |
|
| 775 | - return $this->totals['fees']['recurring']; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * Returns all fees. |
|
| 780 | - * |
|
| 781 | - * @since 1.0.19 |
|
| 782 | - */ |
|
| 783 | - public function get_fees() { |
|
| 784 | - return $this->fees; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * Checks if there are any fees for the form. |
|
| 789 | - * |
|
| 790 | - * @return bool |
|
| 791 | - * @since 1.0.19 |
|
| 792 | - */ |
|
| 793 | - public function has_fees() { |
|
| 794 | - return count( $this->fees ) !== 0; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - /* |
|
| 704 | + /** |
|
| 705 | + * Prepares the submission's fees. |
|
| 706 | + * |
|
| 707 | + * @since 1.0.19 |
|
| 708 | + */ |
|
| 709 | + public function process_fees() { |
|
| 710 | + |
|
| 711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 712 | + |
|
| 713 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | + $this->add_fee( $fee ); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * Adds a fee to the submission. |
|
| 722 | + * |
|
| 723 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 724 | + * @since 1.0.19 |
|
| 725 | + */ |
|
| 726 | + public function add_fee( $fee ) { |
|
| 727 | + |
|
| 728 | + if ( $fee['name'] == 'shipping' ) { |
|
| 729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 731 | + return; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 737 | + |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Removes a fee from the submission. |
|
| 742 | + * |
|
| 743 | + * @since 1.0.19 |
|
| 744 | + */ |
|
| 745 | + public function remove_fee( $name ) { |
|
| 746 | + |
|
| 747 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | + unset( $this->fees[ $name ] ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + if ( 'shipping' == $name ) { |
|
| 754 | + $this->totals['shipping']['initial'] = 0; |
|
| 755 | + $this->totals['shipping']['recurring'] = 0; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * Returns the fees. |
|
| 762 | + * |
|
| 763 | + * @since 1.0.19 |
|
| 764 | + */ |
|
| 765 | + public function get_fee() { |
|
| 766 | + return $this->totals['fees']['initial']; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Returns the recurring fees. |
|
| 771 | + * |
|
| 772 | + * @since 1.0.19 |
|
| 773 | + */ |
|
| 774 | + public function get_recurring_fee() { |
|
| 775 | + return $this->totals['fees']['recurring']; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * Returns all fees. |
|
| 780 | + * |
|
| 781 | + * @since 1.0.19 |
|
| 782 | + */ |
|
| 783 | + public function get_fees() { |
|
| 784 | + return $this->fees; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * Checks if there are any fees for the form. |
|
| 789 | + * |
|
| 790 | + * @return bool |
|
| 791 | + * @since 1.0.19 |
|
| 792 | + */ |
|
| 793 | + public function has_fees() { |
|
| 794 | + return count( $this->fees ) !== 0; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + /* |
|
| 798 | 798 | |-------------------------------------------------------------------------- |
| 799 | 799 | | MISC |
| 800 | 800 | |-------------------------------------------------------------------------- |
@@ -802,147 +802,147 @@ discard block |
||
| 802 | 802 | | Extra submission functions. |
| 803 | 803 | */ |
| 804 | 804 | |
| 805 | - /** |
|
| 806 | - * Returns the shipping amount. |
|
| 807 | - * |
|
| 808 | - * @since 1.0.19 |
|
| 809 | - */ |
|
| 810 | - public function get_shipping() { |
|
| 811 | - return $this->totals['shipping']['initial']; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Returns the recurring shipping. |
|
| 816 | - * |
|
| 817 | - * @since 1.0.19 |
|
| 818 | - */ |
|
| 819 | - public function get_recurring_shipping() { |
|
| 820 | - return $this->totals['shipping']['recurring']; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Checks if there are any shipping fees for the form. |
|
| 825 | - * |
|
| 826 | - * @return bool |
|
| 827 | - * @since 1.0.19 |
|
| 828 | - */ |
|
| 829 | - public function has_shipping() { |
|
| 830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * Checks if this is the initial fetch. |
|
| 835 | - * |
|
| 836 | - * @return bool |
|
| 837 | - * @since 1.0.19 |
|
| 838 | - */ |
|
| 839 | - public function is_initial_fetch() { |
|
| 840 | - return empty( $this->data['initial_state'] ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * Returns the total amount to collect for this submission. |
|
| 845 | - * |
|
| 846 | - * @since 1.0.19 |
|
| 847 | - */ |
|
| 848 | - public function get_total() { |
|
| 849 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 850 | - return max( $total, 0 ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Returns the recurring total amount to collect for this submission. |
|
| 855 | - * |
|
| 856 | - * @since 1.0.19 |
|
| 857 | - */ |
|
| 858 | - public function get_recurring_total() { |
|
| 859 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 860 | - return max( $total, 0 ); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Whether payment details should be collected for this submission. |
|
| 865 | - * |
|
| 866 | - * @since 1.0.19 |
|
| 867 | - */ |
|
| 868 | - public function should_collect_payment_details() { |
|
| 869 | - $initial = $this->get_total(); |
|
| 870 | - $recurring = $this->get_recurring_total(); |
|
| 871 | - |
|
| 872 | - if ( $this->has_recurring == 0 ) { |
|
| 873 | - $recurring = 0; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - $collect = $initial > 0 || $recurring > 0; |
|
| 877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Returns the billing email of the user. |
|
| 882 | - * |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - */ |
|
| 885 | - public function get_billing_email() { |
|
| 886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * Checks if the submitter has a billing email. |
|
| 891 | - * |
|
| 892 | - * @since 1.0.19 |
|
| 893 | - */ |
|
| 894 | - public function has_billing_email() { |
|
| 895 | - $billing_email = $this->get_billing_email(); |
|
| 896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Returns the appropriate currency for the submission. |
|
| 901 | - * |
|
| 902 | - * @since 1.0.19 |
|
| 903 | - * @return string |
|
| 904 | - */ |
|
| 905 | - public function get_currency() { |
|
| 906 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Returns the raw submission data. |
|
| 911 | - * |
|
| 912 | - * @since 1.0.19 |
|
| 913 | - * @return array |
|
| 914 | - */ |
|
| 915 | - public function get_data() { |
|
| 916 | - return $this->data; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * Returns a field from the submission data |
|
| 921 | - * |
|
| 922 | - * @param string $field |
|
| 923 | - * @since 1.0.19 |
|
| 924 | - * @return mixed|null |
|
| 925 | - */ |
|
| 926 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Checks if a required field is set. |
|
| 932 | - * |
|
| 933 | - * @since 1.0.19 |
|
| 934 | - */ |
|
| 935 | - public function is_required_field_set( $field ) { |
|
| 936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * Formats an amount |
|
| 941 | - * |
|
| 942 | - * @since 1.0.19 |
|
| 943 | - */ |
|
| 944 | - public function format_amount( $amount ) { |
|
| 945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 946 | - } |
|
| 805 | + /** |
|
| 806 | + * Returns the shipping amount. |
|
| 807 | + * |
|
| 808 | + * @since 1.0.19 |
|
| 809 | + */ |
|
| 810 | + public function get_shipping() { |
|
| 811 | + return $this->totals['shipping']['initial']; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Returns the recurring shipping. |
|
| 816 | + * |
|
| 817 | + * @since 1.0.19 |
|
| 818 | + */ |
|
| 819 | + public function get_recurring_shipping() { |
|
| 820 | + return $this->totals['shipping']['recurring']; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Checks if there are any shipping fees for the form. |
|
| 825 | + * |
|
| 826 | + * @return bool |
|
| 827 | + * @since 1.0.19 |
|
| 828 | + */ |
|
| 829 | + public function has_shipping() { |
|
| 830 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * Checks if this is the initial fetch. |
|
| 835 | + * |
|
| 836 | + * @return bool |
|
| 837 | + * @since 1.0.19 |
|
| 838 | + */ |
|
| 839 | + public function is_initial_fetch() { |
|
| 840 | + return empty( $this->data['initial_state'] ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * Returns the total amount to collect for this submission. |
|
| 845 | + * |
|
| 846 | + * @since 1.0.19 |
|
| 847 | + */ |
|
| 848 | + public function get_total() { |
|
| 849 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 850 | + return max( $total, 0 ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Returns the recurring total amount to collect for this submission. |
|
| 855 | + * |
|
| 856 | + * @since 1.0.19 |
|
| 857 | + */ |
|
| 858 | + public function get_recurring_total() { |
|
| 859 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 860 | + return max( $total, 0 ); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Whether payment details should be collected for this submission. |
|
| 865 | + * |
|
| 866 | + * @since 1.0.19 |
|
| 867 | + */ |
|
| 868 | + public function should_collect_payment_details() { |
|
| 869 | + $initial = $this->get_total(); |
|
| 870 | + $recurring = $this->get_recurring_total(); |
|
| 871 | + |
|
| 872 | + if ( $this->has_recurring == 0 ) { |
|
| 873 | + $recurring = 0; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + $collect = $initial > 0 || $recurring > 0; |
|
| 877 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Returns the billing email of the user. |
|
| 882 | + * |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + */ |
|
| 885 | + public function get_billing_email() { |
|
| 886 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * Checks if the submitter has a billing email. |
|
| 891 | + * |
|
| 892 | + * @since 1.0.19 |
|
| 893 | + */ |
|
| 894 | + public function has_billing_email() { |
|
| 895 | + $billing_email = $this->get_billing_email(); |
|
| 896 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Returns the appropriate currency for the submission. |
|
| 901 | + * |
|
| 902 | + * @since 1.0.19 |
|
| 903 | + * @return string |
|
| 904 | + */ |
|
| 905 | + public function get_currency() { |
|
| 906 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Returns the raw submission data. |
|
| 911 | + * |
|
| 912 | + * @since 1.0.19 |
|
| 913 | + * @return array |
|
| 914 | + */ |
|
| 915 | + public function get_data() { |
|
| 916 | + return $this->data; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * Returns a field from the submission data |
|
| 921 | + * |
|
| 922 | + * @param string $field |
|
| 923 | + * @since 1.0.19 |
|
| 924 | + * @return mixed|null |
|
| 925 | + */ |
|
| 926 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Checks if a required field is set. |
|
| 932 | + * |
|
| 933 | + * @since 1.0.19 |
|
| 934 | + */ |
|
| 935 | + public function is_required_field_set( $field ) { |
|
| 936 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * Formats an amount |
|
| 941 | + * |
|
| 942 | + * @since 1.0.19 |
|
| 943 | + */ |
|
| 944 | + public function format_amount( $amount ) { |
|
| 945 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 946 | + } |
|
| 947 | 947 | |
| 948 | 948 | } |