spree_bitcoin_checkout 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
|
|
1
|
+
module Spree
|
2
|
+
module BitcoinCheckout
|
3
|
+
def self.included(base)
|
4
|
+
base.before_filter :redirect_to_bitcoin_central_if_needed,
|
5
|
+
:only => [:update]
|
6
|
+
end
|
7
|
+
|
8
|
+
def redirect_to_bitcoin_central_if_needed
|
9
|
+
if should_redirect_to_bitcoin_sci?
|
10
|
+
redirect_to create_invoice_through_api!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def should_redirect_to_bitcoin_sci?
|
15
|
+
params[:state] == "payment" &&
|
16
|
+
(PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id]).type.to_s =~ /BitcoinCheckout/)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_invoice_through_api!
|
20
|
+
require "net/https"
|
21
|
+
require "uri"
|
22
|
+
require "json"
|
23
|
+
|
24
|
+
payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
|
25
|
+
|
26
|
+
base_url = AppConfiguration.first.preferred_site_url.gsub(/\/$/, "")
|
27
|
+
base_url = "http://#{base_url}" unless base_url =~ /^http/
|
28
|
+
callback_url = [base_url, bitcoin_checkout_notification_path].join
|
29
|
+
item_url = [base_url, order_path(@order)].join
|
30
|
+
|
31
|
+
user = payment_method.preferred_user
|
32
|
+
password = payment_method.preferred_password
|
33
|
+
|
34
|
+
uri = URI.parse("#{payment_method.preferred_api_url}.json")
|
35
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
36
|
+
http.use_ssl = (uri.scheme == "https")
|
37
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
|
38
|
+
|
39
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
40
|
+
request.basic_auth(user, password)
|
41
|
+
request.set_form_data({
|
42
|
+
"invoice[merchant_reference]" => @order.number,
|
43
|
+
"invoice[merchant_memo]" => "Payment for order #{@order.number}",
|
44
|
+
"invoice[amount]" => @order.total.to_s,
|
45
|
+
"invoice[callback_url]" => callback_url,
|
46
|
+
"invoice[item_url]" => item_url
|
47
|
+
}
|
48
|
+
)
|
49
|
+
|
50
|
+
response = http.request(request)
|
51
|
+
Rails.logger.warn("**********************************************************")
|
52
|
+
Rails.logger.warn(response.body)
|
53
|
+
Rails.logger.warn("**********************************************************")
|
54
|
+
JSON.parse(response.body)["invoice"]["public_url"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.platform = Gem::Platform::RUBY
|
3
3
|
s.name = 'spree_bitcoin_checkout'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.3'
|
5
5
|
s.summary = "Automatically integrate bitcoin-central.net's API"
|
6
6
|
s.description = 'Leverages the invoicing API in order to seamlessly accept bitcoin denominated payments'
|
7
7
|
s.required_ruby_version = '>= 1.8.7'
|
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.requirements << 'none'
|
17
17
|
|
18
18
|
s.add_dependency('spree_core', '>= 0.60.0')
|
19
|
+
s.add_dependency('json', '>= 1.5.1')
|
19
20
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_bitcoin_checkout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David FRANCOIS
|
@@ -34,6 +34,22 @@ dependencies:
|
|
34
34
|
version: 0.60.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: json
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 1
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 5
|
49
|
+
- 1
|
50
|
+
version: 1.5.1
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
37
53
|
description: Leverages the invoicing API in order to seamlessly accept bitcoin denominated payments
|
38
54
|
email: david@bitcoin-central.net
|
39
55
|
executables: []
|
@@ -49,11 +65,11 @@ files:
|
|
49
65
|
- Rakefile
|
50
66
|
- Versionfile
|
51
67
|
- app/controllers/bitcoin_checkout_notification_controller.rb
|
52
|
-
- app/controllers/checkout_controller_decorator.rb
|
53
68
|
- app/models/billing/bitcoin_checkout.rb
|
54
69
|
- app/views/checkout/payment/_bitcoincheckout.erb
|
55
70
|
- config/routes.rb
|
56
71
|
- db/migrate/20110519233636_add_bitcoin_checkout_columns_in_order.rb
|
72
|
+
- lib/spree/bitcoin_checkout.rb
|
57
73
|
- lib/spree_bitcoin_checkout.rb
|
58
74
|
- lib/spree_bitcoin_checkout_hooks.rb
|
59
75
|
- lib/tasks/install.rake
|
@@ -1,49 +0,0 @@
|
|
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(order.payments.first.payment_method.preferred_api_url)
|
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
|