mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-06 17:49:24 +00:00
* REFACTOR: Use api to add subscribe link * FIX: I18n subscribe link * REFACTOR: Use models to store some data This enables the plugin to show only subscription information which was generated on Discourse. Subscription data storage is limited to the external identifiers Stripe generates so we can interact with the API. * DEV: Test/linting fixes/rake task
36 lines
774 B
Ruby
36 lines
774 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseSubscriptions
|
|
class InvoicesController < ::ApplicationController
|
|
include DiscourseSubscriptions::Stripe
|
|
before_action :set_api_key
|
|
requires_login
|
|
|
|
def index
|
|
begin
|
|
customer = find_customer
|
|
|
|
if viewing_own_invoices && customer.present?
|
|
invoices = ::Stripe::Invoice.list(customer: customer.customer_id)
|
|
|
|
render_json_dump invoices.data
|
|
else
|
|
render_json_dump []
|
|
end
|
|
rescue ::Stripe::InvalidRequestError => e
|
|
render_json_error e.message
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def viewing_own_invoices
|
|
current_user.id == params[:user_id].to_i
|
|
end
|
|
|
|
def find_customer
|
|
Customer.find_user(current_user)
|
|
end
|
|
end
|
|
end
|