wp-pay-gateways /
nocks
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Pronamic\WordPress\Pay\Gateways\Nocks; |
||||
| 4 | |||||
| 5 | use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration; |
||||
| 6 | use Pronamic\WordPress\Pay\Util; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * Title: Nocks integration |
||||
| 10 | * Description: |
||||
| 11 | * Copyright: 2005-2020 Pronamic |
||||
| 12 | * Company: Pronamic |
||||
| 13 | * |
||||
| 14 | * @author Reüel van der Steege |
||||
| 15 | * @version 2.0.0 |
||||
| 16 | * @since 1.0.0 |
||||
| 17 | */ |
||||
| 18 | class Integration extends AbstractIntegration { |
||||
| 19 | public function __construct() { |
||||
| 20 | $this->id = 'nocks'; |
||||
| 21 | $this->name = 'Nocks - Checkout'; |
||||
| 22 | $this->product_url = 'https://www.nocks.com/'; |
||||
| 23 | $this->dashboard_url = 'https://www.nocks.com/'; |
||||
| 24 | $this->provider = 'nocks'; |
||||
| 25 | $this->supports = array( |
||||
| 26 | 'payment_status_request', |
||||
| 27 | 'webhook', |
||||
| 28 | 'webhook_log', |
||||
| 29 | 'webhook_no_config', |
||||
| 30 | ); |
||||
| 31 | |||||
| 32 | // Actions |
||||
| 33 | $function = array( __NAMESPACE__ . '\Listener', 'listen' ); |
||||
| 34 | |||||
| 35 | if ( ! has_action( 'wp_loaded', $function ) ) { |
||||
| 36 | add_action( 'wp_loaded', $function ); |
||||
| 37 | } |
||||
| 38 | } |
||||
| 39 | |||||
| 40 | /** |
||||
| 41 | * Get settings fields. |
||||
| 42 | * |
||||
| 43 | * @return array |
||||
| 44 | */ |
||||
| 45 | public function get_settings_fields() { |
||||
| 46 | $fields = array(); |
||||
| 47 | |||||
| 48 | // Access token. |
||||
| 49 | $fields[] = array( |
||||
| 50 | 'section' => 'general', |
||||
| 51 | 'filter' => FILTER_SANITIZE_STRING, |
||||
| 52 | 'meta_key' => '_pronamic_gateway_nocks_access_token', |
||||
| 53 | 'title' => _x( 'Access Token', 'nocks', 'pronamic_ideal' ), |
||||
| 54 | 'type' => 'textarea', |
||||
| 55 | 'classes' => array( 'code' ), |
||||
| 56 | ); |
||||
| 57 | |||||
| 58 | // Merchant profile. |
||||
| 59 | $fields[] = array( |
||||
| 60 | 'section' => 'general', |
||||
| 61 | 'filter' => FILTER_SANITIZE_STRING, |
||||
| 62 | 'meta_key' => '_pronamic_gateway_nocks_merchant_profile', |
||||
| 63 | 'title' => _x( 'Merchant Profile', 'nocks', 'pronamic_ideal' ), |
||||
| 64 | 'type' => 'description', |
||||
| 65 | 'callback' => array( $this, 'field_merchant_profile' ), |
||||
| 66 | ); |
||||
| 67 | |||||
| 68 | // Webhook URL. |
||||
| 69 | $fields[] = array( |
||||
| 70 | 'section' => 'feedback', |
||||
| 71 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
||||
| 72 | 'type' => 'text', |
||||
| 73 | 'classes' => array( 'large-text', 'code' ), |
||||
| 74 | 'value' => add_query_arg( 'nocks_webhook', '', home_url( '/' ) ), |
||||
| 75 | 'readonly' => true, |
||||
| 76 | 'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
||||
| 77 | ); |
||||
| 78 | |||||
| 79 | return $fields; |
||||
| 80 | } |
||||
| 81 | |||||
| 82 | /** |
||||
| 83 | * Field merchant profile select. |
||||
| 84 | * |
||||
| 85 | * @param array $field Settings field. |
||||
| 86 | */ |
||||
| 87 | public function field_merchant_profile( $field ) { |
||||
| 88 | $access_token = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_access_token', true ); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 89 | $merchant_profile = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_merchant_profile', true ); |
||||
| 90 | |||||
| 91 | if ( ! $access_token ) { |
||||
| 92 | esc_html_e( 'First enter an API Key and save the configuration, to be able to choose from your Nocks merchant profiles.', 'pronamic_ideal' ); |
||||
| 93 | |||||
| 94 | return; |
||||
| 95 | } |
||||
| 96 | |||||
| 97 | $client = new Client(); |
||||
| 98 | |||||
| 99 | $client->set_access_token( $access_token ); |
||||
| 100 | |||||
| 101 | // Select merchant profile. |
||||
| 102 | printf( '<select name="%s">', esc_attr( $field['meta_key'] ) ); |
||||
| 103 | |||||
| 104 | $options = array( |
||||
| 105 | __( '— Select Merchant Profile —', 'pronamic_ideal' ), |
||||
| 106 | ); |
||||
| 107 | |||||
| 108 | try { |
||||
| 109 | $options = array_merge( $options, $client->get_merchant_profiles() ); |
||||
| 110 | } catch ( \Exception $e ) { |
||||
| 111 | // What to do? |
||||
| 112 | } |
||||
| 113 | |||||
| 114 | $options = array( |
||||
| 115 | array( |
||||
| 116 | 'options' => $options, |
||||
| 117 | ), |
||||
| 118 | ); |
||||
| 119 | |||||
| 120 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||||
| 121 | echo Util::select_options_grouped( $options, $merchant_profile ); |
||||
|
0 ignored issues
–
show
It seems like
$merchant_profile can also be of type false; however, parameter $selected_value of Pronamic\WordPress\Pay\U...elect_options_grouped() does only seem to accept string, 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...
|
|||||
| 122 | |||||
| 123 | echo '</select>'; |
||||
| 124 | } |
||||
| 125 | |||||
| 126 | public function get_config( $post_id ) { |
||||
| 127 | $config = new Config(); |
||||
| 128 | |||||
| 129 | $config->mode = $this->get_meta( $post_id, '_pronamic_gateway_mode' ); |
||||
| 130 | $config->access_token = $this->get_meta( $post_id, '_pronamic_gateway_nocks_access_token' ); |
||||
| 131 | $config->merchant_profile = $this->get_meta( $post_id, '_pronamic_gateway_nocks_merchant_profile' ); |
||||
| 132 | |||||
| 133 | return $config; |
||||
| 134 | } |
||||
| 135 | |||||
| 136 | /** |
||||
| 137 | * Get gateway. |
||||
| 138 | * |
||||
| 139 | * @param int $post_id Post ID. |
||||
| 140 | * @return Gateway |
||||
| 141 | */ |
||||
| 142 | public function get_gateway( $post_id ) { |
||||
| 143 | return new Gateway( $this->get_config( $post_id ) ); |
||||
| 144 | } |
||||
| 145 | } |
||||
| 146 |