Skip to content

[Payment card / Subscription] make backend return relevant onyxData when changing currency for billing card #45124

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

Closed
1 of 6 tasks
MitchExpensify opened this issue Jul 9, 2024 · 16 comments
Assignees
Labels
Daily KSv2 Engineering Internal Requires API changes or must be handled by Expensify staff Reviewing Has a PR in review

Comments

@MitchExpensify
Copy link
Contributor

MitchExpensify commented Jul 9, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v9.0.5-10
Reproducible in staging?: Staging
Reproducible in production?:
If this was caught during regression testing, add the test name, ID and link from TestRail: NA
Email or phone of affected tester (no customers):
Logs: NA
Expensify/Expensify Issue URL: NA
Issue reported by: [email protected]
Slack conversation: Internal: https://expensify.slack.com/archives/C036QM0SLJK/p1720560965872139?thread_ts=1720544914.651789&cid=C036QM0SLJK

Action Performed:

  1. Open new.expensify.com/settings/subscription
  2. Add a payment card
  3. Click the 3 dot menu
  4. Click "Change payment currency"
  5. Choose a different currency to the one already saved
  6. Enter the card on file's CVV number
  7. Hit Save

Expected Result:

You should see you payment currency update to the choice made at step 5

Actual Result:

The updated payment currency does not show without hard refresh and a small lag

Workaround:

Wait

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Currency.not.updating.mov

View all open jobs on GitHub

@MitchExpensify MitchExpensify added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 9, 2024
Copy link

melvin-bot bot commented Jul 9, 2024

