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

Feature: Add UI for SCA error banner and re-authentication flow #46319

Merged
merged 13 commits into from
Aug 20, 2024

Conversation

waterim
Copy link
Contributor

@waterim waterim commented Jul 26, 2024

Details

Add UI for SCA error banner and re-authentication flow

Fixed Issues

$ #46064
PROPOSAL: N/A

Tests

NOTE: You need to connect to someone local backend to test live mode of the stripe

  1. Navigate to /settings/subscription/add-payment-card
  2. Fill the data with card which requires authentication from here https://docs.stripe.com/testing#regulatory-cards
  3. Select GBP currency
  4. Observe that modal appears correctly
  5. Click Fail
  6. Observe error UI and button for "Authenticate payment"
  7. Click on it and should redirect to "add-payment-card"
  8. Modal should appear
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

None

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2024-08-12.at.23.39.49.mov

@blimpich
Copy link
Contributor

Looked at this locally. I think we should apply these changes so that (A) the authenticate button only shows if the error banner also shows, and (B) so that the error banner will show even if the user is on a free trial and even if there is no amount owed. Lemme know what you think.

diff --git a/src/libs/SubscriptionUtils.ts b/src/libs/SubscriptionUtils.ts
index 0cc4e05f7b..8516d8e082 100644
--- a/src/libs/SubscriptionUtils.ts
+++ b/src/libs/SubscriptionUtils.ts
@@ -175,7 +175,7 @@ function hasAmountOwed(): boolean {
  * @returns Whether there is a card authentication error.
  */
 function hasCardAuthenticatedError() {
-    return stripeCustomerId?.status === 'authentication_required' && amountOwed === 0;
+    return stripeCustomerId?.status === 'authentication_required' && getAmountOwed() === 0;
 }
 
 /**
@@ -460,5 +460,6 @@ export {
     getCardForSubscriptionBilling,
     hasSubscriptionGreenDotInfo,
     hasRetryBillingError,
+    hasCardAuthenticatedError,
     PAYMENT_STATUS,
 };
diff --git a/src/pages/settings/Subscription/CardSection/CardSection.tsx b/src/pages/settings/Subscription/CardSection/CardSection.tsx
index df3c6809e1..a501c61a8b 100644
--- a/src/pages/settings/Subscription/CardSection/CardSection.tsx
+++ b/src/pages/settings/Subscription/CardSection/CardSection.tsx
@@ -32,6 +32,7 @@ import CardSectionDataEmpty from './CardSectionDataEmpty';
 import RequestEarlyCancellationMenuItem from './RequestEarlyCancellationMenuItem';
 import type {BillingStatusResult} from './utils';
 import CardSectionUtils from './utils';
+import { hasCardAuthenticatedError } from '@libs/SubscriptionUtils';
 
 function CardSection() {
     const [isRequestRefundModalVisible, setIsRequestRefundModalVisible] = useState(false);
@@ -85,7 +86,9 @@ function CardSection() {
         BillingBanner = <TrialStartedBillingBanner />;
     } else if (SubscriptionUtils.hasUserFreeTrialEnded()) {
         BillingBanner = <TrialEndedBillingBanner />;
-    } else if (billingStatus) {
+    }
+
+    if (billingStatus) {
         BillingBanner = (
             <SubscriptionBillingBanner
                 title={billingStatus.title}
@@ -144,7 +147,7 @@ function CardSection() {
                         large
                     />
                 )}
-                {billingStatus?.isAuthenticationRequired !== undefined && (
+                {hasCardAuthenticatedError() && (
                     <Button
                         text={translate('subscription.cardSection.authenticatePayment')}
                         isDisabled={isOffline || !billingStatus?.isAuthenticationRequired}

@waterim
Copy link
Contributor Author

waterim commented Jul 29, 2024

@blimpich Looks a bit weird this part: "getAmountOwed() === 0", do we need to check for owed amount for authentication error? Shouldn't it be only like this return stripeCustomerId?.status === 'authentication_required' ?

@blimpich
Copy link
Contributor

@blimpich Looks a bit weird this part: "getAmountOwed() === 0", do we need to check for owed amount for authentication error? Shouldn't it be only like this return stripeCustomerId?.status === 'authentication_required' ?

This confuses me too, and to be completely honest I don't understand why that is the logic, but that is the logic that we have in the Old Dot version of the application too, so we should try to mimic it. I looked into why that code was written that way in the old version of the app, but there wasn't really an explanation in the PR that added it, so 🤷. Lets keep it with the owed amount conditional.

My guess is that if there is an owed amount we have prioritized showing a different error banner instead of the authentication error banner.

@waterim
Copy link
Contributor Author

waterim commented Jul 30, 2024

@blimpich Can you please verify it works or not

@blimpich
Copy link
Contributor

@waterim I will try to get to it today. I was on vacation yesterday so couldn't get to it.

@blimpich
Copy link
Contributor

Error banner looks good but when I click "Authenticate" it just opens up a empty billing card form. It looks like the problem is that we clear the authenticationLink onyx key here, which means we aren't able to reuse it when we try to reauthenticate. The clearing of the authentication link also seems to be how we decide to close the the iframe modal in the first place. That's an issue. We need the modal to close without clearing the authentication link from our onyx data. @waterim can you figure out a way to do that?

Screen.Recording.2024-07-31.at.1.39.46.PM.mov

@waterim
Copy link
Contributor Author

waterim commented Jul 31, 2024

I will try it tomorrow without clearing the link
Do you think it will be fine to store a secure link all the time?
Or maybe maybe I will remove link after success and keep it after fail, okay, should be fine

@blimpich
Copy link
Contributor

If we can clear it on success and keep it on failure then that should be good but I also don't see a problem with keeping it. There's nothing in that link that I'm worried about being exposed on the frontend.

@blimpich
Copy link
Contributor

blimpich commented Aug 1, 2024

Hmmm, so the iframe opens but then closes before rendering. Not sure why that is.

Screen.Recording.2024-08-01.at.2.15.35.PM.mov

@blimpich
Copy link
Contributor

blimpich commented Aug 1, 2024

I can make the modal not auto-close by removing this line but I still just get a blank page instead of the stripe verification screen. Probably something backend I need to adjust here. Looking into it.

@blimpich
Copy link
Contributor

blimpich commented Aug 1, 2024

Ah, I think I've figured it out. Comes down to onyx updates. The old way we did this was we would call User_VerifySetupIntent when we wanted to re-authenticate and that would give us a new authentication link, and we'd use that to make this work. We can't just reuse the old link I don't think. We aren't able to get that new link right now because the backend isn't updating the frontend's onyx data to have the authentication link. I will make a PR for that.

Lets do this:

  • revert the changes where we make the modal close by clearing the authenticationLink
  • instead of having the authenticate payment button navigate to the add payment card screen, lets have it call User_VerifySetupIntent, but with the parameter "isVerifying" set to false. That call should update the authenticationLink onyx data, which should then cause the modal to open up on the frontend.

The changes I'm going to make also mean that we shouldn't need to use makeRequestWithSideEffect here. The backend will update the onyx key and push it to the frontend.

Does that sound good @waterim?

@waterim
Copy link
Contributor Author

waterim commented Aug 1, 2024

Sounds great and makes a lot of sense for me know. thank you!

@waterim waterim marked this pull request as ready for review August 9, 2024 09:54
@waterim waterim requested a review from a team as a code owner August 9, 2024 09:54
@melvin-bot melvin-bot bot requested review from mananjadhav and removed request for a team August 9, 2024 09:54
Copy link

melvin-bot bot commented Aug 9, 2024

@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@mananjadhav
Copy link
Collaborator

I'll start with the review of this code, but I don't see any screenshots/videos for the testing. @waterim Can you please add them?

@waterim
Copy link
Contributor Author

waterim commented Aug 12, 2024

@mananjadhav Its not possible to test it without a local backend and dev env stripe
To get this you will need to ask @blimpich to share it with you

Also I will be able to upload a video with steps only when @blimpich ngrok is online (in 3-4 hours from now)

If its okay for you you are able to go through code for now and when @blimpich will be online we can proceed with testing this flow manually

@waterim
Copy link
Contributor Author

waterim commented Aug 12, 2024

@mananjadhav added video with the flow

Firstly you will need to fail the 3ds secure and after this PRs flow starts from "Authenticate payment"

@@ -81,7 +95,8 @@ function CardSection() {
BillingBanner = <TrialStartedBillingBanner />;
} else if (SubscriptionUtils.hasUserFreeTrialEnded()) {
BillingBanner = <TrialEndedBillingBanner />;
} else if (billingStatus) {
}
if (billingStatus) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this else if --> if intentional?

Are we saying along with Trial/Trial ended banner we would show the authenticate payment button?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I got the change now.

@mananjadhav
Copy link
Collaborator

mananjadhav commented Aug 14, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native android-sca-card
Android: mWeb Chrome
mweb-chrome-sca-error.mov
iOS: Native
iOS: mWeb Safari
mweb-safari-sca-error.mov
MacOS: Chrome / Safari
web-sca-error.mov
MacOS: Desktop
desktop-sca-error.mov

@mananjadhav
Copy link
Collaborator

@blimpich There is no popup shown on payment currency change right.

Steps:

  1. Go to subscription page.
  2. Add a card in USD.
  3. Go to the payment method row and lcik on three dots menu.
  4. Click change payment currency.
  5. Select GBP and enter CVV.
  6. It doesn't show any popup like it does when we add a GBP card.

@blimpich
Copy link
Contributor

There is no popup shown on payment currency change right.

Correct. That is a known issue, choosing not to prioritize right now.

Copy link
Collaborator

@mananjadhav mananjadhav left a comment

Choose a reason for hiding this comment

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

The code changes look good and also works well.

My iOS build is failing but this feature is anyway not available for native app.

Another follow up thing unrelated to the current PR could be, when clicking on Submit instead of Fail, Authenticate payment modal doesn't have a good visible loader. This is I think loaded from iframe. The rest it looks good.

@melvin-bot melvin-bot bot requested a review from blimpich August 14, 2024 19:43
Copy link
Contributor

@blimpich blimpich left a comment

Choose a reason for hiding this comment

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

Looks good and tests well but can we follow up on this comment I made awhile back?

The changes I'm going to make also mean that we shouldn't need to use makeRequestWithSideEffect here. The backend will update the onyx key and push it to the frontend.

It would be good to get rid of the side effect usage where we can, and I think we can here.

@blimpich
Copy link
Contributor

@waterim can you also update this branch with main in addition to changes requested above?

@waterim
Copy link
Contributor Author

waterim commented Aug 19, 2024

@blimpich Sure!
I had days off and today Callstack had half-day upskilling day and now Im working on this ticket!

@waterim
Copy link
Contributor Author

waterim commented Aug 19, 2024

@blimpich updated, can you test please?

@blimpich
Copy link
Contributor

Ugh, I was wrong, I misunderstood one of the backend api endpoints and how it worked. @waterim can you please revert the changes related to getting rid of makeRequestWithSideEffects()? Then lets get this merged. Thank you for working on this and being patient with me!

@waterim
Copy link
Contributor Author

waterim commented Aug 19, 2024

Sure! Will revert it tomorrow morning :)

Copy link
Contributor

@blimpich blimpich left a comment

Choose a reason for hiding this comment

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

Tested it again, works great! Lets merge this!!!

@blimpich blimpich merged commit 82f3ff4 into Expensify:main Aug 20, 2024
15 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/blimpich in version: 9.0.23-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@mvtglobally
Copy link

Are we able to use this test data in Staging? I think Staging might be pointing to PROD Stripe.

image (14)
image (13)

bandicam.2024-08-21.12-20-30-056.mp4

@blimpich
Copy link
Contributor

@mvtglobally yes staging points to prod stripe, sorry I should have written something here before you QA'ed. Please skip QA for this.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/chiragsalian in version: 9.0.23-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

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

Successfully merging this pull request may close these issues.

5 participants