1 | <?php |
||
2 | /** |
||
3 | * Integration |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2019 Pronamic |
||
7 | * @license GPL-3.0-or-later |
||
8 | * @package Pronamic\WordPress\Pay\Gateways\Adyen |
||
9 | */ |
||
10 | |||
11 | namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
||
12 | |||
13 | use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration; |
||
14 | use Pronamic\WordPress\Pay\Util as Pay_Util; |
||
15 | |||
16 | /** |
||
17 | * Integration |
||
18 | * |
||
19 | * @author Remco Tolsma |
||
20 | * @version 1.0.0 |
||
21 | * @since 1.0.0 |
||
22 | */ |
||
23 | class Integration extends AbstractIntegration { |
||
24 | /** |
||
25 | * Integration constructor. |
||
26 | */ |
||
27 | 1 | public function __construct() { |
|
28 | 1 | $this->id = 'adyen'; |
|
29 | 1 | $this->name = 'Adyen'; |
|
30 | 1 | $this->provider = 'adyen'; |
|
31 | 1 | $this->url = 'https://www.adyen.com/'; |
|
32 | 1 | $this->dashboard_url = array( |
|
33 | 1 | __( 'test', 'pronamic_ideal' ) => 'https://ca-test.adyen.com/ca/ca/login.shtml', |
|
34 | 1 | __( 'live', 'pronamic_ideal' ) => 'https://ca-live.adyen.com/ca/ca/login.shtml', |
|
35 | ); |
||
36 | |||
37 | // Notifications. |
||
38 | 1 | $notifications = new NotificationsController(); |
|
39 | |||
40 | 1 | $notifications->setup(); |
|
41 | |||
42 | // Settings. |
||
43 | 1 | add_action( 'init', array( $this, 'init' ) ); |
|
44 | 1 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
|
45 | 1 | } |
|
46 | |||
47 | /** |
||
48 | * Initialize. |
||
49 | */ |
||
50 | public function init() { |
||
51 | /* |
||
52 | * Authentication - User Name |
||
53 | */ |
||
54 | register_setting( |
||
55 | 'pronamic_pay', |
||
56 | 'pronamic_pay_adyen_notification_authentication_username', |
||
57 | array( |
||
58 | 'type' => 'string', |
||
59 | 'sanitize_callback' => 'sanitize_text_field', |
||
60 | ) |
||
61 | ); |
||
62 | |||
63 | /* |
||
64 | * Authentication - Password |
||
65 | */ |
||
66 | register_setting( |
||
67 | 'pronamic_pay', |
||
68 | 'pronamic_pay_adyen_notification_authentication_password', |
||
69 | array( |
||
70 | 'type' => 'string', |
||
71 | 'sanitize_callback' => 'sanitize_text_field', |
||
72 | ) |
||
73 | ); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Admin initialize. |
||
78 | */ |
||
79 | public function admin_init() { |
||
80 | add_settings_section( |
||
81 | 'pronamic_pay_adyen_notification_authentication', |
||
82 | __( 'Adyen Notification Authentication', 'pronamic_ideal' ), |
||
83 | '__return_false', |
||
84 | 'pronamic_pay' |
||
85 | ); |
||
86 | |||
87 | add_settings_field( |
||
88 | 'pronamic_pay_adyen_notification_authentication_username', |
||
89 | __( 'User Name', 'pronamic_ideal' ), |
||
90 | array( __CLASS__, 'input_element' ), |
||
91 | 'pronamic_pay', |
||
92 | 'pronamic_pay_adyen_notification_authentication', |
||
93 | array( |
||
94 | 'label_for' => 'pronamic_pay_adyen_notification_authentication_username', |
||
95 | ) |
||
96 | ); |
||
97 | |||
98 | add_settings_field( |
||
99 | 'pronamic_pay_adyen_notification_authentication_password', |
||
100 | __( 'Password', 'pronamic_ideal' ), |
||
101 | array( __CLASS__, 'input_element' ), |
||
102 | 'pronamic_pay', |
||
103 | 'pronamic_pay_adyen_notification_authentication', |
||
104 | array( |
||
105 | 'label_for' => 'pronamic_pay_adyen_notification_authentication_password', |
||
106 | ) |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Input text. |
||
112 | * |
||
113 | * @param array $args Arguments. |
||
114 | */ |
||
115 | public static function input_element( $args ) { |
||
116 | $defaults = array( |
||
117 | 'type' => 'text', |
||
118 | 'classes' => 'regular-text', |
||
119 | 'description' => '', |
||
120 | 'options' => array(), |
||
121 | ); |
||
122 | |||
123 | $args = wp_parse_args( $args, $defaults ); |
||
124 | |||
125 | $name = $args['label_for']; |
||
126 | $value = get_option( $name ); |
||
127 | |||
128 | $atts = array( |
||
129 | 'name' => $name, |
||
130 | 'id' => $name, |
||
131 | 'type' => $args['type'], |
||
132 | 'class' => $args['classes'], |
||
133 | 'value' => $value, |
||
134 | ); |
||
135 | |||
136 | switch ( $args['type'] ) { |
||
137 | case 'select': |
||
138 | printf( |
||
139 | '<select %1$s />%2$s</select>', |
||
140 | // @codingStandardsIgnoreStart |
||
141 | Pay_Util::array_to_html_attributes( $atts ), |
||
142 | Pay_Util::select_options_grouped( $args['options'], $value ) |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
143 | // @codingStandardsIgnoreEnd |
||
144 | ); |
||
145 | |||
146 | break; |
||
147 | default: |
||
148 | printf( |
||
149 | '<input %1$s />', |
||
150 | // @codingStandardsIgnoreStart |
||
151 | Pay_Util::array_to_html_attributes( $atts ) |
||
152 | // @codingStandardsIgnoreEnd |
||
153 | ); |
||
154 | } |
||
155 | |||
156 | if ( ! empty( $args['description'] ) ) { |
||
157 | printf( |
||
158 | '<p class="description">%s</p>', |
||
159 | esc_html( $args['description'] ) |
||
160 | ); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Get config factory class. |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | 1 | public function get_config_factory_class() { |
|
170 | 1 | return __NAMESPACE__ . '\ConfigFactory'; |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * Get settings class. |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | public function get_settings_class() { |
||
179 | return __NAMESPACE__ . '\Settings'; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Get required settings for this integration. |
||
184 | * |
||
185 | * @link https://github.com/wp-premium/gravityforms/blob/1.9.16/includes/fields/class-gf-field-multiselect.php#L21-L42 |
||
186 | * @since 1.1.6 |
||
187 | * @return array |
||
188 | */ |
||
189 | public function get_settings() { |
||
190 | $settings = parent::get_settings(); |
||
191 | |||
192 | $settings[] = 'adyen'; |
||
193 | |||
194 | return $settings; |
||
195 | } |
||
196 | } |
||
197 |