PluginProbe
MONEI Payments for WooCommerce / 4.1.1
MONEI Payments for WooCommerce v4.1.1
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / monei.php

monei.php in MONEI Payments for WooCommerce 4.1.1, at monei.php

1,186 lines 44.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * WooCommerce MONEI Gateway
5 *
6 * @package WooCommerce MONEI Gateway
7 * @author José Conti
8 * @copyright 2020-2020 MONEI Conti
9 * @license GPL-3.0+
10 *
11 * Plugin Name: WooCommerce MONEI Gateway
12 * Plugin URI: https://wordpress.org/plugins/monei/
13 * Description: Extends WooCommerce with a MONEI gateway. Best payment gateway rates. The perfect solution to manage your digital payments.
14 * Version: 4.1.1
15 * Author: MONEI
16 * Author URI: https://www.monei.net/
17 * Tested up to: 5.6
18 * WC requires at least: 3.0
19 * WC tested up to: 4.9
20 * Text Domain: monei
21 * Domain Path: /languages/
22 * Copyright: (C) 2017 MONEI.
23 * License: GNU General Public License v3.0
24 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
25 */
26
27 define( 'MONEI_VERSION', '4.1.1' );
28 define( 'MONEI_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
29 define( 'MONEI_SIGNUP', 'https://dashboard.monei.net/?action=signUp' );
30 define( 'MONEI_WEB', 'https://monei.net/' );
31 define( 'MONEI_REVIEW', 'https://wordpress.org/support/plugin/monei/reviews/?rate=5#new-post' );
32 define( 'MONEI_SUPPORT', 'https://support.monei.net/' );
33
34 add_action( 'plugins_loaded', 'woocommerce_gateway_monei_init', 0 );
35
36 require_once 'includes/vendor/autoload.php';
37
38
39 function woocommerce_gateway_monei_init() {
40 if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
41 return;
42 }
43 /**
44 * Localisation
45 */
46 load_plugin_textdomain( 'monei', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
47 /**
48 * Gateway class
49 */
50 class WC_Gateway_Monei extends WC_Payment_Gateway {
51 var $notify_url;
52 /**
53 * Constructor for the gateway.
54 *
55 * @access public
56 * @return void
57 */
58 public function __construct() {
59 global $woocommerce;
60 $this->id = 'monei';
61 $logo_url = $this->get_option( 'logo' );
62 if ( ! empty( $logo_url ) ) {
63 $logo_url = $this->get_option( 'logo' );
64 $this->icon = apply_filters( 'woocommerce_monei_icon', $logo_url );
65 } else {
66 $this->icon = apply_filters( 'woocommerce_monei_icon', plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) . '/assets/images/MONEI-logo.png' );
67 }
68 $this->has_fields = true;
69 $this->liveurl = 'https://pay.monei.net/checkout';
70 $this->refund_url = 'https://api.monei.net/v1/refund';
71 $this->charge_url = 'https://api.monei.net/v1/charge';
72 $this->testmode = $this->get_option( 'testmode' );
73 $this->method_title = __( 'MONEI', 'monei' );
74 $this->notify_url = add_query_arg( 'wc-api', 'WC_Gateway_monei', home_url( '/' ) );
75 $this->notify_url_not_https = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_monei', home_url( '/' ) ) );
76 // Define user set variables.
77 $this->title = $this->get_option( 'title' );
78 $this->description = $this->get_option( 'description' );
79 $this->logo = $this->get_option( 'logo' );
80 $this->orderdo = $this->get_option( 'orderdo' );
81 $this->accountid = $this->get_option( 'accountid' );
82 $this->apikey = $this->get_option( 'apikey' );
83 $this->commercename = $this->get_option( 'commercename' );
84 $this->secret = $this->get_option( 'secret' );
85 $this->password = $this->get_option( 'password' );
86 $this->tokenization = $this->get_option( 'tokenization' );
87 $this->debug = $this->get_option( 'debug' );
88 $this->log = new WC_Logger();
89 $this->supports = array(
90 'products',
91 'tokenization',
92 'refunds',
93 'subscriptions',
94 'subscription_cancellation',
95 'subscription_suspension',
96 'subscription_reactivation',
97 'subscription_amount_changes',
98 'subscription_date_changes',
99 'subscription_payment_method_change',
100 'subscription_payment_method_change_customer',
101 'subscription_payment_method_change_admin',
102 'multiple_subscriptions',
103 );
104 $this->init_form_fields();
105 $this->init_settings();
106 // Actions.
107 add_action( 'valid_monei_standard_ipn_request', array( $this, 'successful_request' ) );
108 add_action( 'woocommerce_receipt_monei', array( $this, 'receipt_page' ) );
109 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
110 // Payment listener/API hook.
111 add_action( 'woocommerce_api_wc_gateway_' . $this->id, array( $this, 'check_ipn_response' ) );
112
113 if ( class_exists( 'WC_Subscriptions_Order' ) ) {
114 add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'doing_scheduled_subscription_payment' ), 10, 2 );
115 }
116 if ( ! $this->is_valid_for_use() ) {
117 $this->enabled = false;
118 }
119 }
120
121 /**
122 * Check if this gateway is enabled and available in the user's country
123 *
124 * @access public
125 * @return bool
126 */
127 function is_valid_for_use() {
128
129 if ( ! in_array( get_woocommerce_currency(), array( 'EUR', 'USD', 'GBP' ), true ) ) {
130 return false;
131 } else {
132 return true;
133 }
134 }
135 function product_description( $order ) {
136
137 $product_id = '';
138 $name = '';
139 $sku = '';
140 foreach ( $order->get_items() as $item ) {
141 $product_id .= $item->get_product_id() . ', ';
142 $name .= $item->get_name() . ', ';
143 $sku .= get_post_meta( $item->get_product_id(), '_sku', true) . ', ';
144 }
145 // Can be order, id, name or sku
146 $description_type = 'name';
147
148 if ( 'id' === $description_type ) {
149 $description = $product_id;
150 } elseif ( 'name' === $description_type ) {
151 $description = $name;
152 } elseif ( 'sku' === $description_type ) {
153 $description = $sku;
154 } else {
155 $description = __( 'Order', 'monei' ) . ' ' . $order->get_order_number();
156 }
157 return $description;
158 }
159 /**
160 * Admin Panel Options
161 *
162 * @since 1.0.0
163 */
164 public function admin_options() {
165 ?>
166 <h3><?php esc_html_e( 'MONEI', 'monei' ); ?></h3>
167 <p><?php esc_html_e( 'Best payment gateway rates. The perfect solution to manage your digital payments.', 'monei' ); ?></p>
168 <?php if ( $this->is_valid_for_use() ) : ?>
169 <table class="form-table">
170 <?php
171 // Generate the HTML For the settings form.
172 $this->generate_settings_html();
173 ?>
174 </table><!--/.form-table-->
175 <?php else : ?>
176 <div class="inline error"><p><strong><?php esc_html_e( 'Gateway Disabled', 'monei' ); ?></strong>: <?php esc_html_e( 'MONEI only support EUROS, USD & GBP currencies.', 'monei' ); ?></p></div>
177 <?php
178 endif;
179 }
180 /**
181 * Initialise Gateway Settings Form Fields
182 *
183 * @access public
184 * @return void
185 */
186 function init_form_fields() {
187 $this->form_fields = array(
188 'enabled' => array(
189 'title' => __( 'Enable/Disable', 'monei' ),
190 'type' => 'checkbox',
191 'label' => __( 'Enable MONEI', 'monei' ),
192 'default' => 'no',
193 ),
194 'title' => array(
195 'title' => __( 'Title', 'monei' ),
196 'type' => 'text',
197 'description' => __( 'This controls the title which the user sees during checkout.', 'monei' ),
198 'default' => __( 'MONEI', 'monei' ),
199 'desc_tip' => true,
200 ),
201 'description' => array(
202 'title' => __( 'Description', 'monei' ),
203 'type' => 'textarea',
204 'description' => __( 'This controls the description which the user sees during checkout.', 'monei' ),
205 'default' => __( 'Pay via MONEI; you can pay with your credit card.', 'monei' ),
206 ),
207 'logo' => array(
208 'title' => __( 'Logo', 'monei' ),
209 'type' => 'text',
210 'description' => __( 'Add link to image logo.', 'monei' ),
211 'desc_tip' => true,
212 ),
213 'commercename' => array(
214 'title' => __( 'Shop Name', 'monei' ),
215 'type' => 'text',
216 'description' => __( 'Shop Name', 'monei' ),
217 'desc_tip' => true,
218 ),
219 'accountid' => array(
220 'title' => __( 'Account ID', 'monei' ),
221 'type' => 'text',
222 'description' => __( 'Account ID', 'monei' ),
223 'desc_tip' => true,
224 ),
225 'apikey' => array(
226 'title' => __( 'API Key', 'monei' ),
227 'type' => 'text',
228 'description' => __( 'API Key', 'monei' ),
229 ),
230 'password' => array(
231 'title' => __( 'Password', 'monei' ),
232 'type' => 'text',
233 'description' => __( 'MONEI Password', 'monei' ),
234 'desc_tip' => true,
235 ),
236 'tokenization' => array(
237 'title' => __( 'Enable/Disable', 'monei' ),
238 'type' => 'checkbox',
239 'label' => __( 'Enable Tokenization', 'monei' ),
240 'default' => 'no',
241 ),
242 'orderdo' => array(
243 'title' => __( 'What to do after payment?', 'monei' ),
244 'type' => 'select',
245 'description' => __( 'Chose what to do after the customer pay the order.', 'monei' ),
246 'default' => 'processing',
247 'options' => array(
248 'processing' => __( 'Mark as Processing (default & recomended)', 'monei' ),
249 'completed' => __( 'Mark as Complete', 'monei' ),
250 ),
251 ),
252 'testmode' => array(
253 'title' => __( 'Running in test mode', 'monei' ),
254 'type' => 'checkbox',
255 'label' => __( 'Running in test mode', 'monei' ),
256 'default' => 'yes',
257 'description' => sprintf( __( 'Select this option for the initial testing required by MONEI, deselect this option once you pass the required test phase and your production environment is active.', 'monei' ) ),
258 ),
259 'debug' => array(
260 'title' => __( 'Debug Log', 'monei' ),
261 'type' => 'checkbox',
262 'label' => __( 'Enable logging', 'monei' ),
263 'default' => 'no',
264 'description' => __( 'Log MONEY events, such as notifications requests, inside <code>WooCommerce > Status > Logs > Select MONEI Logs</code>', 'monei' ),
265 ),
266 );
267 }
268
269 function test_mode() {
270 if ( 'yes' === $this->testmode ) {
271 $test = 'true';
272 } else {
273 $test = 'false';
274 }
275 return $test;
276 }
277
278 function amount_format( $total ) {
279 $order_total_sign = number_format( $total, 2, '', '' );
280 return $order_total_sign;
281 }
282
283 function get_monei_args( $order ) {
284 global $woocommerce;
285
286 $order_id = $order->get_id();
287 $url_challenge = get_transient( 'monei_url_challenge_' . sanitize_title( $order_id ) );
288 $param_md = get_transient( 'monei_param_md_challenge_' . sanitize_title( $order_id ) );
289 $param_pareq = get_transient( 'monei_param_pareq_challenge_' . sanitize_title( $order_id ) );
290 $param_termurl = get_transient( 'monei_param_termurl_challenge_' . sanitize_title( $$order_id ) );
291
292 if ( $url_challenge ) {
293
294 $monei_args = array();
295
296 } else {
297
298 $currency = get_woocommerce_currency();
299 $account_id = $this->accountid;
300 $transaction_id = str_pad( $order_id, 12, '0', STR_PAD_LEFT );
301 $transaction_id1 = wp_rand( 1, 999 ); // lets to create a random number.
302 $transaction_id2 = substr_replace( $transaction_id, $transaction_id1, 0, -9 ); // new order number.
303 $amount = $order->get_total();
304 $country = new WC_Countries();
305 $shop_country = $country->get_base_country();
306 $shop_name = $this->commercename;
307 $url_callback = $this->notify_url;
308 $url_cancel = html_entity_decode( $order->get_cancel_order_url() );
309 $url_complete = utf8_encode( add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ) );
310 $transaction_type = 'sale';
311 $password = $this->password;
312 $test = $this->test_mode();
313
314 $message = 'account_id' . $account_id . 'amount' . $amount . 'currency' . $currency . 'order_id' . $transaction_id2 . 'shop_name' . $shop_name . 'test' . $test . 'transaction_type' . $transaction_type . 'url_callback' . $url_callback . 'url_cancel' . $url_cancel . 'url_complete' . $url_complete;
315
316 $sign = hash_hmac('sha256', $message, $password );
317
318 if ( 'yes' === $this->debug ) {
319 $this->log->add( 'monei', 'Generating payment form for order ' . $order->get_order_number() );
320 $this->log->add( 'monei', 'Helping to understand the encrypted code: ' );
321 $this->log->add( 'monei', 'account_id: ' . $account_id );
322 $this->log->add( 'monei', 'amount: ' . $amount );
323 $this->log->add( 'monei', 'currency: ' . $currency );
324 $this->log->add( 'monei', 'order_id: ' . $transaction_id2 );
325 $this->log->add( 'monei', 'shop_name: ' . $shop_name );
326 $this->log->add( 'monei', 'test: ' . $test );
327 $this->log->add( 'monei', 'url_callback: ' . $url_callback );
328 $this->log->add( 'monei', 'url_cancel: ' . $url_cancel );
329 $this->log->add( 'monei', 'url_complete: ' . $url_complete );
330 $this->log->add( 'monei', 'Password: ' . $password );
331 $this->log->add( 'monei', 'Shop country: ' . $shop_country );
332 $this->log->add( 'monei', 'concatenated: ' . $message );
333 $this->log->add( 'monei', 'sign: ' . $sign );
334 }
335 $monei_args = array(
336 'account_id' => $account_id,
337 'amount' => $amount,
338 'currency' => $currency,
339 'order_id' => $transaction_id2,
340 'shop_name' => $shop_name,
341 'test' => $test,
342 'transaction_type' => $transaction_type,
343 'url_callback' => $url_callback,
344 'url_cancel' => $url_cancel,
345 'url_complete' => $url_complete,
346 'signature' => $sign,
347 );
348 }
349 $monei_args = apply_filters( 'woocommerce_monei_args', $monei_args );
350 return $monei_args;
351 }
352
353 /**
354 * Generate the monei form
355 *
356 * @access public
357 * @param mixed $order_id
358 * @return string
359 */
360 function generate_monei_form( $order_id ) {
361 global $woocommerce;
362
363 $order = new WC_Order( $order_id );
364 $monei_args = $this->get_monei_args( $order );
365 $form_inputs = '';
366 $url_challenge = get_transient( 'monei_url_challenge_' . sanitize_title( $order_id ) );
367 if ( $url_challenge ) {
368 $monei_adr = $url_challenge;
369 } else {
370 $monei_adr = $this->liveurl . '?';
371 }
372
373 foreach ( $monei_args as $key => $value ) {
374 $form_inputs .= '<input type="hidden" name="' . $key . '" value="' . esc_attr( $value ) . '" />';
375 }
376 wc_enqueue_js( '
377 $("body").block({
378 message: "<img src=\"' . esc_url( apply_filters( 'woocommerce_ajax_loader_url', $woocommerce->plugin_url() . '/assets/images/select2-spinner.gif' ) ) . '\" alt=\"Redirecting&hellip;\" style=\"float:left; margin-right: 10px;\" />' . __( 'Thank you for your order. We are now redirecting you to MONEI to make the payment.', 'monei' ) . '",
379 overlayCSS:
380 {
381 background: "#fff",
382 opacity: 1.0
383 },
384 css: {
385 padding: 20,
386 textAlign: "center",
387 color: "#555",
388 border: "3px solid #aaa",
389 backgroundColor:"#fff",
390 cursor: "wait",
391 lineHeight: "32px"
392 }
393 });
394 jQuery("#submit_monei_payment_form").click();
395 ' );
396 return '<form action="' . esc_url( $monei_adr ) . '" method="post" id="monei_payment_form" target="_top">
397 ' . $form_inputs . '
398 <input type="submit" class="button-alt" id="submit_monei_payment_form" value="' . __( 'Pay with Credit Card via MONEI', 'monei' ) . '" /> <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' . __( 'Cancel order &amp; restore cart', 'monei' ) . '</a>
399 </form>';
400 }
401
402 function get_monei_users_token() {
403 $customer_token = null;
404 if ( is_user_logged_in() ) {
405 $tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id(), 'monei' );
406 foreach ( $tokens as $token ) {
407 if ( $token->get_gateway_id() === 'monei' ) {
408 $customer_token = $token->get_token();
409 }
410 }
411 }
412 return $customer_token;
413 }
414
415 function get_users_token_bulk( $user_id ) {
416 $customer_token = null;
417 $tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, 'monei' );
418 foreach ( $tokens as $token ) {
419 if ( $token->get_gateway_id() === 'monei' ) {
420 $customer_token = $token->get_token();
421 }
422 }
423 return $customer_token;
424 }
425
426 protected function order_contains_subscription( $order_id ) {
427 if ( ! function_exists( 'wcs_order_contains_subscription' ) ) {
428 return false;
429 } elseif ( wcs_order_contains_subscription( $order_id ) ) {
430 return true;
431 } elseif ( wcs_order_contains_resubscribe( $order_id ) ) {
432 return true;
433 } elseif ( wcs_order_contains_renewal( $order_id ) ) {
434 return true;
435 } else {
436 return false;
437 }
438 }
439
440 /**
441 * Process the payment and return the result
442 *
443 * @access public
444 * @param int $order_id
445 * @return array
446 */
447 function process_payment( $order_id ) {
448
449 $order = new WC_Order( $order_id );
450 $descripcion = $this->product_description( $order );
451 $transaction_type = 'sale';
452 $currency = get_woocommerce_currency();
453 $order_id = $order->get_id();
454 $user_id = $order->get_user_id();
455 $currency = get_woocommerce_currency();
456 $account_id = $this->accountid;
457 $transaction_id = str_pad( $order_id, 12, '0', STR_PAD_LEFT );
458 $transaction_id1 = wp_rand( 1, 999 ); // lets to create a random number.
459 $transaction_id2 = substr_replace( $transaction_id, $transaction_id1, 0, -9 ); // new order number.
460 $shop_name = $this->commercename;
461 $test = $this->test_mode();
462 $url_callback = $this->notify_url;
463 $url_cancel = html_entity_decode( $order->get_cancel_order_url() );
464 $url_complete = utf8_encode( add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ) );
465 $userip = WC_Geolocation::get_ip_address();
466 $useragent = wc_get_user_agent();
467 $monei_adr = $this->charge_url;
468 $amount = $this->amount_format( $order->get_total() );
469 $apikey = $this->apikey;
470 $customer_emial = $order->billing_email;
471 $token = false;
472 $token_post_id = false;
473
474 if ( 'yes' === $this->debug ) {
475 $this->log->add( 'monei', '$url_callback: ' . $url_callback );
476 $this->log->add( 'monei', '$url_cancel: ' . $url_cancel );
477 $this->log->add( 'monei', '$url_complete: ' . $url_complete );
478 }
479
480 if ( isset( $_POST['moneitoken'] ) ) {
481 $token_post_id = sanitize_text_field( $_POST['moneitoken'] );
482 }
483
484 if ( $token_post_id && ( 'no' !== $token_post_id && 'yes' !== $token_post_id ) ) {
485 $token_ob = WC_Payment_Tokens::get( $token_post_id );
486 $token = $token_ob->get_token();
487 }
488
489 if ( 'yes' === $this->debug ) {
490 $this->log->add( 'monei', '$token_post_id: ' . $token_post_id );
491 $this->log->add( 'monei', '$token: ' . $token );
492 //$this->log->add( 'monei', '$token_ob: ' . print_r( $token_ob, true ) );
493 }
494
495 if ( ( $this->order_contains_subscription( $order_id ) && ! $token ) || ( 'yes' === $this->tokenization && 'yes' === $token_post_id ) ) {
496 update_post_meta( $order_id, 'get_token', 'yes' );
497 $get_token = get_post_meta( $order_id, 'get_token', true );
498 if ( 'yes' === $this->debug ) {
499 $this->log->add( 'monei', '$get_token: ' . $get_token );
500 }
501 $body = array(
502 'amount' => $amount,
503 'currency' => $currency,
504 'orderId' => $transaction_id2,
505 'description' => $descripcion,
506 'customer' => array(
507 'email' => $customer_emial,
508 ),
509 'callbackUrl' => $url_callback,
510 'completeUrl' => $url_complete,
511 'cancelUrl' => $url_cancel,
512 'failUrl' => $url_cancel,
513 'generatePaymentToken' => 'true',
514 );
515 } elseif ( ( $this->order_contains_subscription( $order_id ) ) || ( 'yes' === $this->tokenization && $token ) ) {
516 $body = array(
517 'amount' => $amount,
518 'currency' => $currency,
519 'orderId' => $transaction_id2,
520 'description' => $descripcion,
521 'customer' => array(
522 'email' => $customer_emial,
523 ),
524 'callbackUrl' => $url_callback,
525 'completeUrl' => $url_complete,
526 'cancelUrl' => $url_cancel,
527 'failUrl' => $url_cancel,
528 'paymentToken' => $token,
529 );
530 } else {
531 update_post_meta( $order_id, 'get_token', 'no' );
532 $get_token = get_post_meta( $order_id, 'get_token', true );
533 if ( 'yes' === $this->debug ) {
534 $this->log->add( 'monei', '$get_token: ' . $get_token );
535 }
536 $body = array(
537 'amount' => $amount,
538 'currency' => $currency,
539 'orderId' => $transaction_id2,
540 'description' => $descripcion,
541 'customer' => array(
542 'email' => $customer_emial,
543 ),
544 'callbackUrl' => $url_callback,
545 'completeUrl' => $url_complete,
546 'cancelUrl' => $url_cancel,
547 'failUrl' => $url_cancel,
548 );
549 }
550
551 if ( 'yes' === $this->debug ) {
552 $this->log->add( 'monei', '$body: ' . print_r( json_decode( $body ), true ) );
553 }
554
555 $data_string = json_encode( $body );
556 $options = array(
557 'headers' => array(
558 'Content-Type' => 'application/json',
559 'Authorization' => $apikey,
560 ),
561 'body' => $data_string,
562 );
563 if ( 'yes' === $this->debug ) {
564 $this->log->add( 'monei', print_r( $options, true ) );
565 }
566 $monei_adr = 'https://api.monei.net/v1/payments';
567 $response = wp_remote_post( $monei_adr, $options );
568 $response_code = wp_remote_retrieve_response_code( $response );
569 $response_body = wp_remote_retrieve_body( $response );
570 $result = json_decode( $response_body );
571 $urlchallenge = $result->redirect_url;
572 $refultmonei = $result->result;
573 $status = $result->status;
574 $authorizationCode = $result->authorizationCode;
575 $id = $result->id;
576
577 if ( 'yes' === $this->debug ) {
578 $this->log->add( 'monei', '$response_body: ' . print_r( $response, true ) );
579 $this->log->add( 'monei', 'URL: ' . print_r( $result, true ) );
580 $this->log->add( 'monei', '/*************************/');
581 $this->log->add( 'monei', ' Get URL To redirect ');
582 $this->log->add( 'monei', '/*************************/');
583 $this->log->add( 'monei', '$response_body: ' . $response_body );
584 $this->log->add( 'monei', 'URL: ' . $result->nextAction->redirectUrl );
585 $this->log->add( 'monei', '$status: ' . $status );
586 $this->log->add( 'monei', '$authorizationCode: ' . $authorizationCode );
587 $this->log->add( 'monei', '$id: ' . $id );
588 }
589
590 return array(
591 'result' => 'success',
592 'redirect' => $result->nextAction->redirectUrl,
593 );
594 }
595 /**
596 * Output for the order received page.
597 *
598 * @access public
599 * @return void
600 */
601 function receipt_page( $order ) {
602 echo '<p>' . esc_html__( 'Thank you for your order, please click the button below to pay with Credit Card via MONEI.', 'monei' ) . '</p>';
603 echo $this->generate_monei_form( $order );
604 }
605
606 /**
607 * Check for Monei HTTP Notification
608 *
609 * @access public
610 * @return void
611 */
612 function check_ipn_response() {
613 if ( 'yes' === $this->debug ) {
614 $this->log->add( 'monei', ' ' );
615 $this->log->add( 'monei', '/****************************/' );
616 $this->log->add( 'monei', ' check_ipn_response ' );
617 $this->log->add( 'monei', '/****************************/' );
618 $this->log->add( 'monei', ' ' );
619 }
620 @ob_clean();
621 $json = file_get_contents( 'php://input' );
622 $data = json_decode( $json );
623 $result = $data->status;
624 if ( 'yes' === $this->debug ) {
625 $this->log->add( 'monei', $json );
626 $this->log->add( 'monei', '$result: ' . $result );
627 }
628
629 if ( 'SUCCEEDED' === $result ) {
630 header( 'HTTP/1.1 200 OK' );
631 do_action( 'valid_monei_standard_ipn_request', $data );
632 } else {
633 wp_die( 'MONEI Notification Request Failure' );
634 }
635 }
636 function is_paid( $order_id ){
637
638 $order = wc_get_order( $order_id );
639 $status = $order->get_status();
640 $status_paid = array(
641 'pending',
642 );
643 if ( $status_paid ) {
644 foreach ( $status_paid as $spaid ) {
645 if ( ( string ) $status === ( string ) $spaid ) {
646 if ( 'yes' === $this->debug ) {
647 $this->log->add( 'monei', '$status: ' . $status );
648 $this->log->add( 'monei', '$spaid: ' . $spaid );
649 $this->log->add( 'monei', 'Returning false' );
650 }
651 return false;
652 }
653 continue;
654 }
655 if ( 'yes' === $this->debug ) {
656 $this->log->add( 'monei', 'Returning true' );
657 }
658 return true;
659 } else {
660 if ( 'yes' === $this->debug ) {
661 $this->log->add( 'monei', 'Returning false' );
662 }
663 return false;
664 }
665 }
666 /**
667 * Successful Payment!
668 *
669 * @access public
670 * @param array $posted
671 * @return void
672 */
673 function successful_request( $data ) {
674 global $woocommerce;
675
676 $monei_order_id = sanitize_text_field( $data->id );
677 $order_id = sanitize_text_field( $data->orderId );
678 $message = sanitize_text_field( $data->message );
679 $order2 = substr( $order_id, 3 ); // cojo los 9 digitos del final.
680 $order = $this->get_monei_order( (int) $order2 );
681 $status = sanitize_text_field( $data->status );
682 $amount = floatval( $data->amount ) / 100;
683 $json = file_get_contents( 'php://input' );
684 $data = json_decode( $json );
685
686 if ( 'yes' === $this->debug ) {
687 $this->log->add( 'monei', '$monei_order_id: ' . $monei_order_id );
688 $this->log->add( 'monei', '$order_id: ' . $order_id );
689 $this->log->add( 'monei', '$status: ' . $status );
690 $this->log->add( 'monei', '$message: ' . $message );
691 }
692
693 if ( 'SUCCEEDED' === $status ) {
694 // authorized.
695 $order2 = substr( $order_id, 3 ); //cojo los 9 digitos del final
696 $order = new WC_Order( $order2 );
697 $amountwoo = floatval($order->get_total());
698
699 if ( $amountwoo !== $amount ) {
700 // amount does not match.
701 if ( 'yes' === $this->debug ) {
702 $this->log->add( 'monei', 'Payment error: Amounts do not match (order: ' . $amountwoo . ' - received: ' . $amount . ')' );
703 }
704 // Put this order on-hold for manual checking.
705 /* translators: order an received are the amount */
706 $order->update_status( 'on-hold', sprintf( __( 'Validation error: Order vs. Notification amounts do not match (order: %1$s - received: %2&s).', 'monei' ), $amountwoo, $amount ) );
707 exit;
708 }
709
710 if ( ! empty( $monei_order_id ) ) {
711 update_post_meta( $order->get_id(), '_payment_order_number_monei', $monei_order_id );
712 }
713
714 if ( ! empty( $order_id ) ) {
715 update_post_meta( $order->get_id(), '_payment_wc_order_id_monei', $order_id );
716 }
717
718 // Payment completed.
719 $order->add_order_note( __( 'HTTP Notification received - payment completed', 'monei' ) );
720 $order->add_order_note( __( 'MONEI Order Number: ', 'monei' ) . $monei_order_id );
721 $is_paid = $this->is_paid( $order2 );
722 if ( $is_paid ) {
723 return;
724 }
725 $order->payment_complete();
726 if ( 'completed' === $this->orderdo ) {
727 $order->update_status( 'completed', __( 'Order Completed by MONEI', 'monei' ) );
728 }
729
730 $get_token = get_post_meta( $order->get_id(), 'get_token', true );
731
732 if ( 'yes' === $this->debug ) {
733 $this->log->add( 'monei', '$get_token: ' . $get_token );
734 }
735
736 if ( 'yes' === $get_token ) {
737 $monei = new Monei\MoneiClient( $this->apikey );
738 $data_payment = $monei->payments->get( $monei_order_id );
739
740 $data_array = json_decode( $data_payment );
741
742 if ( isset( $data_array->paymentToken ) ) {
743 if ( 'yes' === $this->debug ) {
744 $this->log->add( 'monei', '$token: ' . $data_array->paymentToken );
745 $this->log->add( 'monei', '$brand: ' .$data->paymentMethod->card->brand );
746 $this->log->add( 'monei', '$lastfour: ' . $data->paymentMethod->card->last4 );
747 }
748 $token_n = $data_array->paymentToken;
749 $brand = $data->paymentMethod->card->brand;
750 $lastfour = $data->paymentMethod->card->last4;
751 $token = new WC_Payment_Token_CC();
752 $token->set_token( $token_n );
753 $token->set_gateway_id( 'monei' );
754 $token->set_user_id( $order->get_user_id() );
755 $token->set_card_type( $brand );
756 $token->set_last4( $lastfour );
757 $token->set_expiry_month( '12' );
758 $token->set_expiry_year( '2040' );
759 $token->set_default( true );
760 $token->save();
761 }
762 }
763
764 if ( 'yes' === $this->debug ) {
765 $this->log->add( 'monei', '$data_payment: ' . $data_payment );
766 }
767
768 if ( 'yes' === $this->debug ) {
769 $this->log->add( 'monei', 'Payment complete.' );
770 }
771 } else {
772 // Tarjeta caducada.
773 if ( 'yes' === $this->debug ) {
774 $this->log->add( 'monei', 'Order cancelled by MONEI: ' . $message );
775 }
776 // Order cancelled.
777 $order->update_status( 'cancelled', 'Cancelled by MONEI: ' . $message);
778 $order->add_order_note( 'Order cancelled by MONEI: ' . $message );
779 WC()->cart->empty_cart();
780 }
781 }
782
783 /**
784 * get_monei_order function.
785 *
786 * @access public
787 * @param mixed $order_id
788 * @return void
789 */
790 function get_monei_order( $order_id ) {
791 $order = new WC_Order( $order_id );
792 return $order;
793 }
794
795 function payment_fields() {
796
797 if ( is_user_logged_in() && 'yes' === $this->tokenization ) {
798 $user_id = get_current_user_id();
799 $tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, $this->id );
800 if ( ! empty( $tokens ) ) {
801 echo '<h4>Select a Credit Card</h4>';
802 echo '<div class="credit-cards-monei">';
803 foreach ( $tokens as $token ) {
804 $is_default = $token->is_default();
805 if ( $is_default ) {
806 $checked = 'checked="checked"';
807 } else {
808 $checked = '';
809 }
810 echo '<div class="moneicreditcards">';
811 echo '<input id="' . $token->get_id() . '" name="moneitoken" type="radio" ' . $checked . ' value="' . $token->get_id() . '"/>';
812 echo '<label for="' . $token->get_id() . '">' . $token->get_card_type() . ' ended in ' . $token->get_last4() . ' ' . $token->get_expiry_month() . '/' . $token->get_expiry_year() . '</label>';
813 echo '</div>';
814 continue;
815 }
816 echo '<div class="moneicreditcards">';
817 echo '<input id="yes" name="moneitoken" type="radio" value="yes"/>';
818 echo '<label for="yes">Add new Credit Card</label>';
819 echo '</div>';
820 echo '<div class="moneicreditcards">';
821 echo '<input id="no" name="moneitoken" type="radio" value="no"/>';
822 echo '<label for="no">Do not use any Credit Card</label>';
823 echo '</div>';
824 echo '</div>';
825 } else {
826 echo '<div class="credit-cards-monei">
827 <h4>Do we save your credit card?</h4>
828 <p>We won\'t keep your card, we\'ll keep a token that MONEI will provide. It\'s totally safe.</p>
829 <div class="moneicreditcards">
830 <input id="yes" name="moneitoken" type="radio" value="yes"/>
831 <label for="yes">Yes</label>
832 </div>
833 <div class="moneicreditcards">
834 <input id="no" name="moneitoken" type="radio" value="no"/>
835 <label for="no">No</label>
836 </div>
837 </div>';
838 }
839 } else {
840 echo $this->description;
841 }
842 }
843 /**
844 * Copyright: (C) 2013 - 2021 José Conti
845 */
846 public function doing_scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
847
848 $order_id = $renewal_order->get_id();
849 $order = $renewal_order;
850 $amount = $amount_to_charge;
851 $user_id = $order->get_user_id();
852 $descripcion = $this->product_description( $order );
853
854 $transaction_type = 'sale';
855 $currency = get_woocommerce_currency();
856 $currency = get_woocommerce_currency();
857 $account_id = $this->accountid;
858 $transaction_id = str_pad( $order_id, 12, '0', STR_PAD_LEFT );
859 $transaction_id1 = wp_rand( 1, 999 ); // lets to create a random number.
860 $transaction_id2 = substr_replace( $transaction_id, $transaction_id1, 0, -9 ); // new order number.
861 $shop_name = $this->commercename;
862 $test = $this->test_mode();
863 $url_callback = $this->notify_url;
864 $url_cancel = html_entity_decode( $order->get_cancel_order_url() );
865 $url_complete = utf8_encode( add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ) );
866 $monei_adr = $this->charge_url;
867 $amount = $this->amount_format( $order->get_total() );
868 $apikey = $this->apikey;
869 $customer_emial = $order->billing_email;
870 $token = false;
871 $token_post_id = false;
872
873 $token = $this->get_users_token_bulk( $user_id );
874
875 $body = array(
876 'amount' => $amount,
877 'currency' => $currency,
878 'orderId' => $transaction_id2,
879 'description' => $descripcion,
880 'customer' => array(
881 'email' => $customer_emial,
882 ),
883 'callbackUrl' => $url_callback,
884 'completeUrl' => $url_complete,
885 'cancelUrl' => $url_cancel,
886 'paymentToken' => $token,
887 );
888
889 if ( 'yes' === $this->debug ) {
890 $this->log->add( 'monei', '$body: ' . print_r( json_decode( $body ), true ) );
891 }
892
893 $data_string = json_encode( $body );
894 $options = array(
895 'headers' => array(
896 'Content-Type' => 'application/json',
897 'Authorization' => $apikey,
898 ),
899 'body' => $data_string,
900 );
901 if ( 'yes' === $this->debug ) {
902 $this->log->add( 'monei', print_r( $options, true ) );
903 }
904 $monei_adr = 'https://api.monei.net/v1/payments';
905 $response = wp_remote_post( $monei_adr, $options );
906 $response_code = wp_remote_retrieve_response_code( $response );
907 $response_body = wp_remote_retrieve_body( $response );
908 $result = json_decode( $response_body );
909 $urlchallenge = $result->redirect_url;
910 $refultmonei = $result->result;
911 $status = $result->status;
912 $authorizationCode = $result->authorizationCode;
913 $id = $result->id;
914
915 if ( 'yes' === $this->debug ) {
916 $this->log->add( 'monei', '$response_body: ' . print_r( $response, true ) );
917 $this->log->add( 'monei', 'URL: ' . print_r( $result, true ) );
918 $this->log->add( 'monei', '/*************************/');
919 $this->log->add( 'monei', ' Get URL To redirect ');
920 $this->log->add( 'monei', '/*************************/');
921 $this->log->add( 'monei', '$response_body: ' . $response_body );
922 $this->log->add( 'monei', 'URL: ' . $result->nextAction->redirectUrl );
923 $this->log->add( 'monei', '$status: ' . $status );
924 $this->log->add( 'monei', '$authorizationCode: ' . $authorizationCode );
925 $this->log->add( 'monei', '$id: ' . $id );
926 }
927 }
928 /**
929 * Refund
930 */
931
932 function ask_for_refund( $order_id, $transaction_id, $amount ) {
933
934 //post code to MONEI
935 $order2 = get_post_meta( $order_id, '_payment_wc_order_id_monei', true );
936 $monei_order_number = $transaction_id;
937 $currency_codes = get_woocommerce_currency();
938 $account_id = $this->accountid;
939 $test = $this->test_mode();
940 $transaction_type = 'refund';
941 $shop_name = $this->commercename;
942 $password = $this->password;
943 $country = new WC_Countries();
944 $shop_country = $country->get_base_country();
945 $monei_adr = $this->refund_url;
946
947 $message = 'account_id' . $account_id .
948 'amount' . $amount .
949 'currency' . $currency_codes .
950 'monei_order_id' . $monei_order_number .
951 'order_id' . $order2 .
952 'shop_name' . $shop_name .
953 'test' . $test .
954 'transaction_type' . $transaction_type;
955
956 $sign = hash_hmac('sha256', $message, $password );
957
958 if ( 'yes' === $this->debug ) {
959 $this->log->add( 'monei', ' ' );
960 $this->log->add( 'monei', '$message ' . $message );
961 $this->log->add( 'monei', '$password ' . $password );
962 $this->log->add( 'monei', '$sign: ' . $sign );
963 $this->log->add( 'monei', __( 'Order Number MONEI : ', 'monei' ) . $monei_order_number );
964 }
965
966 if ( 'yes' === $this->debug ) {
967 $this->log->add( 'monei', ' ' );
968 $this->log->add( 'monei', ' ' );
969 $this->log->add( 'monei', '/**************************/' );
970 $this->log->add( 'monei', __( 'Starting asking for Refund', 'monei' ) );
971 $this->log->add( 'monei', '/**************************/' );
972 $this->log->add( 'monei', ' ' );
973 }
974
975 if ( 'yes' === $this->debug ) {
976 $this->log->add( 'monei', ' ' );
977 $this->log->add( 'monei', __( 'All data from meta', 'monei' ) );
978 $this->log->add( 'monei', '**********************' );
979 $this->log->add( 'monei', ' ' );
980 $this->log->add( 'monei', __( 'If something is empty, the data was not saved', 'monei' ) );
981 $this->log->add( 'monei', ' ' );
982 $this->log->add( 'monei', __( 'All data from meta', 'monei' ) );
983 $this->log->add( 'monei', __( 'Order Number MONEI : ', 'monei' ) . $monei_order_number );
984 }
985
986 if ( 'yes' === $this->debug ) {
987 $this->log->add( 'monei', ' ' );
988 $this->log->add( 'monei', __( 'Data sent to MONEI for refund', 'monei' ) );
989 $this->log->add( 'monei', '*********************************' );
990 $this->log->add( 'monei', ' ' );
991 $this->log->add( 'monei', __( 'URL to MONEI : ', 'monei' ) . $monei_adr );
992 $this->log->add( 'monei', __( 'account_id : ', 'monei' ) . $account_id );
993 $this->log->add( 'monei', __( 'amount : ', 'monei' ) . $amount );
994 $this->log->add( 'monei', __( 'currency : ', 'monei' ) . $currency_codes );
995 $this->log->add( 'monei', __( 'order_id : ', 'monei' ) . $order2 );
996 $this->log->add( 'monei', __( 'monei_order_id : ', 'monei' ) . $monei_order_number );
997 $this->log->add( 'monei', __( 'signature : ', 'monei' ) . $sign );
998 $this->log->add( 'monei', __( 'test : ', 'monei' ) . $test );
999 $this->log->add( 'monei', __( 'transaction_type : refund', 'monei' ) );
1000 $this->log->add( 'monei', __( 'ask_for_refund Asking for order #: ', 'monei' ) . $order_id );
1001 $this->log->add( 'monei', ' ' );
1002 }
1003
1004 $body = array(
1005 'account_id' => $account_id,
1006 'amount' => $amount,
1007 'currency' => $currency_codes,
1008 'monei_order_id' => $monei_order_number,
1009 'order_id' => $order2,
1010 'shop_name' => $shop_name,
1011 'signature' => $sign,
1012 'test' => $test,
1013 'transaction_type' => 'refund',
1014 );
1015
1016 $data_string = json_encode( $body );
1017
1018 $options = array(
1019 'headers' => array(
1020 'Content-Type' => 'application/json',
1021 ),
1022 'body' => $data_string,
1023 );
1024
1025 $response = wp_remote_post( $monei_adr, $options );
1026 $response_code = wp_remote_retrieve_response_code( $response );
1027 $response_body = wp_remote_retrieve_body( $response );
1028
1029 if ( is_wp_error( $response ) ) {
1030 $error_string = $response->get_error_message();
1031 if ( 'yes' === $this->debug ) {
1032 $this->log->add( 'monei', ' ' );
1033 $this->log->add( 'monei', __( 'There is an error', 'monei' ) );
1034 $this->log->add( 'monei', '*********************************' );
1035 $this->log->add( 'monei', ' ' );
1036 $this->log->add( 'monei', __( 'The error is : ', 'monei' ) . $error_string );
1037 }
1038 return $error_string;
1039 }
1040
1041 $result = json_decode( $response_body );
1042 $end = $result->result;
1043
1044 if ( 'yes' === $this->debug ) {
1045 $this->log->add( 'monei', ' ' );
1046 $this->log->add( 'monei', '$result: ' . $end );
1047 $this->log->add( 'monei', ' ' );
1048 }
1049
1050 if ( 'completed' === $end ) {
1051 return true;
1052 } else {
1053 return $end;
1054 }
1055 }
1056
1057 public function process_refund( $order_id, $amount = null, $reason = '' ) {
1058
1059 // Do your refund here. Refund $amount for the order with ID $order_id _transaction_id
1060 set_time_limit( 0 );
1061 $order = $this->get_monei_order( $order_id );
1062 $order2 = get_post_meta( $order_id, '_payment_wc_order_id_monei', true );
1063 $monei_order_number = get_post_meta( $order_id, '_payment_order_number_monei', true );
1064
1065
1066 if ( ! $amount ) {
1067 $order_total_sign = $order->get_total();
1068 } else {
1069 $order_total_sign = $amount;
1070 }
1071
1072 if ( ! empty( $order2 ) ) {
1073 if ( 'yes' === $this->debug ) {
1074 $this->log->add( 'monei', ' ' );
1075 $this->log->add( 'monei', '/****************************/' );
1076 $this->log->add( 'monei', ' Once upon a time ' );
1077 $this->log->add( 'monei', '/****************************/' );
1078 $this->log->add( 'monei', ' ' );
1079 $this->log->add( 'monei', __( 'check_monei_refund Asking for order #: ', 'monei' ) . $order_id );
1080 }
1081
1082 $refund_asked = $this->ask_for_refund( $order_id, $monei_order_number, $order_total_sign );
1083
1084 if ( $refund_asked ) {
1085 if ( 'yes' === $this->debug && $result ) {
1086 $this->log->add( 'monei', __( 'check_monei_refund = true ', 'monei' ) );
1087 $this->log->add( 'monei', ' ' );
1088 $this->log->add( 'monei', '/********************************/' );
1089 $this->log->add( 'monei', ' Refund complete by MONEI ' );
1090 $this->log->add( 'monei', '/********************************/' );
1091 $this->log->add( 'monei', ' ' );
1092 $this->log->add( 'monei', '/******************************************/' );
1093 $this->log->add( 'monei', ' The final has come, this story has ended ' );
1094 $this->log->add( 'monei', '/******************************************/' );
1095 $this->log->add( 'monei', ' ' );
1096 }
1097 return true;
1098 } else {
1099 if ( is_wp_error( $refund_asked ) ) {
1100 if ( 'yes' === $this->debug ) {
1101 $this->log->add( 'monei', __( 'Refund Failed: ', 'monei' ) . $refund_asked->get_error_message() );
1102 }
1103 return new WP_Error( 'error', $refund_asked->get_error_message() );
1104 }
1105 }
1106
1107 if ( is_wp_error( $refund_asked ) ) {
1108 if ( 'yes' === $this->debug ) {
1109 $this->log->add( 'monei', __( 'Refund Failed: ', 'monei' ) . $refund_asked->get_error_message() );
1110 }
1111 return new WP_Error( 'error', $refund_asked->get_error_message() );
1112 }
1113 } else {
1114 if ( 'yes' === $this->debug && $result ) {
1115 $this->log->add( 'monei', __( 'Refund Failed: No transaction ID', 'monei' ) );
1116 }
1117 return new WP_Error( 'monei', __( 'Refund Failed: No transaction ID', 'monei' ) );
1118 }
1119 }
1120 }
1121
1122 function monei_add_notice_new_version() {
1123
1124 $version = get_option( 'hide-new-version-monei-notice' );
1125
1126 if ( ! $version ) {
1127 if ( isset( $_REQUEST['monei-hide-new-version'] ) && 'hide-new-version-monei' === $_REQUEST['monei-hide-new-version'] ) {
1128 $nonce = sanitize_text_field( $_REQUEST['_monei_hide_new_version_nonce'] );
1129 if ( wp_verify_nonce( $nonce, 'monei_hide_new_version_nonce' ) ) {
1130 update_option( 'hide-new-version-monei-notice', MONEI_VERSION );
1131 }
1132 } else {
1133 ?>
1134 <div id="message" class="updated woocommerce-message woocommerce-monei-messages">
1135 <div class="contenido-monei-notice">
1136 <a class="woocommerce-message-close notice-dismiss" style="top:0;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'monei-hide-new-version', 'hide-new-version-monei' ), 'monei_hide_new_version_nonce', '_monei_hide_new_version_nonce' ) ); ?>"><?php esc_html_e( 'Dismiss', 'monei' ); ?></a>
1137 <p>
1138 <h3>
1139 <?php esc_html_e( 'Thank you for install MONEI for WooCommerce. Version: ', 'monei' ) . ' ' . esc_html_e( MONEI_VERSION ); ?>
1140 </h3>
1141 </p>
1142 <p>
1143 <?php esc_html_e( 'The best payment gateway rates. The perfect solution to manage your digital payments.,', 'monei' ); ?>
1144 </p>
1145 <p class="submit">
1146 <a href="<?php esc_html_e( MONEI_SIGNUP ); ?>" class="button-primary" target="_blank"><?php esc_html_e( 'Signup', 'monei' ); ?></a>
1147 <a href="<?php esc_html_e( MONEI_WEB ); ?>" class="button-primary" target="_blank"><?php esc_html_e( 'MONEI website', 'monei' ); ?></a>
1148 <a href="<?php esc_html_e( MONEI_REVIEW ); ?>" class="button-primary" target="_blank"><?php esc_html_e( 'Leave a review', 'monei' ); ?></a>
1149 <a href="<?php esc_html_e( MONEI_SUPPORT ); ?>" class="button-primary" target="_blank"><?php esc_html_e( 'Support', 'monei' ); ?></a>
1150 </p>
1151 </div>
1152 </div>
1153 <?php }
1154 }
1155 }
1156 add_action( 'admin_notices', 'monei_add_notice_new_version' );
1157
1158 function monei_notice_style() {
1159 wp_register_style( 'monei_notice_css', MONEI_PLUGIN_URL . 'assets/css/monei-notice.css', false, MONEI_VERSION );
1160 wp_enqueue_style( 'monei_notice_css' );
1161 }
1162 add_action( 'admin_enqueue_scripts', 'monei_notice_style' );
1163
1164 function monei_style_checkout() {
1165 wp_register_style( 'monei_checkput_css', MONEI_PLUGIN_URL . 'assets/css/monei-checkout-card.css', false, MONEI_VERSION );
1166 wp_enqueue_style( 'monei_checkput_css' );
1167 }
1168 //add_action( 'wp_enqueue_scripts', 'monei_style_checkout' );
1169
1170 function woocommerce_add_gateway_monei_gateway( $methods ) {
1171 $methods[] = 'WC_Gateway_monei';
1172 return $methods;
1173 }
1174 add_filter( 'woocommerce_payment_gateways', 'woocommerce_add_gateway_monei_gateway' );
1175
1176 function add_monei_meta_box() {
1177 $date_decoded = get_post_meta( get_the_ID(), '_payment_date_monei', true );
1178 $hour_decoded = get_post_meta( get_the_ID(), '_payment_hour_monei', true );
1179 echo '<h4>' . esc_html__( 'Payment Details', 'monei' ) . '</h4>';
1180 echo '<p><strong>' . esc_html__( 'MONEI Date', 'monei' ) . ': </strong><br />' . esc_html( $date_decoded ) . '</p>';
1181 echo '<p><strong>' . esc_html__( 'MONEI Hour', 'monei' ) . ': </strong><br />' . esc_html( $hour_decoded ) . '</p>';
1182 echo '<p><strong>' . esc_html__( 'MONEI Order Number', 'monei' ) . ': </strong><br />' . esc_attr( get_post_meta( get_the_ID(), '_payment_order_number_monei', true ) ) . '</p>';
1183 }
1184 add_action( 'woocommerce_admin_order_data_after_billing_address', 'add_monei_meta_box' );
1185 }
1186