Skip to content

Commit 9d7d2f9

Browse files
committed
link to billing portal
1 parent 5f2707c commit 9d7d2f9

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

app/controllers/organizations/refills_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def add_payment_method
1515
customer_update: { address: :auto, name: :auto },
1616
tax_id_collection: { enabled: true }
1717
)
18-
redirect_to session.url, allow_other_host: true
18+
redirect_to session.url, allow_other_host: true, status: :see_other
1919
end
2020

2121
# POST /credits/charge_payment_method
@@ -39,4 +39,9 @@ def charge_payment_method
3939
end
4040
redirect_to organization_refills_url(current_organization)
4141
end
42+
43+
def billing_portal
44+
session = current_organization.payment_processor.billing_portal(return_url: organization_refills_url(current_organization))
45+
redirect_to session.url, allow_other_host: true, status: :see_other
46+
end
4247
end

app/views/organizations/refills/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<%= render PageComponent.new(title: "Payment details") do |component| %>
1212
<% component.with_action_list do %>
1313
<%= button_to "Add payment method", add_payment_method_organization_refills_path(current_organization), method: :post, class: "btn btn-primary", data: { turbo: "false" } %>
14+
<%= button_to "Manage billing", billing_portal_organization_refills_path(current_organization), method: :post, class: "btn btn-primary", data: { turbo: "false" } %>
1415
<% end %>
1516

1617
<% if @payment_methods.any? %>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
collection do
2020
post :add_payment_method
2121
post :charge_payment_method
22+
post :billing_portal
2223
end
2324
end
2425
end

0 commit comments

Comments
 (0)