How to let the customer change their credit card info

A thing that I have struggled with is how to let the customer change their credit card info. The most recent time this came up I ended up canceling their subscription and asked them to make a new one. At long last, I’ve found out how to generate a link to a Stripe page that will let them see their invoice history, add a payment method, and update their billing information (email address).

I’d like to submit a PR to the subscriptions plugin to add this link, but I don’t have the couple of hours that it would take me at this instant, so here’s how to do it by hand in rails:

user = User.find_by_username('=USERNAME=');
sub=DiscourseSubscriptions::Customer.where(user_id: user.id).first;

Stripe.api_key = SiteSetting.discourse_subscriptions_secret_key
session=Stripe::BillingPortal::Session.create({
  customer: sub.customer_id,
  return_url: '=SITE_URL=/my/billing/subscriptions',
});
puts session.url

Here’s the documentionation:

and Stripe Login | Sign in to the Stripe Dashboard will let you generate a link that they can visit and paste in an email address.

9 Likes

I didn’t realize this functionality was missing from Discourse Subscriptions, but this is a must-have feature.

2 Likes

Yeah, I didn’t realize this either. These feels urgent.

1 Like

Awesome! Where should this code be added?

1 Like

Hi, can you elaborate on the code you provided and how to use it?

I also need my users to be able to access this Stripe portal because I legally have to provide them an invoice which is not sent when a subscription is created via the API:

image

The workaround I found was to use the Custom Hamburger Menu Links Theme Component and add a link to the Stripe portal. It works, but it’s not great for the users which have to connect to it via an email link.

1 Like

You would need to put it in a plugin that generated the link and added it to the serializer and then put that link somewhere in the UX. It’s not something that I’ve found time for. That will work from the rails console, but that doesn’t do you much good.

It does appear that the code still works.

The easy thing to do would be to fork the plugin and add the code. The harder, but much better thing to do woud be to add the code and tests such that it would be accepted as a PR. If you have a budget, you can post in marketplace or contact me directly. A middle ground would be to create a plugin that, say, adds the link to the serializer so that you could then put it in the UX somewhere, like the hamburger menu as you’re doing now.

2 Likes

Thanks for your reply and explanation. Unfortunately I don’t have any experience with plugins development and I can only do some light html/css modifications, maybe a few commands in the rails console if need be.

I think I’ll stick with my workaround for now. I will also add the link to the Stripe Portal wherever possible when the user subscribes (Admin > Customize > Text).

2 Likes

That link is time limited, so I think the way to do it would be to add a route that does a redirect. That would save the commission) complication of knowing when to get a new link and keto from making a bunch of unnecessary calls to get a link they will never be clicked.

It’s still a plugin, but I think it would be a much simpler pr.

1 Like

Ah, I think we’re not talking about the same link… You are probably talking about the link generated from the code you provided. I’m talking about the no-code customer portal link that I can activate in the Stripe dashboard. I believe this one is valid as long as the portal is activated.

Yeah. If I remember correctly, my code just keeps them from entering their email address and getting the link for themselves via email (and knowing what email address they used). If that’s Good Enough, then you’re all set.

Of note, this seems to be supported now directly in the plugin:

Screenshot 2024-01-10 08.56.56

image

2 Likes

Indeed! And this is a big help (and is a big part of why I haven’t done anything about the magic link). It doesn’t solve the problem of gaining access to your payment history and links to invoices, though.

2 Likes