@@ -12,285 +12,285 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 34 | - ); |
|
| 35 | - |
|
| 36 | - $this->add_totals( $submission ); |
|
| 37 | - $this->add_texts( $submission ); |
|
| 38 | - $this->add_items( $submission ); |
|
| 39 | - $this->add_fees( $submission ); |
|
| 40 | - $this->add_discounts( $submission ); |
|
| 41 | - $this->add_taxes( $submission ); |
|
| 42 | - $this->add_gateways( $submission ); |
|
| 43 | - $this->add_data( $submission ); |
|
| 44 | - |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Adds totals to a response for submission refresh prices. |
|
| 49 | - * |
|
| 50 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 51 | - */ |
|
| 52 | - public function add_totals( $submission ) { |
|
| 53 | - |
|
| 54 | - $this->response = array_merge( |
|
| 55 | - $this->response, |
|
| 56 | - array( |
|
| 57 | - |
|
| 58 | - 'totals' => array( |
|
| 59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 65 | - ), |
|
| 66 | - |
|
| 67 | - 'recurring' => array( |
|
| 68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 73 | - ), |
|
| 74 | - |
|
| 75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 76 | - 'currency' => $submission->get_currency(), |
|
| 77 | - |
|
| 78 | - ) |
|
| 79 | - ); |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Adds texts to a response for submission refresh prices. |
|
| 85 | - * |
|
| 86 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 87 | - */ |
|
| 88 | - public function add_texts( $submission ) { |
|
| 89 | - |
|
| 90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 92 | - |
|
| 93 | - if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
| 94 | - |
|
| 95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 97 | - |
|
| 98 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 99 | - $payable = "$payable / $period"; |
|
| 100 | - } else { |
|
| 101 | - $payable = sprintf( |
|
| 102 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 103 | - $submission->format_amount( $submission->get_total() ), |
|
| 104 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 105 | - $period |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $texts = array( |
|
| 112 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 113 | - ); |
|
| 114 | - |
|
| 115 | - foreach ( $submission->get_items() as $item ) { |
|
| 116 | - $item_id = $item->get_id(); |
|
| 117 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 118 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 119 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 123 | - |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Adds items to a response for submission refresh prices. |
|
| 128 | - * |
|
| 129 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 130 | - */ |
|
| 131 | - public function add_items( $submission ) { |
|
| 132 | - |
|
| 133 | - // Add items. |
|
| 134 | - $items = array(); |
|
| 34 | + ); |
|
| 35 | + |
|
| 36 | + $this->add_totals( $submission ); |
|
| 37 | + $this->add_texts( $submission ); |
|
| 38 | + $this->add_items( $submission ); |
|
| 39 | + $this->add_fees( $submission ); |
|
| 40 | + $this->add_discounts( $submission ); |
|
| 41 | + $this->add_taxes( $submission ); |
|
| 42 | + $this->add_gateways( $submission ); |
|
| 43 | + $this->add_data( $submission ); |
|
| 44 | + |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Adds totals to a response for submission refresh prices. |
|
| 49 | + * |
|
| 50 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 51 | + */ |
|
| 52 | + public function add_totals( $submission ) { |
|
| 53 | + |
|
| 54 | + $this->response = array_merge( |
|
| 55 | + $this->response, |
|
| 56 | + array( |
|
| 57 | + |
|
| 58 | + 'totals' => array( |
|
| 59 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 65 | + ), |
|
| 66 | + |
|
| 67 | + 'recurring' => array( |
|
| 68 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 73 | + ), |
|
| 74 | + |
|
| 75 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 76 | + 'currency' => $submission->get_currency(), |
|
| 77 | + |
|
| 78 | + ) |
|
| 79 | + ); |
|
| 80 | + |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Adds texts to a response for submission refresh prices. |
|
| 85 | + * |
|
| 86 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 87 | + */ |
|
| 88 | + public function add_texts( $submission ) { |
|
| 89 | + |
|
| 90 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
| 92 | + |
|
| 93 | + if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
| 94 | + |
|
| 95 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 97 | + |
|
| 98 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 99 | + $payable = "$payable / $period"; |
|
| 100 | + } else { |
|
| 101 | + $payable = sprintf( |
|
| 102 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 103 | + $submission->format_amount( $submission->get_total() ), |
|
| 104 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 105 | + $period |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $texts = array( |
|
| 112 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 113 | + ); |
|
| 114 | + |
|
| 115 | + foreach ( $submission->get_items() as $item ) { |
|
| 116 | + $item_id = $item->get_id(); |
|
| 117 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 118 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 119 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 123 | + |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Adds items to a response for submission refresh prices. |
|
| 128 | + * |
|
| 129 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 130 | + */ |
|
| 131 | + public function add_items( $submission ) { |
|
| 132 | + |
|
| 133 | + // Add items. |
|
| 134 | + $items = array(); |
|
| 135 | 135 | |
| 136 | 136 | foreach ( $submission->get_items() as $item ) { |
| 137 | - $item_id = $item->get_id(); |
|
| 138 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 139 | - } |
|
| 137 | + $item_id = $item->get_id(); |
|
| 138 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $this->response = array_merge( |
|
| 142 | - $this->response, |
|
| 143 | - array( 'items' => $items ) |
|
| 144 | - ); |
|
| 141 | + $this->response = array_merge( |
|
| 142 | + $this->response, |
|
| 143 | + array( 'items' => $items ) |
|
| 144 | + ); |
|
| 145 | 145 | |
| 146 | - } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Adds fees to a response for submission refresh prices. |
|
| 150 | - * |
|
| 151 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 152 | - */ |
|
| 153 | - public function add_fees( $submission ) { |
|
| 148 | + /** |
|
| 149 | + * Adds fees to a response for submission refresh prices. |
|
| 150 | + * |
|
| 151 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 152 | + */ |
|
| 153 | + public function add_fees( $submission ) { |
|
| 154 | 154 | |
| 155 | - $fees = array(); |
|
| 155 | + $fees = array(); |
|
| 156 | 156 | |
| 157 | 157 | foreach ( $submission->get_fees() as $name => $data ) { |
| 158 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 159 | - } |
|
| 158 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - $this->response = array_merge( |
|
| 162 | - $this->response, |
|
| 163 | - array( 'fees' => $fees ) |
|
| 164 | - ); |
|
| 161 | + $this->response = array_merge( |
|
| 162 | + $this->response, |
|
| 163 | + array( 'fees' => $fees ) |
|
| 164 | + ); |
|
| 165 | 165 | |
| 166 | - } |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Adds discounts to a response for submission refresh prices. |
|
| 170 | - * |
|
| 171 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 172 | - */ |
|
| 173 | - public function add_discounts( $submission ) { |
|
| 168 | + /** |
|
| 169 | + * Adds discounts to a response for submission refresh prices. |
|
| 170 | + * |
|
| 171 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 172 | + */ |
|
| 173 | + public function add_discounts( $submission ) { |
|
| 174 | 174 | |
| 175 | - $discounts = array(); |
|
| 175 | + $discounts = array(); |
|
| 176 | 176 | |
| 177 | 177 | foreach ( $submission->get_discounts() as $name => $data ) { |
| 178 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $this->response = array_merge( |
|
| 182 | - $this->response, |
|
| 183 | - array( 'discounts' => $discounts ) |
|
| 184 | - ); |
|
| 178 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 179 | + } |
|
| 185 | 180 | |
| 186 | - } |
|
| 181 | + $this->response = array_merge( |
|
| 182 | + $this->response, |
|
| 183 | + array( 'discounts' => $discounts ) |
|
| 184 | + ); |
|
| 187 | 185 | |
| 188 | - /** |
|
| 189 | - * Adds taxes to a response for submission refresh prices. |
|
| 190 | - * |
|
| 191 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 192 | - */ |
|
| 193 | - public function add_taxes( $submission ) { |
|
| 186 | + } |
|
| 194 | 187 | |
| 195 | - $taxes = array(); |
|
| 196 | - $markup = ''; |
|
| 188 | + /** |
|
| 189 | + * Adds taxes to a response for submission refresh prices. |
|
| 190 | + * |
|
| 191 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 192 | + */ |
|
| 193 | + public function add_taxes( $submission ) { |
|
| 194 | + |
|
| 195 | + $taxes = array(); |
|
| 196 | + $markup = ''; |
|
| 197 | 197 | foreach ( $submission->get_taxes() as $name => $data ) { |
| 198 | - $name = sanitize_text_field( $name ); |
|
| 199 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 200 | - $taxes[$name] = $amount; |
|
| 201 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 205 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $this->response = array_merge( |
|
| 209 | - $this->response, |
|
| 210 | - array( 'taxes' => $taxes ) |
|
| 211 | - ); |
|
| 212 | - |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Adds gateways to a response for submission refresh prices. |
|
| 217 | - * |
|
| 218 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 219 | - */ |
|
| 220 | - public function add_gateways( $submission ) { |
|
| 221 | - |
|
| 222 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 223 | - |
|
| 224 | - if ( $this->response['has_recurring'] ) { |
|
| 225 | - |
|
| 226 | - foreach ( $gateways as $i => $gateway ) { |
|
| 227 | - |
|
| 228 | - if ( |
|
| 229 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 230 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 231 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 232 | - unset( $gateways[ $i ] ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 240 | - $this->response = array_merge( |
|
| 241 | - $this->response, |
|
| 242 | - array( 'gateways' => $gateways ) |
|
| 243 | - ); |
|
| 244 | - |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Standardizes prices. |
|
| 249 | - * |
|
| 250 | - * @param int $item_id |
|
| 251 | - * @param float $item_total |
|
| 252 | - * @param string $discount_code |
|
| 253 | - * @param bool $recurring |
|
| 254 | - */ |
|
| 255 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 256 | - |
|
| 257 | - $standardadized_price = $item_total; |
|
| 258 | - |
|
| 259 | - // Do we have a $discount_code? |
|
| 260 | - if ( ! empty( $discount_code ) ) { |
|
| 261 | - |
|
| 262 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 263 | - |
|
| 264 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 265 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return max( 0, $standardadized_price ); |
|
| 271 | - |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Adds data to a response for submission refresh prices. |
|
| 276 | - * |
|
| 277 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 278 | - */ |
|
| 279 | - public function add_data( $submission ) { |
|
| 280 | - |
|
| 281 | - $this->response = array_merge( |
|
| 282 | - $this->response, |
|
| 283 | - array( |
|
| 284 | - 'js_data' => apply_filters( |
|
| 285 | - 'getpaid_submission_js_data', |
|
| 286 | - array( |
|
| 287 | - 'is_recurring' => $this->response['has_recurring'], |
|
| 288 | - ), |
|
| 289 | - $submission |
|
| 290 | - ) |
|
| 291 | - ) |
|
| 292 | - ); |
|
| 293 | - |
|
| 294 | - } |
|
| 198 | + $name = sanitize_text_field( $name ); |
|
| 199 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 200 | + $taxes[$name] = $amount; |
|
| 201 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 205 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $this->response = array_merge( |
|
| 209 | + $this->response, |
|
| 210 | + array( 'taxes' => $taxes ) |
|
| 211 | + ); |
|
| 212 | + |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Adds gateways to a response for submission refresh prices. |
|
| 217 | + * |
|
| 218 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 219 | + */ |
|
| 220 | + public function add_gateways( $submission ) { |
|
| 221 | + |
|
| 222 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 223 | + |
|
| 224 | + if ( $this->response['has_recurring'] ) { |
|
| 225 | + |
|
| 226 | + foreach ( $gateways as $i => $gateway ) { |
|
| 227 | + |
|
| 228 | + if ( |
|
| 229 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 230 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 231 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 232 | + unset( $gateways[ $i ] ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 240 | + $this->response = array_merge( |
|
| 241 | + $this->response, |
|
| 242 | + array( 'gateways' => $gateways ) |
|
| 243 | + ); |
|
| 244 | + |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Standardizes prices. |
|
| 249 | + * |
|
| 250 | + * @param int $item_id |
|
| 251 | + * @param float $item_total |
|
| 252 | + * @param string $discount_code |
|
| 253 | + * @param bool $recurring |
|
| 254 | + */ |
|
| 255 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 256 | + |
|
| 257 | + $standardadized_price = $item_total; |
|
| 258 | + |
|
| 259 | + // Do we have a $discount_code? |
|
| 260 | + if ( ! empty( $discount_code ) ) { |
|
| 261 | + |
|
| 262 | + $discount = new WPInv_Discount( $discount_code ); |
|
| 263 | + |
|
| 264 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 265 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return max( 0, $standardadized_price ); |
|
| 271 | + |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Adds data to a response for submission refresh prices. |
|
| 276 | + * |
|
| 277 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 278 | + */ |
|
| 279 | + public function add_data( $submission ) { |
|
| 280 | + |
|
| 281 | + $this->response = array_merge( |
|
| 282 | + $this->response, |
|
| 283 | + array( |
|
| 284 | + 'js_data' => apply_filters( |
|
| 285 | + 'getpaid_submission_js_data', |
|
| 286 | + array( |
|
| 287 | + 'is_recurring' => $this->response['has_recurring'], |
|
| 288 | + ), |
|
| 289 | + $submission |
|
| 290 | + ) |
|
| 291 | + ) |
|
| 292 | + ); |
|
| 293 | + |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | 296 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission refresh prices class |
@@ -23,24 +23,24 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
| 25 | 25 | */ |
| 26 | - public function __construct( $submission ) { |
|
| 26 | + public function __construct($submission) { |
|
| 27 | 27 | |
| 28 | 28 | $this->response = array( |
| 29 | 29 | 'submission_id' => $submission->id, |
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | 31 | 'has_subscription_group' => $submission->has_subscription_group(), |
| 32 | 32 | 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
| 33 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
| 33 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - $this->add_totals( $submission ); |
|
| 37 | - $this->add_texts( $submission ); |
|
| 38 | - $this->add_items( $submission ); |
|
| 39 | - $this->add_fees( $submission ); |
|
| 40 | - $this->add_discounts( $submission ); |
|
| 41 | - $this->add_taxes( $submission ); |
|
| 42 | - $this->add_gateways( $submission ); |
|
| 43 | - $this->add_data( $submission ); |
|
| 36 | + $this->add_totals($submission); |
|
| 37 | + $this->add_texts($submission); |
|
| 38 | + $this->add_items($submission); |
|
| 39 | + $this->add_fees($submission); |
|
| 40 | + $this->add_discounts($submission); |
|
| 41 | + $this->add_taxes($submission); |
|
| 42 | + $this->add_gateways($submission); |
|
| 43 | + $this->add_data($submission); |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | 46 | |
@@ -49,30 +49,30 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @param GetPaid_Payment_Form_Submission $submission |
| 51 | 51 | */ |
| 52 | - public function add_totals( $submission ) { |
|
| 52 | + public function add_totals($submission) { |
|
| 53 | 53 | |
| 54 | 54 | $this->response = array_merge( |
| 55 | 55 | $this->response, |
| 56 | 56 | array( |
| 57 | 57 | |
| 58 | 58 | 'totals' => array( |
| 59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 59 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
| 60 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
| 61 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
| 62 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
| 63 | + 'total' => $submission->format_amount($submission->get_total()), |
|
| 64 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
| 65 | 65 | ), |
| 66 | 66 | |
| 67 | 67 | 'recurring' => array( |
| 68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 68 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
| 69 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
| 70 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
| 71 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
| 72 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
| 73 | 73 | ), |
| 74 | 74 | |
| 75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 75 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
| 76 | 76 | 'currency' => $submission->get_currency(), |
| 77 | 77 | |
| 78 | 78 | ) |
@@ -85,23 +85,23 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @param GetPaid_Payment_Form_Submission $submission |
| 87 | 87 | */ |
| 88 | - public function add_texts( $submission ) { |
|
| 88 | + public function add_texts($submission) { |
|
| 89 | 89 | |
| 90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 90 | + $payable = $submission->format_amount($submission->get_total()); |
|
| 91 | + $groups = getpaid_get_subscription_groups($submission); |
|
| 92 | 92 | |
| 93 | - if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
| 93 | + if ($submission->has_recurring != 0 && 2 > $groups) { |
|
| 94 | 94 | |
| 95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 95 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
| 96 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
| 97 | 97 | |
| 98 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 98 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
| 99 | 99 | $payable = "$payable / $period"; |
| 100 | 100 | } else { |
| 101 | 101 | $payable = sprintf( |
| 102 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 103 | - $submission->format_amount( $submission->get_total() ), |
|
| 104 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 102 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
| 103 | + $submission->format_amount($submission->get_total()), |
|
| 104 | + $submission->format_amount($submission->get_recurring_total()), |
|
| 105 | 105 | $period |
| 106 | 106 | ); |
| 107 | 107 | } |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | '.getpaid-checkout-total-payable' => $payable, |
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | - foreach ( $submission->get_items() as $item ) { |
|
| 115 | + foreach ($submission->get_items() as $item) { |
|
| 116 | 116 | $item_id = $item->get_id(); |
| 117 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 118 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 119 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 117 | + $initial_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false)); |
|
| 118 | + $recurring_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true)); |
|
| 119 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 122 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
@@ -128,19 +128,19 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @param GetPaid_Payment_Form_Submission $submission |
| 130 | 130 | */ |
| 131 | - public function add_items( $submission ) { |
|
| 131 | + public function add_items($submission) { |
|
| 132 | 132 | |
| 133 | 133 | // Add items. |
| 134 | 134 | $items = array(); |
| 135 | 135 | |
| 136 | - foreach ( $submission->get_items() as $item ) { |
|
| 136 | + foreach ($submission->get_items() as $item) { |
|
| 137 | 137 | $item_id = $item->get_id(); |
| 138 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 138 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $this->response = array_merge( |
| 142 | 142 | $this->response, |
| 143 | - array( 'items' => $items ) |
|
| 143 | + array('items' => $items) |
|
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | 146 | } |
@@ -150,17 +150,17 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @param GetPaid_Payment_Form_Submission $submission |
| 152 | 152 | */ |
| 153 | - public function add_fees( $submission ) { |
|
| 153 | + public function add_fees($submission) { |
|
| 154 | 154 | |
| 155 | 155 | $fees = array(); |
| 156 | 156 | |
| 157 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
| 158 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 157 | + foreach ($submission->get_fees() as $name => $data) { |
|
| 158 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | $this->response = array_merge( |
| 162 | 162 | $this->response, |
| 163 | - array( 'fees' => $fees ) |
|
| 163 | + array('fees' => $fees) |
|
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | 166 | } |
@@ -170,17 +170,17 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @param GetPaid_Payment_Form_Submission $submission |
| 172 | 172 | */ |
| 173 | - public function add_discounts( $submission ) { |
|
| 173 | + public function add_discounts($submission) { |
|
| 174 | 174 | |
| 175 | 175 | $discounts = array(); |
| 176 | 176 | |
| 177 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 178 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 177 | + foreach ($submission->get_discounts() as $name => $data) { |
|
| 178 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $this->response = array_merge( |
| 182 | 182 | $this->response, |
| 183 | - array( 'discounts' => $discounts ) |
|
| 183 | + array('discounts' => $discounts) |
|
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | 186 | } |
@@ -190,24 +190,24 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @param GetPaid_Payment_Form_Submission $submission |
| 192 | 192 | */ |
| 193 | - public function add_taxes( $submission ) { |
|
| 193 | + public function add_taxes($submission) { |
|
| 194 | 194 | |
| 195 | 195 | $taxes = array(); |
| 196 | 196 | $markup = ''; |
| 197 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 198 | - $name = sanitize_text_field( $name ); |
|
| 199 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 197 | + foreach ($submission->get_taxes() as $name => $data) { |
|
| 198 | + $name = sanitize_text_field($name); |
|
| 199 | + $amount = $submission->format_amount($data['initial_tax']); |
|
| 200 | 200 | $taxes[$name] = $amount; |
| 201 | 201 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 204 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
| 205 | 205 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $this->response = array_merge( |
| 209 | 209 | $this->response, |
| 210 | - array( 'taxes' => $taxes ) |
|
| 210 | + array('taxes' => $taxes) |
|
| 211 | 211 | ); |
| 212 | 212 | |
| 213 | 213 | } |
@@ -217,29 +217,29 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @param GetPaid_Payment_Form_Submission $submission |
| 219 | 219 | */ |
| 220 | - public function add_gateways( $submission ) { |
|
| 220 | + public function add_gateways($submission) { |
|
| 221 | 221 | |
| 222 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 222 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 223 | 223 | |
| 224 | - if ( $this->response['has_recurring'] ) { |
|
| 224 | + if ($this->response['has_recurring']) { |
|
| 225 | 225 | |
| 226 | - foreach ( $gateways as $i => $gateway ) { |
|
| 226 | + foreach ($gateways as $i => $gateway) { |
|
| 227 | 227 | |
| 228 | 228 | if ( |
| 229 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 230 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 231 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 232 | - unset( $gateways[ $i ] ); |
|
| 229 | + !getpaid_payment_gateway_supports($gateway, 'subscription') |
|
| 230 | + || ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group')) |
|
| 231 | + || ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) { |
|
| 232 | + unset($gateways[$i]); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 239 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
| 240 | 240 | $this->response = array_merge( |
| 241 | 241 | $this->response, |
| 242 | - array( 'gateways' => $gateways ) |
|
| 242 | + array('gateways' => $gateways) |
|
| 243 | 243 | ); |
| 244 | 244 | |
| 245 | 245 | } |
@@ -252,22 +252,22 @@ discard block |
||
| 252 | 252 | * @param string $discount_code |
| 253 | 253 | * @param bool $recurring |
| 254 | 254 | */ |
| 255 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 255 | + public function standardize_price($item_id, $item_total, $discount_code, $recurring = false) { |
|
| 256 | 256 | |
| 257 | 257 | $standardadized_price = $item_total; |
| 258 | 258 | |
| 259 | 259 | // Do we have a $discount_code? |
| 260 | - if ( ! empty( $discount_code ) ) { |
|
| 260 | + if (!empty($discount_code)) { |
|
| 261 | 261 | |
| 262 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 262 | + $discount = new WPInv_Discount($discount_code); |
|
| 263 | 263 | |
| 264 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 265 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 264 | + if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) { |
|
| 265 | + $standardadized_price = $item_total - $discount->get_discounted_amount($item_total); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - return max( 0, $standardadized_price ); |
|
| 270 | + return max(0, $standardadized_price); |
|
| 271 | 271 | |
| 272 | 272 | } |
| 273 | 273 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @param GetPaid_Payment_Form_Submission $submission |
| 278 | 278 | */ |
| 279 | - public function add_data( $submission ) { |
|
| 279 | + public function add_data($submission) { |
|
| 280 | 280 | |
| 281 | 281 | $this->response = array_merge( |
| 282 | 282 | $this->response, |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,198 +10,198 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Sets the associated payment form. |
|
| 57 | - * |
|
| 58 | - * @var GetPaid_Payment_Form |
|
| 59 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Sets the associated payment form. |
|
| 57 | + * |
|
| 58 | + * @var GetPaid_Payment_Form |
|
| 59 | + */ |
|
| 60 | 60 | protected $payment_form = null; |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * The country for the submission. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - public $country = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The state for the submission. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.19 |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $state = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The invoice associated with the submission. |
|
| 79 | - * |
|
| 80 | - * @var WPInv_Invoice |
|
| 81 | - */ |
|
| 82 | - protected $invoice = null; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The recurring item for the submission. |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - public $has_recurring = 0; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * An array of fees for the submission. |
|
| 93 | - * |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $fees = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * An array of discounts for the submission. |
|
| 100 | - * |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - protected $discounts = array(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of taxes for the submission. |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $taxes = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * An array of items for the submission. |
|
| 114 | - * |
|
| 115 | - * @var GetPaid_Form_Item[] |
|
| 116 | - */ |
|
| 117 | - protected $items = array(); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The last error. |
|
| 121 | - * |
|
| 122 | - * @var string |
|
| 123 | - */ |
|
| 124 | - public $last_error = null; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * The last error code. |
|
| 128 | - * |
|
| 129 | - * @var string |
|
| 130 | - */ |
|
| 131 | - public $last_error_code = null; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Class constructor. |
|
| 135 | - * |
|
| 136 | - */ |
|
| 137 | - public function __construct() { |
|
| 138 | - |
|
| 139 | - // Set the state and country to the default state and country. |
|
| 140 | - $this->country = wpinv_default_billing_country(); |
|
| 141 | - $this->state = wpinv_get_default_state(); |
|
| 142 | - |
|
| 143 | - // Do we have an actual submission? |
|
| 144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 145 | - $this->load_data( $_POST ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Loads submission data. |
|
| 152 | - * |
|
| 153 | - * @param array $data |
|
| 154 | - */ |
|
| 155 | - public function load_data( $data ) { |
|
| 156 | - |
|
| 157 | - // Remove slashes from the submitted data... |
|
| 158 | - $data = wp_unslash( $data ); |
|
| 159 | - |
|
| 160 | - // Allow plugins to filter the data. |
|
| 161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 162 | - |
|
| 163 | - // Cache it... |
|
| 164 | - $this->data = $data; |
|
| 165 | - |
|
| 166 | - // Then generate a unique id from the data. |
|
| 167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 168 | - |
|
| 169 | - // Finally, process the submission. |
|
| 170 | - try { |
|
| 171 | - |
|
| 172 | - // Each process is passed an instance of the class (with reference) |
|
| 173 | - // and should throw an Exception whenever it encounters one. |
|
| 174 | - $processors = apply_filters( |
|
| 175 | - 'getpaid_payment_form_submission_processors', |
|
| 176 | - array( |
|
| 177 | - array( $this, 'process_payment_form' ), |
|
| 178 | - array( $this, 'process_invoice' ), |
|
| 179 | - array( $this, 'process_fees' ), |
|
| 180 | - array( $this, 'process_items' ), |
|
| 181 | - array( $this, 'process_discount' ), |
|
| 182 | - array( $this, 'process_taxes' ), |
|
| 183 | - ), |
|
| 184 | - $this |
|
| 185 | - ); |
|
| 186 | - |
|
| 187 | - foreach ( $processors as $processor ) { |
|
| 188 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
| 192 | - $this->last_error = $e->getMessage(); |
|
| 193 | - $this->last_error_code = $e->getErrorCode(); |
|
| 194 | - } catch ( Exception $e ) { |
|
| 195 | - $this->last_error = $e->getMessage(); |
|
| 196 | - $this->last_error_code = $e->getCode(); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // Fired when we are done processing a submission. |
|
| 200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 201 | - |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /* |
|
| 63 | + * The country for the submission. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + public $country = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The state for the submission. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.19 |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $state = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The invoice associated with the submission. |
|
| 79 | + * |
|
| 80 | + * @var WPInv_Invoice |
|
| 81 | + */ |
|
| 82 | + protected $invoice = null; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The recurring item for the submission. |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + public $has_recurring = 0; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * An array of fees for the submission. |
|
| 93 | + * |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $fees = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * An array of discounts for the submission. |
|
| 100 | + * |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + protected $discounts = array(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of taxes for the submission. |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $taxes = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * An array of items for the submission. |
|
| 114 | + * |
|
| 115 | + * @var GetPaid_Form_Item[] |
|
| 116 | + */ |
|
| 117 | + protected $items = array(); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The last error. |
|
| 121 | + * |
|
| 122 | + * @var string |
|
| 123 | + */ |
|
| 124 | + public $last_error = null; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * The last error code. |
|
| 128 | + * |
|
| 129 | + * @var string |
|
| 130 | + */ |
|
| 131 | + public $last_error_code = null; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Class constructor. |
|
| 135 | + * |
|
| 136 | + */ |
|
| 137 | + public function __construct() { |
|
| 138 | + |
|
| 139 | + // Set the state and country to the default state and country. |
|
| 140 | + $this->country = wpinv_default_billing_country(); |
|
| 141 | + $this->state = wpinv_get_default_state(); |
|
| 142 | + |
|
| 143 | + // Do we have an actual submission? |
|
| 144 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 145 | + $this->load_data( $_POST ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Loads submission data. |
|
| 152 | + * |
|
| 153 | + * @param array $data |
|
| 154 | + */ |
|
| 155 | + public function load_data( $data ) { |
|
| 156 | + |
|
| 157 | + // Remove slashes from the submitted data... |
|
| 158 | + $data = wp_unslash( $data ); |
|
| 159 | + |
|
| 160 | + // Allow plugins to filter the data. |
|
| 161 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 162 | + |
|
| 163 | + // Cache it... |
|
| 164 | + $this->data = $data; |
|
| 165 | + |
|
| 166 | + // Then generate a unique id from the data. |
|
| 167 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 168 | + |
|
| 169 | + // Finally, process the submission. |
|
| 170 | + try { |
|
| 171 | + |
|
| 172 | + // Each process is passed an instance of the class (with reference) |
|
| 173 | + // and should throw an Exception whenever it encounters one. |
|
| 174 | + $processors = apply_filters( |
|
| 175 | + 'getpaid_payment_form_submission_processors', |
|
| 176 | + array( |
|
| 177 | + array( $this, 'process_payment_form' ), |
|
| 178 | + array( $this, 'process_invoice' ), |
|
| 179 | + array( $this, 'process_fees' ), |
|
| 180 | + array( $this, 'process_items' ), |
|
| 181 | + array( $this, 'process_discount' ), |
|
| 182 | + array( $this, 'process_taxes' ), |
|
| 183 | + ), |
|
| 184 | + $this |
|
| 185 | + ); |
|
| 186 | + |
|
| 187 | + foreach ( $processors as $processor ) { |
|
| 188 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + } catch( GetPaid_Payment_Exception $e ) { |
|
| 192 | + $this->last_error = $e->getMessage(); |
|
| 193 | + $this->last_error_code = $e->getErrorCode(); |
|
| 194 | + } catch ( Exception $e ) { |
|
| 195 | + $this->last_error = $e->getMessage(); |
|
| 196 | + $this->last_error_code = $e->getCode(); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // Fired when we are done processing a submission. |
|
| 200 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 201 | + |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /* |
|
| 205 | 205 | |-------------------------------------------------------------------------- |
| 206 | 206 | | Payment Forms. |
| 207 | 207 | |-------------------------------------------------------------------------- |
@@ -210,39 +210,39 @@ discard block |
||
| 210 | 210 | | submission has an active payment form etc. |
| 211 | 211 | */ |
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Prepares the submission's payment form. |
|
| 215 | - * |
|
| 216 | - * @since 1.0.19 |
|
| 217 | - */ |
|
| 218 | - public function process_payment_form() { |
|
| 213 | + /** |
|
| 214 | + * Prepares the submission's payment form. |
|
| 215 | + * |
|
| 216 | + * @since 1.0.19 |
|
| 217 | + */ |
|
| 218 | + public function process_payment_form() { |
|
| 219 | 219 | |
| 220 | - // Every submission needs an active payment form. |
|
| 221 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 223 | - } |
|
| 220 | + // Every submission needs an active payment form. |
|
| 221 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 222 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // Fetch the payment form. |
|
| 226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 225 | + // Fetch the payment form. |
|
| 226 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 227 | 227 | |
| 228 | - if ( ! $this->payment_form->is_active() ) { |
|
| 229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 230 | - } |
|
| 228 | + if ( ! $this->payment_form->is_active() ) { |
|
| 229 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 233 | - } |
|
| 232 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | /** |
| 236 | - * Returns the payment form. |
|
| 237 | - * |
|
| 238 | - * @since 1.0.19 |
|
| 239 | - * @return GetPaid_Payment_Form |
|
| 240 | - */ |
|
| 241 | - public function get_payment_form() { |
|
| 242 | - return $this->payment_form; |
|
| 243 | - } |
|
| 236 | + * Returns the payment form. |
|
| 237 | + * |
|
| 238 | + * @since 1.0.19 |
|
| 239 | + * @return GetPaid_Payment_Form |
|
| 240 | + */ |
|
| 241 | + public function get_payment_form() { |
|
| 242 | + return $this->payment_form; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /* |
|
| 245 | + /* |
|
| 246 | 246 | |-------------------------------------------------------------------------- |
| 247 | 247 | | Invoices. |
| 248 | 248 | |-------------------------------------------------------------------------- |
@@ -251,84 +251,84 @@ discard block |
||
| 251 | 251 | | might be for an existing invoice. |
| 252 | 252 | */ |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Prepares the submission's invoice. |
|
| 256 | - * |
|
| 257 | - * @since 1.0.19 |
|
| 258 | - */ |
|
| 259 | - public function process_invoice() { |
|
| 254 | + /** |
|
| 255 | + * Prepares the submission's invoice. |
|
| 256 | + * |
|
| 257 | + * @since 1.0.19 |
|
| 258 | + */ |
|
| 259 | + public function process_invoice() { |
|
| 260 | 260 | |
| 261 | - // Abort if there is no invoice. |
|
| 262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 261 | + // Abort if there is no invoice. |
|
| 262 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 267 | - // and that it is not paid for. |
|
| 268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 266 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 267 | + // and that it is not paid for. |
|
| 268 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 269 | 269 | |
| 270 | 270 | if ( empty( $invoice ) ) { |
| 271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 272 | - } |
|
| 271 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - if ( $invoice->is_paid() ) { |
|
| 275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 276 | - } |
|
| 274 | + if ( $invoice->is_paid() ) { |
|
| 275 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - $this->payment_form->invoice = $invoice; |
|
| 279 | - if ( ! $this->payment_form->is_default() ) { |
|
| 278 | + $this->payment_form->invoice = $invoice; |
|
| 279 | + if ( ! $this->payment_form->is_default() ) { |
|
| 280 | 280 | |
| 281 | - $items = array(); |
|
| 282 | - $item_ids = array(); |
|
| 281 | + $items = array(); |
|
| 282 | + $item_ids = array(); |
|
| 283 | 283 | |
| 284 | - foreach ( $invoice->get_items() as $item ) { |
|
| 285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 286 | - $item_ids[] = $item->get_id(); |
|
| 287 | - $items[] = $item; |
|
| 288 | - } |
|
| 289 | - } |
|
| 284 | + foreach ( $invoice->get_items() as $item ) { |
|
| 285 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 286 | + $item_ids[] = $item->get_id(); |
|
| 287 | + $items[] = $item; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 293 | - $item_ids[] = $item->get_id(); |
|
| 294 | - $items[] = $item; |
|
| 295 | - } |
|
| 296 | - } |
|
| 291 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
| 292 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 293 | + $item_ids[] = $item->get_id(); |
|
| 294 | + $items[] = $item; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - $this->payment_form->set_items( $items ); |
|
| 298 | + $this->payment_form->set_items( $items ); |
|
| 299 | 299 | |
| 300 | - } else { |
|
| 301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $this->country = $invoice->get_country(); |
|
| 305 | - $this->state = $invoice->get_state(); |
|
| 306 | - $this->invoice = $invoice; |
|
| 307 | - |
|
| 308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Returns the associated invoice. |
|
| 313 | - * |
|
| 314 | - * @since 1.0.19 |
|
| 315 | - * @return WPInv_Invoice |
|
| 316 | - */ |
|
| 317 | - public function get_invoice() { |
|
| 318 | - return $this->invoice; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Checks whether there is an invoice associated with this submission. |
|
| 323 | - * |
|
| 324 | - * @since 1.0.19 |
|
| 325 | - * @return bool |
|
| 326 | - */ |
|
| 327 | - public function has_invoice() { |
|
| 328 | - return ! empty( $this->invoice ); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /* |
|
| 300 | + } else { |
|
| 301 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $this->country = $invoice->get_country(); |
|
| 305 | + $this->state = $invoice->get_state(); |
|
| 306 | + $this->invoice = $invoice; |
|
| 307 | + |
|
| 308 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Returns the associated invoice. |
|
| 313 | + * |
|
| 314 | + * @since 1.0.19 |
|
| 315 | + * @return WPInv_Invoice |
|
| 316 | + */ |
|
| 317 | + public function get_invoice() { |
|
| 318 | + return $this->invoice; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Checks whether there is an invoice associated with this submission. |
|
| 323 | + * |
|
| 324 | + * @since 1.0.19 |
|
| 325 | + * @return bool |
|
| 326 | + */ |
|
| 327 | + public function has_invoice() { |
|
| 328 | + return ! empty( $this->invoice ); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /* |
|
| 332 | 332 | |-------------------------------------------------------------------------- |
| 333 | 333 | | Items. |
| 334 | 334 | |-------------------------------------------------------------------------- |
@@ -337,129 +337,129 @@ discard block |
||
| 337 | 337 | | recurring item. But can have an unlimited number of non-recurring items. |
| 338 | 338 | */ |
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * Prepares the submission's items. |
|
| 342 | - * |
|
| 343 | - * @since 1.0.19 |
|
| 344 | - */ |
|
| 345 | - public function process_items() { |
|
| 346 | - |
|
| 347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 348 | - |
|
| 349 | - foreach ( $processor->items as $item ) { |
|
| 350 | - $this->add_item( $item ); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Adds an item to the submission. |
|
| 358 | - * |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - * @param GetPaid_Form_Item $item |
|
| 361 | - */ |
|
| 362 | - public function add_item( $item ) { |
|
| 363 | - |
|
| 364 | - // Make sure that it is available for purchase. |
|
| 365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 366 | - return; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - // Each submission can only contain one recurring item. |
|
| 370 | - if ( $item->is_recurring() ) { |
|
| 371 | - $this->has_recurring = $item->get_id(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // Update the items and totals. |
|
| 375 | - $this->items[ $item->get_id() ] = $item; |
|
| 376 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 377 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 378 | - |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Removes a specific item. |
|
| 383 | - * |
|
| 384 | - * You should not call this method after the discounts and taxes |
|
| 385 | - * have been calculated. |
|
| 386 | - * |
|
| 387 | - * @since 1.0.19 |
|
| 388 | - */ |
|
| 389 | - public function remove_item( $item_id ) { |
|
| 390 | - |
|
| 391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 394 | - |
|
| 395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 396 | - $this->has_recurring = 0; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - unset( $this->items[ $item_id ] ); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Returns the subtotal. |
|
| 406 | - * |
|
| 407 | - * @since 1.0.19 |
|
| 408 | - */ |
|
| 409 | - public function get_subtotal() { |
|
| 410 | - |
|
| 411 | - if ( wpinv_prices_include_tax() ) { |
|
| 412 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - return $this->totals['subtotal']['initial']; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Returns the recurring subtotal. |
|
| 420 | - * |
|
| 421 | - * @since 1.0.19 |
|
| 422 | - */ |
|
| 423 | - public function get_recurring_subtotal() { |
|
| 424 | - |
|
| 425 | - if ( wpinv_prices_include_tax() ) { |
|
| 426 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return $this->totals['subtotal']['recurring']; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Returns all items. |
|
| 434 | - * |
|
| 435 | - * @since 1.0.19 |
|
| 436 | - * @return GetPaid_Form_Item[] |
|
| 437 | - */ |
|
| 438 | - public function get_items() { |
|
| 439 | - return $this->items; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Checks if there's a single subscription group in the submission. |
|
| 444 | - * |
|
| 445 | - * @since 2.3.0 |
|
| 446 | - * @return bool |
|
| 447 | - */ |
|
| 448 | - public function has_subscription_group() { |
|
| 449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Checks if there are multipe subscription groups in the submission. |
|
| 454 | - * |
|
| 455 | - * @since 2.3.0 |
|
| 456 | - * @return bool |
|
| 457 | - */ |
|
| 458 | - public function has_multiple_subscription_groups() { |
|
| 459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /* |
|
| 340 | + /** |
|
| 341 | + * Prepares the submission's items. |
|
| 342 | + * |
|
| 343 | + * @since 1.0.19 |
|
| 344 | + */ |
|
| 345 | + public function process_items() { |
|
| 346 | + |
|
| 347 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 348 | + |
|
| 349 | + foreach ( $processor->items as $item ) { |
|
| 350 | + $this->add_item( $item ); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Adds an item to the submission. |
|
| 358 | + * |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + * @param GetPaid_Form_Item $item |
|
| 361 | + */ |
|
| 362 | + public function add_item( $item ) { |
|
| 363 | + |
|
| 364 | + // Make sure that it is available for purchase. |
|
| 365 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 366 | + return; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + // Each submission can only contain one recurring item. |
|
| 370 | + if ( $item->is_recurring() ) { |
|
| 371 | + $this->has_recurring = $item->get_id(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // Update the items and totals. |
|
| 375 | + $this->items[ $item->get_id() ] = $item; |
|
| 376 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 377 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 378 | + |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Removes a specific item. |
|
| 383 | + * |
|
| 384 | + * You should not call this method after the discounts and taxes |
|
| 385 | + * have been calculated. |
|
| 386 | + * |
|
| 387 | + * @since 1.0.19 |
|
| 388 | + */ |
|
| 389 | + public function remove_item( $item_id ) { |
|
| 390 | + |
|
| 391 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 392 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 393 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 394 | + |
|
| 395 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 396 | + $this->has_recurring = 0; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + unset( $this->items[ $item_id ] ); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Returns the subtotal. |
|
| 406 | + * |
|
| 407 | + * @since 1.0.19 |
|
| 408 | + */ |
|
| 409 | + public function get_subtotal() { |
|
| 410 | + |
|
| 411 | + if ( wpinv_prices_include_tax() ) { |
|
| 412 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + return $this->totals['subtotal']['initial']; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Returns the recurring subtotal. |
|
| 420 | + * |
|
| 421 | + * @since 1.0.19 |
|
| 422 | + */ |
|
| 423 | + public function get_recurring_subtotal() { |
|
| 424 | + |
|
| 425 | + if ( wpinv_prices_include_tax() ) { |
|
| 426 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return $this->totals['subtotal']['recurring']; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Returns all items. |
|
| 434 | + * |
|
| 435 | + * @since 1.0.19 |
|
| 436 | + * @return GetPaid_Form_Item[] |
|
| 437 | + */ |
|
| 438 | + public function get_items() { |
|
| 439 | + return $this->items; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Checks if there's a single subscription group in the submission. |
|
| 444 | + * |
|
| 445 | + * @since 2.3.0 |
|
| 446 | + * @return bool |
|
| 447 | + */ |
|
| 448 | + public function has_subscription_group() { |
|
| 449 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Checks if there are multipe subscription groups in the submission. |
|
| 454 | + * |
|
| 455 | + * @since 2.3.0 |
|
| 456 | + * @return bool |
|
| 457 | + */ |
|
| 458 | + public function has_multiple_subscription_groups() { |
|
| 459 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /* |
|
| 463 | 463 | |-------------------------------------------------------------------------- |
| 464 | 464 | | Taxes |
| 465 | 465 | |-------------------------------------------------------------------------- |
@@ -468,128 +468,128 @@ discard block |
||
| 468 | 468 | | or only one-time. |
| 469 | 469 | */ |
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * Prepares the submission's taxes. |
|
| 473 | - * |
|
| 474 | - * @since 1.0.19 |
|
| 475 | - */ |
|
| 476 | - public function process_taxes() { |
|
| 477 | - |
|
| 478 | - // Abort if we're not using taxes. |
|
| 479 | - if ( ! $this->use_taxes() ) { |
|
| 480 | - return; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 485 | - if ( ! empty( $country ) ) { |
|
| 486 | - $this->country = $country; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 490 | - if ( ! empty( $state ) ) { |
|
| 491 | - $this->state = $state; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // Confirm if the provided country and the ip country are similar. |
|
| 495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 496 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // Abort if the country is not taxable. |
|
| 501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 502 | - return; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 506 | - |
|
| 507 | - foreach ( $processor->taxes as $tax ) { |
|
| 508 | - $this->add_tax( $tax ); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Adds a tax to the submission. |
|
| 516 | - * |
|
| 517 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 518 | - * @since 1.0.19 |
|
| 519 | - */ |
|
| 520 | - public function add_tax( $tax ) { |
|
| 521 | - |
|
| 522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 530 | - |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Removes a specific tax. |
|
| 535 | - * |
|
| 536 | - * @since 1.0.19 |
|
| 537 | - */ |
|
| 538 | - public function remove_tax( $tax_name ) { |
|
| 539 | - |
|
| 540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 543 | - unset( $this->taxes[ $tax_name ] ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Whether or not we'll use taxes for the submission. |
|
| 550 | - * |
|
| 551 | - * @since 1.0.19 |
|
| 552 | - */ |
|
| 553 | - public function use_taxes() { |
|
| 554 | - |
|
| 555 | - $use_taxes = wpinv_use_taxes(); |
|
| 556 | - |
|
| 557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 558 | - $use_taxes = false; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 562 | - |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Returns the tax. |
|
| 567 | - * |
|
| 568 | - * @since 1.0.19 |
|
| 569 | - */ |
|
| 570 | - public function get_tax() { |
|
| 571 | - return $this->totals['taxes']['initial']; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * Returns the recurring tax. |
|
| 576 | - * |
|
| 577 | - * @since 1.0.19 |
|
| 578 | - */ |
|
| 579 | - public function get_recurring_tax() { |
|
| 580 | - return $this->totals['taxes']['recurring']; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Returns all taxes. |
|
| 585 | - * |
|
| 586 | - * @since 1.0.19 |
|
| 587 | - */ |
|
| 588 | - public function get_taxes() { |
|
| 589 | - return $this->taxes; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /* |
|
| 471 | + /** |
|
| 472 | + * Prepares the submission's taxes. |
|
| 473 | + * |
|
| 474 | + * @since 1.0.19 |
|
| 475 | + */ |
|
| 476 | + public function process_taxes() { |
|
| 477 | + |
|
| 478 | + // Abort if we're not using taxes. |
|
| 479 | + if ( ! $this->use_taxes() ) { |
|
| 480 | + return; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 484 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 485 | + if ( ! empty( $country ) ) { |
|
| 486 | + $this->country = $country; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 490 | + if ( ! empty( $state ) ) { |
|
| 491 | + $this->state = $state; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // Confirm if the provided country and the ip country are similar. |
|
| 495 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 496 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 497 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // Abort if the country is not taxable. |
|
| 501 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 502 | + return; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 506 | + |
|
| 507 | + foreach ( $processor->taxes as $tax ) { |
|
| 508 | + $this->add_tax( $tax ); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Adds a tax to the submission. |
|
| 516 | + * |
|
| 517 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 518 | + * @since 1.0.19 |
|
| 519 | + */ |
|
| 520 | + public function add_tax( $tax ) { |
|
| 521 | + |
|
| 522 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 523 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 524 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 530 | + |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Removes a specific tax. |
|
| 535 | + * |
|
| 536 | + * @since 1.0.19 |
|
| 537 | + */ |
|
| 538 | + public function remove_tax( $tax_name ) { |
|
| 539 | + |
|
| 540 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 541 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 542 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 543 | + unset( $this->taxes[ $tax_name ] ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Whether or not we'll use taxes for the submission. |
|
| 550 | + * |
|
| 551 | + * @since 1.0.19 |
|
| 552 | + */ |
|
| 553 | + public function use_taxes() { |
|
| 554 | + |
|
| 555 | + $use_taxes = wpinv_use_taxes(); |
|
| 556 | + |
|
| 557 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 558 | + $use_taxes = false; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 562 | + |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Returns the tax. |
|
| 567 | + * |
|
| 568 | + * @since 1.0.19 |
|
| 569 | + */ |
|
| 570 | + public function get_tax() { |
|
| 571 | + return $this->totals['taxes']['initial']; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Returns the recurring tax. |
|
| 576 | + * |
|
| 577 | + * @since 1.0.19 |
|
| 578 | + */ |
|
| 579 | + public function get_recurring_tax() { |
|
| 580 | + return $this->totals['taxes']['recurring']; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Returns all taxes. |
|
| 585 | + * |
|
| 586 | + * @since 1.0.19 |
|
| 587 | + */ |
|
| 588 | + public function get_taxes() { |
|
| 589 | + return $this->taxes; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /* |
|
| 593 | 593 | |-------------------------------------------------------------------------- |
| 594 | 594 | | Discounts |
| 595 | 595 | |-------------------------------------------------------------------------- |
@@ -598,99 +598,99 @@ discard block |
||
| 598 | 598 | | or only one-time. They also do not have to come from a discount code. |
| 599 | 599 | */ |
| 600 | 600 | |
| 601 | - /** |
|
| 602 | - * Prepares the submission's discount. |
|
| 603 | - * |
|
| 604 | - * @since 1.0.19 |
|
| 605 | - */ |
|
| 606 | - public function process_discount() { |
|
| 607 | - |
|
| 608 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 609 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 611 | - |
|
| 612 | - foreach ( $processor->discounts as $discount ) { |
|
| 613 | - $this->add_discount( $discount ); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Adds a discount to the submission. |
|
| 621 | - * |
|
| 622 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 623 | - * @since 1.0.19 |
|
| 624 | - */ |
|
| 625 | - public function add_discount( $discount ) { |
|
| 626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * Removes a discount from the submission. |
|
| 633 | - * |
|
| 634 | - * @since 1.0.19 |
|
| 635 | - */ |
|
| 636 | - public function remove_discount( $name ) { |
|
| 637 | - |
|
| 638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 641 | - unset( $this->discounts[ $name ] ); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * Checks whether there is a discount code associated with this submission. |
|
| 648 | - * |
|
| 649 | - * @since 1.0.19 |
|
| 650 | - * @return bool |
|
| 651 | - */ |
|
| 652 | - public function has_discount_code() { |
|
| 653 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Returns the discount code. |
|
| 658 | - * |
|
| 659 | - * @since 1.0.19 |
|
| 660 | - * @return string |
|
| 661 | - */ |
|
| 662 | - public function get_discount_code() { |
|
| 663 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Returns the discount. |
|
| 668 | - * |
|
| 669 | - * @since 1.0.19 |
|
| 670 | - */ |
|
| 671 | - public function get_discount() { |
|
| 672 | - return $this->totals['discount']['initial']; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Returns the recurring discount. |
|
| 677 | - * |
|
| 678 | - * @since 1.0.19 |
|
| 679 | - */ |
|
| 680 | - public function get_recurring_discount() { |
|
| 681 | - return $this->totals['discount']['recurring']; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Returns all discounts. |
|
| 686 | - * |
|
| 687 | - * @since 1.0.19 |
|
| 688 | - */ |
|
| 689 | - public function get_discounts() { |
|
| 690 | - return $this->discounts; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - /* |
|
| 601 | + /** |
|
| 602 | + * Prepares the submission's discount. |
|
| 603 | + * |
|
| 604 | + * @since 1.0.19 |
|
| 605 | + */ |
|
| 606 | + public function process_discount() { |
|
| 607 | + |
|
| 608 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 609 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 610 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 611 | + |
|
| 612 | + foreach ( $processor->discounts as $discount ) { |
|
| 613 | + $this->add_discount( $discount ); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Adds a discount to the submission. |
|
| 621 | + * |
|
| 622 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 623 | + * @since 1.0.19 |
|
| 624 | + */ |
|
| 625 | + public function add_discount( $discount ) { |
|
| 626 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * Removes a discount from the submission. |
|
| 633 | + * |
|
| 634 | + * @since 1.0.19 |
|
| 635 | + */ |
|
| 636 | + public function remove_discount( $name ) { |
|
| 637 | + |
|
| 638 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 639 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 640 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 641 | + unset( $this->discounts[ $name ] ); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * Checks whether there is a discount code associated with this submission. |
|
| 648 | + * |
|
| 649 | + * @since 1.0.19 |
|
| 650 | + * @return bool |
|
| 651 | + */ |
|
| 652 | + public function has_discount_code() { |
|
| 653 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Returns the discount code. |
|
| 658 | + * |
|
| 659 | + * @since 1.0.19 |
|
| 660 | + * @return string |
|
| 661 | + */ |
|
| 662 | + public function get_discount_code() { |
|
| 663 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Returns the discount. |
|
| 668 | + * |
|
| 669 | + * @since 1.0.19 |
|
| 670 | + */ |
|
| 671 | + public function get_discount() { |
|
| 672 | + return $this->totals['discount']['initial']; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Returns the recurring discount. |
|
| 677 | + * |
|
| 678 | + * @since 1.0.19 |
|
| 679 | + */ |
|
| 680 | + public function get_recurring_discount() { |
|
| 681 | + return $this->totals['discount']['recurring']; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Returns all discounts. |
|
| 686 | + * |
|
| 687 | + * @since 1.0.19 |
|
| 688 | + */ |
|
| 689 | + public function get_discounts() { |
|
| 690 | + return $this->discounts; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + /* |
|
| 694 | 694 | |-------------------------------------------------------------------------- |
| 695 | 695 | | Fees |
| 696 | 696 | |-------------------------------------------------------------------------- |
@@ -700,89 +700,89 @@ discard block |
||
| 700 | 700 | | fees. |
| 701 | 701 | */ |
| 702 | 702 | |
| 703 | - /** |
|
| 704 | - * Prepares the submission's fees. |
|
| 705 | - * |
|
| 706 | - * @since 1.0.19 |
|
| 707 | - */ |
|
| 708 | - public function process_fees() { |
|
| 709 | - |
|
| 710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 711 | - |
|
| 712 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 713 | - $this->add_fee( $fee ); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * Adds a fee to the submission. |
|
| 721 | - * |
|
| 722 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 723 | - * @since 1.0.19 |
|
| 724 | - */ |
|
| 725 | - public function add_fee( $fee ) { |
|
| 726 | - |
|
| 727 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 730 | - |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * Removes a fee from the submission. |
|
| 735 | - * |
|
| 736 | - * @since 1.0.19 |
|
| 737 | - */ |
|
| 738 | - public function remove_fee( $name ) { |
|
| 739 | - |
|
| 740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 743 | - unset( $this->fees[ $name ] ); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Returns the fees. |
|
| 750 | - * |
|
| 751 | - * @since 1.0.19 |
|
| 752 | - */ |
|
| 753 | - public function get_fee() { |
|
| 754 | - return $this->totals['fees']['initial']; |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * Returns the recurring fees. |
|
| 759 | - * |
|
| 760 | - * @since 1.0.19 |
|
| 761 | - */ |
|
| 762 | - public function get_recurring_fee() { |
|
| 763 | - return $this->totals['fees']['recurring']; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * Returns all fees. |
|
| 768 | - * |
|
| 769 | - * @since 1.0.19 |
|
| 770 | - */ |
|
| 771 | - public function get_fees() { |
|
| 772 | - return $this->fees; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * Checks if there are any fees for the form. |
|
| 777 | - * |
|
| 778 | - * @return bool |
|
| 779 | - * @since 1.0.19 |
|
| 780 | - */ |
|
| 781 | - public function has_fees() { |
|
| 782 | - return count( $this->fees ) !== 0; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - /* |
|
| 703 | + /** |
|
| 704 | + * Prepares the submission's fees. |
|
| 705 | + * |
|
| 706 | + * @since 1.0.19 |
|
| 707 | + */ |
|
| 708 | + public function process_fees() { |
|
| 709 | + |
|
| 710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 711 | + |
|
| 712 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 713 | + $this->add_fee( $fee ); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * Adds a fee to the submission. |
|
| 721 | + * |
|
| 722 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 723 | + * @since 1.0.19 |
|
| 724 | + */ |
|
| 725 | + public function add_fee( $fee ) { |
|
| 726 | + |
|
| 727 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 730 | + |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * Removes a fee from the submission. |
|
| 735 | + * |
|
| 736 | + * @since 1.0.19 |
|
| 737 | + */ |
|
| 738 | + public function remove_fee( $name ) { |
|
| 739 | + |
|
| 740 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 741 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 742 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 743 | + unset( $this->fees[ $name ] ); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Returns the fees. |
|
| 750 | + * |
|
| 751 | + * @since 1.0.19 |
|
| 752 | + */ |
|
| 753 | + public function get_fee() { |
|
| 754 | + return $this->totals['fees']['initial']; |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * Returns the recurring fees. |
|
| 759 | + * |
|
| 760 | + * @since 1.0.19 |
|
| 761 | + */ |
|
| 762 | + public function get_recurring_fee() { |
|
| 763 | + return $this->totals['fees']['recurring']; |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * Returns all fees. |
|
| 768 | + * |
|
| 769 | + * @since 1.0.19 |
|
| 770 | + */ |
|
| 771 | + public function get_fees() { |
|
| 772 | + return $this->fees; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * Checks if there are any fees for the form. |
|
| 777 | + * |
|
| 778 | + * @return bool |
|
| 779 | + * @since 1.0.19 |
|
| 780 | + */ |
|
| 781 | + public function has_fees() { |
|
| 782 | + return count( $this->fees ) !== 0; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + /* |
|
| 786 | 786 | |-------------------------------------------------------------------------- |
| 787 | 787 | | MISC |
| 788 | 788 | |-------------------------------------------------------------------------- |
@@ -790,119 +790,119 @@ discard block |
||
| 790 | 790 | | Extra submission functions. |
| 791 | 791 | */ |
| 792 | 792 | |
| 793 | - /** |
|
| 794 | - * Checks if this is the initial fetch. |
|
| 795 | - * |
|
| 796 | - * @return bool |
|
| 797 | - * @since 1.0.19 |
|
| 798 | - */ |
|
| 799 | - public function is_initial_fetch() { |
|
| 800 | - return empty( $this->data['initial_state'] ); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * Returns the total amount to collect for this submission. |
|
| 805 | - * |
|
| 806 | - * @since 1.0.19 |
|
| 807 | - */ |
|
| 808 | - public function get_total() { |
|
| 809 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 810 | - return max( $total, 0 ); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * Returns the recurring total amount to collect for this submission. |
|
| 815 | - * |
|
| 816 | - * @since 1.0.19 |
|
| 817 | - */ |
|
| 818 | - public function get_recurring_total() { |
|
| 819 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 820 | - return max( $total, 0 ); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Whether payment details should be collected for this submission. |
|
| 825 | - * |
|
| 826 | - * @since 1.0.19 |
|
| 827 | - */ |
|
| 828 | - public function should_collect_payment_details() { |
|
| 829 | - $initial = $this->get_total(); |
|
| 830 | - $recurring = $this->get_recurring_total(); |
|
| 831 | - |
|
| 832 | - if ( $this->has_recurring == 0 ) { |
|
| 833 | - $recurring = 0; |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - $collect = $initial > 0 || $recurring > 0; |
|
| 837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Returns the billing email of the user. |
|
| 842 | - * |
|
| 843 | - * @since 1.0.19 |
|
| 844 | - */ |
|
| 845 | - public function get_billing_email() { |
|
| 846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * Checks if the submitter has a billing email. |
|
| 851 | - * |
|
| 852 | - * @since 1.0.19 |
|
| 853 | - */ |
|
| 854 | - public function has_billing_email() { |
|
| 855 | - $billing_email = $this->get_billing_email(); |
|
| 856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * Returns the appropriate currency for the submission. |
|
| 861 | - * |
|
| 862 | - * @since 1.0.19 |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - public function get_currency() { |
|
| 866 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * Returns the raw submission data. |
|
| 871 | - * |
|
| 872 | - * @since 1.0.19 |
|
| 873 | - * @return array |
|
| 874 | - */ |
|
| 875 | - public function get_data() { |
|
| 876 | - return $this->data; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * Returns a field from the submission data |
|
| 881 | - * |
|
| 882 | - * @param string $field |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - * @return mixed|null |
|
| 885 | - */ |
|
| 886 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * Checks if a required field is set. |
|
| 892 | - * |
|
| 893 | - * @since 1.0.19 |
|
| 894 | - */ |
|
| 895 | - public function is_required_field_set( $field ) { |
|
| 896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Formats an amount |
|
| 901 | - * |
|
| 902 | - * @since 1.0.19 |
|
| 903 | - */ |
|
| 904 | - public function format_amount( $amount ) { |
|
| 905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 906 | - } |
|
| 793 | + /** |
|
| 794 | + * Checks if this is the initial fetch. |
|
| 795 | + * |
|
| 796 | + * @return bool |
|
| 797 | + * @since 1.0.19 |
|
| 798 | + */ |
|
| 799 | + public function is_initial_fetch() { |
|
| 800 | + return empty( $this->data['initial_state'] ); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * Returns the total amount to collect for this submission. |
|
| 805 | + * |
|
| 806 | + * @since 1.0.19 |
|
| 807 | + */ |
|
| 808 | + public function get_total() { |
|
| 809 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 810 | + return max( $total, 0 ); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * Returns the recurring total amount to collect for this submission. |
|
| 815 | + * |
|
| 816 | + * @since 1.0.19 |
|
| 817 | + */ |
|
| 818 | + public function get_recurring_total() { |
|
| 819 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 820 | + return max( $total, 0 ); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Whether payment details should be collected for this submission. |
|
| 825 | + * |
|
| 826 | + * @since 1.0.19 |
|
| 827 | + */ |
|
| 828 | + public function should_collect_payment_details() { |
|
| 829 | + $initial = $this->get_total(); |
|
| 830 | + $recurring = $this->get_recurring_total(); |
|
| 831 | + |
|
| 832 | + if ( $this->has_recurring == 0 ) { |
|
| 833 | + $recurring = 0; |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + $collect = $initial > 0 || $recurring > 0; |
|
| 837 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Returns the billing email of the user. |
|
| 842 | + * |
|
| 843 | + * @since 1.0.19 |
|
| 844 | + */ |
|
| 845 | + public function get_billing_email() { |
|
| 846 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * Checks if the submitter has a billing email. |
|
| 851 | + * |
|
| 852 | + * @since 1.0.19 |
|
| 853 | + */ |
|
| 854 | + public function has_billing_email() { |
|
| 855 | + $billing_email = $this->get_billing_email(); |
|
| 856 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * Returns the appropriate currency for the submission. |
|
| 861 | + * |
|
| 862 | + * @since 1.0.19 |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + public function get_currency() { |
|
| 866 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * Returns the raw submission data. |
|
| 871 | + * |
|
| 872 | + * @since 1.0.19 |
|
| 873 | + * @return array |
|
| 874 | + */ |
|
| 875 | + public function get_data() { |
|
| 876 | + return $this->data; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * Returns a field from the submission data |
|
| 881 | + * |
|
| 882 | + * @param string $field |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + * @return mixed|null |
|
| 885 | + */ |
|
| 886 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 887 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * Checks if a required field is set. |
|
| 892 | + * |
|
| 893 | + * @since 1.0.19 |
|
| 894 | + */ |
|
| 895 | + public function is_required_field_set( $field ) { |
|
| 896 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Formats an amount |
|
| 901 | + * |
|
| 902 | + * @since 1.0.19 |
|
| 903 | + */ |
|
| 904 | + public function format_amount( $amount ) { |
|
| 905 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 906 | + } |
|
| 907 | 907 | |
| 908 | 908 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | $this->state = wpinv_get_default_state(); |
| 142 | 142 | |
| 143 | 143 | // Do we have an actual submission? |
| 144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 145 | - $this->load_data( $_POST ); |
|
| 144 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 145 | + $this->load_data($_POST); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | } |
@@ -152,19 +152,19 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @param array $data |
| 154 | 154 | */ |
| 155 | - public function load_data( $data ) { |
|
| 155 | + public function load_data($data) { |
|
| 156 | 156 | |
| 157 | 157 | // Remove slashes from the submitted data... |
| 158 | - $data = wp_unslash( $data ); |
|
| 158 | + $data = wp_unslash($data); |
|
| 159 | 159 | |
| 160 | 160 | // Allow plugins to filter the data. |
| 161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 161 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 162 | 162 | |
| 163 | 163 | // Cache it... |
| 164 | 164 | $this->data = $data; |
| 165 | 165 | |
| 166 | 166 | // Then generate a unique id from the data. |
| 167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 167 | + $this->id = md5(wp_json_encode($data)); |
|
| 168 | 168 | |
| 169 | 169 | // Finally, process the submission. |
| 170 | 170 | try { |
@@ -174,30 +174,30 @@ discard block |
||
| 174 | 174 | $processors = apply_filters( |
| 175 | 175 | 'getpaid_payment_form_submission_processors', |
| 176 | 176 | array( |
| 177 | - array( $this, 'process_payment_form' ), |
|
| 178 | - array( $this, 'process_invoice' ), |
|
| 179 | - array( $this, 'process_fees' ), |
|
| 180 | - array( $this, 'process_items' ), |
|
| 181 | - array( $this, 'process_discount' ), |
|
| 182 | - array( $this, 'process_taxes' ), |
|
| 177 | + array($this, 'process_payment_form'), |
|
| 178 | + array($this, 'process_invoice'), |
|
| 179 | + array($this, 'process_fees'), |
|
| 180 | + array($this, 'process_items'), |
|
| 181 | + array($this, 'process_discount'), |
|
| 182 | + array($this, 'process_taxes'), |
|
| 183 | 183 | ), |
| 184 | 184 | $this |
| 185 | 185 | ); |
| 186 | 186 | |
| 187 | - foreach ( $processors as $processor ) { |
|
| 188 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 187 | + foreach ($processors as $processor) { |
|
| 188 | + call_user_func_array($processor, array(&$this)); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
| 191 | + } catch (GetPaid_Payment_Exception $e) { |
|
| 192 | 192 | $this->last_error = $e->getMessage(); |
| 193 | 193 | $this->last_error_code = $e->getErrorCode(); |
| 194 | - } catch ( Exception $e ) { |
|
| 194 | + } catch (Exception $e) { |
|
| 195 | 195 | $this->last_error = $e->getMessage(); |
| 196 | 196 | $this->last_error_code = $e->getCode(); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Fired when we are done processing a submission. |
| 200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 200 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 201 | 201 | |
| 202 | 202 | } |
| 203 | 203 | |
@@ -218,18 +218,18 @@ discard block |
||
| 218 | 218 | public function process_payment_form() { |
| 219 | 219 | |
| 220 | 220 | // Every submission needs an active payment form. |
| 221 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 221 | + if (empty($this->data['form_id'])) { |
|
| 222 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // Fetch the payment form. |
| 226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 226 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 227 | 227 | |
| 228 | - if ( ! $this->payment_form->is_active() ) { |
|
| 229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 228 | + if (!$this->payment_form->is_active()) { |
|
| 229 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 232 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -259,53 +259,53 @@ discard block |
||
| 259 | 259 | public function process_invoice() { |
| 260 | 260 | |
| 261 | 261 | // Abort if there is no invoice. |
| 262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 262 | + if (empty($this->data['invoice_id'])) { |
|
| 263 | 263 | return; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // If the submission is for an existing invoice, ensure that it exists |
| 267 | 267 | // and that it is not paid for. |
| 268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 268 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 269 | 269 | |
| 270 | - if ( empty( $invoice ) ) { |
|
| 271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 270 | + if (empty($invoice)) { |
|
| 271 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if ( $invoice->is_paid() ) { |
|
| 275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 274 | + if ($invoice->is_paid()) { |
|
| 275 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | $this->payment_form->invoice = $invoice; |
| 279 | - if ( ! $this->payment_form->is_default() ) { |
|
| 279 | + if (!$this->payment_form->is_default()) { |
|
| 280 | 280 | |
| 281 | 281 | $items = array(); |
| 282 | 282 | $item_ids = array(); |
| 283 | 283 | |
| 284 | - foreach ( $invoice->get_items() as $item ) { |
|
| 285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 284 | + foreach ($invoice->get_items() as $item) { |
|
| 285 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 286 | 286 | $item_ids[] = $item->get_id(); |
| 287 | 287 | $items[] = $item; |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 291 | + foreach ($this->payment_form->get_items() as $item) { |
|
| 292 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 293 | 293 | $item_ids[] = $item->get_id(); |
| 294 | 294 | $items[] = $item; |
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - $this->payment_form->set_items( $items ); |
|
| 298 | + $this->payment_form->set_items($items); |
|
| 299 | 299 | |
| 300 | 300 | } else { |
| 301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 301 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | $this->country = $invoice->get_country(); |
| 305 | 305 | $this->state = $invoice->get_state(); |
| 306 | 306 | $this->invoice = $invoice; |
| 307 | 307 | |
| 308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 308 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | * @return bool |
| 326 | 326 | */ |
| 327 | 327 | public function has_invoice() { |
| 328 | - return ! empty( $this->invoice ); |
|
| 328 | + return !empty($this->invoice); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /* |
@@ -344,13 +344,13 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | public function process_items() { |
| 346 | 346 | |
| 347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 347 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 348 | 348 | |
| 349 | - foreach ( $processor->items as $item ) { |
|
| 350 | - $this->add_item( $item ); |
|
| 349 | + foreach ($processor->items as $item) { |
|
| 350 | + $this->add_item($item); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 353 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -359,20 +359,20 @@ discard block |
||
| 359 | 359 | * @since 1.0.19 |
| 360 | 360 | * @param GetPaid_Form_Item $item |
| 361 | 361 | */ |
| 362 | - public function add_item( $item ) { |
|
| 362 | + public function add_item($item) { |
|
| 363 | 363 | |
| 364 | 364 | // Make sure that it is available for purchase. |
| 365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 365 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // Each submission can only contain one recurring item. |
| 370 | - if ( $item->is_recurring() ) { |
|
| 370 | + if ($item->is_recurring()) { |
|
| 371 | 371 | $this->has_recurring = $item->get_id(); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // Update the items and totals. |
| 375 | - $this->items[ $item->get_id() ] = $item; |
|
| 375 | + $this->items[$item->get_id()] = $item; |
|
| 376 | 376 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 377 | 377 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 378 | 378 | |
@@ -386,17 +386,17 @@ discard block |
||
| 386 | 386 | * |
| 387 | 387 | * @since 1.0.19 |
| 388 | 388 | */ |
| 389 | - public function remove_item( $item_id ) { |
|
| 389 | + public function remove_item($item_id) { |
|
| 390 | 390 | |
| 391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 391 | + if (isset($this->items[$item_id])) { |
|
| 392 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 393 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 394 | 394 | |
| 395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 395 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 396 | 396 | $this->has_recurring = 0; |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - unset( $this->items[ $item_id ] ); |
|
| 399 | + unset($this->items[$item_id]); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | } |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | public function get_subtotal() { |
| 410 | 410 | |
| 411 | - if ( wpinv_prices_include_tax() ) { |
|
| 411 | + if (wpinv_prices_include_tax()) { |
|
| 412 | 412 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | public function get_recurring_subtotal() { |
| 424 | 424 | |
| 425 | - if ( wpinv_prices_include_tax() ) { |
|
| 425 | + if (wpinv_prices_include_tax()) { |
|
| 426 | 426 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
| 427 | 427 | } |
| 428 | 428 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | * @return bool |
| 447 | 447 | */ |
| 448 | 448 | public function has_subscription_group() { |
| 449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 449 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | * @return bool |
| 457 | 457 | */ |
| 458 | 458 | public function has_multiple_subscription_groups() { |
| 459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 459 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /* |
@@ -476,39 +476,39 @@ discard block |
||
| 476 | 476 | public function process_taxes() { |
| 477 | 477 | |
| 478 | 478 | // Abort if we're not using taxes. |
| 479 | - if ( ! $this->use_taxes() ) { |
|
| 479 | + if (!$this->use_taxes()) { |
|
| 480 | 480 | return; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 485 | - if ( ! empty( $country ) ) { |
|
| 484 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
| 485 | + if (!empty($country)) { |
|
| 486 | 486 | $this->country = $country; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 490 | - if ( ! empty( $state ) ) { |
|
| 489 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
| 490 | + if (!empty($state)) { |
|
| 491 | 491 | $this->state = $state; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | // Confirm if the provided country and the ip country are similar. |
| 495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 496 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 495 | + $address_confirmed = $this->get_field('confirm-address'); |
|
| 496 | + if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
| 497 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | // Abort if the country is not taxable. |
| 501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 501 | + if (!wpinv_is_country_taxable($this->country)) { |
|
| 502 | 502 | return; |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 506 | 506 | |
| 507 | - foreach ( $processor->taxes as $tax ) { |
|
| 508 | - $this->add_tax( $tax ); |
|
| 507 | + foreach ($processor->taxes as $tax) { |
|
| 508 | + $this->add_tax($tax); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 511 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -517,16 +517,16 @@ discard block |
||
| 517 | 517 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 518 | 518 | * @since 1.0.19 |
| 519 | 519 | */ |
| 520 | - public function add_tax( $tax ) { |
|
| 520 | + public function add_tax($tax) { |
|
| 521 | 521 | |
| 522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 522 | + if (wpinv_round_tax_per_tax_rate()) { |
|
| 523 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
| 524 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 527 | + $this->taxes[$tax['name']] = $tax; |
|
| 528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 530 | 530 | |
| 531 | 531 | } |
| 532 | 532 | |
@@ -535,12 +535,12 @@ discard block |
||
| 535 | 535 | * |
| 536 | 536 | * @since 1.0.19 |
| 537 | 537 | */ |
| 538 | - public function remove_tax( $tax_name ) { |
|
| 538 | + public function remove_tax($tax_name) { |
|
| 539 | 539 | |
| 540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 543 | - unset( $this->taxes[ $tax_name ] ); |
|
| 540 | + if (isset($this->taxes[$tax_name])) { |
|
| 541 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 542 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 543 | + unset($this->taxes[$tax_name]); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | } |
@@ -554,11 +554,11 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | $use_taxes = wpinv_use_taxes(); |
| 556 | 556 | |
| 557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 557 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 558 | 558 | $use_taxes = false; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 561 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 562 | 562 | |
| 563 | 563 | } |
| 564 | 564 | |
@@ -607,13 +607,13 @@ discard block |
||
| 607 | 607 | |
| 608 | 608 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 609 | 609 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 610 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 611 | 611 | |
| 612 | - foreach ( $processor->discounts as $discount ) { |
|
| 613 | - $this->add_discount( $discount ); |
|
| 612 | + foreach ($processor->discounts as $discount) { |
|
| 613 | + $this->add_discount($discount); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 616 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -622,10 +622,10 @@ discard block |
||
| 622 | 622 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
| 623 | 623 | * @since 1.0.19 |
| 624 | 624 | */ |
| 625 | - public function add_discount( $discount ) { |
|
| 626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 625 | + public function add_discount($discount) { |
|
| 626 | + $this->discounts[$discount['name']] = $discount; |
|
| 627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -633,12 +633,12 @@ discard block |
||
| 633 | 633 | * |
| 634 | 634 | * @since 1.0.19 |
| 635 | 635 | */ |
| 636 | - public function remove_discount( $name ) { |
|
| 636 | + public function remove_discount($name) { |
|
| 637 | 637 | |
| 638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 641 | - unset( $this->discounts[ $name ] ); |
|
| 638 | + if (isset($this->discounts[$name])) { |
|
| 639 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 640 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 641 | + unset($this->discounts[$name]); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | } |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | * @return bool |
| 651 | 651 | */ |
| 652 | 652 | public function has_discount_code() { |
| 653 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 653 | + return !empty($this->discounts['discount_code']); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -707,13 +707,13 @@ discard block |
||
| 707 | 707 | */ |
| 708 | 708 | public function process_fees() { |
| 709 | 709 | |
| 710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 711 | 711 | |
| 712 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 713 | - $this->add_fee( $fee ); |
|
| 712 | + foreach ($fees_processor->fees as $fee) { |
|
| 713 | + $this->add_fee($fee); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 716 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -722,11 +722,11 @@ discard block |
||
| 722 | 722 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 723 | 723 | * @since 1.0.19 |
| 724 | 724 | */ |
| 725 | - public function add_fee( $fee ) { |
|
| 725 | + public function add_fee($fee) { |
|
| 726 | 726 | |
| 727 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 727 | + $this->fees[$fee['name']] = $fee; |
|
| 728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 730 | 730 | |
| 731 | 731 | } |
| 732 | 732 | |
@@ -735,12 +735,12 @@ discard block |
||
| 735 | 735 | * |
| 736 | 736 | * @since 1.0.19 |
| 737 | 737 | */ |
| 738 | - public function remove_fee( $name ) { |
|
| 738 | + public function remove_fee($name) { |
|
| 739 | 739 | |
| 740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 743 | - unset( $this->fees[ $name ] ); |
|
| 740 | + if (isset($this->fees[$name])) { |
|
| 741 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 742 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 743 | + unset($this->fees[$name]); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | } |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | * @since 1.0.19 |
| 780 | 780 | */ |
| 781 | 781 | public function has_fees() { |
| 782 | - return count( $this->fees ) !== 0; |
|
| 782 | + return count($this->fees) !== 0; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /* |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | * @since 1.0.19 |
| 798 | 798 | */ |
| 799 | 799 | public function is_initial_fetch() { |
| 800 | - return empty( $this->data['initial_state'] ); |
|
| 800 | + return empty($this->data['initial_state']); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | */ |
| 808 | 808 | public function get_total() { |
| 809 | 809 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
| 810 | - return max( $total, 0 ); |
|
| 810 | + return max($total, 0); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | /** |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | */ |
| 818 | 818 | public function get_recurring_total() { |
| 819 | 819 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
| 820 | - return max( $total, 0 ); |
|
| 820 | + return max($total, 0); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | /** |
@@ -829,12 +829,12 @@ discard block |
||
| 829 | 829 | $initial = $this->get_total(); |
| 830 | 830 | $recurring = $this->get_recurring_total(); |
| 831 | 831 | |
| 832 | - if ( $this->has_recurring == 0 ) { |
|
| 832 | + if ($this->has_recurring == 0) { |
|
| 833 | 833 | $recurring = 0; |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | $collect = $initial > 0 || $recurring > 0; |
| 837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 837 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | * @since 1.0.19 |
| 844 | 844 | */ |
| 845 | 845 | public function get_billing_email() { |
| 846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 846 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | */ |
| 854 | 854 | public function has_billing_email() { |
| 855 | 855 | $billing_email = $this->get_billing_email(); |
| 856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 856 | + return !empty($billing_email) && is_email($billing_email); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -883,8 +883,8 @@ discard block |
||
| 883 | 883 | * @since 1.0.19 |
| 884 | 884 | * @return mixed|null |
| 885 | 885 | */ |
| 886 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 886 | + public function get_field($field, $sub_array_key = null) { |
|
| 887 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
@@ -892,8 +892,8 @@ discard block |
||
| 892 | 892 | * |
| 893 | 893 | * @since 1.0.19 |
| 894 | 894 | */ |
| 895 | - public function is_required_field_set( $field ) { |
|
| 896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 895 | + public function is_required_field_set($field) { |
|
| 896 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -901,8 +901,8 @@ discard block |
||
| 901 | 901 | * |
| 902 | 902 | * @since 1.0.19 |
| 903 | 903 | */ |
| 904 | - public function format_amount( $amount ) { |
|
| 905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 904 | + public function format_amount($amount) { |
|
| 905 | + return wpinv_price($amount, $this->get_currency()); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | } |
@@ -13,30 +13,30 @@ discard block |
||
| 13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'manual'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - public $order = 11; |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + public $order = 11; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Class constructor. |
|
| 38 | - */ |
|
| 39 | - public function __construct() { |
|
| 37 | + * Class constructor. |
|
| 38 | + */ |
|
| 39 | + public function __construct() { |
|
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Process Payment. |
|
| 50 | - * |
|
| 51 | - * |
|
| 52 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | - * @param array $submission_data Posted checkout fields. |
|
| 54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 49 | + * Process Payment. |
|
| 50 | + * |
|
| 51 | + * |
|
| 52 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | + * @param array $submission_data Posted checkout fields. |
|
| 54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 58 | 58 | |
| 59 | 59 | // Mark it as paid. |
| 60 | 60 | $invoice->mark_paid(); |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | - * (Maybe) renews a manual subscription profile. |
|
| 83 | - * |
|
| 84 | - * |
|
| 85 | - * @param bool $should_expire |
|
| 82 | + * (Maybe) renews a manual subscription profile. |
|
| 83 | + * |
|
| 84 | + * |
|
| 85 | + * @param bool $should_expire |
|
| 86 | 86 | * @param WPInv_Subscription $subscription |
| 87 | - */ |
|
| 88 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 87 | + */ |
|
| 88 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 89 | 89 | |
| 90 | 90 | // Ensure its our subscription && it's active. |
| 91 | 91 | if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Processes invoice addons. |
|
| 117 | - * |
|
| 118 | - * @param WPInv_Invoice $invoice |
|
| 119 | - * @param GetPaid_Form_Item[] $items |
|
| 120 | - * @return WPInv_Invoice |
|
| 121 | - */ |
|
| 122 | - public function process_addons( $invoice, $items ) { |
|
| 116 | + * Processes invoice addons. |
|
| 117 | + * |
|
| 118 | + * @param WPInv_Invoice $invoice |
|
| 119 | + * @param GetPaid_Form_Item[] $items |
|
| 120 | + * @return WPInv_Invoice |
|
| 121 | + */ |
|
| 122 | + public function process_addons( $invoice, $items ) { |
|
| 123 | 123 | |
| 124 | 124 | foreach ( $items as $item ) { |
| 125 | 125 | $invoice->add_item( $item ); |
@@ -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 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
| 27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | public function __construct() { |
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
| 43 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
| 42 | + $this->title = __('Test Gateway', 'invoicing'); |
|
| 43 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
| 44 | 44 | |
| 45 | - add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 ); |
|
| 45 | + add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,19 +54,19 @@ discard block |
||
| 54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 58 | 58 | |
| 59 | 59 | // Mark it as paid. |
| 60 | 60 | $invoice->mark_paid(); |
| 61 | 61 | |
| 62 | 62 | // (Maybe) activate subscriptions. |
| 63 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 63 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 64 | 64 | |
| 65 | - if ( ! empty( $subscriptions ) ) { |
|
| 66 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
| 65 | + if (!empty($subscriptions)) { |
|
| 66 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
| 67 | 67 | |
| 68 | - foreach ( $subscriptions as $subscription ) { |
|
| 69 | - if ( $subscription->exists() ) { |
|
| 68 | + foreach ($subscriptions as $subscription) { |
|
| 69 | + if ($subscription->exists()) { |
|
| 70 | 70 | $subscription->activate(); |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Send to the success page. |
| 77 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 77 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | * @param bool $should_expire |
| 86 | 86 | * @param WPInv_Subscription $subscription |
| 87 | 87 | */ |
| 88 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 88 | + public function maybe_renew_subscription($should_expire, $subscription) { |
|
| 89 | 89 | |
| 90 | 90 | // Ensure its our subscription && it's active. |
| 91 | - if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
|
| 91 | + if ('manual' != $subscription->get_gateway() || !$subscription->has_status('active trialling')) { |
|
| 92 | 92 | return $should_expire; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // If this is the last renewal, complete the subscription. |
| 96 | - if ( $subscription->is_last_renewal() ) { |
|
| 96 | + if ($subscription->is_last_renewal()) { |
|
| 97 | 97 | $subscription->complete(); |
| 98 | 98 | return false; |
| 99 | 99 | } |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | * @param GetPaid_Form_Item[] $items |
| 120 | 120 | * @return WPInv_Invoice |
| 121 | 121 | */ |
| 122 | - public function process_addons( $invoice, $items ) { |
|
| 122 | + public function process_addons($invoice, $items) { |
|
| 123 | 123 | |
| 124 | - foreach ( $items as $item ) { |
|
| 125 | - $invoice->add_item( $item ); |
|
| 124 | + foreach ($items as $item) { |
|
| 125 | + $invoice->add_item($item); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $invoice->recalculate_total(); |
@@ -7,45 +7,45 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // The payment methods select title. |
| 13 | -if ( empty( $text ) ) { |
|
| 14 | - $text = __( 'Select Payment Method', 'invoicing' ); |
|
| 13 | +if (empty($text)) { |
|
| 14 | + $text = __('Select Payment Method', 'invoicing'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // An array of active payment methods. |
| 18 | -$gateways = wpinv_get_enabled_payment_gateways( true ); |
|
| 18 | +$gateways = wpinv_get_enabled_payment_gateways(true); |
|
| 19 | 19 | |
| 20 | 20 | // The current invoice id. |
| 21 | 21 | $invoice_id = 0; |
| 22 | 22 | $chosen_gateway = wpinv_get_default_gateway(); |
| 23 | 23 | |
| 24 | -if ( ! empty( $form->invoice ) ) { |
|
| 24 | +if (!empty($form->invoice)) { |
|
| 25 | 25 | $invoice_id = $form->invoice->get_id(); |
| 26 | 26 | $chosen_gateway = $form->invoice->get_gateway(); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | ?> |
| 30 | 30 | |
| 31 | - <?php do_action( 'getpaid_before_payment_form_gateway_select', $form ); ?> |
|
| 31 | + <?php do_action('getpaid_before_payment_form_gateway_select', $form); ?> |
|
| 32 | 32 | <div class="mt-4 mb-4 getpaid-gateways"> |
| 33 | 33 | |
| 34 | - <?php do_action( 'wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
| 34 | + <?php do_action('wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
| 35 | 35 | |
| 36 | 36 | <div class="getpaid-select-gateway-title-div"> |
| 37 | - <h6><?php echo sanitize_text_field( $text ); ?></h6> |
|
| 37 | + <h6><?php echo sanitize_text_field($text); ?></h6> |
|
| 38 | 38 | </div> |
| 39 | 39 | |
| 40 | 40 | <div class="getpaid-available-gateways-div"> |
| 41 | 41 | |
| 42 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
| 42 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
| 43 | 43 | |
| 44 | - <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class( $gateway ) ;?>" data-checkout-label='<?php echo esc_attr( apply_filters( "getpaid_gateway_{$gateway}_checkout_button_label", '' ) ); ?>'> |
|
| 44 | + <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class($gateway); ?>" data-checkout-label='<?php echo esc_attr(apply_filters("getpaid_gateway_{$gateway}_checkout_button_label", '')); ?>'> |
|
| 45 | 45 | |
| 46 | 46 | <label class="d-block w-100 getpaid-gateway-radio"> |
| 47 | - <input type="radio" value="<?php echo esc_attr( $gateway ) ;?>" <?php checked( $gateway, $chosen_gateway ) ;?> name="wpi-gateway"> |
|
| 48 | - <span><?php echo sanitize_text_field( wpinv_get_gateway_checkout_label( $gateway ) ); ?></span> |
|
| 47 | + <input type="radio" value="<?php echo esc_attr($gateway); ?>" <?php checked($gateway, $chosen_gateway); ?> name="wpi-gateway"> |
|
| 48 | + <span><?php echo sanitize_text_field(wpinv_get_gateway_checkout_label($gateway)); ?></span> |
|
| 49 | 49 | </label> |
| 50 | 50 | |
| 51 | 51 | </div> |
@@ -56,22 +56,22 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | <div class="getpaid-gateway-descriptions-div"> |
| 58 | 58 | |
| 59 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
| 59 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
| 60 | 60 | |
| 61 | - <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class( $gateway ) ;?>" style="display: none;"> |
|
| 61 | + <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class($gateway); ?>" style="display: none;"> |
|
| 62 | 62 | <?php |
| 63 | 63 | |
| 64 | - $description = wpinv_get_gateway_description( $gateway ); |
|
| 64 | + $description = wpinv_get_gateway_description($gateway); |
|
| 65 | 65 | |
| 66 | - if ( wpinv_is_test_mode( $gateway ) ) { |
|
| 67 | - $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) ); |
|
| 66 | + if (wpinv_is_test_mode($gateway)) { |
|
| 67 | + $sandbox_notice = apply_filters("getpaid_{$gateway}_sandbox_notice", __('SANDBOX ENABLED: No real payments will occur.', 'invoicing')); |
|
| 68 | 68 | $description = "$description $sandbox_notice"; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - echo wpautop( wp_kses_post( $description ) ); |
|
| 71 | + echo wpautop(wp_kses_post($description)); |
|
| 72 | 72 | |
| 73 | - do_action( 'wpinv_' . $gateway . '_checkout_fields', $invoice_id ) ; |
|
| 74 | - do_action( 'wpinv_' . $gateway . '_cc_form', $invoice_id, $form ) ; |
|
| 73 | + do_action('wpinv_' . $gateway . '_checkout_fields', $invoice_id); |
|
| 74 | + do_action('wpinv_' . $gateway . '_cc_form', $invoice_id, $form); |
|
| 75 | 75 | |
| 76 | 76 | ?> |
| 77 | 77 | </div> |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | <?php |
| 85 | 85 | echo aui()->alert( |
| 86 | 86 | array( |
| 87 | - 'content' => __( 'None of the available payment gateways support purchasing recurring items.', 'invoicing' ), |
|
| 87 | + 'content' => __('None of the available payment gateways support purchasing recurring items.', 'invoicing'), |
|
| 88 | 88 | 'type' => 'danger', |
| 89 | 89 | ) |
| 90 | 90 | ); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | <?php |
| 96 | 96 | echo aui()->alert( |
| 97 | 97 | array( |
| 98 | - 'content' => __( 'None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing' ), |
|
| 98 | + 'content' => __('None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing'), |
|
| 99 | 99 | 'type' => 'danger', |
| 100 | 100 | ) |
| 101 | 101 | ); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | <?php |
| 107 | 107 | echo aui()->alert( |
| 108 | 108 | array( |
| 109 | - 'content' => __( 'None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing' ), |
|
| 109 | + 'content' => __('None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing'), |
|
| 110 | 110 | 'type' => 'danger', |
| 111 | 111 | ) |
| 112 | 112 | ); |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | <?php |
| 118 | 118 | echo aui()->alert( |
| 119 | 119 | array( |
| 120 | - 'content' => __( 'There is no active payment gateway available to process your request.', 'invoicing' ), |
|
| 120 | + 'content' => __('There is no active payment gateway available to process your request.', 'invoicing'), |
|
| 121 | 121 | 'type' => 'danger', |
| 122 | 122 | ) |
| 123 | 123 | ); |
| 124 | 124 | ?> |
| 125 | 125 | </div> |
| 126 | 126 | |
| 127 | - <?php do_action( 'wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
| 127 | + <?php do_action('wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
| 128 | 128 | |
| 129 | 129 | </div> |
| 130 | - <?php do_action( 'getpaid_after_payment_form_gateway_select', $form ); ?> |
|
| 130 | + <?php do_action('getpaid_after_payment_form_gateway_select', $form); ?> |
|