paypal-rest-api 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +23 -15
- data/VERSION +1 -1
- data/lib/paypal-api/request_executor.rb +8 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9974530916382123b35a29697760ddeed6a7c67e53cf9b3c03edabe72d1e878e
|
4
|
+
data.tar.gz: b6ab203108f40419f0ca4b94208e716d26a59c8a94487f632a40b37110d40bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af49071e00c4bf5bc36b5819fc4867164546133f345784a9fd29e146d97b4bddf0fbd5169e75528ad63bc7aff8a7239df2e298cde9a4a9ec4ef60ca78aefcfa9
|
7
|
+
data.tar.gz: 138fb221137c2d726e7b432da2269e17e2ba42f359dae415052d8c47f8f06d729663deb3ae26214fafd96374c6f785760699db83f415aa979e41cebb3ff733da
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ bundle add paypal-rest-api
|
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
11
|
-
- Supported Ruby 2.6 -
|
11
|
+
- Supported Ruby Versions - *(2.6 .. 3.3), head, jruby-9.4, truffleruby-24*
|
12
12
|
- No dependencies;
|
13
13
|
- Automatic authorization & reauthorization;
|
14
14
|
- Auto-retries (configured);
|
@@ -144,12 +144,12 @@ client = PaypalAPI::Client.new(
|
|
144
144
|
Webhooks can be verified [offline](https://developer.paypal.com/api/rest/webhooks/rest/#link-selfverificationmethod)
|
145
145
|
or [online](https://developer.paypal.com/api/rest/webhooks/rest/#link-postbackmethod).
|
146
146
|
Method `PaypalAPI.verify_webhook(webhook_id:, headers:, raw_body:)`
|
147
|
-
verifies webhook. It
|
148
|
-
to ONLINE if
|
147
|
+
verifies webhook. It verifies webhook OFFLINE and fallbacks
|
148
|
+
to ONLINE if initial verification returns false to be sure you don't miss a
|
149
149
|
valid webhook.
|
150
150
|
|
151
|
-
When some required header is missing
|
152
|
-
`PaypalAPI::WebhooksVerifier::MissingHeader` error.
|
151
|
+
When some required header is missing the
|
152
|
+
`PaypalAPI::WebhooksVerifier::MissingHeader` error will be raised.
|
153
153
|
|
154
154
|
Example of Rails controller with webhook verification:
|
155
155
|
|
@@ -192,9 +192,17 @@ Callbacks are registered on `client` object.
|
|
192
192
|
Each callback receive `request` and `context` variables.
|
193
193
|
`context` can be modified manually to save state between callbacks.
|
194
194
|
|
195
|
-
|
195
|
+
Arguments:
|
196
196
|
|
197
|
-
`:
|
197
|
+
- `:before` - (request, context)
|
198
|
+
- `:after_success` - (request, context, response)
|
199
|
+
- `:after_fail` - (request, context, response)
|
200
|
+
- `:after_network_error` - (request, context, error)
|
201
|
+
|
202
|
+
`Context` argument contains `retries_enabled` and `retries_count` and
|
203
|
+
`retry_number` keys by default.
|
204
|
+
|
205
|
+
Examples:
|
198
206
|
|
199
207
|
```ruby
|
200
208
|
PaypalAPI.client.add_callback(:before) do |request, context|
|
@@ -202,7 +210,7 @@ PaypalAPI.client.add_callback(:before) do |request, context|
|
|
202
210
|
context[:starts_at] = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
203
211
|
end
|
204
212
|
|
205
|
-
PaypalAPI.client.add_callback(:
|
213
|
+
PaypalAPI.client.add_callback(:after_success) do |request, context, response|
|
206
214
|
ends_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
207
215
|
duration = ends_at - context[:starts_at]
|
208
216
|
|
@@ -229,7 +237,7 @@ end
|
|
229
237
|
|
230
238
|
PaypalAPI.client.add_callback(:after_network_error) do |request, context, error|
|
231
239
|
SomeLogger.error(
|
232
|
-
'PaypalAPI network connection error'
|
240
|
+
'PaypalAPI network connection error',
|
233
241
|
method: request.method,
|
234
242
|
uri: request.uri.to_s,
|
235
243
|
error: error.message,
|
@@ -316,15 +324,15 @@ All API endpoints accept this parameters:
|
|
316
324
|
|
317
325
|
### Payments
|
318
326
|
|
319
|
-
- `PaypalAPI::
|
320
|
-
- `PaypalAPI::
|
321
|
-
- `PaypalAPI::
|
322
|
-
- `PaypalAPI::
|
327
|
+
- `PaypalAPI::AuthorizedPayments.show`
|
328
|
+
- `PaypalAPI::AuthorizedPayments.capture`
|
329
|
+
- `PaypalAPI::AuthorizedPayments.reauthorize`
|
330
|
+
- `PaypalAPI::AuthorizedPayments.void`
|
323
331
|
|
324
332
|
<!-- -->
|
325
333
|
|
326
|
-
- `PaypalAPI::
|
327
|
-
- `PaypalAPI::
|
334
|
+
- `PaypalAPI::CapturedPayments.show`
|
335
|
+
- `PaypalAPI::CapturedPayments.refund`
|
328
336
|
|
329
337
|
<!-- -->
|
330
338
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -5,7 +5,7 @@ module PaypalAPI
|
|
5
5
|
# Executes PaypalAPI::Request and returns PaypalAPI::Response or raises PaypalAPI::Error
|
6
6
|
#
|
7
7
|
class RequestExecutor
|
8
|
-
attr_reader :client, :request, :http_opts, :
|
8
|
+
attr_reader :client, :request, :http_opts, :retries, :callbacks, :callbacks_context
|
9
9
|
|
10
10
|
def initialize(client, request)
|
11
11
|
@client = client
|
@@ -13,7 +13,7 @@ module PaypalAPI
|
|
13
13
|
@http_opts = {use_ssl: request.uri.is_a?(URI::HTTPS), **client.config.http_opts}
|
14
14
|
@retries = client.config.retries
|
15
15
|
@callbacks = client.callbacks
|
16
|
-
@callbacks_context = {retries_count: retries[:count]}
|
16
|
+
@callbacks_context = {retries_enabled: retries[:enabled], retries_count: retries[:count]}
|
17
17
|
end
|
18
18
|
|
19
19
|
#
|
@@ -35,8 +35,10 @@ module PaypalAPI
|
|
35
35
|
|
36
36
|
run_callbacks(:before)
|
37
37
|
response = execute_net_http_request
|
38
|
-
rescue
|
39
|
-
|
38
|
+
rescue => error
|
39
|
+
raise error if NetworkErrorBuilder::ERRORS.none? { |network_error_class| error.is_a?(network_error_class) }
|
40
|
+
|
41
|
+
will_retry = retries[:enabled] && !retries_limit_reached?(retry_number)
|
40
42
|
callbacks_context[:will_retry] = will_retry
|
41
43
|
run_callbacks(:after_network_error, error)
|
42
44
|
raise NetworkErrorBuilder.call(request: request, error: error) unless will_retry
|
@@ -48,7 +50,7 @@ module PaypalAPI
|
|
48
50
|
run_callbacks(:after_success, response)
|
49
51
|
response
|
50
52
|
else
|
51
|
-
will_retry = retryable?(response, retry_number)
|
53
|
+
will_retry = retries[:enabled] && retryable?(response, retry_number)
|
52
54
|
callbacks_context[:will_retry] = will_retry
|
53
55
|
run_callbacks(:after_fail, response)
|
54
56
|
will_retry ? retry_request(retry_number) : response
|
@@ -104,7 +106,7 @@ module PaypalAPI
|
|
104
106
|
end
|
105
107
|
|
106
108
|
def run_callbacks(callback_name, resp = nil)
|
107
|
-
callbacks[callback_name].each { |callback| callback.call(request,
|
109
|
+
callbacks[callback_name].each { |callback| callback.call(request, callbacks_context, resp) }
|
108
110
|
end
|
109
111
|
end
|
110
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal-rest-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Glushkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PayPal REST API with no dependencies.
|
14
14
|
email:
|