PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.12.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.12.3
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / square / gateway / class-charitable-square-initialization.php

class-charitable-square-initialization.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.12.3, at includes/square/gateway/class-charitable-square-initialization.php

102 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class responsible for secure Square initialization.
4 *
5 * @package Charitable Square/Classes/Charitable_Square_Initialization
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.7
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Square_Initialization' ) ) :
18
19 /**
20 * Charitable_Square_Initialization
21 *
22 * @since 1.8.7
23 */
24 class Charitable_Square_Initialization {
25
26 /**
27 * Single instance of this class.
28 *
29 * @since 1.8.7
30 *
31 * @var Charitable_Square_Initialization
32 */
33 private static $instance = null;
34
35 /**
36 * Create class object. Private constructor.
37 *
38 * @since 1.8.7
39 */
40 private function __construct() {
41 }
42
43 /**
44 * Create and return the class object.
45 *
46 * @since 1.8.7
47 *
48 * @return Charitable_Square_Initialization
49 */
50 public static function get_instance() {
51 if ( is_null( self::$instance ) ) {
52 self::$instance = new self();
53 }
54
55 return self::$instance;
56 }
57
58 /**
59 * Initialize Square securely.
60 * Deprecated even though called?
61 *
62 * @since 1.8.7
63 *
64 * @return void
65 */
66 public function initialize_square() {
67 // Verify nonce.
68 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'charitable_square_initialize' ) ) {
69 wp_send_json_error( array( 'message' => __( 'Invalid security token.', 'charitable' ) ) );
70 }
71
72 // Get current mode.
73 $test_mode = charitable_get_option( 'test_mode' );
74 $mode = $test_mode ? 'test' : 'live';
75
76 // Get Square gateway instance.
77 $gateway = Charitable_Gateway_Square::get_instance();
78
79 // Get initialization data.
80 $data = array(
81 'location' => $gateway->get_square_location_id( $mode ),
82 'enable_google_pay' => false,
83 'enable_apple_pay' => false,
84 'wallet_not_supported' => __( 'Recurring payments can\'t be processed using Google Pay or Apple Pay. Please enter your card details.', 'charitable' ),
85 );
86
87 // Log initialization attempt.
88 if ( charitable_is_debug( 'square' ) ) {
89 // phpcs:disable
90 error_log( sprintf(
91 '[Charitable Square] Initializing Square in %s mode',
92 $mode
93 ) );
94 // phpcs:enable
95 }
96
97 wp_send_json_success( $data );
98 }
99 }
100
101 endif;
102