bitpay-client 2.2.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4dc42cd2a385367410f051b9a7def43a3ff3021
4
- data.tar.gz: c6bd1df8c6e5d47deb49afae0ca2caf0c376f6d6
3
+ metadata.gz: dae6ef526679f3cbcc49840dd2e1558913d38af7
4
+ data.tar.gz: e5dd36e2dbfcd8f715c381c4e89a4b44c28aaa50
5
5
  SHA512:
6
- metadata.gz: 6cb61d057cae19d839dc050028c196256c0837e0f64424985aef98df2dd5d3dd6563c3222b5dd7e0310b1931359916c9ce6c178cab0c30f692fdeac72d82ef6b
7
- data.tar.gz: 0e326cd00defdeeb8bae777cc42c5189155683aac1be108dcf05801b84dc5f4bab47d8554da6103ecb35514ec51f2c6033c0bc6c06a15a8aadcc75dcbe410aaa
6
+ metadata.gz: 8555438f87edbb9c2480f422bb5eb35b3433441dfebe9f8d2633e3ff74e96fca8bfc4f774353c9628021b05104115ae18512108a2e2514f24ac74aee2f6a9476
7
+ data.tar.gz: ac5da6a74b4b8ac4157c3ea3a4914277a6de32cc230f7ba6e580d022dfd08565c476bbec6bbab75b10e2d71bf71703558c8fda9f99e07ee21914e9bb066c7c98
data/.gitignore CHANGED
@@ -5,3 +5,5 @@ pkg
5
5
  .c9
6
6
  .ruby-version
7
7
  .ruby-gemset
8
+ .pem.data
9
+ coverage/
data/.travis.yml CHANGED
@@ -1,2 +1,3 @@
1
+ sudo: false
1
2
  rvm:
