PluginProbe
PayPlug for WooCommerce (Official) / 1.2.3
PayPlug for WooCommerce (Official) v1.2.3
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / src / PayplugWoocommerceRequest.php

PayplugWoocommerceRequest.php in PayPlug for WooCommerce (Official) 1.2.3, at src/PayplugWoocommerceRequest.php

73 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce;
4
5 // Exit if accessed directly
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 /**
11 * Class PayplugWoocommerceRequest
12 * @package Payplug\PayplugWoocommerce
13 */
14 class PayplugWoocommerceRequest {
15
16 /**
17 * Gateway settings.
18 *
19 * @var array
20 */
21 protected $settings;
22
23 /**
24 * PayplugWoocommerceRequest constructor.
25 */
26 public function __construct() {
27 $this->settings = get_option( 'woocommerce_payplug_settings', [] );
28 if ( empty( $this->settings ) || ! isset( $this->settings['enabled'] ) || 'yes' !== $this->settings['enabled'] ) {
29 return;
30 }
31
32 // Don't load for change payment method page.
33 if ( isset( $_GET['change_payment_method'] ) ) {
34 return;
35 }
36
37 add_action( 'template_redirect', [ $this, 'set_session' ] );
38 add_action( 'wc_ajax_payplug_create_order', [ $this, 'ajax_create_order' ] );
39 }
40
41 /**
42 * Sets the WC customer session if one is not set.
43 * This is needed so nonces can be verified by AJAX Request.
44 */
45 public function set_session() {
46 if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
47 return;
48 }
49
50 $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
51 $wc_session = new $session_class();
52
53 if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
54 $wc_session->init();
55 }
56
57 $wc_session->set_customer_session_cookie( true );
58 }
59
60 public function ajax_create_order() {
61 if ( WC()->cart->is_empty() ) {
62 wp_send_json_error( __( 'Empty cart', 'payplug' ) );
63 }
64
65 if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
66 define( 'WOOCOMMERCE_CHECKOUT', true );
67 }
68
69 WC()->checkout()->process_checkout();
70
71 die( 0 );
72 }
73 }