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 PaymentMethod to register a custom partial view to display above "Payment Provider Settings" #294

Merged

Conversation

mateus-po
Copy link
Contributor

Allows user to define a custom partial view containing instructions for Payment Method configuration.

The process of creating a custom partial:

  1. Create partial view file in /spree_backend/app/views/spree/admin/payment_methods/configuration_guides/- create the configuration_guides folder if it doesn't exist.
  2. The name of the file has to follow the formula: _name.html.erb.
  3. Define a method payment_configuration_guide in chosen Payment Method class declaration. It should return the name of partial file.

Example custom partial view configuration for Spree::Gateway::Bogus:

View of the Payment Methods edit page before the changes:

Screenshot 2023-12-11 at 12 10 13

  1. Create partial _bogus_partial.html.erb in said directory. Contents of example partial file:
hi, I'm working!
  1. Find the Spree::Gateway::Bogus class declaration. For this example the path is: /spree/core/app/models/spree/gateway/bogus.rb. Add following method to class declaration:
def payment_configuration_guide
    "bogus_partial"
end

View of the Payment Methods edit page after the changes:

Screenshot 2023-12-11 at 12 16 01

<% if @object.respond_to?(:payment_configuration_guide) %>
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0"><%= Spree.t(:payment_method_configuration) %></h5>
Copy link
Member

Choose a reason for hiding this comment

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

@mateus-po one thing to do before merging this PR - could you add a translation key for payment_method_configuration to config/locales/en.yml ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Translation key added here.

@rafalcymerys rafalcymerys merged commit 2ebeb2b into main Jan 10, 2024
9 checks passed
@delete-merged-branch delete-merged-branch bot deleted the sp-167/allow-paymentmethod-register-custom-partial-view branch January 10, 2024 08:40
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.

2 participants