@@ -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 | * Authorize.net Payment Gateway class. |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @var array |
| 63 | 63 | */ |
| 64 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 64 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * URL to view a transaction. |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function __construct() { |
| 77 | 77 | |
| 78 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
| 79 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
| 80 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
| 78 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
| 79 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
| 80 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
| 81 | 81 | |
| 82 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
| 83 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
| 82 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
| 83 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
| 84 | 84 | parent::__construct(); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | * @param int $invoice_id 0 or invoice id. |
| 91 | 91 | * @param GetPaid_Payment_Form $form Current payment form. |
| 92 | 92 | */ |
| 93 | - public function payment_fields( $invoice_id, $form ) { |
|
| 93 | + public function payment_fields($invoice_id, $form) { |
|
| 94 | 94 | |
| 95 | 95 | // Let the user select a payment method. |
| 96 | 96 | $this->saved_payment_methods(); |
| 97 | 97 | |
| 98 | 98 | // Show the credit card entry form. |
| 99 | - $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
| 99 | + $this->new_payment_method_entry($this->get_cc_form(true)); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -109,79 +109,79 @@ discard block |
||
| 109 | 109 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 110 | 110 | * @return string|WP_Error Payment profile id. |
| 111 | 111 | */ |
| 112 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 112 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
| 113 | 113 | |
| 114 | 114 | // Remove non-digits from the number |
| 115 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
| 115 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
| 116 | 116 | |
| 117 | 117 | // Generate args. |
| 118 | 118 | $args = array( |
| 119 | 119 | 'createCustomerProfileRequest' => array( |
| 120 | 120 | 'merchantAuthentication' => $this->get_auth_params(), |
| 121 | 121 | 'profile' => array( |
| 122 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
| 123 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
| 124 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
| 122 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
| 123 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
| 124 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
| 125 | 125 | 'paymentProfiles' => array( |
| 126 | 126 | 'customerType' => 'individual', |
| 127 | 127 | |
| 128 | 128 | // Billing information. |
| 129 | 129 | 'billTo' => array( |
| 130 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
| 131 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
| 132 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
| 133 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
| 134 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
| 135 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
| 136 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
| 130 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
| 131 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
| 132 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
| 133 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
| 134 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
| 135 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
| 136 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
| 137 | 137 | ), |
| 138 | 138 | |
| 139 | 139 | // Payment information. |
| 140 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
| 140 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
| 141 | 141 | ), |
| 142 | 142 | ), |
| 143 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
| 143 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
| 144 | 144 | ), |
| 145 | 145 | ); |
| 146 | 146 | |
| 147 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
| 147 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
| 148 | 148 | |
| 149 | - if ( is_wp_error( $response ) ) { |
|
| 149 | + if (is_wp_error($response)) { |
|
| 150 | 150 | |
| 151 | 151 | // In case the payment profile already exists remotely. |
| 152 | - if ( 'dup_payment_profile' === $response->get_error_code() ) { |
|
| 153 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
| 154 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
| 155 | - return strtok( '.' ); |
|
| 152 | + if ('dup_payment_profile' === $response->get_error_code()) { |
|
| 153 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
| 154 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
| 155 | + return strtok('.'); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // In case the customer profile already exists remotely. |
| 159 | - if ( 'E00039' === $response->get_error_code() ) { |
|
| 160 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
| 161 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
| 162 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
| 159 | + if ('E00039' === $response->get_error_code()) { |
|
| 160 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
| 161 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
| 162 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | return $response; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
| 168 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
| 169 | 169 | |
| 170 | 170 | // Save the payment token. |
| 171 | - if ( $save ) { |
|
| 171 | + if ($save) { |
|
| 172 | 172 | $this->save_token( |
| 173 | 173 | array( |
| 174 | 174 | 'id' => $response->customerPaymentProfileIdList[0], |
| 175 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
| 175 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
| 176 | 176 | 'default' => true, |
| 177 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
| 177 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
| 178 | 178 | ) |
| 179 | 179 | ); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Add a note about the validation response. |
| 183 | 183 | $invoice->add_note( |
| 184 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
| 184 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
| 185 | 185 | false, |
| 186 | 186 | false, |
| 187 | 187 | true |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return string|WP_Error Profile id. |
| 199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
| 200 | 200 | */ |
| 201 | - public function get_customer_profile( $profile_id ) { |
|
| 201 | + public function get_customer_profile($profile_id) { |
|
| 202 | 202 | |
| 203 | 203 | // Generate args. |
| 204 | 204 | $args = array( |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | ), |
| 209 | 209 | ); |
| 210 | 210 | |
| 211 | - return $this->post( $args, false ); |
|
| 211 | + return $this->post($args, false); |
|
| 212 | 212 | |
| 213 | 213 | } |
| 214 | 214 | |
@@ -223,18 +223,18 @@ discard block |
||
| 223 | 223 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 224 | 224 | * @return string|WP_Error Profile id. |
| 225 | 225 | */ |
| 226 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 226 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
| 227 | 227 | |
| 228 | 228 | // Remove non-digits from the number |
| 229 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
| 229 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
| 230 | 230 | |
| 231 | 231 | // Prepare card details. |
| 232 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
| 232 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
| 233 | 233 | |
| 234 | 234 | // Authorize.NET does not support saving the same card twice. |
| 235 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
| 235 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
| 236 | 236 | |
| 237 | - if ( $cached_information ) { |
|
| 237 | + if ($cached_information) { |
|
| 238 | 238 | return $cached_information; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -247,34 +247,34 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | // Billing information. |
| 249 | 249 | 'billTo' => array( |
| 250 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
| 251 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
| 252 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
| 253 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
| 254 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
| 255 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
| 256 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
| 250 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
| 251 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
| 252 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
| 253 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
| 254 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
| 255 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
| 256 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
| 257 | 257 | ), |
| 258 | 258 | |
| 259 | 259 | // Payment information. |
| 260 | 260 | 'payment' => $payment_information, |
| 261 | 261 | ), |
| 262 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
| 262 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
| 263 | 263 | ), |
| 264 | 264 | ); |
| 265 | 265 | |
| 266 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
| 266 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
| 267 | 267 | |
| 268 | - if ( is_wp_error( $response ) ) { |
|
| 268 | + if (is_wp_error($response)) { |
|
| 269 | 269 | |
| 270 | 270 | // In case the payment profile already exists remotely. |
| 271 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
| 272 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
| 273 | - $payment_profile_id = strtok( '.' ); |
|
| 274 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
| 271 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
| 272 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
| 273 | + $payment_profile_id = strtok('.'); |
|
| 274 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
| 275 | 275 | |
| 276 | 276 | // Cache payment profile id. |
| 277 | - $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
| 277 | + $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
| 278 | 278 | |
| 279 | 279 | return $payment_profile_id; |
| 280 | 280 | } |
@@ -283,29 +283,29 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // Save the payment token. |
| 286 | - if ( $save ) { |
|
| 286 | + if ($save) { |
|
| 287 | 287 | $this->save_token( |
| 288 | 288 | array( |
| 289 | 289 | 'id' => $response->customerPaymentProfileId, |
| 290 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
| 290 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
| 291 | 291 | 'default' => true, |
| 292 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
| 292 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
| 293 | 293 | ) |
| 294 | 294 | ); |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Cache payment profile id. |
| 298 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
| 298 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
| 299 | 299 | |
| 300 | 300 | // Add a note about the validation response. |
| 301 | 301 | $invoice->add_note( |
| 302 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
| 302 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
| 303 | 303 | false, |
| 304 | 304 | false, |
| 305 | 305 | true |
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
| 308 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
| 309 | 309 | |
| 310 | 310 | return $response->customerPaymentProfileId; |
| 311 | 311 | } |
@@ -317,12 +317,12 @@ discard block |
||
| 317 | 317 | * @param array $payment_details. |
| 318 | 318 | * @return array|false Profile id. |
| 319 | 319 | */ |
| 320 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 320 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
| 321 | 321 | |
| 322 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
| 323 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
| 322 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
| 323 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
| 324 | 324 | |
| 325 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
| 325 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
| 326 | 326 | return false; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -331,13 +331,13 @@ discard block |
||
| 331 | 331 | 'getCustomerPaymentProfileRequest' => array( |
| 332 | 332 | 'merchantAuthentication' => $this->get_auth_params(), |
| 333 | 333 | 'customerProfileId' => $customer_profile, |
| 334 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
| 334 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
| 335 | 335 | ), |
| 336 | 336 | ); |
| 337 | 337 | |
| 338 | - $response = $this->post( $args, $invoice ); |
|
| 338 | + $response = $this->post($args, $invoice); |
|
| 339 | 339 | |
| 340 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
| 340 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |
@@ -348,14 +348,14 @@ discard block |
||
| 348 | 348 | * @param array $payment_details. |
| 349 | 349 | * @param string $payment_profile_id. |
| 350 | 350 | */ |
| 351 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 351 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
| 352 | 352 | |
| 353 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
| 354 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
| 355 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
| 353 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
| 354 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
| 355 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
| 356 | 356 | |
| 357 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
| 358 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
| 357 | + $cached_information[$payment_details] = $payment_profile_id; |
|
| 358 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
| 359 | 359 | |
| 360 | 360 | } |
| 361 | 361 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return string|WP_Error Profile id. |
| 369 | 369 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 370 | 370 | */ |
| 371 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 371 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
| 372 | 372 | |
| 373 | 373 | // Generate args. |
| 374 | 374 | $args = array( |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | ), |
| 380 | 380 | ); |
| 381 | 381 | |
| 382 | - return $this->post( $args, false ); |
|
| 382 | + return $this->post($args, false); |
|
| 383 | 383 | |
| 384 | 384 | } |
| 385 | 385 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 393 | 393 | * @return WP_Error|object |
| 394 | 394 | */ |
| 395 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 395 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
| 396 | 396 | |
| 397 | 397 | // Generate args. |
| 398 | 398 | $args = array( |
@@ -412,28 +412,28 @@ discard block |
||
| 412 | 412 | ), |
| 413 | 413 | ), |
| 414 | 414 | 'order' => array( |
| 415 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
| 415 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
| 416 | 416 | ), |
| 417 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
| 417 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
| 418 | 418 | 'tax' => array( |
| 419 | 419 | 'amount' => $invoice->get_total_tax(), |
| 420 | - 'name' => __( 'TAX', 'invoicing' ), |
|
| 420 | + 'name' => __('TAX', 'invoicing'), |
|
| 421 | 421 | ), |
| 422 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
| 422 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
| 423 | 423 | 'customer' => array( |
| 424 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
| 425 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
| 424 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
| 425 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
| 426 | 426 | ), |
| 427 | 427 | 'customerIP' => $invoice->get_ip(), |
| 428 | 428 | ), |
| 429 | 429 | ), |
| 430 | 430 | ); |
| 431 | 431 | |
| 432 | - if ( 0 == $invoice->get_total_tax() ) { |
|
| 433 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
| 432 | + if (0 == $invoice->get_total_tax()) { |
|
| 433 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
| 436 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
| 437 | 437 | |
| 438 | 438 | } |
| 439 | 439 | |
@@ -443,31 +443,31 @@ discard block |
||
| 443 | 443 | * @param stdClass $result Api response. |
| 444 | 444 | * @param WPInv_Invoice $invoice Invoice. |
| 445 | 445 | */ |
| 446 | - public function process_charge_response( $result, $invoice ) { |
|
| 446 | + public function process_charge_response($result, $invoice) { |
|
| 447 | 447 | |
| 448 | 448 | wpinv_clear_errors(); |
| 449 | 449 | $response_code = (int) $result->transactionResponse->responseCode; |
| 450 | 450 | |
| 451 | - $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true ); |
|
| 451 | + $invoice->add_note('Transaction Response: ' . print_r($result->transactionResponse, true), false, false, true); |
|
| 452 | 452 | |
| 453 | 453 | // Succeeded. |
| 454 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 454 | + if (1 == $response_code || 4 == $response_code) { |
|
| 455 | 455 | |
| 456 | 456 | // Maybe set a transaction id. |
| 457 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 458 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 457 | + if (!empty($result->transactionResponse->transId)) { |
|
| 458 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 461 | + $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
| 462 | 462 | |
| 463 | - if ( 1 == $response_code ) { |
|
| 463 | + if (1 == $response_code) { |
|
| 464 | 464 | return $invoice->mark_paid(); |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 467 | + $invoice->set_status('wpi-onhold'); |
|
| 468 | 468 | $invoice->add_note( |
| 469 | 469 | sprintf( |
| 470 | - __( 'Held for review: %s', 'invoicing' ), |
|
| 470 | + __('Held for review: %s', 'invoicing'), |
|
| 471 | 471 | $result->transactionResponse->messages->message[0]->description |
| 472 | 472 | ) |
| 473 | 473 | ); |
@@ -476,11 +476,11 @@ discard block |
||
| 476 | 476 | |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - wpinv_set_error( 'card_declined' ); |
|
| 479 | + wpinv_set_error('card_declined'); |
|
| 480 | 480 | |
| 481 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
| 481 | + if (!empty($result->transactionResponse->errors)) { |
|
| 482 | 482 | $errors = (object) $result->transactionResponse->errors; |
| 483 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
| 483 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | } |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | * @param array $card Card details. |
| 493 | 493 | * @return array |
| 494 | 494 | */ |
| 495 | - public function get_payment_information( $card ) { |
|
| 495 | + public function get_payment_information($card) { |
|
| 496 | 496 | return array( |
| 497 | 497 | |
| 498 | 498 | 'creditCard' => array( |
@@ -511,8 +511,8 @@ discard block |
||
| 511 | 511 | * @param WPInv_Invoice $invoice Invoice. |
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 515 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
| 514 | + public function get_customer_profile_meta_name($invoice) { |
|
| 515 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -523,34 +523,34 @@ discard block |
||
| 523 | 523 | * @param WPInv_Invoice $invoice |
| 524 | 524 | * @return WP_Error|string The payment profile id |
| 525 | 525 | */ |
| 526 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 526 | + public function validate_submission_data($submission_data, $invoice) { |
|
| 527 | 527 | |
| 528 | 528 | // Validate authentication details. |
| 529 | 529 | $auth = $this->get_auth_params(); |
| 530 | 530 | |
| 531 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
| 532 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
| 531 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
| 532 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | // Validate the payment method. |
| 536 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
| 537 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
| 536 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
| 537 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // Are we adding a new payment method? |
| 541 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
| 541 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
| 542 | 542 | return $submission_data['getpaid-authorizenet-payment-method']; |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | // Retrieve the customer profile id. |
| 546 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 546 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 547 | 547 | |
| 548 | 548 | // Create payment method. |
| 549 | - if ( empty( $profile_id ) ) { |
|
| 550 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
| 549 | + if (empty($profile_id)) { |
|
| 550 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
| 553 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
| 554 | 554 | |
| 555 | 555 | } |
| 556 | 556 | |
@@ -561,32 +561,32 @@ discard block |
||
| 561 | 561 | * @param WPInv_Invoice $invoice Invoice. |
| 562 | 562 | * @return array |
| 563 | 563 | */ |
| 564 | - public function get_line_items( $invoice ) { |
|
| 564 | + public function get_line_items($invoice) { |
|
| 565 | 565 | $items = array(); |
| 566 | 566 | |
| 567 | - foreach ( $invoice->get_items() as $item ) { |
|
| 567 | + foreach ($invoice->get_items() as $item) { |
|
| 568 | 568 | |
| 569 | 569 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
| 570 | 570 | $items[] = array( |
| 571 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
| 572 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
| 573 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
| 574 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
| 571 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
| 572 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
| 573 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
| 574 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
| 575 | 575 | 'unitPrice' => (float) $amount, |
| 576 | 576 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
| 577 | 577 | ); |
| 578 | 578 | |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
| 581 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
| 582 | 582 | |
| 583 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
| 583 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
| 584 | 584 | |
| 585 | - if ( $amount > 0 ) { |
|
| 585 | + if ($amount > 0) { |
|
| 586 | 586 | $items[] = array( |
| 587 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
| 588 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
| 589 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
| 587 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
| 588 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
| 589 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
| 590 | 590 | 'quantity' => '1', |
| 591 | 591 | 'unitPrice' => (float) $amount, |
| 592 | 592 | 'taxable' => false, |
@@ -606,36 +606,36 @@ discard block |
||
| 606 | 606 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 607 | 607 | * @return array |
| 608 | 608 | */ |
| 609 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 609 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 610 | 610 | |
| 611 | 611 | // Validate the submitted data. |
| 612 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
| 612 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
| 613 | 613 | |
| 614 | 614 | // Do we have an error? |
| 615 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
| 616 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
| 617 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 615 | + if (is_wp_error($payment_profile_id)) { |
|
| 616 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
| 617 | + wpinv_send_back_to_checkout($invoice); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | // Save the payment method to the order. |
| 621 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
| 621 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
| 622 | 622 | |
| 623 | 623 | // Check if this is a subscription or not. |
| 624 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 625 | - if ( ! empty( $subscriptions ) ) { |
|
| 626 | - $this->process_subscription( $invoice, $subscriptions ); |
|
| 624 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 625 | + if (!empty($subscriptions)) { |
|
| 626 | + $this->process_subscription($invoice, $subscriptions); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | // If it is free, send to the success page. |
| 630 | - if ( ! $invoice->needs_payment() ) { |
|
| 630 | + if (!$invoice->needs_payment()) { |
|
| 631 | 631 | $invoice->mark_paid(); |
| 632 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 632 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | // Charge the payment profile. |
| 636 | - $this->process_initial_payment( $invoice ); |
|
| 636 | + $this->process_initial_payment($invoice); |
|
| 637 | 637 | |
| 638 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 638 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 639 | 639 | |
| 640 | 640 | exit; |
| 641 | 641 | |
@@ -646,23 +646,23 @@ discard block |
||
| 646 | 646 | * |
| 647 | 647 | * @param WPInv_Invoice $invoice Invoice. |
| 648 | 648 | */ |
| 649 | - protected function process_initial_payment( $invoice ) { |
|
| 649 | + protected function process_initial_payment($invoice) { |
|
| 650 | 650 | |
| 651 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 652 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 653 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 651 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 652 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 653 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
| 654 | 654 | |
| 655 | 655 | // Do we have an error? |
| 656 | - if ( is_wp_error( $result ) ) { |
|
| 657 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 658 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 656 | + if (is_wp_error($result)) { |
|
| 657 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
| 658 | + wpinv_send_back_to_checkout($invoice); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | // Process the response. |
| 662 | - $this->process_charge_response( $result, $invoice ); |
|
| 662 | + $this->process_charge_response($result, $invoice); |
|
| 663 | 663 | |
| 664 | - if ( wpinv_get_errors() ) { |
|
| 665 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 664 | + if (wpinv_get_errors()) { |
|
| 665 | + wpinv_send_back_to_checkout($invoice); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | } |
@@ -673,30 +673,30 @@ discard block |
||
| 673 | 673 | * @param WPInv_Invoice $invoice Invoice. |
| 674 | 674 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
| 675 | 675 | */ |
| 676 | - public function process_subscription( $invoice, $subscriptions ) { |
|
| 676 | + public function process_subscription($invoice, $subscriptions) { |
|
| 677 | 677 | |
| 678 | 678 | // Check if there is an initial amount to charge. |
| 679 | - if ( (float) $invoice->get_total() > 0 ) { |
|
| 680 | - $this->process_initial_payment( $invoice ); |
|
| 679 | + if ((float) $invoice->get_total() > 0) { |
|
| 680 | + $this->process_initial_payment($invoice); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | // Activate the subscriptions. |
| 684 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
| 684 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
| 685 | 685 | |
| 686 | - foreach ( $subscriptions as $subscription ) { |
|
| 687 | - if ( $subscription->exists() ) { |
|
| 688 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 689 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
| 686 | + foreach ($subscriptions as $subscription) { |
|
| 687 | + if ($subscription->exists()) { |
|
| 688 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
| 689 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
| 690 | 690 | |
| 691 | - $subscription->set_next_renewal_date( $expiry ); |
|
| 692 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 693 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
| 691 | + $subscription->set_next_renewal_date($expiry); |
|
| 692 | + $subscription->set_date_created(current_time('mysql')); |
|
| 693 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
| 694 | 694 | $subscription->activate(); |
| 695 | 695 | } |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | // Redirect to the success page. |
| 699 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 699 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 700 | 700 | |
| 701 | 701 | } |
| 702 | 702 | |
@@ -706,11 +706,11 @@ discard block |
||
| 706 | 706 | * |
| 707 | 707 | * @param WPInv_Subscription $subscription |
| 708 | 708 | */ |
| 709 | - public function maybe_renew_subscription( $subscription ) { |
|
| 709 | + public function maybe_renew_subscription($subscription) { |
|
| 710 | 710 | |
| 711 | 711 | // Ensure its our subscription && it's active. |
| 712 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
| 713 | - $this->renew_subscription( $subscription ); |
|
| 712 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
| 713 | + $this->renew_subscription($subscription); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | } |
@@ -720,28 +720,28 @@ discard block |
||
| 720 | 720 | * |
| 721 | 721 | * @param WPInv_Subscription $subscription |
| 722 | 722 | */ |
| 723 | - public function renew_subscription( $subscription ) { |
|
| 723 | + public function renew_subscription($subscription) { |
|
| 724 | 724 | |
| 725 | 725 | // Generate the renewal invoice. |
| 726 | 726 | $new_invoice = $subscription->create_payment(); |
| 727 | 727 | $old_invoice = $subscription->get_parent_payment(); |
| 728 | 728 | |
| 729 | - if ( empty( $new_invoice ) ) { |
|
| 730 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
| 729 | + if (empty($new_invoice)) { |
|
| 730 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
| 731 | 731 | $subscription->failing(); |
| 732 | 732 | return; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | // Charge the payment method. |
| 736 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 737 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 738 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 736 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 737 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
| 738 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
| 739 | 739 | |
| 740 | 740 | // Do we have an error? |
| 741 | - if ( is_wp_error( $result ) ) { |
|
| 741 | + if (is_wp_error($result)) { |
|
| 742 | 742 | |
| 743 | 743 | $old_invoice->add_note( |
| 744 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 744 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
| 745 | 745 | true, |
| 746 | 746 | false, |
| 747 | 747 | true |
@@ -752,12 +752,12 @@ discard block |
||
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | // Process the response. |
| 755 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 755 | + $this->process_charge_response($result, $new_invoice); |
|
| 756 | 756 | |
| 757 | - if ( wpinv_get_errors() ) { |
|
| 757 | + if (wpinv_get_errors()) { |
|
| 758 | 758 | |
| 759 | 759 | $old_invoice->add_note( |
| 760 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 760 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
| 761 | 761 | true, |
| 762 | 762 | false, |
| 763 | 763 | true |
@@ -767,9 +767,9 @@ discard block |
||
| 767 | 767 | |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | - if ( ! $new_invoice->needs_payment() ) { |
|
| 770 | + if (!$new_invoice->needs_payment()) { |
|
| 771 | 771 | $subscription->renew(); |
| 772 | - $subscription->after_add_payment( $new_invoice ); |
|
| 772 | + $subscription->after_add_payment($new_invoice); |
|
| 773 | 773 | } else { |
| 774 | 774 | $subscription->failing(); |
| 775 | 775 | } |
@@ -782,33 +782,33 @@ discard block |
||
| 782 | 782 | * @param GetPaid_Form_Item[] $items |
| 783 | 783 | * @return WPInv_Invoice |
| 784 | 784 | */ |
| 785 | - public function process_addons( $invoice, $items ) { |
|
| 785 | + public function process_addons($invoice, $items) { |
|
| 786 | 786 | |
| 787 | 787 | global $getpaid_authorize_addons; |
| 788 | 788 | |
| 789 | 789 | $getpaid_authorize_addons = array(); |
| 790 | - foreach ( $items as $item ) { |
|
| 790 | + foreach ($items as $item) { |
|
| 791 | 791 | |
| 792 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
| 792 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
| 793 | 793 | $getpaid_authorize_addons[] = $item; |
| 794 | 794 | } |
| 795 | 795 | } |
| 796 | 796 | |
| 797 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
| 797 | + if (empty($getpaid_authorize_addons)) { |
|
| 798 | 798 | return; |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | $invoice->recalculate_total(); |
| 802 | 802 | |
| 803 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 804 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 803 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 804 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 805 | 805 | |
| 806 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
| 807 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 808 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
| 806 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
| 807 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
| 808 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
| 809 | 809 | |
| 810 | - if ( is_wp_error( $result ) ) { |
|
| 811 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 810 | + if (is_wp_error($result)) { |
|
| 811 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
| 812 | 812 | return; |
| 813 | 813 | } |
| 814 | 814 | |
@@ -821,19 +821,19 @@ discard block |
||
| 821 | 821 | * @param array $args |
| 822 | 822 | * @return array |
| 823 | 823 | */ |
| 824 | - public function filter_addons_request( $args ) { |
|
| 824 | + public function filter_addons_request($args) { |
|
| 825 | 825 | |
| 826 | 826 | global $getpaid_authorize_addons; |
| 827 | 827 | $total = 0; |
| 828 | 828 | |
| 829 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
| 829 | + foreach ($getpaid_authorize_addons as $addon) { |
|
| 830 | 830 | $total += $addon->get_sub_total(); |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
| 834 | 834 | |
| 835 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
| 836 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
| 835 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
| 836 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | return $args; |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | public function sandbox_notice() { |
| 847 | 847 | |
| 848 | 848 | return sprintf( |
| 849 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
| 849 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
| 850 | 850 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
| 851 | 851 | '</a>' |
| 852 | 852 | ); |
@@ -858,42 +858,42 @@ discard block |
||
| 858 | 858 | * |
| 859 | 859 | * @param array $admin_settings |
| 860 | 860 | */ |
| 861 | - public function admin_settings( $admin_settings ) { |
|
| 861 | + public function admin_settings($admin_settings) { |
|
| 862 | 862 | |
| 863 | 863 | $currencies = sprintf( |
| 864 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
| 865 | - implode( ', ', $this->currencies ) |
|
| 864 | + __('Supported Currencies: %s', 'invoicing'), |
|
| 865 | + implode(', ', $this->currencies) |
|
| 866 | 866 | ); |
| 867 | 867 | |
| 868 | 868 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
| 869 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
| 869 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
| 870 | 870 | |
| 871 | 871 | $admin_settings['authorizenet_login_id'] = array( |
| 872 | 872 | 'type' => 'text', |
| 873 | 873 | 'id' => 'authorizenet_login_id', |
| 874 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
| 875 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
| 874 | + 'name' => __('API Login ID', 'invoicing'), |
|
| 875 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
| 876 | 876 | ); |
| 877 | 877 | |
| 878 | 878 | $admin_settings['authorizenet_transaction_key'] = array( |
| 879 | 879 | 'type' => 'text', |
| 880 | 880 | 'id' => 'authorizenet_transaction_key', |
| 881 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
| 881 | + 'name' => __('Transaction Key', 'invoicing'), |
|
| 882 | 882 | ); |
| 883 | 883 | |
| 884 | 884 | $admin_settings['authorizenet_signature_key'] = array( |
| 885 | 885 | 'type' => 'text', |
| 886 | 886 | 'id' => 'authorizenet_signature_key', |
| 887 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
| 888 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
| 887 | + 'name' => __('Signature Key', 'invoicing'), |
|
| 888 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
| 889 | 889 | ); |
| 890 | 890 | |
| 891 | 891 | $admin_settings['authorizenet_ipn_url'] = array( |
| 892 | 892 | 'type' => 'ipn_url', |
| 893 | 893 | 'id' => 'authorizenet_ipn_url', |
| 894 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
| 894 | + 'name' => __('Webhook URL', 'invoicing'), |
|
| 895 | 895 | 'std' => $this->notify_url, |
| 896 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
| 896 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
| 897 | 897 | 'custom' => 'authorizenet', |
| 898 | 898 | 'readonly' => true, |
| 899 | 899 | ); |
@@ -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 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
| 68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
| 69 | 69 | * @param bool $deprecated |
| 70 | 70 | */ |
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 71 | + function __construct($subscription = 0, $deprecated = false) { |
|
| 72 | 72 | |
| 73 | - parent::__construct( $subscription ); |
|
| 73 | + parent::__construct($subscription); |
|
| 74 | 74 | |
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 75 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
| 76 | + $this->set_id($subscription); |
|
| 77 | + } elseif ($subscription instanceof self) { |
|
| 78 | + $this->set_id($subscription->get_id()); |
|
| 79 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
| 80 | + $this->set_id($subscription_id); |
|
| 81 | + } elseif (!empty($subscription->id)) { |
|
| 82 | + $this->set_id($subscription->id); |
|
| 83 | 83 | } else { |
| 84 | - $this->set_object_read( true ); |
|
| 84 | + $this->set_object_read(true); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Load the datastore. |
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 89 | 89 | |
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 90 | + if ($this->get_id() > 0) { |
|
| 91 | + $this->data_store->read($this); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
| 103 | 103 | * @since 1.0.19 |
| 104 | 104 | * @return int |
| 105 | 105 | */ |
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | 109 | // Trim the value. |
| 110 | - $value = trim( $value ); |
|
| 110 | + $value = trim($value); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 112 | + if (empty($value)) { |
|
| 113 | 113 | return 0; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 116 | + if ('invoice_id' == $field) { |
|
| 117 | 117 | $field = 'parent_payment_id'; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | // Ensure a field has been passed. |
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 128 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 129 | 129 | return 0; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Maybe retrieve from the cache. |
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 134 | + if (!empty($subscription_id)) { |
|
| 135 | 135 | return $subscription_id; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
| 140 | 140 | $subscription_id = (int) $wpdb->get_var( |
| 141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
| 141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 144 | + if (empty($subscription_id)) { |
|
| 145 | 145 | return 0; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Update the cache with our data. |
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 150 | 150 | |
| 151 | 151 | return $subscription_id; |
| 152 | 152 | } |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | 'getpaid_subscriptions' => $this->get_id(), |
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | - foreach ( $caches as $cache => $value ) { |
|
| 166 | - if ( '' !== $value && false !== $value ) { |
|
| 167 | - wp_cache_delete( $value, $cache ); |
|
| 165 | + foreach ($caches as $cache => $value) { |
|
| 166 | + if ('' !== $value && false !== $value) { |
|
| 167 | + wp_cache_delete($value, $cache); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | /** |
| 173 | 173 | * Checks if a subscription key is set. |
| 174 | 174 | */ |
| 175 | - public function _isset( $key ) { |
|
| 176 | - return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
| 175 | + public function _isset($key) { |
|
| 176 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /* |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | * @param string $context View or edit context. |
| 199 | 199 | * @return int |
| 200 | 200 | */ |
| 201 | - public function get_customer_id( $context = 'view' ) { |
|
| 202 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 201 | + public function get_customer_id($context = 'view') { |
|
| 202 | + return (int) $this->get_prop('customer_id', $context); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -209,8 +209,8 @@ discard block |
||
| 209 | 209 | * @param string $context View or edit context. |
| 210 | 210 | * @return WP_User|false WP_User object on success, false on failure. |
| 211 | 211 | */ |
| 212 | - public function get_customer( $context = 'view' ) { |
|
| 213 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 212 | + public function get_customer($context = 'view') { |
|
| 213 | + return get_userdata($this->get_customer_id($context)); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | * @param string $context View or edit context. |
| 221 | 221 | * @return int |
| 222 | 222 | */ |
| 223 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 224 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 223 | + public function get_parent_invoice_id($context = 'view') { |
|
| 224 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * @param string $context View or edit context. |
| 232 | 232 | * @return int |
| 233 | 233 | */ |
| 234 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 235 | - return $this->get_parent_invoice_id( $context ); |
|
| 234 | + public function get_parent_payment_id($context = 'view') { |
|
| 235 | + return $this->get_parent_invoice_id($context); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -241,8 +241,8 @@ discard block |
||
| 241 | 241 | * @since 1.0.0 |
| 242 | 242 | * @return int |
| 243 | 243 | */ |
| 244 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 245 | - return $this->get_parent_invoice_id( $context ); |
|
| 244 | + public function get_original_payment_id($context = 'view') { |
|
| 245 | + return $this->get_parent_invoice_id($context); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | * @param string $context View or edit context. |
| 253 | 253 | * @return WPInv_Invoice |
| 254 | 254 | */ |
| 255 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 256 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 255 | + public function get_parent_invoice($context = 'view') { |
|
| 256 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | * @param string $context View or edit context. |
| 264 | 264 | * @return WPInv_Invoice |
| 265 | 265 | */ |
| 266 | - public function get_parent_payment( $context = 'view' ) { |
|
| 267 | - return $this->get_parent_invoice( $context ); |
|
| 266 | + public function get_parent_payment($context = 'view') { |
|
| 267 | + return $this->get_parent_invoice($context); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -274,8 +274,8 @@ discard block |
||
| 274 | 274 | * @param string $context View or edit context. |
| 275 | 275 | * @return int |
| 276 | 276 | */ |
| 277 | - public function get_product_id( $context = 'view' ) { |
|
| 278 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 277 | + public function get_product_id($context = 'view') { |
|
| 278 | + return (int) $this->get_prop('product_id', $context); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | * @param string $context View or edit context. |
| 286 | 286 | * @return WPInv_Item |
| 287 | 287 | */ |
| 288 | - public function get_product( $context = 'view' ) { |
|
| 289 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 288 | + public function get_product($context = 'view') { |
|
| 289 | + return new WPInv_Item($this->get_product_id($context)); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * @param string $context View or edit context. |
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | - public function get_gateway( $context = 'view' ) { |
|
| 302 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 301 | + public function get_gateway($context = 'view') { |
|
| 302 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | * @param string $context View or edit context. |
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | - public function get_period( $context = 'view' ) { |
|
| 313 | - return $this->get_prop( 'period', $context ); |
|
| 312 | + public function get_period($context = 'view') { |
|
| 313 | + return $this->get_prop('period', $context); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -320,8 +320,8 @@ discard block |
||
| 320 | 320 | * @param string $context View or edit context. |
| 321 | 321 | * @return int |
| 322 | 322 | */ |
| 323 | - public function get_frequency( $context = 'view' ) { |
|
| 324 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 323 | + public function get_frequency($context = 'view') { |
|
| 324 | + return (int) $this->get_prop('frequency', $context); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -331,8 +331,8 @@ discard block |
||
| 331 | 331 | * @param string $context View or edit context. |
| 332 | 332 | * @return float |
| 333 | 333 | */ |
| 334 | - public function get_initial_amount( $context = 'view' ) { |
|
| 335 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 334 | + public function get_initial_amount($context = 'view') { |
|
| 335 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | * @param string $context View or edit context. |
| 343 | 343 | * @return float |
| 344 | 344 | */ |
| 345 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 346 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 345 | + public function get_recurring_amount($context = 'view') { |
|
| 346 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | * @param string $context View or edit context. |
| 354 | 354 | * @return int |
| 355 | 355 | */ |
| 356 | - public function get_bill_times( $context = 'view' ) { |
|
| 357 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 356 | + public function get_bill_times($context = 'view') { |
|
| 357 | + return (int) $this->get_prop('bill_times', $context); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * @param string $context View or edit context. |
| 365 | 365 | * @return string |
| 366 | 366 | */ |
| 367 | - public function get_transaction_id( $context = 'view' ) { |
|
| 368 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 367 | + public function get_transaction_id($context = 'view') { |
|
| 368 | + return $this->get_prop('transaction_id', $context); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * @param string $context View or edit context. |
| 376 | 376 | * @return string |
| 377 | 377 | */ |
| 378 | - public function get_created( $context = 'view' ) { |
|
| 379 | - return $this->get_prop( 'created', $context ); |
|
| 378 | + public function get_created($context = 'view') { |
|
| 379 | + return $this->get_prop('created', $context); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -386,8 +386,8 @@ discard block |
||
| 386 | 386 | * @param string $context View or edit context. |
| 387 | 387 | * @return string |
| 388 | 388 | */ |
| 389 | - public function get_date_created( $context = 'view' ) { |
|
| 390 | - return $this->get_created( $context ); |
|
| 389 | + public function get_date_created($context = 'view') { |
|
| 390 | + return $this->get_created($context); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | */ |
| 399 | 399 | public function get_time_created() { |
| 400 | 400 | $created = $this->get_date_created(); |
| 401 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 401 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -408,11 +408,11 @@ discard block |
||
| 408 | 408 | * @param string $context View or edit context. |
| 409 | 409 | * @return string |
| 410 | 410 | */ |
| 411 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 412 | - $date = $this->get_date_created( $context ); |
|
| 411 | + public function get_date_created_gmt($context = 'view') { |
|
| 412 | + $date = $this->get_date_created($context); |
|
| 413 | 413 | |
| 414 | - if ( $date ) { |
|
| 415 | - $date = get_gmt_from_date( $date ); |
|
| 414 | + if ($date) { |
|
| 415 | + $date = get_gmt_from_date($date); |
|
| 416 | 416 | } |
| 417 | 417 | return $date; |
| 418 | 418 | } |
@@ -424,8 +424,8 @@ discard block |
||
| 424 | 424 | * @param string $context View or edit context. |
| 425 | 425 | * @return string |
| 426 | 426 | */ |
| 427 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 428 | - return $this->get_prop( 'expiration', $context ); |
|
| 427 | + public function get_next_renewal_date($context = 'view') { |
|
| 428 | + return $this->get_prop('expiration', $context); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | * @param string $context View or edit context. |
| 436 | 436 | * @return string |
| 437 | 437 | */ |
| 438 | - public function get_expiration( $context = 'view' ) { |
|
| 439 | - return $this->get_next_renewal_date( $context ); |
|
| 438 | + public function get_expiration($context = 'view') { |
|
| 439 | + return $this->get_next_renewal_date($context); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -448,12 +448,12 @@ discard block |
||
| 448 | 448 | public function get_expiration_time() { |
| 449 | 449 | $expiration = $this->get_expiration(); |
| 450 | 450 | |
| 451 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 452 | - return current_time( 'timestamp' ); |
|
| 451 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
| 452 | + return current_time('timestamp'); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 456 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 455 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
| 456 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /** |
@@ -463,11 +463,11 @@ discard block |
||
| 463 | 463 | * @param string $context View or edit context. |
| 464 | 464 | * @return string |
| 465 | 465 | */ |
| 466 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 467 | - $date = $this->get_next_renewal_date( $context ); |
|
| 466 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
| 467 | + $date = $this->get_next_renewal_date($context); |
|
| 468 | 468 | |
| 469 | - if ( $date ) { |
|
| 470 | - $date = get_gmt_from_date( $date ); |
|
| 469 | + if ($date) { |
|
| 470 | + $date = get_gmt_from_date($date); |
|
| 471 | 471 | } |
| 472 | 472 | return $date; |
| 473 | 473 | } |
@@ -479,8 +479,8 @@ discard block |
||
| 479 | 479 | * @param string $context View or edit context. |
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | - public function get_trial_period( $context = 'view' ) { |
|
| 483 | - return $this->get_prop( 'trial_period', $context ); |
|
| 482 | + public function get_trial_period($context = 'view') { |
|
| 483 | + return $this->get_prop('trial_period', $context); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -490,8 +490,8 @@ discard block |
||
| 490 | 490 | * @param string $context View or edit context. |
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | - public function get_status( $context = 'view' ) { |
|
| 494 | - return $this->get_prop( 'status', $context ); |
|
| 493 | + public function get_status($context = 'view') { |
|
| 494 | + return $this->get_prop('status', $context); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -501,8 +501,8 @@ discard block |
||
| 501 | 501 | * @param string $context View or edit context. |
| 502 | 502 | * @return string |
| 503 | 503 | */ |
| 504 | - public function get_profile_id( $context = 'view' ) { |
|
| 505 | - return $this->get_prop( 'profile_id', $context ); |
|
| 504 | + public function get_profile_id($context = 'view') { |
|
| 505 | + return $this->get_prop('profile_id', $context); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /* |
@@ -517,8 +517,8 @@ discard block |
||
| 517 | 517 | * @since 1.0.19 |
| 518 | 518 | * @param int $value The customer's id. |
| 519 | 519 | */ |
| 520 | - public function set_customer_id( $value ) { |
|
| 521 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 520 | + public function set_customer_id($value) { |
|
| 521 | + $this->set_prop('customer_id', (int) $value); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
@@ -527,8 +527,8 @@ discard block |
||
| 527 | 527 | * @since 1.0.19 |
| 528 | 528 | * @param int $value The parent invoice id. |
| 529 | 529 | */ |
| 530 | - public function set_parent_invoice_id( $value ) { |
|
| 531 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 530 | + public function set_parent_invoice_id($value) { |
|
| 531 | + $this->set_prop('parent_payment_id', (int) $value); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -537,8 +537,8 @@ discard block |
||
| 537 | 537 | * @since 1.0.19 |
| 538 | 538 | * @param int $value The parent invoice id. |
| 539 | 539 | */ |
| 540 | - public function set_parent_payment_id( $value ) { |
|
| 541 | - $this->set_parent_invoice_id( $value ); |
|
| 540 | + public function set_parent_payment_id($value) { |
|
| 541 | + $this->set_parent_invoice_id($value); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -547,8 +547,8 @@ discard block |
||
| 547 | 547 | * @since 1.0.19 |
| 548 | 548 | * @param int $value The parent invoice id. |
| 549 | 549 | */ |
| 550 | - public function set_original_payment_id( $value ) { |
|
| 551 | - $this->set_parent_invoice_id( $value ); |
|
| 550 | + public function set_original_payment_id($value) { |
|
| 551 | + $this->set_parent_invoice_id($value); |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -557,8 +557,8 @@ discard block |
||
| 557 | 557 | * @since 1.0.19 |
| 558 | 558 | * @param int $value The subscription product id. |
| 559 | 559 | */ |
| 560 | - public function set_product_id( $value ) { |
|
| 561 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 560 | + public function set_product_id($value) { |
|
| 561 | + $this->set_prop('product_id', (int) $value); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -567,8 +567,8 @@ discard block |
||
| 567 | 567 | * @since 1.0.19 |
| 568 | 568 | * @param string $value The renewal period. |
| 569 | 569 | */ |
| 570 | - public function set_period( $value ) { |
|
| 571 | - $this->set_prop( 'period', $value ); |
|
| 570 | + public function set_period($value) { |
|
| 571 | + $this->set_prop('period', $value); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -577,9 +577,9 @@ discard block |
||
| 577 | 577 | * @since 1.0.19 |
| 578 | 578 | * @param int $value The subscription frequency. |
| 579 | 579 | */ |
| 580 | - public function set_frequency( $value ) { |
|
| 581 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 582 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 580 | + public function set_frequency($value) { |
|
| 581 | + $value = empty($value) ? 1 : (int) $value; |
|
| 582 | + $this->set_prop('frequency', absint($value)); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -588,8 +588,8 @@ discard block |
||
| 588 | 588 | * @since 1.0.19 |
| 589 | 589 | * @param float $value The initial subcription amount. |
| 590 | 590 | */ |
| 591 | - public function set_initial_amount( $value ) { |
|
| 592 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 591 | + public function set_initial_amount($value) { |
|
| 592 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | * @since 1.0.19 |
| 599 | 599 | * @param float $value The recurring subcription amount. |
| 600 | 600 | */ |
| 601 | - public function set_recurring_amount( $value ) { |
|
| 602 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 601 | + public function set_recurring_amount($value) { |
|
| 602 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -608,8 +608,8 @@ discard block |
||
| 608 | 608 | * @since 1.0.19 |
| 609 | 609 | * @param int $value Bill times. |
| 610 | 610 | */ |
| 611 | - public function set_bill_times( $value ) { |
|
| 612 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 611 | + public function set_bill_times($value) { |
|
| 612 | + $this->set_prop('bill_times', (int) $value); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | /** |
@@ -618,8 +618,8 @@ discard block |
||
| 618 | 618 | * @since 1.0.19 |
| 619 | 619 | * @param string $value Bill times. |
| 620 | 620 | */ |
| 621 | - public function set_transaction_id( $value ) { |
|
| 622 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 621 | + public function set_transaction_id($value) { |
|
| 622 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
@@ -628,15 +628,15 @@ discard block |
||
| 628 | 628 | * @since 1.0.19 |
| 629 | 629 | * @param string $value strtotime compliant date. |
| 630 | 630 | */ |
| 631 | - public function set_created( $value ) { |
|
| 632 | - $date = strtotime( $value ); |
|
| 631 | + public function set_created($value) { |
|
| 632 | + $date = strtotime($value); |
|
| 633 | 633 | |
| 634 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 635 | - $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
| 634 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 635 | + $this->set_prop('created', gmdate('Y-m-d H:i:s', $date)); |
|
| 636 | 636 | return; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - $this->set_prop( 'created', '' ); |
|
| 639 | + $this->set_prop('created', ''); |
|
| 640 | 640 | |
| 641 | 641 | } |
| 642 | 642 | |
@@ -646,8 +646,8 @@ discard block |
||
| 646 | 646 | * @since 1.0.19 |
| 647 | 647 | * @param string $value strtotime compliant date. |
| 648 | 648 | */ |
| 649 | - public function set_date_created( $value ) { |
|
| 650 | - $this->set_created( $value ); |
|
| 649 | + public function set_date_created($value) { |
|
| 650 | + $this->set_created($value); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
@@ -656,15 +656,15 @@ discard block |
||
| 656 | 656 | * @since 1.0.19 |
| 657 | 657 | * @param string $value strtotime compliant date. |
| 658 | 658 | */ |
| 659 | - public function set_next_renewal_date( $value ) { |
|
| 660 | - $date = strtotime( $value ); |
|
| 659 | + public function set_next_renewal_date($value) { |
|
| 660 | + $date = strtotime($value); |
|
| 661 | 661 | |
| 662 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 663 | - $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
| 662 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 663 | + $this->set_prop('expiration', gmdate('Y-m-d H:i:s', $date)); |
|
| 664 | 664 | return; |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - $this->set_prop( 'expiration', '' ); |
|
| 667 | + $this->set_prop('expiration', ''); |
|
| 668 | 668 | |
| 669 | 669 | } |
| 670 | 670 | |
@@ -674,8 +674,8 @@ discard block |
||
| 674 | 674 | * @since 1.0.19 |
| 675 | 675 | * @param string $value strtotime compliant date. |
| 676 | 676 | */ |
| 677 | - public function set_expiration( $value ) { |
|
| 678 | - $this->set_next_renewal_date( $value ); |
|
| 677 | + public function set_expiration($value) { |
|
| 678 | + $this->set_next_renewal_date($value); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
@@ -684,8 +684,8 @@ discard block |
||
| 684 | 684 | * @since 1.0.19 |
| 685 | 685 | * @param string $value trial period e.g 1 year. |
| 686 | 686 | */ |
| 687 | - public function set_trial_period( $value ) { |
|
| 688 | - $this->set_prop( 'trial_period', $value ); |
|
| 687 | + public function set_trial_period($value) { |
|
| 688 | + $this->set_prop('trial_period', $value); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -694,22 +694,22 @@ discard block |
||
| 694 | 694 | * @since 1.0.19 |
| 695 | 695 | * @param string $new_status New subscription status. |
| 696 | 696 | */ |
| 697 | - public function set_status( $new_status ) { |
|
| 697 | + public function set_status($new_status) { |
|
| 698 | 698 | |
| 699 | 699 | // Abort if this is not a valid status; |
| 700 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 700 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
| 701 | 701 | return; |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
| 705 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 704 | + $old_status = !empty($this->status_transition['from']) ? $this->status_transition['from'] : $this->get_status(); |
|
| 705 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
| 706 | 706 | $this->status_transition = array( |
| 707 | 707 | 'from' => $old_status, |
| 708 | 708 | 'to' => $new_status, |
| 709 | 709 | ); |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - $this->set_prop( 'status', $new_status ); |
|
| 712 | + $this->set_prop('status', $new_status); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -718,8 +718,8 @@ discard block |
||
| 718 | 718 | * @since 1.0.19 |
| 719 | 719 | * @param string $value the remote profile id. |
| 720 | 720 | */ |
| 721 | - public function set_profile_id( $value ) { |
|
| 722 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 721 | + public function set_profile_id($value) { |
|
| 722 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /* |
@@ -737,8 +737,8 @@ discard block |
||
| 737 | 737 | * @param string|array String or array of strings to check for. |
| 738 | 738 | * @return bool |
| 739 | 739 | */ |
| 740 | - public function has_status( $status ) { |
|
| 741 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
| 740 | + public function has_status($status) { |
|
| 741 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | /** |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | */ |
| 749 | 749 | public function has_trial_period() { |
| 750 | 750 | $period = $this->get_trial_period(); |
| 751 | - return ! empty( $period ); |
|
| 751 | + return !empty($period); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * @return bool |
| 758 | 758 | */ |
| 759 | 759 | public function is_active() { |
| 760 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 760 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | * @return bool |
| 767 | 767 | */ |
| 768 | 768 | public function is_expired() { |
| 769 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
| 769 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('timestamp')); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | /** |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | */ |
| 777 | 777 | public function is_last_renewal() { |
| 778 | 778 | $max_bills = $this->get_bill_times(); |
| 779 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 779 | + return !empty($max_bills) && $max_bills <= $this->get_times_billed(); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /* |
@@ -791,11 +791,11 @@ discard block |
||
| 791 | 791 | /** |
| 792 | 792 | * Backwards compatibilty. |
| 793 | 793 | */ |
| 794 | - public function create( $data = array() ) { |
|
| 794 | + public function create($data = array()) { |
|
| 795 | 795 | |
| 796 | 796 | // Set the properties. |
| 797 | - if ( is_array( $data ) ) { |
|
| 798 | - $this->set_props( $data ); |
|
| 797 | + if (is_array($data)) { |
|
| 798 | + $this->set_props($data); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | // Save the item. |
@@ -806,8 +806,8 @@ discard block |
||
| 806 | 806 | /** |
| 807 | 807 | * Backwards compatibilty. |
| 808 | 808 | */ |
| 809 | - public function update( $args = array() ) { |
|
| 810 | - return $this->create( $args ); |
|
| 809 | + public function update($args = array()) { |
|
| 810 | + return $this->create($args); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | /** |
@@ -816,12 +816,12 @@ discard block |
||
| 816 | 816 | * @since 1.0.0 |
| 817 | 817 | * @return WP_Post[] |
| 818 | 818 | */ |
| 819 | - public function get_child_payments( $hide_pending = true ) { |
|
| 819 | + public function get_child_payments($hide_pending = true) { |
|
| 820 | 820 | |
| 821 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 821 | + $statuses = array('publish', 'wpi-processing', 'wpi-renewal'); |
|
| 822 | 822 | |
| 823 | - if ( ! $hide_pending ) { |
|
| 824 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 823 | + if (!$hide_pending) { |
|
| 824 | + $statuses = array_keys(wpinv_get_invoice_statuses()); |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | return get_posts( |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | * @return int |
| 844 | 844 | */ |
| 845 | 845 | public function get_total_payments() { |
| 846 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
| 846 | + return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id()); |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | public function get_times_billed() { |
| 856 | 856 | $times_billed = $this->get_total_payments(); |
| 857 | 857 | |
| 858 | - if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) { |
|
| 858 | + if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) { |
|
| 859 | 859 | $times_billed--; |
| 860 | 860 | } |
| 861 | 861 | |
@@ -870,52 +870,52 @@ discard block |
||
| 870 | 870 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
| 871 | 871 | * @return bool |
| 872 | 872 | */ |
| 873 | - public function add_payment( $args = array(), $invoice = false ) { |
|
| 873 | + public function add_payment($args = array(), $invoice = false) { |
|
| 874 | 874 | |
| 875 | 875 | // Process each payment once. |
| 876 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 876 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
| 877 | 877 | return false; |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | // Are we creating a new invoice? |
| 881 | - if ( empty( $invoice ) ) { |
|
| 882 | - $invoice = $this->create_payment( false ); |
|
| 881 | + if (empty($invoice)) { |
|
| 882 | + $invoice = $this->create_payment(false); |
|
| 883 | 883 | |
| 884 | - if ( empty( $invoice ) ) { |
|
| 884 | + if (empty($invoice)) { |
|
| 885 | 885 | return false; |
| 886 | 886 | } |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | // Maybe set a transaction id. |
| 890 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 891 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 890 | + if (!empty($args['transaction_id'])) { |
|
| 891 | + $invoice->set_transaction_id($args['transaction_id']); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | // Set the completed date. |
| 895 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 895 | + $invoice->set_completed_date(current_time('mysql')); |
|
| 896 | 896 | |
| 897 | 897 | // And the gateway. |
| 898 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 899 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 898 | + if (!empty($args['gateway'])) { |
|
| 899 | + $invoice->set_gateway($args['gateway']); |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 902 | + $invoice->set_status('wpi-renewal'); |
|
| 903 | 903 | $invoice->save(); |
| 904 | 904 | |
| 905 | - if ( ! $invoice->exists() ) { |
|
| 905 | + if (!$invoice->exists()) { |
|
| 906 | 906 | return false; |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | - return $this->after_add_payment( $invoice ); |
|
| 909 | + return $this->after_add_payment($invoice); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | - public function after_add_payment( $invoice ) { |
|
| 912 | + public function after_add_payment($invoice) { |
|
| 913 | 913 | |
| 914 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 915 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 916 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
| 914 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
| 915 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 916 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
| 917 | 917 | |
| 918 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
| 918 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
| 919 | 919 | |
| 920 | 920 | return $invoice->get_id(); |
| 921 | 921 | } |
@@ -927,47 +927,47 @@ discard block |
||
| 927 | 927 | * @param bool $save Whether we should save the invoice. |
| 928 | 928 | * @return WPInv_Invoice|bool |
| 929 | 929 | */ |
| 930 | - public function create_payment( $save = true ) { |
|
| 930 | + public function create_payment($save = true) { |
|
| 931 | 931 | |
| 932 | 932 | $parent_invoice = $this->get_parent_payment(); |
| 933 | 933 | |
| 934 | - if ( ! $parent_invoice->exists() ) { |
|
| 934 | + if (!$parent_invoice->exists()) { |
|
| 935 | 935 | return false; |
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | // Duplicate the parent invoice. |
| 939 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 940 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 941 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 942 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 939 | + $invoice = getpaid_duplicate_invoice($parent_invoice); |
|
| 940 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
| 941 | + $invoice->set_subscription_id($this->get_id()); |
|
| 942 | + $invoice->set_remote_subscription_id($this->get_profile_id()); |
|
| 943 | 943 | |
| 944 | 944 | // Set invoice items. |
| 945 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 946 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 945 | + $subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id()); |
|
| 946 | + $allowed_items = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']); |
|
| 947 | 947 | $invoice_items = array(); |
| 948 | 948 | |
| 949 | - foreach ( $invoice->get_items() as $item ) { |
|
| 950 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 949 | + foreach ($invoice->get_items() as $item) { |
|
| 950 | + if (in_array($item->get_id(), $allowed_items)) { |
|
| 951 | 951 | $invoice_items[] = $item; |
| 952 | 952 | } |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | - $invoice->set_items( $invoice_items ); |
|
| 955 | + $invoice->set_items($invoice_items); |
|
| 956 | 956 | |
| 957 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 958 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 957 | + if (!empty($subscription_group['fees'])) { |
|
| 958 | + $invoice->set_fees($subscription_group['fees']); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | // Maybe recalculate discount (Pre-GetPaid Fix). |
| 962 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 963 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 964 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 962 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 963 | + if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) { |
|
| 964 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | $invoice->recalculate_total(); |
| 968 | - $invoice->set_status( 'wpi-pending' ); |
|
| 968 | + $invoice->set_status('wpi-pending'); |
|
| 969 | 969 | |
| 970 | - if ( ! $save ) { |
|
| 970 | + if (!$save) { |
|
| 971 | 971 | return $invoice; |
| 972 | 972 | } |
| 973 | 973 | |
@@ -982,24 +982,24 @@ discard block |
||
| 982 | 982 | * @since 1.0.0 |
| 983 | 983 | * @return int The subscription's id |
| 984 | 984 | */ |
| 985 | - public function renew( $calculate_from = null ) { |
|
| 985 | + public function renew($calculate_from = null) { |
|
| 986 | 986 | |
| 987 | 987 | // Complete subscription if applicable |
| 988 | - if ( $this->is_last_renewal() ) { |
|
| 988 | + if ($this->is_last_renewal()) { |
|
| 989 | 989 | return $this->complete(); |
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | // Calculate new expiration |
| 993 | 993 | $frequency = $this->get_frequency(); |
| 994 | 994 | $period = $this->get_period(); |
| 995 | - $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
| 996 | - $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
| 995 | + $calculate_from = empty($calculate_from) ? $this->get_expiration_time() : $calculate_from; |
|
| 996 | + $new_expiration = strtotime("+ $frequency $period", $calculate_from); |
|
| 997 | 997 | |
| 998 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
| 999 | - $this->set_status( 'active' ); |
|
| 998 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
| 999 | + $this->set_status('active'); |
|
| 1000 | 1000 | $this->save(); |
| 1001 | 1001 | |
| 1002 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 1002 | + do_action('getpaid_subscription_renewed', $this); |
|
| 1003 | 1003 | |
| 1004 | 1004 | return $this->get_id(); |
| 1005 | 1005 | } |
@@ -1015,11 +1015,11 @@ discard block |
||
| 1015 | 1015 | public function complete() { |
| 1016 | 1016 | |
| 1017 | 1017 | // Only mark a subscription as complete if it's not already cancelled. |
| 1018 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1018 | + if ($this->has_status('cancelled')) { |
|
| 1019 | 1019 | return false; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | - $this->set_status( 'completed' ); |
|
| 1022 | + $this->set_status('completed'); |
|
| 1023 | 1023 | return $this->save(); |
| 1024 | 1024 | |
| 1025 | 1025 | } |
@@ -1031,14 +1031,14 @@ discard block |
||
| 1031 | 1031 | * @param bool $check_expiration |
| 1032 | 1032 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
| 1033 | 1033 | */ |
| 1034 | - public function expire( $check_expiration = false ) { |
|
| 1034 | + public function expire($check_expiration = false) { |
|
| 1035 | 1035 | |
| 1036 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1036 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
| 1037 | 1037 | // Do not mark as expired since real expiration date is in the future |
| 1038 | 1038 | return false; |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | - $this->set_status( 'expired' ); |
|
| 1041 | + $this->set_status('expired'); |
|
| 1042 | 1042 | return $this->save(); |
| 1043 | 1043 | |
| 1044 | 1044 | } |
@@ -1050,7 +1050,7 @@ discard block |
||
| 1050 | 1050 | * @return int Subscription id. |
| 1051 | 1051 | */ |
| 1052 | 1052 | public function failing() { |
| 1053 | - $this->set_status( 'failing' ); |
|
| 1053 | + $this->set_status('failing'); |
|
| 1054 | 1054 | return $this->save(); |
| 1055 | 1055 | } |
| 1056 | 1056 | |
@@ -1061,7 +1061,7 @@ discard block |
||
| 1061 | 1061 | * @return int Subscription id. |
| 1062 | 1062 | */ |
| 1063 | 1063 | public function cancel() { |
| 1064 | - $this->set_status( 'cancelled' ); |
|
| 1064 | + $this->set_status('cancelled'); |
|
| 1065 | 1065 | return $this->save(); |
| 1066 | 1066 | } |
| 1067 | 1067 | |
@@ -1072,7 +1072,7 @@ discard block |
||
| 1072 | 1072 | * @return bool |
| 1073 | 1073 | */ |
| 1074 | 1074 | public function can_cancel() { |
| 1075 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1075 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1083,7 +1083,7 @@ discard block |
||
| 1083 | 1083 | * @return array |
| 1084 | 1084 | */ |
| 1085 | 1085 | public function get_cancellable_statuses() { |
| 1086 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 1086 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1093,8 +1093,8 @@ discard block |
||
| 1093 | 1093 | * @return string |
| 1094 | 1094 | */ |
| 1095 | 1095 | public function get_cancel_url() { |
| 1096 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1097 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1096 | + $url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url()); |
|
| 1097 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | /** |
@@ -1105,10 +1105,10 @@ discard block |
||
| 1105 | 1105 | */ |
| 1106 | 1106 | public function get_view_url() { |
| 1107 | 1107 | |
| 1108 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1109 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1108 | + $url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
| 1109 | + $url = add_query_arg('subscription', $this->get_id(), $url); |
|
| 1110 | 1110 | |
| 1111 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1111 | + return apply_filters('getpaid_get_subscription_view_url', $url, $this); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
@@ -1121,7 +1121,7 @@ discard block |
||
| 1121 | 1121 | * @return bool |
| 1122 | 1122 | */ |
| 1123 | 1123 | public function can_renew() { |
| 1124 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1124 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | 1127 | /** |
@@ -1140,7 +1140,7 @@ discard block |
||
| 1140 | 1140 | ), |
| 1141 | 1141 | 'getpaid-nonce' |
| 1142 | 1142 | ); |
| 1143 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1143 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | 1146 | /** |
@@ -1150,7 +1150,7 @@ discard block |
||
| 1150 | 1150 | * @return bool |
| 1151 | 1151 | */ |
| 1152 | 1152 | public function can_update() { |
| 1153 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1153 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | 1156 | /** |
@@ -1166,7 +1166,7 @@ discard block |
||
| 1166 | 1166 | 'subscription_id' => $this->get_id(), |
| 1167 | 1167 | ) |
| 1168 | 1168 | ); |
| 1169 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1169 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | /** |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | * @return string |
| 1177 | 1177 | */ |
| 1178 | 1178 | public function get_status_label() { |
| 1179 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1179 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | /** |
@@ -1187,7 +1187,7 @@ discard block |
||
| 1187 | 1187 | */ |
| 1188 | 1188 | public function get_status_class() { |
| 1189 | 1189 | $statuses = getpaid_get_subscription_status_classes(); |
| 1190 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
| 1190 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'bg-dark'; |
|
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | /** |
@@ -1198,9 +1198,9 @@ discard block |
||
| 1198 | 1198 | */ |
| 1199 | 1199 | public function get_status_label_html() { |
| 1200 | 1200 | |
| 1201 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1202 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1203 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1201 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
| 1202 | + $class = esc_attr($this->get_status_class()); |
|
| 1203 | + $status = sanitize_html_class($this->get_status()); |
|
| 1204 | 1204 | |
| 1205 | 1205 | return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
| 1206 | 1206 | } |
@@ -1212,9 +1212,9 @@ discard block |
||
| 1212 | 1212 | * @param string $txn_id The transaction ID from the merchant processor |
| 1213 | 1213 | * @return bool |
| 1214 | 1214 | */ |
| 1215 | - public function payment_exists( $txn_id = '' ) { |
|
| 1216 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1217 | - return ! empty( $invoice_id ); |
|
| 1215 | + public function payment_exists($txn_id = '') { |
|
| 1216 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
| 1217 | + return !empty($invoice_id); |
|
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | /** |
@@ -1226,35 +1226,35 @@ discard block |
||
| 1226 | 1226 | // Reset status transition variable. |
| 1227 | 1227 | $this->status_transition = false; |
| 1228 | 1228 | |
| 1229 | - if ( $status_transition ) { |
|
| 1229 | + if ($status_transition) { |
|
| 1230 | 1230 | try { |
| 1231 | 1231 | |
| 1232 | 1232 | // Fire a hook for the status change. |
| 1233 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1234 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1233 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
| 1234 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
| 1235 | 1235 | |
| 1236 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1236 | + if (!empty($status_transition['from'])) { |
|
| 1237 | 1237 | |
| 1238 | 1238 | /* translators: 1: old subscription status 2: new subscription status */ |
| 1239 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1239 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1240 | 1240 | |
| 1241 | 1241 | // Note the transition occurred. |
| 1242 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1242 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1243 | 1243 | |
| 1244 | 1244 | // Fire another hook. |
| 1245 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1246 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1245 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
| 1246 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
| 1247 | 1247 | |
| 1248 | 1248 | } else { |
| 1249 | 1249 | /* translators: %s: new invoice status */ |
| 1250 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1250 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1251 | 1251 | |
| 1252 | 1252 | // Note the transition occurred. |
| 1253 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1253 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1254 | 1254 | |
| 1255 | 1255 | } |
| 1256 | - } catch ( Exception $e ) { |
|
| 1257 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1256 | + } catch (Exception $e) { |
|
| 1257 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | } |
| 1260 | 1260 | |
@@ -1280,7 +1280,7 @@ discard block |
||
| 1280 | 1280 | */ |
| 1281 | 1281 | public function activate() { |
| 1282 | 1282 | $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
| 1283 | - $this->set_status( $status ); |
|
| 1283 | + $this->set_status($status); |
|
| 1284 | 1284 | return $this->save(); |
| 1285 | 1285 | } |
| 1286 | 1286 | |