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

Removes unused spec related to legacy checkout #12417

Merged
merged 5 commits into from May 13, 2024

Conversation

filipefurtad0
Copy link
Contributor

@filipefurtad0 filipefurtad0 commented Apr 28, 2024

Closes #12439.

Removes a legacy spec (./spec/requests/checkout/failed_checkout_spec.rb) and updates an existing spec (./spec/controllers/checkout_controller_spec.rb).

What? Why?

Contributes to #10958 (first bullet point)

From previous specs, attempting to checkout with a payment with source = nil, related a payment on legacy checkout, with a Stripe SCA payment method, triggered a error 400, preventing checkout completion.

This seems not to be the case on the current checkout.

The legacy spec has been removed and the existing controller spec updated to reflect this.

What should we test?

  • green build.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@filipefurtad0 filipefurtad0 added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Apr 28, 2024
@filipefurtad0 filipefurtad0 self-assigned this Apr 28, 2024
Comment on lines -63 to -74
it "clears shipments and payments before rendering the checkout" do
put update_checkout_path, params:, as: :json

# Checking out a bogus Stripe Gateway without a source fails at :payment
# Shipments and payments should then be cleared before rendering checkout
expect(response.status).to be 400
expect(flash[:error])
.to eq 'Payment could not be processed, please check the details you entered'
order.reload
expect(order.shipments.count).to be 0
expect(order.payments.count).to be 0
expect(order.adjustment_total).to eq 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to cover this scenario for the new checkout ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to cover this scenario for the new checkout ?

Thanks, indeed this is the question I wanted to raise. I don't know if we reach this state on the current checkout - a (Stripe) payment entity without a source. If we do, then I think we should expect a status 400, and not 302. If we don't, then I guess there is no point having this new test.

For #10958 I'm trying to find a correspondence between old and new specs. I might run into such situations more often.

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've added a commit to undo changes and remove the added test, as it is perhaps not particularly useful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, indeed this is the question I wanted to raise. I don't know if we reach this state on the current checkout - a (Stripe) payment entity without a source. If we do, then I think we should expect a status 400, and not 302. If we don't, then I guess there is no point having this new test.

I don't know enough about payment and source to know if it's plausible scenario, happy to have a look if needed. I am wondering if the new checkout does not return a 400 in this scenario but display an error to the user instead.

Copy link
Member

Choose a reason for hiding this comment

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

It sounds like we should try to replicate it with a feature spec. If not replicable, then I guess we can move on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's tough to replicate Stripe errors on feature specs - we'd need a proxy to intercept HTTP requests to the real Stripe... I've tried this with puffing billy but did not succeed.

This error just came in on bugsnag, it looks somewhat related (touches the checkout controller and the payment source). So maybe this scenario is relevant after all. I'll have a more thorough look tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

Good pickup on the error!

I noticed that some data was blank in the request. Perhaps (hopefully) the credit card details were scrubbed before logging, but I wonder about gateway_payment_profile_id.

{
  "_method": "put",
...
  "order": {
    "payments_attributes": [
      {
        "source_attributes": {
...
          "month": "",
          "year": "",
          "cc_type": "",
          "last_digits": "",
          "gateway_payment_profile_id": ""
        },
        "payment_method_id": "201053"
      }
    ]
  },
  "commit": "Next - Order summary"
}

It gets set a few different ways in the codebase, but perhaps it's getting lost somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. The request points to "payment_method_id": "201053" which - by looking at the production DB using Metabase - leads to a Spree::PaymentMethod::Check payment method. It seems we're getting this error across production servers (an error 500 on checkout 👀 ). Below, also on FR-prod:

image

One our codebase, we have the line:
# nil means the payment method doesn't require a source e.g. check

