Skip to content

Payment method preferences returns different object types depending on setup #3717

Closed

Description

@seand7565

When setting up a payment_method, if you don't use static model preferences, you get a Hash object when you call payment_method.preferences. If you do use static model preferences, you instead get a Spree::Preferences::StaticModelPreferences::Definition object when you call payment_method.preferences

While using the default preference source, this command will succeed:
payment_method.preferences[:available_to_users]
While using static model preferences, the same command will fail.

Solidus Version:
2.10 - though likely an issue in more versions

To Reproduce

  1. Create a Check payment method
  2. Set it to use a static model preference (example provided below)
  3. Open a console, run Spree::PaymentMethod.last.preferences[:test_mode] - it will fail
  4. Set the payment method to use the "custom" preference source
  5. In the console, run Spree::PaymentMethod.last.preferences[:test_mode] - it will succeed

Example static model preference:

# config/initializers/example_credentials.rb

Spree::Config.configure do |config|
  config.static_model_preferences.add(
    Spree::PaymentMethod::Check,
    'example_credential_source', {
      test_mode: false
    }
  )
end

Current behavior
payment_method.preferences could return either a Hash or a model object depending on the setup

Expected behavior
payment_method.preferences should always return just one object type - IMO preferably a Hash object.

Screenshots
image
image

Activity

  1. changed the title [-]Static model preferences returns a different [/-] [+]Payment method preferences returns different object types depending on setup[/+] on Jul 21, 2020
  2. peterberkenbosch commented on Jul 22, 2020

    @peterberkenbosch
    Contributor

    Using preferred_ prefix for the preferences works on both setups. I do agree the hash option is more Ruby idiomatic :)

  3. locked and limited conversation to collaborators on Sep 7, 2022
  4. converted this issue into a discussion #4584 on Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions