Skip to content

Commit

Permalink
Billing page fix. Closes #92
Browse files Browse the repository at this point in the history
  • Loading branch information
ghenry committed Oct 28, 2023
1 parent c7a4b72 commit 6bb1a86
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ config :stripity_stripe,
signing_secret: System.get_env("SENTRYPEER_STRIPE_WEBHOOK_SIGNING_SECRET"),
json_library: Jason

# api_version: "2020-08-27" Set if needed

# Oban - https://hexdocs.pm/oban/Oban.html
config :sentrypeer, Oban,
repo: Sentrypeer.Repo,
Expand Down
3 changes: 3 additions & 0 deletions lib/sentrypeer/billing_subscriptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ defmodule Sentrypeer.BillingSubscriptions do
end

def get_subscription_from_stripe(cust_id) do
Logger.debug("Customer ID: #{inspect(cust_id)}")

stripe_id = get_stripe_id(cust_id)
Logger.debug("Stripe ID: #{inspect(stripe_id)}")

case Stripe.Subscription.list(%{customer: stripe_id}) do
{:ok, subscription} ->
Expand Down
12 changes: 8 additions & 4 deletions lib/sentrypeer_web/live/customer_billing_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,28 @@ defmodule SentrypeerWeb.CustomerBillingLive.Index do
def mount(_params, session, socket) do
Logger.debug(inspect(session["current_user"].id))

subscription = get_subscription(session["current_user"])

{:ok,
assign(socket,
current_user: session["current_user"],
app_version: Application.spec(:sentrypeer, :vsn),
git_rev: Application.get_env(:sentrypeer, :git_rev),
page_title: "Billing" <> " · SentryPeer",
meta_description: "SentryPeer Billing tools",
subscription:
List.first(
BillingSubscriptions.get_subscription_from_stripe(session["current_user"].id).data
),
subscription: subscription,
subscription_item: List.first(subscription.items.data),
billing_email: BillingSubscriptions.get_billing_email(session["current_user"].id),
invoices: BillingSubscriptions.get_invoices(session["current_user"].id),
upcoming_invoice: BillingSubscriptions.get_upcoming_invoice(session["current_user"].id),
payment_methods: BillingSubscriptions.get_payment_methods(session["current_user"].id)
)}
end

defp get_subscription(current_user) do
List.first(BillingSubscriptions.get_subscription_from_stripe(current_user.id).data)
end

@impl true
def handle_event("manage_billing", _value, socket) do
case Session.create(%{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
Plan
</dt>
<dd class="mt-1 flex text-sm leading-6 text-gray-700 dark:text-white sm:col-span-2 sm:mt-0">
<span class="flex-grow"><%= @subscription.plan.nickname %></span>
<span class="flex-grow"><%= @subscription_item.plan.nickname %></span>
<span class="ml-4 flex-shrink-0">
<.link
phx-click="manage_billing"
Expand Down

0 comments on commit 6bb1a86

Please sign in to comment.