bpruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +108 -0
- data/Rakefile +2 -0
- data/bin/bpruby +7 -0
- data/bpruby.gemspec +18 -0
- data/lib/bpruby.rb +86 -0
- data/lib/bpruby/bplib.rb +49 -0
- data/lib/bpruby/version.rb +3 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Bpruby
|
2
|
+
|
3
|
+
This Gem is for making easy Api-Calls to the Bitpay.com Payment Api.
|
4
|
+
It currently supports Creating an Invoice and getting the Status of an Invoice.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'bpruby'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install bpruby
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
|
23
|
+
There are two methods available :
|
24
|
+
|
25
|
+
#createInvoice(apikey,price,orderId,posData,options={})
|
26
|
+
|
27
|
+
#Example Call : Bpruby::Bplib.createInvoice(
|
28
|
+
'XXXXAPIKEYHERE',
|
29
|
+
15.40,
|
30
|
+
'333',
|
31
|
+
'230928307203',
|
32
|
+
:transactionSpeed => 'high',
|
33
|
+
:itemDesc =>'Test',
|
34
|
+
:currency => 'USD',
|
35
|
+
:buyerEmail =>'test@bitpay.com',
|
36
|
+
:buyerAddress1 =>'On the',
|
37
|
+
:buyerAddress2 =>'Teststreet')
|
38
|
+
|
39
|
+
Required Parameters :
|
40
|
+
|
41
|
+
- Api-Key : Obtainable in your Bitpay Merchant Account
|
42
|
+
- Price : This is the amount that is required to be collected from the
|
43
|
+
buyer. Note, if this is specified in a currency other than BTC,
|
44
|
+
the price will be converted into BTC at market exchange
|
45
|
+
rates to determine the amount collected from the buyer.
|
46
|
+
- orderID : Used to display an orderID to the buyer. In the account
|
47
|
+
summary view, this value is used to identify a ledger entry if
|
48
|
+
present.
|
49
|
+
- posData : This content of this field is included in status updates or
|
50
|
+
requests to get an invoice. It is intended to be used by
|
51
|
+
the merchant to uniquely identify an order associated with
|
52
|
+
an invoice in their system. Aside from that, Bit-Pay does
|
53
|
+
not use the data in this field. The data in this field can be
|
54
|
+
anything that is meaningful to the merchant
|
55
|
+
|
56
|
+
-Parameters that are required but are already set to a default :
|
57
|
+
|
58
|
+
-:currency => BTC ,can be overwritten if needed. Currently BTC and USD supported. Get more infos from Bitpay.
|
59
|
+
|
60
|
+
-Optional Parameters :
|
61
|
+
|
62
|
+
-:itemDesc ,:itemCode, :notificationEmail, :notificationURL, :redirectURL,
|
63
|
+
-:currency, :physical, :fullNotifications, :transactionSpeed, :buyerName,
|
64
|
+
-:buyerAddress1, :buyerAddress2, :buyerCity, :buyerState, :buyerZip, :buyerEmail, :buyerPhone
|
65
|
+
|
66
|
+
-The Method returns a Json-Object with the following Information :
|
67
|
+
|
68
|
+
-id : The unique id of the invoice.
|
69
|
+
-url : An https URL where the invoice can be viewed.
|
70
|
+
-posData : A data field provided by the merchant and designed to be used by the merchant to
|
71
|
+
-correlate : the invoice with an order or other object in their system.
|
72
|
+
-status : The current invoice status. The possible states are described earlier in this document.
|
73
|
+
-btcPrice : The amount of bitcoins being requested for payment of this invoice (same as the price if
|
74
|
+
the merchant set the price in BTC).
|
75
|
+
-price : The price set by the merchant (in terms of the provided currency).
|
76
|
+
-currency : The 3 letter currency code in which the invoice was priced.
|
77
|
+
-invoiceTime : The time the invoice was created in milliseconds since midnight January 1, 1970.
|
78
|
+
-expirationTime : The time at which the invoice expires and no further payment will be accepted (in
|
79
|
+
-milliseconds : since midnight January 1, 1970). Currently, all invoices are valid for 15
|
80
|
+
minutes.
|
81
|
+
-currentTime : The current time on the Bit-Pay.com system (by subtracting the current time from the
|
82
|
+
-expiration : time, the amount of time remaining for payment can be determined).
|
83
|
+
|
84
|
+
More Information about Parameters and calls : https://bitpay.com/help-api
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
#getInvoice(apikey,invoiceID)
|
89
|
+
|
90
|
+
#example call : Bpruby::Bplib.getInvoice('XXXXXXXXXXYOURAPIKEYHERE','T11zE6Xmoz4rK1qq5ktalduPTUO9C9V9NN-BBEpv58o=')
|
91
|
+
|
92
|
+
To get the current state of an invoice, an http GET request can be sent to https://bitpay.com/api/invoice/
|
93
|
+
<id> where the id is the invoice id provided when the invoice was created. The format of the response is
|
94
|
+
exactly the same as that which is returned when creating an invoice.
|
95
|
+
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
1. Fork it
|
100
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
101
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
102
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
103
|
+
5. Create new Pull Request
|
104
|
+
|
105
|
+
## About me :
|
106
|
+
|
107
|
+
I am a Ruby Newbie and i like to try ideas. If i have fundamental flaws or when i'm missing best practices please tell me , i am eager to learn !
|
108
|
+
|
data/Rakefile
ADDED
data/bin/bpruby
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bpruby'
|
4
|
+
|
5
|
+
puts Bpruby::Bplib.createInvoice('JRcbOrlCYNhMFDfYygX3NSHypUibMZzC59v15P95AQg',0.14,'45','85',:transactionSpeed => 'high',:itemDesc =>'Test',:currency => 'USD',:buyerEmail =>'gekuesst@googlemail.com',:buyerAddress1 =>'Hinterm',:buyerAddress2 =>'Testheim')
|
6
|
+
|
7
|
+
puts Bpruby::Bplib.getInvoice('JRcbOrlCYNhMFDfYygX3NSHypUibMZzC59v15P95AQg','T11zE6Xmoz4rK1qq5ktalduPTUO9C9V9NN-BBEpv58o=')
|
data/bpruby.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bpruby/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Phantastisch"]
|
6
|
+
gem.email = ["gekuesst@googlemail.com"]
|
7
|
+
gem.description = %q{Bitpay for Ruby}
|
8
|
+
gem.summary = %q{Easy Bitpay-Api Calls for Ruby}
|
9
|
+
gem.homepage = "https://github.com/phanaster/BP-for-Ruby"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "bpruby"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Bpruby::VERSION
|
17
|
+
gem.add_dependency "rest-client"
|
18
|
+
end
|
data/lib/bpruby.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "bpruby/version"
|
2
|
+
|
3
|
+
|
4
|
+
module Bpruby
|
5
|
+
class Bplib
|
6
|
+
require 'rest-client'
|
7
|
+
|
8
|
+
=begin
|
9
|
+
Required Parameters :
|
10
|
+
|
11
|
+
- Api-Key : Obtainable in your Bitpay Merchant Account
|
12
|
+
- Price : This is the amount that is required to be collected from the
|
13
|
+
buyer. Note, if this is specified in a currency other than BTC,
|
14
|
+
the price will be converted into BTC at market exchange
|
15
|
+
rates to determine the amount collected from the buyer.
|
16
|
+
- orderID : Used to display an orderID to the buyer. In the account
|
17
|
+
summary view, this value is used to identify a ledger entry if
|
18
|
+
present.
|
19
|
+
- posData : This content of this field is included in status updates or
|
20
|
+
requests to get an invoice. It is intended to be used by
|
21
|
+
the merchant to uniquely identify an order associated with
|
22
|
+
an invoice in their system. Aside from that, Bit-Pay does
|
23
|
+
not use the data in this field. The data in this field can be
|
24
|
+
anything that is meaningful to the merchant
|
25
|
+
|
26
|
+
Parameters that are required but are already set to a default :
|
27
|
+
|
28
|
+
:currency => BTC ,can be overwritten if needed. Currently BTC and USD supported. Get more infos from Bitpay.
|
29
|
+
|
30
|
+
Optional Parameters :
|
31
|
+
|
32
|
+
:itemDesc ,:itemCode, :notificationEmail, :notificationURL, :redirectURL,
|
33
|
+
:currency, :physical, :fullNotifications, :transactionSpeed, :buyerName,
|
34
|
+
:buyerAddress1, :buyerAddress2, :buyerCity, :buyerState, :buyerZip, :buyerEmail, :buyerPhone
|
35
|
+
|
36
|
+
The Method returns a Json-Object with the following Information :
|
37
|
+
|
38
|
+
id : The unique id of the invoice.
|
39
|
+
url : An https URL where the invoice can be viewed.
|
40
|
+
posData : A data field provided by the merchant and designed to be used by the merchant to
|
41
|
+
correlate : the invoice with an order or other object in their system.
|
42
|
+
status : The current invoice status. The possible states are described earlier in this document.
|
43
|
+
btcPrice : The amount of bitcoins being requested for payment of this invoice (same as the price if
|
44
|
+
the merchant set the price in BTC).
|
45
|
+
price : The price set by the merchant (in terms of the provided currency).
|
46
|
+
currency : The 3 letter currency code in which the invoice was priced.
|
47
|
+
invoiceTime : The time the invoice was created in milliseconds since midnight January 1, 1970.
|
48
|
+
expirationTime : The time at which the invoice expires and no further payment will be accepted (in
|
49
|
+
milliseconds : since midnight January 1, 1970). Currently, all invoices are valid for 15
|
50
|
+
minutes.
|
51
|
+
currentTime : The current time on the Bit-Pay.com system (by subtracting the current time from the
|
52
|
+
expiration : time, the amount of time remaining for payment can be determined).
|
53
|
+
|
54
|
+
More Information about Parameters and calls : https://bitpay.com/help-api
|
55
|
+
|
56
|
+
=end
|
57
|
+
|
58
|
+
def self.createInvoice(apikey,price,orderId,posData,options={})
|
59
|
+
|
60
|
+
defaultoptions ||= {
|
61
|
+
:currency => 'BTC' ,
|
62
|
+
:physical => 'true',
|
63
|
+
:fullNotifications => 'true',
|
64
|
+
:transactionSpeed => 'low',
|
65
|
+
}
|
66
|
+
|
67
|
+
options = defaultoptions.merge(options)
|
68
|
+
options[:price] = price
|
69
|
+
options[:orderId]= orderId
|
70
|
+
options[:posData]= posData
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
response = RestClient.post "https://#{apikey}:@bitpay.com/api/invoice", options, :content_type => :json, :accept => :json
|
76
|
+
return response
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def self.getInvoice(apikey,invoiceId)
|
81
|
+
|
82
|
+
response = RestClient.get "http://#{apikey}:@bitpay.com/api/invoice/#{invoiceId}", :content_type => :json, :accept => :json
|
83
|
+
return response
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/bpruby/bplib.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module BPRUBY
|
2
|
+
class BPLIB
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
def bpCreateInvoice(price,orderid,posData,options={})
|
10
|
+
|
11
|
+
|
12
|
+
@options ||= {
|
13
|
+
'currency' => 'BTC' ,
|
14
|
+
'notificationEmail' => '',
|
15
|
+
'notificationURL' => '',
|
16
|
+
'redirectURL' => '',
|
17
|
+
'physical' => 'true',
|
18
|
+
'fullNotifications' => 'true',
|
19
|
+
'transactionSpeed' => 'low',
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
options = @options.merge(options)
|
25
|
+
options[:price] = price
|
26
|
+
options[:orderId]= orderid
|
27
|
+
options[:posData]= posData
|
28
|
+
|
29
|
+
|
30
|
+
postOptions = ['orderID', 'itemDesc', 'itemCode', 'notificationEmail', 'notificationURL', 'redirectURL',
|
31
|
+
'posData', 'price', 'currency', 'physical', 'fullNotifications', 'transactionSpeed', 'buyerName',
|
32
|
+
'buyerAddress1', 'buyerAddress2', 'buyerCity', 'buyerState', 'buyerZip', 'buyerEmail', 'buyerPhone']
|
33
|
+
|
34
|
+
postOptions.each_with_index do |opt,index|
|
35
|
+
if options.include(opt[index])
|
36
|
+
postdata[index] = options[index]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
postdata = {}
|
43
|
+
|
44
|
+
|
45
|
+
response = RestClient.post "https://JRcbOrlCYNhMFDfYygX3NSHypUibMZzC59v15P95AQg:@bitpay.com/api/invoice", postdata, :content_type => :json, :accept => :json
|
46
|
+
return response
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bpruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Phantastisch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Bitpay for Ruby
|
31
|
+
email:
|
32
|
+
- gekuesst@googlemail.com
|
33
|
+
executables:
|
34
|
+
- bpruby
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/bpruby
|
44
|
+
- bpruby.gemspec
|
45
|
+
- lib/bpruby.rb
|
46
|
+
- lib/bpruby/bplib.rb
|
47
|
+
- lib/bpruby/version.rb
|
48
|
+
homepage: https://github.com/phanaster/BP-for-Ruby
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.24
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Easy Bitpay-Api Calls for Ruby
|
72
|
+
test_files: []
|