2
- - 2.1.0
3
+ - 2.2.2
data/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
- Copyright (C) 2014 BitPay
1
+ Copyright (C) 2015 BitPay
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
5
5
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,10 +1,17 @@
1
- # BitPay Library for Ruby [![](https://travis-ci.org/bitpay/ruby-cli.svg)](http://travis-ci.org/bitpay/ruby-cli)
1
+ # BitPay Library for Ruby
2
+
3
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/bitpay/ruby-cli/master/LICENSE.md)
4
+ [![Travis](https://img.shields.io/travis/bitpay/ruby-cli.svg?style=flat-square)](https://travis-ci.org/bitpay/ruby-cli)
5
+ [![Gem](https://img.shields.io/gem/v/bitpay-client.svg?style=flat-square)](https://rubygems.org/gems/bitpay-client)
6
+ [![Coveralls](https://img.shields.io/coveralls/bitpay/ruby-cli.svg?style=flat-square)](https://coveralls.io/github/bitpay/ruby-cli)
7
+ [![Code Climate](https://img.shields.io/codeclimate/github/bitpay/ruby-cli.svg?style=flat-square)](https://codeclimate.com/github/bitpay/ruby-cli)
8
+
2
9
  Powerful, flexible, lightweight interface to the BitPay Bitcoin Payment Gateway API.
3
10
 
4
11
  ## Installation
5
12
 
6
13
  gem install bitpay-client
7
-
14
+
8
15
  In your Gemfile:
9
16
 
10
17
  gem 'bitpay-client', :require => 'bitpay'
@@ -27,11 +34,13 @@ To pair with bitpay.com you need to have an approved merchant account.
27
34
  1. Login to your account
28
35
  2. Navigate to bitpay.com/api-tokens (Dashboard > My Account > API Tokens)
29
36
  3. Copy an existing pairing code or create a new token and copy the pairing code.
30
- 4. Use the bitpay command line tool to pair with bitpay.com `bitpay pair <pairing_code>`
37
+ 4. Use the bitpay command line tool to pair with bitpay.com `bitpay pair <pairing_code>`
31
38
 
32
39
  ### To create an invoice with a paired client:
33
40
 
34
- client = BitPay::Client.new
41
+ The command line utility will save a PEM file in the file $HOME/.bitpay/bitpay.pem. When creating new clients, this pem file is needed in order to have an authorized client.
42
+
43
+ client = BitPay::Client.new(pem: File.read("#{ENV['HOME']}/.bitpay/bitpay.pem"))
35
44
  invoice = client.create_invoice (id: <id>, price: <price>, currency: <currency>, facade: <facade>)
36
45
 
37
46
  With invoice creation, `price` and `currency` are the only required fields. If you are sending a customer from your website to make a purchase, setting `redirectURL` will redirect the customer to your website when the invoice is paid.
@@ -39,7 +48,7 @@ With invoice creation, `price` and `currency` are the only required fields. If y
39
48
  Response will be a hash with information on your newly created invoice. Send your customer to the `url` to complete payment:
40
49
 
41
50
  {
42
- "id" => "DGrAEmbsXe9bavBPMJ8kuk",
51
+ "id" => "DGrAEmbsXe9bavBPMJ8kuk",
43
52
  "url" => "https://bitpay.com/invoice?id=DGrAEmbsXe9bavBPMJ8kuk",
44
53
  "status" => "new",
45
54
  "btcPrice" => "0.0495",
@@ -56,13 +65,11 @@ To get updated information on this invoice, make a get call with the id returned
56
65
 
57
66
  invoice = client.get_public_invoice(DGrAEmbsXe9bavBPMJ8kuk)'
58
67
 
59
- ## Testnet Usage
68
+ The BitPay CLI gem requires the BitPay SDK gem. See the [BitPay SDK Gem](https://github.com/bitpay/ruby-client/blob/master/GUIDE.md) documentation for more details on using the BitPay Client SDK.
60
69
 
61
- During development and testing, take advantage of the [Bitcoin TestNet](https://en.bitcoin.it/wiki/Testnet) by passing a custom `api_uri` option on initialization:
70
+ ## Testnet Usage
62
71
 
63
- BitPay::Client.new("myAPIKey", {api_uri: "https://test.bitpay.com/api"})
64
-
65
- Note that in order to pair with testnet, you will need a pairing code from test.bitpay.com and will need to use the bitpay client with the --test option.
72
+ In order to pair with testnet, you will need a pairing code from test.bitpay.com and will need to use the bitpay client with the --test option.
66
73
 
67
74
  ## API Documentation
68
75
 
@@ -75,9 +82,7 @@ The code has been fully code documented, and the latest version is always availa
75
82
 
76
83
  $ bundle install
77
84
  $ bundle exec rake
78
-
79
- In addition to a full test suite, there is Travis integration for MRI 1.9, JRuby and Rubinius.
80
-
85
+ jj
81
86
  ## Found a bug?
82
87
  Let us know! Send a pull request or a patch. Questions? Ask! We're here to help. We will respond to all filed issues.
83
88
 
data/Rakefile CHANGED
@@ -1,45 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
- require 'capybara'
4
- require 'capybara/poltergeist'
5
- require 'mongo'
6
- require 'cucumber'
7
- require 'cucumber/rake/task'
8
3
 
9
4
  require_relative 'config/constants.rb'
10
- require_relative 'config/capybara.rb'
11
5
 
12
6
  RSpec::Core::RakeTask.new(:spec)
13
7
 
14
8
  task :default => :spec
15
9
 
16
- Cucumber::Rake::Task.new(:features) do |t|
17
- t.cucumber_opts = "features --format pretty"
18
- end
19
-
20
10
  desc "Bitpay Tasks"
21
11
  namespace :bitpay do
22
-
23
- desc "Clear all claim codes from the test server."
24
- task :clear_claim_codes do
25
- puts "clearing claim codes"
26
- client = Mongo::MongoClient.new
27
- db = client['bitpay-dev']
28
- coll = db['tokenaccesses']
29
- coll.remove()
30
- puts "claim codes cleared"
31
- end
32
-
33
- desc "Clear rate limiters from local mongo host"
34
- task :clear_rate_limiters do
35
- puts "clearing rate limiters"
36
- client = Mongo::MongoClient.new
37
- db = client['bitpay-dev']
38
- coll = db['ratelimiters']
39
- coll.remove()
40
- puts "rate limiters cleared"
41
- end
42
-
43
12
  desc "Clear local pem and token file"
44
13
  task :clear_local_files do
45
14
  puts "clearing local files"
@@ -50,25 +19,4 @@ namespace :bitpay do
50
19
  File.delete(TOKEN_FILE) if File.file?(TOKEN_FILE)
51
20
  puts "local files cleared"
52
21
  end
53
-
54
- desc "Clear tokens, rate limiters, and local files."
55
- task :clear do
56
- ["bitpay:clear_local_files", "bitpay:clear_rate_limiters", "bitpay:clear_claim_codes"].each{|task| Rake::Task[task].reenable}
57
- ["bitpay:clear_local_files", "bitpay:clear_rate_limiters", "bitpay:clear_claim_codes"].each{|task| Rake::Task[task].invoke}
58
- end
59
-
60
- desc "Run specs and clear claim codes and rate_limiters."
61
- task :spec_clear => ['spec', 'clear_claim_codes', 'clear_rate_limiters']
62
-
63
- desc "Run specs, clear data, run cukes, clear data"
64
- task :tests_clear do
65
- Rake::Task["bitpay:clear"].invoke
66
- Rake::Task["spec"].invoke
67
- Rake::Task["bitpay:clear"].reenable
68
- Rake::Task["bitpay:clear"].invoke
69
- Rake::Task["features"].invoke
70
- Rake::Task["bitpay:clear"].reenable
71
- Rake::Task["bitpay:clear"].invoke
72
- end
73
-
74
22
  end
@@ -28,10 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'pry', '~> 0.10.1'
29
29
  s.add_development_dependency 'pry-byebug', '~> 2.0.0'
30
30
  s.add_development_dependency 'pry-rescue', '~> 1.4.1'
31
- s.add_development_dependency 'capybara', '~> 2.4.3'
32
- s.add_development_dependency 'cucumber', '~> 1.3.17'
33
- s.add_development_dependency 'poltergeist', '~> 1.5.1'
34
31
  s.add_development_dependency 'airborne', '~> 0.0.20'
35
32
  s.add_development_dependency 'rspec', '~> 3.1.0'
36
- s.add_development_dependency 'mongo', '~> 1.11.1'
33
+ s.add_development_dependency 'coveralls'
37
34
  end
data/config/constants.rb CHANGED
@@ -1,5 +1 @@
1
- BITPAY_ROOT = File.expand_path("~") + "./bp/"
2
- ## test constants
3
1
  ROOT_ADDRESS = ENV['RCROOTADDRESS']
4
- TEST_USER = ENV['RCTESTUSER']
5
- TEST_PASS = ENV['RCTESTPASSWORD']
@@ -18,7 +18,7 @@ module BitPay
18
18
 
19
19
  private
20
20
  def get_token_from_response response
21
- ({response["data"][0]["facade"] => response["data"][0]["token"]}).to_json
21
+ ({response[0]["facade"] => response[0]["token"]}).to_json
22
22
  end
23
23
  end
24
24
  end
@@ -3,5 +3,5 @@
3
3
  # or https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
4
4
 
5
5
  module BitPay
6
- VERSION = '2.2.0'
6
+ VERSION = '2.4.0'
7
7
  end
data/spec/client_spec.rb CHANGED
@@ -14,31 +14,9 @@ describe BitPay::Client do
14
14
  let(:claim_code) { "a12bc3d" }
15
15
 
16
16
  before do
17
- allow(BitPay::KeyUtils).to receive(:nonce).and_return('1')
18
17
  stub_request(:get, /#{BitPay::TEST_API_URI}\/tokens.*/).to_return(:status => 200, :body => tokens.to_json, :headers => {})
19
18
  end
20
19
 
21
-
22
- describe "#send_request" do
23
-
24
- context "GET" do
25
- it 'should generate a get request' do
26
- stub_request(:get, /#{BitPay::TEST_API_URI}\/whatever.*/).to_return(:body => '{"awesome": "json"}')
27
- bitpay_client.send_request("GET", "whatever", facade: "merchant")
28
- expect(WebMock).to have_requested(:get, "#{BitPay::TEST_API_URI}/whatever?nonce=1&token=MERCHANTTOKEN")
29
- end
30
- end
31
-
32
- context "POST" do
33
- it 'should generate a post request' do
34
- stub_request(:post, /#{BitPay::TEST_API_URI}.*/).to_return(:body => '{"awesome": "json"}')
35
- bitpay_client.send_request("POST", "whatever", facade: "merchant")
36
- expect(WebMock).to have_requested(:post, "#{BitPay::TEST_API_URI}/whatever")
37
- end
38
- end
39
-
40
- end
41
-
42
20
  describe "#pair_pos_client" do
43
21
  before do
44
22
  stub_const('ENV', {'BITPAY_PEM' => PEM})
@@ -62,48 +40,4 @@ describe BitPay::Client do
62
40
  end
63
41
  end
64
42
 
65
- describe "#create_invoice" do
66
- subject { bitpay_client }
67
- it { is_expected.to respond_to(:create_invoice) }
68
-
69
- describe "should make the call to the server to create an invoice" do
70
- it 'allows numeric input for the price' do
71
- stub_request(:post, /#{BitPay::TEST_API_URI}\/invoices.*/).to_return(:body => '{"data": "awesome"}')
72
- bitpay_client.create_invoice(price: 20.00, currency: "USD")
73
- assert_requested :post, "#{BitPay::TEST_API_URI}/invoices"
74
- end
75
-
76
- it 'allows string input for the price' do
77
- stub_request(:post, /#{BitPay::TEST_API_URI}\/invoices.*/).to_return(:body => '{"data": "awesome"}')
78
- bitpay_client.create_invoice(price: "20.00", currency: "USD")
79
- assert_requested :post, "#{BitPay::TEST_API_URI}/invoices"
80
- end
81
- end
82
-
83
- it 'should pass through the API error message from load_tokens' do
84
- stub_request(:get, /#{BitPay::TEST_API_URI}\/tokens.*/).to_return(status: 500, body: '{"error": "load_tokens_error"}')
85
- expect { bitpay_client.create_invoice(price: 20, currency: "USD") }.to raise_error(BitPay::BitPayError, '500: load_tokens_error')
86
- end
87
-
88
- it 'verifies the validity of the price argument' do
89
- expect { bitpay_client.create_invoice(price: "3,999", currency: "USD") }.to raise_error(BitPay::ArgumentError, 'Illegal Argument: Price must be formatted as a float')
90
- end
91
-
92
- it 'verifies the validity of the currency argument' do
93
- expect { bitpay_client.create_invoice(price: "3999", currency: "UASD") }.to raise_error(BitPay::ArgumentError, 'Illegal Argument: Currency is invalid.')
94
- end
95
- end
96
-
97
- describe '#set_token' do
98
- subject { bitpay_client }
99
- it { is_expected.to respond_to(:set_token) }
100
- it 'sets a token in the client' do
101
-
102
- end
103
- end
104
-
105
- describe "#verify_token" do
106
- subject { bitpay_client }
107
- it { is_expected.to respond_to(:verify_token) }
108
- end
109
43
  end
@@ -2,22 +2,15 @@ require_relative '../spec_helper.rb'
2
2
 
3
3
  describe "pairing a token", javascript: true, type: :feature do
4
4
  let(:claimCode) do
5
- visit ROOT_ADDRESS
6
- click_link('Login')
7
- fill_in 'email', :with => TEST_USER
8
- fill_in 'password', :with => TEST_PASS
9
- click_button('loginButton')
10
- click_link "My Account"
11
- click_link "API Tokens", match: :first
12
- find(".token-access-new-button").find(".btn").find(".icon-plus").click
13
- sleep 0.25
14
- click_button("Add Token")
15
- find(".token-claimcode", match: :first).text
5
+ File.delete(BitPay::TOKEN_FILE_PATH) if File.exists?(BitPay::TOKEN_FILE_PATH)
6
+ client = BitPay::Client.new(api_uri: ROOT_ADDRESS, insecure: true)
7
+ token = client.get(path: "tokens")["data"].select{|tuple| tuple["merchant"]}.first.values.first
8
+ client.post(path: "tokens", token: token, params: {facade: "pos"})["data"][0]["pairingCode"]
16
9
  end
17
- context "when no pem file exists" do
10
+
11
+ context "when a pem file exists" do
18
12
  before do
19
- File.delete(BitPay::PRIVATE_KEY_PATH) if File.exists?(BitPay::PRIVATE_KEY_PATH)
20
- File.delete(BitPay::TOKEN_FILE) if File.exists?(BitPay::TOKEN_FILE)
13
+ sleep(5)
21
14
  `./bin/bitpay pair #{claimCode} --insecure #{ROOT_ADDRESS}`
22
15
  end
23
16
 
@@ -2,9 +2,3 @@
2
2
 
3
3
  export RCROOTADDRESS=$1
4
4
  echo $RCROOTADDRESS
5
- export RCTESTUSER=$2
6
- echo $RCTESTUSER
7
- export RCTESTPASSWORD=$3
8
- echo $RCTESTPASSWORD
9
- export PRIV_KEY=$4
10
- echo $PRIV_KEY
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  require 'webmock/rspec'
2
- require 'pry'
3
- require 'capybara/rspec'
4
- require 'capybara/poltergeist'
2
+ require 'coveralls'
3
+ Coveralls.wear!
5
4
 
6
5
  require File.join File.dirname(__FILE__), '..', 'lib', 'bitpay.rb'
7
6
 
8
7
  require_relative '../config/constants.rb'
9
- require_relative '../config/capybara.rb'
10
8
  #
11
9
  ## Test Variables
12
10
  #
@@ -15,7 +13,6 @@ PEM = "-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEICg7E4NN53YkaWuAwpoqjfAofjzKI7Jq1
15
13
  PUB_KEY = '038d970d6ba29dcfa190c177140fd889fadd6d2590b1ee1a6a06e255dbf22b4017'
16
14
  CLIENT_ID = "TeyN4LPrXiG5t2yuSamKqP3ynVk3F52iHrX"
17
15
 
18
-
19
16
  RSpec.configure do |config|
20
17
  config.before :each do |example|
21
18
  WebMock.allow_net_connect! if example.metadata[:type] == :feature
@@ -23,6 +20,9 @@ RSpec.configure do |config|
23
20
 
24
21
  config.before :all do |example|
25
22
  FileUtils.mkdir_p(BitPay::BITPAY_CREDENTIALS_DIR)
23
+ unless File.exists?(BitPay::PRIVATE_KEY_PATH)
24
+ File.write(BitPay::PRIVATE_KEY_PATH, ENV['BITPAYPEM'].gsub("\\n", "\n"))
25
+ end
26
26
  end
27
27
  end
28
28
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitpay-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitpay, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-07 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitpay-sdk
@@ -150,48 +150,6 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.4.1
153
- - !ruby/object:Gem::Dependency
154
- name: capybara
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: 2.4.3
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: 2.4.3
167
- - !ruby/object:Gem::Dependency
168
- name: cucumber
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: 1.3.17
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: 1.3.17
181
- - !ruby/object:Gem::Dependency
182
- name: poltergeist
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: 1.5.1
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: 1.5.1
195
153
  - !ruby/object:Gem::Dependency
196
154
  name: airborne
197
155
  requirement: !ruby/object:Gem::Requirement
@@ -221,19 +179,19 @@ dependencies:
221
179
  - !ruby/object:Gem::Version
222
180
  version: 3.1.0
223
181
  - !ruby/object:Gem::Dependency
224
- name: mongo
182
+ name: coveralls
225
183
  requirement: !ruby/object:Gem::Requirement
226
184
  requirements:
227
- - - "~>"
185
+ - - ">="
228
186
  - !ruby/object:Gem::Version
229
- version: 1.11.1
187
+ version: '0'
230
188
  type: :development
231
189
  prerelease: false
232
190
  version_requirements: !ruby/object:Gem::Requirement
233
191
  requirements:
234
- - - "~>"
192
+ - - ">="
235
193
  - !ruby/object:Gem::Version
236
- version: 1.11.1
194
+ version: '0'
237
195
  description: Powerful, flexible, lightweight, thread-safe interface to the BitPay
238
196
  developers API
239
197
  email: info@bitpay.com
@@ -250,14 +208,7 @@ files:
250
208
  - Rakefile
251
209
  - bin/bitpay
252
210
  - bitpay-client.gemspec
253
- - config/capybara.rb
254
211
  - config/constants.rb
255
- - features/creating_invoices.feature
256
- - features/pairing.feature
257
- - features/retrieving_invoices.feature
258
- - features/step_definitions/invoice_steps.rb
259
- - features/step_definitions/keygen_steps.rb
260
- - features/step_definitions/step_helpers.rb
261
212
  - lib/bitpay.rb
262
213
  - lib/bitpay/cacert.pem
263
214
  - lib/bitpay/cli.rb
@@ -266,8 +217,6 @@ files:
266
217
  - lib/bitpay/version.rb
267
218
  - spec/client_spec.rb
268
219
  - spec/features/pair_spec.rb
269
- - spec/features/pos_spec.rb
270
- - spec/features/setup_spec.rb
271
220
  - spec/key_utils_spec.rb
272
221
  - spec/set_constants.sh
273
222
  - spec/spec_helper.rb
@@ -291,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
240
  version: 1.3.4
292
241
  requirements: []
293
242
  rubyforge_project: bitpay-client
294
- rubygems_version: 2.2.2
243
+ rubygems_version: 2.4.6
295
244
  signing_key:
296
245
  specification_version: 4
297
246
  summary: Official ruby client library for the BitPay API
data/config/capybara.rb DELETED
@@ -1,5 +0,0 @@
1
- Capybara.javascript_driver = :poltergeist
2
- Capybara.default_driver = :poltergeist
3
- Capybara.register_driver :poltergeist do |app|
4
- Capybara::Poltergeist::Driver.new(app, js_errors: false, phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1'] )
5
- end
@@ -1,26 +0,0 @@
1
- Feature: creating an invoice
2
- The user won't get any money
3
- If they can't
4
- Create Invoices
5
-
6
- Background:
7
- Given the user is authenticated with BitPay
8
-
9
- Scenario Outline: The request is correct
10
- When the user creates an invoice for <price> <currency>
11
- Then they should recieve an invoice in response for <price> <currency>
12
- Examples:
13
- | price | currency |
14
- | "500.23" | "USD" |
15
- | "300.21" | "EUR" |
16
-
17
- Scenario Outline: The invoice contains illegal characters
18
- When the user creates an invoice for <price> <currency>
19
- Then they will receive a BitPay::ArgumentError matching <message>
20
- Examples:
21
- | price | currency | message |
22
- | "50,023" | "USD" | "Price must be formatted as a float" |
23
- | "300.21" | "EaUR" | "Currency is invalid." |
24
- | "" | "USD" | "Price must be formatted as a float" |
25
- | "Ten" | "USD" | "Price must be formatted as a float" |
26
- | "100" | "" | "Currency is invalid." |
@@ -1,21 +0,0 @@
1
- Feature: pairing with bitpay
2
- In order to access bitpay
3
- It is required that the library
4
- Is able to pair successfully
5
-
6
- Scenario: the client has a correct pairing code
7
- Given the user pairs with BitPay with a valid pairing code
8
- Then the user is paired with BitPay
9
-
10
- Scenario Outline: the client has a bad pairing code
11
- Given the user fails to pair with a semantically <valid> code <code>
12
- Then they will receive a <error> matching <message>
13
- Examples:
14
- | valid | code | error | message |
15
- | valid | "a1b2c3d" | BitPay::BitPayError | "500: Unable to create token" |
16
- | invalid | "a1b2c3d4" | BitPay::ArgumentError | "pairing code is not legal" |
17
-
18
- Scenario: the client has a bad port configuration to a closed port
19
- When the fails to pair with BitPay because of an incorrect port
20
- Then they will receive a BitPay::ConnectionError matching "Connection refused"
21
-
@@ -1,7 +0,0 @@
1
- Feature: retrieving an invoice
2
- The user may want to retrieve invoices
3
- So that they can view them
4
-
5
- Scenario: The request is correct
6
- Given that a user knows an invoice id
7
- Then they can retrieve that invoice
@@ -1,26 +0,0 @@
1
- When(/^the user (?:tries to |)creates? an invoice (?:for|without) "(.*?)" (?:or |and |)"(.*?)"$/) do |price, currency|
2
- begin
3
- @response = @client.create_invoice(price: price, currency: currency)
4
- rescue => error
5
- @error = error
6
- end
7
- end
8
-
9
- Then(/^they should recieve an invoice in response for "(.*?)" "(.*?)"$/) do |price, currency|
10
- raise "#{@response['price']} != #{price} or #{@response['currency']} != #{currency}" unless (price == @response['price'].to_s && currency == @response['currency'])
11
- end
12
-
13
- Given(/^there is an invalid token$/) do
14
- pending # express the regexp above with the code you wish you had
15
- end
16
-
17
- Given(/^that a user knows an invoice id$/) do
18
- client = new_paired_client
19
- @id = (client.create_invoice(price: 100, currency: "USD" ))['id']
20
- end
21
-
22
- Then(/^they can retrieve that invoice$/) do
23
- invoice = BitPay::Client.new(api_uri: ROOT_ADDRESS, insecure: true).get_public_invoice(id: @id)
24
- raise "That's the wrong invoice" unless invoice['id'] == @id
25
- end
26
-
@@ -1,51 +0,0 @@
1
- @token = nil
2
- @error = nil
3
-
4
- When(/^the user pairs with BitPay(?: with a valid pairing code|)$/) do
5
- claim_code = get_claim_code_from_server
6
- pem = BitPay::KeyUtils.generate_pem
7
- @client = BitPay::Client.new(api_uri: ROOT_ADDRESS, pem: pem, insecure: true)
8
- @token = @client.pair_pos_client(claim_code)
9
- end
10
-
11
- When(/^the fails to pair with BitPay because of an incorrect port$/) do
12
- pem = BitPay::KeyUtils.generate_pem
13
- address = ROOT_ADDRESS.split(':').slice(0,2).join(':') + ":999"
14
- client = BitPay::Client.new(api_uri: address, pem: pem, insecure: true)
15
- begin
16
- client.pair_pos_client("1ab2c34")
17
- raise "pairing unexpectedly worked"
18
- rescue => error
19
- @error = error
20
- true
21
- end
22
- end
23
-
24
- Given(/^the user is authenticated with BitPay$/) do
25
- @client = new_client_from_stored_values
26
- end
27
-
28
- Given(/^the user is paired with BitPay$/) do
29
- raise "Client is not paired" unless @client.verify_token
30
- end
31
-
32
- Given(/^the user has a bad pairing_code "(.*?)"$/) do |arg1|
33
- # This is a no-op, pairing codes are transient and never actually saved
34
- end
35
-
36
- Then(/^the user fails to pair with a semantically (?:in|)valid code "(.*?)"$/) do |code|
37
- pem = BitPay::KeyUtils.generate_pem
38
- client = BitPay::Client.new(api_uri: ROOT_ADDRESS, pem: pem, insecure: true)
39
- begin
40
- client.pair_pos_client(code)
41
- raise "pairing unexpectedly worked"
42
- rescue => error
43
- @error = error
44
- true
45
- end
46
- end
47
-
48
- Then(/^they will receive an? (.*?) matching "(.*?)"$/) do |error_class, error_message|
49
- raise "Error: #{@error.class}, message: #{@error.message}" unless Object.const_get(error_class) == @error.class && @error.message.include?(error_message)
50
- end
51
-
@@ -1,73 +0,0 @@
1
- require 'capybara/poltergeist'
2
- require 'pry'
3
-
4
- require File.join File.dirname(__FILE__), '..', '..', 'lib', 'bitpay.rb'
5
- require_relative '../../config/constants.rb'
6
- require_relative '../../config/capybara.rb'
7
-
8
- #
9
- ## Test Variables
10
- #
11
- #PEM = "-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEICg7E4NN53YkaWuAwpoqjfAofjzKI7Jq1f532dX+0O6QoAcGBSuBBAAK\noUQDQgAEjZcNa6Kdz6GQwXcUD9iJ+t1tJZCx7hpqBuJV2/IrQBfue8jh8H7Q/4vX\nfAArmNMaGotTpjdnymWlMfszzXJhlw==\n-----END EC PRIVATE KEY-----\n"
12
- #
13
- #PUB_KEY = '038d970d6ba29dcfa190c177140fd889fadd6d2590b1ee1a6a06e255dbf22b4017'
14
- #CLIENT_ID = "TeyN4LPrXiG5t2yuSamKqP3ynVk3F52iHrX"
15
- module BitPay
16
- # Location for API Credentials
17
- BITPAY_CREDENTIALS_DIR = File.join(Dir.home, ".bitpay")
18
- PRIVATE_KEY_FILE = 'bitpay.pem'
19
- PRIVATE_KEY_PATH = File.join(BITPAY_CREDENTIALS_DIR, PRIVATE_KEY_FILE)
20
- TOKEN_FILE = 'tokens.json'
21
- TOKEN_FILE_PATH = File.join(BITPAY_CREDENTIALS_DIR, TOKEN_FILE)
22
- end
23
-
24
- def get_claim_code_from_server
25
- Capybara::visit ROOT_ADDRESS
26
- if logged_in
27
- Capybara::visit "#{ROOT_ADDRESS}/home"
28
- else
29
- log_in
30
- end
31
- Capybara::click_link "My Account"
32
- Capybara::click_link "API Tokens", match: :first
33
- Capybara::find(".token-access-new-button").find(".btn").find(".icon-plus").click
34
- sleep 0.25
35
- Capybara::find_button("Add Token", match: :first).click
36
- Capybara::find(".token-claimcode", match: :first).text
37
- end
38
-
39
- def log_in
40
- Capybara::click_link('Login')
41
- Capybara::fill_in 'email', :with => TEST_USER
42
- Capybara::fill_in 'password', :with => TEST_PASS
43
- Capybara::click_button('loginButton')
44
- end
45
-
46
- def new_paired_client
47
- claim_code = get_claim_code_from_server
48
- pem = BitPay::KeyUtils.generate_pem
49
- client = BitPay::Client.new(api_uri: ROOT_ADDRESS, pem: pem, insecure: true)
50
- client.pair_pos_client(claim_code)
51
- client
52
- end
53
-
54
- def new_client_from_stored_values
55
- if File.file?(BitPay::PRIVATE_KEY_PATH) && File.file?(BitPay::TOKEN_FILE_PATH)
56
- token = get_token_from_file
57
- pem = File.read(BitPay::PRIVATE_KEY_PATH)
58
- BitPay::Client.new(pem: pem, tokens: token, insecure: true, api_uri: ROOT_ADDRESS )
59
- else
60
- claim_code = get_claim_code_from_server
61
- client = BitPay::Client.new(api_uri: ROOT_ADDRESS, insecure: true)
62
- client.pair_pos_client(claim_code)
63
- client
64
- end
65
- end
66
-
67
- def get_token_from_file
68
- token = JSON.parse(File.read(BitPay::TOKEN_FILE_PATH))
69
- end
70
-
71
- def logged_in
72
- Capybara::has_link?('Dashboard')
73
- end
@@ -1,38 +0,0 @@
1
- require_relative '../spec_helper.rb'
2
-
3
- describe "create an invoice", javascript: true, type: :feature do
4
- before :all do
5
- WebMock.allow_net_connect!
6
- get_claim_code = -> {
7
- visit ROOT_ADDRESS
8
- click_link('Login')
9
- fill_in 'email', :with => TEST_USER
10
- fill_in 'password', :with => TEST_PASS
11
- click_button('loginButton')
12
- click_link "My Account"
13
- click_link "API Tokens", match: :first
14
- find(".token-access-new-button").find(".btn").click
15
- sleep 0.25
16
- click_button("Add Token")
17
- find(".token-claimcode", match: :first).text
18
- }
19
- set_client = -> {
20
- client = BitPay::Client.new(api_uri: ROOT_ADDRESS, pem: PEM, insecure: true)
21
- client.pair_pos_client(get_claim_code.call)
22
- client
23
- }
24
- @client ||= set_client.call
25
- @invoice_id ||= SecureRandom.uuid
26
- @price ||= (100..150).to_a.sample
27
- @invoice = @client.create_invoice(currency: "USD", price: @price)
28
- end
29
-
30
- it "should create an invoice" do
31
- expect(@invoice["status"]).to eq "new"
32
- end
33
-
34
- it "should be able to retrieve an invoice" do
35
- expect(@client.get_public_invoice(id: @invoice['id'])["price"]).to eq @price
36
- end
37
- end
38
-
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- context 'local variables' do
4
- it "should find the root address" do
5
- expect(ROOT_ADDRESS).not_to be_nil
6
- end
7
- it "should find the user" do
8
- expect(TEST_USER).not_to be_nil
9
- end
10
- it "should find the user" do
11
- expect(TEST_PASS).not_to be_nil
12
- end
13
- end