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