wp-pay-gateways /
nocks
| 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_no_config', |
||||
| 28 | ); |
||||
| 29 | |||||
| 30 | // Actions |
||||
| 31 | $function = array( __NAMESPACE__ . '\Listener', 'listen' ); |
||||
| 32 | |||||
| 33 | if ( ! has_action( 'wp_loaded', $function ) ) { |
||||
| 34 | add_action( 'wp_loaded', $function ); |
||||
| 35 | } |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | /** |
||||
| 39 | * Get settings fields. |
||||
| 40 | * |
||||
| 41 | * @return array |
||||
| 42 | */ |
||||
| 43 | public function get_settings_fields() { |
||||
| 44 | $fields = array(); |
||||
| 45 | |||||
| 46 | // Access token. |
||||
| 47 | $fields[] = array( |
||||
| 48 | 'section' => 'general', |
||||
| 49 | 'filter' => FILTER_SANITIZE_STRING, |
||||
| 50 | 'meta_key' => '_pronamic_gateway_nocks_access_token', |
||||
| 51 | 'title' => _x( 'Access Token', 'nocks', 'pronamic_ideal' ), |
||||
| 52 | 'type' => 'textarea', |
||||
| 53 | 'classes' => array( 'code' ), |
||||
| 54 | ); |
||||
| 55 | |||||
| 56 | // Merchant profile. |
||||
| 57 | $fields[] = array( |
||||
| 58 | 'section' => 'general', |
||||
| 59 | 'filter' => FILTER_SANITIZE_STRING, |
||||
| 60 | 'meta_key' => '_pronamic_gateway_nocks_merchant_profile', |
||||
| 61 | 'title' => _x( 'Merchant Profile', 'nocks', 'pronamic_ideal' ), |
||||
| 62 | 'type' => 'description', |
||||
| 63 | 'callback' => array( $this, 'field_merchant_profile' ), |
||||
| 64 | ); |
||||
| 65 | |||||
| 66 | // Webhook URL. |
||||
| 67 | $fields[] = array( |
||||
| 68 | 'section' => 'feedback', |
||||
| 69 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
||||
| 70 | 'type' => 'text', |
||||
| 71 | 'classes' => array( 'large-text', 'code' ), |
||||
| 72 | 'value' => add_query_arg( 'nocks_webhook', '', home_url( '/' ) ), |
||||
| 73 | 'readonly' => true, |
||||
| 74 | 'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
||||
| 75 | ); |
||||
| 76 | |||||
| 77 | return $fields; |
||||
| 78 | } |
||||
| 79 | |||||
| 80 | /** |
||||
| 81 | * Field merchant profile select. |
||||
| 82 | * |
||||
| 83 | * @param array $field Settings field. |
||||
| 84 | */ |
||||
| 85 | public function field_merchant_profile( $field ) { |
||||
| 86 | $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...
|
|||||
| 87 | $merchant_profile = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_merchant_profile', true ); |
||||
| 88 | |||||
| 89 | if ( ! $access_token ) { |
||||
| 90 | esc_html_e( 'First enter an API Key and save the configuration, to be able to choose from your Nocks merchant profiles.', 'pronamic_ideal' ); |
||||
| 91 | |||||
| 92 | return; |
||||
| 93 | } |
||||
| 94 | |||||
| 95 | $client = new Client(); |
||||
| 96 | |||||
| 97 | $client->set_access_token( $access_token ); |
||||
| 98 | |||||
| 99 | // Select merchant profile. |
||||
| 100 | printf( '<select name="%s">', esc_attr( $field['meta_key'] ) ); |
||||
| 101 | |||||
| 102 | $options = array( |
||||
| 103 | __( '— Select Merchant Profile —', 'pronamic_ideal' ), |
||||
| 104 | ); |
||||
| 105 | |||||
| 106 | $options = array_merge( $options, $client->get_merchant_profiles() ); |
||||
| 107 | |||||
| 108 | $options = array( |
||||
| 109 | array( |
||||
| 110 | 'options' => $options, |
||||
| 111 | ), |
||||
| 112 | ); |
||||
| 113 | |||||
| 114 | 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...
|
|||||
| 115 | |||||
| 116 | echo '</select>'; |
||||
| 117 | } |
||||
| 118 | |||||
| 119 | public function get_config( $post_id ) { |
||||
| 120 | $config = new Config(); |
||||
| 121 | |||||
| 122 | $config->post_id = $post_id; |
||||
| 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 |