coinjar-checkout 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/coinjar-checkout.gemspec +26 -0
- data/lib/coinjar-checkout.rb +20 -0
- data/lib/coinjar-checkout/client.rb +43 -0
- data/lib/coinjar-checkout/configuration.rb +29 -0
- data/lib/coinjar-checkout/ipn.rb +27 -0
- data/lib/coinjar-checkout/order.rb +58 -0
- data/lib/coinjar-checkout/version.rb +3 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: deab522795720037d35e7b21abd55b6e2c62ba4d
|
4
|
+
data.tar.gz: a1c4310222c0c6fa3e56fa402d38ef821109a68e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f3ab0adc8d649dfa06714d3bd27f999e86ee2856507f0d21e0f4cd0351dd6b57fe0caac604f4cf5086c20a5344dcebb89c9ab7921a7752e1345a9ca15e1b043
|
7
|
+
data.tar.gz: fe6bb393ad0ab6bdb3c490008161b6592679b616541d80b29390d76bca513915a76e8ab6563ba23d0951ed68ff6395dbc0a966e899a13d95baaf7c5252f7be1b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Zhou Tong
|
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,29 @@
|
|
1
|
+
# Coinjar::Checkout::Ruby
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'coinjar-checkout-ruby'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install coinjar-checkout-ruby
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coinjar-checkout/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coinjar-checkout"
|
8
|
+
spec.version = CoinJarCheckout::VERSION
|
9
|
+
spec.authors = ["CoinJar Pty Ltd", "Ryan Zhou", "Jerrold Poh"]
|
10
|
+
spec.email = ["info@coinjar.io"]
|
11
|
+
spec.description = ["Official Ruby gem for CoinJar Checkout."]
|
12
|
+
spec.summary = ["CoinJar Checkout removes the hassles of accepting digital payments for online merchants."]
|
13
|
+
spec.homepage = "https://coinjar.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "rest-client"
|
24
|
+
spec.add_runtime_dependency "multi_json"
|
25
|
+
spec.add_runtime_dependency "activesupport"
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
require "coinjar-checkout/version"
|
6
|
+
require "coinjar-checkout/configuration"
|
7
|
+
require "coinjar-checkout/client"
|
8
|
+
require "coinjar-checkout/order"
|
9
|
+
require "coinjar-checkout/ipn"
|
10
|
+
|
11
|
+
module CoinJarCheckout
|
12
|
+
extend Configuration
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def client
|
16
|
+
@client = CoinJarCheckout::Client.new unless defined?(@client) && @client.hash == config_options.hash
|
17
|
+
@client
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module CoinJarCheckout
|
2
|
+
class Client
|
3
|
+
|
4
|
+
attr_accessor *Configuration::VALID_CONFIG_KEYS, :root_resource
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
merged_options = CoinJarCheckout.config_options.merge(options)
|
8
|
+
Configuration::VALID_CONFIG_KEYS.each do |key|
|
9
|
+
send("#{key}=", merged_options[key])
|
10
|
+
end
|
11
|
+
@root_resource = RestClient::Resource.new(endpoint, user: uuid, password: secret)
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(path, payload)
|
15
|
+
parse url(path).post(payload)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(path, params = nil)
|
19
|
+
parse url(path).get(:params => params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def put(path, payload)
|
23
|
+
parse url(path).put(payload)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(path)
|
27
|
+
parse url(path).delete
|
28
|
+
end
|
29
|
+
|
30
|
+
def patch(path, payload)
|
31
|
+
parse url(path).patch(payload)
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse(response)
|
35
|
+
MultiJson.load(response, :symbolize_keys => true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def url(path)
|
39
|
+
root_resource["#{path}.#{format}"]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CoinJarCheckout
|
2
|
+
module Configuration
|
3
|
+
VALID_CONFIG_KEYS = [:uuid, :secret, :endpoint, :format]
|
4
|
+
|
5
|
+
DEFAULT_ENDPOINT = 'https://checkout.coinjar.io/api/v1'
|
6
|
+
DEFAULT_UUID = nil
|
7
|
+
DEFAULT_SECRET = nil
|
8
|
+
DEFAULT_FORMAT = :json
|
9
|
+
|
10
|
+
attr_accessor *VALID_CONFIG_KEYS
|
11
|
+
|
12
|
+
# Make sure we have the default values set when we get 'extended'
|
13
|
+
def self.extended(base)
|
14
|
+
base.reset
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset
|
18
|
+
self.endpoint = DEFAULT_ENDPOINT
|
19
|
+
self.uuid = DEFAULT_UUID
|
20
|
+
self.secret = DEFAULT_SECRET
|
21
|
+
self.format = DEFAULT_FORMAT
|
22
|
+
end
|
23
|
+
|
24
|
+
def config_options
|
25
|
+
Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CoinJarCheckout
|
2
|
+
class IPN
|
3
|
+
|
4
|
+
attr_accessor :uuid, :status, :amount, :fee, :currency, :bitcoin_amount, :bitcoin_address, :merchant_reference, :merchant_invoice, :ipn_digest
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
reset(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def verify
|
11
|
+
ipn_digest == Digest::SHA256.new.hexdigest("#{uuid}#{amount}#{currency}#{status}#{CoinJarCheckout.secret}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch_order
|
15
|
+
CoinJarCheckout::Order.find(uuid)
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset(args)
|
19
|
+
args.each do |k,v|
|
20
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
21
|
+
end
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module CoinJarCheckout
|
2
|
+
class Order
|
3
|
+
|
4
|
+
attr_accessor :uuid, :order_items, :bitcoin_address, :amount, :currency, :merchant_reference, :merchant_invoice, :return_url, :cancel_url, :notify_url, :fee, :status, :created_at, :updated_at, :expires_at
|
5
|
+
|
6
|
+
def initialize(args = {})
|
7
|
+
reset(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
response = CoinJarCheckout.client.post("orders", { order: self.order_params, "order[order_items_attributes][]" => self.order_items })
|
12
|
+
self.reset response[:order]
|
13
|
+
end
|
14
|
+
|
15
|
+
def order_params
|
16
|
+
params = self.instance_values
|
17
|
+
params.delete("order_items")
|
18
|
+
params
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_payment
|
22
|
+
response = CoinJarCheckout.client.post("orders/#{uuid}/check_payment", nil)
|
23
|
+
self.reset response[:order]
|
24
|
+
end
|
25
|
+
|
26
|
+
def requote
|
27
|
+
response = CoinJarCheckout.client.post("orders/#{uuid}/requote", nil)
|
28
|
+
self.reset response[:order]
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch
|
32
|
+
response = CoinJarCheckout.client.get("orders/" + uuid)
|
33
|
+
self.reset response[:order]
|
34
|
+
end
|
35
|
+
|
36
|
+
def payment_url
|
37
|
+
uri = URI(CoinJarCheckout.endpoint)
|
38
|
+
"#{uri.scheme}://#{uri.host}/orders/#{uuid}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.find(uuid)
|
42
|
+
order = self.new(uuid: uuid)
|
43
|
+
order.fetch
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.list(offset = 0, limit = 100)
|
47
|
+
CoinJarCheckout.client.get("orders", { offset: offset, limit: limit })[:orders].map { |o| self.new o }
|
48
|
+
end
|
49
|
+
|
50
|
+
def reset(args)
|
51
|
+
args.each do |k,v|
|
52
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
53
|
+
end
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coinjar-checkout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CoinJar Pty Ltd
|
8
|
+
- Ryan Zhou
|
9
|
+
- Jerrold Poh
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.3'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rest-client
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: multi_json
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: activesupport
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
description: '["Official Ruby gem for CoinJar Checkout."]'
|
86
|
+
email:
|
87
|
+
- info@coinjar.io
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- coinjar-checkout.gemspec
|
98
|
+
- lib/coinjar-checkout.rb
|
99
|
+
- lib/coinjar-checkout/client.rb
|
100
|
+
- lib/coinjar-checkout/configuration.rb
|
101
|
+
- lib/coinjar-checkout/ipn.rb
|
102
|
+
- lib/coinjar-checkout/order.rb
|
103
|
+
- lib/coinjar-checkout/version.rb
|
104
|
+
homepage: https://coinjar.io
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.0.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: '["CoinJar Checkout removes the hassles of accepting digital payments for
|
128
|
+
online merchants."]'
|
129
|
+
test_files: []
|