discourse-subscriptions/app/controllers/user/subscriptions_controller.rb

42 lines
1008 B
Ruby
Raw Normal View History

2019-10-31 22:43:09 -04:00
# frozen_string_literal: true
module DiscoursePatrons
module User
class SubscriptionsController < ::ApplicationController
include DiscoursePatrons::Stripe
before_action :set_api_key
requires_login
def index
begin
customers = ::Stripe::Customer.list(
email: current_user.email,
expand: ['data.subscriptions']
)
# TODO: Serialize and remove stuff
subscriptions = customers[:data].map do |customer|
customer[:subscriptions][:data]
end.flatten(1)
render_json_dump subscriptions
rescue ::Stripe::InvalidRequestError => e
return render_json_error e.message
end
end
2019-11-04 00:37:21 -05:00
def destroy
begin
subscription = ::Stripe::Subscription.delete(params[:id])
render_json_dump subscription
rescue ::Stripe::InvalidRequestError => e
return render_json_error e.message
end
end
2019-10-31 22:43:09 -04:00
end
end
end