@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
| 26 | - define( 'WPINV_VERSION', '2.1.3' ); |
|
| 26 | + define( 'WPINV_VERSION', '2.1.3' ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return $GLOBALS['invoicing']; |
|
| 46 | + return $GLOBALS['invoicing']; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -15,20 +15,20 @@ discard block |
||
| 15 | 15 | * @package GetPaid |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -defined( 'ABSPATH' ) || exit; |
|
| 18 | +defined('ABSPATH') || exit; |
|
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | -if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 21 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
| 22 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -if ( ! defined( 'WPINV_VERSION' ) ) { |
|
| 26 | - define( 'WPINV_VERSION', '2.1.3' ); |
|
| 25 | +if (!defined('WPINV_VERSION')) { |
|
| 26 | + define('WPINV_VERSION', '2.1.3'); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | -if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
|
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 30 | +if (!class_exists('WPInv_Plugin', false)) { |
|
| 31 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | function getpaid() { |
| 41 | 41 | |
| 42 | - if ( empty( $GLOBALS['invoicing'] ) ) { |
|
| 42 | + if (empty($GLOBALS['invoicing'])) { |
|
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @since 2.0.8 |
| 53 | 53 | */ |
| 54 | 54 | function getpaid_deactivation_hook() { |
| 55 | - update_option( 'wpinv_flush_permalinks', 1 ); |
|
| 55 | + update_option('wpinv_flush_permalinks', 1); |
|
| 56 | 56 | } |
| 57 | -register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' ); |
|
| 57 | +register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook'); |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * @deprecated |
@@ -64,4 +64,4 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // Kickstart the plugin. |
| 67 | -add_action( 'plugins_loaded', 'getpaid', -100 ); |
|
| 67 | +add_action('plugins_loaded', 'getpaid', -100); |
|
@@ -12,228 +12,228 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission taxes. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $taxes = array(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Whether or not we should skip the taxes. |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $skip_taxes = false; |
|
| 15 | + /** |
|
| 16 | + * Submission taxes. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $taxes = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Whether or not we should skip the taxes. |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $skip_taxes = false; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Validate VAT number. |
|
| 35 | - $this->validate_vat( $submission ); |
|
| 36 | - |
|
| 37 | - if ( $this->skip_taxes ) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - foreach ( $submission->get_items() as $item ) { |
|
| 42 | - $this->process_item_tax( $item, $submission ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // Process any existing invoice taxes. |
|
| 46 | - if ( $submission->has_invoice() ) { |
|
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Maybe process tax. |
|
| 54 | - * |
|
| 55 | - * @since 1.0.19 |
|
| 56 | - * @param GetPaid_Form_Item $item |
|
| 57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | - */ |
|
| 59 | - public function process_item_tax( $item, $submission ) { |
|
| 60 | - |
|
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates ); |
|
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates ); |
|
| 65 | - |
|
| 66 | - foreach ( $taxes as $name => $amount ) { |
|
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | - |
|
| 70 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | - $this->taxes[ $name ] = $tax; |
|
| 72 | - continue; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Checks if the submission has a digital item. |
|
| 84 | - * |
|
| 85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | - * @since 1.0.19 |
|
| 87 | - * @return bool |
|
| 88 | - */ |
|
| 89 | - public function has_digital_item( $submission ) { |
|
| 90 | - |
|
| 91 | - foreach ( $submission->get_items() as $item ) { |
|
| 92 | - |
|
| 93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Checks if this is an eu store. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public static function is_eu_store() { |
|
| 109 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Checks if this is an eu country. |
|
| 114 | - * |
|
| 115 | - * @param string $country |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - public static function is_eu_country( $country ) { |
|
| 120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Checks if this is an eu purchase. |
|
| 125 | - * |
|
| 126 | - * @param string $customer_country |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - public static function is_eu_transaction( $customer_country ) { |
|
| 131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Retrieves the vat number. |
|
| 136 | - * |
|
| 137 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function get_vat_number( $submission ) { |
|
| 142 | - |
|
| 143 | - // Retrieve from the posted number. |
|
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | - if ( ! empty( $vat_number ) ) { |
|
| 146 | - return wpinv_clean( $vat_number ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // Retrieve from the invoice. |
|
| 150 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Retrieves the company. |
|
| 155 | - * |
|
| 156 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | - * @since 1.0.19 |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function get_company( $submission ) { |
|
| 161 | - |
|
| 162 | - // Retrieve from the posted data. |
|
| 163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | - if ( ! empty( $company ) ) { |
|
| 165 | - return wpinv_clean( $company ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Retrieve from the invoice. |
|
| 169 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Checks if we require a VAT number. |
|
| 174 | - * |
|
| 175 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | - * @since 1.0.19 |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | - |
|
| 182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | - |
|
| 186 | - return $prevent_b2c && $is_eu; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Validate VAT data. |
|
| 191 | - * |
|
| 192 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | - * @since 1.0.19 |
|
| 194 | - */ |
|
| 195 | - public function validate_vat( $submission ) { |
|
| 196 | - |
|
| 197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | - |
|
| 199 | - // Abort if we are not validating vat numbers. |
|
| 200 | - if ( ! $in_eu ) { |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Validate VAT number. |
|
| 35 | + $this->validate_vat( $submission ); |
|
| 36 | + |
|
| 37 | + if ( $this->skip_taxes ) { |
|
| 201 | 38 | return; |
| 202 | - } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + foreach ( $submission->get_items() as $item ) { |
|
| 42 | + $this->process_item_tax( $item, $submission ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // Process any existing invoice taxes. |
|
| 46 | + if ( $submission->has_invoice() ) { |
|
| 47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Maybe process tax. |
|
| 54 | + * |
|
| 55 | + * @since 1.0.19 |
|
| 56 | + * @param GetPaid_Form_Item $item |
|
| 57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | + */ |
|
| 59 | + public function process_item_tax( $item, $submission ) { |
|
| 60 | + |
|
| 61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates ); |
|
| 64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates ); |
|
| 65 | + |
|
| 66 | + foreach ( $taxes as $name => $amount ) { |
|
| 67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | + |
|
| 70 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | + $this->taxes[ $name ] = $tax; |
|
| 72 | + continue; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Checks if the submission has a digital item. |
|
| 84 | + * |
|
| 85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | + * @since 1.0.19 |
|
| 87 | + * @return bool |
|
| 88 | + */ |
|
| 89 | + public function has_digital_item( $submission ) { |
|
| 90 | + |
|
| 91 | + foreach ( $submission->get_items() as $item ) { |
|
| 92 | + |
|
| 93 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + } |
|
| 203 | 98 | |
| 204 | - // Prepare variables. |
|
| 205 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | - $ip_country = getpaid_get_ip_country(); |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Checks if this is an eu store. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public static function is_eu_store() { |
|
| 109 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Checks if this is an eu country. |
|
| 114 | + * |
|
| 115 | + * @param string $country |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + public static function is_eu_country( $country ) { |
|
| 120 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Checks if this is an eu purchase. |
|
| 125 | + * |
|
| 126 | + * @param string $customer_country |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + public static function is_eu_transaction( $customer_country ) { |
|
| 131 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Retrieves the vat number. |
|
| 136 | + * |
|
| 137 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function get_vat_number( $submission ) { |
|
| 142 | + |
|
| 143 | + // Retrieve from the posted number. |
|
| 144 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | + if ( ! empty( $vat_number ) ) { |
|
| 146 | + return wpinv_clean( $vat_number ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // Retrieve from the invoice. |
|
| 150 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Retrieves the company. |
|
| 155 | + * |
|
| 156 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | + * @since 1.0.19 |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function get_company( $submission ) { |
|
| 161 | + |
|
| 162 | + // Retrieve from the posted data. |
|
| 163 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | + if ( ! empty( $company ) ) { |
|
| 165 | + return wpinv_clean( $company ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Retrieve from the invoice. |
|
| 169 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Checks if we require a VAT number. |
|
| 174 | + * |
|
| 175 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | + * @since 1.0.19 |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | + |
|
| 182 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | + |
|
| 186 | + return $prevent_b2c && $is_eu; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Validate VAT data. |
|
| 191 | + * |
|
| 192 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | + * @since 1.0.19 |
|
| 194 | + */ |
|
| 195 | + public function validate_vat( $submission ) { |
|
| 196 | + |
|
| 197 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | + |
|
| 199 | + // Abort if we are not validating vat numbers. |
|
| 200 | + if ( ! $in_eu ) { |
|
| 201 | + return; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Prepare variables. |
|
| 205 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | + $ip_country = getpaid_get_ip_country(); |
|
| 207 | 207 | $is_eu = $this->is_eu_country( $submission->country ); |
| 208 | 208 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 209 | 209 | |
| 210 | - // Maybe abort early for initial fetches. |
|
| 211 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 212 | - return; |
|
| 213 | - } |
|
| 210 | + // Maybe abort early for initial fetches. |
|
| 211 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - // If we're preventing business to consumer purchases, |
|
| 216 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 215 | + // If we're preventing business to consumer purchases, |
|
| 216 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 217 | 217 | |
| 218 | - // Ensure that a vat number has been specified. |
|
| 219 | - throw new Exception( |
|
| 220 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 221 | - ); |
|
| 218 | + // Ensure that a vat number has been specified. |
|
| 219 | + throw new Exception( |
|
| 220 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 221 | + ); |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - if ( empty( $vat_number ) ) { |
|
| 226 | - return; |
|
| 227 | - } |
|
| 225 | + if ( empty( $vat_number ) ) { |
|
| 226 | + return; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 230 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 231 | - } |
|
| 229 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 230 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - if ( wpinv_default_billing_country() != $submission->country && 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
| 234 | - $this->skip_taxes = true; |
|
| 235 | - } |
|
| 233 | + if ( wpinv_default_billing_country() != $submission->country && 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
| 234 | + $this->skip_taxes = true; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - } |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
| 31 | 31 | */ |
| 32 | - public function __construct( $submission ) { |
|
| 32 | + public function __construct($submission) { |
|
| 33 | 33 | |
| 34 | 34 | // Validate VAT number. |
| 35 | - $this->validate_vat( $submission ); |
|
| 35 | + $this->validate_vat($submission); |
|
| 36 | 36 | |
| 37 | - if ( $this->skip_taxes ) { |
|
| 37 | + if ($this->skip_taxes) { |
|
| 38 | 38 | return; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - foreach ( $submission->get_items() as $item ) { |
|
| 42 | - $this->process_item_tax( $item, $submission ); |
|
| 41 | + foreach ($submission->get_items() as $item) { |
|
| 42 | + $this->process_item_tax($item, $submission); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // Process any existing invoice taxes. |
| 46 | - if ( $submission->has_invoice() ) { |
|
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 46 | + if ($submission->has_invoice()) { |
|
| 47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
@@ -56,24 +56,24 @@ discard block |
||
| 56 | 56 | * @param GetPaid_Form_Item $item |
| 57 | 57 | * @param GetPaid_Payment_Form_Submission $submission |
| 58 | 58 | */ |
| 59 | - public function process_item_tax( $item, $submission ) { |
|
| 59 | + public function process_item_tax($item, $submission) { |
|
| 60 | 60 | |
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates ); |
|
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates ); |
|
| 61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
| 62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
| 63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false), $rates); |
|
| 64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true), $rates); |
|
| 65 | 65 | |
| 66 | - foreach ( $taxes as $name => $amount ) { |
|
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 66 | + foreach ($taxes as $name => $amount) { |
|
| 67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
| 68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
| 69 | 69 | |
| 70 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | - $this->taxes[ $name ] = $tax; |
|
| 70 | + if (!isset($this->taxes[$name])) { |
|
| 71 | + $this->taxes[$name] = $tax; |
|
| 72 | 72 | continue; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 75 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | * @since 1.0.19 |
| 87 | 87 | * @return bool |
| 88 | 88 | */ |
| 89 | - public function has_digital_item( $submission ) { |
|
| 89 | + public function has_digital_item($submission) { |
|
| 90 | 90 | |
| 91 | - foreach ( $submission->get_items() as $item ) { |
|
| 91 | + foreach ($submission->get_items() as $item) { |
|
| 92 | 92 | |
| 93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 93 | + if ('digital' == $item->get_vat_rule()) { |
|
| 94 | 94 | return true; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @return bool |
| 107 | 107 | */ |
| 108 | 108 | public static function is_eu_store() { |
| 109 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 109 | + return self::is_eu_country(wpinv_get_default_country()); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | * @since 1.0.19 |
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | - public static function is_eu_country( $country ) { |
|
| 120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 119 | + public static function is_eu_country($country) { |
|
| 120 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | * @since 1.0.19 |
| 128 | 128 | * @return bool |
| 129 | 129 | */ |
| 130 | - public static function is_eu_transaction( $customer_country ) { |
|
| 131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 130 | + public static function is_eu_transaction($customer_country) { |
|
| 131 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | * @since 1.0.19 |
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | - public function get_vat_number( $submission ) { |
|
| 141 | + public function get_vat_number($submission) { |
|
| 142 | 142 | |
| 143 | 143 | // Retrieve from the posted number. |
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | - if ( ! empty( $vat_number ) ) { |
|
| 146 | - return wpinv_clean( $vat_number ); |
|
| 144 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
| 145 | + if (!empty($vat_number)) { |
|
| 146 | + return wpinv_clean($vat_number); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // Retrieve from the invoice. |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | * @since 1.0.19 |
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | - public function get_company( $submission ) { |
|
| 160 | + public function get_company($submission) { |
|
| 161 | 161 | |
| 162 | 162 | // Retrieve from the posted data. |
| 163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | - if ( ! empty( $company ) ) { |
|
| 165 | - return wpinv_clean( $company ); |
|
| 163 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
| 164 | + if (!empty($company)) { |
|
| 165 | + return wpinv_clean($company); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // Retrieve from the invoice. |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | * @since 1.0.19 |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 180 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
| 181 | 181 | |
| 182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 182 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
| 183 | + $prevent_b2c = !empty($prevent_b2c); |
|
| 184 | 184 | $is_eu = $ip_in_eu || $country_in_eu; |
| 185 | 185 | |
| 186 | 186 | return $prevent_b2c && $is_eu; |
@@ -192,45 +192,45 @@ discard block |
||
| 192 | 192 | * @param GetPaid_Payment_Form_Submission $submission |
| 193 | 193 | * @since 1.0.19 |
| 194 | 194 | */ |
| 195 | - public function validate_vat( $submission ) { |
|
| 195 | + public function validate_vat($submission) { |
|
| 196 | 196 | |
| 197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 197 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
| 198 | 198 | |
| 199 | 199 | // Abort if we are not validating vat numbers. |
| 200 | - if ( ! $in_eu ) { |
|
| 200 | + if (!$in_eu) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Prepare variables. |
| 205 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 205 | + $vat_number = $this->get_vat_number($submission); |
|
| 206 | 206 | $ip_country = getpaid_get_ip_country(); |
| 207 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
| 208 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
| 207 | + $is_eu = $this->is_eu_country($submission->country); |
|
| 208 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
| 209 | 209 | |
| 210 | 210 | // Maybe abort early for initial fetches. |
| 211 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 211 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
| 212 | 212 | return; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // If we're preventing business to consumer purchases, |
| 216 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 216 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
| 217 | 217 | |
| 218 | 218 | // Ensure that a vat number has been specified. |
| 219 | 219 | throw new Exception( |
| 220 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 220 | + __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing') |
|
| 221 | 221 | ); |
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - if ( empty( $vat_number ) ) { |
|
| 225 | + if (empty($vat_number)) { |
|
| 226 | 226 | return; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 230 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 229 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
| 230 | + throw new Exception(__('Your VAT number is invalid', 'invoicing')); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if ( wpinv_default_billing_country() != $submission->country && 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
| 233 | + if (wpinv_default_billing_country() != $submission->country && 'vat_too' != wpinv_get_option('vat_same_country_rule')) { |
|
| 234 | 234 | $this->skip_taxes = true; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -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,187 +10,187 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Sets the associated payment form. |
|
| 57 | - * |
|
| 58 | - * @var GetPaid_Payment_Form |
|
| 59 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Sets the associated payment form. |
|
| 57 | + * |
|
| 58 | + * @var GetPaid_Payment_Form |
|
| 59 | + */ |
|
| 60 | 60 | protected $payment_form = null; |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * The country for the submission. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - public $country = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The state for the submission. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.19 |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $state = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The invoice associated with the submission. |
|
| 79 | - * |
|
| 80 | - * @var WPInv_Invoice |
|
| 81 | - */ |
|
| 82 | - protected $invoice = null; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The recurring item for the submission. |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - public $has_recurring = 0; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * An array of fees for the submission. |
|
| 93 | - * |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $fees = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * An array of discounts for the submission. |
|
| 100 | - * |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - protected $discounts = array(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of taxes for the submission. |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $taxes = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * An array of items for the submission. |
|
| 114 | - * |
|
| 115 | - * @var GetPaid_Form_Item[] |
|
| 116 | - */ |
|
| 117 | - protected $items = array(); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The last error. |
|
| 121 | - * |
|
| 122 | - * @var string |
|
| 123 | - */ |
|
| 124 | - public $last_error = null; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Class constructor. |
|
| 128 | - * |
|
| 129 | - */ |
|
| 130 | - public function __construct() { |
|
| 131 | - |
|
| 132 | - // Set the state and country to the default state and country. |
|
| 133 | - $this->country = wpinv_default_billing_country(); |
|
| 134 | - $this->state = wpinv_get_default_state(); |
|
| 135 | - |
|
| 136 | - // Do we have an actual submission? |
|
| 137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | - $this->load_data( $_POST ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Loads submission data. |
|
| 145 | - * |
|
| 146 | - * @param array $data |
|
| 147 | - */ |
|
| 148 | - public function load_data( $data ) { |
|
| 149 | - |
|
| 150 | - // Remove slashes from the submitted data... |
|
| 151 | - $data = wp_unslash( $data ); |
|
| 152 | - |
|
| 153 | - // Allow plugins to filter the data. |
|
| 154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | - |
|
| 156 | - // Cache it... |
|
| 157 | - $this->data = $data; |
|
| 158 | - |
|
| 159 | - // Then generate a unique id from the data. |
|
| 160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | - |
|
| 162 | - // Finally, process the submission. |
|
| 163 | - try { |
|
| 164 | - |
|
| 165 | - // Each process is passed an instance of the class (with reference) |
|
| 166 | - // and should throw an Exception whenever it encounters one. |
|
| 167 | - $processors = apply_filters( |
|
| 168 | - 'getpaid_payment_form_submission_processors', |
|
| 169 | - array( |
|
| 170 | - array( $this, 'process_payment_form' ), |
|
| 171 | - array( $this, 'process_invoice' ), |
|
| 172 | - array( $this, 'process_fees' ), |
|
| 173 | - array( $this, 'process_items' ), |
|
| 174 | - array( $this, 'process_discount' ), |
|
| 175 | - array( $this, 'process_taxes' ), |
|
| 176 | - ), |
|
| 177 | - $this |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - foreach ( $processors as $processor ) { |
|
| 181 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - } catch ( Exception $e ) { |
|
| 185 | - $this->last_error = $e->getMessage(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Fired when we are done processing a submission. |
|
| 189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | - |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /* |
|
| 63 | + * The country for the submission. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + public $country = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The state for the submission. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.19 |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $state = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The invoice associated with the submission. |
|
| 79 | + * |
|
| 80 | + * @var WPInv_Invoice |
|
| 81 | + */ |
|
| 82 | + protected $invoice = null; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The recurring item for the submission. |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + public $has_recurring = 0; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * An array of fees for the submission. |
|
| 93 | + * |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $fees = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * An array of discounts for the submission. |
|
| 100 | + * |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + protected $discounts = array(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of taxes for the submission. |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $taxes = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * An array of items for the submission. |
|
| 114 | + * |
|
| 115 | + * @var GetPaid_Form_Item[] |
|
| 116 | + */ |
|
| 117 | + protected $items = array(); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The last error. |
|
| 121 | + * |
|
| 122 | + * @var string |
|
| 123 | + */ |
|
| 124 | + public $last_error = null; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Class constructor. |
|
| 128 | + * |
|
| 129 | + */ |
|
| 130 | + public function __construct() { |
|
| 131 | + |
|
| 132 | + // Set the state and country to the default state and country. |
|
| 133 | + $this->country = wpinv_default_billing_country(); |
|
| 134 | + $this->state = wpinv_get_default_state(); |
|
| 135 | + |
|
| 136 | + // Do we have an actual submission? |
|
| 137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | + $this->load_data( $_POST ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Loads submission data. |
|
| 145 | + * |
|
| 146 | + * @param array $data |
|
| 147 | + */ |
|
| 148 | + public function load_data( $data ) { |
|
| 149 | + |
|
| 150 | + // Remove slashes from the submitted data... |
|
| 151 | + $data = wp_unslash( $data ); |
|
| 152 | + |
|
| 153 | + // Allow plugins to filter the data. |
|
| 154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | + |
|
| 156 | + // Cache it... |
|
| 157 | + $this->data = $data; |
|
| 158 | + |
|
| 159 | + // Then generate a unique id from the data. |
|
| 160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | + |
|
| 162 | + // Finally, process the submission. |
|
| 163 | + try { |
|
| 164 | + |
|
| 165 | + // Each process is passed an instance of the class (with reference) |
|
| 166 | + // and should throw an Exception whenever it encounters one. |
|
| 167 | + $processors = apply_filters( |
|
| 168 | + 'getpaid_payment_form_submission_processors', |
|
| 169 | + array( |
|
| 170 | + array( $this, 'process_payment_form' ), |
|
| 171 | + array( $this, 'process_invoice' ), |
|
| 172 | + array( $this, 'process_fees' ), |
|
| 173 | + array( $this, 'process_items' ), |
|
| 174 | + array( $this, 'process_discount' ), |
|
| 175 | + array( $this, 'process_taxes' ), |
|
| 176 | + ), |
|
| 177 | + $this |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + foreach ( $processors as $processor ) { |
|
| 181 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + } catch ( Exception $e ) { |
|
| 185 | + $this->last_error = $e->getMessage(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Fired when we are done processing a submission. |
|
| 189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | + |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /* |
|
| 194 | 194 | |-------------------------------------------------------------------------- |
| 195 | 195 | | Payment Forms. |
| 196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
| 199 | 199 | | submission has an active payment form etc. |
| 200 | 200 | */ |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Prepares the submission's payment form. |
|
| 204 | - * |
|
| 205 | - * @since 1.0.19 |
|
| 206 | - */ |
|
| 207 | - public function process_payment_form() { |
|
| 202 | + /** |
|
| 203 | + * Prepares the submission's payment form. |
|
| 204 | + * |
|
| 205 | + * @since 1.0.19 |
|
| 206 | + */ |
|
| 207 | + public function process_payment_form() { |
|
| 208 | 208 | |
| 209 | - // Every submission needs an active payment form. |
|
| 210 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | - } |
|
| 209 | + // Every submission needs an active payment form. |
|
| 210 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // Fetch the payment form. |
|
| 215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 214 | + // Fetch the payment form. |
|
| 215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 216 | 216 | |
| 217 | - if ( ! $this->payment_form->is_active() ) { |
|
| 218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | - } |
|
| 217 | + if ( ! $this->payment_form->is_active() ) { |
|
| 218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | - } |
|
| 221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | - * Returns the payment form. |
|
| 226 | - * |
|
| 227 | - * @since 1.0.19 |
|
| 228 | - * @return GetPaid_Payment_Form |
|
| 229 | - */ |
|
| 230 | - public function get_payment_form() { |
|
| 231 | - return $this->payment_form; |
|
| 232 | - } |
|
| 225 | + * Returns the payment form. |
|
| 226 | + * |
|
| 227 | + * @since 1.0.19 |
|
| 228 | + * @return GetPaid_Payment_Form |
|
| 229 | + */ |
|
| 230 | + public function get_payment_form() { |
|
| 231 | + return $this->payment_form; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /* |
|
| 234 | + /* |
|
| 235 | 235 | |-------------------------------------------------------------------------- |
| 236 | 236 | | Invoices. |
| 237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
| 240 | 240 | | might be for an existing invoice. |
| 241 | 241 | */ |
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Prepares the submission's invoice. |
|
| 245 | - * |
|
| 246 | - * @since 1.0.19 |
|
| 247 | - */ |
|
| 248 | - public function process_invoice() { |
|
| 243 | + /** |
|
| 244 | + * Prepares the submission's invoice. |
|
| 245 | + * |
|
| 246 | + * @since 1.0.19 |
|
| 247 | + */ |
|
| 248 | + public function process_invoice() { |
|
| 249 | 249 | |
| 250 | - // Abort if there is no invoice. |
|
| 251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 250 | + // Abort if there is no invoice. |
|
| 251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | - // and that it is not paid for. |
|
| 257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 255 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | + // and that it is not paid for. |
|
| 257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 258 | 258 | |
| 259 | 259 | if ( empty( $invoice ) ) { |
| 260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( $invoice->is_paid() ) { |
|
| 264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | - $this->payment_form->invoice = $invoice; |
|
| 269 | - |
|
| 270 | - $this->country = $invoice->get_country(); |
|
| 271 | - $this->state = $invoice->get_state(); |
|
| 272 | - $this->invoice = $invoice; |
|
| 273 | - |
|
| 274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Returns the associated invoice. |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @return WPInv_Invoice |
|
| 282 | - */ |
|
| 283 | - public function get_invoice() { |
|
| 284 | - return $this->invoice; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Checks whether there is an invoice associated with this submission. |
|
| 289 | - * |
|
| 290 | - * @since 1.0.19 |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 293 | - public function has_invoice() { |
|
| 294 | - return ! empty( $this->invoice ); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /* |
|
| 260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( $invoice->is_paid() ) { |
|
| 264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | + $this->payment_form->invoice = $invoice; |
|
| 269 | + |
|
| 270 | + $this->country = $invoice->get_country(); |
|
| 271 | + $this->state = $invoice->get_state(); |
|
| 272 | + $this->invoice = $invoice; |
|
| 273 | + |
|
| 274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Returns the associated invoice. |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @return WPInv_Invoice |
|
| 282 | + */ |
|
| 283 | + public function get_invoice() { |
|
| 284 | + return $this->invoice; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Checks whether there is an invoice associated with this submission. |
|
| 289 | + * |
|
| 290 | + * @since 1.0.19 |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | + public function has_invoice() { |
|
| 294 | + return ! empty( $this->invoice ); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /* |
|
| 298 | 298 | |-------------------------------------------------------------------------- |
| 299 | 299 | | Items. |
| 300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,115 +303,115 @@ discard block |
||
| 303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
| 304 | 304 | */ |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Prepares the submission's items. |
|
| 308 | - * |
|
| 309 | - * @since 1.0.19 |
|
| 310 | - */ |
|
| 311 | - public function process_items() { |
|
| 312 | - |
|
| 313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | - |
|
| 315 | - foreach ( $processor->items as $item ) { |
|
| 316 | - $this->add_item( $item ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Adds an item to the submission. |
|
| 324 | - * |
|
| 325 | - * @since 1.0.19 |
|
| 326 | - * @param GetPaid_Form_Item $item |
|
| 327 | - */ |
|
| 328 | - public function add_item( $item ) { |
|
| 329 | - |
|
| 330 | - // Make sure that it is available for purchase. |
|
| 331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 332 | - return; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // Each submission can only contain one recurring item. |
|
| 336 | - if ( $item->is_recurring() ) { |
|
| 337 | - |
|
| 338 | - if ( $this->has_recurring != 0 ) { |
|
| 339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $this->has_recurring = $item->get_id(); |
|
| 343 | - |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Update the items and totals. |
|
| 347 | - $this->items[ $item->get_id() ] = $item; |
|
| 348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | - |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Removes a specific item. |
|
| 355 | - * |
|
| 356 | - * You should not call this method after the discounts and taxes |
|
| 357 | - * have been calculated. |
|
| 358 | - * |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - */ |
|
| 361 | - public function remove_item( $item_id ) { |
|
| 362 | - |
|
| 363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | - |
|
| 367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | - $this->has_recurring = 0; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - unset( $this->items[ $item_id ] ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Returns the subtotal. |
|
| 378 | - * |
|
| 379 | - * @since 1.0.19 |
|
| 380 | - */ |
|
| 381 | - public function get_subtotal() { |
|
| 382 | - |
|
| 383 | - if ( wpinv_prices_include_tax() ) { |
|
| 384 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - return $this->totals['subtotal']['initial']; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Returns the recurring subtotal. |
|
| 392 | - * |
|
| 393 | - * @since 1.0.19 |
|
| 394 | - */ |
|
| 395 | - public function get_recurring_subtotal() { |
|
| 396 | - |
|
| 397 | - if ( wpinv_prices_include_tax() ) { |
|
| 398 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - return $this->totals['subtotal']['recurring']; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Returns all items. |
|
| 406 | - * |
|
| 407 | - * @since 1.0.19 |
|
| 408 | - * @return GetPaid_Form_Item[] |
|
| 409 | - */ |
|
| 410 | - public function get_items() { |
|
| 411 | - return $this->items; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /* |
|
| 306 | + /** |
|
| 307 | + * Prepares the submission's items. |
|
| 308 | + * |
|
| 309 | + * @since 1.0.19 |
|
| 310 | + */ |
|
| 311 | + public function process_items() { |
|
| 312 | + |
|
| 313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | + |
|
| 315 | + foreach ( $processor->items as $item ) { |
|
| 316 | + $this->add_item( $item ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Adds an item to the submission. |
|
| 324 | + * |
|
| 325 | + * @since 1.0.19 |
|
| 326 | + * @param GetPaid_Form_Item $item |
|
| 327 | + */ |
|
| 328 | + public function add_item( $item ) { |
|
| 329 | + |
|
| 330 | + // Make sure that it is available for purchase. |
|
| 331 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // Each submission can only contain one recurring item. |
|
| 336 | + if ( $item->is_recurring() ) { |
|
| 337 | + |
|
| 338 | + if ( $this->has_recurring != 0 ) { |
|
| 339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $this->has_recurring = $item->get_id(); |
|
| 343 | + |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Update the items and totals. |
|
| 347 | + $this->items[ $item->get_id() ] = $item; |
|
| 348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | + |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Removes a specific item. |
|
| 355 | + * |
|
| 356 | + * You should not call this method after the discounts and taxes |
|
| 357 | + * have been calculated. |
|
| 358 | + * |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + */ |
|
| 361 | + public function remove_item( $item_id ) { |
|
| 362 | + |
|
| 363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | + |
|
| 367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | + $this->has_recurring = 0; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + unset( $this->items[ $item_id ] ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Returns the subtotal. |
|
| 378 | + * |
|
| 379 | + * @since 1.0.19 |
|
| 380 | + */ |
|
| 381 | + public function get_subtotal() { |
|
| 382 | + |
|
| 383 | + if ( wpinv_prices_include_tax() ) { |
|
| 384 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + return $this->totals['subtotal']['initial']; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Returns the recurring subtotal. |
|
| 392 | + * |
|
| 393 | + * @since 1.0.19 |
|
| 394 | + */ |
|
| 395 | + public function get_recurring_subtotal() { |
|
| 396 | + |
|
| 397 | + if ( wpinv_prices_include_tax() ) { |
|
| 398 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + return $this->totals['subtotal']['recurring']; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Returns all items. |
|
| 406 | + * |
|
| 407 | + * @since 1.0.19 |
|
| 408 | + * @return GetPaid_Form_Item[] |
|
| 409 | + */ |
|
| 410 | + public function get_items() { |
|
| 411 | + return $this->items; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /* |
|
| 415 | 415 | |-------------------------------------------------------------------------- |
| 416 | 416 | | Taxes |
| 417 | 417 | |-------------------------------------------------------------------------- |
@@ -420,128 +420,128 @@ discard block |
||
| 420 | 420 | | or only one-time. |
| 421 | 421 | */ |
| 422 | 422 | |
| 423 | - /** |
|
| 424 | - * Prepares the submission's taxes. |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - */ |
|
| 428 | - public function process_taxes() { |
|
| 429 | - |
|
| 430 | - // Abort if we're not using taxes. |
|
| 431 | - if ( ! $this->use_taxes() ) { |
|
| 432 | - return; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 437 | - if ( ! empty( $country ) ) { |
|
| 438 | - $this->country = $country; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 442 | - if ( ! empty( $state ) ) { |
|
| 443 | - $this->state = $state; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - // Confirm if the provided country and the ip country are similar. |
|
| 447 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 448 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 449 | - 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' ) ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - // Abort if the country is not taxable. |
|
| 453 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 454 | - return; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 458 | - |
|
| 459 | - foreach ( $processor->taxes as $tax ) { |
|
| 460 | - $this->add_tax( $tax ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Adds a tax to the submission. |
|
| 468 | - * |
|
| 469 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - */ |
|
| 472 | - public function add_tax( $tax ) { |
|
| 473 | - |
|
| 474 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 475 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 476 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 480 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 481 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 482 | - |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Removes a specific tax. |
|
| 487 | - * |
|
| 488 | - * @since 1.0.19 |
|
| 489 | - */ |
|
| 490 | - public function remove_tax( $tax_name ) { |
|
| 491 | - |
|
| 492 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 493 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 494 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 495 | - unset( $this->taxes[ $tax_name ] ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Whether or not we'll use taxes for the submission. |
|
| 502 | - * |
|
| 503 | - * @since 1.0.19 |
|
| 504 | - */ |
|
| 505 | - public function use_taxes() { |
|
| 506 | - |
|
| 507 | - $use_taxes = wpinv_use_taxes(); |
|
| 508 | - |
|
| 509 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 510 | - $use_taxes = false; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 514 | - |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Returns the tax. |
|
| 519 | - * |
|
| 520 | - * @since 1.0.19 |
|
| 521 | - */ |
|
| 522 | - public function get_tax() { |
|
| 523 | - return $this->totals['taxes']['initial']; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Returns the recurring tax. |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - */ |
|
| 531 | - public function get_recurring_tax() { |
|
| 532 | - return $this->totals['taxes']['recurring']; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Returns all taxes. |
|
| 537 | - * |
|
| 538 | - * @since 1.0.19 |
|
| 539 | - */ |
|
| 540 | - public function get_taxes() { |
|
| 541 | - return $this->taxes; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /* |
|
| 423 | + /** |
|
| 424 | + * Prepares the submission's taxes. |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + */ |
|
| 428 | + public function process_taxes() { |
|
| 429 | + |
|
| 430 | + // Abort if we're not using taxes. |
|
| 431 | + if ( ! $this->use_taxes() ) { |
|
| 432 | + return; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 436 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 437 | + if ( ! empty( $country ) ) { |
|
| 438 | + $this->country = $country; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 442 | + if ( ! empty( $state ) ) { |
|
| 443 | + $this->state = $state; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + // Confirm if the provided country and the ip country are similar. |
|
| 447 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 448 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 449 | + 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' ) ); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + // Abort if the country is not taxable. |
|
| 453 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 454 | + return; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 458 | + |
|
| 459 | + foreach ( $processor->taxes as $tax ) { |
|
| 460 | + $this->add_tax( $tax ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Adds a tax to the submission. |
|
| 468 | + * |
|
| 469 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + */ |
|
| 472 | + public function add_tax( $tax ) { |
|
| 473 | + |
|
| 474 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 475 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 476 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 480 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 481 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 482 | + |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Removes a specific tax. |
|
| 487 | + * |
|
| 488 | + * @since 1.0.19 |
|
| 489 | + */ |
|
| 490 | + public function remove_tax( $tax_name ) { |
|
| 491 | + |
|
| 492 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 493 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 494 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 495 | + unset( $this->taxes[ $tax_name ] ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Whether or not we'll use taxes for the submission. |
|
| 502 | + * |
|
| 503 | + * @since 1.0.19 |
|
| 504 | + */ |
|
| 505 | + public function use_taxes() { |
|
| 506 | + |
|
| 507 | + $use_taxes = wpinv_use_taxes(); |
|
| 508 | + |
|
| 509 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 510 | + $use_taxes = false; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 514 | + |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Returns the tax. |
|
| 519 | + * |
|
| 520 | + * @since 1.0.19 |
|
| 521 | + */ |
|
| 522 | + public function get_tax() { |
|
| 523 | + return $this->totals['taxes']['initial']; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Returns the recurring tax. |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + */ |
|
| 531 | + public function get_recurring_tax() { |
|
| 532 | + return $this->totals['taxes']['recurring']; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Returns all taxes. |
|
| 537 | + * |
|
| 538 | + * @since 1.0.19 |
|
| 539 | + */ |
|
| 540 | + public function get_taxes() { |
|
| 541 | + return $this->taxes; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /* |
|
| 545 | 545 | |-------------------------------------------------------------------------- |
| 546 | 546 | | Discounts |
| 547 | 547 | |-------------------------------------------------------------------------- |
@@ -550,99 +550,99 @@ discard block |
||
| 550 | 550 | | or only one-time. They also do not have to come from a discount code. |
| 551 | 551 | */ |
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Prepares the submission's discount. |
|
| 555 | - * |
|
| 556 | - * @since 1.0.19 |
|
| 557 | - */ |
|
| 558 | - public function process_discount() { |
|
| 559 | - |
|
| 560 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 561 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 562 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 563 | - |
|
| 564 | - foreach ( $processor->discounts as $discount ) { |
|
| 565 | - $this->add_discount( $discount ); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Adds a discount to the submission. |
|
| 573 | - * |
|
| 574 | - * @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. |
|
| 575 | - * @since 1.0.19 |
|
| 576 | - */ |
|
| 577 | - public function add_discount( $discount ) { |
|
| 578 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 579 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 580 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Removes a discount from the submission. |
|
| 585 | - * |
|
| 586 | - * @since 1.0.19 |
|
| 587 | - */ |
|
| 588 | - public function remove_discount( $name ) { |
|
| 589 | - |
|
| 590 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 591 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 592 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 593 | - unset( $this->discounts[ $name ] ); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * Checks whether there is a discount code associated with this submission. |
|
| 600 | - * |
|
| 601 | - * @since 1.0.19 |
|
| 602 | - * @return bool |
|
| 603 | - */ |
|
| 604 | - public function has_discount_code() { |
|
| 605 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Returns the discount code. |
|
| 610 | - * |
|
| 611 | - * @since 1.0.19 |
|
| 612 | - * @return string |
|
| 613 | - */ |
|
| 614 | - public function get_discount_code() { |
|
| 615 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Returns the discount. |
|
| 620 | - * |
|
| 621 | - * @since 1.0.19 |
|
| 622 | - */ |
|
| 623 | - public function get_discount() { |
|
| 624 | - return $this->totals['discount']['initial']; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Returns the recurring discount. |
|
| 629 | - * |
|
| 630 | - * @since 1.0.19 |
|
| 631 | - */ |
|
| 632 | - public function get_recurring_discount() { |
|
| 633 | - return $this->totals['discount']['recurring']; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Returns all discounts. |
|
| 638 | - * |
|
| 639 | - * @since 1.0.19 |
|
| 640 | - */ |
|
| 641 | - public function get_discounts() { |
|
| 642 | - return $this->discounts; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /* |
|
| 553 | + /** |
|
| 554 | + * Prepares the submission's discount. |
|
| 555 | + * |
|
| 556 | + * @since 1.0.19 |
|
| 557 | + */ |
|
| 558 | + public function process_discount() { |
|
| 559 | + |
|
| 560 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 561 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 562 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 563 | + |
|
| 564 | + foreach ( $processor->discounts as $discount ) { |
|
| 565 | + $this->add_discount( $discount ); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Adds a discount to the submission. |
|
| 573 | + * |
|
| 574 | + * @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. |
|
| 575 | + * @since 1.0.19 |
|
| 576 | + */ |
|
| 577 | + public function add_discount( $discount ) { |
|
| 578 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 579 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 580 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Removes a discount from the submission. |
|
| 585 | + * |
|
| 586 | + * @since 1.0.19 |
|
| 587 | + */ |
|
| 588 | + public function remove_discount( $name ) { |
|
| 589 | + |
|
| 590 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 591 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 592 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 593 | + unset( $this->discounts[ $name ] ); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * Checks whether there is a discount code associated with this submission. |
|
| 600 | + * |
|
| 601 | + * @since 1.0.19 |
|
| 602 | + * @return bool |
|
| 603 | + */ |
|
| 604 | + public function has_discount_code() { |
|
| 605 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Returns the discount code. |
|
| 610 | + * |
|
| 611 | + * @since 1.0.19 |
|
| 612 | + * @return string |
|
| 613 | + */ |
|
| 614 | + public function get_discount_code() { |
|
| 615 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Returns the discount. |
|
| 620 | + * |
|
| 621 | + * @since 1.0.19 |
|
| 622 | + */ |
|
| 623 | + public function get_discount() { |
|
| 624 | + return $this->totals['discount']['initial']; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Returns the recurring discount. |
|
| 629 | + * |
|
| 630 | + * @since 1.0.19 |
|
| 631 | + */ |
|
| 632 | + public function get_recurring_discount() { |
|
| 633 | + return $this->totals['discount']['recurring']; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Returns all discounts. |
|
| 638 | + * |
|
| 639 | + * @since 1.0.19 |
|
| 640 | + */ |
|
| 641 | + public function get_discounts() { |
|
| 642 | + return $this->discounts; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /* |
|
| 646 | 646 | |-------------------------------------------------------------------------- |
| 647 | 647 | | Fees |
| 648 | 648 | |-------------------------------------------------------------------------- |
@@ -652,89 +652,89 @@ discard block |
||
| 652 | 652 | | fees. |
| 653 | 653 | */ |
| 654 | 654 | |
| 655 | - /** |
|
| 656 | - * Prepares the submission's fees. |
|
| 657 | - * |
|
| 658 | - * @since 1.0.19 |
|
| 659 | - */ |
|
| 660 | - public function process_fees() { |
|
| 661 | - |
|
| 662 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 663 | - |
|
| 664 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 665 | - $this->add_fee( $fee ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Adds a fee to the submission. |
|
| 673 | - * |
|
| 674 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 675 | - * @since 1.0.19 |
|
| 676 | - */ |
|
| 677 | - public function add_fee( $fee ) { |
|
| 678 | - |
|
| 679 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 680 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 681 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 682 | - |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Removes a fee from the submission. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - */ |
|
| 690 | - public function remove_fee( $name ) { |
|
| 691 | - |
|
| 692 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 693 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 694 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 695 | - unset( $this->fees[ $name ] ); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Returns the fees. |
|
| 702 | - * |
|
| 703 | - * @since 1.0.19 |
|
| 704 | - */ |
|
| 705 | - public function get_fee() { |
|
| 706 | - return $this->totals['fees']['initial']; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Returns the recurring fees. |
|
| 711 | - * |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - */ |
|
| 714 | - public function get_recurring_fee() { |
|
| 715 | - return $this->totals['fees']['recurring']; |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Returns all fees. |
|
| 720 | - * |
|
| 721 | - * @since 1.0.19 |
|
| 722 | - */ |
|
| 723 | - public function get_fees() { |
|
| 724 | - return $this->fees; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * Checks if there are any fees for the form. |
|
| 729 | - * |
|
| 730 | - * @return bool |
|
| 731 | - * @since 1.0.19 |
|
| 732 | - */ |
|
| 733 | - public function has_fees() { |
|
| 734 | - return count( $this->fees ) !== 0; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /* |
|
| 655 | + /** |
|
| 656 | + * Prepares the submission's fees. |
|
| 657 | + * |
|
| 658 | + * @since 1.0.19 |
|
| 659 | + */ |
|
| 660 | + public function process_fees() { |
|
| 661 | + |
|
| 662 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 663 | + |
|
| 664 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 665 | + $this->add_fee( $fee ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Adds a fee to the submission. |
|
| 673 | + * |
|
| 674 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 675 | + * @since 1.0.19 |
|
| 676 | + */ |
|
| 677 | + public function add_fee( $fee ) { |
|
| 678 | + |
|
| 679 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 680 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 681 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 682 | + |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Removes a fee from the submission. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + */ |
|
| 690 | + public function remove_fee( $name ) { |
|
| 691 | + |
|
| 692 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 693 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 694 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 695 | + unset( $this->fees[ $name ] ); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Returns the fees. |
|
| 702 | + * |
|
| 703 | + * @since 1.0.19 |
|
| 704 | + */ |
|
| 705 | + public function get_fee() { |
|
| 706 | + return $this->totals['fees']['initial']; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Returns the recurring fees. |
|
| 711 | + * |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + */ |
|
| 714 | + public function get_recurring_fee() { |
|
| 715 | + return $this->totals['fees']['recurring']; |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Returns all fees. |
|
| 720 | + * |
|
| 721 | + * @since 1.0.19 |
|
| 722 | + */ |
|
| 723 | + public function get_fees() { |
|
| 724 | + return $this->fees; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * Checks if there are any fees for the form. |
|
| 729 | + * |
|
| 730 | + * @return bool |
|
| 731 | + * @since 1.0.19 |
|
| 732 | + */ |
|
| 733 | + public function has_fees() { |
|
| 734 | + return count( $this->fees ) !== 0; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /* |
|
| 738 | 738 | |-------------------------------------------------------------------------- |
| 739 | 739 | | MISC |
| 740 | 740 | |-------------------------------------------------------------------------- |
@@ -742,119 +742,119 @@ discard block |
||
| 742 | 742 | | Extra submission functions. |
| 743 | 743 | */ |
| 744 | 744 | |
| 745 | - /** |
|
| 746 | - * Checks if this is the initial fetch. |
|
| 747 | - * |
|
| 748 | - * @return bool |
|
| 749 | - * @since 1.0.19 |
|
| 750 | - */ |
|
| 751 | - public function is_initial_fetch() { |
|
| 752 | - return empty( $this->data['initial_state'] ); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Returns the total amount to collect for this submission. |
|
| 757 | - * |
|
| 758 | - * @since 1.0.19 |
|
| 759 | - */ |
|
| 760 | - public function get_total() { |
|
| 761 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 762 | - return max( $total, 0 ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Returns the recurring total amount to collect for this submission. |
|
| 767 | - * |
|
| 768 | - * @since 1.0.19 |
|
| 769 | - */ |
|
| 770 | - public function get_recurring_total() { |
|
| 771 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 772 | - return max( $total, 0 ); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * Whether payment details should be collected for this submission. |
|
| 777 | - * |
|
| 778 | - * @since 1.0.19 |
|
| 779 | - */ |
|
| 780 | - public function should_collect_payment_details() { |
|
| 781 | - $initial = $this->get_total(); |
|
| 782 | - $recurring = $this->get_recurring_total(); |
|
| 783 | - |
|
| 784 | - if ( $this->has_recurring == 0 ) { |
|
| 785 | - $recurring = 0; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - $collect = $initial > 0 || $recurring > 0; |
|
| 789 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * Returns the billing email of the user. |
|
| 794 | - * |
|
| 795 | - * @since 1.0.19 |
|
| 796 | - */ |
|
| 797 | - public function get_billing_email() { |
|
| 798 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Checks if the submitter has a billing email. |
|
| 803 | - * |
|
| 804 | - * @since 1.0.19 |
|
| 805 | - */ |
|
| 806 | - public function has_billing_email() { |
|
| 807 | - $billing_email = $this->get_billing_email(); |
|
| 808 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * Returns the appropriate currency for the submission. |
|
| 813 | - * |
|
| 814 | - * @since 1.0.19 |
|
| 815 | - * @return string |
|
| 816 | - */ |
|
| 817 | - public function get_currency() { |
|
| 818 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * Returns the raw submission data. |
|
| 823 | - * |
|
| 824 | - * @since 1.0.19 |
|
| 825 | - * @return array |
|
| 826 | - */ |
|
| 827 | - public function get_data() { |
|
| 828 | - return $this->data; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * Returns a field from the submission data |
|
| 833 | - * |
|
| 834 | - * @param string $field |
|
| 835 | - * @since 1.0.19 |
|
| 836 | - * @return mixed|null |
|
| 837 | - */ |
|
| 838 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 839 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - /** |
|
| 843 | - * Checks if a required field is set. |
|
| 844 | - * |
|
| 845 | - * @since 1.0.19 |
|
| 846 | - */ |
|
| 847 | - public function is_required_field_set( $field ) { |
|
| 848 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * Formats an amount |
|
| 853 | - * |
|
| 854 | - * @since 1.0.19 |
|
| 855 | - */ |
|
| 856 | - public function format_amount( $amount ) { |
|
| 857 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 858 | - } |
|
| 745 | + /** |
|
| 746 | + * Checks if this is the initial fetch. |
|
| 747 | + * |
|
| 748 | + * @return bool |
|
| 749 | + * @since 1.0.19 |
|
| 750 | + */ |
|
| 751 | + public function is_initial_fetch() { |
|
| 752 | + return empty( $this->data['initial_state'] ); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Returns the total amount to collect for this submission. |
|
| 757 | + * |
|
| 758 | + * @since 1.0.19 |
|
| 759 | + */ |
|
| 760 | + public function get_total() { |
|
| 761 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 762 | + return max( $total, 0 ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Returns the recurring total amount to collect for this submission. |
|
| 767 | + * |
|
| 768 | + * @since 1.0.19 |
|
| 769 | + */ |
|
| 770 | + public function get_recurring_total() { |
|
| 771 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 772 | + return max( $total, 0 ); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * Whether payment details should be collected for this submission. |
|
| 777 | + * |
|
| 778 | + * @since 1.0.19 |
|
| 779 | + */ |
|
| 780 | + public function should_collect_payment_details() { |
|
| 781 | + $initial = $this->get_total(); |
|
| 782 | + $recurring = $this->get_recurring_total(); |
|
| 783 | + |
|
| 784 | + if ( $this->has_recurring == 0 ) { |
|
| 785 | + $recurring = 0; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + $collect = $initial > 0 || $recurring > 0; |
|
| 789 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * Returns the billing email of the user. |
|
| 794 | + * |
|
| 795 | + * @since 1.0.19 |
|
| 796 | + */ |
|
| 797 | + public function get_billing_email() { |
|
| 798 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Checks if the submitter has a billing email. |
|
| 803 | + * |
|
| 804 | + * @since 1.0.19 |
|
| 805 | + */ |
|
| 806 | + public function has_billing_email() { |
|
| 807 | + $billing_email = $this->get_billing_email(); |
|
| 808 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * Returns the appropriate currency for the submission. |
|
| 813 | + * |
|
| 814 | + * @since 1.0.19 |
|
| 815 | + * @return string |
|
| 816 | + */ |
|
| 817 | + public function get_currency() { |
|
| 818 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * Returns the raw submission data. |
|
| 823 | + * |
|
| 824 | + * @since 1.0.19 |
|
| 825 | + * @return array |
|
| 826 | + */ |
|
| 827 | + public function get_data() { |
|
| 828 | + return $this->data; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * Returns a field from the submission data |
|
| 833 | + * |
|
| 834 | + * @param string $field |
|
| 835 | + * @since 1.0.19 |
|
| 836 | + * @return mixed|null |
|
| 837 | + */ |
|
| 838 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 839 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + /** |
|
| 843 | + * Checks if a required field is set. |
|
| 844 | + * |
|
| 845 | + * @since 1.0.19 |
|
| 846 | + */ |
|
| 847 | + public function is_required_field_set( $field ) { |
|
| 848 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * Formats an amount |
|
| 853 | + * |
|
| 854 | + * @since 1.0.19 |
|
| 855 | + */ |
|
| 856 | + public function format_amount( $amount ) { |
|
| 857 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | 860 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | $this->state = wpinv_get_default_state(); |
| 135 | 135 | |
| 136 | 136 | // Do we have an actual submission? |
| 137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | - $this->load_data( $_POST ); |
|
| 137 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 138 | + $this->load_data($_POST); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | } |
@@ -145,19 +145,19 @@ discard block |
||
| 145 | 145 | * |
| 146 | 146 | * @param array $data |
| 147 | 147 | */ |
| 148 | - public function load_data( $data ) { |
|
| 148 | + public function load_data($data) { |
|
| 149 | 149 | |
| 150 | 150 | // Remove slashes from the submitted data... |
| 151 | - $data = wp_unslash( $data ); |
|
| 151 | + $data = wp_unslash($data); |
|
| 152 | 152 | |
| 153 | 153 | // Allow plugins to filter the data. |
| 154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 154 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 155 | 155 | |
| 156 | 156 | // Cache it... |
| 157 | 157 | $this->data = $data; |
| 158 | 158 | |
| 159 | 159 | // Then generate a unique id from the data. |
| 160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 160 | + $this->id = md5(wp_json_encode($data)); |
|
| 161 | 161 | |
| 162 | 162 | // Finally, process the submission. |
| 163 | 163 | try { |
@@ -167,26 +167,26 @@ discard block |
||
| 167 | 167 | $processors = apply_filters( |
| 168 | 168 | 'getpaid_payment_form_submission_processors', |
| 169 | 169 | array( |
| 170 | - array( $this, 'process_payment_form' ), |
|
| 171 | - array( $this, 'process_invoice' ), |
|
| 172 | - array( $this, 'process_fees' ), |
|
| 173 | - array( $this, 'process_items' ), |
|
| 174 | - array( $this, 'process_discount' ), |
|
| 175 | - array( $this, 'process_taxes' ), |
|
| 170 | + array($this, 'process_payment_form'), |
|
| 171 | + array($this, 'process_invoice'), |
|
| 172 | + array($this, 'process_fees'), |
|
| 173 | + array($this, 'process_items'), |
|
| 174 | + array($this, 'process_discount'), |
|
| 175 | + array($this, 'process_taxes'), |
|
| 176 | 176 | ), |
| 177 | 177 | $this |
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | - foreach ( $processors as $processor ) { |
|
| 181 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 180 | + foreach ($processors as $processor) { |
|
| 181 | + call_user_func_array($processor, array(&$this)); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - } catch ( Exception $e ) { |
|
| 184 | + } catch (Exception $e) { |
|
| 185 | 185 | $this->last_error = $e->getMessage(); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Fired when we are done processing a submission. |
| 189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 189 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 190 | 190 | |
| 191 | 191 | } |
| 192 | 192 | |
@@ -207,18 +207,18 @@ discard block |
||
| 207 | 207 | public function process_payment_form() { |
| 208 | 208 | |
| 209 | 209 | // Every submission needs an active payment form. |
| 210 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 210 | + if (empty($this->data['form_id'])) { |
|
| 211 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // Fetch the payment form. |
| 215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 215 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 216 | 216 | |
| 217 | - if ( ! $this->payment_form->is_active() ) { |
|
| 218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 217 | + if (!$this->payment_form->is_active()) { |
|
| 218 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 221 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -248,30 +248,30 @@ discard block |
||
| 248 | 248 | public function process_invoice() { |
| 249 | 249 | |
| 250 | 250 | // Abort if there is no invoice. |
| 251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 251 | + if (empty($this->data['invoice_id'])) { |
|
| 252 | 252 | return; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // If the submission is for an existing invoice, ensure that it exists |
| 256 | 256 | // and that it is not paid for. |
| 257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 257 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 258 | 258 | |
| 259 | - if ( empty( $invoice ) ) { |
|
| 260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 259 | + if (empty($invoice)) { |
|
| 260 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( $invoice->is_paid() ) { |
|
| 264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 263 | + if ($invoice->is_paid()) { |
|
| 264 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 267 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 268 | 268 | $this->payment_form->invoice = $invoice; |
| 269 | 269 | |
| 270 | 270 | $this->country = $invoice->get_country(); |
| 271 | 271 | $this->state = $invoice->get_state(); |
| 272 | 272 | $this->invoice = $invoice; |
| 273 | 273 | |
| 274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 274 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @return bool |
| 292 | 292 | */ |
| 293 | 293 | public function has_invoice() { |
| 294 | - return ! empty( $this->invoice ); |
|
| 294 | + return !empty($this->invoice); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /* |
@@ -310,13 +310,13 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | public function process_items() { |
| 312 | 312 | |
| 313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 313 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 314 | 314 | |
| 315 | - foreach ( $processor->items as $item ) { |
|
| 316 | - $this->add_item( $item ); |
|
| 315 | + foreach ($processor->items as $item) { |
|
| 316 | + $this->add_item($item); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 319 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -325,18 +325,18 @@ discard block |
||
| 325 | 325 | * @since 1.0.19 |
| 326 | 326 | * @param GetPaid_Form_Item $item |
| 327 | 327 | */ |
| 328 | - public function add_item( $item ) { |
|
| 328 | + public function add_item($item) { |
|
| 329 | 329 | |
| 330 | 330 | // Make sure that it is available for purchase. |
| 331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 331 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
| 332 | 332 | return; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // Each submission can only contain one recurring item. |
| 336 | - if ( $item->is_recurring() ) { |
|
| 336 | + if ($item->is_recurring()) { |
|
| 337 | 337 | |
| 338 | - if ( $this->has_recurring != 0 ) { |
|
| 339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 338 | + if ($this->has_recurring != 0) { |
|
| 339 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | $this->has_recurring = $item->get_id(); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Update the items and totals. |
| 347 | - $this->items[ $item->get_id() ] = $item; |
|
| 347 | + $this->items[$item->get_id()] = $item; |
|
| 348 | 348 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 349 | 349 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 350 | 350 | |
@@ -358,17 +358,17 @@ discard block |
||
| 358 | 358 | * |
| 359 | 359 | * @since 1.0.19 |
| 360 | 360 | */ |
| 361 | - public function remove_item( $item_id ) { |
|
| 361 | + public function remove_item($item_id) { |
|
| 362 | 362 | |
| 363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 363 | + if (isset($this->items[$item_id])) { |
|
| 364 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 365 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 366 | 366 | |
| 367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 367 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 368 | 368 | $this->has_recurring = 0; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - unset( $this->items[ $item_id ] ); |
|
| 371 | + unset($this->items[$item_id]); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | } |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | */ |
| 381 | 381 | public function get_subtotal() { |
| 382 | 382 | |
| 383 | - if ( wpinv_prices_include_tax() ) { |
|
| 383 | + if (wpinv_prices_include_tax()) { |
|
| 384 | 384 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | public function get_recurring_subtotal() { |
| 396 | 396 | |
| 397 | - if ( wpinv_prices_include_tax() ) { |
|
| 397 | + if (wpinv_prices_include_tax()) { |
|
| 398 | 398 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -428,39 +428,39 @@ discard block |
||
| 428 | 428 | public function process_taxes() { |
| 429 | 429 | |
| 430 | 430 | // Abort if we're not using taxes. |
| 431 | - if ( ! $this->use_taxes() ) { |
|
| 431 | + if (!$this->use_taxes()) { |
|
| 432 | 432 | return; |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 437 | - if ( ! empty( $country ) ) { |
|
| 436 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
| 437 | + if (!empty($country)) { |
|
| 438 | 438 | $this->country = $country; |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 442 | - if ( ! empty( $state ) ) { |
|
| 441 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
| 442 | + if (!empty($state)) { |
|
| 443 | 443 | $this->state = $state; |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | // Confirm if the provided country and the ip country are similar. |
| 447 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 448 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 449 | - 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' ) ); |
|
| 447 | + $address_confirmed = $this->get_field('confirm-address'); |
|
| 448 | + if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
| 449 | + 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')); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | // Abort if the country is not taxable. |
| 453 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 453 | + if (!wpinv_is_country_taxable($this->country)) { |
|
| 454 | 454 | return; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 457 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 458 | 458 | |
| 459 | - foreach ( $processor->taxes as $tax ) { |
|
| 460 | - $this->add_tax( $tax ); |
|
| 459 | + foreach ($processor->taxes as $tax) { |
|
| 460 | + $this->add_tax($tax); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 463 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -469,16 +469,16 @@ discard block |
||
| 469 | 469 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 470 | 470 | * @since 1.0.19 |
| 471 | 471 | */ |
| 472 | - public function add_tax( $tax ) { |
|
| 472 | + public function add_tax($tax) { |
|
| 473 | 473 | |
| 474 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 475 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 476 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 474 | + if (wpinv_round_tax_per_tax_rate()) { |
|
| 475 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
| 476 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 480 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 481 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 479 | + $this->taxes[$tax['name']] = $tax; |
|
| 480 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 481 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 482 | 482 | |
| 483 | 483 | } |
| 484 | 484 | |
@@ -487,12 +487,12 @@ discard block |
||
| 487 | 487 | * |
| 488 | 488 | * @since 1.0.19 |
| 489 | 489 | */ |
| 490 | - public function remove_tax( $tax_name ) { |
|
| 490 | + public function remove_tax($tax_name) { |
|
| 491 | 491 | |
| 492 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 493 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 494 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 495 | - unset( $this->taxes[ $tax_name ] ); |
|
| 492 | + if (isset($this->taxes[$tax_name])) { |
|
| 493 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 494 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 495 | + unset($this->taxes[$tax_name]); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | } |
@@ -506,11 +506,11 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | $use_taxes = wpinv_use_taxes(); |
| 508 | 508 | |
| 509 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 509 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 510 | 510 | $use_taxes = false; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 513 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 514 | 514 | |
| 515 | 515 | } |
| 516 | 516 | |
@@ -559,13 +559,13 @@ discard block |
||
| 559 | 559 | |
| 560 | 560 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 561 | 561 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 562 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 562 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 563 | 563 | |
| 564 | - foreach ( $processor->discounts as $discount ) { |
|
| 565 | - $this->add_discount( $discount ); |
|
| 564 | + foreach ($processor->discounts as $discount) { |
|
| 565 | + $this->add_discount($discount); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 568 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /** |
@@ -574,10 +574,10 @@ discard block |
||
| 574 | 574 | * @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. |
| 575 | 575 | * @since 1.0.19 |
| 576 | 576 | */ |
| 577 | - public function add_discount( $discount ) { |
|
| 578 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 579 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 580 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 577 | + public function add_discount($discount) { |
|
| 578 | + $this->discounts[$discount['name']] = $discount; |
|
| 579 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 580 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
@@ -585,12 +585,12 @@ discard block |
||
| 585 | 585 | * |
| 586 | 586 | * @since 1.0.19 |
| 587 | 587 | */ |
| 588 | - public function remove_discount( $name ) { |
|
| 588 | + public function remove_discount($name) { |
|
| 589 | 589 | |
| 590 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 591 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 592 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 593 | - unset( $this->discounts[ $name ] ); |
|
| 590 | + if (isset($this->discounts[$name])) { |
|
| 591 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 592 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 593 | + unset($this->discounts[$name]); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | } |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @return bool |
| 603 | 603 | */ |
| 604 | 604 | public function has_discount_code() { |
| 605 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 605 | + return !empty($this->discounts['discount_code']); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -659,13 +659,13 @@ discard block |
||
| 659 | 659 | */ |
| 660 | 660 | public function process_fees() { |
| 661 | 661 | |
| 662 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 662 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 663 | 663 | |
| 664 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 665 | - $this->add_fee( $fee ); |
|
| 664 | + foreach ($fees_processor->fees as $fee) { |
|
| 665 | + $this->add_fee($fee); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 668 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -674,11 +674,11 @@ discard block |
||
| 674 | 674 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 675 | 675 | * @since 1.0.19 |
| 676 | 676 | */ |
| 677 | - public function add_fee( $fee ) { |
|
| 677 | + public function add_fee($fee) { |
|
| 678 | 678 | |
| 679 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 680 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 681 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 679 | + $this->fees[$fee['name']] = $fee; |
|
| 680 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 681 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 682 | 682 | |
| 683 | 683 | } |
| 684 | 684 | |
@@ -687,12 +687,12 @@ discard block |
||
| 687 | 687 | * |
| 688 | 688 | * @since 1.0.19 |
| 689 | 689 | */ |
| 690 | - public function remove_fee( $name ) { |
|
| 690 | + public function remove_fee($name) { |
|
| 691 | 691 | |
| 692 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 693 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 694 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 695 | - unset( $this->fees[ $name ] ); |
|
| 692 | + if (isset($this->fees[$name])) { |
|
| 693 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 694 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 695 | + unset($this->fees[$name]); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | } |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | * @since 1.0.19 |
| 732 | 732 | */ |
| 733 | 733 | public function has_fees() { |
| 734 | - return count( $this->fees ) !== 0; |
|
| 734 | + return count($this->fees) !== 0; |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /* |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | * @since 1.0.19 |
| 750 | 750 | */ |
| 751 | 751 | public function is_initial_fetch() { |
| 752 | - return empty( $this->data['initial_state'] ); |
|
| 752 | + return empty($this->data['initial_state']); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | */ |
| 760 | 760 | public function get_total() { |
| 761 | 761 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
| 762 | - return max( $total, 0 ); |
|
| 762 | + return max($total, 0); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | */ |
| 770 | 770 | public function get_recurring_total() { |
| 771 | 771 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
| 772 | - return max( $total, 0 ); |
|
| 772 | + return max($total, 0); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /** |
@@ -781,12 +781,12 @@ discard block |
||
| 781 | 781 | $initial = $this->get_total(); |
| 782 | 782 | $recurring = $this->get_recurring_total(); |
| 783 | 783 | |
| 784 | - if ( $this->has_recurring == 0 ) { |
|
| 784 | + if ($this->has_recurring == 0) { |
|
| 785 | 785 | $recurring = 0; |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | $collect = $initial > 0 || $recurring > 0; |
| 789 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 789 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | * @since 1.0.19 |
| 796 | 796 | */ |
| 797 | 797 | public function get_billing_email() { |
| 798 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 798 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | /** |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | */ |
| 806 | 806 | public function has_billing_email() { |
| 807 | 807 | $billing_email = $this->get_billing_email(); |
| 808 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 808 | + return !empty($billing_email) && is_email($billing_email); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /** |
@@ -835,8 +835,8 @@ discard block |
||
| 835 | 835 | * @since 1.0.19 |
| 836 | 836 | * @return mixed|null |
| 837 | 837 | */ |
| 838 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 839 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 838 | + public function get_field($field, $sub_array_key = null) { |
|
| 839 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -844,8 +844,8 @@ discard block |
||
| 844 | 844 | * |
| 845 | 845 | * @since 1.0.19 |
| 846 | 846 | */ |
| 847 | - public function is_required_field_set( $field ) { |
|
| 848 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 847 | + public function is_required_field_set($field) { |
|
| 848 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -853,8 +853,8 @@ discard block |
||
| 853 | 853 | * |
| 854 | 854 | * @since 1.0.19 |
| 855 | 855 | */ |
| 856 | - public function format_amount( $amount ) { |
|
| 857 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 856 | + public function format_amount($amount) { |
|
| 857 | + return wpinv_price($amount, $this->get_currency()); |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | } |