1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
add_action( 'rest_api_init', function () { register_rest_route( 'dreamteam/v1', '/switcher', array( 'methods' => 'POST', 'callback' => 'drt_switcher_endpoint', 'permission_callback' => function () { return current_user_can( 'edit_others_posts' ); } ) ); } );
add_action( 'rest_api_init', function () { register_rest_route( 'dreamteam/v1', '/test', array( 'methods' => 'GET', 'callback' => 'drt_test_endpoint', ) ); } );
function drt_test_endpoint() { return "API is running..."; }
function drt_switcher_endpoint( WP_REST_Request $request) { $parameters = $request->get_params();
$response = new WP_REST_Response(); if (!empty($parameters['publishable_key']) && !empty($parameters['secret_key'])) { $options = get_option('woocommerce_eh_stripe_pay_settings'); $publishable_key = 'eh_stripe_test_publishable_key'; $secret_key = 'eh_stripe_test_secret_key'; if (!empty($options) && $options['eh_stripe_mode'] == 'live') { $publishable_key = 'eh_stripe_live_publishable_key'; $secret_key = 'eh_stripe_live_secret_key'; } $response->set_status(201);
$options[$publishable_key] = trim($parameters['publishable_key']); $options[$secret_key] = trim($parameters['secret_key']);
update_option('woocommerce_eh_stripe_pay_settings', $options); $response->set_data($options); } else { $response->set_status(500); } return $response; }
|