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

Allow bad payloads to be saved in payment log entries #4953

Merged

Conversation

elia
Copy link
Member

@elia elia commented Feb 23, 2023

Summary

A followup to #4950 after @gsmendoza and @kennyadsl pointed out that if a payment integration was feeding content that couldn't be deserialized the payment processing could have been disrupted vs. just breaking the payment details page in the admin console.

So we're now falling back to the old and very generous response.to_yaml, but not before showing a proper warning asking it to be fixed. The wording of the warning is intentionally avoiding a promise that we'll reject bad payloads but instead just says that we might skip them, so we ensure to never interrupt payment processing for a secondary issue in the payment logs.

So we're wrapping the bad response into a serializable one that will also report that a problem occurred.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

Allow a rescue to catch both in one go
@elia elia self-assigned this Feb 23, 2023
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Feb 23, 2023
@kennyadsl
Copy link
Member

@elia can you please mark this spec as flaky in this PR?

@elia
Copy link
Member Author

elia commented Feb 23, 2023

@kennyadsl
Copy link
Member

looks like it's already marked as such on master

It failed on multiple retries than 😢

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks for jumping on this Elia, I left one comment for the deprecation message. Also, I'm curious about what's happening on the admin for those items. If we are just raising an error, maybe we can intercept the Error and show some information to the admin?

console.

WARNING:
Future solidus versions might enforce compatibility and discard
Copy link
Member

Choose a reason for hiding this comment

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

This leaves some doubts that people can stay with the current code for some time, while the deprecation has a clear horizon instead (next major). I think we should decide if we want to remove the possibility of saving non-deserializable strings on the next major and be clear about it.

Also, instead of discard, I'd use reject, because the former makes me think that we could also remove existing entries.

Raising an exception at this time could prevent a payment from being
properly processed. Any incompatible response will be wrapped in a
valid one and saved with proper reporting.

This allows it to be both recorded and reported without breaking the
payment details page in the admin.
@elia elia force-pushed the elia/payment-log-entries-yaml-cleanup branch from 212aacd to a36e681 Compare February 23, 2023 16:21
@elia elia marked this pull request as ready for review February 23, 2023 16:48
@elia elia requested a review from a team as a code owner February 23, 2023 16:48
gsmendoza added a commit to solidusio/solidus_braintree that referenced this pull request Feb 24, 2023
Fixes #110.

Summary
--------

A error Braintree response would raise the following error:

```
Spree::LogEntry::DisallowedClass:
  Tried to dump unspecified class: Symbol

  You can specify custom classes to be loaded in config/initializers/spree.rb. E.g:

  Spree.config do |config|
    config.log_entry_permitted_classes = ['MyClass']
  end
```

Solidus Version:
--------

3.4.0.dev

Cause
--------

When `SolidusBraintree::Response.build(result)` accepts an error result, the
`result.params` it passes to the new response has symbol keys. Here's a sample
of the `result.params`:

```
    {:transaction=>
      {:amount=>"20.00",
       :order_id=>"R300000001",
       :channel=>"Solidus",
       :options=>{:store_in_vault_on_success=>"true"},
       :payment_method_token=>"0ev7m4dt",
       :customer_id=>"180763858",
       :type=>"sale"}}
```

Demonstration
--------

See
https://github.com/solidusio/solidus_braintree/tree/gsmendoza/110-log-entry-disallowed-class-demo
for a demonstration of the error and the my attempts to fix it. Start from
the "Try enabling venmo specs" commit.

Additional context
--------

Related to #108.

There is also a PR in Solidus that will temporarily allow bad payloads  to be
saved in payment log entries. See
solidusio/solidus#4953
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @elia!!!

@elia elia requested a review from kennyadsl February 24, 2023 12:33
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

👏👏

@kennyadsl kennyadsl merged commit 6d55800 into solidusio:master Feb 24, 2023
@kennyadsl kennyadsl deleted the elia/payment-log-entries-yaml-cleanup branch February 24, 2023 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants