@@ -13,467 +13,467 @@ 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 | - // Enable Subscriptions. |
|
| 147 | - if ( $this->supports( 'subscription' ) ) { |
|
| 148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Enable sandbox. |
|
| 152 | - if ( $this->supports( 'sandbox' ) ) { |
|
| 153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // Invoice addons. |
|
| 157 | - if ( $this->supports( 'addons' ) ) { |
|
| 158 | - add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
| 159 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // Gateway settings. |
|
| 163 | - 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 | + // Enable Subscriptions. |
|
| 147 | + if ( $this->supports( 'subscription' ) ) { |
|
| 148 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Enable sandbox. |
|
| 152 | + if ( $this->supports( 'sandbox' ) ) { |
|
| 153 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // Invoice addons. |
|
| 157 | + if ( $this->supports( 'addons' ) ) { |
|
| 158 | + add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
| 159 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // Gateway settings. |
|
| 163 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 164 | 164 | |
| 165 | 165 | |
| 166 | - // Gateway checkout fiellds. |
|
| 167 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 168 | - |
|
| 169 | - // Process payment. |
|
| 170 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 166 | + // Gateway checkout fiellds. |
|
| 167 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 168 | + |
|
| 169 | + // Process payment. |
|
| 170 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 171 | + |
|
| 172 | + // Change the checkout button text. |
|
| 173 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 174 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // Check if a gateway is valid for a given currency. |
|
| 178 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 179 | + |
|
| 180 | + // Generate the transaction url. |
|
| 181 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 182 | + |
|
| 183 | + // Generate the subscription url. |
|
| 184 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 185 | + |
|
| 186 | + // Confirm payments. |
|
| 187 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 188 | + |
|
| 189 | + // Verify IPNs. |
|
| 190 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Checks if this gateway is a given gateway. |
|
| 196 | + * |
|
| 197 | + * @since 1.0.19 |
|
| 198 | + * @return bool |
|
| 199 | + */ |
|
| 200 | + public function is( $gateway ) { |
|
| 201 | + return $gateway == $this->id; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns a users saved tokens for this gateway. |
|
| 206 | + * |
|
| 207 | + * @since 1.0.19 |
|
| 208 | + * @return array |
|
| 209 | + */ |
|
| 210 | + public function get_tokens( $sandbox = null ) { |
|
| 211 | + |
|
| 212 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 213 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 214 | + |
|
| 215 | + if ( is_array( $tokens ) ) { |
|
| 216 | + $this->tokens = $tokens; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if ( ! is_bool( $sandbox ) ) { |
|
| 222 | + return $this->tokens; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 226 | + return wp_list_filter( $this->tokens, $args ); |
|
| 227 | + |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Saves a token for this gateway. |
|
| 232 | + * |
|
| 233 | + * @since 1.0.19 |
|
| 234 | + */ |
|
| 235 | + public function save_token( $token ) { |
|
| 236 | + |
|
| 237 | + $tokens = $this->get_tokens(); |
|
| 238 | + $tokens[] = $token; |
|
| 239 | + |
|
| 240 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 241 | + |
|
| 242 | + $this->tokens = $tokens; |
|
| 243 | + |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Return the title for admin screens. |
|
| 248 | + * |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function get_method_title() { |
|
| 252 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Return the description for admin screens. |
|
| 257 | + * |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public function get_method_description() { |
|
| 261 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Get the success url. |
|
| 266 | + * |
|
| 267 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 268 | + * @return string |
|
| 269 | + */ |
|
| 270 | + public function get_return_url( $invoice ) { |
|
| 271 | + |
|
| 272 | + // Payment success url |
|
| 273 | + $return_url = add_query_arg( |
|
| 274 | + array( |
|
| 275 | + 'payment-confirm' => $this->id, |
|
| 276 | + 'invoice_key' => $invoice->get_key(), |
|
| 277 | + 'utm_nooverride' => 1 |
|
| 278 | + ), |
|
| 279 | + wpinv_get_success_page_uri() |
|
| 280 | + ); |
|
| 281 | + |
|
| 282 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Confirms payments when rendering the success page. |
|
| 287 | + * |
|
| 288 | + * @param string $content Success page content. |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + public function confirm_payment( $content ) { |
|
| 292 | + |
|
| 293 | + // Retrieve the invoice. |
|
| 294 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 295 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 296 | + |
|
| 297 | + // Ensure that it exists and that it is pending payment. |
|
| 298 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 299 | + return $content; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // Can the user view this invoice?? |
|
| 303 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 304 | + return $content; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // Show payment processing indicator. |
|
| 308 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Processes ipns and marks payments as complete. |
|
| 313 | + * |
|
| 314 | + * @return void |
|
| 315 | + */ |
|
| 316 | + public function verify_ipn() {} |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Processes invoice addons. |
|
| 320 | + * |
|
| 321 | + * @param WPInv_Invoice $invoice |
|
| 322 | + * @param GetPaid_Form_Item[] $items |
|
| 323 | + * @return WPInv_Invoice |
|
| 324 | + */ |
|
| 325 | + public function process_addons( $invoice, $items ) { |
|
| 326 | + |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 331 | + * |
|
| 332 | + * @param string $transaction_url transaction url. |
|
| 333 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 334 | + * @return string transaction URL, or empty string. |
|
| 335 | + */ |
|
| 336 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 337 | + |
|
| 338 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 339 | + |
|
| 340 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 341 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 342 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 343 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + return $transaction_url; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 351 | + * |
|
| 352 | + * @param string $subscription_url transaction url. |
|
| 353 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 354 | + * @return string subscription URL, or empty string. |
|
| 355 | + */ |
|
| 356 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 171 | 357 | |
| 172 | - // Change the checkout button text. |
|
| 173 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 174 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // Check if a gateway is valid for a given currency. |
|
| 178 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 179 | - |
|
| 180 | - // Generate the transaction url. |
|
| 181 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 182 | - |
|
| 183 | - // Generate the subscription url. |
|
| 184 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 185 | - |
|
| 186 | - // Confirm payments. |
|
| 187 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 188 | - |
|
| 189 | - // Verify IPNs. |
|
| 190 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 191 | - |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Checks if this gateway is a given gateway. |
|
| 196 | - * |
|
| 197 | - * @since 1.0.19 |
|
| 198 | - * @return bool |
|
| 199 | - */ |
|
| 200 | - public function is( $gateway ) { |
|
| 201 | - return $gateway == $this->id; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns a users saved tokens for this gateway. |
|
| 206 | - * |
|
| 207 | - * @since 1.0.19 |
|
| 208 | - * @return array |
|
| 209 | - */ |
|
| 210 | - public function get_tokens( $sandbox = null ) { |
|
| 211 | - |
|
| 212 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 213 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 214 | - |
|
| 215 | - if ( is_array( $tokens ) ) { |
|
| 216 | - $this->tokens = $tokens; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if ( ! is_bool( $sandbox ) ) { |
|
| 222 | - return $this->tokens; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 226 | - return wp_list_filter( $this->tokens, $args ); |
|
| 227 | - |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Saves a token for this gateway. |
|
| 232 | - * |
|
| 233 | - * @since 1.0.19 |
|
| 234 | - */ |
|
| 235 | - public function save_token( $token ) { |
|
| 236 | - |
|
| 237 | - $tokens = $this->get_tokens(); |
|
| 238 | - $tokens[] = $token; |
|
| 239 | - |
|
| 240 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 241 | - |
|
| 242 | - $this->tokens = $tokens; |
|
| 243 | - |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Return the title for admin screens. |
|
| 248 | - * |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function get_method_title() { |
|
| 252 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Return the description for admin screens. |
|
| 257 | - * |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public function get_method_description() { |
|
| 261 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Get the success url. |
|
| 266 | - * |
|
| 267 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 268 | - * @return string |
|
| 269 | - */ |
|
| 270 | - public function get_return_url( $invoice ) { |
|
| 271 | - |
|
| 272 | - // Payment success url |
|
| 273 | - $return_url = add_query_arg( |
|
| 274 | - array( |
|
| 275 | - 'payment-confirm' => $this->id, |
|
| 276 | - 'invoice_key' => $invoice->get_key(), |
|
| 277 | - 'utm_nooverride' => 1 |
|
| 278 | - ), |
|
| 279 | - wpinv_get_success_page_uri() |
|
| 280 | - ); |
|
| 281 | - |
|
| 282 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Confirms payments when rendering the success page. |
|
| 287 | - * |
|
| 288 | - * @param string $content Success page content. |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - public function confirm_payment( $content ) { |
|
| 292 | - |
|
| 293 | - // Retrieve the invoice. |
|
| 294 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 295 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 296 | - |
|
| 297 | - // Ensure that it exists and that it is pending payment. |
|
| 298 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 299 | - return $content; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // Can the user view this invoice?? |
|
| 303 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 304 | - return $content; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // Show payment processing indicator. |
|
| 308 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Processes ipns and marks payments as complete. |
|
| 313 | - * |
|
| 314 | - * @return void |
|
| 315 | - */ |
|
| 316 | - public function verify_ipn() {} |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Processes invoice addons. |
|
| 320 | - * |
|
| 321 | - * @param WPInv_Invoice $invoice |
|
| 322 | - * @param GetPaid_Form_Item[] $items |
|
| 323 | - * @return WPInv_Invoice |
|
| 324 | - */ |
|
| 325 | - public function process_addons( $invoice, $items ) { |
|
| 326 | - |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 331 | - * |
|
| 332 | - * @param string $transaction_url transaction url. |
|
| 333 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 334 | - * @return string transaction URL, or empty string. |
|
| 335 | - */ |
|
| 336 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 337 | - |
|
| 338 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 339 | - |
|
| 340 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 341 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 342 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 343 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - return $transaction_url; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 351 | - * |
|
| 352 | - * @param string $subscription_url transaction url. |
|
| 353 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 354 | - * @return string subscription URL, or empty string. |
|
| 355 | - */ |
|
| 356 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 357 | - |
|
| 358 | - $profile_id = $subscription->get_profile_id(); |
|
| 359 | - |
|
| 360 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 361 | - |
|
| 362 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 363 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 364 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 365 | - |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $subscription_url; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Check if the gateway is available for use. |
|
| 373 | - * |
|
| 374 | - * @return bool |
|
| 375 | - */ |
|
| 376 | - public function is_available() { |
|
| 377 | - return ! empty( $this->enabled ); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Return the gateway's title. |
|
| 382 | - * |
|
| 383 | - * @return string |
|
| 384 | - */ |
|
| 385 | - public function get_title() { |
|
| 386 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Return the gateway's description. |
|
| 391 | - * |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - public function get_description() { |
|
| 395 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Process Payment. |
|
| 400 | - * |
|
| 401 | - * |
|
| 402 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 403 | - * @param array $submission_data Posted checkout fields. |
|
| 404 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 405 | - * @return void |
|
| 406 | - */ |
|
| 407 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 408 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 409 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Process refund. |
|
| 414 | - * |
|
| 415 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 416 | - * a passed in amount. |
|
| 417 | - * |
|
| 418 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 419 | - * @param float $amount Refund amount. |
|
| 420 | - * @param string $reason Refund reason. |
|
| 421 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 422 | - */ |
|
| 423 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 424 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Displays the payment fields, credit cards etc. |
|
| 429 | - * |
|
| 430 | - * @param int $invoice_id 0 or invoice id. |
|
| 431 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 432 | - */ |
|
| 433 | - public function payment_fields( $invoice_id, $form ) { |
|
| 434 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Filters the gateway settings. |
|
| 439 | - * |
|
| 440 | - * @param array $admin_settings |
|
| 441 | - */ |
|
| 442 | - public function admin_settings( $admin_settings ) { |
|
| 443 | - return $admin_settings; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Retrieves the value of a gateway setting. |
|
| 448 | - * |
|
| 449 | - * @param string $option |
|
| 450 | - */ |
|
| 451 | - public function get_option( $option, $default = false ) { |
|
| 452 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Check if a gateway supports a given feature. |
|
| 457 | - * |
|
| 458 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 459 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 460 | - * |
|
| 461 | - * @param string $feature string The name of a feature to test support for. |
|
| 462 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - */ |
|
| 465 | - public function supports( $feature ) { |
|
| 466 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Returns the credit card form html. |
|
| 471 | - * |
|
| 472 | - * @param bool $save whether or not to display the save button. |
|
| 473 | - */ |
|
| 358 | + $profile_id = $subscription->get_profile_id(); |
|
| 359 | + |
|
| 360 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 361 | + |
|
| 362 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 363 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 364 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 365 | + |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $subscription_url; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Check if the gateway is available for use. |
|
| 373 | + * |
|
| 374 | + * @return bool |
|
| 375 | + */ |
|
| 376 | + public function is_available() { |
|
| 377 | + return ! empty( $this->enabled ); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Return the gateway's title. |
|
| 382 | + * |
|
| 383 | + * @return string |
|
| 384 | + */ |
|
| 385 | + public function get_title() { |
|
| 386 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Return the gateway's description. |
|
| 391 | + * |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + public function get_description() { |
|
| 395 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Process Payment. |
|
| 400 | + * |
|
| 401 | + * |
|
| 402 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 403 | + * @param array $submission_data Posted checkout fields. |
|
| 404 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 405 | + * @return void |
|
| 406 | + */ |
|
| 407 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 408 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 409 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Process refund. |
|
| 414 | + * |
|
| 415 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 416 | + * a passed in amount. |
|
| 417 | + * |
|
| 418 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 419 | + * @param float $amount Refund amount. |
|
| 420 | + * @param string $reason Refund reason. |
|
| 421 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 422 | + */ |
|
| 423 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 424 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Displays the payment fields, credit cards etc. |
|
| 429 | + * |
|
| 430 | + * @param int $invoice_id 0 or invoice id. |
|
| 431 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 432 | + */ |
|
| 433 | + public function payment_fields( $invoice_id, $form ) { |
|
| 434 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Filters the gateway settings. |
|
| 439 | + * |
|
| 440 | + * @param array $admin_settings |
|
| 441 | + */ |
|
| 442 | + public function admin_settings( $admin_settings ) { |
|
| 443 | + return $admin_settings; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Retrieves the value of a gateway setting. |
|
| 448 | + * |
|
| 449 | + * @param string $option |
|
| 450 | + */ |
|
| 451 | + public function get_option( $option, $default = false ) { |
|
| 452 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Check if a gateway supports a given feature. |
|
| 457 | + * |
|
| 458 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 459 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 460 | + * |
|
| 461 | + * @param string $feature string The name of a feature to test support for. |
|
| 462 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + */ |
|
| 465 | + public function supports( $feature ) { |
|
| 466 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Returns the credit card form html. |
|
| 471 | + * |
|
| 472 | + * @param bool $save whether or not to display the save button. |
|
| 473 | + */ |
|
| 474 | 474 | public function get_cc_form( $save = false ) { |
| 475 | 475 | |
| 476 | - ob_start(); |
|
| 476 | + ob_start(); |
|
| 477 | 477 | |
| 478 | 478 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 479 | 479 | |
@@ -568,11 +568,11 @@ discard block |
||
| 568 | 568 | 'name' => $this->id . '[cc_cvv2]', |
| 569 | 569 | 'id' => "$id_prefix-cc-cvv2", |
| 570 | 570 | 'label' => __( 'CCV', 'invoicing' ), |
| 571 | - 'label_type' => 'vertical', |
|
| 572 | - 'class' => 'form-control-sm', |
|
| 573 | - 'extra_attributes' => array( |
|
| 574 | - 'autocomplete' => "cc-csc", |
|
| 575 | - ), |
|
| 571 | + 'label_type' => 'vertical', |
|
| 572 | + 'class' => 'form-control-sm', |
|
| 573 | + 'extra_attributes' => array( |
|
| 574 | + 'autocomplete' => "cc-csc", |
|
| 575 | + ), |
|
| 576 | 576 | ) |
| 577 | 577 | ); |
| 578 | 578 | ?> |
@@ -582,191 +582,191 @@ discard block |
||
| 582 | 582 | |
| 583 | 583 | <?php |
| 584 | 584 | |
| 585 | - if ( $save ) { |
|
| 586 | - echo $this->save_payment_method_checkbox(); |
|
| 587 | - } |
|
| 585 | + if ( $save ) { |
|
| 586 | + echo $this->save_payment_method_checkbox(); |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - ?> |
|
| 589 | + ?> |
|
| 590 | 590 | </div> |
| 591 | 591 | |
| 592 | 592 | </div> |
| 593 | 593 | <?php |
| 594 | 594 | |
| 595 | - return ob_get_clean(); |
|
| 595 | + return ob_get_clean(); |
|
| 596 | 596 | |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - /** |
|
| 600 | - * Displays a new payment method entry form. |
|
| 601 | - * |
|
| 602 | - * @since 1.0.19 |
|
| 603 | - */ |
|
| 604 | - public function new_payment_method_entry( $form ) { |
|
| 605 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Grab and display our saved payment methods. |
|
| 610 | - * |
|
| 611 | - * @since 1.0.19 |
|
| 612 | - */ |
|
| 613 | - public function saved_payment_methods() { |
|
| 614 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 615 | - |
|
| 616 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 617 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - $html .= $this->get_new_payment_method_option_html(); |
|
| 621 | - $html .= '</ul>'; |
|
| 622 | - |
|
| 623 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Gets saved payment method HTML from a token. |
|
| 628 | - * |
|
| 629 | - * @since 1.0.19 |
|
| 630 | - * @param array $token Payment Token. |
|
| 631 | - * @return string Generated payment method HTML |
|
| 632 | - */ |
|
| 633 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 634 | - |
|
| 635 | - return sprintf( |
|
| 636 | - '<li class="getpaid-payment-method form-group"> |
|
| 599 | + /** |
|
| 600 | + * Displays a new payment method entry form. |
|
| 601 | + * |
|
| 602 | + * @since 1.0.19 |
|
| 603 | + */ |
|
| 604 | + public function new_payment_method_entry( $form ) { |
|
| 605 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Grab and display our saved payment methods. |
|
| 610 | + * |
|
| 611 | + * @since 1.0.19 |
|
| 612 | + */ |
|
| 613 | + public function saved_payment_methods() { |
|
| 614 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 615 | + |
|
| 616 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 617 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + $html .= $this->get_new_payment_method_option_html(); |
|
| 621 | + $html .= '</ul>'; |
|
| 622 | + |
|
| 623 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Gets saved payment method HTML from a token. |
|
| 628 | + * |
|
| 629 | + * @since 1.0.19 |
|
| 630 | + * @param array $token Payment Token. |
|
| 631 | + * @return string Generated payment method HTML |
|
| 632 | + */ |
|
| 633 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 634 | + |
|
| 635 | + return sprintf( |
|
| 636 | + '<li class="getpaid-payment-method form-group"> |
|
| 637 | 637 | <label> |
| 638 | 638 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 639 | 639 | <span>%3$s</span> |
| 640 | 640 | </label> |
| 641 | 641 | </li>', |
| 642 | - esc_attr( $this->id ), |
|
| 643 | - esc_attr( $token['id'] ), |
|
| 644 | - esc_html( $token['name'] ), |
|
| 645 | - checked( empty( $token['default'] ), false, false ) |
|
| 646 | - ); |
|
| 642 | + esc_attr( $this->id ), |
|
| 643 | + esc_attr( $token['id'] ), |
|
| 644 | + esc_html( $token['name'] ), |
|
| 645 | + checked( empty( $token['default'] ), false, false ) |
|
| 646 | + ); |
|
| 647 | 647 | |
| 648 | - } |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - /** |
|
| 651 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 652 | - * |
|
| 653 | - * @since 1.0.19 |
|
| 654 | - */ |
|
| 655 | - public function get_new_payment_method_option_html() { |
|
| 650 | + /** |
|
| 651 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 652 | + * |
|
| 653 | + * @since 1.0.19 |
|
| 654 | + */ |
|
| 655 | + public function get_new_payment_method_option_html() { |
|
| 656 | 656 | |
| 657 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 657 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 658 | 658 | |
| 659 | - return sprintf( |
|
| 660 | - '<li class="getpaid-new-payment-method"> |
|
| 659 | + return sprintf( |
|
| 660 | + '<li class="getpaid-new-payment-method"> |
|
| 661 | 661 | <label> |
| 662 | 662 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
| 663 | 663 | <span>%2$s</span> |
| 664 | 664 | </label> |
| 665 | 665 | </li>', |
| 666 | - esc_attr( $this->id ), |
|
| 667 | - esc_html( $label ) |
|
| 668 | - ); |
|
| 669 | - |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 674 | - * |
|
| 675 | - * @since 1.0.19 |
|
| 676 | - */ |
|
| 677 | - public function save_payment_method_checkbox() { |
|
| 678 | - |
|
| 679 | - return aui()->input( |
|
| 680 | - array( |
|
| 681 | - 'type' => 'checkbox', |
|
| 682 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 683 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 684 | - 'required' => false, |
|
| 685 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 686 | - 'value' => 'true', |
|
| 687 | - 'checked' => true, |
|
| 688 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 689 | - ) |
|
| 690 | - ); |
|
| 691 | - |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Registers the gateway. |
|
| 696 | - * |
|
| 697 | - * @return array |
|
| 698 | - */ |
|
| 699 | - public function register_gateway( $gateways ) { |
|
| 700 | - |
|
| 701 | - $gateways[ $this->id ] = array( |
|
| 702 | - |
|
| 703 | - 'admin_label' => $this->method_title, |
|
| 666 | + esc_attr( $this->id ), |
|
| 667 | + esc_html( $label ) |
|
| 668 | + ); |
|
| 669 | + |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 674 | + * |
|
| 675 | + * @since 1.0.19 |
|
| 676 | + */ |
|
| 677 | + public function save_payment_method_checkbox() { |
|
| 678 | + |
|
| 679 | + return aui()->input( |
|
| 680 | + array( |
|
| 681 | + 'type' => 'checkbox', |
|
| 682 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 683 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 684 | + 'required' => false, |
|
| 685 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 686 | + 'value' => 'true', |
|
| 687 | + 'checked' => true, |
|
| 688 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 689 | + ) |
|
| 690 | + ); |
|
| 691 | + |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Registers the gateway. |
|
| 696 | + * |
|
| 697 | + * @return array |
|
| 698 | + */ |
|
| 699 | + public function register_gateway( $gateways ) { |
|
| 700 | + |
|
| 701 | + $gateways[ $this->id ] = array( |
|
| 702 | + |
|
| 703 | + 'admin_label' => $this->method_title, |
|
| 704 | 704 | 'checkout_label' => $this->title, |
| 705 | - 'ordering' => $this->order, |
|
| 705 | + 'ordering' => $this->order, |
|
| 706 | 706 | |
| 707 | - ); |
|
| 707 | + ); |
|
| 708 | 708 | |
| 709 | - return $gateways; |
|
| 709 | + return $gateways; |
|
| 710 | 710 | |
| 711 | - } |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - /** |
|
| 714 | - * Checks whether or not this is a sandbox request. |
|
| 715 | - * |
|
| 716 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 717 | - * @return bool |
|
| 718 | - */ |
|
| 719 | - public function is_sandbox( $invoice = null ) { |
|
| 713 | + /** |
|
| 714 | + * Checks whether or not this is a sandbox request. |
|
| 715 | + * |
|
| 716 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 717 | + * @return bool |
|
| 718 | + */ |
|
| 719 | + public function is_sandbox( $invoice = null ) { |
|
| 720 | 720 | |
| 721 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 722 | - return $invoice->get_mode() == 'test'; |
|
| 723 | - } |
|
| 721 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 722 | + return $invoice->get_mode() == 'test'; |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - return wpinv_is_test_mode( $this->id ); |
|
| 725 | + return wpinv_is_test_mode( $this->id ); |
|
| 726 | 726 | |
| 727 | - } |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | - /** |
|
| 730 | - * Renames the checkout button |
|
| 731 | - * |
|
| 732 | - * @return string |
|
| 733 | - */ |
|
| 734 | - public function rename_checkout_button() { |
|
| 735 | - return $this->checkout_button_text; |
|
| 736 | - } |
|
| 729 | + /** |
|
| 730 | + * Renames the checkout button |
|
| 731 | + * |
|
| 732 | + * @return string |
|
| 733 | + */ |
|
| 734 | + public function rename_checkout_button() { |
|
| 735 | + return $this->checkout_button_text; |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - /** |
|
| 739 | - * Validate gateway currency |
|
| 740 | - * |
|
| 741 | - * @return bool |
|
| 742 | - */ |
|
| 743 | - public function validate_currency( $validation, $currency ) { |
|
| 738 | + /** |
|
| 739 | + * Validate gateway currency |
|
| 740 | + * |
|
| 741 | + * @return bool |
|
| 742 | + */ |
|
| 743 | + public function validate_currency( $validation, $currency ) { |
|
| 744 | 744 | |
| 745 | - // Required currencies. |
|
| 746 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 747 | - return false; |
|
| 748 | - } |
|
| 745 | + // Required currencies. |
|
| 746 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 747 | + return false; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - // Excluded currencies. |
|
| 751 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 752 | - return false; |
|
| 753 | - } |
|
| 750 | + // Excluded currencies. |
|
| 751 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - return $validation; |
|
| 756 | - } |
|
| 755 | + return $validation; |
|
| 756 | + } |
|
| 757 | 757 | |
| 758 | - /** |
|
| 759 | - * Displays an error |
|
| 760 | - * |
|
| 761 | - */ |
|
| 762 | - public function show_error( $code, $message, $type ) { |
|
| 758 | + /** |
|
| 759 | + * Displays an error |
|
| 760 | + * |
|
| 761 | + */ |
|
| 762 | + public function show_error( $code, $message, $type ) { |
|
| 763 | 763 | |
| 764 | - if ( is_admin() ) { |
|
| 765 | - getpaid_admin()->{"show_$type"}( $message ); |
|
| 766 | - } |
|
| 764 | + if ( is_admin() ) { |
|
| 765 | + getpaid_admin()->{"show_$type"}( $message ); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | - wpinv_set_error( $code, $message, $type ); |
|
| 768 | + wpinv_set_error( $code, $message, $type ); |
|
| 769 | 769 | |
| 770 | - } |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | 772 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Abstaract Payment Gateway class. |
@@ -139,55 +139,55 @@ discard block |
||
| 139 | 139 | public function __construct() { |
| 140 | 140 | |
| 141 | 141 | // Register gateway. |
| 142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 142 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
| 143 | 143 | |
| 144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 144 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
| 145 | 145 | |
| 146 | 146 | // Enable Subscriptions. |
| 147 | - if ( $this->supports( 'subscription' ) ) { |
|
| 148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 147 | + if ($this->supports('subscription')) { |
|
| 148 | + add_filter("wpinv_{$this->id}_support_subscription", '__return_true'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Enable sandbox. |
| 152 | - if ( $this->supports( 'sandbox' ) ) { |
|
| 153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 152 | + if ($this->supports('sandbox')) { |
|
| 153 | + add_filter("wpinv_{$this->id}_supports_sandbox", '__return_true'); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // Invoice addons. |
| 157 | - if ( $this->supports( 'addons' ) ) { |
|
| 158 | - add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
| 159 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 157 | + if ($this->supports('addons')) { |
|
| 158 | + add_filter("getpaid_{$this->id}_supports_addons", '__return_true'); |
|
| 159 | + add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // Gateway settings. |
| 163 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 163 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | // Gateway checkout fiellds. |
| 167 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 167 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
| 168 | 168 | |
| 169 | 169 | // Process payment. |
| 170 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 170 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
| 171 | 171 | |
| 172 | 172 | // Change the checkout button text. |
| 173 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 174 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 173 | + if (!empty($this->checkout_button_text)) { |
|
| 174 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // Check if a gateway is valid for a given currency. |
| 178 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 178 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
| 179 | 179 | |
| 180 | 180 | // Generate the transaction url. |
| 181 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 181 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
| 182 | 182 | |
| 183 | 183 | // Generate the subscription url. |
| 184 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 184 | + add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2); |
|
| 185 | 185 | |
| 186 | 186 | // Confirm payments. |
| 187 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 187 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
| 188 | 188 | |
| 189 | 189 | // Verify IPNs. |
| 190 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 190 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
| 191 | 191 | |
| 192 | 192 | } |
| 193 | 193 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @since 1.0.19 |
| 198 | 198 | * @return bool |
| 199 | 199 | */ |
| 200 | - public function is( $gateway ) { |
|
| 200 | + public function is($gateway) { |
|
| 201 | 201 | return $gateway == $this->id; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -207,23 +207,23 @@ discard block |
||
| 207 | 207 | * @since 1.0.19 |
| 208 | 208 | * @return array |
| 209 | 209 | */ |
| 210 | - public function get_tokens( $sandbox = null ) { |
|
| 210 | + public function get_tokens($sandbox = null) { |
|
| 211 | 211 | |
| 212 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 213 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 212 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
| 213 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
| 214 | 214 | |
| 215 | - if ( is_array( $tokens ) ) { |
|
| 215 | + if (is_array($tokens)) { |
|
| 216 | 216 | $this->tokens = $tokens; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if ( ! is_bool( $sandbox ) ) { |
|
| 221 | + if (!is_bool($sandbox)) { |
|
| 222 | 222 | return $this->tokens; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 226 | - return wp_list_filter( $this->tokens, $args ); |
|
| 225 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
| 226 | + return wp_list_filter($this->tokens, $args); |
|
| 227 | 227 | |
| 228 | 228 | } |
| 229 | 229 | |
@@ -232,12 +232,12 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @since 1.0.19 |
| 234 | 234 | */ |
| 235 | - public function save_token( $token ) { |
|
| 235 | + public function save_token($token) { |
|
| 236 | 236 | |
| 237 | 237 | $tokens = $this->get_tokens(); |
| 238 | 238 | $tokens[] = $token; |
| 239 | 239 | |
| 240 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 240 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
| 241 | 241 | |
| 242 | 242 | $this->tokens = $tokens; |
| 243 | 243 | |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | 251 | public function get_method_title() { |
| 252 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 252 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | 260 | public function get_method_description() { |
| 261 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 261 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @param WPInv_Invoice $invoice Invoice object. |
| 268 | 268 | * @return string |
| 269 | 269 | */ |
| 270 | - public function get_return_url( $invoice ) { |
|
| 270 | + public function get_return_url($invoice) { |
|
| 271 | 271 | |
| 272 | 272 | // Payment success url |
| 273 | 273 | $return_url = add_query_arg( |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | wpinv_get_success_page_uri() |
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 282 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -288,24 +288,24 @@ discard block |
||
| 288 | 288 | * @param string $content Success page content. |
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | - public function confirm_payment( $content ) { |
|
| 291 | + public function confirm_payment($content) { |
|
| 292 | 292 | |
| 293 | 293 | // Retrieve the invoice. |
| 294 | 294 | $invoice_id = getpaid_get_current_invoice_id(); |
| 295 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 295 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 296 | 296 | |
| 297 | 297 | // Ensure that it exists and that it is pending payment. |
| 298 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 298 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
| 299 | 299 | return $content; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // Can the user view this invoice?? |
| 303 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 303 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
| 304 | 304 | return $content; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Show payment processing indicator. |
| 308 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 308 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @param GetPaid_Form_Item[] $items |
| 323 | 323 | * @return WPInv_Invoice |
| 324 | 324 | */ |
| 325 | - public function process_addons( $invoice, $items ) { |
|
| 325 | + public function process_addons($invoice, $items) { |
|
| 326 | 326 | |
| 327 | 327 | } |
| 328 | 328 | |
@@ -333,14 +333,14 @@ discard block |
||
| 333 | 333 | * @param WPInv_Invoice $invoice Invoice object. |
| 334 | 334 | * @return string transaction URL, or empty string. |
| 335 | 335 | */ |
| 336 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 336 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
| 337 | 337 | |
| 338 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 338 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 339 | 339 | |
| 340 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 341 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 342 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 343 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 340 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
| 341 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
| 342 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
| 343 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | return $transaction_url; |
@@ -353,15 +353,15 @@ discard block |
||
| 353 | 353 | * @param WPInv_Subscription $subscription Subscription objectt. |
| 354 | 354 | * @return string subscription URL, or empty string. |
| 355 | 355 | */ |
| 356 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 356 | + public function generate_subscription_url($subscription_url, $subscription) { |
|
| 357 | 357 | |
| 358 | - $profile_id = $subscription->get_profile_id(); |
|
| 358 | + $profile_id = $subscription->get_profile_id(); |
|
| 359 | 359 | |
| 360 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 360 | + if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) { |
|
| 361 | 361 | |
| 362 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 363 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 364 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 362 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
| 363 | + $replace = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : ''; |
|
| 364 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
| 365 | 365 | |
| 366 | 366 | } |
| 367 | 367 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @return bool |
| 375 | 375 | */ |
| 376 | 376 | public function is_available() { |
| 377 | - return ! empty( $this->enabled ); |
|
| 377 | + return !empty($this->enabled); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | * @return string |
| 384 | 384 | */ |
| 385 | 385 | public function get_title() { |
| 386 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 386 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @return string |
| 393 | 393 | */ |
| 394 | 394 | public function get_description() { |
| 395 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 395 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 405 | 405 | * @return void |
| 406 | 406 | */ |
| 407 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 407 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 408 | 408 | // Process the payment then either redirect to the success page or the gateway. |
| 409 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 409 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | * @param string $reason Refund reason. |
| 421 | 421 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
| 422 | 422 | */ |
| 423 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 424 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 423 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
| 424 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | * @param int $invoice_id 0 or invoice id. |
| 431 | 431 | * @param GetPaid_Payment_Form $form Current payment form. |
| 432 | 432 | */ |
| 433 | - public function payment_fields( $invoice_id, $form ) { |
|
| 434 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 433 | + public function payment_fields($invoice_id, $form) { |
|
| 434 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | * |
| 440 | 440 | * @param array $admin_settings |
| 441 | 441 | */ |
| 442 | - public function admin_settings( $admin_settings ) { |
|
| 442 | + public function admin_settings($admin_settings) { |
|
| 443 | 443 | return $admin_settings; |
| 444 | 444 | } |
| 445 | 445 | |
@@ -448,8 +448,8 @@ discard block |
||
| 448 | 448 | * |
| 449 | 449 | * @param string $option |
| 450 | 450 | */ |
| 451 | - public function get_option( $option, $default = false ) { |
|
| 452 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 451 | + public function get_option($option, $default = false) { |
|
| 452 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -462,8 +462,8 @@ discard block |
||
| 462 | 462 | * @return bool True if the gateway supports the feature, false otherwise. |
| 463 | 463 | * @since 1.0.19 |
| 464 | 464 | */ |
| 465 | - public function supports( $feature ) { |
|
| 466 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 465 | + public function supports($feature) { |
|
| 466 | + return apply_filters('getpaid_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -471,36 +471,36 @@ discard block |
||
| 471 | 471 | * |
| 472 | 472 | * @param bool $save whether or not to display the save button. |
| 473 | 473 | */ |
| 474 | - public function get_cc_form( $save = false ) { |
|
| 474 | + public function get_cc_form($save = false) { |
|
| 475 | 475 | |
| 476 | 476 | ob_start(); |
| 477 | 477 | |
| 478 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
| 478 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
| 479 | 479 | |
| 480 | 480 | $months = array( |
| 481 | - '01' => __( 'January', 'invoicing' ), |
|
| 482 | - '02' => __( 'February', 'invoicing' ), |
|
| 483 | - '03' => __( 'March', 'invoicing' ), |
|
| 484 | - '04' => __( 'April', 'invoicing' ), |
|
| 485 | - '05' => __( 'May', 'invoicing' ), |
|
| 486 | - '06' => __( 'June', 'invoicing' ), |
|
| 487 | - '07' => __( 'July', 'invoicing' ), |
|
| 488 | - '08' => __( 'August', 'invoicing' ), |
|
| 489 | - '09' => __( 'September', 'invoicing' ), |
|
| 490 | - '10' => __( 'October', 'invoicing' ), |
|
| 491 | - '11' => __( 'November', 'invoicing' ), |
|
| 492 | - '12' => __( 'December', 'invoicing' ), |
|
| 481 | + '01' => __('January', 'invoicing'), |
|
| 482 | + '02' => __('February', 'invoicing'), |
|
| 483 | + '03' => __('March', 'invoicing'), |
|
| 484 | + '04' => __('April', 'invoicing'), |
|
| 485 | + '05' => __('May', 'invoicing'), |
|
| 486 | + '06' => __('June', 'invoicing'), |
|
| 487 | + '07' => __('July', 'invoicing'), |
|
| 488 | + '08' => __('August', 'invoicing'), |
|
| 489 | + '09' => __('September', 'invoicing'), |
|
| 490 | + '10' => __('October', 'invoicing'), |
|
| 491 | + '11' => __('November', 'invoicing'), |
|
| 492 | + '12' => __('December', 'invoicing'), |
|
| 493 | 493 | ); |
| 494 | 494 | |
| 495 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
| 495 | + $year = (int) date('Y', current_time('timestamp')); |
|
| 496 | 496 | $years = array(); |
| 497 | 497 | |
| 498 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
| 499 | - $years[ $year + $i ] = $year + $i; |
|
| 498 | + for ($i = 0; $i <= 10; $i++) { |
|
| 499 | + $years[$year + $i] = $year + $i; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | ?> |
| 503 | - <div class="<?php echo esc_attr( $this->id );?>-cc-form getpaid-cc-form mt-1"> |
|
| 503 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1"> |
|
| 504 | 504 | |
| 505 | 505 | |
| 506 | 506 | <div class="getpaid-cc-card-inner"> |
@@ -509,14 +509,14 @@ discard block |
||
| 509 | 509 | <div class="col-12"> |
| 510 | 510 | |
| 511 | 511 | <div class="form-group"> |
| 512 | - <label for="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>"><?php _e( 'Card number', 'invoicing' ); ?></label> |
|
| 512 | + <label for="<?php echo esc_attr("$id_prefix-cc-number") ?>"><?php _e('Card number', 'invoicing'); ?></label> |
|
| 513 | 513 | <div class="input-group input-group-sm"> |
| 514 | 514 | <div class="input-group-prepend "> |
| 515 | 515 | <span class="input-group-text"> |
| 516 | 516 | <i class="fa fa-credit-card"></i> |
| 517 | 517 | </span> |
| 518 | 518 | </div> |
| 519 | - <input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ) ?>authorizenet[cc_number]" id="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
| 519 | + <input type="text" name="<?php echo esc_attr($this->id . '[cc_number]') ?>authorizenet[cc_number]" id="<?php echo esc_attr("$id_prefix-cc-number") ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
| 520 | 520 | </div> |
| 521 | 521 | </div> |
| 522 | 522 | |
@@ -524,17 +524,17 @@ discard block |
||
| 524 | 524 | |
| 525 | 525 | <div class="col-12"> |
| 526 | 526 | <div class="form-group"> |
| 527 | - <label><?php _e( 'Expiration', 'invoicing' ); ?></label> |
|
| 527 | + <label><?php _e('Expiration', 'invoicing'); ?></label> |
|
| 528 | 528 | <div class="form-row"> |
| 529 | 529 | |
| 530 | 530 | <div class="col"> |
| 531 | - <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id );?>[cc_expire_month]"> |
|
| 532 | - <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option> |
|
| 531 | + <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
| 532 | + <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option> |
|
| 533 | 533 | |
| 534 | 534 | <?php |
| 535 | - foreach ( $months as $key => $month ) { |
|
| 536 | - $key = esc_attr( $key ); |
|
| 537 | - $month = wpinv_clean( $month ); |
|
| 535 | + foreach ($months as $key => $month) { |
|
| 536 | + $key = esc_attr($key); |
|
| 537 | + $month = wpinv_clean($month); |
|
| 538 | 538 | echo "<option value='$key'>$month</option>" . PHP_EOL; |
| 539 | 539 | } |
| 540 | 540 | ?> |
@@ -543,13 +543,13 @@ discard block |
||
| 543 | 543 | </div> |
| 544 | 544 | |
| 545 | 545 | <div class="col"> |
| 546 | - <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id );?>[cc_expire_year]"> |
|
| 547 | - <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option> |
|
| 546 | + <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
| 547 | + <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option> |
|
| 548 | 548 | |
| 549 | 549 | <?php |
| 550 | - foreach ( $years as $key => $year ) { |
|
| 551 | - $key = esc_attr( $key ); |
|
| 552 | - $year = wpinv_clean( $year ); |
|
| 550 | + foreach ($years as $key => $year) { |
|
| 551 | + $key = esc_attr($key); |
|
| 552 | + $year = wpinv_clean($year); |
|
| 553 | 553 | echo "<option value='$key'>$year</option>" . PHP_EOL; |
| 554 | 554 | } |
| 555 | 555 | ?> |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | array( |
| 568 | 568 | 'name' => $this->id . '[cc_cvv2]', |
| 569 | 569 | 'id' => "$id_prefix-cc-cvv2", |
| 570 | - 'label' => __( 'CCV', 'invoicing' ), |
|
| 570 | + 'label' => __('CCV', 'invoicing'), |
|
| 571 | 571 | 'label_type' => 'vertical', |
| 572 | 572 | 'class' => 'form-control-sm', |
| 573 | 573 | 'extra_attributes' => array( |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | |
| 583 | 583 | <?php |
| 584 | 584 | |
| 585 | - if ( $save ) { |
|
| 585 | + if ($save) { |
|
| 586 | 586 | echo $this->save_payment_method_checkbox(); |
| 587 | 587 | } |
| 588 | 588 | |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | * |
| 602 | 602 | * @since 1.0.19 |
| 603 | 603 | */ |
| 604 | - public function new_payment_method_entry( $form ) { |
|
| 604 | + public function new_payment_method_entry($form) { |
|
| 605 | 605 | echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
| 606 | 606 | } |
| 607 | 607 | |
@@ -611,16 +611,16 @@ discard block |
||
| 611 | 611 | * @since 1.0.19 |
| 612 | 612 | */ |
| 613 | 613 | public function saved_payment_methods() { |
| 614 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 614 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
| 615 | 615 | |
| 616 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 617 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 616 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
| 617 | + $html .= $this->get_saved_payment_method_option_html($token); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | $html .= $this->get_new_payment_method_option_html(); |
| 621 | 621 | $html .= '</ul>'; |
| 622 | 622 | |
| 623 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 623 | + echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | * @param array $token Payment Token. |
| 631 | 631 | * @return string Generated payment method HTML |
| 632 | 632 | */ |
| 633 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 633 | + public function get_saved_payment_method_option_html($token) { |
|
| 634 | 634 | |
| 635 | 635 | return sprintf( |
| 636 | 636 | '<li class="getpaid-payment-method form-group"> |
@@ -639,10 +639,10 @@ discard block |
||
| 639 | 639 | <span>%3$s</span> |
| 640 | 640 | </label> |
| 641 | 641 | </li>', |
| 642 | - esc_attr( $this->id ), |
|
| 643 | - esc_attr( $token['id'] ), |
|
| 644 | - esc_html( $token['name'] ), |
|
| 645 | - checked( empty( $token['default'] ), false, false ) |
|
| 642 | + esc_attr($this->id), |
|
| 643 | + esc_attr($token['id']), |
|
| 644 | + esc_html($token['name']), |
|
| 645 | + checked(empty($token['default']), false, false) |
|
| 646 | 646 | ); |
| 647 | 647 | |
| 648 | 648 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | */ |
| 655 | 655 | public function get_new_payment_method_option_html() { |
| 656 | 656 | |
| 657 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 657 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
| 658 | 658 | |
| 659 | 659 | return sprintf( |
| 660 | 660 | '<li class="getpaid-new-payment-method"> |
@@ -663,8 +663,8 @@ discard block |
||
| 663 | 663 | <span>%2$s</span> |
| 664 | 664 | </label> |
| 665 | 665 | </li>', |
| 666 | - esc_attr( $this->id ), |
|
| 667 | - esc_html( $label ) |
|
| 666 | + esc_attr($this->id), |
|
| 667 | + esc_html($label) |
|
| 668 | 668 | ); |
| 669 | 669 | |
| 670 | 670 | } |
@@ -679,10 +679,10 @@ discard block |
||
| 679 | 679 | return aui()->input( |
| 680 | 680 | array( |
| 681 | 681 | 'type' => 'checkbox', |
| 682 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 683 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 682 | + 'name' => esc_attr("getpaid-$this->id-new-payment-method"), |
|
| 683 | + 'id' => esc_attr(uniqid($this->id)), |
|
| 684 | 684 | 'required' => false, |
| 685 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 685 | + 'label' => esc_html__('Save payment method', 'invoicing'), |
|
| 686 | 686 | 'value' => 'true', |
| 687 | 687 | 'checked' => true, |
| 688 | 688 | 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
@@ -696,9 +696,9 @@ discard block |
||
| 696 | 696 | * |
| 697 | 697 | * @return array |
| 698 | 698 | */ |
| 699 | - public function register_gateway( $gateways ) { |
|
| 699 | + public function register_gateway($gateways) { |
|
| 700 | 700 | |
| 701 | - $gateways[ $this->id ] = array( |
|
| 701 | + $gateways[$this->id] = array( |
|
| 702 | 702 | |
| 703 | 703 | 'admin_label' => $this->method_title, |
| 704 | 704 | 'checkout_label' => $this->title, |
@@ -716,13 +716,13 @@ discard block |
||
| 716 | 716 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
| 717 | 717 | * @return bool |
| 718 | 718 | */ |
| 719 | - public function is_sandbox( $invoice = null ) { |
|
| 719 | + public function is_sandbox($invoice = null) { |
|
| 720 | 720 | |
| 721 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 721 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
| 722 | 722 | return $invoice->get_mode() == 'test'; |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | - return wpinv_is_test_mode( $this->id ); |
|
| 725 | + return wpinv_is_test_mode($this->id); |
|
| 726 | 726 | |
| 727 | 727 | } |
| 728 | 728 | |
@@ -740,15 +740,15 @@ discard block |
||
| 740 | 740 | * |
| 741 | 741 | * @return bool |
| 742 | 742 | */ |
| 743 | - public function validate_currency( $validation, $currency ) { |
|
| 743 | + public function validate_currency($validation, $currency) { |
|
| 744 | 744 | |
| 745 | 745 | // Required currencies. |
| 746 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 746 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
| 747 | 747 | return false; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | // Excluded currencies. |
| 751 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 751 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
| 752 | 752 | return false; |
| 753 | 753 | } |
| 754 | 754 | |
@@ -759,13 +759,13 @@ discard block |
||
| 759 | 759 | * Displays an error |
| 760 | 760 | * |
| 761 | 761 | */ |
| 762 | - public function show_error( $code, $message, $type ) { |
|
| 762 | + public function show_error($code, $message, $type) { |
|
| 763 | 763 | |
| 764 | - if ( is_admin() ) { |
|
| 765 | - getpaid_admin()->{"show_$type"}( $message ); |
|
| 764 | + if (is_admin()) { |
|
| 765 | + getpaid_admin()->{"show_$type"}($message); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | - wpinv_set_error( $code, $message, $type ); |
|
| 768 | + wpinv_set_error($code, $message, $type); |
|
| 769 | 769 | |
| 770 | 770 | } |
| 771 | 771 | |
@@ -14,144 +14,144 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Register the widget with WordPress. |
|
| 19 | - * |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - |
|
| 23 | - $options = array( |
|
| 24 | - 'textdomain' => 'invoicing', |
|
| 25 | - 'block-icon' => 'controls-repeat', |
|
| 26 | - 'block-category'=> 'widgets', |
|
| 27 | - 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | - 'class_name' => __CLASS__, |
|
| 29 | - 'base_id' => 'wpinv_subscriptions', |
|
| 30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | - 'widget_ops' => array( |
|
| 32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | - ), |
|
| 35 | - 'arguments' => array( |
|
| 36 | - 'title' => array( |
|
| 37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | - 'type' => 'text', |
|
| 40 | - 'desc_tip' => true, |
|
| 41 | - 'default' => '', |
|
| 42 | - 'advanced' => false |
|
| 43 | - ), |
|
| 44 | - ) |
|
| 45 | - |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - parent::__construct( $options ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Retrieves current user's subscriptions. |
|
| 54 | - * |
|
| 55 | - * @return GetPaid_Subscriptions_Query |
|
| 56 | - */ |
|
| 57 | - public function get_subscriptions() { |
|
| 58 | - |
|
| 59 | - // Prepare license args. |
|
| 60 | - $args = array( |
|
| 61 | - 'customer_in' => get_current_user_id(), |
|
| 62 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - return new GetPaid_Subscriptions_Query( $args ); |
|
| 66 | - |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The Super block output function. |
|
| 71 | - * |
|
| 72 | - * @param array $args |
|
| 73 | - * @param array $widget_args |
|
| 74 | - * @param string $content |
|
| 75 | - * |
|
| 76 | - * @return mixed|string|bool |
|
| 77 | - */ |
|
| 78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 79 | - |
|
| 80 | - // Ensure that the user is logged in. |
|
| 81 | - if ( ! is_user_logged_in() ) { |
|
| 82 | - |
|
| 83 | - return aui()->alert( |
|
| 84 | - array( |
|
| 85 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 86 | - 'type' => 'error', |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Are we displaying a single subscription? |
|
| 93 | - if ( isset( $_GET['subscription'] ) ) { |
|
| 94 | - return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // Retrieve the user's subscriptions. |
|
| 98 | - $subscriptions = $this->get_subscriptions(); |
|
| 99 | - |
|
| 100 | - // Start the output buffer. |
|
| 101 | - ob_start(); |
|
| 102 | - |
|
| 103 | - // Backwards compatibility. |
|
| 104 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 105 | - |
|
| 106 | - // Display errors and notices. |
|
| 107 | - wpinv_print_errors(); |
|
| 108 | - |
|
| 109 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 110 | - |
|
| 111 | - // Print the table header. |
|
| 112 | - $this->print_table_header(); |
|
| 113 | - |
|
| 114 | - // Print table body. |
|
| 115 | - $this->print_table_body( $subscriptions->get_results() ); |
|
| 116 | - |
|
| 117 | - // Print table footer. |
|
| 118 | - $this->print_table_footer(); |
|
| 119 | - |
|
| 120 | - // Print the navigation. |
|
| 121 | - $this->print_navigation( $subscriptions->get_total() ); |
|
| 122 | - |
|
| 123 | - // Backwards compatibility. |
|
| 124 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 125 | - |
|
| 126 | - // Return the output. |
|
| 127 | - return ob_get_clean(); |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Retrieves the subscription columns. |
|
| 133 | - * |
|
| 134 | - * @return array |
|
| 135 | - */ |
|
| 136 | - public function get_subscriptions_table_columns() { |
|
| 17 | + /** |
|
| 18 | + * Register the widget with WordPress. |
|
| 19 | + * |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + |
|
| 23 | + $options = array( |
|
| 24 | + 'textdomain' => 'invoicing', |
|
| 25 | + 'block-icon' => 'controls-repeat', |
|
| 26 | + 'block-category'=> 'widgets', |
|
| 27 | + 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | + 'class_name' => __CLASS__, |
|
| 29 | + 'base_id' => 'wpinv_subscriptions', |
|
| 30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | + 'widget_ops' => array( |
|
| 32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | + ), |
|
| 35 | + 'arguments' => array( |
|
| 36 | + 'title' => array( |
|
| 37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | + 'type' => 'text', |
|
| 40 | + 'desc_tip' => true, |
|
| 41 | + 'default' => '', |
|
| 42 | + 'advanced' => false |
|
| 43 | + ), |
|
| 44 | + ) |
|
| 45 | + |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + parent::__construct( $options ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Retrieves current user's subscriptions. |
|
| 54 | + * |
|
| 55 | + * @return GetPaid_Subscriptions_Query |
|
| 56 | + */ |
|
| 57 | + public function get_subscriptions() { |
|
| 58 | + |
|
| 59 | + // Prepare license args. |
|
| 60 | + $args = array( |
|
| 61 | + 'customer_in' => get_current_user_id(), |
|
| 62 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + return new GetPaid_Subscriptions_Query( $args ); |
|
| 66 | + |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The Super block output function. |
|
| 71 | + * |
|
| 72 | + * @param array $args |
|
| 73 | + * @param array $widget_args |
|
| 74 | + * @param string $content |
|
| 75 | + * |
|
| 76 | + * @return mixed|string|bool |
|
| 77 | + */ |
|
| 78 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 79 | + |
|
| 80 | + // Ensure that the user is logged in. |
|
| 81 | + if ( ! is_user_logged_in() ) { |
|
| 82 | + |
|
| 83 | + return aui()->alert( |
|
| 84 | + array( |
|
| 85 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 86 | + 'type' => 'error', |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Are we displaying a single subscription? |
|
| 93 | + if ( isset( $_GET['subscription'] ) ) { |
|
| 94 | + return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // Retrieve the user's subscriptions. |
|
| 98 | + $subscriptions = $this->get_subscriptions(); |
|
| 99 | + |
|
| 100 | + // Start the output buffer. |
|
| 101 | + ob_start(); |
|
| 102 | + |
|
| 103 | + // Backwards compatibility. |
|
| 104 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
| 105 | + |
|
| 106 | + // Display errors and notices. |
|
| 107 | + wpinv_print_errors(); |
|
| 108 | + |
|
| 109 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 110 | + |
|
| 111 | + // Print the table header. |
|
| 112 | + $this->print_table_header(); |
|
| 113 | + |
|
| 114 | + // Print table body. |
|
| 115 | + $this->print_table_body( $subscriptions->get_results() ); |
|
| 116 | + |
|
| 117 | + // Print table footer. |
|
| 118 | + $this->print_table_footer(); |
|
| 119 | + |
|
| 120 | + // Print the navigation. |
|
| 121 | + $this->print_navigation( $subscriptions->get_total() ); |
|
| 122 | + |
|
| 123 | + // Backwards compatibility. |
|
| 124 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
| 125 | + |
|
| 126 | + // Return the output. |
|
| 127 | + return ob_get_clean(); |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Retrieves the subscription columns. |
|
| 133 | + * |
|
| 134 | + * @return array |
|
| 135 | + */ |
|
| 136 | + public function get_subscriptions_table_columns() { |
|
| 137 | 137 | |
| 138 | - $columns = array( |
|
| 139 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 140 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 141 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 142 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 143 | - ); |
|
| 138 | + $columns = array( |
|
| 139 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 140 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 141 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 142 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 143 | + ); |
|
| 144 | 144 | |
| 145 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 146 | - } |
|
| 145 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Displays the table header. |
|
| 150 | - * |
|
| 151 | - */ |
|
| 152 | - public function print_table_header() { |
|
| 148 | + /** |
|
| 149 | + * Displays the table header. |
|
| 150 | + * |
|
| 151 | + */ |
|
| 152 | + public function print_table_header() { |
|
| 153 | 153 | |
| 154 | - ?> |
|
| 154 | + ?> |
|
| 155 | 155 | |
| 156 | 156 | <table class="table table-bordered table-striped"> |
| 157 | 157 | |
@@ -167,121 +167,121 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | <?php |
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Displays the table body. |
|
| 174 | - * |
|
| 175 | - * @param WPInv_Subscription[] $subscriptions |
|
| 176 | - */ |
|
| 177 | - public function print_table_body( $subscriptions ) { |
|
| 172 | + /** |
|
| 173 | + * Displays the table body. |
|
| 174 | + * |
|
| 175 | + * @param WPInv_Subscription[] $subscriptions |
|
| 176 | + */ |
|
| 177 | + public function print_table_body( $subscriptions ) { |
|
| 178 | 178 | |
| 179 | - if ( empty( $subscriptions ) ) { |
|
| 180 | - $this->print_table_body_no_subscriptions(); |
|
| 181 | - } else { |
|
| 182 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
| 183 | - } |
|
| 179 | + if ( empty( $subscriptions ) ) { |
|
| 180 | + $this->print_table_body_no_subscriptions(); |
|
| 181 | + } else { |
|
| 182 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Displays the table body if no subscriptions were found. |
|
| 189 | - * |
|
| 190 | - */ |
|
| 191 | - public function print_table_body_no_subscriptions() { |
|
| 187 | + /** |
|
| 188 | + * Displays the table body if no subscriptions were found. |
|
| 189 | + * |
|
| 190 | + */ |
|
| 191 | + public function print_table_body_no_subscriptions() { |
|
| 192 | 192 | |
| 193 | - ?> |
|
| 193 | + ?> |
|
| 194 | 194 | <tbody> |
| 195 | 195 | |
| 196 | 196 | <tr> |
| 197 | 197 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
| 198 | 198 | |
| 199 | 199 | <?php |
| 200 | - echo aui()->alert( |
|
| 201 | - array( |
|
| 202 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 203 | - 'type' => 'warning', |
|
| 204 | - ) |
|
| 205 | - ); |
|
| 206 | - ?> |
|
| 200 | + echo aui()->alert( |
|
| 201 | + array( |
|
| 202 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 203 | + 'type' => 'warning', |
|
| 204 | + ) |
|
| 205 | + ); |
|
| 206 | + ?> |
|
| 207 | 207 | |
| 208 | 208 | </td> |
| 209 | 209 | </tr> |
| 210 | 210 | |
| 211 | 211 | </tbody> |
| 212 | 212 | <?php |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Displays the table body if subscriptions were found. |
|
| 217 | - * |
|
| 218 | - * @param WPInv_Subscription[] $subscriptions |
|
| 219 | - */ |
|
| 220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
| 215 | + /** |
|
| 216 | + * Displays the table body if subscriptions were found. |
|
| 217 | + * |
|
| 218 | + * @param WPInv_Subscription[] $subscriptions |
|
| 219 | + */ |
|
| 220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
| 221 | 221 | |
| 222 | - ?> |
|
| 222 | + ?> |
|
| 223 | 223 | <tbody> |
| 224 | 224 | |
| 225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
| 226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
| 227 | 227 | <?php |
| 228 | - wpinv_get_template( |
|
| 229 | - 'subscriptions/subscriptions-table-row.php', |
|
| 230 | - array( |
|
| 231 | - 'subscription' => $subscription, |
|
| 232 | - 'widget' => $this |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - ?> |
|
| 228 | + wpinv_get_template( |
|
| 229 | + 'subscriptions/subscriptions-table-row.php', |
|
| 230 | + array( |
|
| 231 | + 'subscription' => $subscription, |
|
| 232 | + 'widget' => $this |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + ?> |
|
| 236 | 236 | </tr> |
| 237 | 237 | <?php endforeach; ?> |
| 238 | 238 | |
| 239 | 239 | </tbody> |
| 240 | 240 | <?php |
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Adds row actions to a column |
|
| 245 | - * |
|
| 246 | - * @param string $content column content |
|
| 247 | - * @param WPInv_Subscription $subscription |
|
| 248 | - * @since 1.0.0 |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function add_row_actions( $content, $subscription ) { |
|
| 252 | - |
|
| 253 | - // Prepare row actions. |
|
| 254 | - $actions = array(); |
|
| 255 | - |
|
| 256 | - // View subscription action. |
|
| 257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | - |
|
| 261 | - // Filter the actions. |
|
| 262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | - |
|
| 264 | - $sanitized = array(); |
|
| 265 | - foreach ( $actions as $key => $action ) { |
|
| 266 | - $key = sanitize_html_class( $key ); |
|
| 267 | - $action = wp_kses_post( $action ); |
|
| 268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | - $row_actions .= '</small>'; |
|
| 274 | - |
|
| 275 | - return $content . $row_actions; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Displays the table footer. |
|
| 280 | - * |
|
| 281 | - */ |
|
| 282 | - public function print_table_footer() { |
|
| 283 | - |
|
| 284 | - ?> |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Adds row actions to a column |
|
| 245 | + * |
|
| 246 | + * @param string $content column content |
|
| 247 | + * @param WPInv_Subscription $subscription |
|
| 248 | + * @since 1.0.0 |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function add_row_actions( $content, $subscription ) { |
|
| 252 | + |
|
| 253 | + // Prepare row actions. |
|
| 254 | + $actions = array(); |
|
| 255 | + |
|
| 256 | + // View subscription action. |
|
| 257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | + |
|
| 261 | + // Filter the actions. |
|
| 262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | + |
|
| 264 | + $sanitized = array(); |
|
| 265 | + foreach ( $actions as $key => $action ) { |
|
| 266 | + $key = sanitize_html_class( $key ); |
|
| 267 | + $action = wp_kses_post( $action ); |
|
| 268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | + $row_actions .= '</small>'; |
|
| 274 | + |
|
| 275 | + return $content . $row_actions; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Displays the table footer. |
|
| 280 | + * |
|
| 281 | + */ |
|
| 282 | + public function print_table_footer() { |
|
| 283 | + |
|
| 284 | + ?> |
|
| 285 | 285 | |
| 286 | 286 | <tfoot> |
| 287 | 287 | <tr> |
@@ -296,129 +296,129 @@ discard block |
||
| 296 | 296 | </table> |
| 297 | 297 | <?php |
| 298 | 298 | |
| 299 | - } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Displays the navigation. |
|
| 303 | - * |
|
| 304 | - * @param int $total |
|
| 305 | - */ |
|
| 306 | - public function print_navigation( $total ) { |
|
| 301 | + /** |
|
| 302 | + * Displays the navigation. |
|
| 303 | + * |
|
| 304 | + * @param int $total |
|
| 305 | + */ |
|
| 306 | + public function print_navigation( $total ) { |
|
| 307 | 307 | |
| 308 | - if ( $total < 1 ) { |
|
| 308 | + if ( $total < 1 ) { |
|
| 309 | 309 | |
| 310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | - $args = array( |
|
| 312 | - 'customer_in' => get_current_user_id(), |
|
| 313 | - 'fields' => 'id', |
|
| 314 | - ); |
|
| 310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | + $args = array( |
|
| 312 | + 'customer_in' => get_current_user_id(), |
|
| 313 | + 'fields' => 'id', |
|
| 314 | + ); |
|
| 315 | 315 | |
| 316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | - $total = $count_query->get_total(); |
|
| 318 | - } |
|
| 316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | + $total = $count_query->get_total(); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Abort if we do not have pages. |
|
| 321 | - if ( 2 > $total ) { |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // Abort if we do not have pages. |
|
| 321 | + if ( 2 > $total ) { |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - ?> |
|
| 325 | + ?> |
|
| 326 | 326 | |
| 327 | 327 | <div class="getpaid-subscriptions-pagination"> |
| 328 | 328 | <?php |
| 329 | - $big = 999999; |
|
| 330 | - |
|
| 331 | - echo getpaid_paginate_links( |
|
| 332 | - array( |
|
| 333 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 334 | - 'format' => '?paged=%#%', |
|
| 335 | - 'total' => (int) ceil( $total / 10 ), |
|
| 336 | - ) |
|
| 337 | - ); |
|
| 338 | - ?> |
|
| 329 | + $big = 999999; |
|
| 330 | + |
|
| 331 | + echo getpaid_paginate_links( |
|
| 332 | + array( |
|
| 333 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 334 | + 'format' => '?paged=%#%', |
|
| 335 | + 'total' => (int) ceil( $total / 10 ), |
|
| 336 | + ) |
|
| 337 | + ); |
|
| 338 | + ?> |
|
| 339 | 339 | </div> |
| 340 | 340 | |
| 341 | 341 | <?php |
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Returns a single subscription's columns. |
|
| 346 | - * |
|
| 347 | - * @param WPInv_Subscription $subscription |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - */ |
|
| 351 | - public function get_single_subscription_columns( $subscription ) { |
|
| 352 | - |
|
| 353 | - // Prepare subscription detail columns. |
|
| 354 | - $fields = apply_filters( |
|
| 355 | - 'getpaid_single_subscription_details_fields', |
|
| 356 | - array( |
|
| 357 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 358 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 359 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 360 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 361 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 362 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
| 363 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 364 | - ), |
|
| 365 | - $subscription |
|
| 366 | - ); |
|
| 367 | - |
|
| 368 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 369 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
| 373 | - unset( $fields['initial_amount'] ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - return $fields; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Displays a single subscription. |
|
| 381 | - * |
|
| 382 | - * @param string $subscription |
|
| 383 | - * |
|
| 384 | - * @return string |
|
| 385 | - */ |
|
| 386 | - public function display_single_subscription( $subscription ) { |
|
| 387 | - |
|
| 388 | - // Fetch the subscription. |
|
| 389 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 390 | - |
|
| 391 | - if ( ! $subscription->get_id() ) { |
|
| 392 | - |
|
| 393 | - return aui()->alert( |
|
| 394 | - array( |
|
| 395 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 396 | - 'type' => 'error', |
|
| 397 | - ) |
|
| 398 | - ); |
|
| 399 | - |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - // Ensure that the user owns this subscription key. |
|
| 403 | - if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) { |
|
| 404 | - |
|
| 405 | - return aui()->alert( |
|
| 406 | - array( |
|
| 407 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 408 | - 'type' => 'error', |
|
| 409 | - ) |
|
| 410 | - ); |
|
| 411 | - |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - return wpinv_get_template_html( |
|
| 415 | - 'subscriptions/subscription-details.php', |
|
| 416 | - array( |
|
| 417 | - 'subscription' => $subscription, |
|
| 418 | - 'widget' => $this |
|
| 419 | - ) |
|
| 420 | - ); |
|
| 421 | - |
|
| 422 | - } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Returns a single subscription's columns. |
|
| 346 | + * |
|
| 347 | + * @param WPInv_Subscription $subscription |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + */ |
|
| 351 | + public function get_single_subscription_columns( $subscription ) { |
|
| 352 | + |
|
| 353 | + // Prepare subscription detail columns. |
|
| 354 | + $fields = apply_filters( |
|
| 355 | + 'getpaid_single_subscription_details_fields', |
|
| 356 | + array( |
|
| 357 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 358 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 359 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 360 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 361 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 362 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
| 363 | + 'item' => __( 'Item', 'invoicing' ), |
|
| 364 | + ), |
|
| 365 | + $subscription |
|
| 366 | + ); |
|
| 367 | + |
|
| 368 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 369 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
| 373 | + unset( $fields['initial_amount'] ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + return $fields; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Displays a single subscription. |
|
| 381 | + * |
|
| 382 | + * @param string $subscription |
|
| 383 | + * |
|
| 384 | + * @return string |
|
| 385 | + */ |
|
| 386 | + public function display_single_subscription( $subscription ) { |
|
| 387 | + |
|
| 388 | + // Fetch the subscription. |
|
| 389 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 390 | + |
|
| 391 | + if ( ! $subscription->get_id() ) { |
|
| 392 | + |
|
| 393 | + return aui()->alert( |
|
| 394 | + array( |
|
| 395 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 396 | + 'type' => 'error', |
|
| 397 | + ) |
|
| 398 | + ); |
|
| 399 | + |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + // Ensure that the user owns this subscription key. |
|
| 403 | + if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) { |
|
| 404 | + |
|
| 405 | + return aui()->alert( |
|
| 406 | + array( |
|
| 407 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 408 | + 'type' => 'error', |
|
| 409 | + ) |
|
| 410 | + ); |
|
| 411 | + |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + return wpinv_get_template_html( |
|
| 415 | + 'subscriptions/subscription-details.php', |
|
| 416 | + array( |
|
| 417 | + 'subscription' => $subscription, |
|
| 418 | + 'widget' => $this |
|
| 419 | + ) |
|
| 420 | + ); |
|
| 421 | + |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | 424 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * @version 1.0.0 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
| 28 | 28 | 'class_name' => __CLASS__, |
| 29 | 29 | 'base_id' => 'wpinv_subscriptions', |
| 30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
| 31 | 31 | 'widget_ops' => array( |
| 32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
| 33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
| 34 | 34 | ), |
| 35 | 35 | 'arguments' => array( |
| 36 | 36 | 'title' => array( |
| 37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 37 | + 'title' => __('Widget title', 'invoicing'), |
|
| 38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
| 39 | 39 | 'type' => 'text', |
| 40 | 40 | 'desc_tip' => true, |
| 41 | 41 | 'default' => '', |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | |
| 49 | - parent::__construct( $options ); |
|
| 49 | + parent::__construct($options); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | public function get_subscriptions() { |
| 58 | 58 | |
| 59 | 59 | // Prepare license args. |
| 60 | - $args = array( |
|
| 60 | + $args = array( |
|
| 61 | 61 | 'customer_in' => get_current_user_id(), |
| 62 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | - return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | + return new GetPaid_Subscriptions_Query($args); |
|
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return mixed|string|bool |
| 77 | 77 | */ |
| 78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 79 | 79 | |
| 80 | 80 | // Ensure that the user is logged in. |
| 81 | - if ( ! is_user_logged_in() ) { |
|
| 81 | + if (!is_user_logged_in()) { |
|
| 82 | 82 | |
| 83 | 83 | return aui()->alert( |
| 84 | 84 | array( |
| 85 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
| 86 | 86 | 'type' => 'error', |
| 87 | 87 | ) |
| 88 | 88 | ); |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Are we displaying a single subscription? |
| 93 | - if ( isset( $_GET['subscription'] ) ) { |
|
| 94 | - return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
| 93 | + if (isset($_GET['subscription'])) { |
|
| 94 | + return $this->display_single_subscription(trim($_GET['subscription'])); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // Retrieve the user's subscriptions. |
@@ -101,27 +101,27 @@ discard block |
||
| 101 | 101 | ob_start(); |
| 102 | 102 | |
| 103 | 103 | // Backwards compatibility. |
| 104 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | + do_action('wpinv_before_user_subscriptions'); |
|
| 105 | 105 | |
| 106 | 106 | // Display errors and notices. |
| 107 | 107 | wpinv_print_errors(); |
| 108 | 108 | |
| 109 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
| 110 | 110 | |
| 111 | 111 | // Print the table header. |
| 112 | 112 | $this->print_table_header(); |
| 113 | 113 | |
| 114 | 114 | // Print table body. |
| 115 | - $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | + $this->print_table_body($subscriptions->get_results()); |
|
| 116 | 116 | |
| 117 | 117 | // Print table footer. |
| 118 | 118 | $this->print_table_footer(); |
| 119 | 119 | |
| 120 | 120 | // Print the navigation. |
| 121 | - $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | + $this->print_navigation($subscriptions->get_total()); |
|
| 122 | 122 | |
| 123 | 123 | // Backwards compatibility. |
| 124 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | + do_action('wpinv_after_user_subscriptions'); |
|
| 125 | 125 | |
| 126 | 126 | // Return the output. |
| 127 | 127 | return ob_get_clean(); |
@@ -136,13 +136,13 @@ discard block |
||
| 136 | 136 | public function get_subscriptions_table_columns() { |
| 137 | 137 | |
| 138 | 138 | $columns = array( |
| 139 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 140 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 141 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 142 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 139 | + 'subscription' => __('Subscription', 'invoicing'), |
|
| 140 | + 'amount' => __('Amount', 'invoicing'), |
|
| 141 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
| 142 | + 'status' => __('Status', 'invoicing'), |
|
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | <thead> |
| 159 | 159 | <tr> |
| 160 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
| 161 | - <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>"> |
|
| 162 | - <?php echo sanitize_text_field( $label ); ?> |
|
| 160 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
| 161 | + <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>"> |
|
| 162 | + <?php echo sanitize_text_field($label); ?> |
|
| 163 | 163 | </th> |
| 164 | 164 | <?php endforeach; ?> |
| 165 | 165 | </tr> |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @param WPInv_Subscription[] $subscriptions |
| 176 | 176 | */ |
| 177 | - public function print_table_body( $subscriptions ) { |
|
| 177 | + public function print_table_body($subscriptions) { |
|
| 178 | 178 | |
| 179 | - if ( empty( $subscriptions ) ) { |
|
| 179 | + if (empty($subscriptions)) { |
|
| 180 | 180 | $this->print_table_body_no_subscriptions(); |
| 181 | 181 | } else { |
| 182 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | + $this->print_table_body_subscriptions($subscriptions); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | } |
@@ -194,12 +194,12 @@ discard block |
||
| 194 | 194 | <tbody> |
| 195 | 195 | |
| 196 | 196 | <tr> |
| 197 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
| 197 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
| 198 | 198 | |
| 199 | 199 | <?php |
| 200 | 200 | echo aui()->alert( |
| 201 | 201 | array( |
| 202 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
| 203 | 203 | 'type' => 'warning', |
| 204 | 204 | ) |
| 205 | 205 | ); |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @param WPInv_Subscription[] $subscriptions |
| 219 | 219 | */ |
| 220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
| 220 | + public function print_table_body_subscriptions($subscriptions) { |
|
| 221 | 221 | |
| 222 | 222 | ?> |
| 223 | 223 | <tbody> |
| 224 | 224 | |
| 225 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
| 225 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
| 226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
| 227 | 227 | <?php |
| 228 | 228 | wpinv_get_template( |
@@ -248,28 +248,28 @@ discard block |
||
| 248 | 248 | * @since 1.0.0 |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | - public function add_row_actions( $content, $subscription ) { |
|
| 251 | + public function add_row_actions($content, $subscription) { |
|
| 252 | 252 | |
| 253 | 253 | // Prepare row actions. |
| 254 | 254 | $actions = array(); |
| 255 | 255 | |
| 256 | 256 | // View subscription action. |
| 257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 257 | + $view_url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
| 258 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url)); |
|
| 259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
| 260 | 260 | |
| 261 | 261 | // Filter the actions. |
| 262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 262 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
| 263 | 263 | |
| 264 | - $sanitized = array(); |
|
| 265 | - foreach ( $actions as $key => $action ) { |
|
| 266 | - $key = sanitize_html_class( $key ); |
|
| 267 | - $action = wp_kses_post( $action ); |
|
| 264 | + $sanitized = array(); |
|
| 265 | + foreach ($actions as $key => $action) { |
|
| 266 | + $key = sanitize_html_class($key); |
|
| 267 | + $action = wp_kses_post($action); |
|
| 268 | 268 | $sanitized[] = "<span class='$key'>$action</span>"; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
| 272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
| 272 | + $row_actions .= implode(' | ', $sanitized); |
|
| 273 | 273 | $row_actions .= '</small>'; |
| 274 | 274 | |
| 275 | 275 | return $content . $row_actions; |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | |
| 286 | 286 | <tfoot> |
| 287 | 287 | <tr> |
| 288 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
| 289 | - <th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>"> |
|
| 290 | - <?php echo sanitize_text_field( $label ); ?> |
|
| 288 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
| 289 | + <th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>"> |
|
| 290 | + <?php echo sanitize_text_field($label); ?> |
|
| 291 | 291 | </th> |
| 292 | 292 | <?php endforeach; ?> |
| 293 | 293 | </tr> |
@@ -303,22 +303,22 @@ discard block |
||
| 303 | 303 | * |
| 304 | 304 | * @param int $total |
| 305 | 305 | */ |
| 306 | - public function print_navigation( $total ) { |
|
| 306 | + public function print_navigation($total) { |
|
| 307 | 307 | |
| 308 | - if ( $total < 1 ) { |
|
| 308 | + if ($total < 1) { |
|
| 309 | 309 | |
| 310 | 310 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 311 | - $args = array( |
|
| 311 | + $args = array( |
|
| 312 | 312 | 'customer_in' => get_current_user_id(), |
| 313 | 313 | 'fields' => 'id', |
| 314 | 314 | ); |
| 315 | 315 | |
| 316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 316 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
| 317 | 317 | $total = $count_query->get_total(); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // Abort if we do not have pages. |
| 321 | - if ( 2 > $total ) { |
|
| 321 | + if (2 > $total) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | |
| 331 | 331 | echo getpaid_paginate_links( |
| 332 | 332 | array( |
| 333 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 333 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 334 | 334 | 'format' => '?paged=%#%', |
| 335 | - 'total' => (int) ceil( $total / 10 ), |
|
| 335 | + 'total' => (int) ceil($total / 10), |
|
| 336 | 336 | ) |
| 337 | 337 | ); |
| 338 | 338 | ?> |
@@ -348,29 +348,29 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | * @return array |
| 350 | 350 | */ |
| 351 | - public function get_single_subscription_columns( $subscription ) { |
|
| 351 | + public function get_single_subscription_columns($subscription) { |
|
| 352 | 352 | |
| 353 | 353 | // Prepare subscription detail columns. |
| 354 | 354 | $fields = apply_filters( |
| 355 | 355 | 'getpaid_single_subscription_details_fields', |
| 356 | 356 | array( |
| 357 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 358 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 359 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 360 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 361 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 362 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
| 363 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 357 | + 'status' => __('Status', 'invoicing'), |
|
| 358 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
| 359 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
| 360 | + 'start_date' => __('Start date', 'invoicing'), |
|
| 361 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
| 362 | + 'payments' => __('Payments', 'invoicing'), |
|
| 363 | + 'item' => __('Item', 'invoicing'), |
|
| 364 | 364 | ), |
| 365 | 365 | $subscription |
| 366 | 366 | ); |
| 367 | 367 | |
| 368 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 369 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 368 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
| 369 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
| 373 | - unset( $fields['initial_amount'] ); |
|
| 372 | + if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) { |
|
| 373 | + unset($fields['initial_amount']); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | return $fields; |
@@ -383,16 +383,16 @@ discard block |
||
| 383 | 383 | * |
| 384 | 384 | * @return string |
| 385 | 385 | */ |
| 386 | - public function display_single_subscription( $subscription ) { |
|
| 386 | + public function display_single_subscription($subscription) { |
|
| 387 | 387 | |
| 388 | 388 | // Fetch the subscription. |
| 389 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 389 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
| 390 | 390 | |
| 391 | - if ( ! $subscription->get_id() ) { |
|
| 391 | + if (!$subscription->get_id()) { |
|
| 392 | 392 | |
| 393 | 393 | return aui()->alert( |
| 394 | 394 | array( |
| 395 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 395 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
| 396 | 396 | 'type' => 'error', |
| 397 | 397 | ) |
| 398 | 398 | ); |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | // Ensure that the user owns this subscription key. |
| 403 | - if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) { |
|
| 403 | + if (get_current_user_id() != $subscription->get_customer_id() && current_user_can('edit_options')) { |
|
| 404 | 404 | |
| 405 | 405 | return aui()->alert( |
| 406 | 406 | array( |
| 407 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 407 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
| 408 | 408 | 'type' => 'error', |
| 409 | 409 | ) |
| 410 | 410 | ); |
@@ -411,9 +411,9 @@ |
||
| 411 | 411 | $bill_times = $item->get_recurring_limit(); |
| 412 | 412 | |
| 413 | 413 | if ( ! empty( $bill_times ) ) { |
| 414 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 415 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 416 | - } |
|
| 414 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 415 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | 418 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
| 419 | 419 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | * @param int the item ID to retrieve. |
| 15 | 15 | * @return WPInv_Item|false |
| 16 | 16 | */ |
| 17 | -function wpinv_get_item_by_id( $id ) { |
|
| 18 | - $item = wpinv_get_item( $id ); |
|
| 19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
| 17 | +function wpinv_get_item_by_id($id) { |
|
| 18 | + $item = wpinv_get_item($id); |
|
| 19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return WPInv_Item|false |
| 26 | 26 | */ |
| 27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
| 27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
| 28 | 28 | |
| 29 | - if ( 'id' == strtolower( $field ) ) { |
|
| 30 | - return wpinv_get_item_by_id( $field ); |
|
| 29 | + if ('id' == strtolower($field)) { |
|
| 30 | + return wpinv_get_item_by_id($field); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
| 34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
| 33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
| 34 | + return empty($id) ? false : wpinv_get_item($id); |
|
| 35 | 35 | |
| 36 | 36 | } |
| 37 | 37 | |
@@ -41,22 +41,22 @@ discard block |
||
| 41 | 41 | * @param int|WPInv_Item the item to retrieve. |
| 42 | 42 | * @return WPInv_Item|false |
| 43 | 43 | */ |
| 44 | -function wpinv_get_item( $item = 0 ) { |
|
| 44 | +function wpinv_get_item($item = 0) { |
|
| 45 | 45 | |
| 46 | - if ( empty( $item ) ) { |
|
| 46 | + if (empty($item)) { |
|
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $item = new WPInv_Item( $item ); |
|
| 50 | + $item = new WPInv_Item($item); |
|
| 51 | 51 | return $item->exists() ? $item : false; |
| 52 | 52 | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | -function wpinv_get_all_items( $args = array() ) { |
|
| 55 | +function wpinv_get_all_items($args = array()) { |
|
| 56 | 56 | |
| 57 | - $args = wp_parse_args( $args, array( |
|
| 58 | - 'status' => array( 'publish' ), |
|
| 59 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 57 | + $args = wp_parse_args($args, array( |
|
| 58 | + 'status' => array('publish'), |
|
| 59 | + 'limit' => get_option('posts_per_page'), |
|
| 60 | 60 | 'page' => 1, |
| 61 | 61 | 'exclude' => array(), |
| 62 | 62 | 'orderby' => 'date', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | 'meta_query' => array(), |
| 66 | 66 | 'return' => 'objects', |
| 67 | 67 | 'paginate' => false, |
| 68 | - ) ); |
|
| 68 | + )); |
|
| 69 | 69 | |
| 70 | 70 | $wp_query_args = array( |
| 71 | 71 | 'post_type' => 'wpi_item', |
@@ -75,26 +75,26 @@ discard block |
||
| 75 | 75 | 'fields' => 'ids', |
| 76 | 76 | 'orderby' => $args['orderby'], |
| 77 | 77 | 'order' => $args['order'], |
| 78 | - 'paged' => absint( $args['page'] ), |
|
| 78 | + 'paged' => absint($args['page']), |
|
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 82 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 81 | + if (!empty($args['exclude'])) { |
|
| 82 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ( ! $args['paginate' ] ) { |
|
| 85 | + if (!$args['paginate']) { |
|
| 86 | 86 | $wp_query_args['no_found_rows'] = true; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ( ! empty( $args['search'] ) ) { |
|
| 89 | + if (!empty($args['search'])) { |
|
| 90 | 90 | $wp_query_args['s'] = $args['search']; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
| 94 | - $types = wpinv_parse_list( $args['type'] ); |
|
| 93 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
| 94 | + $types = wpinv_parse_list($args['type']); |
|
| 95 | 95 | $wp_query_args['meta_query'][] = array( |
| 96 | 96 | 'key' => '_wpinv_type', |
| 97 | - 'value' => implode( ',', $types ), |
|
| 97 | + 'value' => implode(',', $types), |
|
| 98 | 98 | 'compare' => 'IN', |
| 99 | 99 | ); |
| 100 | 100 | } |
@@ -102,17 +102,17 @@ discard block |
||
| 102 | 102 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
| 103 | 103 | |
| 104 | 104 | // Get results. |
| 105 | - $items = new WP_Query( $wp_query_args ); |
|
| 105 | + $items = new WP_Query($wp_query_args); |
|
| 106 | 106 | |
| 107 | - if ( 'objects' === $args['return'] ) { |
|
| 108 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
| 109 | - } elseif ( 'self' === $args['return'] ) { |
|
| 107 | + if ('objects' === $args['return']) { |
|
| 108 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
| 109 | + } elseif ('self' === $args['return']) { |
|
| 110 | 110 | return $items; |
| 111 | 111 | } else { |
| 112 | 112 | $return = $items->posts; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( $args['paginate' ] ) { |
|
| 115 | + if ($args['paginate']) { |
|
| 116 | 116 | return (object) array( |
| 117 | 117 | 'items' => $return, |
| 118 | 118 | 'total' => $items->found_posts, |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 128 | - if( empty( $item_id ) ) { |
|
| 127 | +function wpinv_is_free_item($item_id = 0) { |
|
| 128 | + if (empty($item_id)) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $item = new WPInv_Item( $item_id ); |
|
| 132 | + $item = new WPInv_Item($item_id); |
|
| 133 | 133 | |
| 134 | 134 | return $item->is_free(); |
| 135 | 135 | } |
@@ -139,21 +139,21 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
| 141 | 141 | */ |
| 142 | -function wpinv_item_is_editable( $item = 0 ) { |
|
| 142 | +function wpinv_item_is_editable($item = 0) { |
|
| 143 | 143 | |
| 144 | 144 | // Fetch the item. |
| 145 | - $item = new WPInv_Item( $item ); |
|
| 145 | + $item = new WPInv_Item($item); |
|
| 146 | 146 | |
| 147 | 147 | // Check if it is editable. |
| 148 | 148 | return $item->is_editable(); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 152 | - if( empty( $item_id ) ) { |
|
| 151 | +function wpinv_get_item_price($item_id = 0) { |
|
| 152 | + if (empty($item_id)) { |
|
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $item = new WPInv_Item( $item_id ); |
|
| 156 | + $item = new WPInv_Item($item_id); |
|
| 157 | 157 | |
| 158 | 158 | return $item->get_price(); |
| 159 | 159 | } |
@@ -163,96 +163,96 @@ discard block |
||
| 163 | 163 | * |
| 164 | 164 | * @param WPInv_Item|int $item |
| 165 | 165 | */ |
| 166 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
| 167 | - $item = new WPInv_Item( $item ); |
|
| 166 | +function wpinv_is_recurring_item($item = 0) { |
|
| 167 | + $item = new WPInv_Item($item); |
|
| 168 | 168 | return $item->is_recurring(); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 172 | - if( empty( $item_id ) ) { |
|
| 171 | +function wpinv_item_price($item_id = 0) { |
|
| 172 | + if (empty($item_id)) { |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $price = wpinv_get_item_price( $item_id ); |
|
| 177 | - $price = wpinv_price( $price ); |
|
| 176 | + $price = wpinv_get_item_price($item_id); |
|
| 177 | + $price = wpinv_price($price); |
|
| 178 | 178 | |
| 179 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 179 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 183 | - if ( is_null( $amount_override ) ) { |
|
| 184 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 182 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 183 | + if (is_null($amount_override)) { |
|
| 184 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 185 | 185 | } else { |
| 186 | 186 | $original_price = $amount_override; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $price = $original_price; |
| 190 | 190 | |
| 191 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 191 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 195 | - if( empty( $item_id ) ) { |
|
| 194 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 195 | + if (empty($item_id)) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - $item = new WPInv_Item( $item_id ); |
|
| 199 | + $item = new WPInv_Item($item_id); |
|
| 200 | 200 | |
| 201 | 201 | return $item->get_custom_singular_name(); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | function wpinv_get_item_types() { |
| 205 | 205 | $item_types = array( |
| 206 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 207 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 206 | + 'custom' => __('Standard', 'invoicing'), |
|
| 207 | + 'fee' => __('Fee', 'invoicing'), |
|
| 208 | 208 | ); |
| 209 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 209 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function wpinv_item_types() { |
| 213 | 213 | $item_types = wpinv_get_item_types(); |
| 214 | 214 | |
| 215 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 215 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | -function wpinv_get_item_type( $item_id ) { |
|
| 219 | - if( empty( $item_id ) ) { |
|
| 218 | +function wpinv_get_item_type($item_id) { |
|
| 219 | + if (empty($item_id)) { |
|
| 220 | 220 | return false; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - $item = new WPInv_Item( $item_id ); |
|
| 223 | + $item = new WPInv_Item($item_id); |
|
| 224 | 224 | |
| 225 | 225 | return $item->get_type(); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | -function wpinv_item_type( $item_id ) { |
|
| 228 | +function wpinv_item_type($item_id) { |
|
| 229 | 229 | $item_types = wpinv_get_item_types(); |
| 230 | 230 | |
| 231 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 231 | + $item_type = wpinv_get_item_type($item_id); |
|
| 232 | 232 | |
| 233 | - if ( empty( $item_type ) ) { |
|
| 233 | + if (empty($item_type)) { |
|
| 234 | 234 | $item_type = '-'; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
| 237 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 238 | 238 | |
| 239 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 239 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 243 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 242 | +function wpinv_get_random_item($post_ids = true) { |
|
| 243 | + wpinv_get_random_items(1, $post_ids); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 247 | - if ( $post_ids ) { |
|
| 248 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
| 246 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 247 | + if ($post_ids) { |
|
| 248 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
| 249 | 249 | } else { |
| 250 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
| 250 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 253 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 254 | 254 | |
| 255 | - return get_posts( $args ); |
|
| 255 | + return get_posts($args); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -261,13 +261,13 @@ discard block |
||
| 261 | 261 | * @param WPInv_Item|int $item |
| 262 | 262 | * @param bool $html |
| 263 | 263 | */ |
| 264 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 264 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 265 | 265 | |
| 266 | - $item = new WPInv_Item( $item ); |
|
| 267 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
| 268 | - $suffix = $html ? $suffix : strip_tags( $suffix ); |
|
| 266 | + $item = new WPInv_Item($item); |
|
| 267 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
| 268 | + $suffix = $html ? $suffix : strip_tags($suffix); |
|
| 269 | 269 | |
| 270 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 270 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * @param WPInv_Item|int $item |
| 277 | 277 | * @param bool $force_delete |
| 278 | 278 | */ |
| 279 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 280 | - $item = new WPInv_Item( $item ); |
|
| 281 | - $item->delete( $force_delete ); |
|
| 279 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 280 | + $item = new WPInv_Item($item); |
|
| 281 | + $item->delete($force_delete); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -317,45 +317,45 @@ discard block |
||
| 317 | 317 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
| 318 | 318 | * @return bool|WP_Error|WPInv_Item |
| 319 | 319 | */ |
| 320 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
| 320 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
| 321 | 321 | |
| 322 | 322 | // Prepare the item. |
| 323 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
| 324 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
| 325 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
| 323 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
| 324 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
| 325 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
| 326 | 326 | |
| 327 | - if ( ! empty( $item ) ) { |
|
| 327 | + if (!empty($item)) { |
|
| 328 | 328 | $args['ID'] = $item->get_id(); |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // Do we have an item? |
| 334 | - if ( ! empty( $args['ID'] ) ) { |
|
| 335 | - $item = new WPInv_Item( $args['ID'] ); |
|
| 334 | + if (!empty($args['ID'])) { |
|
| 335 | + $item = new WPInv_Item($args['ID']); |
|
| 336 | 336 | } else { |
| 337 | 337 | $item = new WPInv_Item(); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | // Do we have an error? |
| 341 | - if ( ! empty( $item->last_error ) ) { |
|
| 342 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
| 341 | + if (!empty($item->last_error)) { |
|
| 342 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | // Update item props. |
| 346 | - $item->set_props( $args ); |
|
| 346 | + $item->set_props($args); |
|
| 347 | 347 | |
| 348 | 348 | // Save the item. |
| 349 | 349 | $item->save(); |
| 350 | 350 | |
| 351 | 351 | // Do we have an error? |
| 352 | - if ( ! empty( $item->last_error ) ) { |
|
| 353 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
| 352 | + if (!empty($item->last_error)) { |
|
| 353 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Was the item saved? |
| 357 | - if ( ! $item->get_id() ) { |
|
| 358 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
| 357 | + if (!$item->get_id()) { |
|
| 358 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | return $item; |
@@ -367,14 +367,14 @@ discard block |
||
| 367 | 367 | * |
| 368 | 368 | * @see wpinv_create_item() |
| 369 | 369 | */ |
| 370 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
| 371 | - return wpinv_create_item( $args, $wp_error ); |
|
| 370 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
| 371 | + return wpinv_create_item($args, $wp_error); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
| 375 | 375 | * Sanitizes a recurring period |
| 376 | 376 | */ |
| 377 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
| 377 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
| 378 | 378 | |
| 379 | 379 | $periods = array( |
| 380 | 380 | 'D' => 'day', |
@@ -383,11 +383,11 @@ discard block |
||
| 383 | 383 | 'Y' => 'year', |
| 384 | 384 | ); |
| 385 | 385 | |
| 386 | - if ( ! isset( $periods[ $period ] ) ) { |
|
| 386 | + if (!isset($periods[$period])) { |
|
| 387 | 387 | $period = 'D'; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - return $full ? $periods[ $period ] : $period; |
|
| 390 | + return $full ? $periods[$period] : $period; |
|
| 391 | 391 | |
| 392 | 392 | } |
| 393 | 393 | |
@@ -396,46 +396,46 @@ discard block |
||
| 396 | 396 | * |
| 397 | 397 | * @param WPInv_Item|GetPaid_Form_Item $item |
| 398 | 398 | */ |
| 399 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
| 399 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
| 400 | 400 | |
| 401 | 401 | // Abort if it is not recurring. |
| 402 | - if ( ! $item->is_recurring() ) { |
|
| 402 | + if (!$item->is_recurring()) { |
|
| 403 | 403 | return ''; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
| 407 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
| 408 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
| 406 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
| 407 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
| 408 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
| 409 | 409 | $initial_class = 'getpaid-item-initial-price'; |
| 410 | 410 | $recurring_class = 'getpaid-item-recurring-price'; |
| 411 | 411 | $bill_times = $item->get_recurring_limit(); |
| 412 | 412 | |
| 413 | - if ( ! empty( $bill_times ) ) { |
|
| 413 | + if (!empty($bill_times)) { |
|
| 414 | 414 | $bill_times = $item->get_recurring_interval() * $bill_times; |
| 415 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 415 | + $bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
| 419 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
| 420 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
| 418 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
| 419 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
| 420 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
| 424 | - return __( 'Free forever', 'invoicing' ); |
|
| 423 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
| 424 | + return __('Free forever', 'invoicing'); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | // For free trial items. |
| 428 | - if ( $item->has_free_trial() ) { |
|
| 429 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
| 428 | + if ($item->has_free_trial()) { |
|
| 429 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
| 430 | 430 | |
| 431 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
| 431 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
| 432 | 432 | |
| 433 | - if ( empty( $bill_times ) ) { |
|
| 433 | + if (empty($bill_times)) { |
|
| 434 | 434 | |
| 435 | 435 | return sprintf( |
| 436 | 436 | |
| 437 | 437 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
| 438 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
| 438 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
| 439 | 439 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 440 | 440 | "<span class='$recurring_class'>$recurring_price</span>", |
| 441 | 441 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | return sprintf( |
| 448 | 448 | |
| 449 | 449 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
| 450 | - _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 450 | + _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
| 451 | 451 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 452 | 452 | "<span class='$recurring_class'>$recurring_price</span>", |
| 453 | 453 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -457,12 +457,12 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if ( empty( $bill_times ) ) { |
|
| 460 | + if (empty($bill_times)) { |
|
| 461 | 461 | |
| 462 | 462 | return sprintf( |
| 463 | 463 | |
| 464 | 464 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
| 465 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
| 465 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
| 466 | 466 | "<span class='$initial_class'>$initial_price</span>", |
| 467 | 467 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 468 | 468 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | return sprintf( |
| 476 | 476 | |
| 477 | 477 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
| 478 | - _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
|
| 478 | + _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'), |
|
| 479 | 479 | "<span class='$initial_class'>$initial_price</span>", |
| 480 | 480 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
| 481 | 481 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -486,14 +486,14 @@ discard block |
||
| 486 | 486 | |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - if ( $initial_price == $recurring_price ) { |
|
| 489 | + if ($initial_price == $recurring_price) { |
|
| 490 | 490 | |
| 491 | - if ( empty( $bill_times ) ) { |
|
| 491 | + if (empty($bill_times)) { |
|
| 492 | 492 | |
| 493 | 493 | return sprintf( |
| 494 | 494 | |
| 495 | 495 | // translators: $1: is the recurring price, $2: is the susbcription period |
| 496 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 496 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
| 497 | 497 | "<span class='$recurring_class'>$recurring_price</span>", |
| 498 | 498 | "<span class='getpaid-item-recurring-period'>$period</span>" |
| 499 | 499 | |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | return sprintf( |
| 505 | 505 | |
| 506 | 506 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
| 507 | - _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 507 | + _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
| 508 | 508 | "<span class='$recurring_class'>$recurring_price</span>", |
| 509 | 509 | "<span class='getpaid-item-recurring-period'>$period</span>", |
| 510 | 510 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -513,14 +513,14 @@ discard block |
||
| 513 | 513 | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
| 516 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
| 517 | 517 | |
| 518 | - if ( empty( $bill_times ) ) { |
|
| 518 | + if (empty($bill_times)) { |
|
| 519 | 519 | |
| 520 | 520 | return sprintf( |
| 521 | 521 | |
| 522 | 522 | // translators: $1: is the recurring period, $2: is the recurring price |
| 523 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
| 523 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
| 524 | 524 | "<span class='getpaid-item-recurring-period'>$period</span>", |
| 525 | 525 | "<span class='$recurring_class'>$recurring_price</span>" |
| 526 | 526 | |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | return sprintf( |
| 532 | 532 | |
| 533 | 533 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
| 534 | - _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
|
| 534 | + _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'), |
|
| 535 | 535 | "<span class='getpaid-item-recurring-period'>$period</span>", |
| 536 | 536 | "<span class='$recurring_class'>$recurring_price</span>", |
| 537 | 537 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -540,12 +540,12 @@ discard block |
||
| 540 | 540 | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - if ( empty( $bill_times ) ) { |
|
| 543 | + if (empty($bill_times)) { |
|
| 544 | 544 | |
| 545 | 545 | return sprintf( |
| 546 | 546 | |
| 547 | 547 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
| 548 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
| 548 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
| 549 | 549 | "<span class='$initial_class'>$initial_price</span>", |
| 550 | 550 | "<span class='$recurring_class'>$recurring_price</span>", |
| 551 | 551 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | return sprintf( |
| 558 | 558 | |
| 559 | 559 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
| 560 | - _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
|
| 560 | + _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'), |
|
| 561 | 561 | "<span class='$initial_class'>$initial_price</span>", |
| 562 | 562 | "<span class='$recurring_class'>$recurring_price</span>", |
| 563 | 563 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -17,28 +17,28 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
| 19 | 19 | |
| 20 | - // Do not retrieve all fields if we just want the count. |
|
| 21 | - if ( 'count' == $return ) { |
|
| 22 | - $args['fields'] = 'id'; |
|
| 23 | - $args['number'] = 1; |
|
| 24 | - } |
|
| 20 | + // Do not retrieve all fields if we just want the count. |
|
| 21 | + if ( 'count' == $return ) { |
|
| 22 | + $args['fields'] = 'id'; |
|
| 23 | + $args['number'] = 1; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - // Do not count all matches if we just want the results. |
|
| 27 | - if ( 'results' == $return ) { |
|
| 28 | - $args['count_total'] = false; |
|
| 29 | - } |
|
| 26 | + // Do not count all matches if we just want the results. |
|
| 27 | + if ( 'results' == $return ) { |
|
| 28 | + $args['count_total'] = false; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 31 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 32 | 32 | |
| 33 | - if ( 'results' == $return ) { |
|
| 34 | - return $query->get_results(); |
|
| 35 | - } |
|
| 33 | + if ( 'results' == $return ) { |
|
| 34 | + return $query->get_results(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if ( 'count' == $return ) { |
|
| 38 | - return $query->get_total(); |
|
| 39 | - } |
|
| 37 | + if ( 'count' == $return ) { |
|
| 38 | + return $query->get_total(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return $query; |
|
| 41 | + return $query; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -48,18 +48,18 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function getpaid_get_subscription_statuses() { |
| 50 | 50 | |
| 51 | - return apply_filters( |
|
| 52 | - 'getpaid_get_subscription_statuses', |
|
| 53 | - array( |
|
| 54 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 55 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 56 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 57 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 58 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 59 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 60 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 61 | - ) |
|
| 62 | - ); |
|
| 51 | + return apply_filters( |
|
| 52 | + 'getpaid_get_subscription_statuses', |
|
| 53 | + array( |
|
| 54 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
| 55 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 56 | + 'active' => __( 'Active', 'invoicing' ), |
|
| 57 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
| 58 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
| 59 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
| 60 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 61 | + ) |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | 71 | function getpaid_get_subscription_status_label( $status ) { |
| 72 | - $statuses = getpaid_get_subscription_statuses(); |
|
| 73 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 72 | + $statuses = getpaid_get_subscription_statuses(); |
|
| 73 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -80,18 +80,18 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function getpaid_get_subscription_status_classes() { |
| 82 | 82 | |
| 83 | - return apply_filters( |
|
| 84 | - 'getpaid_get_subscription_status_classes', |
|
| 85 | - array( |
|
| 86 | - 'pending' => 'badge-dark', |
|
| 87 | - 'trialling' => 'badge-info', |
|
| 88 | - 'active' => 'badge-success', |
|
| 89 | - 'failing' => 'badge-warning', |
|
| 90 | - 'expired' => 'badge-danger', |
|
| 91 | - 'completed' => 'badge-primary', |
|
| 92 | - 'cancelled' => 'badge-secondary', |
|
| 93 | - ) |
|
| 94 | - ); |
|
| 83 | + return apply_filters( |
|
| 84 | + 'getpaid_get_subscription_status_classes', |
|
| 85 | + array( |
|
| 86 | + 'pending' => 'badge-dark', |
|
| 87 | + 'trialling' => 'badge-info', |
|
| 88 | + 'active' => 'badge-success', |
|
| 89 | + 'failing' => 'badge-warning', |
|
| 90 | + 'expired' => 'badge-danger', |
|
| 91 | + 'completed' => 'badge-primary', |
|
| 92 | + 'cancelled' => 'badge-secondary', |
|
| 93 | + ) |
|
| 94 | + ); |
|
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
@@ -102,15 +102,15 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function getpaid_get_subscription_status_counts( $args = array() ) { |
| 104 | 104 | |
| 105 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 106 | - $counts = array(); |
|
| 105 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 106 | + $counts = array(); |
|
| 107 | 107 | |
| 108 | - foreach ( $statuses as $status ) { |
|
| 109 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 110 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 111 | - } |
|
| 108 | + foreach ( $statuses as $status ) { |
|
| 109 | + $_args = wp_parse_args( "status=$status", $args ); |
|
| 110 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return $counts; |
|
| 113 | + return $counts; |
|
| 114 | 114 | |
| 115 | 115 | } |
| 116 | 116 | |
@@ -121,32 +121,32 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | function getpaid_get_subscription_periods() { |
| 123 | 123 | |
| 124 | - return apply_filters( |
|
| 125 | - 'getpaid_get_subscription_periods', |
|
| 126 | - array( |
|
| 124 | + return apply_filters( |
|
| 125 | + 'getpaid_get_subscription_periods', |
|
| 126 | + array( |
|
| 127 | 127 | |
| 128 | - 'day' => array( |
|
| 129 | - 'singular' => __( '%s day', 'invoicing' ), |
|
| 130 | - 'plural' => __( '%d days', 'invoicing' ), |
|
| 131 | - ), |
|
| 128 | + 'day' => array( |
|
| 129 | + 'singular' => __( '%s day', 'invoicing' ), |
|
| 130 | + 'plural' => __( '%d days', 'invoicing' ), |
|
| 131 | + ), |
|
| 132 | 132 | |
| 133 | - 'week' => array( |
|
| 134 | - 'singular' => __( '%s week', 'invoicing' ), |
|
| 135 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 136 | - ), |
|
| 133 | + 'week' => array( |
|
| 134 | + 'singular' => __( '%s week', 'invoicing' ), |
|
| 135 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 136 | + ), |
|
| 137 | 137 | |
| 138 | - 'month' => array( |
|
| 139 | - 'singular' => __( '%s month', 'invoicing' ), |
|
| 140 | - 'plural' => __( '%d months', 'invoicing' ), |
|
| 141 | - ), |
|
| 138 | + 'month' => array( |
|
| 139 | + 'singular' => __( '%s month', 'invoicing' ), |
|
| 140 | + 'plural' => __( '%d months', 'invoicing' ), |
|
| 141 | + ), |
|
| 142 | 142 | |
| 143 | - 'year' => array( |
|
| 144 | - 'singular' => __( '%s year', 'invoicing' ), |
|
| 145 | - 'plural' => __( '%d years', 'invoicing' ), |
|
| 146 | - ), |
|
| 143 | + 'year' => array( |
|
| 144 | + 'singular' => __( '%s year', 'invoicing' ), |
|
| 145 | + 'plural' => __( '%d years', 'invoicing' ), |
|
| 146 | + ), |
|
| 147 | 147 | |
| 148 | - ) |
|
| 149 | - ); |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @return int |
| 158 | 158 | */ |
| 159 | 159 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
| 160 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 160 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @return string |
| 168 | 168 | */ |
| 169 | 169 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
| 170 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 170 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | 180 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
| 181 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 182 | - return strtolower( sanitize_text_field( $label ) ); |
|
| 181 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 182 | + return strtolower( sanitize_text_field( $label ) ); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -190,22 +190,22 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
| 192 | 192 | |
| 193 | - $periods = getpaid_get_subscription_periods(); |
|
| 194 | - $period = strtolower( $period ); |
|
| 193 | + $periods = getpaid_get_subscription_periods(); |
|
| 194 | + $period = strtolower( $period ); |
|
| 195 | 195 | |
| 196 | - if ( isset( $periods[ $period ] ) ) { |
|
| 197 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 198 | - } |
|
| 196 | + if ( isset( $periods[ $period ] ) ) { |
|
| 197 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - // Backwards compatibility. |
|
| 201 | - foreach ( $periods as $key => $data ) { |
|
| 202 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 203 | - return sprintf( $data['singular'], $singular_prefix ); |
|
| 204 | - } |
|
| 205 | - } |
|
| 200 | + // Backwards compatibility. |
|
| 201 | + foreach ( $periods as $key => $data ) { |
|
| 202 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 203 | + return sprintf( $data['singular'], $singular_prefix ); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - // Invalid string. |
|
| 208 | - return ''; |
|
| 207 | + // Invalid string. |
|
| 208 | + return ''; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -217,22 +217,22 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
| 219 | 219 | |
| 220 | - $periods = getpaid_get_subscription_periods(); |
|
| 221 | - $period = strtolower( $period ); |
|
| 220 | + $periods = getpaid_get_subscription_periods(); |
|
| 221 | + $period = strtolower( $period ); |
|
| 222 | 222 | |
| 223 | - if ( isset( $periods[ $period ] ) ) { |
|
| 224 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 225 | - } |
|
| 223 | + if ( isset( $periods[ $period ] ) ) { |
|
| 224 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - // Backwards compatibility. |
|
| 228 | - foreach ( $periods as $key => $data ) { |
|
| 229 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 230 | - return sprintf( $data['plural'], $interval ); |
|
| 231 | - } |
|
| 232 | - } |
|
| 227 | + // Backwards compatibility. |
|
| 228 | + foreach ( $periods as $key => $data ) { |
|
| 229 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 230 | + return sprintf( $data['plural'], $interval ); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - // Invalid string. |
|
| 235 | - return ''; |
|
| 234 | + // Invalid string. |
|
| 235 | + return ''; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -243,101 +243,101 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
| 245 | 245 | |
| 246 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 247 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 248 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 249 | - $bill_times = $subscription->get_bill_times(); |
|
| 246 | + $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 247 | + $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 248 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 249 | + $bill_times = $subscription->get_bill_times(); |
|
| 250 | 250 | |
| 251 | - if ( ! empty( $bill_times ) ) { |
|
| 252 | - $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 253 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 254 | - } |
|
| 251 | + if ( ! empty( $bill_times ) ) { |
|
| 252 | + $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 253 | + $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - // Trial periods. |
|
| 257 | - if ( $subscription->has_trial_period() ) { |
|
| 256 | + // Trial periods. |
|
| 257 | + if ( $subscription->has_trial_period() ) { |
|
| 258 | 258 | |
| 259 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 260 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 259 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 260 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 261 | 261 | |
| 262 | - if ( empty( $bill_times ) ) { |
|
| 262 | + if ( empty( $bill_times ) ) { |
|
| 263 | 263 | |
| 264 | - return sprintf( |
|
| 264 | + return sprintf( |
|
| 265 | 265 | |
| 266 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 267 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 268 | - $initial, |
|
| 269 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 270 | - $recurring, |
|
| 271 | - $period |
|
| 266 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 267 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 268 | + $initial, |
|
| 269 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 270 | + $recurring, |
|
| 271 | + $period |
|
| 272 | 272 | |
| 273 | - ); |
|
| 273 | + ); |
|
| 274 | 274 | |
| 275 | - } |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - return sprintf( |
|
| 277 | + return sprintf( |
|
| 278 | 278 | |
| 279 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 280 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 281 | - $initial, |
|
| 282 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 283 | - $recurring, |
|
| 284 | - $period, |
|
| 285 | - $bill_times |
|
| 286 | - ); |
|
| 279 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 280 | + _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 281 | + $initial, |
|
| 282 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 283 | + $recurring, |
|
| 284 | + $period, |
|
| 285 | + $bill_times |
|
| 286 | + ); |
|
| 287 | 287 | |
| 288 | - } |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - if ( $initial != $recurring ) { |
|
| 290 | + if ( $initial != $recurring ) { |
|
| 291 | 291 | |
| 292 | - if ( empty( $bill_times ) ) { |
|
| 292 | + if ( empty( $bill_times ) ) { |
|
| 293 | 293 | |
| 294 | - return sprintf( |
|
| 294 | + return sprintf( |
|
| 295 | 295 | |
| 296 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 297 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 298 | - $initial, |
|
| 299 | - $recurring, |
|
| 300 | - $period |
|
| 296 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 297 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 298 | + $initial, |
|
| 299 | + $recurring, |
|
| 300 | + $period |
|
| 301 | 301 | |
| 302 | - ); |
|
| 302 | + ); |
|
| 303 | 303 | |
| 304 | - } |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - return sprintf( |
|
| 306 | + return sprintf( |
|
| 307 | 307 | |
| 308 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 309 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 310 | - $initial, |
|
| 311 | - $recurring, |
|
| 312 | - $period, |
|
| 313 | - $bill_times |
|
| 308 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 309 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 310 | + $initial, |
|
| 311 | + $recurring, |
|
| 312 | + $period, |
|
| 313 | + $bill_times |
|
| 314 | 314 | |
| 315 | - ); |
|
| 315 | + ); |
|
| 316 | 316 | |
| 317 | - } |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - if ( empty( $bill_times ) ) { |
|
| 319 | + if ( empty( $bill_times ) ) { |
|
| 320 | 320 | |
| 321 | - return sprintf( |
|
| 321 | + return sprintf( |
|
| 322 | 322 | |
| 323 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 324 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 325 | - $initial, |
|
| 326 | - $period |
|
| 323 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 324 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 325 | + $initial, |
|
| 326 | + $period |
|
| 327 | 327 | |
| 328 | - ); |
|
| 328 | + ); |
|
| 329 | 329 | |
| 330 | - } |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - return sprintf( |
|
| 332 | + return sprintf( |
|
| 333 | 333 | |
| 334 | - // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 335 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 336 | - $bill_times, |
|
| 337 | - $initial, |
|
| 338 | - $period |
|
| 334 | + // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 335 | + _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 336 | + $bill_times, |
|
| 337 | + $initial, |
|
| 338 | + $period |
|
| 339 | 339 | |
| 340 | - ); |
|
| 340 | + ); |
|
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @return WPInv_Subscription|bool |
| 349 | 349 | */ |
| 350 | 350 | function getpaid_get_invoice_subscription( $invoice ) { |
| 351 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 351 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -357,10 +357,10 @@ discard block |
||
| 357 | 357 | * @param WPInv_Invoice $invoice |
| 358 | 358 | */ |
| 359 | 359 | function getpaid_activate_invoice_subscription( $invoice ) { |
| 360 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 361 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 362 | - $subscription->activate(); |
|
| 363 | - } |
|
| 360 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 361 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 362 | + $subscription->activate(); |
|
| 363 | + } |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | * @return WPInv_Subscriptions |
| 370 | 370 | */ |
| 371 | 371 | function getpaid_subscriptions() { |
| 372 | - return getpaid()->get( 'subscriptions' ); |
|
| 372 | + return getpaid()->get( 'subscriptions' ); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -387,14 +387,14 @@ discard block |
||
| 387 | 387 | return false; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - // Fetch the invoiec subscription. |
|
| 391 | - $subscription = getpaid_get_subscriptions( |
|
| 392 | - array( |
|
| 393 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 394 | - 'number' => 1, |
|
| 395 | - ) |
|
| 396 | - ); |
|
| 390 | + // Fetch the invoiec subscription. |
|
| 391 | + $subscription = getpaid_get_subscriptions( |
|
| 392 | + array( |
|
| 393 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 394 | + 'number' => 1, |
|
| 395 | + ) |
|
| 396 | + ); |
|
| 397 | 397 | |
| 398 | - return empty( $subscription ) ? false : $subscription[0]; |
|
| 398 | + return empty( $subscription ) ? false : $subscription[0]; |
|
| 399 | 399 | |
| 400 | 400 | } |
@@ -15,26 +15,26 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
| 17 | 17 | */ |
| 18 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
| 18 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
| 19 | 19 | |
| 20 | 20 | // Do not retrieve all fields if we just want the count. |
| 21 | - if ( 'count' == $return ) { |
|
| 21 | + if ('count' == $return) { |
|
| 22 | 22 | $args['fields'] = 'id'; |
| 23 | 23 | $args['number'] = 1; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Do not count all matches if we just want the results. |
| 27 | - if ( 'results' == $return ) { |
|
| 27 | + if ('results' == $return) { |
|
| 28 | 28 | $args['count_total'] = false; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 31 | + $query = new GetPaid_Subscriptions_Query($args); |
|
| 32 | 32 | |
| 33 | - if ( 'results' == $return ) { |
|
| 33 | + if ('results' == $return) { |
|
| 34 | 34 | return $query->get_results(); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if ( 'count' == $return ) { |
|
| 37 | + if ('count' == $return) { |
|
| 38 | 38 | return $query->get_total(); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -51,13 +51,13 @@ discard block |
||
| 51 | 51 | return apply_filters( |
| 52 | 52 | 'getpaid_get_subscription_statuses', |
| 53 | 53 | array( |
| 54 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 55 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 56 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 57 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 58 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 59 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 60 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 54 | + 'pending' => __('Pending', 'invoicing'), |
|
| 55 | + 'trialling' => __('Trialing', 'invoicing'), |
|
| 56 | + 'active' => __('Active', 'invoicing'), |
|
| 57 | + 'failing' => __('Failing', 'invoicing'), |
|
| 58 | + 'expired' => __('Expired', 'invoicing'), |
|
| 59 | + 'completed' => __('Complete', 'invoicing'), |
|
| 60 | + 'cancelled' => __('Cancelled', 'invoicing'), |
|
| 61 | 61 | ) |
| 62 | 62 | ); |
| 63 | 63 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | -function getpaid_get_subscription_status_label( $status ) { |
|
| 71 | +function getpaid_get_subscription_status_label($status) { |
|
| 72 | 72 | $statuses = getpaid_get_subscription_statuses(); |
| 73 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 73 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status)); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @return array |
| 102 | 102 | */ |
| 103 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
| 103 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
| 104 | 104 | |
| 105 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 105 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
| 106 | 106 | $counts = array(); |
| 107 | 107 | |
| 108 | - foreach ( $statuses as $status ) { |
|
| 109 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 110 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 108 | + foreach ($statuses as $status) { |
|
| 109 | + $_args = wp_parse_args("status=$status", $args); |
|
| 110 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return $counts; |
@@ -126,23 +126,23 @@ discard block |
||
| 126 | 126 | array( |
| 127 | 127 | |
| 128 | 128 | 'day' => array( |
| 129 | - 'singular' => __( '%s day', 'invoicing' ), |
|
| 130 | - 'plural' => __( '%d days', 'invoicing' ), |
|
| 129 | + 'singular' => __('%s day', 'invoicing'), |
|
| 130 | + 'plural' => __('%d days', 'invoicing'), |
|
| 131 | 131 | ), |
| 132 | 132 | |
| 133 | 133 | 'week' => array( |
| 134 | - 'singular' => __( '%s week', 'invoicing' ), |
|
| 135 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 134 | + 'singular' => __('%s week', 'invoicing'), |
|
| 135 | + 'plural' => __('%d weeks', 'invoicing'), |
|
| 136 | 136 | ), |
| 137 | 137 | |
| 138 | 138 | 'month' => array( |
| 139 | - 'singular' => __( '%s month', 'invoicing' ), |
|
| 140 | - 'plural' => __( '%d months', 'invoicing' ), |
|
| 139 | + 'singular' => __('%s month', 'invoicing'), |
|
| 140 | + 'plural' => __('%d months', 'invoicing'), |
|
| 141 | 141 | ), |
| 142 | 142 | |
| 143 | 143 | 'year' => array( |
| 144 | - 'singular' => __( '%s year', 'invoicing' ), |
|
| 145 | - 'plural' => __( '%d years', 'invoicing' ), |
|
| 144 | + 'singular' => __('%s year', 'invoicing'), |
|
| 145 | + 'plural' => __('%d years', 'invoicing'), |
|
| 146 | 146 | ), |
| 147 | 147 | |
| 148 | 148 | ) |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | * @param string $trial_period |
| 157 | 157 | * @return int |
| 158 | 158 | */ |
| 159 | -function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
|
| 160 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 159 | +function getpaid_get_subscription_trial_period_interval($trial_period) { |
|
| 160 | + return (int) preg_replace('/[^0-9]/', '', $trial_period); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | * @param string $trial_period |
| 167 | 167 | * @return string |
| 168 | 168 | */ |
| 169 | -function getpaid_get_subscription_trial_period_period( $trial_period ) { |
|
| 170 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 169 | +function getpaid_get_subscription_trial_period_period($trial_period) { |
|
| 170 | + return preg_replace('/[^a-z]/', '', strtolower($trial_period)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | * @param int $interval |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | -function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
|
| 181 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 182 | - return strtolower( sanitize_text_field( $label ) ); |
|
| 180 | +function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') { |
|
| 181 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix); |
|
| 182 | + return strtolower(sanitize_text_field($label)); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -188,19 +188,19 @@ discard block |
||
| 188 | 188 | * @param string $period |
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | -function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
|
| 191 | +function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') { |
|
| 192 | 192 | |
| 193 | 193 | $periods = getpaid_get_subscription_periods(); |
| 194 | - $period = strtolower( $period ); |
|
| 194 | + $period = strtolower($period); |
|
| 195 | 195 | |
| 196 | - if ( isset( $periods[ $period ] ) ) { |
|
| 197 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 196 | + if (isset($periods[$period])) { |
|
| 197 | + return sprintf($periods[$period]['singular'], $singular_prefix); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Backwards compatibility. |
| 201 | - foreach ( $periods as $key => $data ) { |
|
| 202 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 203 | - return sprintf( $data['singular'], $singular_prefix ); |
|
| 201 | + foreach ($periods as $key => $data) { |
|
| 202 | + if (strpos($key, $period) === 0) { |
|
| 203 | + return sprintf($data['singular'], $singular_prefix); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
@@ -215,19 +215,19 @@ discard block |
||
| 215 | 215 | * @param int $interval |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | -function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
|
| 218 | +function getpaid_get_plural_subscription_period_label($period, $interval) { |
|
| 219 | 219 | |
| 220 | 220 | $periods = getpaid_get_subscription_periods(); |
| 221 | - $period = strtolower( $period ); |
|
| 221 | + $period = strtolower($period); |
|
| 222 | 222 | |
| 223 | - if ( isset( $periods[ $period ] ) ) { |
|
| 224 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 223 | + if (isset($periods[$period])) { |
|
| 224 | + return sprintf($periods[$period]['plural'], $interval); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | // Backwards compatibility. |
| 228 | - foreach ( $periods as $key => $data ) { |
|
| 229 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 230 | - return sprintf( $data['plural'], $interval ); |
|
| 228 | + foreach ($periods as $key => $data) { |
|
| 229 | + if (strpos($key, $period) === 0) { |
|
| 230 | + return sprintf($data['plural'], $interval); |
|
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
@@ -241,32 +241,32 @@ discard block |
||
| 241 | 241 | * @param WPInv_Subscription $subscription |
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | -function getpaid_get_formatted_subscription_amount( $subscription ) { |
|
| 244 | +function getpaid_get_formatted_subscription_amount($subscription) { |
|
| 245 | 245 | |
| 246 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 247 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 248 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 246 | + $initial = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
| 247 | + $recurring = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
| 248 | + $period = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
| 249 | 249 | $bill_times = $subscription->get_bill_times(); |
| 250 | 250 | |
| 251 | - if ( ! empty( $bill_times ) ) { |
|
| 251 | + if (!empty($bill_times)) { |
|
| 252 | 252 | $bill_times = $subscription->get_frequency() * $bill_times; |
| 253 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 253 | + $bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Trial periods. |
| 257 | - if ( $subscription->has_trial_period() ) { |
|
| 257 | + if ($subscription->has_trial_period()) { |
|
| 258 | 258 | |
| 259 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 260 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 259 | + $trial_period = getpaid_get_subscription_trial_period_period($subscription->get_trial_period()); |
|
| 260 | + $trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period()); |
|
| 261 | 261 | |
| 262 | - if ( empty( $bill_times ) ) { |
|
| 262 | + if (empty($bill_times)) { |
|
| 263 | 263 | |
| 264 | 264 | return sprintf( |
| 265 | 265 | |
| 266 | 266 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
| 267 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 267 | + _x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'), |
|
| 268 | 268 | $initial, |
| 269 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 269 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
| 270 | 270 | $recurring, |
| 271 | 271 | $period |
| 272 | 272 | |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | return sprintf( |
| 278 | 278 | |
| 279 | 279 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
| 280 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 280 | + _x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
| 281 | 281 | $initial, |
| 282 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 282 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
| 283 | 283 | $recurring, |
| 284 | 284 | $period, |
| 285 | 285 | $bill_times |
@@ -287,14 +287,14 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - if ( $initial != $recurring ) { |
|
| 290 | + if ($initial != $recurring) { |
|
| 291 | 291 | |
| 292 | - if ( empty( $bill_times ) ) { |
|
| 292 | + if (empty($bill_times)) { |
|
| 293 | 293 | |
| 294 | 294 | return sprintf( |
| 295 | 295 | |
| 296 | 296 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
| 297 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 297 | + _x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'), |
|
| 298 | 298 | $initial, |
| 299 | 299 | $recurring, |
| 300 | 300 | $period |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | return sprintf( |
| 307 | 307 | |
| 308 | 308 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
| 309 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 309 | + _x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'), |
|
| 310 | 310 | $initial, |
| 311 | 311 | $recurring, |
| 312 | 312 | $period, |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - if ( empty( $bill_times ) ) { |
|
| 319 | + if (empty($bill_times)) { |
|
| 320 | 320 | |
| 321 | 321 | return sprintf( |
| 322 | 322 | |
| 323 | 323 | // translators: $1: is the recurring amount, $2: is the recurring period |
| 324 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 324 | + _x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
| 325 | 325 | $initial, |
| 326 | 326 | $period |
| 327 | 327 | |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | return sprintf( |
| 333 | 333 | |
| 334 | 334 | // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
| 335 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 335 | + _x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
| 336 | 336 | $bill_times, |
| 337 | 337 | $initial, |
| 338 | 338 | $period |
@@ -347,8 +347,8 @@ discard block |
||
| 347 | 347 | * @param WPInv_Invoice $invoice |
| 348 | 348 | * @return WPInv_Subscription|bool |
| 349 | 349 | */ |
| 350 | -function getpaid_get_invoice_subscription( $invoice ) { |
|
| 351 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 350 | +function getpaid_get_invoice_subscription($invoice) { |
|
| 351 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | * |
| 357 | 357 | * @param WPInv_Invoice $invoice |
| 358 | 358 | */ |
| 359 | -function getpaid_activate_invoice_subscription( $invoice ) { |
|
| 360 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 361 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 359 | +function getpaid_activate_invoice_subscription($invoice) { |
|
| 360 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
| 361 | + if (is_a($subscription, 'WPInv_Subscription')) { |
|
| 362 | 362 | $subscription->activate(); |
| 363 | 363 | } |
| 364 | 364 | } |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | * @return WPInv_Subscriptions |
| 370 | 370 | */ |
| 371 | 371 | function getpaid_subscriptions() { |
| 372 | - return getpaid()->get( 'subscriptions' ); |
|
| 372 | + return getpaid()->get('subscriptions'); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -377,13 +377,13 @@ discard block |
||
| 377 | 377 | * |
| 378 | 378 | * @return WPInv_Subscription|bool |
| 379 | 379 | */ |
| 380 | -function wpinv_get_subscription( $invoice ) { |
|
| 380 | +function wpinv_get_subscription($invoice) { |
|
| 381 | 381 | |
| 382 | 382 | // Retrieve the invoice. |
| 383 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 383 | + $invoice = new WPInv_Invoice($invoice); |
|
| 384 | 384 | |
| 385 | 385 | // Ensure it is a recurring invoice. |
| 386 | - if ( ! $invoice->is_recurring() ) { |
|
| 386 | + if (!$invoice->is_recurring()) { |
|
| 387 | 387 | return false; |
| 388 | 388 | } |
| 389 | 389 | |
@@ -395,6 +395,6 @@ discard block |
||
| 395 | 395 | ) |
| 396 | 396 | ); |
| 397 | 397 | |
| 398 | - return empty( $subscription ) ? false : $subscription[0]; |
|
| 398 | + return empty($subscription) ? false : $subscription[0]; |
|
| 399 | 399 | |
| 400 | 400 | } |
@@ -7,50 +7,50 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -$class = ! is_singular( 'page' ) ? 'px-1' : ''; |
|
| 12 | +$class = !is_singular('page') ? 'px-1' : ''; |
|
| 13 | 13 | ?> |
| 14 | 14 | |
| 15 | - <?php do_action( 'getpaid_before_invoice_meta', $invoice ); ?> |
|
| 15 | + <?php do_action('getpaid_before_invoice_meta', $invoice); ?> |
|
| 16 | 16 | <div class="getpaid-invoice-meta-data"> |
| 17 | 17 | |
| 18 | - <?php do_action( 'getpaid_before_invoice_meta_table', $invoice ); ?> |
|
| 18 | + <?php do_action('getpaid_before_invoice_meta_table', $invoice); ?> |
|
| 19 | 19 | <table class="table table-bordered"> |
| 20 | 20 | <tbody> |
| 21 | 21 | |
| 22 | - <?php do_action( "getpaid_before_invoice_meta_rows", $invoice ); ?> |
|
| 23 | - <?php foreach ( $meta as $key => $data ) : ?> |
|
| 22 | + <?php do_action("getpaid_before_invoice_meta_rows", $invoice); ?> |
|
| 23 | + <?php foreach ($meta as $key => $data) : ?> |
|
| 24 | 24 | |
| 25 | - <?php if ( ! empty( $data['value'] ) ) : ?> |
|
| 25 | + <?php if (!empty($data['value'])) : ?> |
|
| 26 | 26 | |
| 27 | - <?php do_action( "getpaid_before_invoice_meta_$key", $invoice, $data ); ?> |
|
| 27 | + <?php do_action("getpaid_before_invoice_meta_$key", $invoice, $data); ?> |
|
| 28 | 28 | |
| 29 | - <tr class="getpaid-invoice-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
| 29 | + <tr class="getpaid-invoice-meta-<?php echo sanitize_html_class($key); ?>"> |
|
| 30 | 30 | |
| 31 | 31 | <th class="<?php echo $class; ?> font-weight-bold" style="width: 40%"> |
| 32 | - <?php echo sanitize_text_field( $data['label'] ); ?> |
|
| 32 | + <?php echo sanitize_text_field($data['label']); ?> |
|
| 33 | 33 | </th> |
| 34 | 34 | |
| 35 | 35 | <td class="<?php echo $class; ?> <?php echo $key == 'invoice_total' ? 'font-weight-bold' : 'font-weight-normal'; ?> text-break" style="width: 60%"> |
| 36 | - <span class="getpaid-invoice-meta-<?php echo sanitize_html_class( $key ); ?>-value"><?php echo wp_kses_post( $data['value'] ); ?></span> |
|
| 36 | + <span class="getpaid-invoice-meta-<?php echo sanitize_html_class($key); ?>-value"><?php echo wp_kses_post($data['value']); ?></span> |
|
| 37 | 37 | </td> |
| 38 | 38 | |
| 39 | 39 | </tr> |
| 40 | 40 | |
| 41 | - <?php do_action( "getpaid_after_invoice_meta_$key", $invoice, $data ); ?> |
|
| 41 | + <?php do_action("getpaid_after_invoice_meta_$key", $invoice, $data); ?> |
|
| 42 | 42 | |
| 43 | 43 | <?php endif; ?> |
| 44 | 44 | |
| 45 | 45 | <?php endforeach; ?> |
| 46 | - <?php do_action( "getpaid_after_invoice_meta_rows", $invoice ); ?> |
|
| 46 | + <?php do_action("getpaid_after_invoice_meta_rows", $invoice); ?> |
|
| 47 | 47 | |
| 48 | 48 | </tbody> |
| 49 | 49 | </table> |
| 50 | - <?php do_action( 'getpaid_after_invoice_meta_table', $invoice ); ?> |
|
| 50 | + <?php do_action('getpaid_after_invoice_meta_table', $invoice); ?> |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | </div> |
| 54 | - <?php do_action( 'getpaid_after_invoice_meta', $invoice ); ?> |
|
| 54 | + <?php do_action('getpaid_after_invoice_meta', $invoice); ?> |
|
| 55 | 55 | |
| 56 | 56 | <?php |
@@ -12,280 +12,280 @@ |
||
| 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 | 31 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 32 | - ); |
|
| 33 | - |
|
| 34 | - $this->add_totals( $submission ); |
|
| 35 | - $this->add_texts( $submission ); |
|
| 36 | - $this->add_items( $submission ); |
|
| 37 | - $this->add_fees( $submission ); |
|
| 38 | - $this->add_discounts( $submission ); |
|
| 39 | - $this->add_taxes( $submission ); |
|
| 40 | - $this->add_gateways( $submission ); |
|
| 41 | - $this->add_data( $submission ); |
|
| 42 | - |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Adds totals to a response for submission refresh prices. |
|
| 47 | - * |
|
| 48 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 49 | - */ |
|
| 50 | - public function add_totals( $submission ) { |
|
| 51 | - |
|
| 52 | - $this->response = array_merge( |
|
| 53 | - $this->response, |
|
| 54 | - array( |
|
| 55 | - |
|
| 56 | - 'totals' => array( |
|
| 57 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 58 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 59 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 60 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 61 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 62 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 63 | - ), |
|
| 64 | - |
|
| 65 | - 'recurring' => array( |
|
| 66 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 67 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 68 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 69 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 70 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 71 | - ), |
|
| 72 | - |
|
| 73 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 74 | - 'currency' => $submission->get_currency(), |
|
| 75 | - |
|
| 76 | - ) |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Adds texts to a response for submission refresh prices. |
|
| 83 | - * |
|
| 84 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 85 | - */ |
|
| 86 | - public function add_texts( $submission ) { |
|
| 87 | - |
|
| 88 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 89 | - |
|
| 90 | - if ( $submission->has_recurring != 0 ) { |
|
| 91 | - |
|
| 92 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 93 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 94 | - |
|
| 95 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 96 | - $payable = "$payable / $period"; |
|
| 97 | - } else { |
|
| 98 | - $payable = sprintf( |
|
| 99 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 100 | - $submission->format_amount( $submission->get_total() ), |
|
| 101 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 102 | - $period |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $texts = array( |
|
| 109 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 110 | - ); |
|
| 111 | - |
|
| 112 | - foreach ( $submission->get_items() as $item ) { |
|
| 113 | - $item_id = $item->get_id(); |
|
| 114 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 115 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 116 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Adds items to a response for submission refresh prices. |
|
| 125 | - * |
|
| 126 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 127 | - */ |
|
| 128 | - public function add_items( $submission ) { |
|
| 129 | - |
|
| 130 | - // Add items. |
|
| 131 | - $items = array(); |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + $this->add_totals( $submission ); |
|
| 35 | + $this->add_texts( $submission ); |
|
| 36 | + $this->add_items( $submission ); |
|
| 37 | + $this->add_fees( $submission ); |
|
| 38 | + $this->add_discounts( $submission ); |
|
| 39 | + $this->add_taxes( $submission ); |
|
| 40 | + $this->add_gateways( $submission ); |
|
| 41 | + $this->add_data( $submission ); |
|
| 42 | + |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Adds totals to a response for submission refresh prices. |
|
| 47 | + * |
|
| 48 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 49 | + */ |
|
| 50 | + public function add_totals( $submission ) { |
|
| 51 | + |
|
| 52 | + $this->response = array_merge( |
|
| 53 | + $this->response, |
|
| 54 | + array( |
|
| 55 | + |
|
| 56 | + 'totals' => array( |
|
| 57 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 58 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 59 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 60 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 61 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 62 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 63 | + ), |
|
| 64 | + |
|
| 65 | + 'recurring' => array( |
|
| 66 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 67 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 68 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 69 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 70 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 71 | + ), |
|
| 72 | + |
|
| 73 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 74 | + 'currency' => $submission->get_currency(), |
|
| 75 | + |
|
| 76 | + ) |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Adds texts to a response for submission refresh prices. |
|
| 83 | + * |
|
| 84 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 85 | + */ |
|
| 86 | + public function add_texts( $submission ) { |
|
| 87 | + |
|
| 88 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 89 | + |
|
| 90 | + if ( $submission->has_recurring != 0 ) { |
|
| 91 | + |
|
| 92 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 93 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 94 | + |
|
| 95 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 96 | + $payable = "$payable / $period"; |
|
| 97 | + } else { |
|
| 98 | + $payable = sprintf( |
|
| 99 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 100 | + $submission->format_amount( $submission->get_total() ), |
|
| 101 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 102 | + $period |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $texts = array( |
|
| 109 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 110 | + ); |
|
| 132 | 111 | |
| 133 | 112 | foreach ( $submission->get_items() as $item ) { |
| 134 | - $item_id = $item->get_id(); |
|
| 135 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 136 | - } |
|
| 113 | + $item_id = $item->get_id(); |
|
| 114 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 115 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 116 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 117 | + } |
|
| 137 | 118 | |
| 138 | - $this->response = array_merge( |
|
| 139 | - $this->response, |
|
| 140 | - array( 'items' => $items ) |
|
| 141 | - ); |
|
| 119 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 142 | 120 | |
| 143 | - } |
|
| 121 | + } |
|
| 144 | 122 | |
| 145 | - /** |
|
| 146 | - * Adds fees to a response for submission refresh prices. |
|
| 147 | - * |
|
| 148 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 149 | - */ |
|
| 150 | - public function add_fees( $submission ) { |
|
| 123 | + /** |
|
| 124 | + * Adds items to a response for submission refresh prices. |
|
| 125 | + * |
|
| 126 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 127 | + */ |
|
| 128 | + public function add_items( $submission ) { |
|
| 151 | 129 | |
| 152 | - $fees = array(); |
|
| 130 | + // Add items. |
|
| 131 | + $items = array(); |
|
| 153 | 132 | |
| 154 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
| 155 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 156 | - } |
|
| 133 | + foreach ( $submission->get_items() as $item ) { |
|
| 134 | + $item_id = $item->get_id(); |
|
| 135 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 136 | + } |
|
| 157 | 137 | |
| 158 | - $this->response = array_merge( |
|
| 159 | - $this->response, |
|
| 160 | - array( 'fees' => $fees ) |
|
| 161 | - ); |
|
| 138 | + $this->response = array_merge( |
|
| 139 | + $this->response, |
|
| 140 | + array( 'items' => $items ) |
|
| 141 | + ); |
|
| 162 | 142 | |
| 163 | - } |
|
| 143 | + } |
|
| 164 | 144 | |
| 165 | - /** |
|
| 166 | - * Adds discounts to a response for submission refresh prices. |
|
| 167 | - * |
|
| 168 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 169 | - */ |
|
| 170 | - public function add_discounts( $submission ) { |
|
| 145 | + /** |
|
| 146 | + * Adds fees to a response for submission refresh prices. |
|
| 147 | + * |
|
| 148 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 149 | + */ |
|
| 150 | + public function add_fees( $submission ) { |
|
| 171 | 151 | |
| 172 | - $discounts = array(); |
|
| 152 | + $fees = array(); |
|
| 173 | 153 | |
| 174 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 175 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 176 | - } |
|
| 154 | + foreach ( $submission->get_fees() as $name => $data ) { |
|
| 155 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 156 | + } |
|
| 177 | 157 | |
| 178 | - $this->response = array_merge( |
|
| 179 | - $this->response, |
|
| 180 | - array( 'discounts' => $discounts ) |
|
| 181 | - ); |
|
| 158 | + $this->response = array_merge( |
|
| 159 | + $this->response, |
|
| 160 | + array( 'fees' => $fees ) |
|
| 161 | + ); |
|
| 182 | 162 | |
| 183 | - } |
|
| 163 | + } |
|
| 184 | 164 | |
| 185 | - /** |
|
| 186 | - * Adds taxes to a response for submission refresh prices. |
|
| 187 | - * |
|
| 188 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 189 | - */ |
|
| 190 | - public function add_taxes( $submission ) { |
|
| 165 | + /** |
|
| 166 | + * Adds discounts to a response for submission refresh prices. |
|
| 167 | + * |
|
| 168 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 169 | + */ |
|
| 170 | + public function add_discounts( $submission ) { |
|
| 191 | 171 | |
| 192 | - $taxes = array(); |
|
| 193 | - $markup = ''; |
|
| 194 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 195 | - $name = sanitize_text_field( $name ); |
|
| 196 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 197 | - $taxes[$name] = $amount; |
|
| 198 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 199 | - } |
|
| 172 | + $discounts = array(); |
|
| 173 | + |
|
| 174 | + foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 175 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 176 | + } |
|
| 200 | 177 | |
| 201 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 202 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 203 | - } |
|
| 178 | + $this->response = array_merge( |
|
| 179 | + $this->response, |
|
| 180 | + array( 'discounts' => $discounts ) |
|
| 181 | + ); |
|
| 204 | 182 | |
| 205 | - $this->response = array_merge( |
|
| 206 | - $this->response, |
|
| 207 | - array( 'taxes' => $taxes ) |
|
| 208 | - ); |
|
| 183 | + } |
|
| 209 | 184 | |
| 210 | - } |
|
| 185 | + /** |
|
| 186 | + * Adds taxes to a response for submission refresh prices. |
|
| 187 | + * |
|
| 188 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 189 | + */ |
|
| 190 | + public function add_taxes( $submission ) { |
|
| 191 | + |
|
| 192 | + $taxes = array(); |
|
| 193 | + $markup = ''; |
|
| 194 | + foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 195 | + $name = sanitize_text_field( $name ); |
|
| 196 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 197 | + $taxes[$name] = $amount; |
|
| 198 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 199 | + } |
|
| 211 | 200 | |
| 212 | - /** |
|
| 213 | - * Adds gateways to a response for submission refresh prices. |
|
| 214 | - * |
|
| 215 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 216 | - */ |
|
| 217 | - public function add_gateways( $submission ) { |
|
| 201 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 202 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 203 | + } |
|
| 218 | 204 | |
| 219 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 205 | + $this->response = array_merge( |
|
| 206 | + $this->response, |
|
| 207 | + array( 'taxes' => $taxes ) |
|
| 208 | + ); |
|
| 220 | 209 | |
| 221 | - if ( $this->response['has_recurring'] ) { |
|
| 210 | + } |
|
| 222 | 211 | |
| 223 | - foreach ( $gateways as $i => $gateway ) { |
|
| 212 | + /** |
|
| 213 | + * Adds gateways to a response for submission refresh prices. |
|
| 214 | + * |
|
| 215 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 216 | + */ |
|
| 217 | + public function add_gateways( $submission ) { |
|
| 224 | 218 | |
| 225 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 226 | - unset( $gateways[ $i ] ); |
|
| 227 | - } |
|
| 219 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 228 | 220 | |
| 229 | - } |
|
| 221 | + if ( $this->response['has_recurring'] ) { |
|
| 230 | 222 | |
| 231 | - } |
|
| 223 | + foreach ( $gateways as $i => $gateway ) { |
|
| 232 | 224 | |
| 225 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 226 | + unset( $gateways[ $i ] ); |
|
| 227 | + } |
|
| 233 | 228 | |
| 234 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 235 | - $this->response = array_merge( |
|
| 236 | - $this->response, |
|
| 237 | - array( 'gateways' => $gateways ) |
|
| 238 | - ); |
|
| 229 | + } |
|
| 239 | 230 | |
| 240 | - } |
|
| 231 | + } |
|
| 241 | 232 | |
| 242 | - /** |
|
| 243 | - * Standardizes prices. |
|
| 244 | - * |
|
| 245 | - * @param int $item_id |
|
| 246 | - * @param float $item_total |
|
| 247 | - * @param string $discount_code |
|
| 248 | - * @param bool $recurring |
|
| 249 | - */ |
|
| 250 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 251 | 233 | |
| 252 | - $standardadized_price = $item_total; |
|
| 234 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 235 | + $this->response = array_merge( |
|
| 236 | + $this->response, |
|
| 237 | + array( 'gateways' => $gateways ) |
|
| 238 | + ); |
|
| 253 | 239 | |
| 254 | - // Do we have a $discount_code? |
|
| 255 | - if ( ! empty( $discount_code ) ) { |
|
| 240 | + } |
|
| 256 | 241 | |
| 257 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 242 | + /** |
|
| 243 | + * Standardizes prices. |
|
| 244 | + * |
|
| 245 | + * @param int $item_id |
|
| 246 | + * @param float $item_total |
|
| 247 | + * @param string $discount_code |
|
| 248 | + * @param bool $recurring |
|
| 249 | + */ |
|
| 250 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 251 | + |
|
| 252 | + $standardadized_price = $item_total; |
|
| 258 | 253 | |
| 259 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 260 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 261 | - } |
|
| 254 | + // Do we have a $discount_code? |
|
| 255 | + if ( ! empty( $discount_code ) ) { |
|
| 262 | 256 | |
| 263 | - } |
|
| 257 | + $discount = new WPInv_Discount( $discount_code ); |
|
| 264 | 258 | |
| 265 | - return max( 0, $standardadized_price ); |
|
| 259 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 260 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 261 | + } |
|
| 266 | 262 | |
| 267 | - } |
|
| 263 | + } |
|
| 268 | 264 | |
| 269 | - /** |
|
| 270 | - * Adds data to a response for submission refresh prices. |
|
| 271 | - * |
|
| 272 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 273 | - */ |
|
| 274 | - public function add_data( $submission ) { |
|
| 265 | + return max( 0, $standardadized_price ); |
|
| 275 | 266 | |
| 276 | - $this->response = array_merge( |
|
| 277 | - $this->response, |
|
| 278 | - array( |
|
| 279 | - 'js_data' => apply_filters( |
|
| 280 | - 'getpaid_submission_js_data', |
|
| 281 | - array( |
|
| 282 | - 'is_recurring' => $this->response['has_recurring'], |
|
| 283 | - ), |
|
| 284 | - $submission |
|
| 285 | - ) |
|
| 286 | - ) |
|
| 287 | - ); |
|
| 267 | + } |
|
| 288 | 268 | |
| 289 | - } |
|
| 269 | + /** |
|
| 270 | + * Adds data to a response for submission refresh prices. |
|
| 271 | + * |
|
| 272 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 273 | + */ |
|
| 274 | + public function add_data( $submission ) { |
|
| 275 | + |
|
| 276 | + $this->response = array_merge( |
|
| 277 | + $this->response, |
|
| 278 | + array( |
|
| 279 | + 'js_data' => apply_filters( |
|
| 280 | + 'getpaid_submission_js_data', |
|
| 281 | + array( |
|
| 282 | + 'is_recurring' => $this->response['has_recurring'], |
|
| 283 | + ), |
|
| 284 | + $submission |
|
| 285 | + ) |
|
| 286 | + ) |
|
| 287 | + ); |
|
| 288 | + |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission refresh prices class |
@@ -23,22 +23,22 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
| 25 | 25 | */ |
| 26 | - public function __construct( $submission ) { |
|
| 26 | + public function __construct($submission) { |
|
| 27 | 27 | |
| 28 | 28 | $this->response = array( |
| 29 | 29 | 'submission_id' => $submission->id, |
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
| 31 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | - $this->add_totals( $submission ); |
|
| 35 | - $this->add_texts( $submission ); |
|
| 36 | - $this->add_items( $submission ); |
|
| 37 | - $this->add_fees( $submission ); |
|
| 38 | - $this->add_discounts( $submission ); |
|
| 39 | - $this->add_taxes( $submission ); |
|
| 40 | - $this->add_gateways( $submission ); |
|
| 41 | - $this->add_data( $submission ); |
|
| 34 | + $this->add_totals($submission); |
|
| 35 | + $this->add_texts($submission); |
|
| 36 | + $this->add_items($submission); |
|
| 37 | + $this->add_fees($submission); |
|
| 38 | + $this->add_discounts($submission); |
|
| 39 | + $this->add_taxes($submission); |
|
| 40 | + $this->add_gateways($submission); |
|
| 41 | + $this->add_data($submission); |
|
| 42 | 42 | |
| 43 | 43 | } |
| 44 | 44 | |
@@ -47,30 +47,30 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param GetPaid_Payment_Form_Submission $submission |
| 49 | 49 | */ |
| 50 | - public function add_totals( $submission ) { |
|
| 50 | + public function add_totals($submission) { |
|
| 51 | 51 | |
| 52 | 52 | $this->response = array_merge( |
| 53 | 53 | $this->response, |
| 54 | 54 | array( |
| 55 | 55 | |
| 56 | 56 | 'totals' => array( |
| 57 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 58 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 59 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 60 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 61 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 62 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 57 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
| 58 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
| 59 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
| 60 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
| 61 | + 'total' => $submission->format_amount($submission->get_total()), |
|
| 62 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
| 63 | 63 | ), |
| 64 | 64 | |
| 65 | 65 | 'recurring' => array( |
| 66 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 67 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 68 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 69 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 70 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 66 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
| 67 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
| 68 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
| 69 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
| 70 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
| 71 | 71 | ), |
| 72 | 72 | |
| 73 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 73 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
| 74 | 74 | 'currency' => $submission->get_currency(), |
| 75 | 75 | |
| 76 | 76 | ) |
@@ -83,22 +83,22 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @param GetPaid_Payment_Form_Submission $submission |
| 85 | 85 | */ |
| 86 | - public function add_texts( $submission ) { |
|
| 86 | + public function add_texts($submission) { |
|
| 87 | 87 | |
| 88 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 88 | + $payable = $submission->format_amount($submission->get_total()); |
|
| 89 | 89 | |
| 90 | - if ( $submission->has_recurring != 0 ) { |
|
| 90 | + if ($submission->has_recurring != 0) { |
|
| 91 | 91 | |
| 92 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 93 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 92 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
| 93 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
| 94 | 94 | |
| 95 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 95 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
| 96 | 96 | $payable = "$payable / $period"; |
| 97 | 97 | } else { |
| 98 | 98 | $payable = sprintf( |
| 99 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 100 | - $submission->format_amount( $submission->get_total() ), |
|
| 101 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 99 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
| 100 | + $submission->format_amount($submission->get_total()), |
|
| 101 | + $submission->format_amount($submission->get_recurring_total()), |
|
| 102 | 102 | $period |
| 103 | 103 | ); |
| 104 | 104 | } |
@@ -109,14 +109,14 @@ discard block |
||
| 109 | 109 | '.getpaid-checkout-total-payable' => $payable, |
| 110 | 110 | ); |
| 111 | 111 | |
| 112 | - foreach ( $submission->get_items() as $item ) { |
|
| 112 | + foreach ($submission->get_items() as $item) { |
|
| 113 | 113 | $item_id = $item->get_id(); |
| 114 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 115 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 116 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 114 | + $initial_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false)); |
|
| 115 | + $recurring_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true)); |
|
| 116 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 119 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | |
@@ -125,19 +125,19 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @param GetPaid_Payment_Form_Submission $submission |
| 127 | 127 | */ |
| 128 | - public function add_items( $submission ) { |
|
| 128 | + public function add_items($submission) { |
|
| 129 | 129 | |
| 130 | 130 | // Add items. |
| 131 | 131 | $items = array(); |
| 132 | 132 | |
| 133 | - foreach ( $submission->get_items() as $item ) { |
|
| 133 | + foreach ($submission->get_items() as $item) { |
|
| 134 | 134 | $item_id = $item->get_id(); |
| 135 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 135 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $this->response = array_merge( |
| 139 | 139 | $this->response, |
| 140 | - array( 'items' => $items ) |
|
| 140 | + array('items' => $items) |
|
| 141 | 141 | ); |
| 142 | 142 | |
| 143 | 143 | } |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @param GetPaid_Payment_Form_Submission $submission |
| 149 | 149 | */ |
| 150 | - public function add_fees( $submission ) { |
|
| 150 | + public function add_fees($submission) { |
|
| 151 | 151 | |
| 152 | 152 | $fees = array(); |
| 153 | 153 | |
| 154 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
| 155 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 154 | + foreach ($submission->get_fees() as $name => $data) { |
|
| 155 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | $this->response = array_merge( |
| 159 | 159 | $this->response, |
| 160 | - array( 'fees' => $fees ) |
|
| 160 | + array('fees' => $fees) |
|
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | 163 | } |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @param GetPaid_Payment_Form_Submission $submission |
| 169 | 169 | */ |
| 170 | - public function add_discounts( $submission ) { |
|
| 170 | + public function add_discounts($submission) { |
|
| 171 | 171 | |
| 172 | 172 | $discounts = array(); |
| 173 | 173 | |
| 174 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 175 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 174 | + foreach ($submission->get_discounts() as $name => $data) { |
|
| 175 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $this->response = array_merge( |
| 179 | 179 | $this->response, |
| 180 | - array( 'discounts' => $discounts ) |
|
| 180 | + array('discounts' => $discounts) |
|
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | 183 | } |
@@ -187,24 +187,24 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @param GetPaid_Payment_Form_Submission $submission |
| 189 | 189 | */ |
| 190 | - public function add_taxes( $submission ) { |
|
| 190 | + public function add_taxes($submission) { |
|
| 191 | 191 | |
| 192 | 192 | $taxes = array(); |
| 193 | 193 | $markup = ''; |
| 194 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 195 | - $name = sanitize_text_field( $name ); |
|
| 196 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 194 | + foreach ($submission->get_taxes() as $name => $data) { |
|
| 195 | + $name = sanitize_text_field($name); |
|
| 196 | + $amount = $submission->format_amount($data['initial_tax']); |
|
| 197 | 197 | $taxes[$name] = $amount; |
| 198 | 198 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 201 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
| 202 | 202 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $this->response = array_merge( |
| 206 | 206 | $this->response, |
| 207 | - array( 'taxes' => $taxes ) |
|
| 207 | + array('taxes' => $taxes) |
|
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | 210 | } |
@@ -214,16 +214,16 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @param GetPaid_Payment_Form_Submission $submission |
| 216 | 216 | */ |
| 217 | - public function add_gateways( $submission ) { |
|
| 217 | + public function add_gateways($submission) { |
|
| 218 | 218 | |
| 219 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 219 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 220 | 220 | |
| 221 | - if ( $this->response['has_recurring'] ) { |
|
| 221 | + if ($this->response['has_recurring']) { |
|
| 222 | 222 | |
| 223 | - foreach ( $gateways as $i => $gateway ) { |
|
| 223 | + foreach ($gateways as $i => $gateway) { |
|
| 224 | 224 | |
| 225 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 226 | - unset( $gateways[ $i ] ); |
|
| 225 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
| 226 | + unset($gateways[$i]); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | } |
@@ -231,10 +231,10 @@ discard block |
||
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | |
| 234 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 234 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
| 235 | 235 | $this->response = array_merge( |
| 236 | 236 | $this->response, |
| 237 | - array( 'gateways' => $gateways ) |
|
| 237 | + array('gateways' => $gateways) |
|
| 238 | 238 | ); |
| 239 | 239 | |
| 240 | 240 | } |
@@ -247,22 +247,22 @@ discard block |
||
| 247 | 247 | * @param string $discount_code |
| 248 | 248 | * @param bool $recurring |
| 249 | 249 | */ |
| 250 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 250 | + public function standardize_price($item_id, $item_total, $discount_code, $recurring = false) { |
|
| 251 | 251 | |
| 252 | 252 | $standardadized_price = $item_total; |
| 253 | 253 | |
| 254 | 254 | // Do we have a $discount_code? |
| 255 | - if ( ! empty( $discount_code ) ) { |
|
| 255 | + if (!empty($discount_code)) { |
|
| 256 | 256 | |
| 257 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 257 | + $discount = new WPInv_Discount($discount_code); |
|
| 258 | 258 | |
| 259 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 260 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 259 | + if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) { |
|
| 260 | + $standardadized_price = $item_total - $discount->get_discounted_amount($item_total); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - return max( 0, $standardadized_price ); |
|
| 265 | + return max(0, $standardadized_price); |
|
| 266 | 266 | |
| 267 | 267 | } |
| 268 | 268 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | * @param GetPaid_Payment_Form_Submission $submission |
| 273 | 273 | */ |
| 274 | - public function add_data( $submission ) { |
|
| 274 | + public function add_data($submission) { |
|
| 275 | 275 | |
| 276 | 276 | $this->response = array_merge( |
| 277 | 277 | $this->response, |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | class InstalledVersions |
| 13 | 13 | { |
| 14 | 14 | private static $installed = array ( |
| 15 | - 'root' => |
|
| 16 | - array ( |
|
| 15 | + 'root' => |
|
| 16 | + array ( |
|
| 17 | 17 | 'pretty_version' => 'dev-master', |
| 18 | 18 | 'version' => 'dev-master', |
| 19 | 19 | 'aliases' => |
@@ -21,87 +21,87 @@ discard block |
||
| 21 | 21 | ), |
| 22 | 22 | 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
| 23 | 23 | 'name' => 'ayecode/invoicing', |
| 24 | - ), |
|
| 25 | - 'versions' => |
|
| 26 | - array ( |
|
| 24 | + ), |
|
| 25 | + 'versions' => |
|
| 26 | + array ( |
|
| 27 | 27 | 'ayecode/ayecode-connect-helper' => |
| 28 | 28 | array ( |
| 29 | - 'pretty_version' => '1.0.3', |
|
| 30 | - 'version' => '1.0.3.0', |
|
| 31 | - 'aliases' => |
|
| 32 | - array ( |
|
| 33 | - ), |
|
| 34 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 29 | + 'pretty_version' => '1.0.3', |
|
| 30 | + 'version' => '1.0.3.0', |
|
| 31 | + 'aliases' => |
|
| 32 | + array ( |
|
| 33 | + ), |
|
| 34 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 35 | 35 | ), |
| 36 | 36 | 'ayecode/invoicing' => |
| 37 | 37 | array ( |
| 38 | - 'pretty_version' => 'dev-master', |
|
| 39 | - 'version' => 'dev-master', |
|
| 40 | - 'aliases' => |
|
| 41 | - array ( |
|
| 42 | - ), |
|
| 43 | - 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
|
| 38 | + 'pretty_version' => 'dev-master', |
|
| 39 | + 'version' => 'dev-master', |
|
| 40 | + 'aliases' => |
|
| 41 | + array ( |
|
| 42 | + ), |
|
| 43 | + 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
|
| 44 | 44 | ), |
| 45 | 45 | 'ayecode/wp-ayecode-ui' => |
| 46 | 46 | array ( |
| 47 | - 'pretty_version' => '0.1.46', |
|
| 48 | - 'version' => '0.1.46.0', |
|
| 49 | - 'aliases' => |
|
| 50 | - array ( |
|
| 51 | - ), |
|
| 52 | - 'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3', |
|
| 47 | + 'pretty_version' => '0.1.46', |
|
| 48 | + 'version' => '0.1.46.0', |
|
| 49 | + 'aliases' => |
|
| 50 | + array ( |
|
| 51 | + ), |
|
| 52 | + 'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3', |
|
| 53 | 53 | ), |
| 54 | 54 | 'ayecode/wp-font-awesome-settings' => |
| 55 | 55 | array ( |
| 56 | - 'pretty_version' => '1.0.12', |
|
| 57 | - 'version' => '1.0.12.0', |
|
| 58 | - 'aliases' => |
|
| 59 | - array ( |
|
| 60 | - ), |
|
| 61 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 56 | + 'pretty_version' => '1.0.12', |
|
| 57 | + 'version' => '1.0.12.0', |
|
| 58 | + 'aliases' => |
|
| 59 | + array ( |
|
| 60 | + ), |
|
| 61 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 62 | 62 | ), |
| 63 | 63 | 'ayecode/wp-super-duper' => |
| 64 | 64 | array ( |
| 65 | - 'pretty_version' => '1.0.24', |
|
| 66 | - 'version' => '1.0.24.0', |
|
| 67 | - 'aliases' => |
|
| 68 | - array ( |
|
| 69 | - ), |
|
| 70 | - 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
|
| 65 | + 'pretty_version' => '1.0.24', |
|
| 66 | + 'version' => '1.0.24.0', |
|
| 67 | + 'aliases' => |
|
| 68 | + array ( |
|
| 69 | + ), |
|
| 70 | + 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
|
| 71 | 71 | ), |
| 72 | 72 | 'composer/installers' => |
| 73 | 73 | array ( |
| 74 | - 'pretty_version' => 'v1.10.0', |
|
| 75 | - 'version' => '1.10.0.0', |
|
| 76 | - 'aliases' => |
|
| 77 | - array ( |
|
| 78 | - ), |
|
| 79 | - 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 74 | + 'pretty_version' => 'v1.10.0', |
|
| 75 | + 'version' => '1.10.0.0', |
|
| 76 | + 'aliases' => |
|
| 77 | + array ( |
|
| 78 | + ), |
|
| 79 | + 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 80 | 80 | ), |
| 81 | 81 | 'maxmind-db/reader' => |
| 82 | 82 | array ( |
| 83 | - 'pretty_version' => 'v1.6.0', |
|
| 84 | - 'version' => '1.6.0.0', |
|
| 85 | - 'aliases' => |
|
| 86 | - array ( |
|
| 87 | - ), |
|
| 88 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 83 | + 'pretty_version' => 'v1.6.0', |
|
| 84 | + 'version' => '1.6.0.0', |
|
| 85 | + 'aliases' => |
|
| 86 | + array ( |
|
| 87 | + ), |
|
| 88 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 89 | 89 | ), |
| 90 | 90 | 'roundcube/plugin-installer' => |
| 91 | 91 | array ( |
| 92 | - 'replaced' => |
|
| 93 | - array ( |
|
| 92 | + 'replaced' => |
|
| 93 | + array ( |
|
| 94 | 94 | 0 => '*', |
| 95 | - ), |
|
| 95 | + ), |
|
| 96 | 96 | ), |
| 97 | 97 | 'shama/baton' => |
| 98 | 98 | array ( |
| 99 | - 'replaced' => |
|
| 100 | - array ( |
|
| 99 | + 'replaced' => |
|
| 100 | + array ( |
|
| 101 | 101 | 0 => '*', |
| 102 | - ), |
|
| 102 | + ), |
|
| 103 | + ), |
|
| 103 | 104 | ), |
| 104 | - ), |
|
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | |
@@ -11,93 +11,93 @@ |
||
| 11 | 11 | |
| 12 | 12 | class InstalledVersions |
| 13 | 13 | { |
| 14 | -private static $installed = array ( |
|
| 14 | +private static $installed = array( |
|
| 15 | 15 | 'root' => |
| 16 | - array ( |
|
| 16 | + array( |
|
| 17 | 17 | 'pretty_version' => 'dev-master', |
| 18 | 18 | 'version' => 'dev-master', |
| 19 | 19 | 'aliases' => |
| 20 | - array ( |
|
| 20 | + array( |
|
| 21 | 21 | ), |
| 22 | 22 | 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
| 23 | 23 | 'name' => 'ayecode/invoicing', |
| 24 | 24 | ), |
| 25 | 25 | 'versions' => |
| 26 | - array ( |
|
| 26 | + array( |
|
| 27 | 27 | 'ayecode/ayecode-connect-helper' => |
| 28 | - array ( |
|
| 28 | + array( |
|
| 29 | 29 | 'pretty_version' => '1.0.3', |
| 30 | 30 | 'version' => '1.0.3.0', |
| 31 | 31 | 'aliases' => |
| 32 | - array ( |
|
| 32 | + array( |
|
| 33 | 33 | ), |
| 34 | 34 | 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
| 35 | 35 | ), |
| 36 | 36 | 'ayecode/invoicing' => |
| 37 | - array ( |
|
| 37 | + array( |
|
| 38 | 38 | 'pretty_version' => 'dev-master', |
| 39 | 39 | 'version' => 'dev-master', |
| 40 | 40 | 'aliases' => |
| 41 | - array ( |
|
| 41 | + array( |
|
| 42 | 42 | ), |
| 43 | 43 | 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
| 44 | 44 | ), |
| 45 | 45 | 'ayecode/wp-ayecode-ui' => |
| 46 | - array ( |
|
| 46 | + array( |
|
| 47 | 47 | 'pretty_version' => '0.1.46', |
| 48 | 48 | 'version' => '0.1.46.0', |
| 49 | 49 | 'aliases' => |
| 50 | - array ( |
|
| 50 | + array( |
|
| 51 | 51 | ), |
| 52 | 52 | 'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3', |
| 53 | 53 | ), |
| 54 | 54 | 'ayecode/wp-font-awesome-settings' => |
| 55 | - array ( |
|
| 55 | + array( |
|
| 56 | 56 | 'pretty_version' => '1.0.12', |
| 57 | 57 | 'version' => '1.0.12.0', |
| 58 | 58 | 'aliases' => |
| 59 | - array ( |
|
| 59 | + array( |
|
| 60 | 60 | ), |
| 61 | 61 | 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
| 62 | 62 | ), |
| 63 | 63 | 'ayecode/wp-super-duper' => |
| 64 | - array ( |
|
| 64 | + array( |
|
| 65 | 65 | 'pretty_version' => '1.0.24', |
| 66 | 66 | 'version' => '1.0.24.0', |
| 67 | 67 | 'aliases' => |
| 68 | - array ( |
|
| 68 | + array( |
|
| 69 | 69 | ), |
| 70 | 70 | 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
| 71 | 71 | ), |
| 72 | 72 | 'composer/installers' => |
| 73 | - array ( |
|
| 73 | + array( |
|
| 74 | 74 | 'pretty_version' => 'v1.10.0', |
| 75 | 75 | 'version' => '1.10.0.0', |
| 76 | 76 | 'aliases' => |
| 77 | - array ( |
|
| 77 | + array( |
|
| 78 | 78 | ), |
| 79 | 79 | 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
| 80 | 80 | ), |
| 81 | 81 | 'maxmind-db/reader' => |
| 82 | - array ( |
|
| 82 | + array( |
|
| 83 | 83 | 'pretty_version' => 'v1.6.0', |
| 84 | 84 | 'version' => '1.6.0.0', |
| 85 | 85 | 'aliases' => |
| 86 | - array ( |
|
| 86 | + array( |
|
| 87 | 87 | ), |
| 88 | 88 | 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
| 89 | 89 | ), |
| 90 | 90 | 'roundcube/plugin-installer' => |
| 91 | - array ( |
|
| 91 | + array( |
|
| 92 | 92 | 'replaced' => |
| 93 | - array ( |
|
| 93 | + array( |
|
| 94 | 94 | 0 => '*', |
| 95 | 95 | ), |
| 96 | 96 | ), |
| 97 | 97 | 'shama/baton' => |
| 98 | - array ( |
|
| 98 | + array( |
|
| 99 | 99 | 'replaced' => |
| 100 | - array ( |
|
| 100 | + array( |
|
| 101 | 101 | 0 => '*', |
| 102 | 102 | ), |
| 103 | 103 | ), |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php return array ( |
| 2 | - 'root' => |
|
| 3 | - array ( |
|
| 2 | + 'root' => |
|
| 3 | + array ( |
|
| 4 | 4 | 'pretty_version' => 'dev-master', |
| 5 | 5 | 'version' => 'dev-master', |
| 6 | 6 | 'aliases' => |
@@ -8,85 +8,85 @@ discard block |
||
| 8 | 8 | ), |
| 9 | 9 | 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
| 10 | 10 | 'name' => 'ayecode/invoicing', |
| 11 | - ), |
|
| 12 | - 'versions' => |
|
| 13 | - array ( |
|
| 11 | + ), |
|
| 12 | + 'versions' => |
|
| 13 | + array ( |
|
| 14 | 14 | 'ayecode/ayecode-connect-helper' => |
| 15 | 15 | array ( |
| 16 | - 'pretty_version' => '1.0.3', |
|
| 17 | - 'version' => '1.0.3.0', |
|
| 18 | - 'aliases' => |
|
| 19 | - array ( |
|
| 20 | - ), |
|
| 21 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 16 | + 'pretty_version' => '1.0.3', |
|
| 17 | + 'version' => '1.0.3.0', |
|
| 18 | + 'aliases' => |
|
| 19 | + array ( |
|
| 20 | + ), |
|
| 21 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 22 | 22 | ), |
| 23 | 23 | 'ayecode/invoicing' => |
| 24 | 24 | array ( |
| 25 | - 'pretty_version' => 'dev-master', |
|
| 26 | - 'version' => 'dev-master', |
|
| 27 | - 'aliases' => |
|
| 28 | - array ( |
|
| 29 | - ), |
|
| 30 | - 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
|
| 25 | + 'pretty_version' => 'dev-master', |
|
| 26 | + 'version' => 'dev-master', |
|
| 27 | + 'aliases' => |
|
| 28 | + array ( |
|
| 29 | + ), |
|
| 30 | + 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
|
| 31 | 31 | ), |
| 32 | 32 | 'ayecode/wp-ayecode-ui' => |
| 33 | 33 | array ( |
| 34 | - 'pretty_version' => '0.1.46', |
|
| 35 | - 'version' => '0.1.46.0', |
|
| 36 | - 'aliases' => |
|
| 37 | - array ( |
|
| 38 | - ), |
|
| 39 | - 'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3', |
|
| 34 | + 'pretty_version' => '0.1.46', |
|
| 35 | + 'version' => '0.1.46.0', |
|
| 36 | + 'aliases' => |
|
| 37 | + array ( |
|
| 38 | + ), |
|
| 39 | + 'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3', |
|
| 40 | 40 | ), |
| 41 | 41 | 'ayecode/wp-font-awesome-settings' => |
| 42 | 42 | array ( |
| 43 | - 'pretty_version' => '1.0.12', |
|
| 44 | - 'version' => '1.0.12.0', |
|
| 45 | - 'aliases' => |
|
| 46 | - array ( |
|
| 47 | - ), |
|
| 48 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 43 | + 'pretty_version' => '1.0.12', |
|
| 44 | + 'version' => '1.0.12.0', |
|
| 45 | + 'aliases' => |
|
| 46 | + array ( |
|
| 47 | + ), |
|
| 48 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 49 | 49 | ), |
| 50 | 50 | 'ayecode/wp-super-duper' => |
| 51 | 51 | array ( |
| 52 | - 'pretty_version' => '1.0.24', |
|
| 53 | - 'version' => '1.0.24.0', |
|
| 54 | - 'aliases' => |
|
| 55 | - array ( |
|
| 56 | - ), |
|
| 57 | - 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
|
| 52 | + 'pretty_version' => '1.0.24', |
|
| 53 | + 'version' => '1.0.24.0', |
|
| 54 | + 'aliases' => |
|
| 55 | + array ( |
|
| 56 | + ), |
|
| 57 | + 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
|
| 58 | 58 | ), |
| 59 | 59 | 'composer/installers' => |
| 60 | 60 | array ( |
| 61 | - 'pretty_version' => 'v1.10.0', |
|
| 62 | - 'version' => '1.10.0.0', |
|
| 63 | - 'aliases' => |
|
| 64 | - array ( |
|
| 65 | - ), |
|
| 66 | - 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 61 | + 'pretty_version' => 'v1.10.0', |
|
| 62 | + 'version' => '1.10.0.0', |
|
| 63 | + 'aliases' => |
|
| 64 | + array ( |
|
| 65 | + ), |
|
| 66 | + 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 67 | 67 | ), |
| 68 | 68 | 'maxmind-db/reader' => |
| 69 | 69 | array ( |
| 70 | - 'pretty_version' => 'v1.6.0', |
|
| 71 | - 'version' => '1.6.0.0', |
|
| 72 | - 'aliases' => |
|
| 73 | - array ( |
|
| 74 | - ), |
|
| 75 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 70 | + 'pretty_version' => 'v1.6.0', |
|
| 71 | + 'version' => '1.6.0.0', |
|
| 72 | + 'aliases' => |
|
| 73 | + array ( |
|
| 74 | + ), |
|
| 75 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 76 | 76 | ), |
| 77 | 77 | 'roundcube/plugin-installer' => |
| 78 | 78 | array ( |
| 79 | - 'replaced' => |
|
| 80 | - array ( |
|
| 79 | + 'replaced' => |
|
| 80 | + array ( |
|
| 81 | 81 | 0 => '*', |
| 82 | - ), |
|
| 82 | + ), |
|
| 83 | 83 | ), |
| 84 | 84 | 'shama/baton' => |
| 85 | 85 | array ( |
| 86 | - 'replaced' => |
|
| 87 | - array ( |
|
| 86 | + 'replaced' => |
|
| 87 | + array ( |
|
| 88 | 88 | 0 => '*', |
| 89 | - ), |
|
| 89 | + ), |
|
| 90 | + ), |
|
| 90 | 91 | ), |
| 91 | - ), |
|
| 92 | 92 | ); |
@@ -1,90 +1,90 @@ |
||
| 1 | -<?php return array ( |
|
| 1 | +<?php return array( |
|
| 2 | 2 | 'root' => |
| 3 | - array ( |
|
| 3 | + array( |
|
| 4 | 4 | 'pretty_version' => 'dev-master', |
| 5 | 5 | 'version' => 'dev-master', |
| 6 | 6 | 'aliases' => |
| 7 | - array ( |
|
| 7 | + array( |
|
| 8 | 8 | ), |
| 9 | 9 | 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
| 10 | 10 | 'name' => 'ayecode/invoicing', |
| 11 | 11 | ), |
| 12 | 12 | 'versions' => |
| 13 | - array ( |
|
| 13 | + array( |
|
| 14 | 14 | 'ayecode/ayecode-connect-helper' => |
| 15 | - array ( |
|
| 15 | + array( |
|
| 16 | 16 | 'pretty_version' => '1.0.3', |
| 17 | 17 | 'version' => '1.0.3.0', |
| 18 | 18 | 'aliases' => |
| 19 | - array ( |
|
| 19 | + array( |
|
| 20 | 20 | ), |
| 21 | 21 | 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
| 22 | 22 | ), |
| 23 | 23 | 'ayecode/invoicing' => |
| 24 | - array ( |
|
| 24 | + array( |
|
| 25 | 25 | 'pretty_version' => 'dev-master', |
| 26 | 26 | 'version' => 'dev-master', |
| 27 | 27 | 'aliases' => |
| 28 | - array ( |
|
| 28 | + array( |
|
| 29 | 29 | ), |
| 30 | 30 | 'reference' => 'fb4f29a148b1524852836f00b2884f287f708067', |
| 31 | 31 | ), |
| 32 | 32 | 'ayecode/wp-ayecode-ui' => |
| 33 | - array ( |
|
| 33 | + array( |
|
| 34 | 34 | 'pretty_version' => '0.1.46', |
| 35 | 35 | 'version' => '0.1.46.0', |
| 36 | 36 | 'aliases' => |
| 37 | - array ( |
|
| 37 | + array( |
|
| 38 | 38 | ), |
| 39 | 39 | 'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3', |
| 40 | 40 | ), |
| 41 | 41 | 'ayecode/wp-font-awesome-settings' => |
| 42 | - array ( |
|
| 42 | + array( |
|
| 43 | 43 | 'pretty_version' => '1.0.12', |
| 44 | 44 | 'version' => '1.0.12.0', |
| 45 | 45 | 'aliases' => |
| 46 | - array ( |
|
| 46 | + array( |
|
| 47 | 47 | ), |
| 48 | 48 | 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
| 49 | 49 | ), |
| 50 | 50 | 'ayecode/wp-super-duper' => |
| 51 | - array ( |
|
| 51 | + array( |
|
| 52 | 52 | 'pretty_version' => '1.0.24', |
| 53 | 53 | 'version' => '1.0.24.0', |
| 54 | 54 | 'aliases' => |
| 55 | - array ( |
|
| 55 | + array( |
|
| 56 | 56 | ), |
| 57 | 57 | 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
| 58 | 58 | ), |
| 59 | 59 | 'composer/installers' => |
| 60 | - array ( |
|
| 60 | + array( |
|
| 61 | 61 | 'pretty_version' => 'v1.10.0', |
| 62 | 62 | 'version' => '1.10.0.0', |
| 63 | 63 | 'aliases' => |
| 64 | - array ( |
|
| 64 | + array( |
|
| 65 | 65 | ), |
| 66 | 66 | 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
| 67 | 67 | ), |
| 68 | 68 | 'maxmind-db/reader' => |
| 69 | - array ( |
|
| 69 | + array( |
|
| 70 | 70 | 'pretty_version' => 'v1.6.0', |
| 71 | 71 | 'version' => '1.6.0.0', |
| 72 | 72 | 'aliases' => |
| 73 | - array ( |
|
| 73 | + array( |
|
| 74 | 74 | ), |
| 75 | 75 | 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
| 76 | 76 | ), |
| 77 | 77 | 'roundcube/plugin-installer' => |
| 78 | - array ( |
|
| 78 | + array( |
|
| 79 | 79 | 'replaced' => |
| 80 | - array ( |
|
| 80 | + array( |
|
| 81 | 81 | 0 => '*', |
| 82 | 82 | ), |
| 83 | 83 | ), |
| 84 | 84 | 'shama/baton' => |
| 85 | - array ( |
|
| 85 | + array( |
|
| 86 | 86 | 'replaced' => |
| 87 | - array ( |
|
| 87 | + array( |
|
| 88 | 88 | 0 => '*', |
| 89 | 89 | ), |
| 90 | 90 | ), |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | * Bail if we are not in WP. |
| 8 | 8 | */ |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; |
|
| 10 | + exit; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Set the version only if its the current newest while loading. |
| 15 | 15 | */ |
| 16 | 16 | add_action('after_setup_theme', function () { |
| 17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | - $this_version = "0.1.46"; |
|
| 19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | - $ayecode_ui_version = $this_version ; |
|
| 21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | - } |
|
| 17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | + $this_version = "0.1.46"; |
|
| 19 | + if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | + $ayecode_ui_version = $this_version ; |
|
| 21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | + } |
|
| 23 | 23 | },0); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
| 27 | 27 | */ |
| 28 | 28 | add_action('after_setup_theme', function () { |
| 29 | - global $ayecode_ui_file_key; |
|
| 30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | - } |
|
| 29 | + global $ayecode_ui_file_key; |
|
| 30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | + } |
|
| 34 | 34 | },1); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Add the function that calls the class. |
| 38 | 38 | */ |
| 39 | 39 | if(!function_exists('aui')){ |
| 40 | - function aui(){ |
|
| 41 | - if(!class_exists("AUI",false)){ |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - return AUI::instance(); |
|
| 45 | - } |
|
| 40 | + function aui(){ |
|
| 41 | + if(!class_exists("AUI",false)){ |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + return AUI::instance(); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |
@@ -6,39 +6,39 @@ |
||
| 6 | 6 | /** |
| 7 | 7 | * Bail if we are not in WP. |
| 8 | 8 | */ |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if (!defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Set the version only if its the current newest while loading. |
| 15 | 15 | */ |
| 16 | -add_action('after_setup_theme', function () { |
|
| 17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 16 | +add_action('after_setup_theme', function() { |
|
| 17 | + global $ayecode_ui_version, $ayecode_ui_file_key; |
|
| 18 | 18 | $this_version = "0.1.46"; |
| 19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | - $ayecode_ui_version = $this_version ; |
|
| 21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 19 | + if (version_compare($this_version, $ayecode_ui_version, '>')) { |
|
| 20 | + $ayecode_ui_version = $this_version; |
|
| 21 | + $ayecode_ui_file_key = wp_hash(__FILE__); |
|
| 22 | 22 | } |
| 23 | 23 | },0); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
| 27 | 27 | */ |
| 28 | -add_action('after_setup_theme', function () { |
|
| 28 | +add_action('after_setup_theme', function() { |
|
| 29 | 29 | global $ayecode_ui_file_key; |
| 30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 30 | + if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) { |
|
| 31 | + include_once(dirname(__FILE__) . '/includes/class-aui.php'); |
|
| 32 | + include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php'); |
|
| 33 | 33 | } |
| 34 | 34 | },1); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Add the function that calls the class. |
| 38 | 38 | */ |
| 39 | -if(!function_exists('aui')){ |
|
| 40 | - function aui(){ |
|
| 41 | - if(!class_exists("AUI",false)){ |
|
| 39 | +if (!function_exists('aui')) { |
|
| 40 | + function aui() { |
|
| 41 | + if (!class_exists("AUI", false)) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | return AUI::instance(); |