mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #4236 from mkllnk/4222-checkout-paypal-error-handling
4233 Add missing Spree route for Paypal
This commit is contained in:
@@ -104,6 +104,9 @@ Spree::Core::Engine.routes.prepend do
|
||||
|
||||
resources :products
|
||||
|
||||
# Used by spree_paypal_express
|
||||
get '/checkout/:state', :to => 'checkout#edit', :as => :checkout_state
|
||||
|
||||
get '/unauthorized', :to => 'home#unauthorized', :as => :unauthorized
|
||||
get '/content/cvv', :to => 'content#cvv', :as => :cvv
|
||||
get '/content/*path', :to => 'content#show', :as => :content
|
||||
|
||||
88
spec/features/consumer/shopping/checkout_paypal_spec.rb
Normal file
88
spec/features/consumer/shopping/checkout_paypal_spec.rb
Normal file
@@ -0,0 +1,88 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature "Checking out with Paypal", js: true do
|
||||
include ShopWorkflow
|
||||
include CheckoutWorkflow
|
||||
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:product) { create(:simple_product, supplier: supplier) }
|
||||
let(:variant) { product.variants.first }
|
||||
let(:order_cycle) {
|
||||
create(
|
||||
:simple_order_cycle,
|
||||
suppliers: [supplier],
|
||||
distributors: [distributor],
|
||||
coordinator: distributor,
|
||||
variants: [variant]
|
||||
)
|
||||
}
|
||||
let(:order) {
|
||||
create(
|
||||
:order,
|
||||
order_cycle: order_cycle,
|
||||
distributor: distributor,
|
||||
bill_address_id: nil,
|
||||
ship_address_id: nil
|
||||
)
|
||||
}
|
||||
let(:free_shipping) { create(:shipping_method) }
|
||||
let!(:paypal) do
|
||||
Spree::Gateway::PayPalExpress.create!(
|
||||
name: "Paypal",
|
||||
environment: "test",
|
||||
distributor_ids: [distributor.id]
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
distributor.shipping_methods << free_shipping
|
||||
set_order order
|
||||
add_product_to_cart order, product
|
||||
end
|
||||
|
||||
describe "as a guest" do
|
||||
it "fails with an error message" do
|
||||
visit checkout_path
|
||||
complete_the_form
|
||||
|
||||
paypal_response = double(:response, success?: false, errors: [])
|
||||
paypal_provider = double(
|
||||
:provider,
|
||||
build_set_express_checkout: nil,
|
||||
set_express_checkout: paypal_response
|
||||
)
|
||||
allow_any_instance_of(Spree::PaypalController).to receive(:provider).
|
||||
and_return(paypal_provider)
|
||||
|
||||
place_order
|
||||
expect(page).to have_content "PayPal failed."
|
||||
end
|
||||
end
|
||||
|
||||
def complete_the_form
|
||||
checkout_as_guest
|
||||
|
||||
within "#details" do
|
||||
fill_in "First Name", with: "Will"
|
||||
fill_in "Last Name", with: "Marshall"
|
||||
fill_in "Email", with: "test@test.com"
|
||||
fill_in "Phone", with: "0468363090"
|
||||
end
|
||||
|
||||
within "#billing" do
|
||||
fill_in "City", with: "Melbourne"
|
||||
fill_in "Postcode", with: "3066"
|
||||
fill_in "Address", with: "123 Your Head"
|
||||
select "Australia", from: "Country"
|
||||
select "Victoria", from: "State"
|
||||
end
|
||||
|
||||
within "#shipping" do
|
||||
choose free_shipping.name
|
||||
end
|
||||
within "#payment" do
|
||||
choose paypal.name
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -26,12 +26,12 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
end
|
||||
|
||||
describe "with shipping and payment methods" do
|
||||
let(:sm1) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0.00)) }
|
||||
let(:sm2) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 4.56)) }
|
||||
let(:sm3) { create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local") }
|
||||
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") }
|
||||
let!(:pm2) { create(:payment_method, distributors: [distributor], calculator: Spree::Calculator::FlatRate.new(preferred_amount: 5.67)) }
|
||||
let!(:pm3) do
|
||||
let(:free_shipping) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0.00)) }
|
||||
let(:shipping_with_fee) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 4.56)) }
|
||||
let(:tagged_shipping) { create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local") }
|
||||
let!(:check_without_fee) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") }
|
||||
let!(:check_with_fee) { create(:payment_method, distributors: [distributor], calculator: Spree::Calculator::FlatRate.new(preferred_amount: 5.67)) }
|
||||
let!(:paypal) do
|
||||
Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', distributor_ids: [distributor.id]).tap do |pm|
|
||||
pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com'
|
||||
pm.preferred_password = '1406163716'
|
||||
@@ -40,9 +40,9 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
end
|
||||
|
||||
before do
|
||||
distributor.shipping_methods << sm1
|
||||
distributor.shipping_methods << sm2
|
||||
distributor.shipping_methods << sm3
|
||||
distributor.shipping_methods << free_shipping
|
||||
distributor.shipping_methods << shipping_with_fee
|
||||
distributor.shipping_methods << tagged_shipping
|
||||
end
|
||||
|
||||
describe "when I have an out of stock product in my cart" do
|
||||
@@ -55,9 +55,9 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
it "returns me to the cart with an error message" do
|
||||
visit checkout_path
|
||||
|
||||
page.should_not have_selector 'closing', text: "Checkout now"
|
||||
page.should have_selector 'closing', text: "Your shopping cart"
|
||||
page.should have_content "An item in your cart has become unavailable"
|
||||
expect(page).not_to have_selector 'closing', text: "Checkout now"
|
||||
expect(page).to have_selector 'closing', text: "Your shopping cart"
|
||||
expect(page).to have_content "An item in your cart has become unavailable"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -75,23 +75,23 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
end
|
||||
|
||||
it "allows user to save default billing address and shipping address" do
|
||||
user.bill_address.should be_nil
|
||||
user.ship_address.should be_nil
|
||||
expect(user.bill_address).to be_nil
|
||||
expect(user.ship_address).to be_nil
|
||||
|
||||
order.bill_address.should be_nil
|
||||
order.ship_address.should be_nil
|
||||
expect(order.bill_address).to be_nil
|
||||
expect(order.ship_address).to be_nil
|
||||
|
||||
place_order
|
||||
page.should have_content "Your order has been processed successfully"
|
||||
expect(page).to have_content "Your order has been processed successfully"
|
||||
|
||||
order.reload.bill_address.address1.should eq '123 Your Head'
|
||||
order.reload.ship_address.address1.should eq '123 Your Head'
|
||||
expect(order.reload.bill_address.address1).to eq '123 Your Head'
|
||||
expect(order.reload.ship_address.address1).to eq '123 Your Head'
|
||||
|
||||
order.customer.bill_address.address1.should eq '123 Your Head'
|
||||
order.customer.ship_address.address1.should eq '123 Your Head'
|
||||
expect(order.customer.bill_address.address1).to eq '123 Your Head'
|
||||
expect(order.customer.ship_address.address1).to eq '123 Your Head'
|
||||
|
||||
user.reload.bill_address.address1.should eq '123 Your Head'
|
||||
user.reload.ship_address.address1.should eq '123 Your Head'
|
||||
expect(user.reload.bill_address.address1).to eq '123 Your Head'
|
||||
expect(user.reload.ship_address.address1).to eq '123 Your Head'
|
||||
end
|
||||
|
||||
it "it doesn't tell about previous orders" do
|
||||
@@ -122,12 +122,12 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
it "checks out successfully" do
|
||||
visit checkout_path
|
||||
choose sm2.name
|
||||
choose pm1.name
|
||||
choose shipping_with_fee.name
|
||||
choose check_without_fee.name
|
||||
|
||||
expect do
|
||||
place_order
|
||||
page.should have_content "Your order has been processed successfully"
|
||||
expect(page).to have_content "Your order has been processed successfully"
|
||||
end.to enqueue_job ConfirmOrderJob
|
||||
end
|
||||
end
|
||||
@@ -205,8 +205,8 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
fill_out_details
|
||||
fill_out_billing_address
|
||||
choose sm1.name
|
||||
choose pm1.name
|
||||
choose free_shipping.name
|
||||
choose check_without_fee.name
|
||||
|
||||
place_order
|
||||
expect(page).to have_content "Your order has been processed successfully"
|
||||
@@ -215,8 +215,8 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
visit shop_path
|
||||
# The presence of the control product ensures the list of products is fully loaded
|
||||
# before we verify the sold product is not present
|
||||
page.should have_content control_product.name
|
||||
page.should_not have_content product.name
|
||||
expect(page).to have_content control_product.name
|
||||
expect(page).not_to have_content product.name
|
||||
end
|
||||
end
|
||||
|
||||
@@ -228,44 +228,44 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
it "shows the current distributor" do
|
||||
visit checkout_path
|
||||
page.should have_content distributor.name
|
||||
expect(page).to have_content distributor.name
|
||||
end
|
||||
|
||||
it 'does not show the save as default address checkbox' do
|
||||
page.should_not have_content "Save as default billing address"
|
||||
page.should_not have_content "Save as default shipping address"
|
||||
expect(page).not_to have_content "Save as default billing address"
|
||||
expect(page).not_to have_content "Save as default shipping address"
|
||||
end
|
||||
|
||||
it "shows a breakdown of the order price" do
|
||||
choose sm2.name
|
||||
choose shipping_with_fee.name
|
||||
|
||||
page.should have_selector 'orderdetails .cart-total', text: with_currency(11.23)
|
||||
page.should have_selector 'orderdetails .shipping', text: with_currency(4.56)
|
||||
page.should have_selector 'orderdetails .total', text: with_currency(15.79)
|
||||
expect(page).to have_selector 'orderdetails .cart-total', text: with_currency(11.23)
|
||||
expect(page).to have_selector 'orderdetails .shipping', text: with_currency(4.56)
|
||||
expect(page).to have_selector 'orderdetails .total', text: with_currency(15.79)
|
||||
|
||||
# Tax should not be displayed in checkout, as the customer's choice of shipping method
|
||||
# affects the tax and we haven't written code to live-update the tax amount when they
|
||||
# make a change.
|
||||
page.should_not have_content product.tax_category.name
|
||||
expect(page).not_to have_content product.tax_category.name
|
||||
end
|
||||
|
||||
it "shows all shipping methods in order by name" do
|
||||
within '#shipping' do
|
||||
expect(page).to have_selector "label", count: 4 # Three shipping methods + instructions label
|
||||
labels = page.all('label').map(&:text)
|
||||
expect(labels[0]).to start_with("Donkeys") # sm2
|
||||
expect(labels[1]).to start_with("Frogs") # sm1
|
||||
expect(labels[2]).to start_with("Local") # sm3
|
||||
expect(labels[0]).to start_with("Donkeys") # shipping_with_fee
|
||||
expect(labels[1]).to start_with("Frogs") # free_shipping
|
||||
expect(labels[2]).to start_with("Local") # tagged_shipping
|
||||
end
|
||||
end
|
||||
|
||||
context "when shipping method requires an address" do
|
||||
before do
|
||||
choose sm1.name
|
||||
choose free_shipping.name
|
||||
end
|
||||
it "shows ship address forms when 'same as billing address' is unchecked" do
|
||||
uncheck "Shipping address same as billing address?"
|
||||
find("#ship_address > div.visible").visible?.should be true
|
||||
expect(find("#ship_address > div.visible").visible?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -275,9 +275,9 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
it "shows shipping methods allowed by the rule" do
|
||||
# No rules in effect
|
||||
page.should have_content "Frogs"
|
||||
page.should have_content "Donkeys"
|
||||
page.should have_content "Local"
|
||||
expect(page).to have_content "Frogs"
|
||||
expect(page).to have_content "Donkeys"
|
||||
expect(page).to have_content "Local"
|
||||
|
||||
create(:filter_shipping_methods_tag_rule,
|
||||
enterprise: distributor,
|
||||
@@ -293,25 +293,25 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
checkout_as_guest
|
||||
|
||||
# Default rule in effect, disallows access to 'Local'
|
||||
page.should have_content "Frogs"
|
||||
page.should have_content "Donkeys"
|
||||
page.should_not have_content "Local"
|
||||
expect(page).to have_content "Frogs"
|
||||
expect(page).to have_content "Donkeys"
|
||||
expect(page).not_to have_content "Local"
|
||||
|
||||
quick_login_as(user)
|
||||
visit checkout_path
|
||||
|
||||
# Default rule in still effect, disallows access to 'Local'
|
||||
page.should have_content "Frogs"
|
||||
page.should have_content "Donkeys"
|
||||
page.should_not have_content "Local"
|
||||
expect(page).to have_content "Frogs"
|
||||
expect(page).to have_content "Donkeys"
|
||||
expect(page).not_to have_content "Local"
|
||||
|
||||
customer.update_attribute(:tag_list, "local")
|
||||
visit checkout_path
|
||||
|
||||
# #local Customer can access 'Local' shipping method
|
||||
page.should have_content "Frogs"
|
||||
page.should have_content "Donkeys"
|
||||
page.should have_content "Local"
|
||||
expect(page).to have_content "Frogs"
|
||||
expect(page).to have_content "Donkeys"
|
||||
expect(page).to have_content "Local"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -323,9 +323,9 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
end
|
||||
|
||||
it "shows all available payment methods" do
|
||||
page.should have_content pm1.name
|
||||
page.should have_content pm2.name
|
||||
page.should have_content pm3.name
|
||||
expect(page).to have_content check_without_fee.name
|
||||
expect(page).to have_content check_with_fee.name
|
||||
expect(page).to have_content paypal.name
|
||||
end
|
||||
|
||||
describe "purchasing" do
|
||||
@@ -334,12 +334,12 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
fill_out_billing_address
|
||||
|
||||
within "#shipping" do
|
||||
choose sm2.name
|
||||
choose shipping_with_fee.name
|
||||
fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS"
|
||||
end
|
||||
|
||||
within "#payment" do
|
||||
choose pm1.name
|
||||
choose check_without_fee.name
|
||||
end
|
||||
|
||||
expect do
|
||||
@@ -366,8 +366,8 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
context "with basic details filled" do
|
||||
before do
|
||||
choose sm1.name
|
||||
choose pm1.name
|
||||
choose free_shipping.name
|
||||
choose check_without_fee.name
|
||||
fill_out_details
|
||||
fill_out_billing_address
|
||||
check "Shipping address same as billing address?"
|
||||
@@ -375,7 +375,7 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do
|
||||
place_order
|
||||
page.should have_content "Your order has been processed successfully"
|
||||
expect(page).to have_content "Your order has been processed successfully"
|
||||
end
|
||||
|
||||
it "takes us to the cart page with an error when a product becomes out of stock just before we purchase", js: true do
|
||||
@@ -385,22 +385,22 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
place_order
|
||||
|
||||
page.should_not have_content "Your order has been processed successfully"
|
||||
page.should have_selector 'closing', text: "Your shopping cart"
|
||||
page.should have_content "An item in your cart has become unavailable."
|
||||
expect(page).not_to have_content "Your order has been processed successfully"
|
||||
expect(page).to have_selector 'closing', text: "Your shopping cart"
|
||||
expect(page).to have_content "An item in your cart has become unavailable."
|
||||
end
|
||||
|
||||
context "when we are charged a shipping fee" do
|
||||
before { choose sm2.name }
|
||||
before { choose shipping_with_fee.name }
|
||||
|
||||
it "creates a payment for the full amount inclusive of shipping" do
|
||||
place_order
|
||||
page.should have_content "Your order has been processed successfully"
|
||||
expect(page).to have_content "Your order has been processed successfully"
|
||||
|
||||
# There are two orders - our order and our new cart
|
||||
o = Spree::Order.complete.first
|
||||
o.adjustments.shipping.first.amount.should == 4.56
|
||||
o.payments.first.amount.should == 10 + 1.23 + 4.56 # items + fees + shipping
|
||||
expect(o.adjustments.shipping.first.amount).to eq(4.56)
|
||||
expect(o.payments.first.amount).to eq(10 + 1.23 + 4.56) # items + fees + shipping
|
||||
end
|
||||
end
|
||||
|
||||
@@ -410,7 +410,7 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
expect(page).to have_selector ".transaction-fee td", text: with_currency(0.00)
|
||||
expect(page).to have_selector ".total", text: with_currency(11.23)
|
||||
|
||||
choose "#{pm2.name} (#{with_currency(5.67)})"
|
||||
choose "#{check_with_fee.name} (#{with_currency(5.67)})"
|
||||
|
||||
expect(page).to have_selector ".transaction-fee td", text: with_currency(5.67)
|
||||
expect(page).to have_selector ".total", text: with_currency(16.90)
|
||||
@@ -428,7 +428,7 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
describe "credit card payments" do
|
||||
["Spree::Gateway::Bogus", "Spree::Gateway::BogusSimple"].each do |gateway_type|
|
||||
context "with a credit card payment method using #{gateway_type}" do
|
||||
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: gateway_type) }
|
||||
let!(:check_without_fee) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: gateway_type) }
|
||||
|
||||
it "takes us to the order confirmation page when submitted with a valid credit card" do
|
||||
fill_in 'Card Number', with: "4111111111111111"
|
||||
@@ -437,11 +437,11 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
fill_in 'Security Code', with: '123'
|
||||
|
||||
place_order
|
||||
page.should have_content "Your order has been processed successfully"
|
||||
expect(page).to 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 == 11.23
|
||||
expect(o.payments.first.amount).to eq(11.23)
|
||||
end
|
||||
|
||||
it "shows the payment processing failed message when submitted with an invalid credit card" do
|
||||
@@ -451,11 +451,11 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
fill_in 'Security Code', with: '123'
|
||||
|
||||
place_order
|
||||
page.should have_content 'Bogus Gateway: Forced failure'
|
||||
expect(page).to have_content 'Bogus Gateway: Forced failure'
|
||||
|
||||
# Does not show duplicate shipping fee
|
||||
visit checkout_path
|
||||
page.should have_selector "th", text: "Shipping", count: 1
|
||||
expect(page).to have_selector "th", text: "Shipping", count: 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -485,8 +485,8 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
end
|
||||
|
||||
def fill_out_form
|
||||
choose sm1.name
|
||||
choose pm1.name
|
||||
choose free_shipping.name
|
||||
choose check_without_fee.name
|
||||
|
||||
fill_out_details
|
||||
check "Save as default billing address"
|
||||
|
||||
Reference in New Issue
Block a user