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 complete solidusio#229 since solidusio#236 was incomplete: adds PayPal button customizable
parameters only for checkout/payment step. This PR adds the same feature also
for cart page.

Ref. solidusio#229
Ref. solidusio#236
  • Loading branch information
Flavio Auciello committed Nov 15, 2019
1 parent e85a085 commit 97a2e03
Show file tree
Hide file tree
Showing 3 changed files with 16 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

0 comments on commit 97a2e03

Please sign in to comment.