Fix payments coming up as $0, credit card charges failing for the same reason

This commit is contained in:
Rohan Mitchell
2014-06-11 12:41:08 +10:00
committed by Will Marshall
parent d9a5b02415
commit 71020a14ef
3 changed files with 21 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ class CheckoutController < Spree::CheckoutController
end
def update
if @order.update_attributes(params[:order])
if @order.update_attributes(object_params)
fire_event('spree.checkout.update')
while @order.state != "complete"
if @order.state == "payment"
@@ -52,8 +52,23 @@ class CheckoutController < Spree::CheckoutController
end
end
private
# Copied and modified from spree. Remove check for order state, since the state machine is
# progressed all the way in one go with the one page checkout.
def object_params
# For payment step, filter order parameters to produce the expected nested attributes for a single payment and its source, discarding attributes for payment methods other than the one selected
if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore]
params[:order][:payments_attributes].first[:source_attributes] = source_params
end
if (params[:order][:payments_attributes])
params[:order][:payments_attributes].first[:amount] = @order.total
end
params[:order]
end
def update_failed
clear_ship_address
respond_to do |format|

View File

@@ -145,6 +145,10 @@ feature "As a consumer I want to check out my cart", js: true do
place_order
page.should have_content "Your order has been processed successfully"
# Order should have a payment with the correct amount
o = Spree::Order.complete.first
o.payments.first.amount.should == 10
end
it "shows the payment processing failed message when submitted with an invalid credit card" do

View File

@@ -13,6 +13,7 @@ module ShopWorkflow
def add_product_to_cart
create(:line_item, variant: product.master, order: order)
order.reload.save! # Recalculate totals
end
def toggle_accordion(name)