Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credit card management updates #14670

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

andesol
Copy link
Contributor

@andesol andesol commented Jan 22, 2025

Done

  • Update "payment methods" page to allow removing the payment method
  • If removed, show warning notification on Pro dashboard and disable renewal and resize features
  • Use singular: "Payment method", as there's only one

QA

  • Open demo or run site locally
  • Go to /account/payment-methods
  • Remove the credit card
    • The card goes away and it shows an empty state type of page
  • Go to /pro/dashboard
    • There's a warning notification stating there's no payment method
    • You can't change renewal settings
    • You can't edit/resize any subscription
  • Compare with design

Issue

https://warthogs.atlassian.net/browse/WD-18327

@webteam-app
Copy link

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 72.40%. Comparing base (a9423d8) to head (eb79b76).
Report is 42 commits behind head on main.

Files with missing lines Patch % Lines
static/js/src/advantage/api/contracts.js 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14670      +/-   ##
==========================================
+ Coverage   72.32%   72.40%   +0.07%     
==========================================
  Files         120      121       +1     
  Lines        3404     3424      +20     
  Branches     1172     1179       +7     
==========================================
+ Hits         2462     2479      +17     
- Misses        917      920       +3     
  Partials       25       25              
Files with missing lines Coverage Δ
...ents/Subscriptions/Notifications/Notifications.tsx 87.87% <100.00%> (+1.67%) ⬆️
...ubscriptions/SubscriptionEdit/SubscriptionEdit.tsx 83.21% <100.00%> (+0.12%) ⬆️
...bscriptionList/RenewalSettings/RenewalSettings.tsx 96.10% <100.00%> (+0.15%) ⬆️
...s/src/advantage/react/hooks/useHasPaymentMethod.ts 100.00% <100.00%> (ø)
.../subscribe/checkout/components/Summary/Summary.tsx 76.92% <ø> (ø)
.../checkout/components/UserInfoForm/UserInfoForm.tsx 68.38% <ø> (ø)
static/js/src/advantage/api/contracts.js 23.58% <0.00%> (+0.05%) ⬆️

@andesol andesol force-pushed the credit-card-mgmt branch 5 times, most recently from cb9ec35 to 4ef9df2 Compare January 30, 2025 16:05
@andesol andesol force-pushed the credit-card-mgmt branch 3 times, most recently from 36dfd12 to d54aff8 Compare February 3, 2025 08:35
@andesol andesol marked this pull request as ready for review February 3, 2025 09:27
@andesol andesol force-pushed the credit-card-mgmt branch 3 times, most recently from 8a3e0e1 to e6672de Compare February 6, 2025 14:55
@andesol andesol requested a review from minkyngkm February 6, 2025 15:22
@minkyngkm
Copy link
Contributor

If no card presented, all auto renewal should be switched off on the dashboard, right?
but it seems it's not switched off
image
image

</div>
<div class="col-8">
<div class="u-align--left col-8 col-medium-4 col-small-3">
<p class="p-heading--4 u-no-margin--bottom">You have no payment method saved</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think margin-bottom should be 0. margin-bottom is -0.45rem !important; because of this class u-no-margin--bottom

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always though it was the same... Done, thanks!

</div>
<div class="col-8"></div>
</div>
<hr class="{% if not default_payment_method.id %}u-hide{% endif %}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the line should always show?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line at the bottom of the card form. I think it should not be there when there's no card?

</div>
<div class="col-4 u-align--right">
<button class="p-button" id="cancel-payment-details">Cancel</button>
<button class="p-button--positive" id="update-payment-details" disabled>Update</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "Save" or "Update"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good 👀 Let's use "Save" that works for both editing and adding.

style="margin-top: 2rem">
<div class="col-8">
<div id="card-element"></div>
<span id="card-errors" class="p-form-validation__message u-hide"></span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this work the same as the check out page? (the red part)
image

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The styles are different across pages. I tried to keep that part as is.

<div class="col-4 u-align--right">
{% if default_payment_method["id"] %}<button class="p-button" id="cancel-payment-details">Cancel</button>{% endif %}
<button class="p-button--positive" id="update-payment-details" disabled>Update</button>
<div id="edit-payment-method-section"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's minor but in design, there seems to be more space between the title "Payment method" and the input area.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I can wrap the h1 in a section to give the layout a bit more vertical space. But having tried that, I think it looks a bit strange, and it's inconsistent with other pages. So I would suggest keeping it as it is.