I wonder if this happens due to a sort of race condition in which initially a Stripe payment method is selected for checkout but, during this time, disabled but the admin... or so. Since it relates to checkout, I think it might deserve an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've tried to reproduce the bugsnag error with a spec:

  • with a cash payment method, we can trigger the error message, but somehow we get a status 200 (I was expecting 500')
  • with Stripe payment method, we can see the data is incomplete, and just get the expected 422, with no error message

I'm not sure how to proceed on this one; do we expect payment_source_class to be required for payment methods with type: "Spree::PaymentMethod::Check"?

Copy link
Member

Choose a reason for hiding this comment

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

Good find Filipe! I think the comment is right, we should just make it nil in this case. I've updated the code and the spec to show the error is now avoided. How does that look?

@filipefurtad0 filipefurtad0 force-pushed the migrate_legacy_specs branch 3 times, most recently from db4c4b0 to f2eae55 Compare May 3, 2024 11:47
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

David got there before I did :). I think it looks good now.

spec/controllers/checkout_controller_spec.rb Outdated Show resolved Hide resolved
Comment on lines -63 to -74
it "clears shipments and payments before rendering the checkout" do
put update_checkout_path, params:, as: :json

# Checking out a bogus Stripe Gateway without a source fails at :payment
# Shipments and payments should then be cleared before rendering checkout
expect(response.status).to be 400
expect(flash[:error])
.to eq 'Payment could not be processed, please check the details you entered'
order.reload
expect(order.shipments.count).to be 0
expect(order.payments.count).to be 0
expect(order.adjustment_total).to eq 0
Copy link
Member

Choose a reason for hiding this comment

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

Good find Filipe! I think the comment is right, we should just make it nil in this case. I've updated the code and the spec to show the error is now avoided. How does that look?

@dacook
Copy link
Member

dacook commented May 6, 2024

Sorry I forgot to press submit on my comments 😀

@filipefurtad0 filipefurtad0 added user facing changes Thes pull requests affect the user experience and removed technical changes only These pull requests do not contain user facing changes and are grouped in release notes labels May 6, 2024
@filipefurtad0
Copy link
Contributor Author

filipefurtad0 commented May 6, 2024

Good find Filipe! I think the comment is right, we should just make it nil in this case. I've updated the code and the spec to show the error is now avoided. How does that look?

Awesome, @dacook . I think this can have an impact on checkout, so:

  • I've opened an issue to add some context
  • changed this issue to type user facing

We do have system specs for checkout with cash/check. Do you think it's worth having a round of manual testing?

@dacook
Copy link
Member

dacook commented May 6, 2024

Great job Filipe 👍

We do have system specs for checkout with cash/check. Do you think it's worth having a round of manual testing?

I'm not sure, but given that we don't have a system spec for this case and don't know how to replicate it, I think it would be worth a manual test. Just to see if we can replicate or learn anything more about it. Would you be willing to do that?

@dacook
Copy link
Member

dacook commented May 6, 2024

I just realised we only have one review for my code change. I'll request Maikel's review before proceeding.

@dacook dacook requested a review from mkllnk May 6, 2024 23:25
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

This makes sense.

@@ -308,6 +308,62 @@
end
end

context "with no payment source" do
Copy link
Member

Choose a reason for hiding this comment

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

FYI: you referenced a Bugsnag issue but Bugsnags retention is quite limited and it a month or so the link won't be valid anymore.

@mkllnk
Copy link
Member

mkllnk commented May 7, 2024

I think that we should check the checkout on staging though, with a cash payment method.

@drummer83 drummer83 self-assigned this May 7, 2024
@drummer83 drummer83 added pr-staged-au staging.openfoodnetwork.org.au no-staging-AU A tag which does not trigger deployments, indicating a server is being used and removed pr-staged-au staging.openfoodnetwork.org.au labels May 7, 2024
@drummer83
Copy link
Contributor

Hi @filipefurtad0,
Thanks for working on this one! 💪

I have staged the PR and tested the following:

  • Build is green. ✔️
  • Check out with cash payment method. ✔️
  • Check Bugsnag for errors. ✔️
  • Check browser console for errors. ❓

We do see some errors in the console. I am just now staging master to check if we have it there too. Probably it's unrelated. We shall see.

