straight-server 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ae2d0fa734b525a466d866b825cf18c95cd8886
4
+ data.tar.gz: 054c7bef45cc6ed613149cda162368d1bbeac012
5
+ SHA512:
6
+ metadata.gz: f3c2cad75571e4bcc882bd33978b34efc7f831cd1fe154055b0ca2e0354ce70ac7a3b0c170cee2b54059811ace9bcd993aace43ccf09116d7f99aed64bceaf35
7
+ data.tar.gz: 29da34227a4b893dba7e285f84881dc20830d9d71d9e2dbb07c77e4f9aac391a7aed047ce5479297e23d820622bab79ffdd0835c2048558f080943fe1ed7c545
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "straight"
4
+ gem "satoshi-unit"
5
+ gem "goliath"
6
+ gem "faye-websocket"
7
+ gem "sequel"
8
+ gem "logmaster"
9
+ gem "ruby-hmac"
10
+
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem "bundler", "~> 1.0"
15
+ gem "jeweler", "~> 2.0.1"
16
+ gem "github_api", "0.11.3"
17
+ end
18
+
19
+ group :test do
20
+ gem 'rspec'
21
+ gem 'factory_girl'
22
+ gem 'sqlite3'
23
+ gem 'hashie'
24
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,138 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.6)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ async-rack (0.5.1)
12
+ rack (~> 1.1)
13
+ builder (3.2.2)
14
+ descendants_tracker (0.0.4)
15
+ thread_safe (~> 0.3, >= 0.3.1)
16
+ diff-lcs (1.2.5)
17
+ em-synchrony (1.0.3)
18
+ eventmachine (>= 1.0.0.beta.1)
19
+ em-websocket (0.3.8)
20
+ addressable (>= 2.1.1)
21
+ eventmachine (>= 0.12.9)
22
+ eventmachine (1.0.3)
23
+ factory_girl (4.4.0)
24
+ activesupport (>= 3.0.0)
25
+ faraday (0.9.0)
26
+ multipart-post (>= 1.2, < 3)
27
+ faye-websocket (0.7.4)
28
+ eventmachine (>= 0.12.0)
29
+ websocket-driver (>= 0.3.1)
30
+ ffi (1.9.3)
31
+ git (1.2.8)
32
+ github_api (0.11.3)
33
+ addressable (~> 2.3)
34
+ descendants_tracker (~> 0.0.1)
35
+ faraday (~> 0.8, < 0.10)
36
+ hashie (>= 1.2)
37
+ multi_json (>= 1.7.5, < 2.0)
38
+ nokogiri (~> 1.6.0)
39
+ oauth2
40
+ goliath (1.0.4)
41
+ async-rack
42
+ em-synchrony (>= 1.0.0)
43
+ em-websocket (= 0.3.8)
44
+ eventmachine (>= 1.0.0.beta.4)
45
+ http_parser.rb (= 0.6.0)
46
+ log4r
47
+ multi_json
48
+ rack (>= 1.2.2)
49
+ rack-contrib
50
+ rack-respond_to
51
+ hashie (3.3.1)
52
+ highline (1.6.21)
53
+ http_parser.rb (0.6.0)
54
+ i18n (0.6.11)
55
+ jeweler (2.0.1)
56
+ builder
57
+ bundler (>= 1.0)
58
+ git (>= 1.2.5)
59
+ github_api
60
+ highline (>= 1.6.15)
61
+ nokogiri (>= 1.5.10)
62
+ rake
63
+ rdoc
64
+ json (1.8.1)
65
+ jwt (1.0.0)
66
+ log4r (1.1.10)
67
+ logmaster (0.1.1)
68
+ pony
69
+ mail (2.6.1)
70
+ mime-types (>= 1.16, < 3)
71
+ mime-types (2.3)
72
+ mini_portile (0.6.0)
73
+ minitest (5.4.1)
74
+ money-tree (0.8.7)
75
+ ffi
76
+ multi_json (1.10.1)
77
+ multi_xml (0.5.5)
78
+ multipart-post (2.0.0)
79
+ nokogiri (1.6.3.1)
80
+ mini_portile (= 0.6.0)
81
+ oauth2 (1.0.0)
82
+ faraday (>= 0.8, < 0.10)
83
+ jwt (~> 1.0)
84
+ multi_json (~> 1.3)
85
+ multi_xml (~> 0.5)
86
+ rack (~> 1.2)
87
+ pony (1.11)
88
+ mail (>= 2.0)
89
+ rack (1.5.2)
90
+ rack-accept-media-types (0.9)
91
+ rack-contrib (1.1.0)
92
+ rack (>= 0.9.1)
93
+ rack-respond_to (0.9.8)
94
+ rack-accept-media-types (>= 0.6)
95
+ rake (10.3.2)
96
+ rdoc (4.1.2)
97
+ json (~> 1.4)
98
+ rspec (3.1.0)
99
+ rspec-core (~> 3.1.0)
100
+ rspec-expectations (~> 3.1.0)
101
+ rspec-mocks (~> 3.1.0)
102
+ rspec-core (3.1.2)
103
+ rspec-support (~> 3.1.0)
104
+ rspec-expectations (3.1.0)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.1.0)
107
+ rspec-mocks (3.1.0)
108
+ rspec-support (~> 3.1.0)
109
+ rspec-support (3.1.0)
110
+ ruby-hmac (0.4.0)
111
+ satoshi-unit (0.1.6)
112
+ sequel (4.13.0)
113
+ sqlite3 (1.3.9)
114
+ straight (0.1.0)
115
+ money-tree
116
+ thread_safe (0.3.4)
117
+ tzinfo (1.2.2)
118
+ thread_safe (~> 0.1)
119
+ websocket-driver (0.3.4)
120
+
121
+ PLATFORMS
122
+ ruby
123
+
124
+ DEPENDENCIES
125
+ bundler (~> 1.0)
126
+ factory_girl
127
+ faye-websocket
128
+ github_api (= 0.11.3)
129
+ goliath
130
+ hashie
131
+ jeweler (~> 2.0.1)
132
+ logmaster
133
+ rspec
134
+ ruby-hmac
135
+ satoshi-unit
136
+ sequel
137
+ sqlite3
138
+ straight
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Roman Snitko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,219 @@
1
+ Straight server
2
+ ===============
3
+ > A stand-alone Bitcoin payment gateway server
4
+ > Receives bitcoin payments directly into your wallet, holds no private keys
5
+
6
+ > Website: http://straight.romansnitko.com
7
+
8
+ If you'd like to accept Bitcoin payments on your website automatically, but you're not
9
+ fond of services like Coinbase or Bitpay, which hold your bitcoins for you and require a ton
10
+ of AML/KYC info, you came to the right place.
11
+
12
+ Straight server is a software you install on your machine, which you can then talk to
13
+ via a RESTful API to create orders and generate payment addresses. Straight server will
14
+ issue callback requests to the specified URLs when the bitcoins arrive and store all the information
15
+ about the order in a DB.
16
+
17
+ While it is written in Ruby, I made special effort so that it would be easy to install and configure.
18
+ You can use Straight server with any application and website. You can even run your own payment
19
+ gateway which serves many online stores.
20
+
21
+ Straight uses BIP32 pubkeys so that you and only you control your private keys.
22
+ If you're not sure what a BIP32 address and HD wallets are, read this article:
23
+ http://bitcoinmagazine.com/8396/deterministic-wallets-advantages-flaw/
24
+
25
+ Installation
26
+ ------------
27
+ I currently only tested it on Unix machines.
28
+
29
+ 1. Install RVM and Ruby 2.1 (see [RVM guide](http://rvm.io/rvm/install))
30
+
31
+ 2. run `gem install straight-server`
32
+
33
+ 3. start the server by running `straight-server`. This will generate a` ~/.straight` dir and put a `config.yml`
34
+ file in there, then shut down. You have to edit the file first to be able to run the server again.
35
+
36
+ 4. In `config.yml`, under the `gateways/default` section, insert your BIP32 pubkey and a callback URL.
37
+ Everything may be left as is for now. To generate a BIP32 private/public keys, you can use one of the
38
+ wallets that support BIP32 (currently it's bitWallet for iOS) or go to http://bip32.org
39
+
40
+ 5. Run the server again with `straight-server -p 9696`
41
+
42
+
43
+ Usage
44
+ -----
45
+ When the server is running, you can access it via http and use its RESTful API.
46
+ Below I assume it runs on localhost on port 9696.
47
+
48
+ **Creating a new order:**
49
+
50
+ # creates a new order for 1 satoshi
51
+ POST /gateways/1/orders?amount=1
52
+
53
+ the result of this request will be the following json:
54
+
55
+ {"status":0,"amount":1,"address":"1NZov2nm6gRCGW6r4q1qHtxXurrWNpPr1q","tid":null,"id":1 }
56
+
57
+ Now you can obviously use that output to provide your user with the address and the expected
58
+ amount to be sent there. At this point, the server starts automatically tracking the order address
59
+ in a separate thread, so that when the money arrive, a callback will be issued to the url provided
60
+ in the `~/.straight/config.yml` file for the current gateway. This callback request will contain order info too.
61
+ Here's an example of a callback url request that could be made by Straight server when order status changes:
62
+
63
+ GET http://mystore.com/payment-callback?order_id=1&amount=1&status=2&address=1NZov2nm6gRCGW6r4q1qHtxXurrWNpPr1q&tid=tid1&data=some+random+data
64
+
65
+ As you may have noticed, there's a parameter called `data`. It is a way for you to pass info back
66
+ to your app. It will have the same value as the `data` parameter you passed to the create order request:
67
+
68
+ POST /gateways/1/orders?amount=1&data=some+random+data
69
+
70
+ You can specify amount in other currencies, as well as various BTC denominations.
71
+ It will be converted using the current exchange rate (see [Straight::ExchangeAdapter](https://github.com/snitko/straight/blob/master/lib/straight/exchange_rate_adapter.rb)) into satoshis:
72
+
73
+ # creates a new order for 1 USD
74
+ POST /gateways/1/orders?amount=1&currency=USD
75
+
76
+ # creates an order for 0.00000001 BTC or 1 satoshi
77
+ POST /gateways/1/orders?amount=1&btc_denomination=btc
78
+
79
+
80
+ **Checking the order manually**
81
+ You can check the status of the order manually with the following request:
82
+
83
+ GET /gateways/1/orders/1
84
+
85
+ may return something like:
86
+
87
+ {"status":2,"amount":1,"address":"1NZov2nm6gRCGW6r4q1qHtxXurrWNpPr1q","tid":"f0f9205e41bf1b79cb7634912e86bb840cedf8b1d108bd2faae1651ca79a5838","id":1 }
88
+
89
+ **Subscribing to the order using websockets**:
90
+ You can also subscribe to the order status changes using websockets at:
91
+
92
+ /gateways/1/orders/1/websocket
93
+
94
+ It will send a message to the client upon the status change and close connection afterwards.
95
+
96
+ Client Example
97
+ --------------
98
+ I've implemented a small client example app written purely in Dart. It creates new orders,
99
+ tracks changes via websockets and displays status info upon status change. To see how it works,
100
+ download Dartium browser and navigate it to the `http://localhost:9696` while running the
101
+ Straight server in development mode (nothing special has to be done for that).
102
+
103
+ The code for this client app example can be found in [examples/client](https://github.com/snitko/straight-server/tree/master/examples/client).
104
+
105
+ Using many different gateways
106
+ ------------------------------
107
+ When you have many online stores, you'd want to create a separate gateway for each one of them.
108
+ They would all be running within one Straight server.
109
+
110
+ The standard way to do this is to use `~/.straight/config.yml` file. Under the `gateways` section,
111
+ simply add a new gateway (come up with a nice name for it!) and set all the options you see were
112
+ used for the default one. Change them as you wish. Restart the server.
113
+
114
+ To create an order for the new gateway, simply send this request:
115
+
116
+ POST /gateways/2/orders?amount=1&currency=USD
117
+
118
+ Notice that the gateway id has changed to 2. Gateway ids are assigned according to the order in
119
+ which they follow in the config file.
120
+
121
+ ** Gateways from DB **
122
+ When you have too many gateways, it is unwise to keep them in the config file. In that case,
123
+ you can store gateway settings in the DB. To do that, change `~/.straight/config.yml` setting
124
+ 'gateways_source: config` to `gateways_source: db`.
125
+
126
+ Then you should be able to use `straight-console` to manually create gateways to the DB. To do
127
+ that, you'd have to consult [Sequel documentation](http://sequel.jeremyevans.net/) because currently
128
+ there is no standard way to manage gateways through a web interface. In the future, it will be added.
129
+ In general, it shouldn't be difficult, and may look like this:
130
+
131
+ $ straight-console
132
+
133
+ > g = Gateway.new
134
+ > gateway.pubkey = 'xpub1234'
135
+ > gateway.confirmations_required = 0
136
+ > gateway.order_class = 'StraightServer::Order'
137
+ > gateway.callback_url = 'http://myapp.com/payment_callback'
138
+ > gateway.save
139
+ > exit
140
+
141
+ Using signatures
142
+ ----------------
143
+ If you are running straight-server on a machine separate from your online stores, you
144
+ HAVE to make sure that when somebody accesses your RESTful API it is those stores only,
145
+ and not somebody else. For that purpose, you're gonna need signatures.
146
+
147
+ Go to your `~/.straight/config.yml` directory and set two options for each of your gateways:
148
+
149
+ secret: 'a long string of random chars'
150
+ check_signature: true
151
+
152
+ This will force gateways to check signatures when you try to create a new order. A signature is
153
+ a HMAC SHA1 hash of the secret and an order id. Because you need order id, it means you have
154
+ to actually provide it manually in the params. It can be any integer > 0, but it's better
155
+ that it is a consecutive integer, so keep track of order ids in your application. Obviously,
156
+ if an order with such an id already exists, the request will be rejected. A possible request
157
+ (assuming secret is the line mentioned above in the sample config) would look like this:
158
+
159
+ POST /gateways/1/orders?amount=1&order_id=1&signature=fb0e8d863621a3e6e2bf4e81f8ab70737190d92b
160
+
161
+ An example of obtaining such signature in Ruby:
162
+
163
+ require 'hmac'
164
+ require 'hmac-sha1'
165
+
166
+ secret = 'a long string of random chars'
167
+ h = HMAC::SHA1.new(secret)
168
+ h << '1' # order id
169
+ h.hexdigest
170
+
171
+ Straight server will also sign the callback url request. However, since the signature may be
172
+ known to an attacker once it was used for creating a new order, we can no longer use it directly.
173
+ Thus, Straight server will use a double signature calculated like this:
174
+
175
+ secret = 'a long string of random chars'
176
+ h = HMAC::SHA1.new(secret)
177
+ h << '1' # order id
178
+ h2 = HMAC::SHA1.new(secret)
179
+ h2 << h.hexdigest
180
+ h2.hexdigest
181
+
182
+ and then send the request to the callback url with that signature:
183
+
184
+ GET http://mystore.com/payment-callback?order_id=1&amount=1&status=2&address=1NZov2nm6gRCGW6r4q1qHtxXurrWNpPr1q&tid=tid1&data=some+random+data?signature=a61381c87ea3f7e6958ef779b6a9789ec966c2b9
185
+
186
+ It is now up to your application to calculate that signature, compare it and
187
+ make sure that only one such request is allowed (that is, if signature was used, it cannot be used again).
188
+
189
+ Running in production
190
+ ---------------------
191
+ Running in production usually assumes running server as daemon with a pid. Straight server
192
+ uses [Goliath](https://github.com/postrank-labs/goliath) so you can look up various options there.
193
+ However, my recommendation is the following:
194
+
195
+ straight-server -e production -p 9696 --daemonize --pid ~/.straight/straight.pid
196
+
197
+ Note that goliath server log file settings do not apply here. Straight has its own logging
198
+ system and the file is usually `~/.straight/straight.log`. You can set various loggin options
199
+ in `~/.straight/config.yml`. For production, you may want to set log level to WARN and also
200
+ turn on email notifications, so that when a FATAL errors occurs, an email is sent to you address
201
+ (emailing would most likely require *sendmail* to be installed).
202
+
203
+ I would also recommend you to use something like *monit* daemon to monitor a *straight-server* process.
204
+
205
+ Requirements
206
+ ------------
207
+ Ruby 2.1 or later.
208
+
209
+ Donations
210
+ ---------
211
+ To go on with this project and make it truly awesome, I need more time. I can only buy free time with money, so any donation is highly appreciated. Please send bitcoins over to **1D3PknG4Lw1gFuJ9SYenA7pboF9gtXtdcD**
212
+
213
+ There are [development plans](http://straight.romansnitko.com/#todo) for this software you might be interested in.
214
+
215
+ Credits
216
+ -------
217
+ Author: [Roman Snitko](http://romansnitko.com)
218
+
219
+ Licence: MIT (see the LICENCE file)
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "straight-server"
18
+ gem.homepage = "http://github.com/snitko/straight-server"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A Bitcoin payment gateway server: a state server for the stateless Straight library}
21
+ gem.description = %Q{Accepts orders via http, returns payment info via http or streams updates via websockets, stores orders in a DB}
22
+ gem.email = "roman.snitko@gmail.com"
23
+ gem.authors = ["Roman Snitko"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'irb'
4
+ require_relative '../lib/straight-server'
5
+ include StraightServer::Initializer
6
+ prepare
7
+
8
+ require_relative '../lib/straight-server/order'
9
+ require_relative '../lib/straight-server/gateway'
10
+
11
+ ARGV.clear
12
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'goliath'
4
+
5
+ require_relative '../lib/straight-server'
6
+ require_relative '../lib/straight-server/server'
@@ -0,0 +1,26 @@
1
+ Sequel.migration do
2
+
3
+ up do
4
+ create_table(:orders) do
5
+ primary_key :id
6
+ String :address, null: false
7
+ String :tid
8
+ Integer :status, null: false, default: 0
9
+ Integer :keychain_id, null: false
10
+ Bignum :amount, null: false
11
+ Integer :gateway_id, null: false
12
+ String :data
13
+ String :callback_response, text: true
14
+ DateTime :created_at, null: false
15
+ DateTime :updated_at
16
+ end
17
+ add_index :orders, :id, unique: true
18
+ add_index :orders, :address, unique: true
19
+ add_index :orders, [:keychain_id, :gateway_id], unique: true
20
+ end
21
+
22
+ down do
23
+ drop_table(:orders)
24
+ end
25
+
26
+ end
@@ -0,0 +1,28 @@
1
+ Sequel.migration do
2
+
3
+ up do
4
+ create_table(:gateways) do
5
+ primary_key :id
6
+ Integer :confirmations_required, null: false, default: 0
7
+ Integer :last_keychain_id, null: false, default: 0
8
+ String :pubkey, null: false
9
+ String :order_class, null: false
10
+ String :secret, null: false
11
+ String :name, null: false
12
+ String :default_currency, default: 'BTC'
13
+ String :callback_url
14
+ Boolean :check_signature, null: false, default: false
15
+ String :exchange_rate_adapter_names
16
+ DateTime :created_at, null: false
17
+ DateTime :updated_at
18
+ end
19
+ add_index :gateways, :id, unique: true
20
+ add_index :gateways, :pubkey, unique: true
21
+ add_index :gateways, :name, unique: true
22
+ end
23
+
24
+ down do
25
+ drop_table(:gateways)
26
+ end
27
+
28
+ end
@@ -0,0 +1,67 @@
1
+ import 'dart:html';
2
+ import 'dart:convert';
3
+
4
+ main() {
5
+
6
+ var create_order_button = document.querySelector('button#create_order');
7
+
8
+ create_order_button.onClick.listen((e) =>
9
+ create_order().listen((event) {
10
+ var order = JSON.decode(event.target.responseText);
11
+ show_pay_order(order);
12
+ listen_to_order(order);
13
+ })
14
+ );
15
+
16
+ }
17
+
18
+ create_order() {
19
+ var request = new HttpRequest();
20
+ var listener = request.onLoad;
21
+ request.open('POST', '/gateways/1/orders?amount=1');
22
+ request.send();
23
+ return listener;
24
+ }
25
+
26
+ listen_to_order(order) {
27
+ var ws = new WebSocket("ws://localhost:9696/gateways/1/orders/${order['id']}/websocket");
28
+ ws.onMessage.listen((MessageEvent e) {
29
+ var order = JSON.decode(e.data);
30
+ if(order['status'] > 1) show_order_paid(order);
31
+ });
32
+ }
33
+
34
+ show_pay_order(order) {
35
+ var new_order_el = document.querySelector('#newOrder');
36
+ var pay_order_el = document.querySelector('#payOrder');
37
+
38
+ pay_order_el.querySelector('.orderId').text = order['id'].toString();
39
+ pay_order_el.querySelector('.orderAmount').text = order['amount'].toString();
40
+ pay_order_el.querySelector('.orderAddress').text = order['address'];
41
+
42
+ new_order_el.style.display = 'none';
43
+ pay_order_el.style.display = '';
44
+ }
45
+
46
+ show_order_paid(order) {
47
+
48
+ var status;
49
+ if(order['status'] == 2) {
50
+ status = 'PAID';
51
+ } else if(order['status'] == 3) {
52
+ status = 'UNDERPAID';
53
+ } else if(order['status'] == 4) {
54
+ status = 'OVERPAID';
55
+ } else {
56
+ status = order['status'].toString();
57
+ }
58
+
59
+ var order_paid_el = document.querySelector('#orderPaid');
60
+ var pay_order_el = document.querySelector('#payOrder');
61
+ order_paid_el.querySelector('.orderStatus').text = status;
62
+ order_paid_el.querySelector('.orderTid').text = order['tid'];
63
+
64
+ pay_order_el.style.display = 'none';
65
+ order_paid_el.style.display = '';
66
+
67
+ }
@@ -0,0 +1,32 @@
1
+ <html>
2
+
3
+ <head>
4
+ <title>A Straight client example</title>
5
+ <script type="application/dart" src="client.dart"></script>
6
+ </head>
7
+
8
+ <body>
9
+
10
+ <p><b style="color: red; font-size: 80%;">Attention: this page requires <a href="https://www.dartlang.org/tools/dartium/">Dartium</a> to run properly.</b></p>
11
+
12
+ <div id="newOrder">
13
+ <p>Welcome to the Straight client example. It assumes you have your Straight server running on localhost on the standart Straight port and this page is loaded by accessing the / (root) on that server: that is, check that in your browser address you currently see http://localhost:9696. Loding this page from the filesystem won't work since ajax-requests cannot be sent to other domains.</p>
14
+
15
+ <p>Clicking the button below will generate a new address for the order and will subscribe you to the websocket, which will automatically notify you when the money arrive to the address. You don't have to refresh this page.</p>
16
+
17
+ <p>Use this button to generate a new order:</p>
18
+ <p><button id="create_order">Create Order</button></p>
19
+ </div>
20
+
21
+ <div id="payOrder" style="display: none;">
22
+ Order <span class="orderId"></span> created. Please send exactly <b><span class="orderAmount"></span> satoshi(s)</b> to address <span class="orderAddress" style="font-weight: bold;"></span>. This page will be updated as soon as the transaction is made.
23
+ </div>
24
+
25
+ <div id="orderPaid" style="display: none;">
26
+ The status of your order is now <span class="orderStatus"></span><br/>
27
+ Transaction id is: <span class="orderTid"></span>
28
+ </div>
29
+
30
+ </body>
31
+
32
+ </html>
@@ -0,0 +1,11 @@
1
+ module StraightServer
2
+
3
+ class Config
4
+
5
+ class << self
6
+ attr_accessor :db, :gateways_source, :gateways, :logmaster
7
+ end
8
+
9
+ end
10
+
11
+ end