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\OmniKassa2 |
||||||
9 | */ |
||||||
10 | |||||||
11 | namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; |
||||||
12 | |||||||
13 | use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration; |
||||||
14 | |||||||
15 | /** |
||||||
16 | * Integration |
||||||
17 | * |
||||||
18 | * @author Remco Tolsma |
||||||
19 | * @version 2.1.0 |
||||||
20 | * @since 1.0.0 |
||||||
21 | */ |
||||||
22 | class Integration extends AbstractIntegration { |
||||||
23 | /** |
||||||
24 | * Construct and initialize integration. |
||||||
25 | */ |
||||||
26 | public function __construct() { |
||||||
27 | $this->id = 'rabobank-omnikassa-2'; |
||||||
28 | $this->name = 'Rabobank - OmniKassa 2.0'; |
||||||
29 | $this->product_url = 'https://www.rabobank.nl/bedrijven/betalen/geld-ontvangen/rabo-omnikassa/'; |
||||||
30 | $this->dashboard_url = 'https://bankieren.rabobank.nl/omnikassa-dashboard/'; |
||||||
31 | $this->provider = 'rabobank'; |
||||||
32 | $this->supports = array( |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
33 | 'webhook', |
||||||
34 | ); |
||||||
35 | |||||||
36 | /** |
||||||
37 | * Webhook listener function. |
||||||
38 | * |
||||||
39 | * @var callable $webhook_listener_function |
||||||
40 | */ |
||||||
41 | $webhook_listener_function = array( __NAMESPACE__ . '\WebhookListener', 'listen' ); |
||||||
42 | |||||||
43 | if ( ! has_action( 'wp_loaded', $webhook_listener_function ) ) { |
||||||
44 | add_action( 'wp_loaded', $webhook_listener_function ); |
||||||
45 | } |
||||||
46 | |||||||
47 | /** |
||||||
48 | * Save post. |
||||||
49 | * |
||||||
50 | * @link https://github.com/WordPress/WordPress/blob/5.0/wp-includes/post.php#L3724-L3736 |
||||||
51 | * |
||||||
52 | * @var callable $delete_access_token_meta_function |
||||||
53 | */ |
||||||
54 | $delete_access_token_meta_function = array( $this, 'delete_access_token_meta' ); |
||||||
55 | |||||||
56 | if ( ! has_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function ) ) { |
||||||
57 | add_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function ); |
||||||
58 | } |
||||||
59 | |||||||
60 | /** |
||||||
61 | * Admin notices. |
||||||
62 | * |
||||||
63 | * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264 |
||||||
64 | * |
||||||
65 | * @var callable $admin_notices_function |
||||||
66 | */ |
||||||
67 | $admin_notices_function = array( $this, 'admin_notice_tld_test' ); |
||||||
68 | |||||||
69 | if ( ! has_action( 'admin_notices', $admin_notices_function ) ) { |
||||||
70 | add_action( 'admin_notices', $admin_notices_function ); |
||||||
71 | } |
||||||
72 | } |
||||||
73 | |||||||
74 | /** |
||||||
75 | * Admin notice TLD .test. |
||||||
76 | * |
||||||
77 | * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264 |
||||||
78 | * @link https://developer.wordpress.org/reference/hooks/admin_notices/ |
||||||
79 | * @link https://developer.wordpress.org/reference/functions/get_current_screen/ |
||||||
80 | */ |
||||||
81 | public function admin_notice_tld_test() { |
||||||
82 | if ( has_filter( 'pronamic_pay_omnikassa_2_merchant_return_url' ) ) { |
||||||
83 | return; |
||||||
84 | } |
||||||
85 | |||||||
86 | $screen = get_current_screen(); |
||||||
87 | |||||||
88 | if ( null === $screen ) { |
||||||
89 | return; |
||||||
90 | } |
||||||
91 | |||||||
92 | if ( 'pronamic_gateway' !== $screen->id ) { |
||||||
93 | return; |
||||||
94 | } |
||||||
95 | |||||||
96 | $host = wp_parse_url( home_url( '/' ), PHP_URL_HOST ); |
||||||
97 | |||||||
98 | if ( is_array( $host ) ) { |
||||||
99 | return; |
||||||
100 | } |
||||||
101 | |||||||
102 | if ( '.test' !== substr( $host, -5 ) ) { |
||||||
103 | return; |
||||||
104 | } |
||||||
105 | |||||||
106 | $post_id = get_the_ID(); |
||||||
107 | |||||||
108 | if ( empty( $post_id ) ) { |
||||||
109 | return; |
||||||
110 | } |
||||||
111 | |||||||
112 | $gateway_id = get_post_meta( $post_id, '_pronamic_gateway_id', true ); |
||||||
113 | |||||||
114 | if ( 'rabobank-omnikassa-2' !== $gateway_id ) { |
||||||
115 | return; |
||||||
116 | } |
||||||
117 | |||||||
118 | $class = 'notice notice-error'; |
||||||
119 | $message = sprintf( |
||||||
120 | /* translators: 1: Pronamic Pay, 2: Documentation link, 3: <code>.test</code> */ |
||||||
121 | __( '%1$s — <a href="%2$s">OmniKassa 2 does not accept payments from %3$s environments</a>.', 'pronamic_ideal' ), |
||||||
122 | sprintf( |
||||||
123 | '<strong>%s</strong>', |
||||||
124 | __( 'Pronamic Pay', 'pronamic_ideal' ) |
||||||
125 | ), |
||||||
126 | 'https://github.com/wp-pay-gateways/omnikassa-2/tree/develop/documentation#merchantreturnurl-is-not-a-valid-web-address', |
||||||
127 | '<code>.test</code>' |
||||||
128 | ); |
||||||
129 | |||||||
130 | printf( |
||||||
131 | '<div class="%1$s"><p>%2$s</p></div>', |
||||||
132 | esc_attr( $class ), |
||||||
133 | wp_kses( |
||||||
134 | $message, |
||||||
135 | array( |
||||||
136 | 'a' => array( |
||||||
137 | 'href' => true, |
||||||
138 | ), |
||||||
139 | 'code' => array(), |
||||||
140 | 'strong' => array(), |
||||||
141 | ) |
||||||
142 | ) |
||||||
143 | ); |
||||||
144 | } |
||||||
145 | |||||||
146 | /** |
||||||
147 | * Get settings fields. |
||||||
148 | * |
||||||
149 | * @return array |
||||||
150 | */ |
||||||
151 | public function get_settings_fields() { |
||||||
152 | $fields = array(); |
||||||
153 | |||||||
154 | // Refresh Token. |
||||||
155 | $fields[] = array( |
||||||
156 | 'section' => 'general', |
||||||
157 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
158 | 'meta_key' => '_pronamic_gateway_omnikassa_2_refresh_token', |
||||||
159 | 'title' => _x( 'Refresh Token', 'omnikassa', 'pronamic_ideal' ), |
||||||
160 | 'type' => 'textarea', |
||||||
161 | 'classes' => array( 'code' ), |
||||||
162 | ); |
||||||
163 | |||||||
164 | // Signing Key. |
||||||
165 | $fields[] = array( |
||||||
166 | 'section' => 'general', |
||||||
167 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
168 | 'meta_key' => '_pronamic_gateway_omnikassa_2_signing_key', |
||||||
169 | 'title' => _x( 'Signing Key', 'omnikassa', 'pronamic_ideal' ), |
||||||
170 | 'type' => 'text', |
||||||
171 | 'classes' => array( 'large-text', 'code' ), |
||||||
172 | ); |
||||||
173 | |||||||
174 | // Purchase ID. |
||||||
175 | $fields[] = array( |
||||||
176 | 'section' => 'advanced', |
||||||
177 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
178 | 'meta_key' => '_pronamic_gateway_omnikassa_2_order_id', |
||||||
179 | 'title' => __( 'Order ID', 'pronamic_ideal' ), |
||||||
180 | 'type' => 'text', |
||||||
181 | 'classes' => array( 'regular-text', 'code' ), |
||||||
182 | 'tooltip' => sprintf( |
||||||
183 | /* translators: %s: Parameter */ |
||||||
184 | __( 'The OmniKassa %s parameter.', 'pronamic_ideal' ), |
||||||
185 | sprintf( '<code>%s</code>', 'orderId' ) |
||||||
186 | ), |
||||||
187 | 'description' => sprintf( |
||||||
188 | '%s %s<br />%s', |
||||||
189 | __( 'Available tags:', 'pronamic_ideal' ), |
||||||
190 | sprintf( |
||||||
191 | '<code>%s</code> <code>%s</code>', |
||||||
192 | '{order_id}', |
||||||
193 | '{payment_id}' |
||||||
194 | ), |
||||||
195 | sprintf( |
||||||
196 | /* translators: %s: {payment_id} */ |
||||||
197 | __( 'Default: <code>%s</code>', 'pronamic_ideal' ), |
||||||
198 | '{payment_id}' |
||||||
199 | ) |
||||||
200 | ), |
||||||
201 | ); |
||||||
202 | |||||||
203 | // Webhook. |
||||||
204 | $fields[] = array( |
||||||
205 | 'section' => 'feedback', |
||||||
206 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
||||||
207 | 'type' => 'text', |
||||||
208 | 'classes' => array( 'large-text', 'code' ), |
||||||
209 | 'value' => add_query_arg( 'omnikassa2_webhook', '', home_url( '/' ) ), |
||||||
210 | 'readonly' => true, |
||||||
211 | 'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
||||||
212 | ); |
||||||
213 | |||||||
214 | return $fields; |
||||||
215 | } |
||||||
216 | |||||||
217 | /** |
||||||
218 | * Get configuration by post ID. |
||||||
219 | * |
||||||
220 | * @param string $post_id Post ID. |
||||||
221 | * @return Config |
||||||
222 | */ |
||||||
223 | public function get_config( $post_id ) { |
||||||
224 | $config = new Config(); |
||||||
225 | |||||||
226 | $config->post_id = intval( $post_id ); |
||||||
227 | $config->mode = $this->get_meta( $post_id, 'mode' ); |
||||||
0 ignored issues
–
show
The method
get_meta() does not exist on Pronamic\WordPress\Pay\G...\OmniKassa2\Integration . Did you maybe mean get_name() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
228 | $config->refresh_token = $this->get_meta( $post_id, 'omnikassa_2_refresh_token' ); |
||||||
229 | $config->signing_key = $this->get_meta( $post_id, 'omnikassa_2_signing_key' ); |
||||||
230 | $config->access_token = $this->get_meta( $post_id, 'omnikassa_2_access_token' ); |
||||||
231 | $config->access_token_valid_until = $this->get_meta( $post_id, 'omnikassa_2_access_token_valid_until' ); |
||||||
232 | $config->order_id = $this->get_meta( $post_id, 'omnikassa_2_order_id' ); |
||||||
233 | |||||||
234 | return $config; |
||||||
235 | } |
||||||
236 | |||||||
237 | /** |
||||||
238 | * Delete access token meta for the specified post ID. |
||||||
239 | * |
||||||
240 | * @link https://github.com/WordPress/WordPress/blob/5.0/wp-includes/post.php#L3724-L3736 |
||||||
241 | * @link https://codex.wordpress.org/Function_Reference/delete_post_meta |
||||||
242 | * |
||||||
243 | * @param int $post_id Post ID. |
||||||
244 | */ |
||||||
245 | public static function delete_access_token_meta( $post_id ) { |
||||||
246 | delete_post_meta( $post_id, '_pronamic_gateway_omnikassa_2_access_token' ); |
||||||
247 | delete_post_meta( $post_id, '_pronamic_gateway_omnikassa_2_access_token_valid_until' ); |
||||||
248 | } |
||||||
249 | |||||||
250 | /** |
||||||
251 | * Get gateway. |
||||||
252 | * |
||||||
253 | * @param int $post_id Post ID. |
||||||
254 | * @return Gateway |
||||||
255 | */ |
||||||
256 | public function get_gateway( $post_id ) { |
||||||
257 | return new Gateway( $this->get_config( $post_id ) ); |
||||||
258 | } |
||||||
259 | } |
||||||
260 |