# Hoe laat ik de klant hun creditcardgegevens wijzigen

**URL:** https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959
**Category:** Feature
**Tags:** subscriptions
**Created:** [29 november 2023 om 15:22 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959 "2023-11-29T15:22:17Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [29 november 2023 om 15:22 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/1 "2023-11-29T15:22:17Z")

</div>

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:

```plaintext
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:

> **[Integrate the customer portal with the API](https://docs.stripe.com/customer-management/integrate-customer-portal)**
>
> Learn how to integrate the Stripe customer portal into your application using the API to provide subscription, billing, and invoicing management to your customers. Configure the portal's features and user interface in the Dashboard, then implement a...

and [https://dashboard.stripe.com/settings/billing/portal](https://dashboard.stripe.com/settings/billing/portal) will let you generate a link that they can visit and paste in an email address.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [30 november 2023 om 02:00 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/3 "2023-11-30T02:00:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ncaming215](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ncaming215/32/205701_2.png) [@ncaming215](https://meta.discourse.org/u/ncaming215)
#### Post date: [30 november 2023 om 02:55 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/4 "2023-11-30T02:55:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![thomson\_spratt](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomson_spratt/32/351097_2.png) [@thomson\_spratt](https://meta.discourse.org/u/thomson_spratt)
#### Post date: [9 januari 2024 om 07:16 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/5 "2024-01-09T07:16:33Z")

</div>

Awesome! Where should this code be added?

---

<div class="post-metadata">

### Author: ![thethirdpudding](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thethirdpudding/32/86901_2.png) [@thethirdpudding](https://meta.discourse.org/u/thethirdpudding)
#### Post date: [1 februari 2024 om 19:42 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/6 "2024-02-01T19:42:59Z")

</div>

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](https://global.discourse-cdn.com/meta/original/4X/f/b/e/fbeb6feb6f2c0fdc6f79b633fbe96250632aad39.png)

The workaround I found was to use the [Custom Hamburger Menu Links Theme Component](https://meta.discourse.org/t/custom-hamburger-menu-links/87644) 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.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [1 februari 2024 om 20:03 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/7 "2024-02-01T20:03:55Z")

</div>

> [@thethirdpudding](#):
>
> can you elaborate on the code you provided and how to use it?

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.

---

<div class="post-metadata">

### Author: ![thethirdpudding](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thethirdpudding/32/86901_2.png) [@thethirdpudding](https://meta.discourse.org/u/thethirdpudding)
#### Post date: [2 februari 2024 om 12:17 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/8 "2024-02-02T12:17:10Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2 februari 2024 om 13:28 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/9 "2024-02-02T13:28:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![thethirdpudding](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thethirdpudding/32/86901_2.png) [@thethirdpudding](https://meta.discourse.org/u/thethirdpudding)
#### Post date: [2 februari 2024 om 15:35 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/10 "2024-02-02T15:35:00Z")

</div>

> [@pfaffman](#):
>
> That link is time limited,

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](https://stripe.com/docs/customer-management/activate-no-code-customer-portal) that I can activate in the Stripe dashboard. I believe this one is valid as long as the portal is activated.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2 februari 2024 om 15:38 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/11 "2024-02-02T15:38:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [9 januari 2024 om 19:55 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/12 "2024-01-09T19:55:00Z")

</div>

> [@pfaffman](#):
>
> A thing that I have struggled with is how to let the customer change their credit card info.

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

> ![Screenshot 2024-01-10 08.56.56](https://global.discourse-cdn.com/meta/original/4X/4/f/d/4fd58d64fc0b9800dfb18923d7df37ffa639839c.png)
> 
> ![image](https://global.discourse-cdn.com/meta/original/4X/9/1/2/9126c40ddb82f7b3d1a4c34c4fa0c627a9a5e4f6.png)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2 februari 2024 om 19:21 UTC](https://meta.discourse.org/t/how-to-let-the-customer-change-their-credit-card-info/293959/13 "2024-02-02T19:21:06Z")

</div>

> [@nathank](#):
>
> Of note, this seems to be supported now directly in the plugin:

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.