Triggered auto assignment to @puneetlath (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@MitchExpensify
Copy link
Contributor Author

Do you think this will solve the delay here @blimpich ? #44904

@MitchExpensify MitchExpensify changed the title Change payment currency: Not able to update payment currency Change payment currency: Update payment currency is slow to update Jul 9, 2024
@dominictb
Copy link
Contributor

dominictb commented Jul 10, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

  • The updated payment currency does not show without hard refresh and a small lag

What is the root cause of that problem?

  • After clicking on Save button, we close the form:
    const changeBillingCurrency = useCallback((currency?: ValueOf<typeof CONST.PAYMENT_CARD_CURRENCY>, values?: FormOnyxValues<typeof ONYXKEYS.FORMS.CHANGE_BILLING_CURRENCY_FORM>) => {
    if (values?.securityCode) {
    PaymentMethods.updateBillingCurrency(currency ?? CONST.PAYMENT_CARD_CURRENCY.USD, values.securityCode);
    }
    Navigation.goBack();
    }, []);
  • Then, we need to wait until the API is called successfully. Then, the updated currency is displayed.

What changes do you think we should make in order to solve the problem?

  • When modifying the billing currency, the CVV code must be validated on the backend. The solution is to keep the form displayed with a loading indicator after clicking the Save button. If the API call succeeds, the form closes; otherwise, errors are displayed.

  • The same solution with this proposal.

  • First, we need to update:

    if (values?.securityCode) {
    PaymentMethods.updateBillingCurrency(currency ?? CONST.PAYMENT_CARD_CURRENCY.USD, values.securityCode);
    }
    Navigation.goBack();

    to:

        if (values?.securityCode) {
            PaymentMethods.updateBillingCurrency(currency ?? CONST.PAYMENT_CARD_CURRENCY.USD, values.securityCode);
            return;
        }
        Navigation.goBack();
  • Then, add the logic:
    const [formData] = useOnyx(ONYXKEYS.FORMS.CHANGE_BILLING_CURRENCY_FORM);
    const formDataComplete = formData?.isLoading === false && !formData.errors;
    const prevFormDataComplete = usePrevious(formDataComplete);

    useEffect(() => {
        if (isSecurityCodeRequired && formDataComplete && !prevFormDataComplete) {
            Navigation.goBack();
        }
    }, [formDataComplete, prevFormDataComplete, isSecurityCodeRequired]);

to the PaymentCardChangeCurrencyForm.

  • Note: The onyx data returned by BE has key billingCurrencyForm, but now in FE it is changeBillingCurrencyForm. We should fix it.

What alternative solutions did you explore? (Optional)

@dominictb
Copy link
Contributor

Proposal updated

1 similar comment
@dominictb
Copy link
Contributor

Proposal updated

@trjExpensify trjExpensify changed the title Change payment currency: Update payment currency is slow to update [Payment card / Subscription] Change payment currency: Update payment currency is slow to update Jul 10, 2024
@trjExpensify trjExpensify moved this from Release 2: Summer 2024 (Aug) to Polish in [#whatsnext] #wave-collect Jul 10, 2024
@trjExpensify
Copy link
Contributor

For sure let's handle this in the same way as #44904 when aligned.

@blimpich
Copy link
Contributor

Do you think this will solve the delay here @blimpich ? #44904

It won't fix it but it'll be fixed in the same way, so we might as well handle them in 1 PR. See this comment.

@blimpich blimpich added Internal Requires API changes or must be handled by Expensify staff Hot Pick Ready for an engineer to pick up and run with Engineering and removed Bug Something is broken. Auto assigns a BugZero manager. labels Jul 12, 2024
@blimpich blimpich changed the title [Payment card / Subscription] Change payment currency: Update payment currency is slow to update [Payment card / Subscription] make backend return relevant onyxData when changing currency for billing card Jul 12, 2024
@blimpich blimpich moved this from Polish to HOT PICKS in [#whatsnext] #wave-collect Jul 12, 2024
@blimpich
Copy link
Contributor

blimpich commented Jul 12, 2024

Okay so looks like this is a backend bug. I briefly looked into this and its one of those problems that looks fairly straightforward at first but is more complicated than it seems.

When we call UpdateBillingCardCurrency we aren't passing back any onyx data to the frontend, so the currency doesn't update unless the client does a full refresh, which then triggers a OpenSubscriptionPage call which gets the updated fund. So naturally we could just add the onyx data to the auth command SetFundCurrency, which is the Auth command that is triggered here, but its really just using CreateFund under the hood. So fixing this "correctly" means moving Onyx updates from UserApi::addPaymentCard in Web to CreateFund.cpp, and then making sure that both adding a new payment card and changing the currency correctly update the onyx data and return it. Not insane stuff, but slightly more complicated than you would expect.

Marking this as an internal hotpick so that someone can pick up soon.

@dominictb
Copy link
Contributor

@blimpich Beside of the BE bug, this issue still need to implement solution to fix the original issue: The updated payment currency does not show without hard refresh and a small lag.

@melvin-bot melvin-bot bot added the Overdue label Jul 15, 2024
@blimpich
Copy link
Contributor

I think yes we will still need some frontend work, but lets come back to that once an Expensify engineer has fixed the backend bug. We'll handle this separately since this we have to wait for an Expensify engineer to have time to fix this.

@melvin-bot melvin-bot bot removed the Overdue label Jul 15, 2024
@dominictb
Copy link
Contributor

@blimpich Can you re-assign me to this issue for easier to self keep track? Then I will create a PR to fix once the BE is fixed. Thanks

@blimpich blimpich assigned dominictb and blimpich and unassigned dominictb Jul 17, 2024
@blimpich
Copy link
Contributor

@blimpich Can you re-assign me to this issue for easier to self keep track? Then I will create a PR to fix once the BE is fixed. Thanks

Well actually this doesn't make sense really. This issue is now a backend issue. I'll create a separate frontend issue for making it wait for the request to finish.

@blimpich blimpich removed the Hot Pick Ready for an engineer to pick up and run with label Jul 17, 2024
@blimpich
Copy link
Contributor

Got an auth PR up to fix this. Will also need to get a web PR out to clean up onyx updates that are no longer needed in web. In review.

@blimpich blimpich added the Reviewing Has a PR in review label Jul 17, 2024
@blimpich blimpich moved this from HOT PICKS to Release 2: Summer 2024 (Aug) in [#whatsnext] #wave-collect Jul 18, 2024
Copy link

melvin-bot bot commented Jul 25, 2024

@blimpich Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

Copy link

melvin-bot bot commented Jul 29, 2024

@blimpich Still overdue 6 days?! Let's take care of this!

@blimpich
Copy link
Contributor

Looks like web and auth PRs have been deployed. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Daily KSv2 Engineering Internal Requires API changes or must be handled by Expensify staff Reviewing Has a PR in review
Projects
No open projects
Archived in project
Development

No branches or pull requests

5 participants