PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.4.2
WooCommerce Square v5.4.2
5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Admin / Rest / WC_REST_Square_Cash_App_Settings_Controller.php
woocommerce-square / includes / Admin / Rest Last commit date
WC_REST_Square_Cash_App_Settings_Controller.php 2 years ago WC_REST_Square_Credit_Card_Payment_Settings_Controller.php 2 years ago WC_REST_Square_Gift_Cards_Settings_Controller.php 1 year ago WC_REST_Square_Settings_Controller.php 4 months ago WC_Square_REST_Base_Controller.php 2 years ago
WC_REST_Square_Cash_App_Settings_Controller.php
156 lines
1 <?php
2 /**
3 * Class WC_REST_Square_Cash_App_Settings_Controller file.
4 */
5
6 namespace WooCommerce\Square\Admin\Rest;
7
8 use WP_REST_Server;
9 use WP_REST_Request;
10 use WP_REST_Response;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Class WC_REST_Square_Cash_App_Settings_Controller.
16 *
17 * @since 4.7.0
18 */
19 class WC_REST_Square_Cash_App_Settings_Controller extends WC_Square_REST_Base_Controller {
20
21 /**
22 * Square settings option name.
23 *
24 * @var string
25 */
26 const SQUARE_CASH_APP_SETTINGS_OPTION_NAME = 'woocommerce_square_cash_app_pay_settings';
27
28 /**
29 * Endpoint path.
30 *
31 * @var string
32 */
33 protected $rest_base = 'wc_square/cash_app_settings';
34
35 /**
36 * Allowed parameters.
37 *
38 * @var array
39 */
40 private $allowed_params;
41
42 /**
43 * Constructor.
44 */
45 public function __construct() {
46 $this->allowed_params = array(
47 'enabled',
48 'title',
49 'description',
50 'transaction_type',
51 'button_theme',
52 'charge_virtual_orders',
53 'enable_paid_capture',
54 'button_shape',
55 );
56
57 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
58 }
59
60 /**
61 * Register routes.
62 */
63 public function register_routes() {
64 register_rest_route(
65 $this->namespace,
66 '/' . $this->rest_base,
67 array(
68 'methods' => WP_REST_Server::READABLE,
69 'callback' => array( $this, 'get_settings' ),
70 'permission_callback' => array( $this, 'check_permission' ),
71 )
72 );
73 register_rest_route(
74 $this->namespace,
75 '/' . $this->rest_base,
76 array(
77 'methods' => WP_REST_Server::EDITABLE,
78 'callback' => array( $this, 'save_settings' ),
79 'permission_callback' => array( $this, 'check_permission' ),
80 'args' => array(
81 'enabled' => array(
82 'description' => __( 'Enable Square payment gateway.', 'woocommerce-square' ),
83 'type' => 'string',
84 'sanitize_callback' => '',
85 ),
86 'title' => array(
87 'description' => __( 'Square payment gateway title.', 'woocommerce-square' ),
88 'type' => 'string',
89 'sanitize_callback' => '',
90 ),
91 'description' => array(
92 'description' => __( 'Square payment gateway description.', 'woocommerce-square' ),
93 'type' => 'string',
94 'sanitize_callback' => '',
95 ),
96 'transaction_type' => array(
97 'description' => __( 'The transaction type.', 'woocommerce-square' ),
98 'type' => 'string',
99 'sanitize_callback' => '',
100 ),
101 'charge_virtual_orders' => array(
102 'description' => __( 'If the order contains exclusively virtual items, enable this to immediately charge, rather than authorize, the transaction.', 'woocommerce-square' ),
103 'type' => 'string',
104 'sanitize_callback' => '',
105 ),
106 'enable_paid_capture' => array(
107 'description' => __( 'Automatically capture orders when they are changed to Processing or Completed.', 'woocommerce-square' ),
108 'type' => 'string',
109 'sanitize_callback' => '',
110 ),
111 'button_theme' => array(
112 'description' => __( 'Button Theme.', 'woocommerce-square' ),
113 'type' => 'string',
114 'sanitize_callback' => '',
115 ),
116 'button_shape' => array(
117 'description' => __( 'Button Shape.', 'woocommerce-square' ),
118 'type' => 'string',
119 'sanitize_callback' => '',
120 ),
121 ),
122 )
123 );
124 }
125
126 /**
127 * Get the data.
128 *
129 * @return WP_REST_Response
130 */
131 public function get_settings() {
132 $square_settings = get_option( self::SQUARE_CASH_APP_SETTINGS_OPTION_NAME, array() );
133 $filtered_settings = array_intersect_key( $square_settings, array_flip( $this->allowed_params ) );
134
135 return new WP_REST_Response( $filtered_settings );
136 }
137
138 /**
139 * Update the data.
140 *
141 * @param WP_REST_Request $request Full data about the request.
142 */
143 public function save_settings( WP_REST_Request $request ) {
144 $settings = array();
145
146 foreach ( $this->allowed_params as $index => $key ) {
147 $new_value = wc_clean( wp_unslash( $request->get_param( $key ) ) );
148
149 $settings[ $key ] = $new_value;
150 }
151
152 update_option( self::SQUARE_CASH_APP_SETTINGS_OPTION_NAME, $settings );
153 wp_send_json_success();
154 }
155 }
156