UX: Surface stripe AuthenticationError on the Admin Dashboard
This commit is contained in:
parent
331c8630c3
commit
b1f303a1c8
|
@ -4,6 +4,8 @@ module DiscourseSubscriptions
|
|||
module Stripe
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
AUTH_PROBLEM_IDENTIFIER = "#{DiscourseSubscriptions::PLUGIN_NAME}.stripe_auth_error"
|
||||
|
||||
def set_api_key
|
||||
::Stripe.api_key = SiteSetting.discourse_subscriptions_secret_key
|
||||
end
|
||||
|
|
|
@ -17,6 +17,7 @@ module DiscourseSubscriptions
|
|||
product_ids = product_ids.include?(campaign_product) ? [campaign_product] : []
|
||||
end
|
||||
|
||||
begin
|
||||
amount = 0.00
|
||||
subscriptions = get_subscription_data
|
||||
subscriptions = filter_to_subscriptions_products(subscriptions, product_ids)
|
||||
|
@ -37,6 +38,18 @@ module DiscourseSubscriptions
|
|||
SiteSetting.discourse_subscriptions_campaign_amount_raised = amount.round(2)
|
||||
|
||||
check_goal_status
|
||||
rescue ::Stripe::AuthenticationError
|
||||
message =
|
||||
I18n.t(
|
||||
"discourse_subscriptions.auth.invalid",
|
||||
settingsUrl: "admin/site_settings/category/discourse_subscriptions",
|
||||
)
|
||||
AdminDashboardData.add_found_scheduled_check_problem(
|
||||
AdminDashboardData::Problem.new(message, identifier: AUTH_PROBLEM_IDENTIFIER),
|
||||
)
|
||||
else
|
||||
AdminDashboardData.clear_found_problem(AUTH_PROBLEM_IDENTIFIER)
|
||||
end
|
||||
end
|
||||
|
||||
def create_campaign
|
||||
|
|
|
@ -4,3 +4,5 @@ en:
|
|||
card:
|
||||
declined: Card Declined
|
||||
invalid: Card Invalid
|
||||
auth:
|
||||
invalid: Invalid Credentials for Stripe. Please check your <a href="%{settingsUrl}" target="_blank">discourse-subscriptions settings</a>.
|
||||
|
|
|
@ -27,6 +27,10 @@ extend_content_security_policy(script_src: %w[https://js.stripe.com/v3/ https://
|
|||
|
||||
add_admin_route "discourse_subscriptions.admin_navigation", "discourse-subscriptions.products"
|
||||
|
||||
module ::DiscourseSubscriptions
|
||||
PLUGIN_NAME = "discourse-subscriptions"
|
||||
end
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
get "/admin/plugins/discourse-subscriptions" => "admin/plugins#index",
|
||||
:constraints => AdminConstraint.new
|
||||
|
|
|
@ -150,6 +150,31 @@ describe DiscourseSubscriptions::Campaign do
|
|||
expect(SiteSetting.discourse_subscriptions_campaign_amount_raised).to eq 8.33
|
||||
end
|
||||
end
|
||||
|
||||
context "with ::Stripe::AuthenticationError" do
|
||||
it "adds a problem to the admin dashboard" do
|
||||
::Stripe::Subscription.expects(:list).raises(::Stripe::AuthenticationError)
|
||||
|
||||
DiscourseSubscriptions::Campaign.new.refresh_data
|
||||
|
||||
expect(AdminDashboardData.load_found_scheduled_check_problems.count).to eq(1)
|
||||
end
|
||||
|
||||
it "clears the problem when no errors" do
|
||||
::Stripe::Subscription.expects(:list).returns(data: [subscription], has_more: false)
|
||||
::Stripe::Invoice.expects(:list).returns(data: [invoice, invoice2], has_more: false)
|
||||
AdminDashboardData.add_found_scheduled_check_problem(
|
||||
AdminDashboardData::Problem.new(
|
||||
"x",
|
||||
identifier: DiscourseSubscriptions::Stripe::AUTH_PROBLEM_IDENTIFIER,
|
||||
),
|
||||
)
|
||||
|
||||
DiscourseSubscriptions::Campaign.new.refresh_data
|
||||
|
||||
expect(AdminDashboardData.load_found_scheduled_check_problems.count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue