1 | <?php |
||||
2 | |||||
3 | namespace Pronamic\WordPress\Pay\Gateways\Nocks; |
||||
4 | |||||
5 | use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration; |
||||
6 | |||||
7 | /** |
||||
8 | * Title: Nocks integration |
||||
9 | * Description: |
||||
10 | * Copyright: 2005-2019 Pronamic |
||||
11 | * Company: Pronamic |
||||
12 | * |
||||
13 | * @author Reüel van der Steege |
||||
14 | * @version 2.0.0 |
||||
15 | * @since 1.0.0 |
||||
16 | */ |
||||
17 | class Integration extends AbstractIntegration { |
||||
18 | public function __construct() { |
||||
19 | $this->id = 'nocks'; |
||||
20 | $this->name = 'Nocks - Checkout'; |
||||
21 | $this->product_url = 'https://www.nocks.com/'; |
||||
22 | $this->dashboard_url = 'https://www.nocks.com/'; |
||||
23 | $this->provider = 'nocks'; |
||||
24 | $this->supports = array( |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
25 | 'payment_status_request', |
||||
26 | 'webhook', |
||||
27 | 'webhook_log', |
||||
28 | 'webhook_no_config', |
||||
29 | ); |
||||
30 | |||||
31 | // Actions |
||||
32 | $function = array( __NAMESPACE__ . '\Listener', 'listen' ); |
||||
33 | |||||
34 | if ( ! has_action( 'wp_loaded', $function ) ) { |
||||
35 | add_action( 'wp_loaded', $function ); |
||||
36 | } |
||||
37 | } |
||||
38 | |||||
39 | /** |
||||
40 | * Get settings fields. |
||||
41 | * |
||||
42 | * @return array |
||||
43 | */ |
||||
44 | public function get_settings_fields() { |
||||
45 | $fields = array(); |
||||
46 | |||||
47 | // Access token. |
||||
48 | $fields[] = array( |
||||
49 | 'section' => 'general', |
||||
50 | 'filter' => FILTER_SANITIZE_STRING, |
||||
51 | 'meta_key' => '_pronamic_gateway_nocks_access_token', |
||||
52 | 'title' => _x( 'Access Token', 'nocks', 'pronamic_ideal' ), |
||||
53 | 'type' => 'textarea', |
||||
54 | 'classes' => array( 'code' ), |
||||
55 | ); |
||||
56 | |||||
57 | // Merchant profile. |
||||
58 | $fields[] = array( |
||||
59 | 'section' => 'general', |
||||
60 | 'filter' => FILTER_SANITIZE_STRING, |
||||
61 | 'meta_key' => '_pronamic_gateway_nocks_merchant_profile', |
||||
62 | 'title' => _x( 'Merchant Profile', 'nocks', 'pronamic_ideal' ), |
||||
63 | 'type' => 'description', |
||||
64 | 'callback' => array( $this, 'field_merchant_profile' ), |
||||
65 | ); |
||||
66 | |||||
67 | // Webhook URL. |
||||
68 | $fields[] = array( |
||||
69 | 'section' => 'feedback', |
||||
70 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
||||
71 | 'type' => 'text', |
||||
72 | 'classes' => array( 'large-text', 'code' ), |
||||
73 | 'value' => add_query_arg( 'nocks_webhook', '', home_url( '/' ) ), |
||||
74 | 'readonly' => true, |
||||
75 | 'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
||||
76 | ); |
||||
77 | |||||
78 | return $fields; |
||||
79 | } |
||||
80 | |||||
81 | /** |
||||
82 | * Field merchant profile select. |
||||
83 | * |
||||
84 | * @param array $field Settings field. |
||||
85 | */ |
||||
86 | public function field_merchant_profile( $field ) { |
||||
87 | $access_token = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_access_token', true ); |
||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post_id of get_post_meta() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
88 | $merchant_profile = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_merchant_profile', true ); |
||||
89 | |||||
90 | if ( ! $access_token ) { |
||||
91 | esc_html_e( 'First enter an API Key and save the configuration, to be able to choose from your Nocks merchant profiles.', 'pronamic_ideal' ); |
||||
92 | |||||
93 | return; |
||||
94 | } |
||||
95 | |||||
96 | $client = new Client(); |
||||
97 | |||||
98 | $client->set_access_token( $access_token ); |
||||
99 | |||||
100 | // Select merchant profile. |
||||
101 | printf( '<select name="%s">', esc_attr( $field['meta_key'] ) ); |
||||
102 | |||||
103 | $options = array( |
||||
104 | __( '— Select Merchant Profile —', 'pronamic_ideal' ), |
||||
105 | ); |
||||
106 | |||||
107 | $options = array_merge( $options, $client->get_merchant_profiles() ); |
||||
108 | |||||
109 | $options = array( |
||||
110 | array( |
||||
111 | 'options' => $options, |
||||
112 | ), |
||||
113 | ); |
||||
114 | |||||
115 | echo Pay_Util::select_options_grouped( $options, $merchant_profile ); // WPCS: xss ok. |
||||
0 ignored issues
–
show
The type
Pronamic\WordPress\Pay\Gateways\Nocks\Pay_Util was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||||
116 | |||||
117 | echo '</select>'; |
||||
118 | } |
||||
119 | |||||
120 | public function get_config( $post_id ) { |
||||
121 | $config = new Config(); |
||||
122 | |||||
123 | $config->mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true ); |
||||
0 ignored issues
–
show
It seems like
get_post_meta($post_id, ...ic_gateway_mode', true) can also be of type false . However, the property $mode is declared as type string . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
124 | $config->access_token = get_post_meta( $post_id, '_pronamic_gateway_nocks_access_token', true ); |
||||
125 | $config->merchant_profile = get_post_meta( $post_id, '_pronamic_gateway_nocks_merchant_profile', true ); |
||||
126 | |||||
127 | return $config; |
||||
128 | } |
||||
129 | |||||
130 | /** |
||||
131 | * Get gateway. |
||||
132 | * |
||||
133 | * @param int $post_id Post ID. |
||||
134 | * @return Gateway |
||||
135 | */ |
||||
136 | public function get_gateway( $post_id ) { |
||||
137 | return new Gateway( $this->get_config( $post_id ) ); |
||||
138 | } |
||||
139 | } |
||||
140 |