Skip to content

Commit

Permalink
Merge pull request #259 from WebGents/add_quickpay_support
Browse files Browse the repository at this point in the history
Add support for the QuickPay gateway
  • Loading branch information
damianlegawiec authored Aug 28, 2016
2 parents c02d6ff + d104290 commit 772fe18
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/models/spree/gateway/quickpay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Spree
class Gateway::Quickpay < Gateway
preference :api_key, :string

def provider_class
ActiveMerchant::Billing::QuickpayV10Gateway
end
end
end
1 change: 1 addition & 0 deletions lib/spree_gateway/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Engine < Rails::Engine
app.config.spree.payment_methods << Spree::Gateway::PayflowPro
app.config.spree.payment_methods << Spree::Gateway::Paymill
app.config.spree.payment_methods << Spree::Gateway::PinGateway
app.config.spree.payment_methods << Spree::Gateway::Quickpay
app.config.spree.payment_methods << Spree::Gateway::SagePay
app.config.spree.payment_methods << Spree::Gateway::SecurePayAU
app.config.spree.payment_methods << Spree::Gateway::SpreedlyCoreGateway
Expand Down
16 changes: 14 additions & 2 deletions spec/features/stripe_checkout_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "Stripe checkout" do
describe "Stripe checkout", type: :feature do
let!(:country) { create(:country, :states_required => true) }
let!(:state) { create(:state, :country => country) }
let!(:shipping_method) { create(:shipping_method) }
Expand Down Expand Up @@ -30,7 +30,14 @@
Spree::CheckoutController.any_instance.stub(:try_spree_current_user => user)
Spree::CheckoutController.any_instance.stub(:skip_state_validation? => true)

# Capybara should wait up to 10 seconds for async. changes to be applied
Capybara.default_max_wait_time = 10

visit spree.checkout_state_path(:payment)
begin
setup_stripe_watcher
rescue Capybara::NotSupportedByDriverError
end
end

# This will pass the CC data to the server and the StripeGateway class handles it
Expand All @@ -53,7 +60,8 @@
fill_in "Card Code", :with => "123"
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
click_button "Save and Continue"
sleep(5) # Wait for Stripe API to return + form to submit
wait_for_stripe # Wait for Stripe API to return + form to submit
page.should have_css('#checkout_form_confirm')
page.current_url.should include("/checkout/confirm")
click_button "Place Order"
page.should have_content("Your order has been processed successfully")
Expand All @@ -63,6 +71,7 @@
# Card number is NOT valid. Fails Luhn checksum
fill_in "Card Number", :with => "4242 4242 4242 4249"
click_button "Save and Continue"
wait_for_stripe
page.should have_content("Your card number is incorrect")
page.should have_css('.has-error #card_number.error')
end
Expand All @@ -71,6 +80,7 @@
fill_in "Card Number", :with => "4242 4242 4242 4242"
fill_in "Expiration", :with => "01 / #{Time.now.year + 1}"
click_button "Save and Continue"
wait_for_stripe
page.should have_content("Your card's security code is invalid.")
page.should have_css('.has-error #card_code.error')
end
Expand All @@ -80,6 +90,7 @@
fill_in "Expiration", :with => "00 / #{Time.now.year + 1}"
fill_in "Card Code", :with => "123"
click_button "Save and Continue"
wait_for_stripe
page.should have_content("Your card's expiration month is invalid.")
page.should have_css('.has-error #card_expiry.error')
end
Expand All @@ -89,6 +100,7 @@
fill_in "Expiration", :with => "12 / "
fill_in "Card Code", :with => "123"
click_button "Save and Continue"
wait_for_stripe
page.should have_content("Your card's expiration year is invalid.")
page.should have_css('.has-error #card_expiry.error')
end
Expand Down
11 changes: 11 additions & 0 deletions spec/models/gateway/quickpay_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe Spree::Gateway::Quickpay do
let(:gateway) { described_class.create!(name: 'QuickpayGateway') }

context '.provider_class' do
it 'is a Quickpay gateway' do
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::QuickpayV10Gateway
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require 'ffaker'
require 'rspec/active_model/mocks'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each { |f| require f }

require 'spree/testing_support/factories'
require 'spree/testing_support/order_walkthrough'
Expand Down
27 changes: 27 additions & 0 deletions spec/support/wait_for_stripe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module WaitForStripe
def wait_for_stripe
Timeout.timeout(Capybara.default_max_wait_time) do
loop until page.evaluate_script('window.activeStripeRequests').zero?
end
end

def setup_stripe_watcher
page.evaluate_script <<-JS
window.activeStripeRequests = 0;
$('#checkout_form_payment [data-hook=buttons]').on('click', function() {
window.activeStripeRequests = window.activeStripeRequests + 1;
});
stripeResponseHandler = (function() {
var _f = stripeResponseHandler;
return function() {
window.activeStripeRequests = window.activeStripeRequests - 1;
_f.apply(this, arguments);
}
})();
JS
end
end

RSpec.configure do |config|
config.include WaitForStripe, type: :feature
end

0 comments on commit 772fe18

Please sign in to comment.