hyperwallet-api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f31081cedba40c93a380dfd7585086cbc3107d831c4f6c73e9ebb34a3d2074b2
4
+ data.tar.gz: 0e5bcfa99c18483e0fa7fe5516eaad124512e987cbbafd089a82902552c0a44f
5
+ SHA512:
6
+ metadata.gz: 41dbb1320af2b60195d024329599f3670f902e5219b1f8dda4d6e7316607a0a5bd20ce6f40483ef0b8594d9696a8dc2f103d693185bff7a5a63509d48178563d
7
+ data.tar.gz: b0701e2343c45c1defa69c4dc4f87c4dae257dc1af0b5ca46ec7b071bec90d2fbec714a891fb4daceac3857460557912b15dd01443f426e765fffc83131dfcd5
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .env
3
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Taylor Brooks
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Hyperwallet Ruby Client
2
+ A Ruby wrapper for the Hyperwallet API
3
+
4
+ To get a general overview of API: https://docs.hyperwallet.com/content/hyperwallet-payout-documentation
5
+
6
+ ### Installation
7
+ Add this line to your application's Gemfile:
8
+ ````ruby
9
+ # in your Gemfile
10
+ gem 'hyperwallet-api', '~> 1.0'
11
+
12
+ # then...
13
+ bundle install
14
+ ````
15
+
16
+ ### Usage
17
+ ````ruby
18
+ client = Hyperwallet::Client.new(
19
+ url: ...,
20
+ username: ...,
21
+ password: ...,
22
+ )
23
+
24
+ response = client.list_users
25
+
26
+ puts response
27
+ ````
28
+
29
+ ### History
30
+
31
+ View the [changelog](https://github.com/taylorbrooks/hyperwallet/blob/master/CHANGELOG.md)
32
+ This gem follows [Semantic Versioning](http://semver.org/)
33
+
34
+ ### Contributing
35
+
36
+ Everyone is encouraged to help improve this project. Here are a few ways you can help:
37
+
38
+ - [Report bugs](https://github.com/taylorbrooks/hyperwallet/issues)
39
+ - Fix bugs and [submit pull requests](https://github.com/taylorbrooks/hyperwallet/pulls)
40
+ - Write, clarify, or fix documentation
41
+ - Suggest or add new features
42
+
43
+ ### Copyright
44
+ Copyright (c) 2022 Taylor Brooks. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ task :environment do
9
+ require 'dotenv'
10
+ Dotenv.load
11
+
12
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
13
+ require 'hyperwallet'
14
+ end
data/bin/rspec ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path(
12
+ '../../Gemfile',
13
+ Pathname.new(__FILE__).realpath
14
+ )
15
+
16
+ require 'rubygems'
17
+ require 'bundler/setup'
18
+
19
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,33 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'hyperwallet/version'
3
+ require 'base64'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'hyperwallet-api'
7
+ s.version = Hyperwallet::VERSION
8
+ s.authors = ['Taylor Brooks']
9
+ s.email = ['dGJyb29rc0BnbWFpbC5jb20='].map { |e| Base64.decode64(e) }
10
+ s.homepage = 'https://github.com/taylorbrooks/hyperwallet'
11
+ s.summary = 'A Ruby wrapper for the Hyperwallet API'
12
+ s.description = 'A Ruby wrapper for the Hyperwallet API'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test)/})
18
+
19
+ s.required_ruby_version = '>= 2.7'
20
+
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_runtime_dependency 'faraday', '~> 2.0'
24
+ s.add_runtime_dependency 'json'
25
+
26
+ s.add_development_dependency 'bundler', '~> 2.3'
27
+ s.add_development_dependency 'dotenv'
28
+ s.add_development_dependency 'pry'
29
+ s.add_development_dependency 'rake', '~> 13.0'
30
+ s.add_development_dependency 'rspec', '~> 3.7'
31
+ s.add_development_dependency 'sinatra', '~> 2.0'
32
+ s.add_development_dependency 'webmock', '~> 3.1'
33
+ end
@@ -0,0 +1,67 @@
1
+ require 'faraday'
2
+
3
+ Dir[File.expand_path('../resources/*.rb', __FILE__)].each { |f| require f }
4
+ require File.expand_path('../response/base.rb', __FILE__)
5
+ Dir[File.expand_path('../response/*.rb', __FILE__)].each { |f| require f }
6
+
7
+ module Hyperwallet
8
+ class Client
9
+ include Hyperwallet::Client::BankAccount
10
+ include Hyperwallet::Client::Payment
11
+ include Hyperwallet::Client::User
12
+ include Hyperwallet::Client::WebhookNotification
13
+
14
+ attr_reader :url, :username, :password, :logger, :connection, :adapter
15
+
16
+ def initialize(url:, username:, password:, logger: true, adapter: Faraday.default_adapter)
17
+ @url = "#{url}/rest/v4/"
18
+ @username = username
19
+ @password = password
20
+ @logger = logger
21
+ @adapter = adapter
22
+ end
23
+
24
+ def delete(path, options = {})
25
+ connection.delete(path, options).body
26
+ end
27
+
28
+ def get(path, options = {})
29
+ connection.get(path, options).body
30
+ end
31
+
32
+ def patch(path, options = {})
33
+ connection.patch(path, options).body
34
+ end
35
+
36
+ def post(path, options = {})
37
+ connection.post(path, options).body
38
+ end
39
+
40
+ def put(path, options = {})
41
+ connection.put(path, options).body
42
+ end
43
+
44
+ private
45
+
46
+ def connection
47
+ headers = {
48
+ accept: 'application/json',
49
+ 'User-Agent' => "hyperwallet-gem/v#{Hyperwallet::VERSION}"
50
+ }
51
+
52
+ client_opts = {
53
+ url: url,
54
+ headers: headers
55
+ }
56
+
57
+ Faraday.new(client_opts) do |conn|
58
+ conn.request :authorization, :basic, username, password
59
+ conn.request :json
60
+ conn.response :json
61
+ conn.response :logger if logger
62
+ conn.response :hyperwallet_errors
63
+ conn.adapter adapter
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,48 @@
1
+ module Hyperwallet
2
+ class Error < StandardError; end
3
+ class BadGateway < Error; end
4
+ class BadRequest < Error; end
5
+ class Forbidden < Error; end
6
+ class GatewayTimeout < Error; end
7
+ class InternalServerError < Error; end
8
+ class NotFound < Error; end
9
+ class ServiceUnavailable < Error; end
10
+ class Unauthorized < Error; end
11
+ end
12
+
13
+ module Hyperwallet
14
+ class ErrorHandler < Faraday::Middleware
15
+ ERROR_STATUSES = 400..600
16
+
17
+ def on_complete(env)
18
+ case env[:status]
19
+ when 400
20
+ raise Hyperwallet::BadRequest, error_message(env)
21
+ when 401
22
+ raise Hyperwallet::Unauthorized, error_message(env)
23
+ when 403
24
+ raise Hyperwallet::Forbidden, error_message(env)
25
+ when 404
26
+ raise Hyperwallet::NotFound, error_message(env)
27
+ when 500
28
+ raise Hyperwallet::InternalServerError, error_message(env)
29
+ when 502
30
+ raise Hyperwallet::BadGateway, error_message(env)
31
+ when 503
32
+ raise Hyperwallet::ServiceUnavailable, error_message(env)
33
+ when 504
34
+ raise Hyperwallet::GatewayTimeout, error_message(env)
35
+ when ERROR_STATUSES
36
+ raise Hyperwallet::Error, error_message(env)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def error_message(env)
43
+ "#{env[:status]}: #{env[:url]} #{env[:body]}"
44
+ end
45
+ end
46
+ end
47
+
48
+ Faraday::Response.register_middleware(hyperwallet_errors: Hyperwallet::ErrorHandler)
@@ -0,0 +1,52 @@
1
+ module Hyperwallet
2
+ class Client
3
+ module BankAccount
4
+ PATH = 'bank-accounts'.freeze
5
+
6
+ def list_bank_accounts(user_token, options = {})
7
+ get(bank_account_path(user_token), options)
8
+ end
9
+
10
+ def find_bank_account(user_token, id)
11
+ get(bank_account_path(user_token, id))
12
+ end
13
+
14
+ def create_bank_account(
15
+ user_token,
16
+ routing_number:,
17
+ account_number:,
18
+ business_name:,
19
+ address:,
20
+ city:,
21
+ state:,
22
+ postal_code:
23
+ )
24
+
25
+ options = {
26
+ profileType: 'BUSINESS',
27
+ transferMethodCountry: 'US',
28
+ transferMethodCurrency: 'USD',
29
+ type: 'BANK_ACCOUNT',
30
+ branchId: routing_number,
31
+ bankAccountId: account_number,
32
+ bankAccountPurpose: 'CHECKING',
33
+ businessName: business_name,
34
+ addressLine1: address,
35
+ city: city,
36
+ stateProvince: state,
37
+ postalCode: postal_code,
38
+ country: 'US'
39
+ }
40
+
41
+ post(bank_account_path(user_token), options)
42
+ end
43
+
44
+ private
45
+
46
+ def bank_account_path(user_token, id = nil)
47
+ root_path = "users/#{user_token}/#{PATH}"
48
+ id ? "#{root_path}/#{id}" : root_path
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,42 @@
1
+ module Hyperwallet
2
+ class Client
3
+ module Payment
4
+ PATH = 'payments'.freeze
5
+
6
+ def list_payments(options = {})
7
+ get(payment_path, options)
8
+ end
9
+
10
+ def find_payment(id)
11
+ get(payment_path(id))
12
+ end
13
+
14
+ def create_payment(
15
+ amount:,
16
+ client_payment_id:,
17
+ destination_token:,
18
+ program_token:,
19
+ currency: 'USD',
20
+ purpose: 'OTHER'
21
+ )
22
+
23
+ options = {
24
+ amount: amount,
25
+ clientPaymentId: client_payment_id,
26
+ currency: currency,
27
+ destinationToken: destination_token,
28
+ programToken: program_token,
29
+ purpose: purpose
30
+ }
31
+
32
+ post(payment_path, options)
33
+ end
34
+
35
+ private
36
+
37
+ def payment_path(id = nil)
38
+ id ? "#{PATH}/#{id}" : PATH
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ module Hyperwallet
2
+ class Client
3
+ module User
4
+ PATH = 'users'.freeze
5
+
6
+ def list_users(options = {})
7
+ get(user_path, options)
8
+ end
9
+
10
+ def find_user(id)
11
+ get(user_path(id))
12
+ end
13
+
14
+ def create_user(
15
+ program_token:,
16
+ client_user_id:,
17
+ email:,
18
+ profile_type: 'BUSINESS',
19
+ business_type: 'NOT_FOR_PROFIT_ORGANIZATION',
20
+ business_name:,
21
+ address:,
22
+ city:,
23
+ state:,
24
+ postal_code:,
25
+ country: 'US'
26
+ )
27
+
28
+ options = {
29
+ programToken: program_token,
30
+ clientUserId: client_user_id,
31
+ profileType: profile_type,
32
+ email: email,
33
+ profileType: profile_type,
34
+ businessType: business_type,
35
+ businessName: business_name,
36
+ addressLine1: address,
37
+ city: city,
38
+ stateProvince: state,
39
+ postalCode: postal_code,
40
+ country: country
41
+ }
42
+
43
+ post(user_path, options)
44
+ end
45
+
46
+ private
47
+
48
+ def user_path(id = nil)
49
+ id ? "#{PATH}/#{id}" : PATH
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ module Hyperwallet
2
+ class Client
3
+ module WebhookNotification
4
+ PATH = 'webhook-notifications'.freeze
5
+
6
+ def list_webhook_notifications(options = {})
7
+ get(webhook_notifications_path, options)
8
+ end
9
+
10
+ private
11
+
12
+ def webhook_notifications_path(id = nil)
13
+ id ? "#{PATH}/#{id}" : PATH
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ module Hyperwallet
2
+ module Response
3
+ class Base
4
+ attr_reader :data
5
+
6
+ def self.format(data)
7
+ new(data).format
8
+ end
9
+
10
+ def initialize(data)
11
+ @data = data
12
+ end
13
+
14
+ def format
15
+ if data.is_a?(Array)
16
+ data.map { |item| format_single(item) }
17
+ else
18
+ format_single(data)
19
+ end
20
+ end
21
+
22
+ def to_h(dict, data)
23
+ return {} if data.nil?
24
+
25
+ dict.each_with_object({}) do |(l, r), object|
26
+ object[l] = data[r]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Hyperwallet
2
+ VERSION = '0.0.2'.freeze
3
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'hyperwallet/client'
2
+ require_relative 'hyperwallet/error'
3
+ require_relative 'hyperwallet/version'
4
+
5
+ module Hyperwallet
6
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hyperwallet-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Taylor Brooks
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
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: pry
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: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sinatra
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.1'
139
+ description: A Ruby wrapper for the Hyperwallet API
140
+ email:
141
+ - tbrooks@gmail.com
142
+ executables:
143
+ - rspec
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - Gemfile
149
+ - LICENSE
150
+ - README.md
151
+ - Rakefile
152
+ - bin/rspec
153
+ - hyperwallet.gemspec
154
+ - lib/hyperwallet.rb
155
+ - lib/hyperwallet/client.rb
156
+ - lib/hyperwallet/error.rb
157
+ - lib/hyperwallet/resources/bank_account.rb
158
+ - lib/hyperwallet/resources/payment.rb
159
+ - lib/hyperwallet/resources/user.rb
160
+ - lib/hyperwallet/resources/webhook_notification.rb
161
+ - lib/hyperwallet/response/base.rb
162
+ - lib/hyperwallet/version.rb
163
+ homepage: https://github.com/taylorbrooks/hyperwallet
164
+ licenses:
165
+ - MIT
166
+ metadata: {}
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '2.7'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubygems_version: 3.1.6
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: A Ruby wrapper for the Hyperwallet API
186
+ test_files: []