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 49 50 51 52 53 54 55 56 57 58
<?php
defined( 'ABSPATH' ) || exit();
class WC_Braintree_Controller_Payment_Tokens extends WC_Braintree_Rest_Controller {
protected $namespace = 'payment-tokens/';
public function register_routes() {
register_rest_route(
$this->rest_uri(),
'(?P<token_id>[\d]+)',
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete' ),
'permission_callback' => array( $this, 'check_user_permissions' ),
'args' => array(
'token_id' => array(
'required' => true,
'type' => 'number',
),
),
)
);
}
public function check_user_permissions( $request ) {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return new WP_Error(
'permission-error',
__( 'You do not have permissions to access this resource.', 'woo-payment-gateway' ),
array(
'status' => 403,
)
);
}
return true;
}
public function delete( $request ) {
$token_id = $request->get_param( 'token_id' );
WC()->payment_gateways();
WC_Payment_Tokens::delete( $token_id );
return rest_ensure_response( array( 'success' => true ) );
}
}