spree_bitcoin_checkout 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ tmp
8
+ nbproject
9
+ *.swp
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ SpreeBitcoinCheckout
2
+ ====================
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2011 [name of extension creator], released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/packagetask'
5
+ require 'rake/gempackagetask'
6
+
7
+ gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
8
+ if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
9
+ require 'bundler'
10
+ ENV['BUNDLE_GEMFILE'] = gemfile
11
+ Bundler.setup
12
+
13
+ require 'rspec'
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new
16
+
17
+ require 'cucumber/rake/task'
18
+ Cucumber::Rake::Task.new do |t|
19
+ t.cucumber_opts = %w{--format progress}
20
+ end
21
+ end
22
+
23
+ desc "Default Task"
24
+ task :default => [:spec, :cucumber ]
25
+
26
+ spec = eval(File.read('spree_bitcoin_checkout.gemspec'))
27
+
28
+ Rake::GemPackageTask.new(spec) do |p|
29
+ p.gem_spec = spec
30
+ end
31
+
32
+ desc "Release to gemcutter"
33
+ task :release => :package do
34
+ require 'rake/gemcutter'
35
+ Rake::Gemcutter::Tasks.new(spec).define
36
+ Rake::Task['gem:push'].invoke
37
+ end
38
+
39
+ desc "Default Task"
40
+ task :default => [ :spec ]
41
+
42
+ desc "Regenerates a rails 3 app for testing"
43
+ task :test_app do
44
+ require '../spree/lib/generators/spree/test_app_generator'
45
+ class SpreeBitcoinCheckoutTestAppGenerator < Spree::Generators::TestAppGenerator
46
+
47
+ def install_gems
48
+ inside "test_app" do
49
+ run 'rake spree_core:install'
50
+ run 'rake spree_bitcoin_checkout:install'
51
+ end
52
+ end
53
+
54
+ def migrate_db
55
+ run_migrations
56
+ end
57
+
58
+ protected
59
+ def full_path_for_local_gems
60
+ <<-gems
61
+ gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
62
+ gem 'spree_bitcoin_checkout', :path => \'#{File.dirname(__FILE__)}\'
63
+ gems
64
+ end
65
+
66
+ end
67
+ SpreeBitcoinCheckoutTestAppGenerator.start
68
+ end
69
+
70
+ namespace :test_app do
71
+ desc 'Rebuild test and cucumber databases'
72
+ task :rebuild_dbs do
73
+ system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
74
+ end
75
+ end
data/Versionfile ADDED
@@ -0,0 +1,9 @@
1
+ # This file is used to designate compatibilty with different versions of Spree
2
+ # Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
3
+
4
+ # Examples
5
+ #
6
+ # "0.50.x" => { :branch => "master" }
7
+ # "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
8
+
9
+
@@ -0,0 +1,7 @@
1
+ class BitcoinCheckoutNotificationController < ApplicationController
2
+ protect_from_forgery :except => :create
3
+
4
+ def create
5
+ # Nothing here yet
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ CheckoutController.class_eval do
2
+ def update_with_redirect_to_bitcoin_sci
3
+ if should_redirect_to_bitcoin_sci?
4
+ create_invoice_through_api!
5
+ redirect_to "https://bitcoin-central.net/invoices"
6
+ else
7
+ update_without_redirect_to_bitcoin_sci
8
+ end
9
+ end
10
+
11
+ alias_method_chain :update, :redirect_to_bitcoin_sci
12
+
13
+ def should_redirect_to_bitcoin_sci?
14
+ params[:state] == "payment" &&
15
+ (PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id]).type.to_s =~ /BitcoinCheckout/)
16
+ end
17
+
18
+ def create_invoice_through_api!
19
+ require "net/https"
20
+ require "uri"
21
+
22
+ order = current_order
23
+
24
+ base_url = AppConfiguration.first.preferred_site_url.gsub(/\/$/, "")
25
+ callback_url = [base_url, bitcoin_checkout_notification_path].join
26
+
27
+ user = order.payments.first.payment_method.preferred_user
28
+ password = order.payments.first.payment_method.preferred_password
29
+
30
+ uri = URI.parse("https://bitcoin-central.net/invoices")
31
+ http = Net::HTTP.new(uri.host, uri.port)
32
+ http.use_ssl = true
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
+
35
+ request = Net::HTTP::Post.new(uri.request_uri)
36
+ request.basic_auth(user, password)
37
+ request.set_form_data({
38
+ "invoice[merchant_reference]" => order.number,
39
+ "invoice[merchant_memo]" => "Payment for order #{order.number}",
40
+ "invoice[amount]" => order.total.to_s,
41
+ "invoice[callback_url]" => callback_url,
42
+ "invoice[item_url]" => order_path(order)
43
+ }
44
+ )
45
+ response = http.request(request)
46
+ puts response.body
47
+ # response.status
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ class Billing::BitcoinCheckout < BillingIntegration
2
+ preference :account, :string
3
+ preference :api_key, :string
4
+ preference :api_url, :string
5
+ end
@@ -0,0 +1,10 @@
1
+ <% title = "Checkout with Bitcoin !" -%>
2
+
3
+ <%=
4
+ image_submit_tag( "bitcoin.jpg",
5
+ :name => "Bitcoin Checkout",
6
+ :alt => title,
7
+ :title => title,
8
+ :name => "bitcoin_payment"
9
+ )
10
+ %>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ resources :bitcoin_checkout_notification,
3
+ :only => :create
4
+ end
@@ -0,0 +1,15 @@
1
+ class AddGoogleCheckoutColumnsInOrder < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :orders, :financial_order_state , :string
4
+ add_column :orders, :google_order_number, :string
5
+ add_column :orders, :buyer_id, :string
6
+ add_column :orders, :gateway, :string
7
+ end
8
+
9
+ def self.down
10
+ remove_column :orders, :financial_order_state
11
+ remove_column :orders, :google_order_number
12
+ remove_column :orders, :buyer_id
13
+ remove_column :orders, :gateway
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require 'spree_core'
2
+ require 'spree_bitcoin_checkout_hooks'
3
+
4
+ module SpreeBitcoinCheckout
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
11
+ Rails.env.production? ? require(c) : load(c)
12
+ end
13
+
14
+ Billing::BitcoinCheckout.register
15
+ end
16
+
17
+ initializer "static assets" do |app|
18
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
19
+ end
20
+
21
+ config.to_prepare &method(:activate).to_proc
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ class SpreeBitcoinCheckoutHooks < Spree::ThemeSupport::HookListener
2
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_bitcoin_checkout do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_bitcoin_checkout:install:migrations'].invoke
5
+ Rake::Task['spree_bitcoin_checkout:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
Binary file
@@ -0,0 +1,30 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../test_app/config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ # == Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+ config.mock_with :rspec
20
+
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ #config.include Devise::TestHelpers, :type => :controller
24
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
25
+ # examples within a transaction, comment the following line or assign false
26
+ # instead of true.
27
+ config.use_transactional_fixtures = true
28
+ end
29
+
30
+ @configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'spree_bitcoin_checkout'
4
+ s.version = '0.1'
5
+ s.summary = "Automatically integrate bitcoin-central.net's API"
6
+ s.description = 'Leverages the invoicing API in order to seamlessly accept bitcoin denominated payments'
7
+ s.required_ruby_version = '>= 1.8.7'
8
+
9
+ s.author = 'David FRANCOIS'
10
+ s.email = 'david@bitcoin-central.net'
11
+ s.homepage = 'https://bitcoin-central.net/'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.require_path = 'lib'
16
+ s.requirements << 'none'
17
+
18
+ s.add_dependency('spree_core', '>= 0.60.0')
19
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_bitcoin_checkout
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - David FRANCOIS
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-22 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: spree_core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 239
29
+ segments:
30
+ - 0
31
+ - 60
32
+ - 0
33
+ version: 0.60.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Leverages the invoicing API in order to seamlessly accept bitcoin denominated payments
37
+ email: david@bitcoin-central.net
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - Versionfile
50
+ - app/controllers/bitcoin_checkout_notification_controller.rb
51
+ - app/controllers/checkout_controller_decorator.rb
52
+ - app/models/billing/bitcoin_checkout.rb
53
+ - app/views/checkout/payment/_bitcoincheckout.erb
54
+ - config/routes.rb
55
+ - db/migrate/20110519233636_add_bitcoin_checkout_columns_in_order.rb
56
+ - lib/spree_bitcoin_checkout.rb
57
+ - lib/spree_bitcoin_checkout_hooks.rb
58
+ - lib/tasks/install.rake
59
+ - lib/tasks/spree_bitcoin_checkout.rake
60
+ - public/images/bitcoin.jpg
61
+ - spec/spec_helper.rb
62
+ - spree_bitcoin_checkout.gemspec
63
+ has_rdoc: true
64
+ homepage: https://bitcoin-central.net/
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 57
78
+ segments:
79
+ - 1
80
+ - 8
81
+ - 7
82
+ version: 1.8.7
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements:
93
+ - none
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.7
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Automatically integrate bitcoin-central.net's API
99
+ test_files: []
100
+