quickpay-ruby-client 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -9
- data/.travis.yml +6 -2
- data/CHANGELOG.md +10 -12
- data/README.md +62 -34
- data/lib/quickpay/api/client.rb +47 -23
- data/lib/quickpay/api/error.rb +52 -0
- data/lib/quickpay/api/{errors/conflict.rb → version.rb} +1 -3
- data/quickpay-ruby-client.gemspec +7 -10
- metadata +14 -71
- data/.rspec +0 -2
- data/lib/quickpay.rb +0 -4
- data/lib/quickpay/api/errors.rb +0 -10
- data/lib/quickpay/api/errors/bad_request.rb +0 -7
- data/lib/quickpay/api/errors/forbidden.rb +0 -7
- data/lib/quickpay/api/errors/method_not_allowed.rb +0 -7
- data/lib/quickpay/api/errors/not_acceptable.rb +0 -7
- data/lib/quickpay/api/errors/not_found.rb +0 -7
- data/lib/quickpay/api/errors/payment_required.rb +0 -7
- data/lib/quickpay/api/errors/quickpay_error.rb +0 -13
- data/lib/quickpay/api/errors/server_error.rb +0 -7
- data/lib/quickpay/api/errors/unauthorized.rb +0 -7
- data/lib/quickpay/api/request.rb +0 -98
- data/lib/quickpay/constants.rb +0 -21
- data/lib/quickpay/logger.rb +0 -16
- data/lib/quickpay/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5cbbfa5f7a1d0ecd4004ed342f9be6c117685ac
|
4
|
+
data.tar.gz: 1e57b8ce8cfb0e37faffc843286d65ddad532e64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e1e75a6652268e6343461d4b2e861a3d83f603c721582ca16f919c3cccaee29520384bbad883ef4a896487a40e022c6506ceb683247c0af41cc54c914ba9137
|
7
|
+
data.tar.gz: 76788896e3ff36f96a8e47bcea140b943ece98e6262dd418fa97225d6619a7e41f4f80775250c8212910f14585636ebad5bc321807d13685a2612dd815130a2a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.1.
|
3
|
+
- 2.1.10
|
4
|
+
- 2.2.10
|
5
|
+
- 2.3.7
|
6
|
+
- 2.4.4
|
7
|
+
- 2.5.1
|
4
8
|
cache: bundler
|
5
|
-
script: bundle exec
|
9
|
+
script: bundle exec ruby test/client.rb
|
6
10
|
notifications:
|
7
11
|
slack:
|
8
12
|
secure: SixeTgiVsOaeWyKwICxLJ0GLN/C9j6qW1ZdaEytIDuZaBAn9oArrRGkJiehFdlzcPUHwzMWC0vl9GQzyBhZ7dbq+B53QY1mH9LTb9A53Y2d1OO1kBjJAkC5Yprvpjm52+x889Dwlz0bfLETvLsC2ej0NZDvSSLKFjpZZIZMOWkg=
|
data/CHANGELOG.md
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
4
3
|
## Unreleased
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
(your contribution here)
|
5
|
+
## v2.0.0
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
(
|
7
|
+
* This is a total rewrite and while the code is cleaner, simpler and faster, it does present some **breaking changes compared to v1.X.X**:
|
8
|
+
* The client now accepts arguements `username` instead of `password` and `api_key` has been removed. To authenticate with an API key, simply set `password: <key>` and omit username.
|
9
|
+
* The request methods now accepts request body as an named option (`client.post(<endpoint>, body: { amount: 100 })`) rather than a hash of body params (`client.post(<endpoint>, amount: 100)`).
|
10
|
+
* Replace the following dependencies - which reduces the total number of dependencies to 5 (was 27):
|
11
|
+
* HTTParty => Excon (https://github.com/excon/excon) - which luckily means no more partying hard.
|
12
|
+
* Rspec => Minitest
|
13
13
|
|
14
14
|
## v1.2.0 (2016-10-25)
|
15
15
|
|
16
|
-
|
16
|
+
* Can now HEAD (https://github.com/QuickPay/quickpay-ruby-client/pull/21)
|
17
17
|
|
18
18
|
## v1.1.0 (2016-01-11)
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
- Send options to the underlaying HTTParty (https://github.com/QuickPay/quickpay-ruby-client/pull/16)
|
23
|
-
- Be able to upload files (https://github.com/QuickPay/quickpay-ruby-client/pull/17<Paste>)
|
20
|
+
* Send options to the underlaying HTTParty (https://github.com/QuickPay/quickpay-ruby-client/pull/16)
|
21
|
+
* Be able to upload files (https://github.com/QuickPay/quickpay-ruby-client/pull/17<Paste>)
|
data/README.md
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# QuickPay::API::Client
|
2
|
+
|
3
3
|
[![Build Status](https://travis-ci.org/QuickPay/quickpay-ruby-client.svg)](https://travis-ci.org/QuickPay/quickpay-ruby-client)
|
4
4
|
|
5
|
-
`quickpay-ruby-client` is a official client for [QuickPay API](http://tech.quickpay.net/api). The Quickpay API enables you to accept payments in a secure and reliable manner.
|
5
|
+
The `quickpay-ruby-client` gem is a official client for [QuickPay API](http://tech.quickpay.net/api). The Quickpay API enables you to accept payments in a secure and reliable manner.
|
6
|
+
|
7
|
+
This gem currently support QuickPay `v10` api.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add to your Gemfile
|
10
|
-
|
11
|
-
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "quickpay-ruby-client"
|
15
|
+
```
|
12
16
|
|
13
17
|
or install from Rubygems:
|
14
|
-
|
15
|
-
|
18
|
+
|
19
|
+
```
|
20
|
+
$ gem install quickpay-ruby-client
|
21
|
+
```
|
16
22
|
|
17
23
|
It is currently tested with Ruby ( >= 2.1.x)
|
18
24
|
|
@@ -25,59 +31,79 @@ Before doing anything you should register yourself with QuickPay and get access
|
|
25
31
|
|
26
32
|
### Create a new API client
|
27
33
|
|
28
|
-
First you should create a client instance that is anonymous or authorized with
|
34
|
+
First you should create a client instance that is anonymous or authorized with your API key or login credentials provided by QuickPay.
|
29
35
|
|
30
36
|
To initialise an anonymous client:
|
31
37
|
|
32
|
-
```
|
33
|
-
require
|
38
|
+
```ruby
|
39
|
+
require "quickpay/api/client"
|
34
40
|
client = QuickPay::API::Client.new
|
35
41
|
```
|
36
42
|
|
37
|
-
To initialise a client with QuickPay
|
43
|
+
To initialise a client with QuickPay API Key:
|
38
44
|
|
39
|
-
```
|
40
|
-
require
|
41
|
-
client = QuickPay::API::Client.new(
|
45
|
+
```ruby
|
46
|
+
require "quickpay/api/client"
|
47
|
+
client = QuickPay::API::Client.new(password: ENV["QUICKPAY_API_KEY"])
|
42
48
|
```
|
43
49
|
|
44
50
|
Or you can provide login credentials like:
|
45
51
|
|
46
|
-
```
|
47
|
-
require
|
48
|
-
client = QuickPay::API::Client.new(
|
52
|
+
```ruby
|
53
|
+
require "quickpay/api/client"
|
54
|
+
client = QuickPay::API::Client.new(username: ENV["QUICKPAY_LOGIN"], password: ENV["QUICKPAY_PASSWORD"])
|
49
55
|
```
|
50
56
|
|
51
|
-
|
57
|
+
You can also set some connection specific options (default values shown):
|
52
58
|
|
53
|
-
```
|
54
|
-
client = Quickpay::API::Client.new(
|
55
|
-
|
59
|
+
```ruby
|
60
|
+
client = Quickpay::API::Client.new(
|
61
|
+
read_timeout: 60,
|
62
|
+
write_timeout: 60,
|
63
|
+
connect_timeout: 60,
|
64
|
+
)
|
56
65
|
```
|
57
66
|
|
58
67
|
|
59
|
-
###
|
68
|
+
### Sending request
|
60
69
|
|
61
|
-
You can afterwards call any method described in QuickPay
|
70
|
+
You can afterwards call any method described in QuickPay API with corresponding http method and endpoint. These methods are supported currently: `get`, `post`, `put`, `patch`, `delete` and `head`.
|
62
71
|
|
63
|
-
```
|
72
|
+
```ruby
|
64
73
|
client.get("/activity").each do |activity|
|
65
74
|
puts activity["id"]
|
66
75
|
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Beyond the endpoint, the client accepts the following options (default values shown):
|
79
|
+
|
80
|
+
* `body: ""`
|
81
|
+
* `headers: {}`
|
82
|
+
* `query: {}`
|
83
|
+
* `raw: false`
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
response = client.post(
|
87
|
+
"/payments/1/capture",
|
88
|
+
body: { amount: 100 }.to_json,
|
89
|
+
headers: { "Content-Type" => "application/json" },
|
90
|
+
query: { "synchronized" => "" }
|
91
|
+
raw: false
|
92
|
+
)
|
67
93
|
|
68
94
|
```
|
69
95
|
|
70
96
|
If you want raw http response, headers Please add `:raw => true` parameter:
|
71
97
|
|
72
|
-
```
|
73
|
-
status, body, headers = client.get("/activity", :
|
98
|
+
```ruby
|
99
|
+
status, body, headers = client.get("/activity", raw: true)
|
74
100
|
|
75
101
|
if status == 200
|
76
102
|
JSON.parse(body).each do |activity|
|
77
103
|
puts activity["id"]
|
78
104
|
end
|
79
105
|
else
|
80
|
-
|
106
|
+
# do something else
|
81
107
|
end
|
82
108
|
|
83
109
|
```
|
@@ -98,26 +124,28 @@ Response status | Error |
|
|
98
124
|
`406` | `QuickPay::API::NotAcceptable`
|
99
125
|
`409` | `QuickPay::API::Conflict`
|
100
126
|
`500` | `QuickPay::API::ServerError`
|
127
|
+
`502` | `QuickPay::API::BadGateway`
|
128
|
+
`503` | `QuickPay::API::ServiceUnavailable`
|
129
|
+
`504` | `QuickPay::API::GatewayTimeout`
|
101
130
|
|
102
131
|
All exceptions inherits `QuickPay::API::Error`, so you can listen for any api error like:
|
103
132
|
|
104
|
-
```
|
133
|
+
```ruby
|
105
134
|
begin
|
106
|
-
client.post("/payments", :
|
107
|
-
...
|
135
|
+
client.post("/payments", body: { currency: "DKK", order_id: "1212" })
|
108
136
|
rescue QuickPay::API::Error => e
|
109
137
|
puts e.body
|
110
138
|
end
|
111
139
|
```
|
112
140
|
|
113
|
-
You can read more about
|
141
|
+
You can read more about QuickPay API responses at [http://tech.quickpay.net/api/](http://tech.quickpay.net/api).
|
114
142
|
|
115
143
|
## Contributions
|
116
144
|
|
117
145
|
To contribute:
|
118
146
|
|
119
|
-
1. Write a
|
120
|
-
2. Fix
|
147
|
+
1. Write a test that fails
|
148
|
+
2. Fix test by adding/changing code
|
121
149
|
3. Add feature or bugfix to changelog in the "Unreleased" section
|
122
150
|
4. Submit a pull request
|
123
151
|
5. World is now a better place! :)
|
@@ -125,5 +153,5 @@ To contribute:
|
|
125
153
|
### Running the specs
|
126
154
|
|
127
155
|
```
|
128
|
-
bundle exec
|
156
|
+
$ bundle exec ruby test/client.rb
|
129
157
|
```
|
data/lib/quickpay/api/client.rb
CHANGED
@@ -1,34 +1,58 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "excon"
|
2
|
+
require "json"
|
3
|
+
require "quickpay/api/error"
|
4
|
+
require "quickpay/api/version"
|
4
5
|
|
5
6
|
module QuickPay
|
6
|
-
class << self
|
7
|
-
attr_accessor :base_uri
|
8
|
-
end
|
9
|
-
|
10
7
|
module API
|
11
8
|
class Client
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
opts[:base_uri] ||= (QuickPay.base_uri || QuickPay::BASE_URI)
|
9
|
+
DEFAULT_HEADERS = {
|
10
|
+
"User-Agent" => "quickpay-ruby-client, v#{QuickPay::API::VERSION}",
|
11
|
+
"Accept-Version" => "v10"
|
12
|
+
}.freeze
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
def initialize(username: nil, password: nil, base_uri: "https://api.quickpay.net", options: {})
|
15
|
+
opts = {
|
16
|
+
read_timeout: options.fetch(:read_timeout, 60),
|
17
|
+
write_timeout: options.fetch(:write_timeout, 60),
|
18
|
+
connect_timeout: options.fetch(:connect_timeout, 60),
|
19
|
+
}
|
20
|
+
|
21
|
+
opts[:username] = Excon::Utils.escape_uri(username) if username
|
22
|
+
opts[:password] = Excon::Utils.escape_uri(password) if password
|
23
|
+
|
24
|
+
@connection = Excon.new(base_uri, opts)
|
27
25
|
end
|
28
26
|
|
29
27
|
[:get, :post, :patch, :put, :delete, :head].each do |method|
|
30
|
-
define_method(method) do
|
31
|
-
|
28
|
+
define_method(method) do |path, options = {}|
|
29
|
+
headers = DEFAULT_HEADERS.merge(options.fetch(:headers, {}))
|
30
|
+
body = begin
|
31
|
+
data = options.fetch(:body, "")
|
32
|
+
if headers["Content-Type"] == "application/json" && data.instance_of?(Hash)
|
33
|
+
data.to_json
|
34
|
+
else
|
35
|
+
data
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
res = @connection.__send__(
|
40
|
+
method,
|
41
|
+
path: path,
|
42
|
+
body: body,
|
43
|
+
headers: headers,
|
44
|
+
query: options.fetch(:query, {})
|
45
|
+
)
|
46
|
+
|
47
|
+
if options.fetch(:raw, false)
|
48
|
+
[res.status, res.body, res.headers]
|
49
|
+
else
|
50
|
+
if res.status >= 400
|
51
|
+
raise QuickPay::API::Error.by_status_code(res.status, res.body, res.headers)
|
52
|
+
end
|
53
|
+
|
54
|
+
res.headers["Content-Type"] == "application/json" ? JSON.parse(res.body) : res.body
|
55
|
+
end
|
32
56
|
end
|
33
57
|
end
|
34
58
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module QuickPay
|
2
|
+
module API
|
3
|
+
class Error < StandardError
|
4
|
+
class BadRequest < Error; end
|
5
|
+
class Unauthorized < Error; end
|
6
|
+
class PaymentRequired < Error; end
|
7
|
+
class Forbidden < Error; end
|
8
|
+
class NotFound < Error; end
|
9
|
+
class MethodNotAllowed < Error; end
|
10
|
+
class NotAcceptable < Error; end
|
11
|
+
class Conflict < Error; end
|
12
|
+
class TooManyRequest < Error; end
|
13
|
+
class InternalServerError < Error; end
|
14
|
+
class BadGateway < Error; end
|
15
|
+
class ServiceUnavailable < Error; end
|
16
|
+
class GatewayTimeout < Error; end
|
17
|
+
|
18
|
+
CLASS_MAP = {
|
19
|
+
400 => "BadRequest",
|
20
|
+
401 => "Unauthorized",
|
21
|
+
402 => "PaymentRequired",
|
22
|
+
403 => "Forbidden",
|
23
|
+
404 => "NotFound",
|
24
|
+
405 => "MethodNotAllowed",
|
25
|
+
406 => "NotAcceptable",
|
26
|
+
409 => "Conflict",
|
27
|
+
429 => "TooManyRequest",
|
28
|
+
500 => "InternalServerError",
|
29
|
+
502 => "BadGateway",
|
30
|
+
503 => "ServiceUnavailable",
|
31
|
+
504 => "GatewayTimeout"
|
32
|
+
}.freeze
|
33
|
+
|
34
|
+
attr_reader :status, :body, :headers
|
35
|
+
|
36
|
+
def initialize(status, body, headers)
|
37
|
+
@status = status
|
38
|
+
@body = body
|
39
|
+
@headers = headers
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.by_status_code(status, body, headers)
|
43
|
+
if CLASS_MAP[status]
|
44
|
+
klass = QuickPay::API::Error.const_get(CLASS_MAP[status])
|
45
|
+
fail klass.new(status, body, headers)
|
46
|
+
else
|
47
|
+
fail QuickPay::API::Error.new(status, body, headers)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("lib", __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "quickpay/api/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "quickpay-ruby-client"
|
8
|
-
spec.version = QuickPay::VERSION
|
8
|
+
spec.version = QuickPay::API::VERSION
|
9
9
|
spec.authors = ["QuickPay Developers"]
|
10
10
|
spec.email = ["support@quickpay.net"]
|
11
11
|
|
12
12
|
spec.summary = "Ruby client for QuickPay API"
|
13
|
-
spec.description = "Embed QuickPay's secure payments directly into your Ruby applications. more at https://tech.quickpay.net"
|
13
|
+
spec.description = "Embed QuickPay's secure payments directly into your Ruby applications. Learn more at https://tech.quickpay.net"
|
14
14
|
spec.homepage = "https://github.com/QuickPay/quickpay-ruby-client"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -19,11 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler"
|
22
|
-
spec.add_development_dependency "rake", "~>
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "rspec-mocks"
|
25
|
-
spec.add_development_dependency "webmock", "~> 1.24"
|
26
|
-
spec.add_development_dependency "pry-byebug"
|
22
|
+
spec.add_development_dependency "rake", "~> 12.3.2"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.11.3"
|
27
24
|
|
28
|
-
spec.add_dependency "
|
25
|
+
spec.add_dependency "excon", "~> 0.62.0"
|
29
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickpay-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- QuickPay Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,86 +30,44 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 5.11.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 5.11.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: webmock
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.24'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.24'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry-byebug
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: httmultiparty
|
56
|
+
name: excon
|
99
57
|
requirement: !ruby/object:Gem::Requirement
|
100
58
|
requirements:
|
101
59
|
- - "~>"
|
102
60
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
61
|
+
version: 0.62.0
|
104
62
|
type: :runtime
|
105
63
|
prerelease: false
|
106
64
|
version_requirements: !ruby/object:Gem::Requirement
|
107
65
|
requirements:
|
108
66
|
- - "~>"
|
109
67
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
68
|
+
version: 0.62.0
|
111
69
|
description: Embed QuickPay's secure payments directly into your Ruby applications.
|
112
|
-
more at https://tech.quickpay.net
|
70
|
+
Learn more at https://tech.quickpay.net
|
113
71
|
email:
|
114
72
|
- support@quickpay.net
|
115
73
|
executables: []
|
@@ -117,30 +75,15 @@ extensions: []
|
|
117
75
|
extra_rdoc_files: []
|
118
76
|
files:
|
119
77
|
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
78
|
- ".travis.yml"
|
122
79
|
- CHANGELOG.md
|
123
80
|
- Gemfile
|
124
81
|
- LICENSE.txt
|
125
82
|
- README.md
|
126
83
|
- Rakefile
|
127
|
-
- lib/quickpay.rb
|
128
84
|
- lib/quickpay/api/client.rb
|
129
|
-
- lib/quickpay/api/
|
130
|
-
- lib/quickpay/api/
|
131
|
-
- lib/quickpay/api/errors/conflict.rb
|
132
|
-
- lib/quickpay/api/errors/forbidden.rb
|
133
|
-
- lib/quickpay/api/errors/method_not_allowed.rb
|
134
|
-
- lib/quickpay/api/errors/not_acceptable.rb
|
135
|
-
- lib/quickpay/api/errors/not_found.rb
|
136
|
-
- lib/quickpay/api/errors/payment_required.rb
|
137
|
-
- lib/quickpay/api/errors/quickpay_error.rb
|
138
|
-
- lib/quickpay/api/errors/server_error.rb
|
139
|
-
- lib/quickpay/api/errors/unauthorized.rb
|
140
|
-
- lib/quickpay/api/request.rb
|
141
|
-
- lib/quickpay/constants.rb
|
142
|
-
- lib/quickpay/logger.rb
|
143
|
-
- lib/quickpay/version.rb
|
85
|
+
- lib/quickpay/api/error.rb
|
86
|
+
- lib/quickpay/api/version.rb
|
144
87
|
- quickpay-ruby-client.gemspec
|
145
88
|
homepage: https://github.com/QuickPay/quickpay-ruby-client
|
146
89
|
licenses:
|
@@ -162,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
105
|
version: '0'
|
163
106
|
requirements: []
|
164
107
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.5.2.3
|
166
109
|
signing_key:
|
167
110
|
specification_version: 4
|
168
111
|
summary: Ruby client for QuickPay API
|
data/.rspec
DELETED
data/lib/quickpay.rb
DELETED
data/lib/quickpay/api/errors.rb
DELETED
data/lib/quickpay/api/request.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'httmultiparty'
|
2
|
-
|
3
|
-
module QuickPay
|
4
|
-
module API
|
5
|
-
class Request
|
6
|
-
include HTTMultiParty
|
7
|
-
|
8
|
-
attr_reader :options, :secret
|
9
|
-
|
10
|
-
def initialize (options = {})
|
11
|
-
@options = options.dup
|
12
|
-
@secret = @options.delete(:secret)
|
13
|
-
self.class.base_uri(options[:base_uri] || BASE_URI)
|
14
|
-
end
|
15
|
-
|
16
|
-
def request method, path, data = {}
|
17
|
-
raw = data.delete(:raw)
|
18
|
-
req_headers = headers.merge(data.delete(:headers) || {})
|
19
|
-
|
20
|
-
http_options = options.dup
|
21
|
-
if data.any? { |_key, value| value.is_a?(File) }
|
22
|
-
http_options[:body] = data
|
23
|
-
http_options[:detect_mime_type] = true
|
24
|
-
else
|
25
|
-
case method
|
26
|
-
when :get, :delete, :head
|
27
|
-
http_options[:query] = data
|
28
|
-
when :post, :patch, :put
|
29
|
-
http_options[:body] = data.to_json
|
30
|
-
req_headers["Content-Type"] = "application/json"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
http_options[:headers] = headers.merge(req_headers)
|
35
|
-
QuickPay.logger.debug { "#{method.to_s.upcase} #{base_uri}#{path} #{http_options}" }
|
36
|
-
create_response(raw, self.class.send(method, path, http_options))
|
37
|
-
end
|
38
|
-
|
39
|
-
def create_response raw, res
|
40
|
-
if raw
|
41
|
-
[res.code, res.body, res.headers]
|
42
|
-
else
|
43
|
-
response = res.parsed_response
|
44
|
-
raise_error(response, res.code) if res.code >= 400
|
45
|
-
response
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def raise_error body, status
|
50
|
-
code = API_STATUS_CODES[status].to_s
|
51
|
-
args = [code, status, body]
|
52
|
-
|
53
|
-
klass =
|
54
|
-
begin
|
55
|
-
require "quickpay/api/errors/#{code}"
|
56
|
-
class_name = code.split('_').map(&:capitalize).join('')
|
57
|
-
QuickPay::API.const_get(class_name)
|
58
|
-
rescue LoadError, NameError
|
59
|
-
QuickPay::API::Error
|
60
|
-
end
|
61
|
-
|
62
|
-
fail klass.new(*args), error_description(body)
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def base_uri
|
68
|
-
self.class.default_options[:base_uri]
|
69
|
-
end
|
70
|
-
|
71
|
-
def error_description msg
|
72
|
-
msg
|
73
|
-
end
|
74
|
-
|
75
|
-
def headers
|
76
|
-
heads = {
|
77
|
-
'User-Agent' => user_agent,
|
78
|
-
'Accept-Version' => "v#{QuickPay::API_VERSION}"
|
79
|
-
}
|
80
|
-
heads['Authorization'] = "Basic #{authorization}" if secret != nil
|
81
|
-
heads
|
82
|
-
end
|
83
|
-
|
84
|
-
def user_agent
|
85
|
-
user_agent = "quickpay-ruby-client, v#{QuickPay::VERSION}"
|
86
|
-
user_agent += ", #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}"
|
87
|
-
if defined?(RUBY_ENGINE)
|
88
|
-
user_agent += ", #{RUBY_ENGINE}"
|
89
|
-
end
|
90
|
-
user_agent
|
91
|
-
end
|
92
|
-
|
93
|
-
def authorization
|
94
|
-
Base64.strict_encode64(secret)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
data/lib/quickpay/constants.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
module QuickPay
|
3
|
-
BASE_URI = 'https://api.quickpay.net'
|
4
|
-
API_VERSION = 10
|
5
|
-
|
6
|
-
API_STATUS_CODES = {
|
7
|
-
200 => :ok,
|
8
|
-
201 => :created,
|
9
|
-
202 => :accepted,
|
10
|
-
400 => :bad_request,
|
11
|
-
401 => :unauthorized,
|
12
|
-
402 => :payment_required,
|
13
|
-
403 => :forbidden,
|
14
|
-
404 => :not_found,
|
15
|
-
405 => :method_not_allowed,
|
16
|
-
406 => :not_acceptable,
|
17
|
-
409 => :conflict,
|
18
|
-
500 => :server_error
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
data/lib/quickpay/logger.rb
DELETED
data/lib/quickpay/version.rb
DELETED