diff --git a/includes/gateways/paypal/class-wc-gateway-paypal.php b/includes/gateways/paypal/class-wc-gateway-paypal.php index d3d1bd6b461..7d0ce897776 100644 --- a/includes/gateways/paypal/class-wc-gateway-paypal.php +++ b/includes/gateways/paypal/class-wc-gateway-paypal.php @@ -1,9 +1,4 @@ init_form_fields(); $this->init_settings(); - // Define user set variables + // Define user set variables. $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); @@ -69,7 +72,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { /** * Logging method. - * @param string $message + * @param string $message */ public static function log( $message ) { if ( self::$log_enabled ) { @@ -82,7 +85,6 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { /** * get_icon function. - * * @return string */ public function get_icon() { @@ -181,7 +183,6 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { /** * Check if this gateway is enabled and available in the user's country. - * * @return bool */ public function is_valid_for_use() { @@ -213,9 +214,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { /** * Get the transaction URL. - * * @param WC_Order $order - * * @return string */ public function get_transaction_url( $order ) { @@ -229,8 +228,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { /** * Process the payment and return the result. - * - * @param int $order_id + * @param int $order_id * @return array */ public function process_payment( $order_id ) { @@ -256,10 +254,10 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { /** * Process a refund if supported. - * @param int $order_id - * @param float $amount + * @param int $order_id + * @param float $amount * @param string $reason - * @return boolean True or false based on success, or a WP_Error object + * @return boolean True or false based on success, or a WP_Error object */ public function process_refund( $order_id, $amount = null, $reason = '' ) { $order = wc_get_order( $order_id ); diff --git a/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php b/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php index cb56d118500..e8977fb7212 100644 --- a/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php +++ b/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php @@ -1,7 +1,7 @@ validate_ipn() ) { $posted = wp_unslash( $_POST ); - do_action( "valid-paypal-standard-ipn-request", $posted ); + do_action( 'valid-paypal-standard-ipn-request', $posted ); exit; } - wp_die( "PayPal IPN Request Failure", "PayPal IPN", array( 'response' => 500 ) ); + + wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); } /** @@ -45,10 +46,10 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { public function valid_response( $posted ) { if ( ! empty( $posted['custom'] ) && ( $order = $this->get_paypal_order( $posted['custom'] ) ) ) { - // Lowercase returned variables + // Lowercase returned variables. $posted['payment_status'] = strtolower( $posted['payment_status'] ); - // Sandbox fix + // Sandbox fix. if ( isset( $posted['test_ipn'] ) && 1 == $posted['test_ipn'] && 'pending' == $posted['payment_status'] ) { $posted['payment_status'] = 'completed'; } @@ -82,13 +83,13 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { 'user-agent' => 'WooCommerce/' . WC()->version ); - // Post back to get a response + // Post back to get a response. $response = wp_safe_remote_post( $this->sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); WC_Gateway_Paypal::log( 'IPN Request: ' . print_r( $params, true ) ); WC_Gateway_Paypal::log( 'IPN Response: ' . print_r( $response, true ) ); - // check to see if the request was valid + // Check to see if the request was valid. if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { WC_Gateway_Paypal::log( 'Received valid response from PayPal' ); return true; @@ -105,7 +106,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Check for a valid transaction type. - * @param string $txn_type + * @param string $txn_type */ protected function validate_transaction_type( $txn_type ) { $accepted_types = array( 'cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money' ); @@ -118,15 +119,14 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Check currency from IPN matches the order. - * @param WC_Order $order - * @param string $currency + * @param WC_Order $order + * @param string $currency */ protected function validate_currency( $order, $currency ) { - // Validate currency if ( $order->get_order_currency() != $currency ) { WC_Gateway_Paypal::log( 'Payment error: Currencies do not match (sent "' . $order->get_order_currency() . '" | returned "' . $currency . '")' ); - // Put this order on-hold for manual checking + // Put this order on-hold for manual checking. $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'woocommerce' ), $currency ) ); exit; } @@ -134,13 +134,13 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Check payment amount from IPN matches the order. - * @param WC_Order $order + * @param WC_Order $order */ protected function validate_amount( $order, $amount ) { if ( number_format( $order->get_total(), 2, '.', '' ) != number_format( $amount, 2, '.', '' ) ) { WC_Gateway_Paypal::log( 'Payment error: Amounts do not match (gross ' . $amount . ')' ); - // Put this order on-hold for manual checking + // Put this order on-hold for manual checking. $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'woocommerce' ), $amount ) ); exit; } @@ -149,22 +149,21 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Check receiver email from PayPal. If the receiver email in the IPN is different than what is stored in. * WooCommerce -> Settings -> Checkout -> PayPal, it will log an error about it. - * @param WC_Order $order + * @param WC_Order $order */ protected function validate_receiver_email( $order, $receiver_email ) { if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) != 0 ) { WC_Gateway_Paypal::log( "IPN Response is for another account: {$receiver_email}. Your email is {$this->receiver_email}" ); - // Put this order on-hold for manual checking + // Put this order on-hold for manual checking. $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'woocommerce' ), $receiver_email ) ); - exit; } } /** * Handle a completed payment. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_completed( $order, $posted ) { if ( $order->has_status( 'completed' ) ) { @@ -182,7 +181,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { $this->payment_complete( $order, ( ! empty( $posted['txn_id'] ) ? wc_clean( $posted['txn_id'] ) : '' ), __( 'IPN payment completed', 'woocommerce' ) ); if ( ! empty( $posted['mc_fee'] ) ) { - // log paypal transaction fee + // Log paypal transaction fee. update_post_meta( $order->id, 'PayPal Transaction Fee', wc_clean( $posted['mc_fee'] ) ); } @@ -193,7 +192,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle a pending payment. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_pending( $order, $posted ) { $this->payment_status_completed( $order, $posted ); @@ -201,7 +200,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle a failed payment. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_failed( $order, $posted ) { $order->update_status( 'failed', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) ); @@ -209,7 +208,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle a denied payment. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_denied( $order, $posted ) { $this->payment_status_failed( $order, $posted ); @@ -217,7 +216,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle an expired payment. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_expired( $order, $posted ) { $this->payment_status_failed( $order, $posted ); @@ -225,7 +224,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle a voided payment. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_voided( $order, $posted ) { $this->payment_status_failed( $order, $posted ); @@ -233,13 +232,13 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle a refunded order. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_refunded( $order, $posted ) { - // Only handle full refunds, not partial + // Only handle full refunds, not partial. if ( $order->get_total() == ( $posted['mc_gross'] * -1 ) ) { - // Mark order as refunded + // Mark order as refunded. $order->update_status( 'refunded', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) ); $this->send_ipn_email_notification( @@ -251,7 +250,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle a reveral. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_reversed( $order, $posted ) { $order->update_status( 'on-hold', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) ); @@ -264,7 +263,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Handle a cancelled reveral. - * @param WC_Order $order + * @param WC_Order $order */ protected function payment_status_canceled_reversal( $order, $posted ) { $this->send_ipn_email_notification( @@ -294,8 +293,8 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response { /** * Send a notification to the user handling orders. - * @param string $subject - * @param string $message + * @param string $subject + * @param string $message */ protected function send_ipn_email_notification( $subject, $message ) { $new_order_settings = get_option( 'woocommerce_new_order_settings', array() ); diff --git a/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php b/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php index 124a6a4d96d..d0e9abfb69a 100644 --- a/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php +++ b/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php @@ -1,7 +1,7 @@ 'WooCommerce/' . WC_VERSION ); - // Post back to get a response + // Post back to get a response. $response = wp_safe_remote_post( $this->sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $pdt ); if ( is_wp_error( $response ) || ! strpos( $response['body'], "SUCCESS" ) === 0 ) { @@ -76,7 +76,7 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response { $this->payment_complete( $order, $transaction, __( 'PDT payment completed', 'woocommerce' ) ); if ( ! empty( $_REQUEST['mc_fee'] ) ) { - // log paypal transaction fee + // Log paypal transaction fee. update_post_meta( $order->id, 'PayPal Transaction Fee', wc_clean( $_REQUEST['mc_fee'] ) ); } } diff --git a/includes/gateways/paypal/includes/class-wc-gateway-paypal-refund.php b/includes/gateways/paypal/includes/class-wc-gateway-paypal-refund.php index 359a2ed34c2..3e4a0e4e89f 100644 --- a/includes/gateways/paypal/includes/class-wc-gateway-paypal-refund.php +++ b/includes/gateways/paypal/includes/class-wc-gateway-paypal-refund.php @@ -1,11 +1,11 @@ get_total_shipping() > 0 && ! $this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->round( $order->get_total_shipping(), $order ) ) ) { return false; } - // Check for mismatched totals + // Check for mismatched totals. if ( $this->number_format( $calculated_total + $order->get_total_tax() + $this->round( $order->get_total_shipping(), $order ) - $this->round( $order->get_total_discount(), $order ), $order ) != $this->number_format( $order->get_total(), $order ) ) { return false; } @@ -277,10 +275,10 @@ class WC_Gateway_Paypal_Request { /** * Add PayPal Line Item. - * @param string $item_name - * @param integer $quantity - * @param integer $amount - * @param string $item_number + * @param string $item_name + * @param integer $quantity + * @param integer $amount + * @param string $item_number * @return bool successfully added or not */ protected function add_line_item( $item_name, $quantity = 1, $amount = 0, $item_number = '' ) { @@ -320,9 +318,7 @@ class WC_Gateway_Paypal_Request { /** * Check if currency has decimals. - * * @param string $currency - * * @return bool */ protected function currency_has_decimals( $currency ) { @@ -335,10 +331,8 @@ class WC_Gateway_Paypal_Request { /** * Round prices. - * * @param double $price * @param WC_Order $order - * * @return double */ protected function round( $price, $order ) { @@ -353,10 +347,8 @@ class WC_Gateway_Paypal_Request { /** * Format prices. - * * @param float|int $price * @param WC_Order $order - * * @return string */ protected function number_format( $price, $order ) { diff --git a/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php b/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php index 8bbbdc71e3d..b2a9d585201 100644 --- a/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php +++ b/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php @@ -1,11 +1,11 @@ order_id; $order_key = $custom->order_key; @@ -29,14 +28,14 @@ abstract class WC_Gateway_Paypal_Response { $order_id = $custom[0]; $order_key = $custom[1]; - // Nothing was found + // Nothing was found. } else { WC_Gateway_Paypal::log( 'Error: Order ID and key were not found in "custom".' ); return false; } if ( ! $order = wc_get_order( $order_id ) ) { - // We have an invalid $order_id, probably because invoice_prefix has changed + // We have an invalid $order_id, probably because invoice_prefix has changed. $order_id = wc_get_order_id_by_order_key( $order_key ); $order = wc_get_order( $order_id ); } @@ -52,8 +51,8 @@ abstract class WC_Gateway_Paypal_Response { /** * Complete order, add transaction ID and note. * @param WC_Order $order - * @param string $txn_id - * @param string $note + * @param string $txn_id + * @param string $note */ protected function payment_complete( $order, $txn_id = '', $note = '' ) { $order->add_order_note( $note ); @@ -63,7 +62,7 @@ abstract class WC_Gateway_Paypal_Response { /** * Hold order and add note. * @param WC_Order $order - * @param string $reason + * @param string $reason */ protected function payment_on_hold( $order, $reason = '' ) { $order->update_status( 'on-hold', $reason );