Skip to content

Commit

Permalink
Add PayPal button customizable style also for cart page
Browse files Browse the repository at this point in the history
This PR solidusio#236
was incomplete since adds PayPal button customizable parameters only for
checkout/payment step. This PR adds the same feature also for
cart page.

Also add an ad-hoc example at cart page feautre test
  • Loading branch information
Flavio Auciello committed Nov 15, 2019
1 parent e85a085 commit 685e793
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
10 changes: 9 additions & 1 deletion app/views/spree/shared/_paypal_cart_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
var paypalOptions = {
flow: 'vault',
enableShippingAddress: true,
environment: '<%= Rails.env.production? ? "production" : "sandbox" %>'
environment: '<%= Rails.env.production? ? "production" : "sandbox" %>',
locale: '<%= paypal_button_preference(:paypal_button_locale, store: current_store) %>',
style: {
color: '<%= paypal_button_preference(:paypal_button_color, store: current_store) %>',
size: '<%= paypal_button_preference(:paypal_button_size, store: current_store) %>',
shape: '<%= paypal_button_preference(:paypal_button_shape, store: current_store) %>',
label: '<%= paypal_button_preference(:paypal_button_label, store: current_store) %>',
tagline: '<%= paypal_button_preference(:paypal_button_tagline, store: current_store) %>'
}
}
var options = {
restart_checkout: true
Expand Down
1 change: 1 addition & 0 deletions config/initializers/braintree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

if SolidusSupport.frontend_available?
Spree::CheckoutController.helper :braintree_checkout
Spree::OrdersController.helper :braintree_checkout
end
20 changes: 6 additions & 14 deletions spec/features/frontend/paypal_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

let!(:store) do
create(:store, payment_methods: [payment_method]).tap do |s|
s.braintree_configuration.update!(paypal: true)
s.braintree_configuration.update!(braintree_preferences)
end
end
let(:braintree_preferences) { {paypal: true }.merge(paypal_options) }
let(:paypal_options) { {} }

let!(:country) { create(:country, states_required: true) }
let!(:state) { create(:state, country: country, abbr: "CA", name: "California") }
Expand All @@ -34,21 +36,11 @@
end

context 'using custom paypal button style' do
before do
store.braintree_configuration.tap do |conf|
conf.set_preference(:paypal_button_color, 'blue')
conf.save!
end
end
let(:paypal_options) { { preferred_paypal_button_color: 'blue' } }

it 'should display required PayPal button style' do
pend_if_paypal_slow do
expect_any_instance_of(Spree::Order).to receive(:restart_checkout_flow)
move_through_paypal_popup

within(find('#paypal-button iframe')) do
expect(page).to have_selector('[class="paypal-button-color-blue]')
end
within_frame find('#paypal-button iframe') do
expect(page).to have_selector('.paypal-button-color-blue')
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@
page.driver.browser.manage.window.resize_to(1600, 1024)
end
end

# From Capybara gem - drivers.rb:
Capybara.register_driver :chrome_headless do |app|
Capybara::Selenium::Driver.load_selenium
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
opts.args << '--headless'
opts.args << '--disable-gpu' if Gem.win_platform?
end
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

Capybara.javascript_driver = :chrome_headless

# You can enable the following to see the specs running
# Capybara.javascript_driver = :selenium_chrome

0 comments on commit 685e793

Please sign in to comment.