paypal_client 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -4
- data/Gemfile +6 -0
- data/README.md +41 -5
- data/lib/paypal_client.rb +4 -17
- data/lib/paypal_client/errors.rb +67 -0
- data/lib/paypal_client/version.rb +1 -1
- data/paypal_client.gemspec +2 -1
- metadata +4 -18
- data/Gemfile.lock +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2279ec026d46415c6c4ba27b11f14fba739eafa9
|
4
|
+
data.tar.gz: 556beeb56f57d81e19750c2e87478462e3d9a587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1150eab9847c8eec968d55a99b94f048c59895d7c0d4947cbd914b889e8d6906449f6c074c81700813e191727727b4890964f1d2271b4c6ebff165ae4bc5508b
|
7
|
+
data.tar.gz: 397a04b94a5b17bf30428daeb1ebe1f34c37f01c1ae5b8d045db6fd929e915dd41a0d96220d53bcc5e1483f0f5a45a84b8cf6ba768038b5962280da48070ed35
|
data/.travis.yml
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
- 2.3.8
|
5
|
+
- 2.4.5
|
6
|
+
- 2.5.3
|
7
|
+
- 2.6.0
|
8
|
+
|
7
9
|
before_install: gem install bundler -v 1.16.1
|
8
10
|
matrix:
|
9
11
|
fast_finish: true
|
10
12
|
script:
|
11
|
-
|
13
|
+
- bundle exec rspec --exclude-pattern "spec/integration/*"
|
14
|
+
jobs:
|
15
|
+
include:
|
16
|
+
- stage: integration
|
17
|
+
name: Run integration against paypal
|
18
|
+
rvm: 2.5.3
|
19
|
+
allow_failure: true
|
20
|
+
script:
|
21
|
+
- bundle exec rspec spec/integration/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# PaypalClient
|
2
2
|
|
3
|
-
|
3
|
+
Ruby client for the [PayPal REST API](https://developer.paypal.com/docs/api/overview/). PayPal offers their own [SDK](https://github.com/paypal/PayPal-Ruby-SDK) but that felt a big heavy and was not seeing active development at the end of 2018.
|
4
4
|
|
5
|
-
|
5
|
+
PaypalClient is using Faraday to make the http calls to the Paypal API and uses ActiveSupport::Cache::MemoryStore to store the auth token required to make authenticated requests to Paypal [more info](https://developer.paypal.com/docs/api/overview/#authentication-and-authorization).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,43 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
To [list payments](https://developer.paypal.com/docs/api/payments/v1/#payment_list)
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
paypal_client = PaypalClient::Client.build
|
29
|
+
response = paypal_client.get('/payments/payments').body
|
30
|
+
response[:payments].each do |payment|
|
31
|
+
puts "Paypal payment with ID: #{payment[:id]}"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
`PaypalClient::Client.build` requires the following environment variables to be set:
|
36
|
+
|
37
|
+
```shell
|
38
|
+
PAYPAL_CLIENT_ID=<paypal_client_id>
|
39
|
+
PAYPAL_CLIENT_SECRET=<paypal_client_secret>
|
40
|
+
PAYPAL_SANDBOX=true
|
41
|
+
```
|
42
|
+
|
43
|
+
You can also configure the client using `PaypalClient::Client.new` as in the following example.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
paypal_client = PaypalClient::Client.new(
|
47
|
+
client_id: <paypal_client_id>,
|
48
|
+
client_secret: <paypal_client_secret>,
|
49
|
+
sandbox: true,
|
50
|
+
cache: Rails.cache,
|
51
|
+
version: 'v1'
|
52
|
+
)
|
53
|
+
```
|
54
|
+
|
55
|
+
## Documentation
|
56
|
+
|
57
|
+
TODO
|
58
|
+
|
59
|
+
## Testing
|
60
|
+
|
61
|
+
There is a good amount of unit testing in `spec/paypal_client_spec.rb`. To run those test **no** active Paypal Developer account is required. To run the tests in `spec/integration/integration_spec.rb` valid Paypal sandbox credentials are required.
|
26
62
|
|
27
63
|
## Development
|
28
64
|
|
@@ -32,8 +68,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
68
|
|
33
69
|
## Contributing
|
34
70
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dennisvdvliet/paypal_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
72
|
|
37
73
|
## Code of Conduct
|
38
74
|
|
39
|
-
Everyone interacting in the PaypalClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
75
|
+
Everyone interacting in the PaypalClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dennisvdvliet/paypal_client/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/paypal_client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'paypal_client/version'
|
4
|
+
require 'paypal_client/errors'
|
4
5
|
require 'active_support/cache'
|
5
6
|
|
6
7
|
module PaypalClient
|
@@ -38,12 +39,13 @@ module PaypalClient
|
|
38
39
|
|
39
40
|
def connection
|
40
41
|
@conn ||= Faraday.new(url: base_url) do |faraday|
|
42
|
+
faraday.use PaypalClient::Errors::Middleware
|
43
|
+
|
41
44
|
faraday.headers = default_headers
|
42
45
|
faraday.response @logger if @logger
|
43
46
|
faraday.request :json
|
44
|
-
faraday.response :json, parser_options: { symbolize_names: true }
|
47
|
+
faraday.response :json, content_type: /\bjson$/, parser_options: { symbolize_names: true }
|
45
48
|
|
46
|
-
faraday.use ErrorMiddleware
|
47
49
|
faraday.adapter *adapter
|
48
50
|
end
|
49
51
|
end
|
@@ -102,19 +104,4 @@ module PaypalClient
|
|
102
104
|
Faraday.default_adapter
|
103
105
|
end
|
104
106
|
end
|
105
|
-
|
106
|
-
class ResponseError < StandardError; end
|
107
|
-
class NotFound < ResponseError; end
|
108
|
-
|
109
|
-
class ErrorMiddleware < Faraday::Response::Middleware
|
110
|
-
ERROR_MAP = {
|
111
|
-
404 => NotFound
|
112
|
-
}.freeze
|
113
|
-
|
114
|
-
def on_complete(response)
|
115
|
-
key = response[:status].to_i
|
116
|
-
raise ERROR_MAP[key], response if ERROR_MAP.key? key
|
117
|
-
raise ResponseError, response if response.status >= 400
|
118
|
-
end
|
119
|
-
end
|
120
107
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module PaypalClient
|
4
|
+
module Errors
|
5
|
+
class Error < StandardError
|
6
|
+
attr_reader :status_code
|
7
|
+
attr_reader :body
|
8
|
+
attr_reader :error
|
9
|
+
attr_reader :error_message
|
10
|
+
|
11
|
+
def initialize(response)
|
12
|
+
@status_code = response.status
|
13
|
+
@body = response.body
|
14
|
+
|
15
|
+
if @body.class == Hash
|
16
|
+
@error = @body[:name] if @body.has_key?(:name)
|
17
|
+
@error_message = @body[:message] if @body.has_key?(:message)
|
18
|
+
else
|
19
|
+
@error = response.reason_phrase if @error.nil?
|
20
|
+
end
|
21
|
+
super(@error)
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
extra = ""
|
26
|
+
extra << " status_code: #{status_code.inspect}" unless status_code.nil?
|
27
|
+
extra << " body: #{body.inspect}" unless body.nil?
|
28
|
+
"#<#{self.class.name}: #{message}#{extra}>"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class InvalidRequest < Error; end
|
33
|
+
class AuthenticationFailure < Error; end
|
34
|
+
class NotAuthorized < Error; end
|
35
|
+
class ResourceNotFound < Error; end
|
36
|
+
class MethodNotSupported < Error; end
|
37
|
+
class MediaTypeNotAcceptable < Error; end
|
38
|
+
class UnsupportedMediaType < Error; end
|
39
|
+
class UnprocessableEntity < Error; end
|
40
|
+
class RateLimitReached < Error; end
|
41
|
+
|
42
|
+
class InternalServerError < Error; end
|
43
|
+
class ServiceUnavailable < Error; end
|
44
|
+
|
45
|
+
class Middleware < ::Faraday::Response::Middleware
|
46
|
+
ERROR_MAP = {
|
47
|
+
400 => InvalidRequest,
|
48
|
+
401 => AuthenticationFailure,
|
49
|
+
403 => NotAuthorized,
|
50
|
+
404 => ResourceNotFound,
|
51
|
+
405 => MethodNotSupported,
|
52
|
+
406 => MediaTypeNotAcceptable,
|
53
|
+
415 => UnsupportedMediaType,
|
54
|
+
422 => UnprocessableEntity,
|
55
|
+
429 => RateLimitReached,
|
56
|
+
500 => InternalServerError,
|
57
|
+
503 => ServiceUnavailable
|
58
|
+
}.freeze
|
59
|
+
|
60
|
+
def on_complete(response)
|
61
|
+
key = response[:status].to_i
|
62
|
+
raise ERROR_MAP[key], response if ERROR_MAP.key? key
|
63
|
+
raise Error, response if response.status >= 400
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/paypal_client.gemspec
CHANGED
@@ -35,5 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
36
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
37
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
-
|
38
|
+
|
39
|
+
spec.required_ruby_version = '>= 2.3'
|
39
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis van der Vliet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop
|
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
97
|
description: Faraday based API client for the PayPal REST API. Includes support for
|
112
98
|
saving the authentication token and limited release endpoints.
|
113
99
|
email:
|
@@ -121,12 +107,12 @@ files:
|
|
121
107
|
- ".travis.yml"
|
122
108
|
- CODE_OF_CONDUCT.md
|
123
109
|
- Gemfile
|
124
|
-
- Gemfile.lock
|
125
110
|
- README.md
|
126
111
|
- Rakefile
|
127
112
|
- bin/console
|
128
113
|
- bin/setup
|
129
114
|
- lib/paypal_client.rb
|
115
|
+
- lib/paypal_client/errors.rb
|
130
116
|
- lib/paypal_client/version.rb
|
131
117
|
- paypal_client.gemspec
|
132
118
|
homepage: https://github.com/dennisvdvliet/paypal_client
|
@@ -141,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
127
|
requirements:
|
142
128
|
- - ">="
|
143
129
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
130
|
+
version: '2.3'
|
145
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
132
|
requirements:
|
147
133
|
- - ">="
|
data/Gemfile.lock
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
paypal_client (0.1.0)
|
5
|
-
activesupport (~> 5)
|
6
|
-
faraday (~> 0.15)
|
7
|
-
faraday_middleware (~> 0.12)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
activesupport (5.2.2)
|
13
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>= 0.7, < 2)
|
15
|
-
minitest (~> 5.1)
|
16
|
-
tzinfo (~> 1.1)
|
17
|
-
ast (2.4.0)
|
18
|
-
concurrent-ruby (1.1.4)
|
19
|
-
diff-lcs (1.3)
|
20
|
-
faraday (0.15.4)
|
21
|
-
multipart-post (>= 1.2, < 3)
|
22
|
-
faraday_middleware (0.12.2)
|
23
|
-
faraday (>= 0.7.4, < 1.0)
|
24
|
-
i18n (1.2.0)
|
25
|
-
concurrent-ruby (~> 1.0)
|
26
|
-
jaro_winkler (1.5.1)
|
27
|
-
minitest (5.11.3)
|
28
|
-
multipart-post (2.0.0)
|
29
|
-
parallel (1.12.1)
|
30
|
-
parser (2.5.3.0)
|
31
|
-
ast (~> 2.4.0)
|
32
|
-
powerpack (0.1.2)
|
33
|
-
rainbow (3.0.0)
|
34
|
-
rake (10.5.0)
|
35
|
-
rspec (3.8.0)
|
36
|
-
rspec-core (~> 3.8.0)
|
37
|
-
rspec-expectations (~> 3.8.0)
|
38
|
-
rspec-mocks (~> 3.8.0)
|
39
|
-
rspec-core (3.8.0)
|
40
|
-
rspec-support (~> 3.8.0)
|
41
|
-
rspec-expectations (3.8.2)
|
42
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.8.0)
|
44
|
-
rspec-mocks (3.8.0)
|
45
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.8.0)
|
47
|
-
rspec-support (3.8.0)
|
48
|
-
rubocop (0.61.1)
|
49
|
-
jaro_winkler (~> 1.5.1)
|
50
|
-
parallel (~> 1.10)
|
51
|
-
parser (>= 2.5, != 2.5.1.1)
|
52
|
-
powerpack (~> 0.1)
|
53
|
-
rainbow (>= 2.2.2, < 4.0)
|
54
|
-
ruby-progressbar (~> 1.7)
|
55
|
-
unicode-display_width (~> 1.4.0)
|
56
|
-
ruby-progressbar (1.10.0)
|
57
|
-
thread_safe (0.3.6)
|
58
|
-
tzinfo (1.2.5)
|
59
|
-
thread_safe (~> 0.1)
|
60
|
-
unicode-display_width (1.4.0)
|
61
|
-
|
62
|
-
PLATFORMS
|
63
|
-
ruby
|
64
|
-
|
65
|
-
DEPENDENCIES
|
66
|
-
bundler (~> 1.16)
|
67
|
-
paypal_client!
|
68
|
-
rake (~> 10.0)
|
69
|
-
rspec (~> 3.0)
|
70
|
-
rubocop
|
71
|
-
|
72
|
-
BUNDLED WITH
|
73
|
-
1.16.1
|