paysafe 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.sample +3 -0
- data/.gitignore +10 -0
- data/.travis.yml +14 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +10 -0
- data/bin/console +25 -0
- data/bin/setup +31 -0
- data/lib/paysafe.rb +3 -0
- data/lib/paysafe/error.rb +114 -0
- data/lib/paysafe/rest/client.rb +237 -0
- data/lib/paysafe/version.rb +3 -0
- data/paysafe.gemspec +32 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ef4b1c9b6aaaabafc65842eb238af4a84bb0a67
|
4
|
+
data.tar.gz: 0320393b37e6fd6cacc4131a3a8fa465f177f4fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bdac8afafe8563459b1e8c8ffa2ebb18d054fc0e863d1b3d70d1a0c337ffb8a1892ca117f1238251e0001a070d9ac2c6bcdc00f39d4b1a7a50e26744fc3bb613
|
7
|
+
data.tar.gz: b42dbf57e8a876c2dd57d789e8be2a5bdfc0a39727786204f8876399fd10251c39b1b17fa83e802b01bd0b76dd541419affc2bd06c9c97f05b24d5a96f2ae71a
|
data/.env.sample
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Javier Julio
|
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,65 @@
|
|
1
|
+
# The Paysafe Ruby Gem
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/paysafe.svg)][gem]
|
4
|
+
[![Build Status](https://travis-ci.org/javierjulio/paysafe.svg?branch=master)][travis]
|
5
|
+
|
6
|
+
[gem]: https://rubygems.org/gems/paysafe
|
7
|
+
[travis]: https://travis-ci.org/javierjulio/paysafe
|
8
|
+
|
9
|
+
A tested Ruby interface to the Paysafe REST API (formerly Optimal Payments). Note: requires Ruby 2.1 and up. Not all API actions are supported yet.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'paysafe'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install paysafe
|
26
|
+
|
27
|
+
To try out the gem and experiment, you're better off following the development instructions.
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
TODO: Write usage instructions here
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
1. Clone the repo: `git clone https://github.com/javierjulio/paysafe.git`
|
36
|
+
2. Use Ruby 2.1 and up. If you need to install use [rbenv](https://github.com/sstephenson/rbenv) and [ruby-build](https://github.com/sstephenson/ruby-build) and then run:
|
37
|
+
|
38
|
+
gem update --system
|
39
|
+
gem update
|
40
|
+
gem install bundler --no-rdoc --no-ri
|
41
|
+
|
42
|
+
3. From project root run `./bin/setup` script
|
43
|
+
4. Run `./bin/console` for an interactive prompt with an authenticated client for you to experiment:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
profile = client.create_profile(merchantCustomerId: '123', locale: 'en_US')
|
47
|
+
puts profile[:id]
|
48
|
+
# => b088ac37...
|
49
|
+
```
|
50
|
+
|
51
|
+
### Tests
|
52
|
+
|
53
|
+
Run `bundle exec rake test` or to skip integration tests run with `SKIP_INTEGRATION_TESTS=true`.
|
54
|
+
|
55
|
+
### Releasing
|
56
|
+
|
57
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests for missing API support are welcome on GitHub at https://github.com/javierjulio/paysafe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "paysafe"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'dotenv'
|
14
|
+
Dotenv.load
|
15
|
+
|
16
|
+
def client
|
17
|
+
Paysafe::REST::Client.new do |config|
|
18
|
+
config.account_number = ENV['OPTIMAL_PAYMENTS_ACCOUNT_NUMBER']
|
19
|
+
config.api_key = ENV['OPTIMAL_PAYMENTS_API_KEY']
|
20
|
+
config.api_secret = ENV['OPTIMAL_PAYMENTS_API_SECRET']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "irb"
|
25
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
|
5
|
+
bundle install
|
6
|
+
|
7
|
+
read -r -p 'Do you have an Optimal Payments Developer Centre account? (y/n) ' has_account
|
8
|
+
|
9
|
+
if [[ "$has_account" =~ ^(Yes|yes|Y|y)$ ]]; then
|
10
|
+
echo "Great! You can get your account credentials from:"
|
11
|
+
echo " https://developer.optimalpayments.com/en/my-account/"
|
12
|
+
echo
|
13
|
+
else
|
14
|
+
echo "Then you'll need to create an account first at:"
|
15
|
+
echo " https://developer.optimalpayments.com/en/get-started/"
|
16
|
+
echo
|
17
|
+
read -s -p "Press Enter key if you're ready to continue..."
|
18
|
+
echo
|
19
|
+
fi
|
20
|
+
|
21
|
+
echo "Enter your account credentials below."
|
22
|
+
read -p 'Account Number: ' account_number
|
23
|
+
read -p 'API Key: ' api_key
|
24
|
+
read -p 'API Secret: ' api_secret
|
25
|
+
|
26
|
+
cp .env.sample .env
|
27
|
+
sed -i -e s/YOUR_ACCOUNT_NUMBER/"$account_number"/g .env
|
28
|
+
sed -i -e s/YOUR_API_KEY/"$api_key"/g .env
|
29
|
+
sed -i -e s/YOUR_API_SECRET/"$api_secret"/g .env
|
30
|
+
|
31
|
+
echo "Done."
|
data/lib/paysafe.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
module Paysafe
|
2
|
+
class Error < StandardError
|
3
|
+
# Raised on a 4xx HTTP status code
|
4
|
+
ClientError = Class.new(self)
|
5
|
+
|
6
|
+
# Raised on the HTTP status code 400
|
7
|
+
BadRequest = Class.new(ClientError)
|
8
|
+
|
9
|
+
# Raised on the HTTP status code 401
|
10
|
+
Unauthorized = Class.new(ClientError)
|
11
|
+
|
12
|
+
# Raised on the HTTP status code 402
|
13
|
+
RequestDeclined = Class.new(ClientError)
|
14
|
+
|
15
|
+
# Raised on the HTTP status code 403
|
16
|
+
Forbidden = Class.new(ClientError)
|
17
|
+
|
18
|
+
# Raised on the HTTP status code 404
|
19
|
+
NotFound = Class.new(ClientError)
|
20
|
+
|
21
|
+
# Raised on the HTTP status code 406
|
22
|
+
NotAcceptable = Class.new(ClientError)
|
23
|
+
|
24
|
+
# Raised on the HTTP status code 409
|
25
|
+
Conflict = Class.new(ClientError)
|
26
|
+
|
27
|
+
# Raised on the HTTP status code 415
|
28
|
+
UnsupportedMediaType = Class.new(ClientError)
|
29
|
+
|
30
|
+
# Raised on the HTTP status code 422
|
31
|
+
UnprocessableEntity = Class.new(ClientError)
|
32
|
+
|
33
|
+
# Raised on the HTTP status code 429
|
34
|
+
TooManyRequests = Class.new(ClientError)
|
35
|
+
|
36
|
+
# Raised on a 5xx HTTP status code
|
37
|
+
ServerError = Class.new(self)
|
38
|
+
|
39
|
+
# Raised on the HTTP status code 500
|
40
|
+
InternalServerError = Class.new(ServerError)
|
41
|
+
|
42
|
+
# Raised on the HTTP status code 502
|
43
|
+
BadGateway = Class.new(ServerError)
|
44
|
+
|
45
|
+
# Raised on the HTTP status code 503
|
46
|
+
ServiceUnavailable = Class.new(ServerError)
|
47
|
+
|
48
|
+
# Raised on the HTTP status code 504
|
49
|
+
GatewayTimeout = Class.new(ServerError)
|
50
|
+
|
51
|
+
ERRORS = {
|
52
|
+
400 => Paysafe::Error::BadRequest,
|
53
|
+
401 => Paysafe::Error::Unauthorized,
|
54
|
+
402 => Paysafe::Error::RequestDeclined,
|
55
|
+
403 => Paysafe::Error::Forbidden,
|
56
|
+
404 => Paysafe::Error::NotFound,
|
57
|
+
406 => Paysafe::Error::NotAcceptable,
|
58
|
+
409 => Paysafe::Error::Conflict,
|
59
|
+
415 => Paysafe::Error::UnsupportedMediaType,
|
60
|
+
422 => Paysafe::Error::UnprocessableEntity,
|
61
|
+
429 => Paysafe::Error::TooManyRequests,
|
62
|
+
500 => Paysafe::Error::InternalServerError,
|
63
|
+
502 => Paysafe::Error::BadGateway,
|
64
|
+
503 => Paysafe::Error::ServiceUnavailable,
|
65
|
+
504 => Paysafe::Error::GatewayTimeout,
|
66
|
+
}
|
67
|
+
|
68
|
+
# The Paysafe API Error Code
|
69
|
+
#
|
70
|
+
# @return [Integer]
|
71
|
+
attr_reader :code
|
72
|
+
|
73
|
+
# The JSON HTTP response in Hash form
|
74
|
+
#
|
75
|
+
# @return [Hash]
|
76
|
+
attr_reader :response
|
77
|
+
|
78
|
+
class << self
|
79
|
+
# Create a new error from an HTTP response
|
80
|
+
#
|
81
|
+
# @param body [String]
|
82
|
+
# @param code [Integer]
|
83
|
+
# @return [Paysafe::Error]
|
84
|
+
def error_from_response(body, code)
|
85
|
+
klass = ERRORS[code] || Paysafe::Error
|
86
|
+
message, error_code = parse_error(body)
|
87
|
+
klass.new(message: message, code: error_code, response: body)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def parse_error(body)
|
93
|
+
if body.nil? || body.empty?
|
94
|
+
['', nil]
|
95
|
+
elsif body.is_a?(Hash) && body[:error].is_a?(Hash)
|
96
|
+
[body[:error][:message], body[:error][:code]]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
# Initializes a new Error object
|
103
|
+
#
|
104
|
+
# @param message [Exception, String]
|
105
|
+
# @param code [Integer]
|
106
|
+
# @param response [Hash]
|
107
|
+
# @return [Paysafe::Error]
|
108
|
+
def initialize(message: '', code: nil, response: {})
|
109
|
+
super(message)
|
110
|
+
@code = code
|
111
|
+
@response = response
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require 'http'
|
2
|
+
|
3
|
+
module Paysafe
|
4
|
+
module REST
|
5
|
+
class Client
|
6
|
+
|
7
|
+
API_TEST = 'https://api.test.netbanx.com'
|
8
|
+
API_LIVE = 'https://api.netbanx.com'
|
9
|
+
|
10
|
+
HEADERS = {
|
11
|
+
'Content-Type' => 'application/json',
|
12
|
+
'User-Agent' => "PaysafeRubyGem/#{Paysafe::VERSION}",
|
13
|
+
'X-Ruby-Version' => RUBY_VERSION,
|
14
|
+
'X-Ruby-Platform' => RUBY_PLATFORM
|
15
|
+
}
|
16
|
+
|
17
|
+
attr_accessor :account_number, :api_key, :api_secret, :test_mode
|
18
|
+
attr_reader :api_base
|
19
|
+
|
20
|
+
# Initializes a new Client object
|
21
|
+
#
|
22
|
+
# @param options [Hash]
|
23
|
+
# @return [Paysafe::REST::Client]
|
24
|
+
def initialize(options={})
|
25
|
+
@test_mode = true
|
26
|
+
|
27
|
+
options.each do |key, value|
|
28
|
+
instance_variable_set("@#{key}", value)
|
29
|
+
end
|
30
|
+
|
31
|
+
yield(self) if block_given?
|
32
|
+
|
33
|
+
@api_base = test_mode ? API_TEST : API_LIVE
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Hash]
|
37
|
+
def credentials
|
38
|
+
{
|
39
|
+
account_number: account_number,
|
40
|
+
api_key: api_key,
|
41
|
+
api_secret: api_secret
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean]
|
46
|
+
def credentials?
|
47
|
+
credentials.values.all?
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_profile(merchantCustomerId:, locale:, **args)
|
51
|
+
data = {
|
52
|
+
merchantCustomerId: merchantCustomerId,
|
53
|
+
locale: locale,
|
54
|
+
firstName: args[:firstName],
|
55
|
+
lastName: args[:lastName],
|
56
|
+
email: args[:email],
|
57
|
+
card: args[:card]
|
58
|
+
}
|
59
|
+
|
60
|
+
response = post(path: "/customervault/v1/profiles", data: data)
|
61
|
+
response_body = symbolize_keys!(response.parse)
|
62
|
+
fail_or_return_response_body(response.code, response_body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_profile(id:)
|
66
|
+
response = delete(path: "/customervault/v1/profiles/#{id}")
|
67
|
+
fail_or_return_response_body(response.code, (response.code == 200))
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_profile(id:, fields: [])
|
71
|
+
fields.keep_if { |field| field == :cards || field == :addresses }
|
72
|
+
|
73
|
+
path = "/customervault/v1/profiles/#{id}"
|
74
|
+
|
75
|
+
if !fields.empty?
|
76
|
+
path += "?fields=#{fields.join(',')}"
|
77
|
+
end
|
78
|
+
|
79
|
+
response = get(path: path)
|
80
|
+
response_body = symbolize_keys!(response.parse)
|
81
|
+
fail_or_return_response_body(response.code, response_body)
|
82
|
+
end
|
83
|
+
|
84
|
+
def create_address(profile_id:, country:, zip:, **args)
|
85
|
+
data = {
|
86
|
+
nickName: args[:nickName],
|
87
|
+
street: args[:street],
|
88
|
+
city: args[:city],
|
89
|
+
country: country,
|
90
|
+
state: args[:state],
|
91
|
+
zip: zip
|
92
|
+
}
|
93
|
+
|
94
|
+
response = post(path: "/customervault/v1/profiles/#{profile_id}/addresses", data: data)
|
95
|
+
response_body = symbolize_keys!(response.parse)
|
96
|
+
fail_or_return_response_body(response.code, response_body)
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_card(profile_id:, number:, month:, year:, **args)
|
100
|
+
data = {
|
101
|
+
cardNum: number,
|
102
|
+
cardExpiry: {
|
103
|
+
month: month,
|
104
|
+
year: year
|
105
|
+
},
|
106
|
+
nickName: args[:nickName],
|
107
|
+
holderName: args[:holderName],
|
108
|
+
merchantRefNum: args[:merchantRefNum],
|
109
|
+
billingAddressId: args[:billingAddressId],
|
110
|
+
defaultCardIndicator: args[:defaultCardIndicator]
|
111
|
+
}.reject { |key, value| value.nil? }
|
112
|
+
|
113
|
+
response = post(path: "/customervault/v1/profiles/#{profile_id}/cards", data: data)
|
114
|
+
response_body = symbolize_keys!(response.parse)
|
115
|
+
fail_or_return_response_body(response.code, response_body)
|
116
|
+
end
|
117
|
+
|
118
|
+
def delete_card(profile_id:, id:)
|
119
|
+
response = delete(path: "/customervault/v1/profiles/#{profile_id}/cards/#{id}")
|
120
|
+
response_body = symbolize_keys!(response.parse)
|
121
|
+
fail_or_return_response_body(response.code, response_body)
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_card(profile_id:, id:)
|
125
|
+
response = get(path: "/customervault/v1/profiles/#{profile_id}/cards/#{id}")
|
126
|
+
response_body = symbolize_keys!(response.parse)
|
127
|
+
fail_or_return_response_body(response.code, response_body)
|
128
|
+
end
|
129
|
+
|
130
|
+
def update_card(profile_id:, id:, month:, year:, **args)
|
131
|
+
data = {
|
132
|
+
cardExpiry: {
|
133
|
+
month: month,
|
134
|
+
year: year
|
135
|
+
},
|
136
|
+
nickName: args[:nickName],
|
137
|
+
holderName: args[:holderName],
|
138
|
+
merchantRefNum: args[:merchantRefNum],
|
139
|
+
billingAddressId: args[:billingAddressId],
|
140
|
+
defaultCardIndicator: args[:defaultCardIndicator]
|
141
|
+
}.reject { |key, value| value.nil? }
|
142
|
+
|
143
|
+
response = put(path: "/customervault/v1/profiles/#{profile_id}/cards/#{id}", data: data)
|
144
|
+
response_body = symbolize_keys!(response.parse)
|
145
|
+
fail_or_return_response_body(response.code, response_body)
|
146
|
+
end
|
147
|
+
|
148
|
+
def purchase(amount:, token:, merchantRefNum:, **args)
|
149
|
+
data = {
|
150
|
+
amount: amount,
|
151
|
+
merchantRefNum: merchantRefNum,
|
152
|
+
settleWithAuth: true,
|
153
|
+
card: {
|
154
|
+
paymentToken: token
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
response = post(path: "/cardpayments/v1/accounts/#{account_number}/auths", data: data)
|
159
|
+
response_body = symbolize_keys!(response.parse)
|
160
|
+
fail_or_return_response_body(response.code, response_body)
|
161
|
+
end
|
162
|
+
|
163
|
+
def verify_card(merchantRefNum:, number:, month:, year:, **args)
|
164
|
+
data = {
|
165
|
+
merchantRefNum: merchantRefNum,
|
166
|
+
card: {
|
167
|
+
cardNum: number,
|
168
|
+
cardExpiry: {
|
169
|
+
month: month,
|
170
|
+
year: year
|
171
|
+
},
|
172
|
+
cvv: args[:cvv]
|
173
|
+
},
|
174
|
+
profile: {
|
175
|
+
firstName: args[:firstName],
|
176
|
+
lastName: args[:lastName],
|
177
|
+
email: args[:email]
|
178
|
+
},
|
179
|
+
billingDetails: args[:address],
|
180
|
+
customerIp: args[:customerIp],
|
181
|
+
description: args[:description]
|
182
|
+
}
|
183
|
+
|
184
|
+
response = post(path: "/cardpayments/v1/accounts/#{account_number}/verifications", data: data)
|
185
|
+
response_body = symbolize_keys!(response.parse)
|
186
|
+
fail_or_return_response_body(response.code, response_body)
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
190
|
+
|
191
|
+
def http_client
|
192
|
+
HTTP
|
193
|
+
.headers(HEADERS)
|
194
|
+
.timeout(write: 2, connect: 5, read: 10)
|
195
|
+
.basic_auth(user: @api_key, pass: @api_secret)
|
196
|
+
end
|
197
|
+
|
198
|
+
def post(path:, data:)
|
199
|
+
http_client.post("#{api_base}#{path}", json: data)
|
200
|
+
end
|
201
|
+
|
202
|
+
def get(path:)
|
203
|
+
http_client.get("#{api_base}#{path}")
|
204
|
+
end
|
205
|
+
|
206
|
+
def delete(path:)
|
207
|
+
http_client.delete("#{api_base}#{path}")
|
208
|
+
end
|
209
|
+
|
210
|
+
def put(path:, data:)
|
211
|
+
http_client.put("#{api_base}#{path}", json: data)
|
212
|
+
end
|
213
|
+
|
214
|
+
def symbolize_keys!(object)
|
215
|
+
if object.is_a?(Array)
|
216
|
+
object.each_with_index do |val, index|
|
217
|
+
object[index] = symbolize_keys!(val)
|
218
|
+
end
|
219
|
+
elsif object.is_a?(Hash)
|
220
|
+
object.keys.each do |key|
|
221
|
+
object[key.to_sym] = symbolize_keys!(object.delete(key))
|
222
|
+
end
|
223
|
+
end
|
224
|
+
object
|
225
|
+
end
|
226
|
+
|
227
|
+
def fail_or_return_response_body(code, body)
|
228
|
+
if code < 200 || code >= 206
|
229
|
+
error = Paysafe::Error.error_from_response(body, code)
|
230
|
+
fail(error)
|
231
|
+
end
|
232
|
+
body
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
data/paysafe.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paysafe/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paysafe"
|
8
|
+
spec.version = Paysafe::VERSION
|
9
|
+
spec.authors = ["Javier Julio"]
|
10
|
+
spec.email = ["jjfutbol@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem to wrap Paysafe REST API}
|
13
|
+
spec.description = %q{Gem to wrap Paysafe REST API}
|
14
|
+
spec.homepage = "https://github.com/javierjulio/paysafe"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "dotenv"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
spec.add_development_dependency "minitest-reporters"
|
27
|
+
spec.add_development_dependency "vcr"
|
28
|
+
spec.add_development_dependency "webmock"
|
29
|
+
|
30
|
+
spec.add_dependency "http", '~> 0.9.8'
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paysafe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javier Julio
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
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: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
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: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: http
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.8
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.8
|
125
|
+
description: Gem to wrap Paysafe REST API
|
126
|
+
email:
|
127
|
+
- jjfutbol@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".env.sample"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- lib/paysafe.rb
|
143
|
+
- lib/paysafe/error.rb
|
144
|
+
- lib/paysafe/rest/client.rb
|
145
|
+
- lib/paysafe/version.rb
|
146
|
+
- paysafe.gemspec
|
147
|
+
homepage: https://github.com/javierjulio/paysafe
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.4.8
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Gem to wrap Paysafe REST API
|
171
|
+
test_files: []
|