Skip to content
This repository has been archived by the owner on Nov 29, 2019. It is now read-only.

Paypal express button on cart step #141

Open
wants to merge 1 commit into
base: 1-3-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/controllers/spree/checkout_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ def paypal_confirm
@order.ship_address = order_ship_address
@order.bill_address ||= order_ship_address

@order.email ||= @ppx_details.params["payer"]

#Add Instant Update Shipping
if payment_method.preferred_cart_checkout
add_shipping_charge

unless @order.adjustments.tax.exists?
@order.create_tax_charge!
end
end

end
Expand Down Expand Up @@ -359,7 +365,7 @@ def shipping_options
end

{
:callback_url => spree.root_url + "paypal_shipping_update",
:callback_url => spree.root_url + "paypal_shipping_update/#{@order.number}",
:callback_timeout => 6,
:callback_version => '61.0',
:shipping_options => shipping_default
Expand Down Expand Up @@ -492,5 +498,11 @@ def estimate_shipping_for_user
@rate_hash_user = @shipping_order.rate_hash
#TODO
end

def skip_state_validation_with_paypal_express?
%w(paypal_checkout paypal_payment paypal_confirm paypal_finish).include?(action_name) or skip_state_validation_without_paypal_express?
end
alias_method_chain :skip_state_validation?, :paypal_express

end
end
18 changes: 11 additions & 7 deletions app/controllers/spree/paypal_express_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def shipping_estimate
estimate_shipping_and_taxes

payment_methods_atts2 = {}
@rate_hash.each_with_index do |shipping_method, idx|
payment_methods_atts2["L_TAXAMT#{idx}"] = @order.tax_total #TODO need to calculate based on shipping method
@shipping_and_taxes.each_with_index do |(shipping_method, tax_total), idx|
payment_methods_atts2["L_TAXAMT#{idx}"] = tax_total
payment_methods_atts2["L_SHIPPINGOPTIONAMOUNT#{idx}"] = shipping_method.cost
payment_methods_atts2["L_SHIPPINGOPTIONNAME#{idx}"] = shipping_method.name
payment_methods_atts2["L_SHIPPINGOPTIONLABEL#{idx}"] = "Shipping" #Do not change, required field
Expand All @@ -73,17 +73,21 @@ def retrieve_details
end

def estimate_shipping_and_taxes
@order = Spree::Order.find_by_number(current_order(true).number)
zipcode = @zip
shipping_methods = Spree::ShippingMethod.all
@order = Spree::Order.find_by_number(params[:id])
#TODO remove hard coded shipping
#Make a deep copy of the order object then stub out the parts required to get a shipping quote
@shipping_order = Marshal::load(Marshal.dump(@order)) #Make a deep copy of the order object
@shipping_order.ship_address = Spree::Address.new(:country => Spree::Country.find_by_iso("#{@country}"), :zipcode => zipcode)
@shipping_order.ship_address = Spree::Address.new(:country => Spree::Country.find_by_iso("#{@country}"), :zipcode => @zip)
shipment = Spree::Shipment.new(:address => @shipping_order.ship_address)
@shipping_order.ship_address.shipments<<shipment
@shipping_order.shipments<<shipment
@rate_hash = @shipping_order.rate_hash
@shipping_and_taxes = @shipping_order.rate_hash.map do |shipping_method|
#TODO need to calculate based on shipping method
tax_total = TaxRate.match(@shipping_order).sum do |rate|
rate.compute_amount(@shipping_order)
end
[shipping_method, tax_total]
end
end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--
insert_bottom '[data-hook=cart_buttons]'
-->
<%= render :partial => 'spree/orders/cart_paypalexpress_button' %>

10 changes: 10 additions & 0 deletions app/views/spree/orders/_cart_paypalexpress_button.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% @order.available_payment_methods.each do |payment_method| %>
<% if payment_method.method_type.start_with?('paypalexpress') and payment_method.preferred_cart_checkout %>
<a href="<%= paypal_payment_order_checkout_url @order, :payment_method_id => payment_method.id %>">
<img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" />
</a>
<% end %>
<% end %>



2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

match '/paypal_notify' => 'paypal_express_callbacks#notify', :via => [:get, :post]

match '/paypal_shipping_update' => 'paypal_express_callbacks#shipping_estimate', :via => :post
match '/paypal_shipping_update/:id' => 'paypal_express_callbacks#shipping_estimate', :via => :post

namespace :admin do
resources :orders do
Expand Down