function get_plans(WP_REST_Request $data)
{
$this->set_api_key();
$data = $data->get_params();
try {
$args = array('limit' => 10);
if (isset($data['starting_after'])) {
$args['starting_after'] = $data['starting_after'];
$plans = \Stripe\Plan::all($args);
} elseif (!isset($data['starting_after']) && !isset($data['id'])) {
$plans = \Stripe\Plan::all(array('limit' => 10));
} elseif (isset($data['id'])) {
$plans = \Stripe\Plan::retrieve($data['id']);
}
return new WP_REST_Response($plans, 200);
} catch (Stripe_AuthenticationError $e) {
$body = $e->getJsonBody();
$err = $body['error'];
return new WP_Error($err['type'], __($err['message']), array('status' => 403));
} catch (Stripe_Error $e) {
$body = $e->getJsonBody();
$err = $body['error'];
return new WP_Error($err['type'], __($err['message']), array('status' => 403));
} catch (\Stripe\Error\Base $e) {
$body = $e->getJsonBody();
$err = $body['error'];
return new WP_Error($err['type'], __($err['message']), array('status' => 403));
}
}