Issues (942)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

gateways/cheque/class-wc-gateway-cheque.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Class WC_Gateway_Cheque file.
4
 *
5
 * @package WooCommerce\Gateways
6
 */
7
8 1
if ( ! defined( 'ABSPATH' ) ) {
9
	exit; // Exit if accessed directly.
10
}
11
12
/**
13
 * Cheque Payment Gateway.
14
 *
15
 * Provides a Cheque Payment Gateway, mainly for testing purposes.
16
 *
17
 * @class       WC_Gateway_Cheque
18
 * @extends     WC_Payment_Gateway
19
 * @version     2.1.0
20
 * @package     WooCommerce/Classes/Payment
21
 */
22
class WC_Gateway_Cheque extends WC_Payment_Gateway {
23
24
	/**
25
	 * Constructor for the gateway.
26
	 */
27 1
	public function __construct() {
28 1
		$this->id                 = 'cheque';
29 1
		$this->icon               = apply_filters( 'woocommerce_cheque_icon', '' );
30 1
		$this->has_fields         = false;
31 1
		$this->method_title       = _x( 'Check payments', 'Check payment method', 'woocommerce' );
32 1
		$this->method_description = __( 'Take payments in person via checks. This offline gateway can also be useful to test purchases.', 'woocommerce' );
33
34
		// Load the settings.
35 1
		$this->init_form_fields();
36 1
		$this->init_settings();
37
38
		// Define user set variables.
39 1
		$this->title        = $this->get_option( 'title' );
40 1
		$this->description  = $this->get_option( 'description' );
41 1
		$this->instructions = $this->get_option( 'instructions' );
42
43
		// Actions.
44 1
		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
45 1
		add_action( 'woocommerce_thankyou_cheque', array( $this, 'thankyou_page' ) );
46
47
		// Customer Emails.
48 1
		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
49
	}
50
51
	/**
52
	 * Initialise Gateway Settings Form Fields.
53
	 */
54 1 View Code Duplication
	public function init_form_fields() {
55
56 1
		$this->form_fields = array(
57
			'enabled'      => array(
58 1
				'title'   => __( 'Enable/Disable', 'woocommerce' ),
59 1
				'type'    => 'checkbox',
60 1
				'label'   => __( 'Enable check payments', 'woocommerce' ),
61 1
				'default' => 'no',
62
			),
63
			'title'        => array(
64 1
				'title'       => __( 'Title', 'woocommerce' ),
65 1
				'type'        => 'text',
66 1
				'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
67 1
				'default'     => _x( 'Check payments', 'Check payment method', 'woocommerce' ),
68
				'desc_tip'    => true,
69
			),
70
			'description'  => array(
71 1
				'title'       => __( 'Description', 'woocommerce' ),
72 1
				'type'        => 'textarea',
73 1
				'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),
74 1
				'default'     => __( 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'woocommerce' ),
75
				'desc_tip'    => true,
76
			),
77
			'instructions' => array(
78 1
				'title'       => __( 'Instructions', 'woocommerce' ),
79 1
				'type'        => 'textarea',
80 1
				'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),
81 1
				'default'     => '',
82
				'desc_tip'    => true,
83
			),
84
		);
85
	}
86
87
	/**
88
	 * Output for the order received page.
89
	 */
90
	public function thankyou_page() {
91
		if ( $this->instructions ) {
92
			echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
93
		}
94
	}
95
96
	/**
97
	 * Add content to the WC emails.
98
	 *
99
	 * @access public
100
	 * @param WC_Order $order Order object.
101
	 * @param bool     $sent_to_admin Sent to admin.
102
	 * @param bool     $plain_text Email format: plain text or HTML.
103
	 */
104
	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
105 View Code Duplication
		if ( $this->instructions && ! $sent_to_admin && 'cheque' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
106
			echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
107
		}
108
	}
109
110
	/**
111
	 * Process the payment and return the result.
112
	 *
113
	 * @param int $order_id Order ID.
114
	 * @return array
115
	 */
116 View Code Duplication
	public function process_payment( $order_id ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
118
		$order = wc_get_order( $order_id );
119
120
		if ( $order->get_total() > 0 ) {
121
			// Mark as on-hold (we're awaiting the cheque).
122
			$order->update_status( apply_filters( 'woocommerce_cheque_process_payment_order_status', 'on-hold', $order ), _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
123
		} else {
124
			$order->payment_complete();
125
		}
126
127
		// Remove cart.
128
		WC()->cart->empty_cart();
129
130
		// Return thankyou redirect.
131
		return array(
132
			'result'   => 'success',
133
			'redirect' => $this->get_return_url( $order ),
134
		);
135
	}
136
}
137