Here is the console output:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://js.stripe.com') does not match the recipient window's origin ('https://staging.openfoodnetwork.org.au'). summary
Uncaught Error: frame window is not ready
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    retryTimeout https://js.stripe.com/v3/:1
    __trace__ https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    setTimeout handler*Ye/load/r/< https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    value https://js.stripe.com/v3/:1
    promise callback*value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    b https://js.stripe.com/v3/:1
    _handleMessage https://js.stripe.com/v3/:1
    l https://js.stripe.com/v3/:1
    _setupPostMessage https://js.stripe.com/v3/:1
    __trace__ https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    r https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    addEventListener https://js.stripe.com/v3/:1
    _setupPostMessage https://js.stripe.com/v3/:1
    e https://js.stripe.com/v3/:1
    Ka https://js.stripe.com/v3/:1
    Ya https://js.stripe.com/v3/:1
    Xa https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    e https://js.stripe.com/v3/:1
    Wc https://js.stripe.com/v3/:1
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    mutationObserver https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    n https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    n https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
v3:1:111066
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    retryTimeout https://js.stripe.com/v3/:1
    __trace__ https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    (Async: setTimeout handler)
    r https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    value https://js.stripe.com/v3/:1
    (Async: promise callback)
    value https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    b https://js.stripe.com/v3/:1
    _handleMessage https://js.stripe.com/v3/:1
    l https://js.stripe.com/v3/:1
    _setupPostMessage https://js.stripe.com/v3/:1
    __trace__ https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    (Async: EventListener.handleEvent)
    r https://d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js:1
    addEventListener https://js.stripe.com/v3/:1
    _setupPostMessage https://js.stripe.com/v3/:1
    e https://js.stripe.com/v3/:1
    Ka https://js.stripe.com/v3/:1
    Ya https://js.stripe.com/v3/:1
    Xa https://js.stripe.com/v3/:1
    value https://js.stripe.com/v3/:1
    e https://js.stripe.com/v3/:1
    Wc https://js.stripe.com/v3/:1
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    forEach self-hosted:203
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    mutationObserver https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    (Async: MutationCallback)
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    e https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    value https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    n https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    n https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2
    <anonymous> https://staging.openfoodnetwork.org.au/packs/js/application-d68d15335f2ff6bf3cd4.js:2

I have to stop here and check master later.

Thanks again!

@drummer83
Copy link
Contributor

Sorry it took so long, @filipefurtad0!

I can confirm that the errors are in master as well. Unfortunately there is a conflict now. Could you have a look at that please? Let me know if I should re-test afterwards.

Thanks and sorry again! 🙏

@drummer83 drummer83 added feedback-needed and removed no-staging-AU A tag which does not trigger deployments, indicating a server is being used labels May 13, 2024
We can see on the respective controller spec, that having a Stripe SCA payment, with no source does not trigger the error 400, observed on the legacy checkout.
dacook and others added 2 commits May 13, 2024 12:55
Most of the time this doesn't get called because source_required: false.
But sometimes it [does happen](https://app.bugsnag.com/yaycode/openfoodnetwork-uk/errors/66329690f4b6380007e8a4f8)

I have a feeling that source_required? could be moved to the superclass as payment_source_class.present?. But I don't know enough about this area of the system to try it...
Removes unused error message
@filipefurtad0
Copy link
Contributor Author

filipefurtad0 commented May 13, 2024

I can confirm that the errors are in master as well. Unfortunately there is a conflict now. Could you have a look at that please? Let me know if I should re-test afterwards.

Hey @drummer83 ,

All good - thank you for testing.
The conflict arose due to a change on a file this PR is removing; I've confirmed the file removal during rebase which fixes the conflict.

Everything else is left untouched. I would say it's ok to merge straight away - I've moved to ready to go and wait till someone confirms :-)

@dacook dacook merged commit 1f91c2e into openfoodfoundation:master May 13, 2024
50 checks passed
@dacook
Copy link
Member

dacook commented May 13, 2024

Merged, thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user facing changes Thes pull requests affect the user experience
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Checkout] Error 500 with cash/check payment method
5 participants