diff --git a/Changelog.md b/Changelog.md index 27c3744a..2ad7cee4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +## 2.4.1 (2023-03-03) + +- Allow `stripe_elements_tag` to accept a block. Thanks @chip ! + ## 2.4.0 (2023-02-04) - Add `tax_behavior` attribute to Price. Thanks @szechyjs ! diff --git a/Gemfile b/Gemfile index 4c60bec3..318d4131 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,6 @@ group :test do gem 'webmock' # System tests gem 'capybara' - gem 'puma', '< 6' # https://github.com/teamcapybara/capybara/issues/2598 - gem 'selenium-webdriver' - gem 'webdrivers' + gem 'puma' + gem 'selenium-webdriver', '~> 4.18', '>= 4.18.1' end diff --git a/README.md b/README.md index bc5b449e..c6b8cb14 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ This gem can help your rails application integrate with Stripe in the following - [Configuring your plans and coupons](#configuring-your-plans-and-coupons) [Stripe Elements](#stripe-elements) +- [Custom Elements](#custom-elements) [Webhooks](#webhooks) @@ -322,6 +323,22 @@ Simply include the `stripe_elements_tag` anywhere below the `stripe_javascript_t <%= stripe_elements_tag submit_path: billing_path %> ``` +Additionally, you can pass a block containing custom form elements to stripe_elements_tag: + +## Custom Elements + +> Stripe::Rails allows you to easily include your own custom form elements +> within the Stripe form by including those form elements in a block passed to +> `stripe_elements_tag`: + +```erb +<%= stripe_javascript_tag %> +<%= stripe_elements_tag(submit_path: billing_path) do %> + <%= label_tag 'email', 'Email' %> + <%= text_field :user, :email %> +<% end %> +``` + ### Configuration options Stripe::Rails comes bundled with default CSS and Javascript for Stripe elements, making it easy to drop in to your app. You can also specify your own assets paths: diff --git a/app/helpers/stripe/javascript_helper.rb b/app/helpers/stripe/javascript_helper.rb index 32150afa..9b63efd1 100644 --- a/app/helpers/stripe/javascript_helper.rb +++ b/app/helpers/stripe/javascript_helper.rb @@ -10,14 +10,16 @@ def stripe_javascript_tag(stripe_js_version = DEFAULT_STRIPE_JS_VERSION) def stripe_elements_tag(submit_path:, css_path: asset_path("stripe_elements.css"), - js_path: asset_path("stripe_elements.js")) + js_path: asset_path("stripe_elements.js"), + &block) render partial: 'stripe/elements', locals: { submit_path: submit_path, label_text: t('stripe_rails.elements.label_text'), submit_button_text: t('stripe_rails.elements.submit_button_text'), css_path: css_path, - js_path: js_path + js_path: js_path, + block: block } end end diff --git a/app/views/stripe/_elements.html.erb b/app/views/stripe/_elements.html.erb index b9ea5631..73f454cd 100644 --- a/app/views/stripe/_elements.html.erb +++ b/app/views/stripe/_elements.html.erb @@ -5,6 +5,11 @@ <%= form_tag submit_path, id: "stripe-form" do %> + <% if local_assigns[:block] %> +