@@ -36,6 +41,16 @@ const Notifications = () => {

return (
<>
{hasPaymentMethod === false ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the no payment method notification display on top of the other notifications?
for example,
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question for @polgarp

Comment on lines +399 to +402
<p>
We will save your card information. You can change it in your Ubuntu
Pro Dashboard.
</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distributor users don't have access to the Pro dashboard, but this message is also showing in the checkout for them. Should we display this differently for distributor users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @polgarp

@@ -36,6 +41,16 @@ const Notifications = () => {

return (
<>
{hasPaymentMethod === false ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we simply use !hasPaymentMethod && instead of the ternary operator here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using && for conditional rendering is a debated topic in react. I don't have a strong opinion and I use both depending on the situation. This time I went with the ternary because that's what the rest of the file is using.

As for the === false, it's a way to make sure that the notification doesn't show up when hasPayment method is undefined (since it's returned by a hook, it's going to be undefined at first). As an alternative (and maybe more common) I can check for when the query is done, like:

isHasPaymentMethodSuccess && !hasPaymentMethod ? <Notificacion /> : null

Let's try that.

@@ -75,7 +76,7 @@ const generateError = (error: Error | null) => {
return (
<span data-test="has-pending-purchase-error">
You already have a pending purchase. Please go to{" "}
<a href="/account/payment-methods">payment methods</a> to retry.
<a href="/account/payment-methods">payment method</a> to retry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use {urls.account.paymentMethods} instead of /account/payment-methods here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I didn't realise

@minkyngkm
Copy link
Contributor

Looking good @andesol I've just made some comments for what I found 👍

Copy link
Contributor Author

@andesol andesol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @minkyngkm! I addressed some of your comments. As discussed before, we want to keep the autorenewal independent from this change.

Seems like we have something to clarify before this can land, plus a back-end issue. So let's keep it on hold for now.

<div>
{% if not is_in_maintenance %}<a class="p-button--positive" href="/pro/subscribe">Buy new subscription</a>{% endif %}
<a class="p-button" href="/account/invoices">Invoices</a>
<a class="p-button" href="/account/payment-methods">Payment method</a>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only real change. Rest is formatting

@@ -36,6 +41,16 @@ const Notifications = () => {

return (
<>
{hasPaymentMethod === false ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question for @polgarp

Comment on lines +399 to +402
<p>
We will save your card information. You can change it in your Ubuntu
Pro Dashboard.
</p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @polgarp

<div class="col-4 u-align--right">
{% if default_payment_method["id"] %}<button class="p-button" id="cancel-payment-details">Cancel</button>{% endif %}
<button class="p-button--positive" id="update-payment-details" disabled>Update</button>
<div id="edit-payment-method-section"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I can wrap the h1 in a section to give the layout a bit more vertical space. But having tried that, I think it looks a bit strange, and it's inconsistent with other pages. So I would suggest keeping it as it is.

@@ -36,6 +41,16 @@ const Notifications = () => {

return (
<>
{hasPaymentMethod === false ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using && for conditional rendering is a debated topic in react. I don't have a strong opinion and I use both depending on the situation. This time I went with the ternary because that's what the rest of the file is using.

As for the === false, it's a way to make sure that the notification doesn't show up when hasPayment method is undefined (since it's returned by a hook, it's going to be undefined at first). As an alternative (and maybe more common) I can check for when the query is done, like:

isHasPaymentMethodSuccess && !hasPaymentMethod ? <Notificacion /> : null

Let's try that.

style="margin-top: 2rem">
<div class="col-8">
<div id="card-element"></div>
<span id="card-errors" class="p-form-validation__message u-hide"></span>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The styles are different across pages. I tried to keep that part as is.

</div>
<div class="col-4 u-align--right">
<button class="p-button" id="cancel-payment-details">Cancel</button>
<button class="p-button--positive" id="update-payment-details" disabled>Update</button>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good 👀 Let's use "Save" that works for both editing and adding.

</div>
<div class="col-8"></div>
</div>
<hr class="{% if not default_payment_method.id %}u-hide{% endif %}" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line at the bottom of the card form. I think it should not be there when there's no card?

</div>
<div class="col-8">
<div class="u-align--left col-8 col-medium-4 col-small-3">
<p class="p-heading--4 u-no-margin--bottom">You have no payment method saved</p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always though it was the same... Done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants