@@ -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,206 +10,206 @@ 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 | - * The subscription groups. If more than 2, ensure the gateway |
|
| 93 | - * supports multiple subscriptions. |
|
| 94 | - * |
|
| 95 | - * @var array |
|
| 96 | - */ |
|
| 97 | - public $subscription_groups = array(); |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * An array of fees for the submission. |
|
| 101 | - * |
|
| 102 | - * @var array |
|
| 103 | - */ |
|
| 104 | - protected $fees = array(); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * An array of discounts for the submission. |
|
| 108 | - * |
|
| 109 | - * @var array |
|
| 110 | - */ |
|
| 111 | - protected $discounts = array(); |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * An array of taxes for the submission. |
|
| 115 | - * |
|
| 116 | - * @var array |
|
| 117 | - */ |
|
| 118 | - protected $taxes = array(); |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * An array of items for the submission. |
|
| 122 | - * |
|
| 123 | - * @var GetPaid_Form_Item[] |
|
| 124 | - */ |
|
| 125 | - protected $items = array(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * The last error. |
|
| 129 | - * |
|
| 130 | - * @var string |
|
| 131 | - */ |
|
| 132 | - public $last_error = null; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * The last error code. |
|
| 136 | - * |
|
| 137 | - * @var string |
|
| 138 | - */ |
|
| 139 | - public $last_error_code = null; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Class constructor. |
|
| 143 | - * |
|
| 144 | - */ |
|
| 145 | - public function __construct() { |
|
| 146 | - |
|
| 147 | - // Set the state and country to the default state and country. |
|
| 148 | - $this->country = wpinv_default_billing_country(); |
|
| 149 | - $this->state = wpinv_get_default_state(); |
|
| 150 | - |
|
| 151 | - // Do we have an actual submission? |
|
| 152 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 153 | - $this->load_data( $_POST ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Loads submission data. |
|
| 160 | - * |
|
| 161 | - * @param array $data |
|
| 162 | - */ |
|
| 163 | - public function load_data( $data ) { |
|
| 164 | - |
|
| 165 | - // Remove slashes from the submitted data... |
|
| 166 | - $data = wp_unslash( $data ); |
|
| 167 | - |
|
| 168 | - // Allow plugins to filter the data. |
|
| 169 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 170 | - |
|
| 171 | - // Cache it... |
|
| 172 | - $this->data = $data; |
|
| 173 | - |
|
| 174 | - // Then generate a unique id from the data. |
|
| 175 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 176 | - |
|
| 177 | - // Finally, process the submission. |
|
| 178 | - try { |
|
| 179 | - |
|
| 180 | - // Each process is passed an instance of the class (with reference) |
|
| 181 | - // and should throw an Exception whenever it encounters one. |
|
| 182 | - $processors = apply_filters( |
|
| 183 | - 'getpaid_payment_form_submission_processors', |
|
| 184 | - array( |
|
| 185 | - array( $this, 'process_payment_form' ), |
|
| 186 | - array( $this, 'process_invoice' ), |
|
| 187 | - array( $this, 'process_fees' ), |
|
| 188 | - array( $this, 'process_items' ), |
|
| 189 | - array( $this, 'process_discount' ), |
|
| 190 | - array( $this, 'process_taxes' ), |
|
| 191 | - ), |
|
| 192 | - $this |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - foreach ( $processors as $processor ) { |
|
| 196 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - } catch( GetPaid_Payment_Exception $e ) { |
|
| 200 | - $this->last_error = $e->getMessage(); |
|
| 201 | - $this->last_error_code = $e->getErrorCode(); |
|
| 202 | - } catch ( Exception $e ) { |
|
| 203 | - $this->last_error = $e->getMessage(); |
|
| 204 | - $this->last_error_code = $e->getCode(); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // Fired when we are done processing a submission. |
|
| 208 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 209 | - |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /* |
|
| 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 | + * The subscription groups. If more than 2, ensure the gateway |
|
| 93 | + * supports multiple subscriptions. |
|
| 94 | + * |
|
| 95 | + * @var array |
|
| 96 | + */ |
|
| 97 | + public $subscription_groups = array(); |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * An array of fees for the submission. |
|
| 101 | + * |
|
| 102 | + * @var array |
|
| 103 | + */ |
|
| 104 | + protected $fees = array(); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * An array of discounts for the submission. |
|
| 108 | + * |
|
| 109 | + * @var array |
|
| 110 | + */ |
|
| 111 | + protected $discounts = array(); |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * An array of taxes for the submission. |
|
| 115 | + * |
|
| 116 | + * @var array |
|
| 117 | + */ |
|
| 118 | + protected $taxes = array(); |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * An array of items for the submission. |
|
| 122 | + * |
|
| 123 | + * @var GetPaid_Form_Item[] |
|
| 124 | + */ |
|
| 125 | + protected $items = array(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * The last error. |
|
| 129 | + * |
|
| 130 | + * @var string |
|
| 131 | + */ |
|
| 132 | + public $last_error = null; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * The last error code. |
|
| 136 | + * |
|
| 137 | + * @var string |
|
| 138 | + */ |
|
| 139 | + public $last_error_code = null; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Class constructor. |
|
| 143 | + * |
|
| 144 | + */ |
|
| 145 | + public function __construct() { |
|
| 146 | + |
|
| 147 | + // Set the state and country to the default state and country. |
|
| 148 | + $this->country = wpinv_default_billing_country(); |
|
| 149 | + $this->state = wpinv_get_default_state(); |
|
| 150 | + |
|
| 151 | + // Do we have an actual submission? |
|
| 152 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 153 | + $this->load_data( $_POST ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Loads submission data. |
|
| 160 | + * |
|
| 161 | + * @param array $data |
|
| 162 | + */ |
|
| 163 | + public function load_data( $data ) { |
|
| 164 | + |
|
| 165 | + // Remove slashes from the submitted data... |
|
| 166 | + $data = wp_unslash( $data ); |
|
| 167 | + |
|
| 168 | + // Allow plugins to filter the data. |
|
| 169 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 170 | + |
|
| 171 | + // Cache it... |
|
| 172 | + $this->data = $data; |
|
| 173 | + |
|
| 174 | + // Then generate a unique id from the data. |
|
| 175 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 176 | + |
|
| 177 | + // Finally, process the submission. |
|
| 178 | + try { |
|
| 179 | + |
|
| 180 | + // Each process is passed an instance of the class (with reference) |
|
| 181 | + // and should throw an Exception whenever it encounters one. |
|
| 182 | + $processors = apply_filters( |
|
| 183 | + 'getpaid_payment_form_submission_processors', |
|
| 184 | + array( |
|
| 185 | + array( $this, 'process_payment_form' ), |
|
| 186 | + array( $this, 'process_invoice' ), |
|
| 187 | + array( $this, 'process_fees' ), |
|
| 188 | + array( $this, 'process_items' ), |
|
| 189 | + array( $this, 'process_discount' ), |
|
| 190 | + array( $this, 'process_taxes' ), |
|
| 191 | + ), |
|
| 192 | + $this |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + foreach ( $processors as $processor ) { |
|
| 196 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + } catch( GetPaid_Payment_Exception $e ) { |
|
| 200 | + $this->last_error = $e->getMessage(); |
|
| 201 | + $this->last_error_code = $e->getErrorCode(); |
|
| 202 | + } catch ( Exception $e ) { |
|
| 203 | + $this->last_error = $e->getMessage(); |
|
| 204 | + $this->last_error_code = $e->getCode(); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // Fired when we are done processing a submission. |
|
| 208 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 209 | + |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /* |
|
| 213 | 213 | |-------------------------------------------------------------------------- |
| 214 | 214 | | Payment Forms. |
| 215 | 215 | |-------------------------------------------------------------------------- |
@@ -218,39 +218,39 @@ discard block |
||
| 218 | 218 | | submission has an active payment form etc. |
| 219 | 219 | */ |
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Prepares the submission's payment form. |
|
| 223 | - * |
|
| 224 | - * @since 1.0.19 |
|
| 225 | - */ |
|
| 226 | - public function process_payment_form() { |
|
| 221 | + /** |
|
| 222 | + * Prepares the submission's payment form. |
|
| 223 | + * |
|
| 224 | + * @since 1.0.19 |
|
| 225 | + */ |
|
| 226 | + public function process_payment_form() { |
|
| 227 | 227 | |
| 228 | - // Every submission needs an active payment form. |
|
| 229 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 230 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 231 | - } |
|
| 228 | + // Every submission needs an active payment form. |
|
| 229 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 230 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // Fetch the payment form. |
|
| 234 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 233 | + // Fetch the payment form. |
|
| 234 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 235 | 235 | |
| 236 | - if ( ! $this->payment_form->is_active() ) { |
|
| 237 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 238 | - } |
|
| 236 | + if ( ! $this->payment_form->is_active() ) { |
|
| 237 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 241 | - } |
|
| 240 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | /** |
| 244 | - * Returns the payment form. |
|
| 245 | - * |
|
| 246 | - * @since 1.0.19 |
|
| 247 | - * @return GetPaid_Payment_Form |
|
| 248 | - */ |
|
| 249 | - public function get_payment_form() { |
|
| 250 | - return $this->payment_form; |
|
| 251 | - } |
|
| 244 | + * Returns the payment form. |
|
| 245 | + * |
|
| 246 | + * @since 1.0.19 |
|
| 247 | + * @return GetPaid_Payment_Form |
|
| 248 | + */ |
|
| 249 | + public function get_payment_form() { |
|
| 250 | + return $this->payment_form; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /* |
|
| 253 | + /* |
|
| 254 | 254 | |-------------------------------------------------------------------------- |
| 255 | 255 | | Invoices. |
| 256 | 256 | |-------------------------------------------------------------------------- |
@@ -259,84 +259,84 @@ discard block |
||
| 259 | 259 | | might be for an existing invoice. |
| 260 | 260 | */ |
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Prepares the submission's invoice. |
|
| 264 | - * |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - */ |
|
| 267 | - public function process_invoice() { |
|
| 262 | + /** |
|
| 263 | + * Prepares the submission's invoice. |
|
| 264 | + * |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + */ |
|
| 267 | + public function process_invoice() { |
|
| 268 | 268 | |
| 269 | - // Abort if there is no invoice. |
|
| 270 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 271 | - return; |
|
| 272 | - } |
|
| 269 | + // Abort if there is no invoice. |
|
| 270 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 271 | + return; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 275 | - // and that it is not paid for. |
|
| 276 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 274 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 275 | + // and that it is not paid for. |
|
| 276 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 277 | 277 | |
| 278 | 278 | if ( empty( $invoice ) ) { |
| 279 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 280 | - } |
|
| 279 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - if ( $invoice->is_paid() ) { |
|
| 283 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 284 | - } |
|
| 282 | + if ( $invoice->is_paid() ) { |
|
| 283 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - $this->payment_form->invoice = $invoice; |
|
| 287 | - if ( ! $this->payment_form->is_default() ) { |
|
| 286 | + $this->payment_form->invoice = $invoice; |
|
| 287 | + if ( ! $this->payment_form->is_default() ) { |
|
| 288 | 288 | |
| 289 | - $items = array(); |
|
| 290 | - $item_ids = array(); |
|
| 289 | + $items = array(); |
|
| 290 | + $item_ids = array(); |
|
| 291 | 291 | |
| 292 | - foreach ( $invoice->get_items() as $item ) { |
|
| 293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | - $item_ids[] = $item->get_id(); |
|
| 295 | - $items[] = $item; |
|
| 296 | - } |
|
| 297 | - } |
|
| 292 | + foreach ( $invoice->get_items() as $item ) { |
|
| 293 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | + $item_ids[] = $item->get_id(); |
|
| 295 | + $items[] = $item; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 300 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 301 | - $item_ids[] = $item->get_id(); |
|
| 302 | - $items[] = $item; |
|
| 303 | - } |
|
| 304 | - } |
|
| 299 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
| 300 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 301 | + $item_ids[] = $item->get_id(); |
|
| 302 | + $items[] = $item; |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - $this->payment_form->set_items( $items ); |
|
| 306 | + $this->payment_form->set_items( $items ); |
|
| 307 | 307 | |
| 308 | - } else { |
|
| 309 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $this->country = $invoice->get_country(); |
|
| 313 | - $this->state = $invoice->get_state(); |
|
| 314 | - $this->invoice = $invoice; |
|
| 315 | - |
|
| 316 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Returns the associated invoice. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @return WPInv_Invoice |
|
| 324 | - */ |
|
| 325 | - public function get_invoice() { |
|
| 326 | - return $this->invoice; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Checks whether there is an invoice associated with this submission. |
|
| 331 | - * |
|
| 332 | - * @since 1.0.19 |
|
| 333 | - * @return bool |
|
| 334 | - */ |
|
| 335 | - public function has_invoice() { |
|
| 336 | - return ! empty( $this->invoice ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /* |
|
| 308 | + } else { |
|
| 309 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $this->country = $invoice->get_country(); |
|
| 313 | + $this->state = $invoice->get_state(); |
|
| 314 | + $this->invoice = $invoice; |
|
| 315 | + |
|
| 316 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Returns the associated invoice. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @return WPInv_Invoice |
|
| 324 | + */ |
|
| 325 | + public function get_invoice() { |
|
| 326 | + return $this->invoice; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Checks whether there is an invoice associated with this submission. |
|
| 331 | + * |
|
| 332 | + * @since 1.0.19 |
|
| 333 | + * @return bool |
|
| 334 | + */ |
|
| 335 | + public function has_invoice() { |
|
| 336 | + return ! empty( $this->invoice ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /* |
|
| 340 | 340 | |-------------------------------------------------------------------------- |
| 341 | 341 | | Items. |
| 342 | 342 | |-------------------------------------------------------------------------- |
@@ -345,110 +345,110 @@ discard block |
||
| 345 | 345 | | recurring item. But can have an unlimited number of non-recurring items. |
| 346 | 346 | */ |
| 347 | 347 | |
| 348 | - /** |
|
| 349 | - * Prepares the submission's items. |
|
| 350 | - * |
|
| 351 | - * @since 1.0.19 |
|
| 352 | - */ |
|
| 353 | - public function process_items() { |
|
| 354 | - |
|
| 355 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 356 | - |
|
| 357 | - foreach ( $processor->items as $item ) { |
|
| 358 | - $this->add_item( $item ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Adds an item to the submission. |
|
| 366 | - * |
|
| 367 | - * @since 1.0.19 |
|
| 368 | - * @param GetPaid_Form_Item $item |
|
| 369 | - */ |
|
| 370 | - public function add_item( $item ) { |
|
| 371 | - |
|
| 372 | - // Make sure that it is available for purchase. |
|
| 373 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 374 | - return; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - // Each submission can only contain one recurring item. |
|
| 378 | - if ( $item->is_recurring() ) { |
|
| 379 | - $this->has_recurring = $item->get_id(); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - // Update the items and totals. |
|
| 383 | - $this->items[ $item->get_id() ] = $item; |
|
| 384 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 385 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 386 | - |
|
| 387 | - $this->subscription_groups = getpaid_calculate_subscription_totals( $this ); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Removes a specific item. |
|
| 392 | - * |
|
| 393 | - * You should not call this method after the discounts and taxes |
|
| 394 | - * have been calculated. |
|
| 395 | - * |
|
| 396 | - * @since 1.0.19 |
|
| 397 | - */ |
|
| 398 | - public function remove_item( $item_id ) { |
|
| 399 | - |
|
| 400 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 401 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 402 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 403 | - |
|
| 404 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 405 | - $this->has_recurring = 0; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - unset( $this->items[ $item_id ] ); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Returns the subtotal. |
|
| 415 | - * |
|
| 416 | - * @since 1.0.19 |
|
| 417 | - */ |
|
| 418 | - public function get_subtotal() { |
|
| 419 | - |
|
| 420 | - if ( wpinv_prices_include_tax() ) { |
|
| 421 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - return $this->totals['subtotal']['initial']; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Returns the recurring subtotal. |
|
| 429 | - * |
|
| 430 | - * @since 1.0.19 |
|
| 431 | - */ |
|
| 432 | - public function get_recurring_subtotal() { |
|
| 433 | - |
|
| 434 | - if ( wpinv_prices_include_tax() ) { |
|
| 435 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $this->totals['subtotal']['recurring']; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Returns all items. |
|
| 443 | - * |
|
| 444 | - * @since 1.0.19 |
|
| 445 | - * @return GetPaid_Form_Item[] |
|
| 446 | - */ |
|
| 447 | - public function get_items() { |
|
| 448 | - return $this->items; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /* |
|
| 348 | + /** |
|
| 349 | + * Prepares the submission's items. |
|
| 350 | + * |
|
| 351 | + * @since 1.0.19 |
|
| 352 | + */ |
|
| 353 | + public function process_items() { |
|
| 354 | + |
|
| 355 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 356 | + |
|
| 357 | + foreach ( $processor->items as $item ) { |
|
| 358 | + $this->add_item( $item ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Adds an item to the submission. |
|
| 366 | + * |
|
| 367 | + * @since 1.0.19 |
|
| 368 | + * @param GetPaid_Form_Item $item |
|
| 369 | + */ |
|
| 370 | + public function add_item( $item ) { |
|
| 371 | + |
|
| 372 | + // Make sure that it is available for purchase. |
|
| 373 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + // Each submission can only contain one recurring item. |
|
| 378 | + if ( $item->is_recurring() ) { |
|
| 379 | + $this->has_recurring = $item->get_id(); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + // Update the items and totals. |
|
| 383 | + $this->items[ $item->get_id() ] = $item; |
|
| 384 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 385 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 386 | + |
|
| 387 | + $this->subscription_groups = getpaid_calculate_subscription_totals( $this ); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Removes a specific item. |
|
| 392 | + * |
|
| 393 | + * You should not call this method after the discounts and taxes |
|
| 394 | + * have been calculated. |
|
| 395 | + * |
|
| 396 | + * @since 1.0.19 |
|
| 397 | + */ |
|
| 398 | + public function remove_item( $item_id ) { |
|
| 399 | + |
|
| 400 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 401 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 402 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 403 | + |
|
| 404 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 405 | + $this->has_recurring = 0; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + unset( $this->items[ $item_id ] ); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Returns the subtotal. |
|
| 415 | + * |
|
| 416 | + * @since 1.0.19 |
|
| 417 | + */ |
|
| 418 | + public function get_subtotal() { |
|
| 419 | + |
|
| 420 | + if ( wpinv_prices_include_tax() ) { |
|
| 421 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + return $this->totals['subtotal']['initial']; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Returns the recurring subtotal. |
|
| 429 | + * |
|
| 430 | + * @since 1.0.19 |
|
| 431 | + */ |
|
| 432 | + public function get_recurring_subtotal() { |
|
| 433 | + |
|
| 434 | + if ( wpinv_prices_include_tax() ) { |
|
| 435 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $this->totals['subtotal']['recurring']; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Returns all items. |
|
| 443 | + * |
|
| 444 | + * @since 1.0.19 |
|
| 445 | + * @return GetPaid_Form_Item[] |
|
| 446 | + */ |
|
| 447 | + public function get_items() { |
|
| 448 | + return $this->items; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /* |
|
| 452 | 452 | |-------------------------------------------------------------------------- |
| 453 | 453 | | Taxes |
| 454 | 454 | |-------------------------------------------------------------------------- |
@@ -457,128 +457,128 @@ discard block |
||
| 457 | 457 | | or only one-time. |
| 458 | 458 | */ |
| 459 | 459 | |
| 460 | - /** |
|
| 461 | - * Prepares the submission's taxes. |
|
| 462 | - * |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - */ |
|
| 465 | - public function process_taxes() { |
|
| 466 | - |
|
| 467 | - // Abort if we're not using taxes. |
|
| 468 | - if ( ! $this->use_taxes() ) { |
|
| 469 | - return; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 473 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 474 | - if ( ! empty( $country ) ) { |
|
| 475 | - $this->country = $country; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 479 | - if ( ! empty( $state ) ) { |
|
| 480 | - $this->state = $state; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // Confirm if the provided country and the ip country are similar. |
|
| 484 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 485 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 486 | - 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' ) ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // Abort if the country is not taxable. |
|
| 490 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 491 | - return; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 495 | - |
|
| 496 | - foreach ( $processor->taxes as $tax ) { |
|
| 497 | - $this->add_tax( $tax ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Adds a tax to the submission. |
|
| 505 | - * |
|
| 506 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 507 | - * @since 1.0.19 |
|
| 508 | - */ |
|
| 509 | - public function add_tax( $tax ) { |
|
| 510 | - |
|
| 511 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 512 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 513 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 517 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 518 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 519 | - |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Removes a specific tax. |
|
| 524 | - * |
|
| 525 | - * @since 1.0.19 |
|
| 526 | - */ |
|
| 527 | - public function remove_tax( $tax_name ) { |
|
| 528 | - |
|
| 529 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 530 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 531 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 532 | - unset( $this->taxes[ $tax_name ] ); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Whether or not we'll use taxes for the submission. |
|
| 539 | - * |
|
| 540 | - * @since 1.0.19 |
|
| 541 | - */ |
|
| 542 | - public function use_taxes() { |
|
| 543 | - |
|
| 544 | - $use_taxes = wpinv_use_taxes(); |
|
| 545 | - |
|
| 546 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 547 | - $use_taxes = false; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 551 | - |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Returns the tax. |
|
| 556 | - * |
|
| 557 | - * @since 1.0.19 |
|
| 558 | - */ |
|
| 559 | - public function get_tax() { |
|
| 560 | - return $this->totals['taxes']['initial']; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Returns the recurring tax. |
|
| 565 | - * |
|
| 566 | - * @since 1.0.19 |
|
| 567 | - */ |
|
| 568 | - public function get_recurring_tax() { |
|
| 569 | - return $this->totals['taxes']['recurring']; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Returns all taxes. |
|
| 574 | - * |
|
| 575 | - * @since 1.0.19 |
|
| 576 | - */ |
|
| 577 | - public function get_taxes() { |
|
| 578 | - return $this->taxes; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /* |
|
| 460 | + /** |
|
| 461 | + * Prepares the submission's taxes. |
|
| 462 | + * |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + */ |
|
| 465 | + public function process_taxes() { |
|
| 466 | + |
|
| 467 | + // Abort if we're not using taxes. |
|
| 468 | + if ( ! $this->use_taxes() ) { |
|
| 469 | + return; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 473 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 474 | + if ( ! empty( $country ) ) { |
|
| 475 | + $this->country = $country; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 479 | + if ( ! empty( $state ) ) { |
|
| 480 | + $this->state = $state; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // Confirm if the provided country and the ip country are similar. |
|
| 484 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 485 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 486 | + 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' ) ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // Abort if the country is not taxable. |
|
| 490 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 491 | + return; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 495 | + |
|
| 496 | + foreach ( $processor->taxes as $tax ) { |
|
| 497 | + $this->add_tax( $tax ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Adds a tax to the submission. |
|
| 505 | + * |
|
| 506 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 507 | + * @since 1.0.19 |
|
| 508 | + */ |
|
| 509 | + public function add_tax( $tax ) { |
|
| 510 | + |
|
| 511 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 512 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 513 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 517 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 518 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 519 | + |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Removes a specific tax. |
|
| 524 | + * |
|
| 525 | + * @since 1.0.19 |
|
| 526 | + */ |
|
| 527 | + public function remove_tax( $tax_name ) { |
|
| 528 | + |
|
| 529 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 530 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 531 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 532 | + unset( $this->taxes[ $tax_name ] ); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Whether or not we'll use taxes for the submission. |
|
| 539 | + * |
|
| 540 | + * @since 1.0.19 |
|
| 541 | + */ |
|
| 542 | + public function use_taxes() { |
|
| 543 | + |
|
| 544 | + $use_taxes = wpinv_use_taxes(); |
|
| 545 | + |
|
| 546 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 547 | + $use_taxes = false; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 551 | + |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Returns the tax. |
|
| 556 | + * |
|
| 557 | + * @since 1.0.19 |
|
| 558 | + */ |
|
| 559 | + public function get_tax() { |
|
| 560 | + return $this->totals['taxes']['initial']; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Returns the recurring tax. |
|
| 565 | + * |
|
| 566 | + * @since 1.0.19 |
|
| 567 | + */ |
|
| 568 | + public function get_recurring_tax() { |
|
| 569 | + return $this->totals['taxes']['recurring']; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Returns all taxes. |
|
| 574 | + * |
|
| 575 | + * @since 1.0.19 |
|
| 576 | + */ |
|
| 577 | + public function get_taxes() { |
|
| 578 | + return $this->taxes; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /* |
|
| 582 | 582 | |-------------------------------------------------------------------------- |
| 583 | 583 | | Discounts |
| 584 | 584 | |-------------------------------------------------------------------------- |
@@ -587,99 +587,99 @@ discard block |
||
| 587 | 587 | | or only one-time. They also do not have to come from a discount code. |
| 588 | 588 | */ |
| 589 | 589 | |
| 590 | - /** |
|
| 591 | - * Prepares the submission's discount. |
|
| 592 | - * |
|
| 593 | - * @since 1.0.19 |
|
| 594 | - */ |
|
| 595 | - public function process_discount() { |
|
| 596 | - |
|
| 597 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 598 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 599 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 600 | - |
|
| 601 | - foreach ( $processor->discounts as $discount ) { |
|
| 602 | - $this->add_discount( $discount ); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Adds a discount to the submission. |
|
| 610 | - * |
|
| 611 | - * @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. |
|
| 612 | - * @since 1.0.19 |
|
| 613 | - */ |
|
| 614 | - public function add_discount( $discount ) { |
|
| 615 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 616 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 617 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Removes a discount from the submission. |
|
| 622 | - * |
|
| 623 | - * @since 1.0.19 |
|
| 624 | - */ |
|
| 625 | - public function remove_discount( $name ) { |
|
| 626 | - |
|
| 627 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 628 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 629 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 630 | - unset( $this->discounts[ $name ] ); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Checks whether there is a discount code associated with this submission. |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @return bool |
|
| 640 | - */ |
|
| 641 | - public function has_discount_code() { |
|
| 642 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Returns the discount code. |
|
| 647 | - * |
|
| 648 | - * @since 1.0.19 |
|
| 649 | - * @return string |
|
| 650 | - */ |
|
| 651 | - public function get_discount_code() { |
|
| 652 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * Returns the discount. |
|
| 657 | - * |
|
| 658 | - * @since 1.0.19 |
|
| 659 | - */ |
|
| 660 | - public function get_discount() { |
|
| 661 | - return $this->totals['discount']['initial']; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Returns the recurring discount. |
|
| 666 | - * |
|
| 667 | - * @since 1.0.19 |
|
| 668 | - */ |
|
| 669 | - public function get_recurring_discount() { |
|
| 670 | - return $this->totals['discount']['recurring']; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Returns all discounts. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - */ |
|
| 678 | - public function get_discounts() { |
|
| 679 | - return $this->discounts; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /* |
|
| 590 | + /** |
|
| 591 | + * Prepares the submission's discount. |
|
| 592 | + * |
|
| 593 | + * @since 1.0.19 |
|
| 594 | + */ |
|
| 595 | + public function process_discount() { |
|
| 596 | + |
|
| 597 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 598 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 599 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 600 | + |
|
| 601 | + foreach ( $processor->discounts as $discount ) { |
|
| 602 | + $this->add_discount( $discount ); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Adds a discount to the submission. |
|
| 610 | + * |
|
| 611 | + * @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. |
|
| 612 | + * @since 1.0.19 |
|
| 613 | + */ |
|
| 614 | + public function add_discount( $discount ) { |
|
| 615 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 616 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 617 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Removes a discount from the submission. |
|
| 622 | + * |
|
| 623 | + * @since 1.0.19 |
|
| 624 | + */ |
|
| 625 | + public function remove_discount( $name ) { |
|
| 626 | + |
|
| 627 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 628 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 629 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 630 | + unset( $this->discounts[ $name ] ); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Checks whether there is a discount code associated with this submission. |
|
| 637 | + * |
|
| 638 | + * @since 1.0.19 |
|
| 639 | + * @return bool |
|
| 640 | + */ |
|
| 641 | + public function has_discount_code() { |
|
| 642 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Returns the discount code. |
|
| 647 | + * |
|
| 648 | + * @since 1.0.19 |
|
| 649 | + * @return string |
|
| 650 | + */ |
|
| 651 | + public function get_discount_code() { |
|
| 652 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * Returns the discount. |
|
| 657 | + * |
|
| 658 | + * @since 1.0.19 |
|
| 659 | + */ |
|
| 660 | + public function get_discount() { |
|
| 661 | + return $this->totals['discount']['initial']; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Returns the recurring discount. |
|
| 666 | + * |
|
| 667 | + * @since 1.0.19 |
|
| 668 | + */ |
|
| 669 | + public function get_recurring_discount() { |
|
| 670 | + return $this->totals['discount']['recurring']; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Returns all discounts. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + */ |
|
| 678 | + public function get_discounts() { |
|
| 679 | + return $this->discounts; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /* |
|
| 683 | 683 | |-------------------------------------------------------------------------- |
| 684 | 684 | | Fees |
| 685 | 685 | |-------------------------------------------------------------------------- |
@@ -689,89 +689,89 @@ discard block |
||
| 689 | 689 | | fees. |
| 690 | 690 | */ |
| 691 | 691 | |
| 692 | - /** |
|
| 693 | - * Prepares the submission's fees. |
|
| 694 | - * |
|
| 695 | - * @since 1.0.19 |
|
| 696 | - */ |
|
| 697 | - public function process_fees() { |
|
| 698 | - |
|
| 699 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 700 | - |
|
| 701 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 702 | - $this->add_fee( $fee ); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Adds a fee to the submission. |
|
| 710 | - * |
|
| 711 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - */ |
|
| 714 | - public function add_fee( $fee ) { |
|
| 715 | - |
|
| 716 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 717 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 718 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 719 | - |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Removes a fee from the submission. |
|
| 724 | - * |
|
| 725 | - * @since 1.0.19 |
|
| 726 | - */ |
|
| 727 | - public function remove_fee( $name ) { |
|
| 728 | - |
|
| 729 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 730 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 731 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 732 | - unset( $this->fees[ $name ] ); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * Returns the fees. |
|
| 739 | - * |
|
| 740 | - * @since 1.0.19 |
|
| 741 | - */ |
|
| 742 | - public function get_fee() { |
|
| 743 | - return $this->totals['fees']['initial']; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Returns the recurring fees. |
|
| 748 | - * |
|
| 749 | - * @since 1.0.19 |
|
| 750 | - */ |
|
| 751 | - public function get_recurring_fee() { |
|
| 752 | - return $this->totals['fees']['recurring']; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Returns all fees. |
|
| 757 | - * |
|
| 758 | - * @since 1.0.19 |
|
| 759 | - */ |
|
| 760 | - public function get_fees() { |
|
| 761 | - return $this->fees; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * Checks if there are any fees for the form. |
|
| 766 | - * |
|
| 767 | - * @return bool |
|
| 768 | - * @since 1.0.19 |
|
| 769 | - */ |
|
| 770 | - public function has_fees() { |
|
| 771 | - return count( $this->fees ) !== 0; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /* |
|
| 692 | + /** |
|
| 693 | + * Prepares the submission's fees. |
|
| 694 | + * |
|
| 695 | + * @since 1.0.19 |
|
| 696 | + */ |
|
| 697 | + public function process_fees() { |
|
| 698 | + |
|
| 699 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 700 | + |
|
| 701 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 702 | + $this->add_fee( $fee ); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Adds a fee to the submission. |
|
| 710 | + * |
|
| 711 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + */ |
|
| 714 | + public function add_fee( $fee ) { |
|
| 715 | + |
|
| 716 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 717 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 718 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 719 | + |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Removes a fee from the submission. |
|
| 724 | + * |
|
| 725 | + * @since 1.0.19 |
|
| 726 | + */ |
|
| 727 | + public function remove_fee( $name ) { |
|
| 728 | + |
|
| 729 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 730 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 731 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 732 | + unset( $this->fees[ $name ] ); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * Returns the fees. |
|
| 739 | + * |
|
| 740 | + * @since 1.0.19 |
|
| 741 | + */ |
|
| 742 | + public function get_fee() { |
|
| 743 | + return $this->totals['fees']['initial']; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Returns the recurring fees. |
|
| 748 | + * |
|
| 749 | + * @since 1.0.19 |
|
| 750 | + */ |
|
| 751 | + public function get_recurring_fee() { |
|
| 752 | + return $this->totals['fees']['recurring']; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Returns all fees. |
|
| 757 | + * |
|
| 758 | + * @since 1.0.19 |
|
| 759 | + */ |
|
| 760 | + public function get_fees() { |
|
| 761 | + return $this->fees; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * Checks if there are any fees for the form. |
|
| 766 | + * |
|
| 767 | + * @return bool |
|
| 768 | + * @since 1.0.19 |
|
| 769 | + */ |
|
| 770 | + public function has_fees() { |
|
| 771 | + return count( $this->fees ) !== 0; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + /* |
|
| 775 | 775 | |-------------------------------------------------------------------------- |
| 776 | 776 | | MISC |
| 777 | 777 | |-------------------------------------------------------------------------- |
@@ -779,119 +779,119 @@ discard block |
||
| 779 | 779 | | Extra submission functions. |
| 780 | 780 | */ |
| 781 | 781 | |
| 782 | - /** |
|
| 783 | - * Checks if this is the initial fetch. |
|
| 784 | - * |
|
| 785 | - * @return bool |
|
| 786 | - * @since 1.0.19 |
|
| 787 | - */ |
|
| 788 | - public function is_initial_fetch() { |
|
| 789 | - return empty( $this->data['initial_state'] ); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * Returns the total amount to collect for this submission. |
|
| 794 | - * |
|
| 795 | - * @since 1.0.19 |
|
| 796 | - */ |
|
| 797 | - public function get_total() { |
|
| 798 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 799 | - return max( $total, 0 ); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Returns the recurring total amount to collect for this submission. |
|
| 804 | - * |
|
| 805 | - * @since 1.0.19 |
|
| 806 | - */ |
|
| 807 | - public function get_recurring_total() { |
|
| 808 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 809 | - return max( $total, 0 ); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * Whether payment details should be collected for this submission. |
|
| 814 | - * |
|
| 815 | - * @since 1.0.19 |
|
| 816 | - */ |
|
| 817 | - public function should_collect_payment_details() { |
|
| 818 | - $initial = $this->get_total(); |
|
| 819 | - $recurring = $this->get_recurring_total(); |
|
| 820 | - |
|
| 821 | - if ( $this->has_recurring == 0 ) { |
|
| 822 | - $recurring = 0; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - $collect = $initial > 0 || $recurring > 0; |
|
| 826 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * Returns the billing email of the user. |
|
| 831 | - * |
|
| 832 | - * @since 1.0.19 |
|
| 833 | - */ |
|
| 834 | - public function get_billing_email() { |
|
| 835 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Checks if the submitter has a billing email. |
|
| 840 | - * |
|
| 841 | - * @since 1.0.19 |
|
| 842 | - */ |
|
| 843 | - public function has_billing_email() { |
|
| 844 | - $billing_email = $this->get_billing_email(); |
|
| 845 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Returns the appropriate currency for the submission. |
|
| 850 | - * |
|
| 851 | - * @since 1.0.19 |
|
| 852 | - * @return string |
|
| 853 | - */ |
|
| 854 | - public function get_currency() { |
|
| 855 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * Returns the raw submission data. |
|
| 860 | - * |
|
| 861 | - * @since 1.0.19 |
|
| 862 | - * @return array |
|
| 863 | - */ |
|
| 864 | - public function get_data() { |
|
| 865 | - return $this->data; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * Returns a field from the submission data |
|
| 870 | - * |
|
| 871 | - * @param string $field |
|
| 872 | - * @since 1.0.19 |
|
| 873 | - * @return mixed|null |
|
| 874 | - */ |
|
| 875 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 876 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * Checks if a required field is set. |
|
| 881 | - * |
|
| 882 | - * @since 1.0.19 |
|
| 883 | - */ |
|
| 884 | - public function is_required_field_set( $field ) { |
|
| 885 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * Formats an amount |
|
| 890 | - * |
|
| 891 | - * @since 1.0.19 |
|
| 892 | - */ |
|
| 893 | - public function format_amount( $amount ) { |
|
| 894 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 895 | - } |
|
| 782 | + /** |
|
| 783 | + * Checks if this is the initial fetch. |
|
| 784 | + * |
|
| 785 | + * @return bool |
|
| 786 | + * @since 1.0.19 |
|
| 787 | + */ |
|
| 788 | + public function is_initial_fetch() { |
|
| 789 | + return empty( $this->data['initial_state'] ); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * Returns the total amount to collect for this submission. |
|
| 794 | + * |
|
| 795 | + * @since 1.0.19 |
|
| 796 | + */ |
|
| 797 | + public function get_total() { |
|
| 798 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 799 | + return max( $total, 0 ); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Returns the recurring total amount to collect for this submission. |
|
| 804 | + * |
|
| 805 | + * @since 1.0.19 |
|
| 806 | + */ |
|
| 807 | + public function get_recurring_total() { |
|
| 808 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 809 | + return max( $total, 0 ); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * Whether payment details should be collected for this submission. |
|
| 814 | + * |
|
| 815 | + * @since 1.0.19 |
|
| 816 | + */ |
|
| 817 | + public function should_collect_payment_details() { |
|
| 818 | + $initial = $this->get_total(); |
|
| 819 | + $recurring = $this->get_recurring_total(); |
|
| 820 | + |
|
| 821 | + if ( $this->has_recurring == 0 ) { |
|
| 822 | + $recurring = 0; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + $collect = $initial > 0 || $recurring > 0; |
|
| 826 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * Returns the billing email of the user. |
|
| 831 | + * |
|
| 832 | + * @since 1.0.19 |
|
| 833 | + */ |
|
| 834 | + public function get_billing_email() { |
|
| 835 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Checks if the submitter has a billing email. |
|
| 840 | + * |
|
| 841 | + * @since 1.0.19 |
|
| 842 | + */ |
|
| 843 | + public function has_billing_email() { |
|
| 844 | + $billing_email = $this->get_billing_email(); |
|
| 845 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Returns the appropriate currency for the submission. |
|
| 850 | + * |
|
| 851 | + * @since 1.0.19 |
|
| 852 | + * @return string |
|
| 853 | + */ |
|
| 854 | + public function get_currency() { |
|
| 855 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * Returns the raw submission data. |
|
| 860 | + * |
|
| 861 | + * @since 1.0.19 |
|
| 862 | + * @return array |
|
| 863 | + */ |
|
| 864 | + public function get_data() { |
|
| 865 | + return $this->data; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * Returns a field from the submission data |
|
| 870 | + * |
|
| 871 | + * @param string $field |
|
| 872 | + * @since 1.0.19 |
|
| 873 | + * @return mixed|null |
|
| 874 | + */ |
|
| 875 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 876 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * Checks if a required field is set. |
|
| 881 | + * |
|
| 882 | + * @since 1.0.19 |
|
| 883 | + */ |
|
| 884 | + public function is_required_field_set( $field ) { |
|
| 885 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * Formats an amount |
|
| 890 | + * |
|
| 891 | + * @since 1.0.19 |
|
| 892 | + */ |
|
| 893 | + public function format_amount( $amount ) { |
|
| 894 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | 897 | } |
@@ -12,281 +12,281 @@ |
||
| 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_multiple_subscriptions' => $submission->has_recurring && 1 < count( getpaid_get_subscription_groups( $submission ) ), |
|
| 31 | + 'has_multiple_subscriptions' => $submission->has_recurring && 1 < count( getpaid_get_subscription_groups( $submission ) ), |
|
| 32 | 32 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 33 | - ); |
|
| 34 | - |
|
| 35 | - $this->add_totals( $submission ); |
|
| 36 | - $this->add_texts( $submission ); |
|
| 37 | - $this->add_items( $submission ); |
|
| 38 | - $this->add_fees( $submission ); |
|
| 39 | - $this->add_discounts( $submission ); |
|
| 40 | - $this->add_taxes( $submission ); |
|
| 41 | - $this->add_gateways( $submission ); |
|
| 42 | - $this->add_data( $submission ); |
|
| 43 | - |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Adds totals to a response for submission refresh prices. |
|
| 48 | - * |
|
| 49 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 50 | - */ |
|
| 51 | - public function add_totals( $submission ) { |
|
| 52 | - |
|
| 53 | - $this->response = array_merge( |
|
| 54 | - $this->response, |
|
| 55 | - array( |
|
| 56 | - |
|
| 57 | - 'totals' => array( |
|
| 58 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 59 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 60 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 61 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 62 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 63 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 64 | - ), |
|
| 65 | - |
|
| 66 | - 'recurring' => array( |
|
| 67 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 68 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 69 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 70 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 71 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 72 | - ), |
|
| 73 | - |
|
| 74 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 75 | - 'currency' => $submission->get_currency(), |
|
| 76 | - |
|
| 77 | - ) |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Adds texts to a response for submission refresh prices. |
|
| 84 | - * |
|
| 85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | - */ |
|
| 87 | - public function add_texts( $submission ) { |
|
| 88 | - |
|
| 89 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 90 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 91 | - |
|
| 92 | - if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
| 93 | - |
|
| 94 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 95 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 96 | - |
|
| 97 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 98 | - $payable = "$payable / $period"; |
|
| 99 | - } else { |
|
| 100 | - $payable = sprintf( |
|
| 101 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 102 | - $submission->format_amount( $submission->get_total() ), |
|
| 103 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 104 | - $period |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $texts = array( |
|
| 111 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - foreach ( $submission->get_items() as $item ) { |
|
| 115 | - $item_id = $item->get_id(); |
|
| 116 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 117 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 118 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 122 | - |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Adds items to a response for submission refresh prices. |
|
| 127 | - * |
|
| 128 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 129 | - */ |
|
| 130 | - public function add_items( $submission ) { |
|
| 131 | - |
|
| 132 | - // Add items. |
|
| 133 | - $items = array(); |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + $this->add_totals( $submission ); |
|
| 36 | + $this->add_texts( $submission ); |
|
| 37 | + $this->add_items( $submission ); |
|
| 38 | + $this->add_fees( $submission ); |
|
| 39 | + $this->add_discounts( $submission ); |
|
| 40 | + $this->add_taxes( $submission ); |
|
| 41 | + $this->add_gateways( $submission ); |
|
| 42 | + $this->add_data( $submission ); |
|
| 43 | + |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Adds totals to a response for submission refresh prices. |
|
| 48 | + * |
|
| 49 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 50 | + */ |
|
| 51 | + public function add_totals( $submission ) { |
|
| 52 | + |
|
| 53 | + $this->response = array_merge( |
|
| 54 | + $this->response, |
|
| 55 | + array( |
|
| 56 | + |
|
| 57 | + 'totals' => array( |
|
| 58 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 59 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 60 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 61 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 62 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 63 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 64 | + ), |
|
| 65 | + |
|
| 66 | + 'recurring' => array( |
|
| 67 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 68 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 69 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 70 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 71 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 72 | + ), |
|
| 73 | + |
|
| 74 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 75 | + 'currency' => $submission->get_currency(), |
|
| 76 | + |
|
| 77 | + ) |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Adds texts to a response for submission refresh prices. |
|
| 84 | + * |
|
| 85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | + */ |
|
| 87 | + public function add_texts( $submission ) { |
|
| 88 | + |
|
| 89 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 90 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
| 91 | + |
|
| 92 | + if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
| 93 | + |
|
| 94 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 95 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 96 | + |
|
| 97 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 98 | + $payable = "$payable / $period"; |
|
| 99 | + } else { |
|
| 100 | + $payable = sprintf( |
|
| 101 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 102 | + $submission->format_amount( $submission->get_total() ), |
|
| 103 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 104 | + $period |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $texts = array( |
|
| 111 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 112 | + ); |
|
| 134 | 113 | |
| 135 | 114 | foreach ( $submission->get_items() as $item ) { |
| 136 | - $item_id = $item->get_id(); |
|
| 137 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 138 | - } |
|
| 115 | + $item_id = $item->get_id(); |
|
| 116 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 117 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 118 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 119 | + } |
|
| 139 | 120 | |
| 140 | - $this->response = array_merge( |
|
| 141 | - $this->response, |
|
| 142 | - array( 'items' => $items ) |
|
| 143 | - ); |
|
| 121 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 144 | 122 | |
| 145 | - } |
|
| 123 | + } |
|
| 146 | 124 | |
| 147 | - /** |
|
| 148 | - * Adds fees to a response for submission refresh prices. |
|
| 149 | - * |
|
| 150 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 151 | - */ |
|
| 152 | - public function add_fees( $submission ) { |
|
| 125 | + /** |
|
| 126 | + * Adds items to a response for submission refresh prices. |
|
| 127 | + * |
|
| 128 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 129 | + */ |
|
| 130 | + public function add_items( $submission ) { |
|
| 153 | 131 | |
| 154 | - $fees = array(); |
|
| 132 | + // Add items. |
|
| 133 | + $items = array(); |
|
| 155 | 134 | |
| 156 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
| 157 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 158 | - } |
|
| 135 | + foreach ( $submission->get_items() as $item ) { |
|
| 136 | + $item_id = $item->get_id(); |
|
| 137 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 138 | + } |
|
| 159 | 139 | |
| 160 | - $this->response = array_merge( |
|
| 161 | - $this->response, |
|
| 162 | - array( 'fees' => $fees ) |
|
| 163 | - ); |
|
| 140 | + $this->response = array_merge( |
|
| 141 | + $this->response, |
|
| 142 | + array( 'items' => $items ) |
|
| 143 | + ); |
|
| 164 | 144 | |
| 165 | - } |
|
| 145 | + } |
|
| 166 | 146 | |
| 167 | - /** |
|
| 168 | - * Adds discounts to a response for submission refresh prices. |
|
| 169 | - * |
|
| 170 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | - */ |
|
| 172 | - public function add_discounts( $submission ) { |
|
| 147 | + /** |
|
| 148 | + * Adds fees to a response for submission refresh prices. |
|
| 149 | + * |
|
| 150 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 151 | + */ |
|
| 152 | + public function add_fees( $submission ) { |
|
| 173 | 153 | |
| 174 | - $discounts = array(); |
|
| 154 | + $fees = array(); |
|
| 175 | 155 | |
| 176 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 177 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 178 | - } |
|
| 156 | + foreach ( $submission->get_fees() as $name => $data ) { |
|
| 157 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 158 | + } |
|
| 179 | 159 | |
| 180 | - $this->response = array_merge( |
|
| 181 | - $this->response, |
|
| 182 | - array( 'discounts' => $discounts ) |
|
| 183 | - ); |
|
| 160 | + $this->response = array_merge( |
|
| 161 | + $this->response, |
|
| 162 | + array( 'fees' => $fees ) |
|
| 163 | + ); |
|
| 184 | 164 | |
| 185 | - } |
|
| 165 | + } |
|
| 186 | 166 | |
| 187 | - /** |
|
| 188 | - * Adds taxes to a response for submission refresh prices. |
|
| 189 | - * |
|
| 190 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 191 | - */ |
|
| 192 | - public function add_taxes( $submission ) { |
|
| 167 | + /** |
|
| 168 | + * Adds discounts to a response for submission refresh prices. |
|
| 169 | + * |
|
| 170 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | + */ |
|
| 172 | + public function add_discounts( $submission ) { |
|
| 193 | 173 | |
| 194 | - $taxes = array(); |
|
| 195 | - $markup = ''; |
|
| 196 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 197 | - $name = sanitize_text_field( $name ); |
|
| 198 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 199 | - $taxes[$name] = $amount; |
|
| 200 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 201 | - } |
|
| 174 | + $discounts = array(); |
|
| 175 | + |
|
| 176 | + foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 177 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 178 | + } |
|
| 202 | 179 | |
| 203 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 204 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 205 | - } |
|
| 180 | + $this->response = array_merge( |
|
| 181 | + $this->response, |
|
| 182 | + array( 'discounts' => $discounts ) |
|
| 183 | + ); |
|
| 206 | 184 | |
| 207 | - $this->response = array_merge( |
|
| 208 | - $this->response, |
|
| 209 | - array( 'taxes' => $taxes ) |
|
| 210 | - ); |
|
| 185 | + } |
|
| 211 | 186 | |
| 212 | - } |
|
| 187 | + /** |
|
| 188 | + * Adds taxes to a response for submission refresh prices. |
|
| 189 | + * |
|
| 190 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 191 | + */ |
|
| 192 | + public function add_taxes( $submission ) { |
|
| 193 | + |
|
| 194 | + $taxes = array(); |
|
| 195 | + $markup = ''; |
|
| 196 | + foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 197 | + $name = sanitize_text_field( $name ); |
|
| 198 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 199 | + $taxes[$name] = $amount; |
|
| 200 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 201 | + } |
|
| 213 | 202 | |
| 214 | - /** |
|
| 215 | - * Adds gateways to a response for submission refresh prices. |
|
| 216 | - * |
|
| 217 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 218 | - */ |
|
| 219 | - public function add_gateways( $submission ) { |
|
| 203 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 204 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 205 | + } |
|
| 220 | 206 | |
| 221 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 207 | + $this->response = array_merge( |
|
| 208 | + $this->response, |
|
| 209 | + array( 'taxes' => $taxes ) |
|
| 210 | + ); |
|
| 222 | 211 | |
| 223 | - if ( $this->response['has_recurring'] ) { |
|
| 212 | + } |
|
| 224 | 213 | |
| 225 | - foreach ( $gateways as $i => $gateway ) { |
|
| 214 | + /** |
|
| 215 | + * Adds gateways to a response for submission refresh prices. |
|
| 216 | + * |
|
| 217 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 218 | + */ |
|
| 219 | + public function add_gateways( $submission ) { |
|
| 226 | 220 | |
| 227 | - if ( ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) || ( $this->response['has_multiple_subscriptions'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscriptions' ) ) ) { |
|
| 228 | - unset( $gateways[ $i ] ); |
|
| 229 | - } |
|
| 221 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 230 | 222 | |
| 231 | - } |
|
| 223 | + if ( $this->response['has_recurring'] ) { |
|
| 232 | 224 | |
| 233 | - } |
|
| 225 | + foreach ( $gateways as $i => $gateway ) { |
|
| 234 | 226 | |
| 235 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 236 | - $this->response = array_merge( |
|
| 237 | - $this->response, |
|
| 238 | - array( 'gateways' => $gateways ) |
|
| 239 | - ); |
|
| 227 | + if ( ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) || ( $this->response['has_multiple_subscriptions'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscriptions' ) ) ) { |
|
| 228 | + unset( $gateways[ $i ] ); |
|
| 229 | + } |
|
| 240 | 230 | |
| 241 | - } |
|
| 231 | + } |
|
| 242 | 232 | |
| 243 | - /** |
|
| 244 | - * Standardizes prices. |
|
| 245 | - * |
|
| 246 | - * @param int $item_id |
|
| 247 | - * @param float $item_total |
|
| 248 | - * @param string $discount_code |
|
| 249 | - * @param bool $recurring |
|
| 250 | - */ |
|
| 251 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 233 | + } |
|
| 252 | 234 | |
| 253 | - $standardadized_price = $item_total; |
|
| 235 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 236 | + $this->response = array_merge( |
|
| 237 | + $this->response, |
|
| 238 | + array( 'gateways' => $gateways ) |
|
| 239 | + ); |
|
| 254 | 240 | |
| 255 | - // Do we have a $discount_code? |
|
| 256 | - if ( ! empty( $discount_code ) ) { |
|
| 241 | + } |
|
| 257 | 242 | |
| 258 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 243 | + /** |
|
| 244 | + * Standardizes prices. |
|
| 245 | + * |
|
| 246 | + * @param int $item_id |
|
| 247 | + * @param float $item_total |
|
| 248 | + * @param string $discount_code |
|
| 249 | + * @param bool $recurring |
|
| 250 | + */ |
|
| 251 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 252 | + |
|
| 253 | + $standardadized_price = $item_total; |
|
| 259 | 254 | |
| 260 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 261 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 262 | - } |
|
| 255 | + // Do we have a $discount_code? |
|
| 256 | + if ( ! empty( $discount_code ) ) { |
|
| 263 | 257 | |
| 264 | - } |
|
| 258 | + $discount = new WPInv_Discount( $discount_code ); |
|
| 265 | 259 | |
| 266 | - return max( 0, $standardadized_price ); |
|
| 260 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 261 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 262 | + } |
|
| 267 | 263 | |
| 268 | - } |
|
| 264 | + } |
|
| 269 | 265 | |
| 270 | - /** |
|
| 271 | - * Adds data to a response for submission refresh prices. |
|
| 272 | - * |
|
| 273 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 274 | - */ |
|
| 275 | - public function add_data( $submission ) { |
|
| 266 | + return max( 0, $standardadized_price ); |
|
| 276 | 267 | |
| 277 | - $this->response = array_merge( |
|
| 278 | - $this->response, |
|
| 279 | - array( |
|
| 280 | - 'js_data' => apply_filters( |
|
| 281 | - 'getpaid_submission_js_data', |
|
| 282 | - array( |
|
| 283 | - 'is_recurring' => $this->response['has_recurring'], |
|
| 284 | - ), |
|
| 285 | - $submission |
|
| 286 | - ) |
|
| 287 | - ) |
|
| 288 | - ); |
|
| 268 | + } |
|
| 289 | 269 | |
| 290 | - } |
|
| 270 | + /** |
|
| 271 | + * Adds data to a response for submission refresh prices. |
|
| 272 | + * |
|
| 273 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 274 | + */ |
|
| 275 | + public function add_data( $submission ) { |
|
| 276 | + |
|
| 277 | + $this->response = array_merge( |
|
| 278 | + $this->response, |
|
| 279 | + array( |
|
| 280 | + 'js_data' => apply_filters( |
|
| 281 | + 'getpaid_submission_js_data', |
|
| 282 | + array( |
|
| 283 | + 'is_recurring' => $this->response['has_recurring'], |
|
| 284 | + ), |
|
| 285 | + $submission |
|
| 286 | + ) |
|
| 287 | + ) |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | 292 | } |
@@ -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', 'multiple_subscriptions' ); |
| 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(); |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * (Maybe) renews a manual subscription profile. |
|
| 72 | - * |
|
| 73 | - * |
|
| 74 | - * @param bool $should_expire |
|
| 71 | + * (Maybe) renews a manual subscription profile. |
|
| 72 | + * |
|
| 73 | + * |
|
| 74 | + * @param bool $should_expire |
|
| 75 | 75 | * @param WPInv_Subscription $subscription |
| 76 | - */ |
|
| 77 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 76 | + */ |
|
| 77 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 78 | 78 | |
| 79 | 79 | // Ensure its our subscription && it's active. |
| 80 | 80 | if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | - * Processes invoice addons. |
|
| 106 | - * |
|
| 107 | - * @param WPInv_Invoice $invoice |
|
| 108 | - * @param GetPaid_Form_Item[] $items |
|
| 109 | - * @return WPInv_Invoice |
|
| 110 | - */ |
|
| 111 | - public function process_addons( $invoice, $items ) { |
|
| 105 | + * Processes invoice addons. |
|
| 106 | + * |
|
| 107 | + * @param WPInv_Invoice $invoice |
|
| 108 | + * @param GetPaid_Form_Item[] $items |
|
| 109 | + * @return WPInv_Invoice |
|
| 110 | + */ |
|
| 111 | + public function process_addons( $invoice, $items ) { |
|
| 112 | 112 | |
| 113 | 113 | foreach ( $items as $item ) { |
| 114 | 114 | $invoice->add_item( $item ); |
@@ -13,461 +13,461 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GetPaid_Payment_Gateway { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Set if the place checkout button should be renamed on selection. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $checkout_button_text; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Boolean whether the method is enabled. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - public $enabled = true; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Payment method id. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Payment method order. |
|
| 39 | - * |
|
| 40 | - * @var int |
|
| 41 | - */ |
|
| 42 | - public $order = 10; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Payment method title for the frontend. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $title; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Payment method description for the frontend. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $description; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gateway title. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $method_title = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gateway description. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $method_description = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Countries this gateway is allowed for. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - public $countries; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Currencies this gateway is allowed for. |
|
| 81 | - * |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 84 | - public $currencies; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Currencies this gateway is not allowed for. |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - public $exclude_currencies; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | - * |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - public $max_amount = 0; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Optional URL to view a transaction. |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $view_transaction_url = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Optional URL to view a subscription. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - public $view_subscription_url = ''; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Optional label to show for "new payment method" in the payment |
|
| 116 | - * method/token selection radio selection. |
|
| 117 | - * |
|
| 118 | - * @var string |
|
| 119 | - */ |
|
| 120 | - public $new_method_label = ''; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Contains a user's saved tokens for this gateway. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $tokens = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * An array of features that this gateway supports. |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - protected $supports = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Class constructor. |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - |
|
| 141 | - // Register gateway. |
|
| 142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | - |
|
| 144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | - |
|
| 146 | - // Add support for various features. |
|
| 147 | - foreach ( $this->supports as $feature ) { |
|
| 148 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Invoice addons. |
|
| 152 | - if ( $this->supports( 'addons' ) ) { |
|
| 153 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // Gateway settings. |
|
| 157 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 16 | + /** |
|
| 17 | + * Set if the place checkout button should be renamed on selection. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $checkout_button_text; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Boolean whether the method is enabled. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + public $enabled = true; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Payment method id. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Payment method order. |
|
| 39 | + * |
|
| 40 | + * @var int |
|
| 41 | + */ |
|
| 42 | + public $order = 10; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Payment method title for the frontend. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $title; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Payment method description for the frontend. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $description; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gateway title. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $method_title = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gateway description. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $method_description = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Countries this gateway is allowed for. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + public $countries; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Currencies this gateway is allowed for. |
|
| 81 | + * |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | + public $currencies; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Currencies this gateway is not allowed for. |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + public $exclude_currencies; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | + * |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + public $max_amount = 0; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Optional URL to view a transaction. |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $view_transaction_url = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Optional URL to view a subscription. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + public $view_subscription_url = ''; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Optional label to show for "new payment method" in the payment |
|
| 116 | + * method/token selection radio selection. |
|
| 117 | + * |
|
| 118 | + * @var string |
|
| 119 | + */ |
|
| 120 | + public $new_method_label = ''; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Contains a user's saved tokens for this gateway. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $tokens = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * An array of features that this gateway supports. |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + protected $supports = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Class constructor. |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + |
|
| 141 | + // Register gateway. |
|
| 142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | + |
|
| 144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | + |
|
| 146 | + // Add support for various features. |
|
| 147 | + foreach ( $this->supports as $feature ) { |
|
| 148 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Invoice addons. |
|
| 152 | + if ( $this->supports( 'addons' ) ) { |
|
| 153 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // Gateway settings. |
|
| 157 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - // Gateway checkout fiellds. |
|
| 161 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 162 | - |
|
| 163 | - // Process payment. |
|
| 164 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 160 | + // Gateway checkout fiellds. |
|
| 161 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 162 | + |
|
| 163 | + // Process payment. |
|
| 164 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 165 | + |
|
| 166 | + // Change the checkout button text. |
|
| 167 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 168 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // Check if a gateway is valid for a given currency. |
|
| 172 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 173 | + |
|
| 174 | + // Generate the transaction url. |
|
| 175 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 176 | + |
|
| 177 | + // Generate the subscription url. |
|
| 178 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 179 | + |
|
| 180 | + // Confirm payments. |
|
| 181 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 182 | + |
|
| 183 | + // Verify IPNs. |
|
| 184 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 185 | + |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Checks if this gateway is a given gateway. |
|
| 190 | + * |
|
| 191 | + * @since 1.0.19 |
|
| 192 | + * @return bool |
|
| 193 | + */ |
|
| 194 | + public function is( $gateway ) { |
|
| 195 | + return $gateway == $this->id; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Returns a users saved tokens for this gateway. |
|
| 200 | + * |
|
| 201 | + * @since 1.0.19 |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function get_tokens( $sandbox = null ) { |
|
| 205 | + |
|
| 206 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 207 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 208 | + |
|
| 209 | + if ( is_array( $tokens ) ) { |
|
| 210 | + $this->tokens = $tokens; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if ( ! is_bool( $sandbox ) ) { |
|
| 216 | + return $this->tokens; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 220 | + return wp_list_filter( $this->tokens, $args ); |
|
| 221 | + |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Saves a token for this gateway. |
|
| 226 | + * |
|
| 227 | + * @since 1.0.19 |
|
| 228 | + */ |
|
| 229 | + public function save_token( $token ) { |
|
| 230 | + |
|
| 231 | + $tokens = $this->get_tokens(); |
|
| 232 | + $tokens[] = $token; |
|
| 233 | + |
|
| 234 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 235 | + |
|
| 236 | + $this->tokens = $tokens; |
|
| 237 | + |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Return the title for admin screens. |
|
| 242 | + * |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function get_method_title() { |
|
| 246 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Return the description for admin screens. |
|
| 251 | + * |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 254 | + public function get_method_description() { |
|
| 255 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Get the success url. |
|
| 260 | + * |
|
| 261 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function get_return_url( $invoice ) { |
|
| 265 | + |
|
| 266 | + // Payment success url |
|
| 267 | + $return_url = add_query_arg( |
|
| 268 | + array( |
|
| 269 | + 'payment-confirm' => $this->id, |
|
| 270 | + 'invoice_key' => $invoice->get_key(), |
|
| 271 | + 'utm_nooverride' => 1 |
|
| 272 | + ), |
|
| 273 | + wpinv_get_success_page_uri() |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Confirms payments when rendering the success page. |
|
| 281 | + * |
|
| 282 | + * @param string $content Success page content. |
|
| 283 | + * @return string |
|
| 284 | + */ |
|
| 285 | + public function confirm_payment( $content ) { |
|
| 286 | + |
|
| 287 | + // Retrieve the invoice. |
|
| 288 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 289 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 290 | + |
|
| 291 | + // Ensure that it exists and that it is pending payment. |
|
| 292 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 293 | + return $content; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + // Can the user view this invoice?? |
|
| 297 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 298 | + return $content; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + // Show payment processing indicator. |
|
| 302 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Processes ipns and marks payments as complete. |
|
| 307 | + * |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + public function verify_ipn() {} |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Processes invoice addons. |
|
| 314 | + * |
|
| 315 | + * @param WPInv_Invoice $invoice |
|
| 316 | + * @param GetPaid_Form_Item[] $items |
|
| 317 | + * @return WPInv_Invoice |
|
| 318 | + */ |
|
| 319 | + public function process_addons( $invoice, $items ) { |
|
| 320 | + |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 325 | + * |
|
| 326 | + * @param string $transaction_url transaction url. |
|
| 327 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 328 | + * @return string transaction URL, or empty string. |
|
| 329 | + */ |
|
| 330 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 331 | + |
|
| 332 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 333 | + |
|
| 334 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 335 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 336 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 337 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + return $transaction_url; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 345 | + * |
|
| 346 | + * @param string $subscription_url transaction url. |
|
| 347 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 348 | + * @return string subscription URL, or empty string. |
|
| 349 | + */ |
|
| 350 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 351 | + |
|
| 352 | + $profile_id = $subscription->get_profile_id(); |
|
| 165 | 353 | |
| 166 | - // Change the checkout button text. |
|
| 167 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 168 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // Check if a gateway is valid for a given currency. |
|
| 172 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 173 | - |
|
| 174 | - // Generate the transaction url. |
|
| 175 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 176 | - |
|
| 177 | - // Generate the subscription url. |
|
| 178 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 179 | - |
|
| 180 | - // Confirm payments. |
|
| 181 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 182 | - |
|
| 183 | - // Verify IPNs. |
|
| 184 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 185 | - |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Checks if this gateway is a given gateway. |
|
| 190 | - * |
|
| 191 | - * @since 1.0.19 |
|
| 192 | - * @return bool |
|
| 193 | - */ |
|
| 194 | - public function is( $gateway ) { |
|
| 195 | - return $gateway == $this->id; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Returns a users saved tokens for this gateway. |
|
| 200 | - * |
|
| 201 | - * @since 1.0.19 |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function get_tokens( $sandbox = null ) { |
|
| 205 | - |
|
| 206 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 207 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 208 | - |
|
| 209 | - if ( is_array( $tokens ) ) { |
|
| 210 | - $this->tokens = $tokens; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if ( ! is_bool( $sandbox ) ) { |
|
| 216 | - return $this->tokens; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 220 | - return wp_list_filter( $this->tokens, $args ); |
|
| 221 | - |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Saves a token for this gateway. |
|
| 226 | - * |
|
| 227 | - * @since 1.0.19 |
|
| 228 | - */ |
|
| 229 | - public function save_token( $token ) { |
|
| 230 | - |
|
| 231 | - $tokens = $this->get_tokens(); |
|
| 232 | - $tokens[] = $token; |
|
| 233 | - |
|
| 234 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 235 | - |
|
| 236 | - $this->tokens = $tokens; |
|
| 237 | - |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Return the title for admin screens. |
|
| 242 | - * |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function get_method_title() { |
|
| 246 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Return the description for admin screens. |
|
| 251 | - * |
|
| 252 | - * @return string |
|
| 253 | - */ |
|
| 254 | - public function get_method_description() { |
|
| 255 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Get the success url. |
|
| 260 | - * |
|
| 261 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function get_return_url( $invoice ) { |
|
| 265 | - |
|
| 266 | - // Payment success url |
|
| 267 | - $return_url = add_query_arg( |
|
| 268 | - array( |
|
| 269 | - 'payment-confirm' => $this->id, |
|
| 270 | - 'invoice_key' => $invoice->get_key(), |
|
| 271 | - 'utm_nooverride' => 1 |
|
| 272 | - ), |
|
| 273 | - wpinv_get_success_page_uri() |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Confirms payments when rendering the success page. |
|
| 281 | - * |
|
| 282 | - * @param string $content Success page content. |
|
| 283 | - * @return string |
|
| 284 | - */ |
|
| 285 | - public function confirm_payment( $content ) { |
|
| 286 | - |
|
| 287 | - // Retrieve the invoice. |
|
| 288 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 289 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 290 | - |
|
| 291 | - // Ensure that it exists and that it is pending payment. |
|
| 292 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 293 | - return $content; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - // Can the user view this invoice?? |
|
| 297 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 298 | - return $content; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - // Show payment processing indicator. |
|
| 302 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Processes ipns and marks payments as complete. |
|
| 307 | - * |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - public function verify_ipn() {} |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Processes invoice addons. |
|
| 314 | - * |
|
| 315 | - * @param WPInv_Invoice $invoice |
|
| 316 | - * @param GetPaid_Form_Item[] $items |
|
| 317 | - * @return WPInv_Invoice |
|
| 318 | - */ |
|
| 319 | - public function process_addons( $invoice, $items ) { |
|
| 320 | - |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 325 | - * |
|
| 326 | - * @param string $transaction_url transaction url. |
|
| 327 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 328 | - * @return string transaction URL, or empty string. |
|
| 329 | - */ |
|
| 330 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 331 | - |
|
| 332 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 333 | - |
|
| 334 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 335 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 336 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 337 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - return $transaction_url; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 345 | - * |
|
| 346 | - * @param string $subscription_url transaction url. |
|
| 347 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 348 | - * @return string subscription URL, or empty string. |
|
| 349 | - */ |
|
| 350 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 351 | - |
|
| 352 | - $profile_id = $subscription->get_profile_id(); |
|
| 353 | - |
|
| 354 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 355 | - |
|
| 356 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 357 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 358 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 359 | - |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $subscription_url; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Check if the gateway is available for use. |
|
| 367 | - * |
|
| 368 | - * @return bool |
|
| 369 | - */ |
|
| 370 | - public function is_available() { |
|
| 371 | - return ! empty( $this->enabled ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Return the gateway's title. |
|
| 376 | - * |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_title() { |
|
| 380 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Return the gateway's description. |
|
| 385 | - * |
|
| 386 | - * @return string |
|
| 387 | - */ |
|
| 388 | - public function get_description() { |
|
| 389 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Process Payment. |
|
| 394 | - * |
|
| 395 | - * |
|
| 396 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 397 | - * @param array $submission_data Posted checkout fields. |
|
| 398 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 399 | - * @return void |
|
| 400 | - */ |
|
| 401 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 402 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 403 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Process refund. |
|
| 408 | - * |
|
| 409 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 410 | - * a passed in amount. |
|
| 411 | - * |
|
| 412 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 413 | - * @param float $amount Refund amount. |
|
| 414 | - * @param string $reason Refund reason. |
|
| 415 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 416 | - */ |
|
| 417 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 418 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Displays the payment fields, credit cards etc. |
|
| 423 | - * |
|
| 424 | - * @param int $invoice_id 0 or invoice id. |
|
| 425 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 426 | - */ |
|
| 427 | - public function payment_fields( $invoice_id, $form ) { |
|
| 428 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Filters the gateway settings. |
|
| 433 | - * |
|
| 434 | - * @param array $admin_settings |
|
| 435 | - */ |
|
| 436 | - public function admin_settings( $admin_settings ) { |
|
| 437 | - return $admin_settings; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Retrieves the value of a gateway setting. |
|
| 442 | - * |
|
| 443 | - * @param string $option |
|
| 444 | - */ |
|
| 445 | - public function get_option( $option, $default = false ) { |
|
| 446 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Check if a gateway supports a given feature. |
|
| 451 | - * |
|
| 452 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 453 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 454 | - * |
|
| 455 | - * @param string $feature string The name of a feature to test support for. |
|
| 456 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 457 | - * @since 1.0.19 |
|
| 458 | - */ |
|
| 459 | - public function supports( $feature ) { |
|
| 460 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Returns the credit card form html. |
|
| 465 | - * |
|
| 466 | - * @param bool $save whether or not to display the save button. |
|
| 467 | - */ |
|
| 354 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 355 | + |
|
| 356 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 357 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 358 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 359 | + |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $subscription_url; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Check if the gateway is available for use. |
|
| 367 | + * |
|
| 368 | + * @return bool |
|
| 369 | + */ |
|
| 370 | + public function is_available() { |
|
| 371 | + return ! empty( $this->enabled ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Return the gateway's title. |
|
| 376 | + * |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_title() { |
|
| 380 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Return the gateway's description. |
|
| 385 | + * |
|
| 386 | + * @return string |
|
| 387 | + */ |
|
| 388 | + public function get_description() { |
|
| 389 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Process Payment. |
|
| 394 | + * |
|
| 395 | + * |
|
| 396 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 397 | + * @param array $submission_data Posted checkout fields. |
|
| 398 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 399 | + * @return void |
|
| 400 | + */ |
|
| 401 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 402 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 403 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Process refund. |
|
| 408 | + * |
|
| 409 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 410 | + * a passed in amount. |
|
| 411 | + * |
|
| 412 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 413 | + * @param float $amount Refund amount. |
|
| 414 | + * @param string $reason Refund reason. |
|
| 415 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 416 | + */ |
|
| 417 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 418 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Displays the payment fields, credit cards etc. |
|
| 423 | + * |
|
| 424 | + * @param int $invoice_id 0 or invoice id. |
|
| 425 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 426 | + */ |
|
| 427 | + public function payment_fields( $invoice_id, $form ) { |
|
| 428 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Filters the gateway settings. |
|
| 433 | + * |
|
| 434 | + * @param array $admin_settings |
|
| 435 | + */ |
|
| 436 | + public function admin_settings( $admin_settings ) { |
|
| 437 | + return $admin_settings; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Retrieves the value of a gateway setting. |
|
| 442 | + * |
|
| 443 | + * @param string $option |
|
| 444 | + */ |
|
| 445 | + public function get_option( $option, $default = false ) { |
|
| 446 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Check if a gateway supports a given feature. |
|
| 451 | + * |
|
| 452 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 453 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 454 | + * |
|
| 455 | + * @param string $feature string The name of a feature to test support for. |
|
| 456 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 457 | + * @since 1.0.19 |
|
| 458 | + */ |
|
| 459 | + public function supports( $feature ) { |
|
| 460 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Returns the credit card form html. |
|
| 465 | + * |
|
| 466 | + * @param bool $save whether or not to display the save button. |
|
| 467 | + */ |
|
| 468 | 468 | public function get_cc_form( $save = false ) { |
| 469 | 469 | |
| 470 | - ob_start(); |
|
| 470 | + ob_start(); |
|
| 471 | 471 | |
| 472 | 472 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 473 | 473 | |
@@ -562,11 +562,11 @@ discard block |
||
| 562 | 562 | 'name' => $this->id . '[cc_cvv2]', |
| 563 | 563 | 'id' => "$id_prefix-cc-cvv2", |
| 564 | 564 | 'label' => __( 'CCV', 'invoicing' ), |
| 565 | - 'label_type' => 'vertical', |
|
| 566 | - 'class' => 'form-control-sm', |
|
| 567 | - 'extra_attributes' => array( |
|
| 568 | - 'autocomplete' => "cc-csc", |
|
| 569 | - ), |
|
| 565 | + 'label_type' => 'vertical', |
|
| 566 | + 'class' => 'form-control-sm', |
|
| 567 | + 'extra_attributes' => array( |
|
| 568 | + 'autocomplete' => "cc-csc", |
|
| 569 | + ), |
|
| 570 | 570 | ) |
| 571 | 571 | ); |
| 572 | 572 | ?> |
@@ -576,191 +576,191 @@ discard block |
||
| 576 | 576 | |
| 577 | 577 | <?php |
| 578 | 578 | |
| 579 | - if ( $save ) { |
|
| 580 | - echo $this->save_payment_method_checkbox(); |
|
| 581 | - } |
|
| 579 | + if ( $save ) { |
|
| 580 | + echo $this->save_payment_method_checkbox(); |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - ?> |
|
| 583 | + ?> |
|
| 584 | 584 | </div> |
| 585 | 585 | |
| 586 | 586 | </div> |
| 587 | 587 | <?php |
| 588 | 588 | |
| 589 | - return ob_get_clean(); |
|
| 589 | + return ob_get_clean(); |
|
| 590 | + |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Displays a new payment method entry form. |
|
| 595 | + * |
|
| 596 | + * @since 1.0.19 |
|
| 597 | + */ |
|
| 598 | + public function new_payment_method_entry( $form ) { |
|
| 599 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Grab and display our saved payment methods. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + */ |
|
| 607 | + public function saved_payment_methods() { |
|
| 608 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 609 | + |
|
| 610 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 611 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 612 | + } |
|
| 590 | 613 | |
| 614 | + $html .= $this->get_new_payment_method_option_html(); |
|
| 615 | + $html .= '</ul>'; |
|
| 616 | + |
|
| 617 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 591 | 618 | } |
| 592 | 619 | |
| 593 | - /** |
|
| 594 | - * Displays a new payment method entry form. |
|
| 595 | - * |
|
| 596 | - * @since 1.0.19 |
|
| 597 | - */ |
|
| 598 | - public function new_payment_method_entry( $form ) { |
|
| 599 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Grab and display our saved payment methods. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - */ |
|
| 607 | - public function saved_payment_methods() { |
|
| 608 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 609 | - |
|
| 610 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 611 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - $html .= $this->get_new_payment_method_option_html(); |
|
| 615 | - $html .= '</ul>'; |
|
| 616 | - |
|
| 617 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Gets saved payment method HTML from a token. |
|
| 622 | - * |
|
| 623 | - * @since 1.0.19 |
|
| 624 | - * @param array $token Payment Token. |
|
| 625 | - * @return string Generated payment method HTML |
|
| 626 | - */ |
|
| 627 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 628 | - |
|
| 629 | - return sprintf( |
|
| 630 | - '<li class="getpaid-payment-method form-group"> |
|
| 620 | + /** |
|
| 621 | + * Gets saved payment method HTML from a token. |
|
| 622 | + * |
|
| 623 | + * @since 1.0.19 |
|
| 624 | + * @param array $token Payment Token. |
|
| 625 | + * @return string Generated payment method HTML |
|
| 626 | + */ |
|
| 627 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 628 | + |
|
| 629 | + return sprintf( |
|
| 630 | + '<li class="getpaid-payment-method form-group"> |
|
| 631 | 631 | <label> |
| 632 | 632 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 633 | 633 | <span>%3$s</span> |
| 634 | 634 | </label> |
| 635 | 635 | </li>', |
| 636 | - esc_attr( $this->id ), |
|
| 637 | - esc_attr( $token['id'] ), |
|
| 638 | - esc_html( $token['name'] ), |
|
| 639 | - checked( empty( $token['default'] ), false, false ) |
|
| 640 | - ); |
|
| 636 | + esc_attr( $this->id ), |
|
| 637 | + esc_attr( $token['id'] ), |
|
| 638 | + esc_html( $token['name'] ), |
|
| 639 | + checked( empty( $token['default'] ), false, false ) |
|
| 640 | + ); |
|
| 641 | 641 | |
| 642 | - } |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | - /** |
|
| 645 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 646 | - * |
|
| 647 | - * @since 1.0.19 |
|
| 648 | - */ |
|
| 649 | - public function get_new_payment_method_option_html() { |
|
| 644 | + /** |
|
| 645 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 646 | + * |
|
| 647 | + * @since 1.0.19 |
|
| 648 | + */ |
|
| 649 | + public function get_new_payment_method_option_html() { |
|
| 650 | 650 | |
| 651 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 651 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 652 | 652 | |
| 653 | - return sprintf( |
|
| 654 | - '<li class="getpaid-new-payment-method"> |
|
| 653 | + return sprintf( |
|
| 654 | + '<li class="getpaid-new-payment-method"> |
|
| 655 | 655 | <label> |
| 656 | 656 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
| 657 | 657 | <span>%2$s</span> |
| 658 | 658 | </label> |
| 659 | 659 | </li>', |
| 660 | - esc_attr( $this->id ), |
|
| 661 | - esc_html( $label ) |
|
| 662 | - ); |
|
| 663 | - |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 668 | - * |
|
| 669 | - * @since 1.0.19 |
|
| 670 | - */ |
|
| 671 | - public function save_payment_method_checkbox() { |
|
| 672 | - |
|
| 673 | - return aui()->input( |
|
| 674 | - array( |
|
| 675 | - 'type' => 'checkbox', |
|
| 676 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 677 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 678 | - 'required' => false, |
|
| 679 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 680 | - 'value' => 'true', |
|
| 681 | - 'checked' => true, |
|
| 682 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Registers the gateway. |
|
| 690 | - * |
|
| 691 | - * @return array |
|
| 692 | - */ |
|
| 693 | - public function register_gateway( $gateways ) { |
|
| 694 | - |
|
| 695 | - $gateways[ $this->id ] = array( |
|
| 696 | - |
|
| 697 | - 'admin_label' => $this->method_title, |
|
| 660 | + esc_attr( $this->id ), |
|
| 661 | + esc_html( $label ) |
|
| 662 | + ); |
|
| 663 | + |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 668 | + * |
|
| 669 | + * @since 1.0.19 |
|
| 670 | + */ |
|
| 671 | + public function save_payment_method_checkbox() { |
|
| 672 | + |
|
| 673 | + return aui()->input( |
|
| 674 | + array( |
|
| 675 | + 'type' => 'checkbox', |
|
| 676 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 677 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 678 | + 'required' => false, |
|
| 679 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 680 | + 'value' => 'true', |
|
| 681 | + 'checked' => true, |
|
| 682 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Registers the gateway. |
|
| 690 | + * |
|
| 691 | + * @return array |
|
| 692 | + */ |
|
| 693 | + public function register_gateway( $gateways ) { |
|
| 694 | + |
|
| 695 | + $gateways[ $this->id ] = array( |
|
| 696 | + |
|
| 697 | + 'admin_label' => $this->method_title, |
|
| 698 | 698 | 'checkout_label' => $this->title, |
| 699 | - 'ordering' => $this->order, |
|
| 699 | + 'ordering' => $this->order, |
|
| 700 | 700 | |
| 701 | - ); |
|
| 701 | + ); |
|
| 702 | 702 | |
| 703 | - return $gateways; |
|
| 703 | + return $gateways; |
|
| 704 | 704 | |
| 705 | - } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - /** |
|
| 708 | - * Checks whether or not this is a sandbox request. |
|
| 709 | - * |
|
| 710 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 711 | - * @return bool |
|
| 712 | - */ |
|
| 713 | - public function is_sandbox( $invoice = null ) { |
|
| 707 | + /** |
|
| 708 | + * Checks whether or not this is a sandbox request. |
|
| 709 | + * |
|
| 710 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 711 | + * @return bool |
|
| 712 | + */ |
|
| 713 | + public function is_sandbox( $invoice = null ) { |
|
| 714 | 714 | |
| 715 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 716 | - return $invoice->get_mode() == 'test'; |
|
| 717 | - } |
|
| 715 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 716 | + return $invoice->get_mode() == 'test'; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - return wpinv_is_test_mode( $this->id ); |
|
| 719 | + return wpinv_is_test_mode( $this->id ); |
|
| 720 | 720 | |
| 721 | - } |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | - /** |
|
| 724 | - * Renames the checkout button |
|
| 725 | - * |
|
| 726 | - * @return string |
|
| 727 | - */ |
|
| 728 | - public function rename_checkout_button() { |
|
| 729 | - return $this->checkout_button_text; |
|
| 730 | - } |
|
| 723 | + /** |
|
| 724 | + * Renames the checkout button |
|
| 725 | + * |
|
| 726 | + * @return string |
|
| 727 | + */ |
|
| 728 | + public function rename_checkout_button() { |
|
| 729 | + return $this->checkout_button_text; |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * Validate gateway currency |
|
| 734 | - * |
|
| 735 | - * @return bool |
|
| 736 | - */ |
|
| 737 | - public function validate_currency( $validation, $currency ) { |
|
| 732 | + /** |
|
| 733 | + * Validate gateway currency |
|
| 734 | + * |
|
| 735 | + * @return bool |
|
| 736 | + */ |
|
| 737 | + public function validate_currency( $validation, $currency ) { |
|
| 738 | 738 | |
| 739 | - // Required currencies. |
|
| 740 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 741 | - return false; |
|
| 742 | - } |
|
| 739 | + // Required currencies. |
|
| 740 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 741 | + return false; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - // Excluded currencies. |
|
| 745 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 746 | - return false; |
|
| 747 | - } |
|
| 744 | + // Excluded currencies. |
|
| 745 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 746 | + return false; |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - return $validation; |
|
| 750 | - } |
|
| 749 | + return $validation; |
|
| 750 | + } |
|
| 751 | 751 | |
| 752 | - /** |
|
| 753 | - * Displays an error |
|
| 754 | - * |
|
| 755 | - */ |
|
| 756 | - public function show_error( $code, $message, $type ) { |
|
| 752 | + /** |
|
| 753 | + * Displays an error |
|
| 754 | + * |
|
| 755 | + */ |
|
| 756 | + public function show_error( $code, $message, $type ) { |
|
| 757 | 757 | |
| 758 | - if ( is_admin() ) { |
|
| 759 | - getpaid_admin()->{"show_$type"}( $message ); |
|
| 760 | - } |
|
| 758 | + if ( is_admin() ) { |
|
| 759 | + getpaid_admin()->{"show_$type"}( $message ); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - wpinv_set_error( $code, $message, $type ); |
|
| 762 | + wpinv_set_error( $code, $message, $type ); |
|
| 763 | 763 | |
| 764 | - } |
|
| 764 | + } |
|
| 765 | 765 | |
| 766 | 766 | } |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | class WPInv_Subscriptions { |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * Class constructor. |
|
| 16 | - */ |
|
| 15 | + * Class constructor. |
|
| 16 | + */ |
|
| 17 | 17 | public function __construct(){ |
| 18 | 18 | |
| 19 | 19 | // Fire gateway specific hooks when a subscription changes. |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Processes subscription status changes. |
|
| 92 | + * Processes subscription status changes. |
|
| 93 | 93 | * |
| 94 | 94 | * @param WPInv_Subscription $subscription |
| 95 | 95 | * @param string $from |
| 96 | 96 | * @param string $to |
| 97 | - */ |
|
| 97 | + */ |
|
| 98 | 98 | public function process_subscription_status_change( $subscription, $from, $to ) { |
| 99 | 99 | |
| 100 | 100 | $gateway = $subscription->get_gateway(); |
@@ -15,125 +15,125 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $data_store_name = 'subscription'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'subscription'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'customer_id' => 0, |
|
| 40 | - 'frequency' => 1, |
|
| 41 | - 'period' => 'D', |
|
| 42 | - 'initial_amount' => null, |
|
| 43 | - 'recurring_amount' => null, |
|
| 44 | - 'bill_times' => 0, |
|
| 45 | - 'transaction_id' => '', |
|
| 46 | - 'parent_payment_id' => null, |
|
| 47 | - 'product_id' => 0, |
|
| 48 | - 'created' => '0000-00-00 00:00:00', |
|
| 49 | - 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | - 'trial_period' => '', |
|
| 51 | - 'status' => 'pending', |
|
| 52 | - 'profile_id' => '', |
|
| 53 | - 'gateway' => '', |
|
| 54 | - 'customer' => '', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Stores the status transition information. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - protected $status_transition = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | - * |
|
| 68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | - * @param bool $deprecated |
|
| 70 | - */ |
|
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | - |
|
| 73 | - parent::__construct( $subscription ); |
|
| 74 | - |
|
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 83 | - } else { |
|
| 84 | - $this->set_object_read( true ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Load the datastore. |
|
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | - |
|
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @static |
|
| 101 | - * @param string $value |
|
| 102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | - * @since 1.0.19 |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $data_store_name = 'subscription'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'subscription'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'customer_id' => 0, |
|
| 40 | + 'frequency' => 1, |
|
| 41 | + 'period' => 'D', |
|
| 42 | + 'initial_amount' => null, |
|
| 43 | + 'recurring_amount' => null, |
|
| 44 | + 'bill_times' => 0, |
|
| 45 | + 'transaction_id' => '', |
|
| 46 | + 'parent_payment_id' => null, |
|
| 47 | + 'product_id' => 0, |
|
| 48 | + 'created' => '0000-00-00 00:00:00', |
|
| 49 | + 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | + 'trial_period' => '', |
|
| 51 | + 'status' => 'pending', |
|
| 52 | + 'profile_id' => '', |
|
| 53 | + 'gateway' => '', |
|
| 54 | + 'customer' => '', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Stores the status transition information. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + protected $status_transition = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | + * |
|
| 68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | + * @param bool $deprecated |
|
| 70 | + */ |
|
| 71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | + |
|
| 73 | + parent::__construct( $subscription ); |
|
| 74 | + |
|
| 75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | + $this->set_id( $subscription ); |
|
| 77 | + } elseif ( $subscription instanceof self ) { |
|
| 78 | + $this->set_id( $subscription->get_id() ); |
|
| 79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | + $this->set_id( $subscription_id ); |
|
| 81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | + $this->set_id( $subscription->id ); |
|
| 83 | + } else { |
|
| 84 | + $this->set_object_read( true ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Load the datastore. |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | + |
|
| 90 | + if ( $this->get_id() > 0 ) { |
|
| 91 | + $this->data_store->read( $this ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @static |
|
| 101 | + * @param string $value |
|
| 102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | + * @since 1.0.19 |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - // Trim the value. |
|
| 110 | - $value = trim( $value ); |
|
| 109 | + // Trim the value. |
|
| 110 | + $value = trim( $value ); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 113 | - return 0; |
|
| 114 | - } |
|
| 112 | + if ( empty( $value ) ) { |
|
| 113 | + return 0; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 117 | - $field = 'parent_payment_id'; |
|
| 118 | - } |
|
| 116 | + if ( 'invoice_id' == $field ) { |
|
| 117 | + $field = 'parent_payment_id'; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | // Valid fields. |
| 121 | 121 | $fields = array( |
| 122 | - 'parent_payment_id', |
|
| 123 | - 'transaction_id', |
|
| 124 | - 'profile_id' |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Ensure a field has been passed. |
|
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Maybe retrieve from the cache. |
|
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 135 | - return $subscription_id; |
|
| 136 | - } |
|
| 122 | + 'parent_payment_id', |
|
| 123 | + 'transaction_id', |
|
| 124 | + 'profile_id' |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Ensure a field has been passed. |
|
| 128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Maybe retrieve from the cache. |
|
| 133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | + if ( ! empty( $subscription_id ) ) { |
|
| 135 | + return $subscription_id; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
| 141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 145 | - return 0; |
|
| 146 | - } |
|
| 144 | + if ( empty( $subscription_id ) ) { |
|
| 145 | + return 0; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - // Update the cache with our data. |
|
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 148 | + // Update the cache with our data. |
|
| 149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 150 | 150 | |
| 151 | - return $subscription_id; |
|
| 152 | - } |
|
| 151 | + return $subscription_id; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | + /** |
|
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | - } |
|
| 158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | + /** |
|
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | 167 | public function _isset( $key ) { |
| 168 | 168 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /* |
|
| 171 | + /* |
|
| 172 | 172 | |-------------------------------------------------------------------------- |
| 173 | 173 | | CRUD methods |
| 174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,545 +177,545 @@ discard block |
||
| 177 | 177 | | |
| 178 | 178 | */ |
| 179 | 179 | |
| 180 | - /* |
|
| 180 | + /* |
|
| 181 | 181 | |-------------------------------------------------------------------------- |
| 182 | 182 | | Getters |
| 183 | 183 | |-------------------------------------------------------------------------- |
| 184 | 184 | */ |
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Get customer id. |
|
| 188 | - * |
|
| 189 | - * @since 1.0.19 |
|
| 190 | - * @param string $context View or edit context. |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Get customer information. |
|
| 199 | - * |
|
| 200 | - * @since 1.0.19 |
|
| 201 | - * @param string $context View or edit context. |
|
| 202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | - */ |
|
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get parent invoice id. |
|
| 210 | - * |
|
| 211 | - * @since 1.0.19 |
|
| 212 | - * @param string $context View or edit context. |
|
| 213 | - * @return int |
|
| 214 | - */ |
|
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Alias for self::get_parent_invoice_id(). |
|
| 221 | - * |
|
| 222 | - * @since 1.0.19 |
|
| 223 | - * @param string $context View or edit context. |
|
| 224 | - * @return int |
|
| 225 | - */ |
|
| 226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | - return $this->get_parent_invoice_id( $context ); |
|
| 228 | - } |
|
| 186 | + /** |
|
| 187 | + * Get customer id. |
|
| 188 | + * |
|
| 189 | + * @since 1.0.19 |
|
| 190 | + * @param string $context View or edit context. |
|
| 191 | + * @return int |
|
| 192 | + */ |
|
| 193 | + public function get_customer_id( $context = 'view' ) { |
|
| 194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Get customer information. |
|
| 199 | + * |
|
| 200 | + * @since 1.0.19 |
|
| 201 | + * @param string $context View or edit context. |
|
| 202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | + */ |
|
| 204 | + public function get_customer( $context = 'view' ) { |
|
| 205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get parent invoice id. |
|
| 210 | + * |
|
| 211 | + * @since 1.0.19 |
|
| 212 | + * @param string $context View or edit context. |
|
| 213 | + * @return int |
|
| 214 | + */ |
|
| 215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Alias for self::get_parent_invoice_id(). |
|
| 221 | + * |
|
| 222 | + * @since 1.0.19 |
|
| 223 | + * @param string $context View or edit context. |
|
| 224 | + * @return int |
|
| 225 | + */ |
|
| 226 | + public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | + return $this->get_parent_invoice_id( $context ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Alias for self::get_parent_invoice_id(). |
|
| 232 | + * |
|
| 233 | + * @since 1.0.0 |
|
| 234 | + * @return int |
|
| 235 | + */ |
|
| 236 | + public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | + return $this->get_parent_invoice_id( $context ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Get parent invoice. |
|
| 242 | + * |
|
| 243 | + * @since 1.0.19 |
|
| 244 | + * @param string $context View or edit context. |
|
| 245 | + * @return WPInv_Invoice |
|
| 246 | + */ |
|
| 247 | + public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Alias for self::get_parent_invoice(). |
|
| 253 | + * |
|
| 254 | + * @since 1.0.19 |
|
| 255 | + * @param string $context View or edit context. |
|
| 256 | + * @return WPInv_Invoice |
|
| 257 | + */ |
|
| 258 | + public function get_parent_payment( $context = 'view' ) { |
|
| 259 | + return $this->get_parent_invoice( $context ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Get subscription's product id. |
|
| 264 | + * |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @param string $context View or edit context. |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function get_product_id( $context = 'view' ) { |
|
| 270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Get the subscription product. |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @param string $context View or edit context. |
|
| 278 | + * @return WPInv_Item |
|
| 279 | + */ |
|
| 280 | + public function get_product( $context = 'view' ) { |
|
| 281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Get parent invoice's gateway. |
|
| 286 | + * |
|
| 287 | + * Here for backwards compatibility. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @param string $context View or edit context. |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function get_gateway( $context = 'view' ) { |
|
| 294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Get the period of a renewal. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @param string $context View or edit context. |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function get_period( $context = 'view' ) { |
|
| 305 | + return $this->get_prop( 'period', $context ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Get number of periods each renewal is valid for. |
|
| 310 | + * |
|
| 311 | + * @since 1.0.19 |
|
| 312 | + * @param string $context View or edit context. |
|
| 313 | + * @return int |
|
| 314 | + */ |
|
| 315 | + public function get_frequency( $context = 'view' ) { |
|
| 316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the initial amount for the subscription. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @param string $context View or edit context. |
|
| 324 | + * @return float |
|
| 325 | + */ |
|
| 326 | + public function get_initial_amount( $context = 'view' ) { |
|
| 327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get the recurring amount for the subscription. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return float |
|
| 336 | + */ |
|
| 337 | + public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Get number of times that this subscription can be renewed. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + * @param string $context View or edit context. |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function get_bill_times( $context = 'view' ) { |
|
| 349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Get transaction id of this subscription's parent invoice. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param string $context View or edit context. |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + public function get_transaction_id( $context = 'view' ) { |
|
| 360 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Get the date that the subscription was created. |
|
| 365 | + * |
|
| 366 | + * @since 1.0.19 |
|
| 367 | + * @param string $context View or edit context. |
|
| 368 | + * @return string |
|
| 369 | + */ |
|
| 370 | + public function get_created( $context = 'view' ) { |
|
| 371 | + return $this->get_prop( 'created', $context ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Alias for self::get_created(). |
|
| 376 | + * |
|
| 377 | + * @since 1.0.19 |
|
| 378 | + * @param string $context View or edit context. |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function get_date_created( $context = 'view' ) { |
|
| 382 | + return $this->get_created( $context ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Retrieves the creation date in a timestamp |
|
| 387 | + * |
|
| 388 | + * @since 1.0.0 |
|
| 389 | + * @return int |
|
| 390 | + */ |
|
| 391 | + public function get_time_created() { |
|
| 392 | + $created = $this->get_date_created(); |
|
| 393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get GMT date when the subscription was created. |
|
| 398 | + * |
|
| 399 | + * @since 1.0.19 |
|
| 400 | + * @param string $context View or edit context. |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | + $date = $this->get_date_created( $context ); |
|
| 405 | + |
|
| 406 | + if ( $date ) { |
|
| 407 | + $date = get_gmt_from_date( $date ); |
|
| 408 | + } |
|
| 409 | + return $date; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get the date that the subscription will renew. |
|
| 414 | + * |
|
| 415 | + * @since 1.0.19 |
|
| 416 | + * @param string $context View or edit context. |
|
| 417 | + * @return string |
|
| 418 | + */ |
|
| 419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | + return $this->get_prop( 'expiration', $context ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Alias for self::get_next_renewal_date(). |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + * @param string $context View or edit context. |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function get_expiration( $context = 'view' ) { |
|
| 431 | + return $this->get_next_renewal_date( $context ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Retrieves the expiration date in a timestamp |
|
| 436 | + * |
|
| 437 | + * @since 1.0.0 |
|
| 438 | + * @return int |
|
| 439 | + */ |
|
| 440 | + public function get_expiration_time() { |
|
| 441 | + $expiration = $this->get_expiration(); |
|
| 442 | + |
|
| 443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | + return current_time( 'timestamp' ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Get GMT date when the subscription will renew. |
|
| 453 | + * |
|
| 454 | + * @since 1.0.19 |
|
| 455 | + * @param string $context View or edit context. |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | + $date = $this->get_next_renewal_date( $context ); |
|
| 460 | + |
|
| 461 | + if ( $date ) { |
|
| 462 | + $date = get_gmt_from_date( $date ); |
|
| 463 | + } |
|
| 464 | + return $date; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Get the subscription's trial period. |
|
| 469 | + * |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + * @param string $context View or edit context. |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function get_trial_period( $context = 'view' ) { |
|
| 475 | + return $this->get_prop( 'trial_period', $context ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Get the subscription's status. |
|
| 480 | + * |
|
| 481 | + * @since 1.0.19 |
|
| 482 | + * @param string $context View or edit context. |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + public function get_status( $context = 'view' ) { |
|
| 486 | + return $this->get_prop( 'status', $context ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Get the subscription's profile id. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $context View or edit context. |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + public function get_profile_id( $context = 'view' ) { |
|
| 497 | + return $this->get_prop( 'profile_id', $context ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /* |
|
| 501 | + |-------------------------------------------------------------------------- |
|
| 502 | + | Setters |
|
| 503 | + |-------------------------------------------------------------------------- |
|
| 504 | + */ |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Set customer id. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param int $value The customer's id. |
|
| 511 | + */ |
|
| 512 | + public function set_customer_id( $value ) { |
|
| 513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Set parent invoice id. |
|
| 518 | + * |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + * @param int $value The parent invoice id. |
|
| 521 | + */ |
|
| 522 | + public function set_parent_invoice_id( $value ) { |
|
| 523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Alias for self::set_parent_invoice_id(). |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + * @param int $value The parent invoice id. |
|
| 531 | + */ |
|
| 532 | + public function set_parent_payment_id( $value ) { |
|
| 533 | + $this->set_parent_invoice_id( $value ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Alias for self::set_parent_invoice_id(). |
|
| 538 | + * |
|
| 539 | + * @since 1.0.19 |
|
| 540 | + * @param int $value The parent invoice id. |
|
| 541 | + */ |
|
| 542 | + public function set_original_payment_id( $value ) { |
|
| 543 | + $this->set_parent_invoice_id( $value ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Set subscription's product id. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param int $value The subscription product id. |
|
| 551 | + */ |
|
| 552 | + public function set_product_id( $value ) { |
|
| 553 | + $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Set the period of a renewal. |
|
| 558 | + * |
|
| 559 | + * @since 1.0.19 |
|
| 560 | + * @param string $value The renewal period. |
|
| 561 | + */ |
|
| 562 | + public function set_period( $value ) { |
|
| 563 | + $this->set_prop( 'period', $value ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Set number of periods each renewal is valid for. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + * @param int $value The subscription frequency. |
|
| 571 | + */ |
|
| 572 | + public function set_frequency( $value ) { |
|
| 573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Set the initial amount for the subscription. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @param float $value The initial subcription amount. |
|
| 582 | + */ |
|
| 583 | + public function set_initial_amount( $value ) { |
|
| 584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Set the recurring amount for the subscription. |
|
| 589 | + * |
|
| 590 | + * @since 1.0.19 |
|
| 591 | + * @param float $value The recurring subcription amount. |
|
| 592 | + */ |
|
| 593 | + public function set_recurring_amount( $value ) { |
|
| 594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Set number of times that this subscription can be renewed. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + * @param int $value Bill times. |
|
| 602 | + */ |
|
| 603 | + public function set_bill_times( $value ) { |
|
| 604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Get transaction id of this subscription's parent invoice. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param string $value Bill times. |
|
| 612 | + */ |
|
| 613 | + public function set_transaction_id( $value ) { |
|
| 614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Set date when this subscription started. |
|
| 619 | + * |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + * @param string $value strtotime compliant date. |
|
| 622 | + */ |
|
| 623 | + public function set_created( $value ) { |
|
| 624 | + $date = strtotime( $value ); |
|
| 625 | + |
|
| 626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | + return; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + $this->set_prop( 'created', '' ); |
|
| 229 | 632 | |
| 230 | - /** |
|
| 231 | - * Alias for self::get_parent_invoice_id(). |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Alias for self::set_created(). |
|
| 232 | 637 | * |
| 233 | - * @since 1.0.0 |
|
| 234 | - * @return int |
|
| 638 | + * @since 1.0.19 |
|
| 639 | + * @param string $value strtotime compliant date. |
|
| 235 | 640 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 641 | + public function set_date_created( $value ) { |
|
| 642 | + $this->set_created( $value ); |
|
| 238 | 643 | } |
| 239 | 644 | |
| 240 | - /** |
|
| 241 | - * Get parent invoice. |
|
| 242 | - * |
|
| 243 | - * @since 1.0.19 |
|
| 244 | - * @param string $context View or edit context. |
|
| 245 | - * @return WPInv_Invoice |
|
| 246 | - */ |
|
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Alias for self::get_parent_invoice(). |
|
| 253 | - * |
|
| 254 | - * @since 1.0.19 |
|
| 255 | - * @param string $context View or edit context. |
|
| 256 | - * @return WPInv_Invoice |
|
| 257 | - */ |
|
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Get subscription's product id. |
|
| 264 | - * |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @param string $context View or edit context. |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Get the subscription product. |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @param string $context View or edit context. |
|
| 278 | - * @return WPInv_Item |
|
| 279 | - */ |
|
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Get parent invoice's gateway. |
|
| 286 | - * |
|
| 287 | - * Here for backwards compatibility. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @param string $context View or edit context. |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Get the period of a renewal. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @param string $context View or edit context. |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Get number of periods each renewal is valid for. |
|
| 310 | - * |
|
| 311 | - * @since 1.0.19 |
|
| 312 | - * @param string $context View or edit context. |
|
| 313 | - * @return int |
|
| 314 | - */ |
|
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the initial amount for the subscription. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @param string $context View or edit context. |
|
| 324 | - * @return float |
|
| 325 | - */ |
|
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get the recurring amount for the subscription. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return float |
|
| 336 | - */ |
|
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Get number of times that this subscription can be renewed. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - * @param string $context View or edit context. |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Get transaction id of this subscription's parent invoice. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param string $context View or edit context. |
|
| 357 | - * @return string |
|
| 358 | - */ |
|
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Get the date that the subscription was created. |
|
| 365 | - * |
|
| 366 | - * @since 1.0.19 |
|
| 367 | - * @param string $context View or edit context. |
|
| 368 | - * @return string |
|
| 369 | - */ |
|
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Alias for self::get_created(). |
|
| 376 | - * |
|
| 377 | - * @since 1.0.19 |
|
| 378 | - * @param string $context View or edit context. |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Retrieves the creation date in a timestamp |
|
| 387 | - * |
|
| 388 | - * @since 1.0.0 |
|
| 389 | - * @return int |
|
| 390 | - */ |
|
| 391 | - public function get_time_created() { |
|
| 392 | - $created = $this->get_date_created(); |
|
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get GMT date when the subscription was created. |
|
| 398 | - * |
|
| 399 | - * @since 1.0.19 |
|
| 400 | - * @param string $context View or edit context. |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 645 | + /** |
|
| 646 | + * Set the date that the subscription will renew. |
|
| 647 | + * |
|
| 648 | + * @since 1.0.19 |
|
| 649 | + * @param string $value strtotime compliant date. |
|
| 650 | + */ |
|
| 651 | + public function set_next_renewal_date( $value ) { |
|
| 652 | + $date = strtotime( $value ); |
|
| 405 | 653 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 654 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 656 | + return; |
|
| 408 | 657 | } |
| 409 | - return $date; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get the date that the subscription will renew. |
|
| 414 | - * |
|
| 415 | - * @since 1.0.19 |
|
| 416 | - * @param string $context View or edit context. |
|
| 417 | - * @return string |
|
| 418 | - */ |
|
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Alias for self::get_next_renewal_date(). |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - * @param string $context View or edit context. |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Retrieves the expiration date in a timestamp |
|
| 436 | - * |
|
| 437 | - * @since 1.0.0 |
|
| 438 | - * @return int |
|
| 439 | - */ |
|
| 440 | - public function get_expiration_time() { |
|
| 441 | - $expiration = $this->get_expiration(); |
|
| 442 | - |
|
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Get GMT date when the subscription will renew. |
|
| 453 | - * |
|
| 454 | - * @since 1.0.19 |
|
| 455 | - * @param string $context View or edit context. |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 460 | 658 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 463 | - } |
|
| 464 | - return $date; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Get the subscription's trial period. |
|
| 469 | - * |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - * @param string $context View or edit context. |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Get the subscription's status. |
|
| 480 | - * |
|
| 481 | - * @since 1.0.19 |
|
| 482 | - * @param string $context View or edit context. |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Get the subscription's profile id. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $context View or edit context. |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /* |
|
| 501 | - |-------------------------------------------------------------------------- |
|
| 502 | - | Setters |
|
| 503 | - |-------------------------------------------------------------------------- |
|
| 504 | - */ |
|
| 659 | + $this->set_prop( 'expiration', '' ); |
|
| 505 | 660 | |
| 506 | - /** |
|
| 507 | - * Set customer id. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param int $value The customer's id. |
|
| 511 | - */ |
|
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Set parent invoice id. |
|
| 518 | - * |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - * @param int $value The parent invoice id. |
|
| 521 | - */ |
|
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Alias for self::set_parent_invoice_id(). |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - * @param int $value The parent invoice id. |
|
| 531 | - */ |
|
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 534 | - } |
|
| 661 | + } |
|
| 535 | 662 | |
| 536 | - /** |
|
| 537 | - * Alias for self::set_parent_invoice_id(). |
|
| 663 | + /** |
|
| 664 | + * Alias for self::set_next_renewal_date(). |
|
| 538 | 665 | * |
| 539 | 666 | * @since 1.0.19 |
| 540 | - * @param int $value The parent invoice id. |
|
| 667 | + * @param string $value strtotime compliant date. |
|
| 541 | 668 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Set subscription's product id. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param int $value The subscription product id. |
|
| 551 | - */ |
|
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Set the period of a renewal. |
|
| 558 | - * |
|
| 559 | - * @since 1.0.19 |
|
| 560 | - * @param string $value The renewal period. |
|
| 561 | - */ |
|
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Set number of periods each renewal is valid for. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - * @param int $value The subscription frequency. |
|
| 571 | - */ |
|
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Set the initial amount for the subscription. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @param float $value The initial subcription amount. |
|
| 582 | - */ |
|
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Set the recurring amount for the subscription. |
|
| 589 | - * |
|
| 590 | - * @since 1.0.19 |
|
| 591 | - * @param float $value The recurring subcription amount. |
|
| 592 | - */ |
|
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Set number of times that this subscription can be renewed. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - * @param int $value Bill times. |
|
| 602 | - */ |
|
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get transaction id of this subscription's parent invoice. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param string $value Bill times. |
|
| 612 | - */ |
|
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set date when this subscription started. |
|
| 619 | - * |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - * @param string $value strtotime compliant date. |
|
| 622 | - */ |
|
| 623 | - public function set_created( $value ) { |
|
| 624 | - $date = strtotime( $value ); |
|
| 669 | + public function set_expiration( $value ) { |
|
| 670 | + $this->set_next_renewal_date( $value ); |
|
| 671 | + } |
|
| 625 | 672 | |
| 626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 673 | + /** |
|
| 674 | + * Set the subscription's trial period. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @param string $value trial period e.g 1 year. |
|
| 678 | + */ |
|
| 679 | + public function set_trial_period( $value ) { |
|
| 680 | + $this->set_prop( 'trial_period', $value ); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Set the subscription's status. |
|
| 685 | + * |
|
| 686 | + * @since 1.0.19 |
|
| 687 | + * @param string $new_status New subscription status. |
|
| 688 | + */ |
|
| 689 | + public function set_status( $new_status ) { |
|
| 690 | + |
|
| 691 | + // Abort if this is not a valid status; |
|
| 692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 628 | 693 | return; |
| 629 | 694 | } |
| 630 | 695 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 696 | + $old_status = $this->get_status(); |
|
| 697 | + $this->set_prop( 'status', $new_status ); |
|
| 632 | 698 | |
| 633 | - } |
|
| 699 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | + $this->status_transition = array( |
|
| 701 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | + 'to' => $new_status, |
|
| 703 | + ); |
|
| 704 | + } |
|
| 634 | 705 | |
| 635 | - /** |
|
| 636 | - * Alias for self::set_created(). |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $value strtotime compliant date. |
|
| 640 | - */ |
|
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 643 | 706 | } |
| 644 | 707 | |
| 645 | - /** |
|
| 646 | - * Set the date that the subscription will renew. |
|
| 647 | - * |
|
| 648 | - * @since 1.0.19 |
|
| 649 | - * @param string $value strtotime compliant date. |
|
| 650 | - */ |
|
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 708 | + /** |
|
| 709 | + * Set the subscription's (remote) profile id. |
|
| 710 | + * |
|
| 711 | + * @since 1.0.19 |
|
| 712 | + * @param string $value the remote profile id. |
|
| 713 | + */ |
|
| 714 | + public function set_profile_id( $value ) { |
|
| 715 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | + } |
|
| 653 | 717 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 656 | - return; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 660 | - |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Alias for self::set_next_renewal_date(). |
|
| 665 | - * |
|
| 666 | - * @since 1.0.19 |
|
| 667 | - * @param string $value strtotime compliant date. |
|
| 668 | - */ |
|
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Set the subscription's trial period. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @param string $value trial period e.g 1 year. |
|
| 678 | - */ |
|
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Set the subscription's status. |
|
| 685 | - * |
|
| 686 | - * @since 1.0.19 |
|
| 687 | - * @param string $new_status New subscription status. |
|
| 688 | - */ |
|
| 689 | - public function set_status( $new_status ) { |
|
| 690 | - |
|
| 691 | - // Abort if this is not a valid status; |
|
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $old_status = $this->get_status(); |
|
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 698 | - |
|
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | - $this->status_transition = array( |
|
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | - 'to' => $new_status, |
|
| 703 | - ); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Set the subscription's (remote) profile id. |
|
| 710 | - * |
|
| 711 | - * @since 1.0.19 |
|
| 712 | - * @param string $value the remote profile id. |
|
| 713 | - */ |
|
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /* |
|
| 718 | + /* |
|
| 719 | 719 | |-------------------------------------------------------------------------- |
| 720 | 720 | | Boolean methods |
| 721 | 721 | |-------------------------------------------------------------------------- |
@@ -724,55 +724,55 @@ discard block |
||
| 724 | 724 | | |
| 725 | 725 | */ |
| 726 | 726 | |
| 727 | - /** |
|
| 727 | + /** |
|
| 728 | 728 | * Checks if the subscription has a given status. |
| 729 | - * |
|
| 730 | - * @param string|array String or array of strings to check for. |
|
| 731 | - * @return bool |
|
| 729 | + * |
|
| 730 | + * @param string|array String or array of strings to check for. |
|
| 731 | + * @return bool |
|
| 732 | 732 | */ |
| 733 | 733 | public function has_status( $status ) { |
| 734 | 734 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
| 735 | - } |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - /** |
|
| 737 | + /** |
|
| 738 | 738 | * Checks if the subscription has a trial period. |
| 739 | - * |
|
| 740 | - * @return bool |
|
| 739 | + * |
|
| 740 | + * @return bool |
|
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | - $period = $this->get_trial_period(); |
|
| 743 | + $period = $this->get_trial_period(); |
|
| 744 | 744 | return ! empty( $period ); |
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Is the subscription active? |
|
| 749 | - * |
|
| 750 | - * @return bool |
|
| 751 | - */ |
|
| 752 | - public function is_active() { |
|
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * Is the subscription expired? |
|
| 758 | - * |
|
| 759 | - * @return bool |
|
| 760 | - */ |
|
| 761 | - public function is_expired() { |
|
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Is this the last renewals? |
|
| 767 | - * |
|
| 768 | - * @return bool |
|
| 769 | - */ |
|
| 770 | - public function is_last_renewal() { |
|
| 771 | - $max_bills = $this->get_bill_times(); |
|
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /* |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Is the subscription active? |
|
| 749 | + * |
|
| 750 | + * @return bool |
|
| 751 | + */ |
|
| 752 | + public function is_active() { |
|
| 753 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * Is the subscription expired? |
|
| 758 | + * |
|
| 759 | + * @return bool |
|
| 760 | + */ |
|
| 761 | + public function is_expired() { |
|
| 762 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Is this the last renewals? |
|
| 767 | + * |
|
| 768 | + * @return bool |
|
| 769 | + */ |
|
| 770 | + public function is_last_renewal() { |
|
| 771 | + $max_bills = $this->get_bill_times(); |
|
| 772 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /* |
|
| 776 | 776 | |-------------------------------------------------------------------------- |
| 777 | 777 | | Additional methods |
| 778 | 778 | |-------------------------------------------------------------------------- |
@@ -781,27 +781,27 @@ discard block |
||
| 781 | 781 | | |
| 782 | 782 | */ |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * Backwards compatibilty. |
|
| 786 | - */ |
|
| 787 | - public function create( $data = array() ) { |
|
| 784 | + /** |
|
| 785 | + * Backwards compatibilty. |
|
| 786 | + */ |
|
| 787 | + public function create( $data = array() ) { |
|
| 788 | 788 | |
| 789 | - // Set the properties. |
|
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 792 | - } |
|
| 789 | + // Set the properties. |
|
| 790 | + if ( is_array( $data ) ) { |
|
| 791 | + $this->set_props( $data ); |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - // Save the item. |
|
| 795 | - return $this->save(); |
|
| 794 | + // Save the item. |
|
| 795 | + return $this->save(); |
|
| 796 | 796 | |
| 797 | - } |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - /** |
|
| 800 | - * Backwards compatibilty. |
|
| 801 | - */ |
|
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 804 | - } |
|
| 799 | + /** |
|
| 800 | + * Backwards compatibilty. |
|
| 801 | + */ |
|
| 802 | + public function update( $args = array() ) { |
|
| 803 | + return $this->create( $args ); |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | 806 | /** |
| 807 | 807 | * Retrieve renewal payments for a subscription |
@@ -811,22 +811,22 @@ discard block |
||
| 811 | 811 | */ |
| 812 | 812 | public function get_child_payments( $hide_pending = true ) { |
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | - } |
|
| 816 | + if ( ! $hide_pending ) { |
|
| 817 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | return get_posts( |
| 821 | - array( |
|
| 822 | - 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | - 'numberposts' => -1, |
|
| 824 | - 'post_status' => $statuses, |
|
| 825 | - 'orderby' => 'ID', |
|
| 826 | - 'order' => 'ASC', |
|
| 827 | - 'post_type' => 'wpi_invoice' |
|
| 828 | - ) |
|
| 829 | - ); |
|
| 821 | + array( |
|
| 822 | + 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | + 'numberposts' => -1, |
|
| 824 | + 'post_status' => $statuses, |
|
| 825 | + 'orderby' => 'ID', |
|
| 826 | + 'order' => 'ASC', |
|
| 827 | + 'post_type' => 'wpi_invoice' |
|
| 828 | + ) |
|
| 829 | + ); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -836,16 +836,16 @@ discard block |
||
| 836 | 836 | * @return int |
| 837 | 837 | */ |
| 838 | 838 | public function get_total_payments() { |
| 839 | - global $wpdb; |
|
| 839 | + global $wpdb; |
|
| 840 | 840 | |
| 841 | - $count = (int) $wpdb->get_var( |
|
| 842 | - $wpdb->prepare( |
|
| 843 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 844 | - $this->get_parent_invoice_id() |
|
| 845 | - ) |
|
| 846 | - ); |
|
| 841 | + $count = (int) $wpdb->get_var( |
|
| 842 | + $wpdb->prepare( |
|
| 843 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 844 | + $this->get_parent_invoice_id() |
|
| 845 | + ) |
|
| 846 | + ); |
|
| 847 | 847 | |
| 848 | - // Maybe include parent invoice. |
|
| 848 | + // Maybe include parent invoice. |
|
| 849 | 849 | if ( $this->get_parent_payment()->is_paid() ) { |
| 850 | 850 | $count++; |
| 851 | 851 | } |
@@ -874,57 +874,57 @@ discard block |
||
| 874 | 874 | * |
| 875 | 875 | * @since 2.4 |
| 876 | 876 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 877 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 877 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 878 | 878 | * @return bool |
| 879 | 879 | */ |
| 880 | 880 | public function add_payment( $args = array(), $invoice = false ) { |
| 881 | 881 | |
| 882 | - // Process each payment once. |
|
| 882 | + // Process each payment once. |
|
| 883 | 883 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 884 | 884 | return false; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - // Are we creating a new invoice? |
|
| 888 | - if ( empty( $invoice ) ) { |
|
| 889 | - $invoice = $this->create_payment(); |
|
| 887 | + // Are we creating a new invoice? |
|
| 888 | + if ( empty( $invoice ) ) { |
|
| 889 | + $invoice = $this->create_payment(); |
|
| 890 | 890 | |
| 891 | - if ( empty( $invoice ) ) { |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 891 | + if ( empty( $invoice ) ) { |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - } |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 897 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 898 | 898 | |
| 899 | - // Maybe set a transaction id. |
|
| 900 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 901 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 902 | - } |
|
| 899 | + // Maybe set a transaction id. |
|
| 900 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 901 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - // Set the completed date. |
|
| 905 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 904 | + // Set the completed date. |
|
| 905 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 906 | 906 | |
| 907 | - // And the gateway. |
|
| 908 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 909 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 910 | - } |
|
| 907 | + // And the gateway. |
|
| 908 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 909 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | - $invoice->save(); |
|
| 912 | + $invoice->save(); |
|
| 913 | 913 | |
| 914 | - if ( ! $invoice->exists() ) { |
|
| 915 | - return false; |
|
| 916 | - } |
|
| 914 | + if ( ! $invoice->exists() ) { |
|
| 915 | + return false; |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 919 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 918 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 919 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 920 | 920 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 921 | 921 | |
| 922 | 922 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 923 | 923 | |
| 924 | 924 | return $invoice->get_id(); |
| 925 | - } |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | - /** |
|
| 927 | + /** |
|
| 928 | 928 | * Creates a new invoice and returns it. |
| 929 | 929 | * |
| 930 | 930 | * @since 1.0.19 |
@@ -932,122 +932,122 @@ discard block |
||
| 932 | 932 | */ |
| 933 | 933 | public function create_payment() { |
| 934 | 934 | |
| 935 | - $parent_invoice = $this->get_parent_payment(); |
|
| 936 | - |
|
| 937 | - if ( ! $parent_invoice->exists() ) { |
|
| 938 | - return false; |
|
| 939 | - } |
|
| 935 | + $parent_invoice = $this->get_parent_payment(); |
|
| 936 | + |
|
| 937 | + if ( ! $parent_invoice->exists() ) { |
|
| 938 | + return false; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // Duplicate the parent invoice. |
|
| 942 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 943 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 944 | + |
|
| 945 | + // Set invoice items. |
|
| 946 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 947 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 948 | + $invoice_items = array(); |
|
| 949 | + |
|
| 950 | + foreach ( $invoice->get_items() as $item ) { |
|
| 951 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 952 | + $invoice_items[] = $item; |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + $invoice->set_items( $invoice_items ); |
|
| 957 | + |
|
| 958 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 959 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 963 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 964 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 965 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + $invoice->recalculate_total(); |
|
| 969 | + $invoice->set_status( 'wpi-pending' ); |
|
| 970 | + $invoice->save(); |
|
| 971 | + |
|
| 972 | + return $invoice->exists() ? $invoice : false; |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + /** |
|
| 976 | + * Renews or completes a subscription |
|
| 977 | + * |
|
| 978 | + * @since 1.0.0 |
|
| 979 | + * @return int The subscription's id |
|
| 980 | + */ |
|
| 981 | + public function renew() { |
|
| 982 | + |
|
| 983 | + // Complete subscription if applicable |
|
| 984 | + if ( $this->is_last_renewal() ) { |
|
| 985 | + return $this->complete(); |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + // Calculate new expiration |
|
| 989 | + $frequency = $this->get_frequency(); |
|
| 990 | + $period = $this->get_period(); |
|
| 991 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 992 | + |
|
| 993 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 994 | + $this->set_status( 'active' ); |
|
| 995 | + $this->save(); |
|
| 996 | + |
|
| 997 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 998 | + |
|
| 999 | + return $this->get_id(); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * Marks a subscription as completed |
|
| 1004 | + * |
|
| 1005 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 1006 | + * |
|
| 1007 | + * @since 1.0.0 |
|
| 1008 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 1009 | + */ |
|
| 1010 | + public function complete() { |
|
| 1011 | + |
|
| 1012 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 1013 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 1014 | + return false; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + $this->set_status( 'completed' ); |
|
| 1018 | + return $this->save(); |
|
| 1019 | + |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * Marks a subscription as expired |
|
| 1024 | + * |
|
| 1025 | + * @since 1.0.0 |
|
| 1026 | + * @param bool $check_expiration |
|
| 1027 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1028 | + */ |
|
| 1029 | + public function expire( $check_expiration = false ) { |
|
| 1030 | + |
|
| 1031 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1032 | + // Do not mark as expired since real expiration date is in the future |
|
| 1033 | + return false; |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + $this->set_status( 'expired' ); |
|
| 1037 | + return $this->save(); |
|
| 1038 | + |
|
| 1039 | + } |
|
| 940 | 1040 | |
| 941 | - // Duplicate the parent invoice. |
|
| 942 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 943 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 944 | - |
|
| 945 | - // Set invoice items. |
|
| 946 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 947 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 948 | - $invoice_items = array(); |
|
| 949 | - |
|
| 950 | - foreach ( $invoice->get_items() as $item ) { |
|
| 951 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 952 | - $invoice_items[] = $item; |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - $invoice->set_items( $invoice_items ); |
|
| 957 | - |
|
| 958 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 959 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 963 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 964 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 965 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - $invoice->recalculate_total(); |
|
| 969 | - $invoice->set_status( 'wpi-pending' ); |
|
| 970 | - $invoice->save(); |
|
| 971 | - |
|
| 972 | - return $invoice->exists() ? $invoice : false; |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - /** |
|
| 976 | - * Renews or completes a subscription |
|
| 977 | - * |
|
| 978 | - * @since 1.0.0 |
|
| 979 | - * @return int The subscription's id |
|
| 980 | - */ |
|
| 981 | - public function renew() { |
|
| 982 | - |
|
| 983 | - // Complete subscription if applicable |
|
| 984 | - if ( $this->is_last_renewal() ) { |
|
| 985 | - return $this->complete(); |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - // Calculate new expiration |
|
| 989 | - $frequency = $this->get_frequency(); |
|
| 990 | - $period = $this->get_period(); |
|
| 991 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 992 | - |
|
| 993 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 994 | - $this->set_status( 'active' ); |
|
| 995 | - $this->save(); |
|
| 996 | - |
|
| 997 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 998 | - |
|
| 999 | - return $this->get_id(); |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - /** |
|
| 1003 | - * Marks a subscription as completed |
|
| 1004 | - * |
|
| 1005 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 1006 | - * |
|
| 1007 | - * @since 1.0.0 |
|
| 1008 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 1009 | - */ |
|
| 1010 | - public function complete() { |
|
| 1011 | - |
|
| 1012 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 1013 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1014 | - return false; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - $this->set_status( 'completed' ); |
|
| 1018 | - return $this->save(); |
|
| 1019 | - |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * Marks a subscription as expired |
|
| 1024 | - * |
|
| 1025 | - * @since 1.0.0 |
|
| 1026 | - * @param bool $check_expiration |
|
| 1027 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1028 | - */ |
|
| 1029 | - public function expire( $check_expiration = false ) { |
|
| 1030 | - |
|
| 1031 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1032 | - // Do not mark as expired since real expiration date is in the future |
|
| 1033 | - return false; |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - $this->set_status( 'expired' ); |
|
| 1037 | - return $this->save(); |
|
| 1038 | - |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Marks a subscription as failing |
|
| 1043 | - * |
|
| 1044 | - * @since 2.4.2 |
|
| 1045 | - * @return int Subscription id. |
|
| 1046 | - */ |
|
| 1047 | - public function failing() { |
|
| 1048 | - $this->set_status( 'failing' ); |
|
| 1049 | - return $this->save(); |
|
| 1050 | - } |
|
| 1041 | + /** |
|
| 1042 | + * Marks a subscription as failing |
|
| 1043 | + * |
|
| 1044 | + * @since 2.4.2 |
|
| 1045 | + * @return int Subscription id. |
|
| 1046 | + */ |
|
| 1047 | + public function failing() { |
|
| 1048 | + $this->set_status( 'failing' ); |
|
| 1049 | + return $this->save(); |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | 1052 | /** |
| 1053 | 1053 | * Marks a subscription as cancelled |
@@ -1056,19 +1056,19 @@ discard block |
||
| 1056 | 1056 | * @return int Subscription id. |
| 1057 | 1057 | */ |
| 1058 | 1058 | public function cancel() { |
| 1059 | - $this->set_status( 'cancelled' ); |
|
| 1060 | - return $this->save(); |
|
| 1059 | + $this->set_status( 'cancelled' ); |
|
| 1060 | + return $this->save(); |
|
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - /** |
|
| 1064 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1065 | - * |
|
| 1066 | - * @since 1.0.0 |
|
| 1067 | - * @return bool |
|
| 1068 | - */ |
|
| 1069 | - public function can_cancel() { |
|
| 1070 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1071 | - } |
|
| 1063 | + /** |
|
| 1064 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1065 | + * |
|
| 1066 | + * @since 1.0.0 |
|
| 1067 | + * @return bool |
|
| 1068 | + */ |
|
| 1069 | + public function can_cancel() { |
|
| 1070 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1071 | + } |
|
| 1072 | 1072 | |
| 1073 | 1073 | /** |
| 1074 | 1074 | * Returns an array of subscription statuses that can be cancelled |
@@ -1081,96 +1081,96 @@ discard block |
||
| 1081 | 1081 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | - /** |
|
| 1085 | - * Retrieves the URL to cancel subscription |
|
| 1086 | - * |
|
| 1087 | - * @since 1.0.0 |
|
| 1088 | - * @return string |
|
| 1089 | - */ |
|
| 1090 | - public function get_cancel_url() { |
|
| 1091 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1092 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * Retrieves the URL to view a subscription |
|
| 1097 | - * |
|
| 1098 | - * @since 1.0.19 |
|
| 1099 | - * @return string |
|
| 1100 | - */ |
|
| 1101 | - public function get_view_url() { |
|
| 1102 | - |
|
| 1103 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1104 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1105 | - |
|
| 1106 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - /** |
|
| 1110 | - * Determines if subscription can be manually renewed |
|
| 1111 | - * |
|
| 1112 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1113 | - * that can be renewed manually |
|
| 1114 | - * |
|
| 1115 | - * @since 2.5 |
|
| 1116 | - * @return bool |
|
| 1117 | - */ |
|
| 1118 | - public function can_renew() { |
|
| 1119 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - /** |
|
| 1123 | - * Retrieves the URL to renew a subscription |
|
| 1124 | - * |
|
| 1125 | - * @since 2.5 |
|
| 1126 | - * @return string |
|
| 1127 | - */ |
|
| 1128 | - public function get_renew_url() { |
|
| 1129 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1130 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * Determines if subscription can have their payment method updated |
|
| 1135 | - * |
|
| 1136 | - * @since 1.0.0 |
|
| 1137 | - * @return bool |
|
| 1138 | - */ |
|
| 1139 | - public function can_update() { |
|
| 1140 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - /** |
|
| 1144 | - * Retrieves the URL to update subscription |
|
| 1145 | - * |
|
| 1146 | - * @since 1.0.0 |
|
| 1147 | - * @return string |
|
| 1148 | - */ |
|
| 1149 | - public function get_update_url() { |
|
| 1150 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1151 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - /** |
|
| 1155 | - * Retrieves the subscription status label |
|
| 1156 | - * |
|
| 1157 | - * @since 1.0.0 |
|
| 1158 | - * @return string |
|
| 1159 | - */ |
|
| 1160 | - public function get_status_label() { |
|
| 1161 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - /** |
|
| 1165 | - * Retrieves the subscription status class |
|
| 1166 | - * |
|
| 1167 | - * @since 1.0.19 |
|
| 1168 | - * @return string |
|
| 1169 | - */ |
|
| 1170 | - public function get_status_class() { |
|
| 1171 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1172 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1173 | - } |
|
| 1084 | + /** |
|
| 1085 | + * Retrieves the URL to cancel subscription |
|
| 1086 | + * |
|
| 1087 | + * @since 1.0.0 |
|
| 1088 | + * @return string |
|
| 1089 | + */ |
|
| 1090 | + public function get_cancel_url() { |
|
| 1091 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1092 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * Retrieves the URL to view a subscription |
|
| 1097 | + * |
|
| 1098 | + * @since 1.0.19 |
|
| 1099 | + * @return string |
|
| 1100 | + */ |
|
| 1101 | + public function get_view_url() { |
|
| 1102 | + |
|
| 1103 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1104 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1105 | + |
|
| 1106 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * Determines if subscription can be manually renewed |
|
| 1111 | + * |
|
| 1112 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1113 | + * that can be renewed manually |
|
| 1114 | + * |
|
| 1115 | + * @since 2.5 |
|
| 1116 | + * @return bool |
|
| 1117 | + */ |
|
| 1118 | + public function can_renew() { |
|
| 1119 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + /** |
|
| 1123 | + * Retrieves the URL to renew a subscription |
|
| 1124 | + * |
|
| 1125 | + * @since 2.5 |
|
| 1126 | + * @return string |
|
| 1127 | + */ |
|
| 1128 | + public function get_renew_url() { |
|
| 1129 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1130 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * Determines if subscription can have their payment method updated |
|
| 1135 | + * |
|
| 1136 | + * @since 1.0.0 |
|
| 1137 | + * @return bool |
|
| 1138 | + */ |
|
| 1139 | + public function can_update() { |
|
| 1140 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + /** |
|
| 1144 | + * Retrieves the URL to update subscription |
|
| 1145 | + * |
|
| 1146 | + * @since 1.0.0 |
|
| 1147 | + * @return string |
|
| 1148 | + */ |
|
| 1149 | + public function get_update_url() { |
|
| 1150 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1151 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + /** |
|
| 1155 | + * Retrieves the subscription status label |
|
| 1156 | + * |
|
| 1157 | + * @since 1.0.0 |
|
| 1158 | + * @return string |
|
| 1159 | + */ |
|
| 1160 | + public function get_status_label() { |
|
| 1161 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + /** |
|
| 1165 | + * Retrieves the subscription status class |
|
| 1166 | + * |
|
| 1167 | + * @since 1.0.19 |
|
| 1168 | + * @return string |
|
| 1169 | + */ |
|
| 1170 | + public function get_status_class() { |
|
| 1171 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1172 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | 1175 | /** |
| 1176 | 1176 | * Retrieves the subscription status label |
@@ -1180,11 +1180,11 @@ discard block |
||
| 1180 | 1180 | */ |
| 1181 | 1181 | public function get_status_label_html() { |
| 1182 | 1182 | |
| 1183 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1184 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1185 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1183 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1184 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1185 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 1186 | 1186 | |
| 1187 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1187 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | /** |
@@ -1195,75 +1195,75 @@ discard block |
||
| 1195 | 1195 | * @return bool |
| 1196 | 1196 | */ |
| 1197 | 1197 | public function payment_exists( $txn_id = '' ) { |
| 1198 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1198 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1199 | 1199 | return ! empty( $invoice_id ); |
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - /** |
|
| 1203 | - * Handle the status transition. |
|
| 1204 | - */ |
|
| 1205 | - protected function status_transition() { |
|
| 1206 | - $status_transition = $this->status_transition; |
|
| 1207 | - |
|
| 1208 | - // Reset status transition variable. |
|
| 1209 | - $this->status_transition = false; |
|
| 1210 | - |
|
| 1211 | - if ( $status_transition ) { |
|
| 1212 | - try { |
|
| 1213 | - |
|
| 1214 | - // Fire a hook for the status change. |
|
| 1215 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1216 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1217 | - |
|
| 1218 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1219 | - |
|
| 1220 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1221 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1222 | - |
|
| 1223 | - // Note the transition occurred. |
|
| 1224 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1225 | - |
|
| 1226 | - // Fire another hook. |
|
| 1227 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1228 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1229 | - |
|
| 1230 | - } else { |
|
| 1231 | - /* translators: %s: new invoice status */ |
|
| 1232 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1233 | - |
|
| 1234 | - // Note the transition occurred. |
|
| 1235 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1236 | - |
|
| 1237 | - } |
|
| 1238 | - } catch ( Exception $e ) { |
|
| 1239 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1240 | - } |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * Save data to the database. |
|
| 1247 | - * |
|
| 1248 | - * @since 1.0.19 |
|
| 1249 | - * @return int subscription ID |
|
| 1250 | - */ |
|
| 1251 | - public function save() { |
|
| 1252 | - parent::save(); |
|
| 1253 | - $this->status_transition(); |
|
| 1254 | - return $this->get_id(); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - /** |
|
| 1258 | - * Activates a subscription. |
|
| 1259 | - * |
|
| 1260 | - * @since 1.0.19 |
|
| 1261 | - * @return int subscription ID |
|
| 1262 | - */ |
|
| 1263 | - public function activate() { |
|
| 1264 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1265 | - $this->set_status( $status ); |
|
| 1266 | - return $this->save(); |
|
| 1267 | - } |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + /** |
|
| 1203 | + * Handle the status transition. |
|
| 1204 | + */ |
|
| 1205 | + protected function status_transition() { |
|
| 1206 | + $status_transition = $this->status_transition; |
|
| 1207 | + |
|
| 1208 | + // Reset status transition variable. |
|
| 1209 | + $this->status_transition = false; |
|
| 1210 | + |
|
| 1211 | + if ( $status_transition ) { |
|
| 1212 | + try { |
|
| 1213 | + |
|
| 1214 | + // Fire a hook for the status change. |
|
| 1215 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1216 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1217 | + |
|
| 1218 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1219 | + |
|
| 1220 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1221 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1222 | + |
|
| 1223 | + // Note the transition occurred. |
|
| 1224 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1225 | + |
|
| 1226 | + // Fire another hook. |
|
| 1227 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1228 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1229 | + |
|
| 1230 | + } else { |
|
| 1231 | + /* translators: %s: new invoice status */ |
|
| 1232 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1233 | + |
|
| 1234 | + // Note the transition occurred. |
|
| 1235 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1236 | + |
|
| 1237 | + } |
|
| 1238 | + } catch ( Exception $e ) { |
|
| 1239 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * Save data to the database. |
|
| 1247 | + * |
|
| 1248 | + * @since 1.0.19 |
|
| 1249 | + * @return int subscription ID |
|
| 1250 | + */ |
|
| 1251 | + public function save() { |
|
| 1252 | + parent::save(); |
|
| 1253 | + $this->status_transition(); |
|
| 1254 | + return $this->get_id(); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + /** |
|
| 1258 | + * Activates a subscription. |
|
| 1259 | + * |
|
| 1260 | + * @since 1.0.19 |
|
| 1261 | + * @return int subscription ID |
|
| 1262 | + */ |
|
| 1263 | + public function activate() { |
|
| 1264 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1265 | + $this->set_status( $status ); |
|
| 1266 | + return $this->save(); |
|
| 1267 | + } |
|
| 1268 | 1268 | |
| 1269 | 1269 | } |