diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b54990 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +\#* +*~ +.#* +.DS_Store +.idea +.project +tmp +nbproject +*.swp +spec/dummy diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..53607ea --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..74609dc --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2011 [name of plugin creator] +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name Spree nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..09e1de7 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +SpreeStripe +=========== + +Introduction goes here. + + +Example +======= + +Example goes here. + +Testing +------- + +Be sure to add the rspec-rails gem to your Gemfile and then create a dummy test app for the specs to run against. + + $ bundle exec rake test app + $ bundle exec rspec spec + +Copyright (c) 2011 [name of extension creator], released under the New BSD License diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..fea5d1b --- /dev/null +++ b/Rakefile @@ -0,0 +1,31 @@ +require 'rake' +require 'rake/testtask' +require 'rake/packagetask' +require 'rubygems/package_task' +require 'rspec/core/rake_task' +require 'cucumber/rake/task' +require 'spree_core/testing_support/common_rake' + +RSpec::Core::RakeTask.new +Cucumber::Rake::Task.new + +task :default => [:spec, :cucumber ] + +spec = eval(File.read('spree_stripe.gemspec')) + +Gem::PackageTask.new(spec) do |p| + p.gem_spec = spec +end + +desc "Release to gemcutter" +task :release => :package do + require 'rake/gemcutter' + Rake::Gemcutter::Tasks.new(spec).define + Rake::Task['gem:push'].invoke +end + +desc "Generates a dummy app for testing" +task :test_app do + ENV['LIB_NAME'] = 'spree_stripe' + Rake::Task['common:test_app'].invoke +end diff --git a/Versionfile b/Versionfile new file mode 100644 index 0000000..2010da9 --- /dev/null +++ b/Versionfile @@ -0,0 +1,9 @@ +# This file is used to designate compatibilty with different versions of Spree +# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details + +# Examples +# +# "0.70.x" => { :branch => "master"} +# "0.60.x" => { :branch => "0-60-stable" } +# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" } + diff --git a/app/assets/javascripts/admin/spree_stripe.js b/app/assets/javascripts/admin/spree_stripe.js new file mode 100644 index 0000000..a3b2c53 --- /dev/null +++ b/app/assets/javascripts/admin/spree_stripe.js @@ -0,0 +1 @@ +//= require admin/spree_core diff --git a/app/assets/javascripts/store/spree_stripe.js b/app/assets/javascripts/store/spree_stripe.js new file mode 100644 index 0000000..d5cb5c7 --- /dev/null +++ b/app/assets/javascripts/store/spree_stripe.js @@ -0,0 +1 @@ +//= require store/spree_core diff --git a/app/assets/stylesheets/admin/spree_stripe.css b/app/assets/stylesheets/admin/spree_stripe.css new file mode 100644 index 0000000..21ef02a --- /dev/null +++ b/app/assets/stylesheets/admin/spree_stripe.css @@ -0,0 +1,3 @@ +/* + *= require admin/spree_core +*/ diff --git a/app/assets/stylesheets/store/checkout.js b/app/assets/stylesheets/store/checkout.js new file mode 100644 index 0000000..3ed1bbd --- /dev/null +++ b/app/assets/stylesheets/store/checkout.js @@ -0,0 +1,72 @@ +(function($){ + $(document).ready(function(){ + if($('#checkout_form_address').is('*')){ + + $('#checkout_form_address').validate(); + + var get_states = function(region){ + country = $('p#' + region + 'country' + ' span#' + region + 'country :only-child').val(); + return state_mapper[country]; + } + + var update_state = function(region) { + states = get_states(region); + + state_select = $('p#' + region + 'state select'); + state_input = $('p#' + region + 'state input'); + + if(states) { + selected = state_select.val(); + state_select.html(''); + states_with_blank = [["",""]].concat(states); + $.each(states_with_blank, function(pos,id_nm) { + var opt = $(document.createElement('option')) + .attr('value', id_nm[0]) + .html(id_nm[1]); + if(selected==id_nm[0]){ + opt.prop("selected", true); + } + state_select.append(opt); + }); + state_select.prop("disabled", false).show(); + state_input.hide().prop("disabled", true); + + } else { + state_input.prop("disabled", false).show(); + state_select.hide().prop("disabled", true); + } + + }; + + $('p#bcountry select').change(function() { update_state('b'); }); + $('p#scountry select').change(function() { update_state('s'); }); + update_state('b'); + update_state('s'); + + $('input#order_use_billing').click(function() { + if($(this).is(':checked')) { + $('#shipping .inner').hide(); + $('#shipping .inner input, #shipping .inner select').prop("disabled", true); + } else { + $('#shipping .inner').show(); + $('#shipping .inner input, #shipping .inner select').prop("disabled", false); + //only want to enable relevant field + if(get_states('s')){ + $('span#sstate input').hide().prop("disabled", true); + }else{ + $('span#sstate select').hide().prop("disabled", true); + } + + } + }).triggerHandler('click'); + } + + if($('#checkout_form_payment').is('*')){ + // Show fields for the selected payment method + $("input[type='radio'][name='order[payments_attributes][][payment_method_id]']").click(function(){ + $('#payment-methods li').hide(); + if(this.checked){ $('#payment_method_'+this.value).show(); } + }).triggerHandler('click'); + } + }); +})(jQuery); \ No newline at end of file diff --git a/app/assets/stylesheets/store/spree_stripe.css b/app/assets/stylesheets/store/spree_stripe.css new file mode 100644 index 0000000..94dbe33 --- /dev/null +++ b/app/assets/stylesheets/store/spree_stripe.css @@ -0,0 +1,3 @@ +/* + *= require store/spree_core +*/ diff --git a/app/models/gateway/stripe.rb b/app/models/gateway/stripe.rb new file mode 100644 index 0000000..eb5b6c3 --- /dev/null +++ b/app/models/gateway/stripe.rb @@ -0,0 +1,10 @@ +class Gateway::Stripe < Gateway + preference :login, :string + + def provider_class + ActiveMerchant::Billing::StripeGateway + end + def payment_profiles_supported? + false + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..1c3c3b6 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # Add your extension routes here +end diff --git a/lib/generators/spree_stripe/install/install_generator.rb b/lib/generators/spree_stripe/install/install_generator.rb new file mode 100644 index 0000000..eaff744 --- /dev/null +++ b/lib/generators/spree_stripe/install/install_generator.rb @@ -0,0 +1,29 @@ +module SpreeStripe + module Generators + class InstallGenerator < Rails::Generators::Base + + def add_javascripts + append_file "app/assets/javascripts/store/all.js", "//= require store/spree_stripe\n" + append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_stripe\n" + end + + def add_stylesheets + inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_stripe\n", :before => /\*\//, :verbose => true + inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_stripe\n", :before => /\*\//, :verbose => true + end + + def add_migrations + run 'bundle exec rake railties:install:migrations FROM=spree_stripe' + end + + def run_migrations + res = ask "Would you like to run the migrations now? [Y/n]" + if res == "" || res.downcase == "y" + run 'bundle exec rake db:migrate' + else + puts "Skiping rake db:migrate, don't forget to run it!" + end + end + end + end +end diff --git a/lib/spree_stripe.rb b/lib/spree_stripe.rb new file mode 100644 index 0000000..c6d9715 --- /dev/null +++ b/lib/spree_stripe.rb @@ -0,0 +1,2 @@ +require 'spree_core' +require 'spree_stripe/engine' diff --git a/lib/spree_stripe/engine.rb b/lib/spree_stripe/engine.rb new file mode 100644 index 0000000..a333950 --- /dev/null +++ b/lib/spree_stripe/engine.rb @@ -0,0 +1,28 @@ +module SpreeStripe + class Engine < Rails::Engine + engine_name 'spree_stripe' + + config.autoload_paths += %W(#{config.root}/lib) + + # use rspec for tests + config.generators do |g| + g.test_framework :rspec + end + + def self.activate + Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c| + Rails.application.config.cache_classes ? require(c) : load(c) + end + + Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c| + Rails.application.config.cache_classes ? require(c) : load(c) + end + end + initializer "spree_stripe.register.payment_methods" do |app| + app.config.spree.payment_methods += [ + Gateway::Stripe + ] + end + config.to_prepare &method(:activate).to_proc + end +end diff --git a/script/rails b/script/rails new file mode 100644 index 0000000..ef2a53b --- /dev/null +++ b/script/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + + +ENGINE_PATH = File.expand_path('../..', __FILE__) +APP_PATH = File.expand_path('../../../config/application', __FILE__) +require File.expand_path('../../../config/boot', __FILE__) +require 'rails/commands' + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..cc1bc1c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,31 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + + +require File.expand_path("../../../config/environment.rb", __FILE__) + + +require 'rspec/rails' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} + +RSpec.configure do |config| + # == Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + config.mock_with :rspec + + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true +end diff --git a/spree_stripe.gemspec b/spree_stripe.gemspec new file mode 100644 index 0000000..79a2380 --- /dev/null +++ b/spree_stripe.gemspec @@ -0,0 +1,23 @@ +# encoding: UTF-8 +Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = 'spree_stripe' + s.version = '0.70.1' + s.summary = 'Add gem summary here' + s.description = 'Add (optional) gem description here' + s.required_ruby_version = '>= 1.8.7' + + # s.author = 'David Heinemeier Hansson' + # s.email = 'david@loudthinking.com' + # s.homepage = 'http://www.rubyonrails.org' + # s.rubyforge_project = 'actionmailer' + + #s.files = `git ls-files`.split("\n") + #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.require_path = 'lib' + s.requirements << 'none' + + s.add_dependency 'spree_core', '>= 0.70.1' + s.add_development_dependency 'rspec-rails' +end +