paypal-rest-api 0.0.3 → 0.1.0
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 +320 -44
- data/VERSION +1 -1
- data/lib/paypal-api/access_token.rb +16 -2
- data/lib/paypal-api/api_collection.rb +29 -0
- data/lib/paypal-api/api_collections/authorized_payments.rb +4 -4
- data/lib/paypal-api/api_collections/captured_payments.rb +2 -2
- data/lib/paypal-api/api_collections/catalog_products.rb +2 -2
- data/lib/paypal-api/api_collections/disputes.rb +188 -0
- data/lib/paypal-api/api_collections/invoice_templates.rb +82 -0
- data/lib/paypal-api/api_collections/invoices.rb +196 -0
- data/lib/paypal-api/api_collections/orders.rb +7 -7
- data/lib/paypal-api/api_collections/payout_items.rb +47 -0
- data/lib/paypal-api/api_collections/payouts.rb +47 -0
- data/lib/paypal-api/api_collections/referenced_payout_items.rb +47 -0
- data/lib/paypal-api/api_collections/referenced_payouts.rb +47 -0
- data/lib/paypal-api/api_collections/refunds.rb +1 -1
- data/lib/paypal-api/api_collections/shipment_tracking.rb +2 -2
- data/lib/paypal-api/api_collections/subscription_plans.rb +106 -0
- data/lib/paypal-api/api_collections/subscriptions.rb +16 -98
- data/lib/paypal-api/api_collections/user_info.rb +47 -0
- data/lib/paypal-api/api_collections/users.rb +96 -0
- data/lib/paypal-api/api_collections/webhook_events.rb +78 -0
- data/lib/paypal-api/api_collections/webhook_lookups.rb +68 -0
- data/lib/paypal-api/api_collections/webhooks.rb +5 -108
- data/lib/paypal-api/client.rb +129 -5
- data/lib/paypal-api/config.rb +6 -2
- data/lib/paypal-api/request.rb +53 -21
- data/lib/paypal-api/request_executor.rb +81 -66
- data/lib/paypal-api/response.rb +42 -5
- data/lib/paypal-api/webhook_verifier/certs_cache.rb +75 -0
- data/lib/paypal-api/webhook_verifier.rb +104 -0
- data/lib/paypal-api.rb +120 -12
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 161078b6b9ff7513fe6634bc4e37c181374858dec0cac4261d5cc662d115787c
|
4
|
+
data.tar.gz: 60346804bbd8a930f695a922a6ce07adaefca26e25f7777e70de0d9f5d87a01a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e340f1e223aa903aed6fde693f4a16dc9cdf0ef3d474a633e171b7890eb016d8c42ef593117385419bd07c366bb257bbc0adbbcab8b193cb150523cd3dcaee46
|
7
|
+
data.tar.gz: 74f017ec1aabca6d9a55599bacc32ee7d7d2c425ec109ec076d2f8072819d95047a07d763ed7b5ba0bd4b96a3b91a3aa3b2404d1a0602c2704028661b544a18b
|
data/README.md
CHANGED
@@ -8,73 +8,63 @@ bundle add paypal-rest-api
|
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
11
|
+
- Supported Ruby 2.6 - current Head
|
11
12
|
- No dependencies;
|
12
13
|
- Automatic authorization & reauthorization;
|
13
14
|
- Auto-retries (configured);
|
14
15
|
- Automatically added Paypal-Request-Id header for idempotent requests if not
|
15
16
|
provided;
|
17
|
+
- Webhooks Offline verification (needs to download certificate once)
|
18
|
+
- Custom callbacks before/after request
|
16
19
|
|
17
20
|
## Usage
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
-
|
23
|
-
|
24
|
-
|
25
|
-
- Failed request error (for network errors) contains request and original error
|
22
|
+
There are two options:
|
23
|
+
|
24
|
+
- Setting global client
|
25
|
+
- Setting local client (for possibility to use multiple PayPal environments)
|
26
|
+
|
27
|
+
### Setting global client
|
26
28
|
|
27
29
|
```ruby
|
28
|
-
#
|
29
|
-
client = PaypalAPI::Client.new(
|
30
|
+
# in config/initializers/paypal_rest_api.rb
|
31
|
+
PaypalAPI.client = PaypalAPI::Client.new(
|
30
32
|
client_id: ENV['PAYPAL_CLIENT_ID'],
|
31
33
|
client_secret: ENV['PAYPAL_CLIENT_SECRET'],
|
32
34
|
live: false
|
33
35
|
)
|
34
36
|
|
35
|
-
#
|
36
|
-
response =
|
37
|
-
response =
|
38
|
-
response = client.authorized_payments.capture(authorization_id, headers: headers)
|
39
|
-
response = client.webhooks.list(query: query)
|
40
|
-
|
41
|
-
# Client also can send requests directly, bypassing specific resources methods
|
42
|
-
response = client.post(path, query: query, body: body, headers: headers)
|
43
|
-
response = client.get(path, query: query, body: body, headers: headers)
|
44
|
-
response = client.patch(path, query: query, body: body, headers: headers)
|
45
|
-
response = client.put(path, query: query, body: body, headers: headers)
|
46
|
-
response = client.delete(path, query: query, body: body, headers: headers)
|
47
|
-
|
48
|
-
# Getting response
|
49
|
-
response.body # Parsed JSON. JSON is parsed lazyly, keys are symbolized.
|
50
|
-
response[:foo] # Gets :foo attribute from parsed body
|
51
|
-
response.fetch(:foo) # Fetches :foo attribute from parsed body
|
52
|
-
response.http_response # original Net::HTTP::Response
|
53
|
-
response.http_body # original response string
|
54
|
-
response.http_status # Integer http status
|
55
|
-
response.http_headers # Hash with response headers (keys are strings)
|
56
|
-
response.requested_at # Time when request was sent
|
37
|
+
# in your business logic
|
38
|
+
response = PaypalAPI::Orders.show(order_id)
|
39
|
+
response = PaypalAPI::Orders.create(body: body)
|
57
40
|
```
|
58
41
|
|
59
|
-
|
42
|
+
### Setting local client
|
60
43
|
|
61
44
|
```ruby
|
62
|
-
# in
|
63
|
-
|
45
|
+
# in your business logic
|
46
|
+
client = PaypalAPI::Client.new(
|
64
47
|
client_id: ENV['PAYPAL_CLIENT_ID'],
|
65
48
|
client_secret: ENV['PAYPAL_CLIENT_SECRET'],
|
66
49
|
live: false
|
67
50
|
)
|
68
51
|
|
69
|
-
|
70
|
-
response =
|
71
|
-
|
52
|
+
response = client.orders.show(order_id)
|
53
|
+
response = client.orders.create(body: body)
|
54
|
+
```
|
72
55
|
|
73
|
-
|
74
|
-
|
75
|
-
|
56
|
+
### Client REST methods
|
57
|
+
|
58
|
+
Client can call HTTP methods directly:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
response = client.post(path, query: query, body: body, headers: headers)
|
62
|
+
response = client.get(path, query: query, body: body, headers: headers)
|
63
|
+
response = client.patch(path, query: query, body: body, headers: headers)
|
64
|
+
response = client.put(path, query: query, body: body, headers: headers)
|
65
|
+
response = client.delete(path, query: query, body: body, headers: headers)
|
76
66
|
|
77
|
-
#
|
67
|
+
# Or, after setting global client:
|
78
68
|
response = PaypalAPI.post(path, query: query, body: body, headers: headers)
|
79
69
|
response = PaypalAPI.get(path, query: query, body: body, headers: headers)
|
80
70
|
response = PaypalAPI.patch(path, query: query, body: body, headers: headers)
|
@@ -82,6 +72,23 @@ response = PaypalAPI.put(path, query: query, body: body, headers: headers)
|
|
82
72
|
response = PaypalAPI.delete(path, query: query, body: body, headers: headers)
|
83
73
|
```
|
84
74
|
|
75
|
+
### Parsing response
|
76
|
+
|
77
|
+
`response.body` is a main method that returns parsed JSON respoonse as a Hash.
|
78
|
+
|
79
|
+
There are also many others helpful methods:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
response.body # Parsed JSON. JSON is parsed lazyly, keys are symbolized.
|
83
|
+
response[:foo] # Gets :foo attribute from parsed body
|
84
|
+
response.fetch(:foo) # Fetches :foo attribute from parsed body
|
85
|
+
response.http_response # original Net::HTTP::Response
|
86
|
+
response.http_body # original response string
|
87
|
+
response.http_status # Integer http status
|
88
|
+
response.http_headers # Hash with response headers (keys are strings)
|
89
|
+
response.request # Request that generates this response
|
90
|
+
```
|
91
|
+
|
85
92
|
## Configuration options
|
86
93
|
|
87
94
|
PaypalAPI client accepts this additional options: `:live`, `:retries`, `:http_opts`
|
@@ -132,6 +139,108 @@ client = PaypalAPI::Client.new(
|
|
132
139
|
)
|
133
140
|
```
|
134
141
|
|
142
|
+
## Webhoooks verification
|
143
|
+
|
144
|
+
Webhooks can be verified [offline](https://developer.paypal.com/api/rest/webhooks/rest/#link-selfverificationmethod)
|
145
|
+
or [online](https://developer.paypal.com/api/rest/webhooks/rest/#link-postbackmethod).
|
146
|
+
Method `PaypalAPI.verify_webhook(webhook_id:, headers:, raw_body:)`
|
147
|
+
verifies webhook. It to verify webhook OFFLINE and it fallbacks
|
148
|
+
to ONLINE if offline verification returns false to be sure you don't miss a
|
149
|
+
valid webhook.
|
150
|
+
|
151
|
+
When some required header is missing it will raise
|
152
|
+
`PaypalAPI::WebhooksVerifier::MissingHeader` error.
|
153
|
+
|
154
|
+
Example of Rails controller with webhook verification:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
class Webhooks::PaypalController < ApplicationController
|
158
|
+
def create
|
159
|
+
# PayPal registered webhook ID for current URL
|
160
|
+
webhook_id = ENV['PAYPAL_WEBHOOK_ID']
|
161
|
+
headers = request.headers # must be a Hash
|
162
|
+
raw_body = request.raw_post # must be a raw String body
|
163
|
+
|
164
|
+
webhook_is_valid = PaypalAPI.verify_webhook(
|
165
|
+
webhook_id: webhook_id,
|
166
|
+
headers: headers,
|
167
|
+
raw_body: raw_body
|
168
|
+
)
|
169
|
+
|
170
|
+
if webhook_is_valid
|
171
|
+
handle_valid_webhook_event(body)
|
172
|
+
else
|
173
|
+
handle_invalid_webhook_event(webhook_id, headers, body)
|
174
|
+
end
|
175
|
+
|
176
|
+
head :no_content
|
177
|
+
end
|
178
|
+
end
|
179
|
+
```
|
180
|
+
|
181
|
+
## Callbacks
|
182
|
+
|
183
|
+
Callbacks list:
|
184
|
+
|
185
|
+
- `:before` - Runs before request
|
186
|
+
- `:after_success` - Runs after getting successful response
|
187
|
+
- `:after_fail` - Runs after getting failed response (non-2xx) status code
|
188
|
+
- `:after_network_error` - Runs after getting network error
|
189
|
+
|
190
|
+
Callbacks are registered on `client` object.
|
191
|
+
|
192
|
+
Each callback receive `request` and `context` variables.
|
193
|
+
`context` can be modified manually to save state between callbacks.
|
194
|
+
|
195
|
+
`:after_success` and `:after_fail` callbacks have additional `response` argument
|
196
|
+
|
197
|
+
`:after_network_error` callback has additional `error` argument
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
PaypalAPI.client.add_callback(:before) do |request, context|
|
201
|
+
context[:request_id] = SecureRandom.hex(3)
|
202
|
+
context[:starts_at] = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
203
|
+
end
|
204
|
+
|
205
|
+
PaypalAPI.client.add_callback(:after) do |request, context, response|
|
206
|
+
ends_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
207
|
+
duration = ends_at - context[:starts_at]
|
208
|
+
|
209
|
+
SomeLogger.debug(
|
210
|
+
'PaypalAPI success request',
|
211
|
+
method: request.method,
|
212
|
+
uri: request.uri.to_s,
|
213
|
+
duration: duration
|
214
|
+
)
|
215
|
+
end
|
216
|
+
|
217
|
+
PaypalAPI.client.add_callback(:after_fail) do |request, context, response|
|
218
|
+
SomeLogger.error(
|
219
|
+
'PaypalAPI request failed',
|
220
|
+
method: request.method,
|
221
|
+
uri: request.uri.to_s,
|
222
|
+
response_status: response.http_status,
|
223
|
+
response_body: response.http_body,
|
224
|
+
will_retry: context[:will_retry],
|
225
|
+
retry_number: context[:retry_number],
|
226
|
+
retry_count: context[:retry_count]
|
227
|
+
)
|
228
|
+
end
|
229
|
+
|
230
|
+
PaypalAPI.client.add_callback(:after_network_error) do |request, context, error|
|
231
|
+
SomeLogger.error(
|
232
|
+
'PaypalAPI network connection error'
|
233
|
+
method: request.method,
|
234
|
+
uri: request.uri.to_s,
|
235
|
+
error: error.message,
|
236
|
+
paypal_request_id: request.headers['paypal-request-id'],
|
237
|
+
will_retry: context[:will_retry],
|
238
|
+
retry_number: context[:retry_number],
|
239
|
+
retry_count: context[:retry_count]
|
240
|
+
)
|
241
|
+
end
|
242
|
+
```
|
243
|
+
|
135
244
|
## Errors
|
136
245
|
|
137
246
|
All APIs can raise error in case of network error or non-2xx response status code.
|
@@ -168,11 +277,12 @@ All errors have additional methods:
|
|
168
277
|
|
169
278
|
```ruby
|
170
279
|
begin
|
171
|
-
response = PaypalAPI.
|
280
|
+
response = PaypalAPI.authorized_payments.capture(authorization_id, body: body)
|
172
281
|
rescue PaypalAPI::Error => error
|
173
282
|
YourLogger.error(
|
174
283
|
error,
|
175
284
|
context: {
|
285
|
+
paypal_request_id: error.paypal_request_id,
|
176
286
|
error_name: error.error_name,
|
177
287
|
error_message: error.error_message,
|
178
288
|
error_debug_id: error.error_debug_id,
|
@@ -184,17 +294,183 @@ end
|
|
184
294
|
|
185
295
|
```
|
186
296
|
|
297
|
+
## APIs
|
298
|
+
|
299
|
+
All API endpoints accept this parameters:
|
300
|
+
|
301
|
+
- `resource_id` - Resource ID (Unless `create`/`list` endpoint)
|
302
|
+
- `query` - Hash with request query params
|
303
|
+
- `body` - Hash with request body params
|
304
|
+
- `headers` - Hash with request headers
|
305
|
+
|
306
|
+
### Orders
|
307
|
+
|
308
|
+
- `PaypalAPI::Orders.create`
|
309
|
+
- `PaypalAPI::Orders.show`
|
310
|
+
- `PaypalAPI::Orders.update`
|
311
|
+
- `PaypalAPI::Orders.confirm`
|
312
|
+
- `PaypalAPI::Orders.authorize`
|
313
|
+
- `PaypalAPI::Orders.capture`
|
314
|
+
- `PaypalAPI::Orders.track`
|
315
|
+
- `PaypalAPI::Orders.update_tracker`
|
316
|
+
|
317
|
+
### Payments
|
318
|
+
|
319
|
+
- `PaypalAPI::AuthorizedPayment.show`
|
320
|
+
- `PaypalAPI::AuthorizedPayment.capture`
|
321
|
+
- `PaypalAPI::AuthorizedPayment.reauthorize`
|
322
|
+
- `PaypalAPI::AuthorizedPayment.void`
|
323
|
+
|
324
|
+
<!-- -->
|
325
|
+
|
326
|
+
- `PaypalAPI::CapturedPayment.show`
|
327
|
+
- `PaypalAPI::CapturedPayment.refund`
|
328
|
+
|
329
|
+
<!-- -->
|
330
|
+
|
331
|
+
- `PaypalAPI::Refunds.show`
|
332
|
+
|
333
|
+
### Webhooks
|
334
|
+
|
335
|
+
- `PaypalAPI::Webhooks.create`
|
336
|
+
- `PaypalAPI::Webhooks.list`
|
337
|
+
- `PaypalAPI::Webhooks.show`
|
338
|
+
- `PaypalAPI::Webhooks.update`
|
339
|
+
- `PaypalAPI::Webhooks.delete`
|
340
|
+
- `PaypalAPI::Webhooks.event_types`
|
341
|
+
- `PaypalAPI::Webhooks.verify`
|
342
|
+
|
343
|
+
<!-- -->
|
344
|
+
|
345
|
+
- `PaypalAPI::WebhookEvents.available`
|
346
|
+
- `PaypalAPI::WebhookEvents.list`
|
347
|
+
- `PaypalAPI::WebhookEvents.show`
|
348
|
+
- `PaypalAPI::WebhookEvents.resend`
|
349
|
+
- `PaypalAPI::WebhookEvents.simulate`
|
350
|
+
|
351
|
+
<!-- -->
|
352
|
+
|
353
|
+
- `PaypalAPI::WebhookLookups.create`
|
354
|
+
- `PaypalAPI::WebhookLookups.list`
|
355
|
+
- `PaypalAPI::WebhookLookups.show`
|
356
|
+
- `PaypalAPI::WebhookLookups.delete`
|
357
|
+
|
358
|
+
### Subscriptions
|
359
|
+
|
360
|
+
- `PaypalAPI::Subscriptions.create`
|
361
|
+
- `PaypalAPI::Subscriptions.show`
|
362
|
+
- `PaypalAPI::Subscriptions.update`
|
363
|
+
- `PaypalAPI::Subscriptions.revise`
|
364
|
+
- `PaypalAPI::Subscriptions.suspend`
|
365
|
+
- `PaypalAPI::Subscriptions.cancel`
|
366
|
+
- `PaypalAPI::Subscriptions.activate`
|
367
|
+
- `PaypalAPI::Subscriptions.capture`
|
368
|
+
- `PaypalAPI::Subscriptions.transactions`
|
369
|
+
|
370
|
+
<!-- -->
|
371
|
+
|
372
|
+
- `PaypalAPI::SubscriptionPlans.create`
|
373
|
+
- `PaypalAPI::SubscriptionPlans.list`
|
374
|
+
- `PaypalAPI::SubscriptionPlans.show`
|
375
|
+
- `PaypalAPI::SubscriptionPlans.update`
|
376
|
+
- `PaypalAPI::SubscriptionPlans.activate`
|
377
|
+
- `PaypalAPI::SubscriptionPlans.deactivate`
|
378
|
+
- `PaypalAPI::SubscriptionPlans.update_pricing`
|
379
|
+
|
380
|
+
### Shipment Tracking
|
381
|
+
|
382
|
+
- `PaypalAPI::ShipmentTracking.add`
|
383
|
+
- `PaypalAPI::ShipmentTracking.update`
|
384
|
+
- `PaypalAPI::ShipmentTracking.show`
|
385
|
+
|
386
|
+
### Catalog Products
|
387
|
+
|
388
|
+
- `PaypalAPI::CatalogProducts.create`
|
389
|
+
- `PaypalAPI::CatalogProducts.list`
|
390
|
+
- `PaypalAPI::CatalogProducts.show`
|
391
|
+
- `PaypalAPI::CatalogProducts.update`
|
392
|
+
|
393
|
+
### Disputes
|
394
|
+
|
395
|
+
- `PaypalAPI::Disputes.appeal`
|
396
|
+
- `PaypalAPI::Disputes.make_offer`
|
397
|
+
- `PaypalAPI::Disputes.show`
|
398
|
+
- `PaypalAPI::Disputes.update`
|
399
|
+
- `PaypalAPI::Disputes.send_message`
|
400
|
+
- `PaypalAPI::Disputes.provide_supporting_info`
|
401
|
+
- `PaypalAPI::Disputes.update_status`
|
402
|
+
- `PaypalAPI::Disputes.deny_offer`
|
403
|
+
- `PaypalAPI::Disputes.provide_evidence`
|
404
|
+
- `PaypalAPI::Disputes.settle`
|
405
|
+
- `PaypalAPI::Disputes.acknowledge_return_item`
|
406
|
+
- `PaypalAPI::Disputes.accept_claim`
|
407
|
+
- `PaypalAPI::Disputes.list`
|
408
|
+
- `PaypalAPI::Disputes.escalate`
|
409
|
+
- `PaypalAPI::Disputes.accept_offer`
|
410
|
+
|
411
|
+
### UserInfo
|
412
|
+
|
413
|
+
- `PaypalAPI::UserInfo.show`
|
414
|
+
|
415
|
+
### Users
|
416
|
+
|
417
|
+
- `PaypalAPI::Users.create`
|
418
|
+
- `PaypalAPI::Users.list`
|
419
|
+
- `PaypalAPI::Users.show`
|
420
|
+
- `PaypalAPI::Users.update`
|
421
|
+
- `PaypalAPI::Users.delete`
|
422
|
+
|
423
|
+
### Invoices
|
424
|
+
|
425
|
+
- `PaypalAPI::Invoices.create`
|
426
|
+
- `PaypalAPI::Invoices.list`
|
427
|
+
- `PaypalAPI::Invoices.show`
|
428
|
+
- `PaypalAPI::Invoices.update`
|
429
|
+
- `PaypalAPI::Invoices.delete`
|
430
|
+
- `PaypalAPI::Invoices.search`
|
431
|
+
- `PaypalAPI::Invoices.remind`
|
432
|
+
- `PaypalAPI::Invoices.delete_refund`
|
433
|
+
- `PaypalAPI::Invoices.delete_payment`
|
434
|
+
- `PaypalAPI::Invoices.record_refund`
|
435
|
+
- `PaypalAPI::Invoices.record_payment`
|
436
|
+
- `PaypalAPI::Invoices.send_invoice`
|
437
|
+
- `PaypalAPI::Invoices.cancel`
|
438
|
+
- `PaypalAPI::Invoices.generate_qr_code`
|
439
|
+
- `PaypalAPI::Invoices.generate_invoice_number`
|
440
|
+
|
441
|
+
### InvoiceTemplates
|
442
|
+
|
443
|
+
- `PaypalAPI::InvoiceTemplates.create`
|
444
|
+
- `PaypalAPI::InvoiceTemplates.list`
|
445
|
+
- `PaypalAPI::InvoiceTemplates.show`
|
446
|
+
- `PaypalAPI::InvoiceTemplates.update`
|
447
|
+
- `PaypalAPI::InvoiceTemplates.delete`
|
448
|
+
|
449
|
+
### Payouts
|
450
|
+
|
451
|
+
- `PaypalAPI::Payouts.create`
|
452
|
+
- `PaypalAPI::Payouts.show`
|
453
|
+
- `PaypalAPI::PayoutItems.show`
|
454
|
+
- `PaypalAPI::PayoutItems.cancel`
|
455
|
+
|
456
|
+
### ReferencedPayouts
|
457
|
+
|
458
|
+
- `PaypalAPI::ReferencedPayouts.create`
|
459
|
+
- `PaypalAPI::ReferencedPayouts.show`
|
460
|
+
- `PaypalAPI::ReferencedPayoutItems.create`
|
461
|
+
- `PaypalAPI::ReferencedPayoutItems.show`
|
462
|
+
|
187
463
|
## Development
|
188
464
|
|
189
465
|
```bash
|
190
|
-
bundle install
|
191
466
|
rubocop
|
192
467
|
rspec
|
468
|
+
mdl README.md CHANGELOG.md RELEASE.md
|
193
469
|
```
|
194
470
|
|
195
471
|
## Contributing
|
196
472
|
|
197
|
-
Bug reports and pull requests are welcome on GitHub at <https://github.com/aglushkov/paypal-api>.
|
473
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/aglushkov/paypal-rest-api>.
|
198
474
|
|
199
475
|
## License
|
200
476
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -4,8 +4,20 @@ module PaypalAPI
|
|
4
4
|
#
|
5
5
|
# AccessToken object stores authorization string and its expire time.
|
6
6
|
#
|
7
|
+
# @api private
|
8
|
+
#
|
7
9
|
class AccessToken
|
8
|
-
|
10
|
+
# Time when access token request was sent
|
11
|
+
# @return [Time] Time
|
12
|
+
attr_reader :requested_at
|
13
|
+
|
14
|
+
# Time when access token request expires
|
15
|
+
# @return [Time] Time
|
16
|
+
attr_reader :expires_at
|
17
|
+
|
18
|
+
# Authorization string
|
19
|
+
# @return [String] Authorization string
|
20
|
+
attr_reader :authorization_string
|
9
21
|
|
10
22
|
#
|
11
23
|
# Initializes AccessToken object
|
@@ -32,7 +44,9 @@ module PaypalAPI
|
|
32
44
|
end
|
33
45
|
|
34
46
|
#
|
35
|
-
# Instance representation string
|
47
|
+
# Instance representation string
|
48
|
+
#
|
49
|
+
# @return [String] Inspect value
|
36
50
|
#
|
37
51
|
def inspect
|
38
52
|
"#<#{self.class.name} methods: (requested_at, expires_at, expired?, authorization_string)>"
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "uri"
|
4
|
+
|
3
5
|
module PaypalAPI
|
4
6
|
#
|
5
7
|
# Base class for all PayPal API collections classes
|
@@ -22,5 +24,32 @@ module PaypalAPI
|
|
22
24
|
def self.client
|
23
25
|
PaypalAPI.client
|
24
26
|
end
|
27
|
+
|
28
|
+
# Encodes URI component
|
29
|
+
# @param id [String] Unencoded URI component
|
30
|
+
# @return [String] Encoded URI component
|
31
|
+
def encode(id)
|
32
|
+
self.class.encode(id)
|
33
|
+
end
|
34
|
+
|
35
|
+
# :nocov:
|
36
|
+
if URI.respond_to?(:encode_uri_component)
|
37
|
+
# Encodes URI component
|
38
|
+
# @param id [String] Unencoded URI component
|
39
|
+
# @return [String] Encoded URI component
|
40
|
+
def self.encode(id)
|
41
|
+
URI.encode_uri_component(id)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
# Encodes URI component
|
45
|
+
# @param id [String] Unencoded URI component
|
46
|
+
# @return [String] Encoded URI component
|
47
|
+
def self.encode(id)
|
48
|
+
encoded_id = URI.encode_www_form_component(id)
|
49
|
+
encoded_id.gsub!("+", "%20")
|
50
|
+
encoded_id
|
51
|
+
end
|
52
|
+
end
|
53
|
+
# :nocov:
|
25
54
|
end
|
26
55
|
end
|
@@ -26,7 +26,7 @@ module PaypalAPI
|
|
26
26
|
# @macro request
|
27
27
|
#
|
28
28
|
def show(authorization_id, query: nil, body: nil, headers: nil)
|
29
|
-
client.get("/v2/payments/authorizations/#{authorization_id}", query: query, body: body, headers: headers)
|
29
|
+
client.get("/v2/payments/authorizations/#{encode(authorization_id)}", query: query, body: body, headers: headers)
|
30
30
|
end
|
31
31
|
|
32
32
|
#
|
@@ -38,7 +38,7 @@ module PaypalAPI
|
|
38
38
|
# @macro request
|
39
39
|
#
|
40
40
|
def capture(authorization_id, query: nil, body: nil, headers: nil)
|
41
|
-
client.post("/v2/payments/authorizations/#{authorization_id}/capture", query: query, body: body, headers: headers)
|
41
|
+
client.post("/v2/payments/authorizations/#{encode(authorization_id)}/capture", query: query, body: body, headers: headers)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Reauthorize authorized payment
|
@@ -49,7 +49,7 @@ module PaypalAPI
|
|
49
49
|
# @macro request
|
50
50
|
#
|
51
51
|
def reauthorize(authorization_id, query: nil, body: nil, headers: nil)
|
52
|
-
client.post("/v2/payments/authorizations/#{authorization_id}/reauthorize", query: query, body: body, headers: headers)
|
52
|
+
client.post("/v2/payments/authorizations/#{encode(authorization_id)}/reauthorize", query: query, body: body, headers: headers)
|
53
53
|
end
|
54
54
|
|
55
55
|
# Void authorized payment
|
@@ -60,7 +60,7 @@ module PaypalAPI
|
|
60
60
|
# @macro request
|
61
61
|
#
|
62
62
|
def void(authorization_id, query: nil, body: nil, headers: nil)
|
63
|
-
client.post("/v2/payments/authorizations/#{authorization_id}/void", query: query, body: body, headers: headers)
|
63
|
+
client.post("/v2/payments/authorizations/#{encode(authorization_id)}/void", query: query, body: body, headers: headers)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -26,7 +26,7 @@ module PaypalAPI
|
|
26
26
|
# @macro request
|
27
27
|
#
|
28
28
|
def show(capture_id, query: nil, body: nil, headers: nil)
|
29
|
-
client.get("/v2/payments/captures/#{capture_id}", query: query, body: body, headers: headers)
|
29
|
+
client.get("/v2/payments/captures/#{encode(capture_id)}", query: query, body: body, headers: headers)
|
30
30
|
end
|
31
31
|
|
32
32
|
#
|
@@ -38,7 +38,7 @@ module PaypalAPI
|
|
38
38
|
# @macro request
|
39
39
|
#
|
40
40
|
def refund(capture_id, query: nil, body: nil, headers: nil)
|
41
|
-
client.post("/v2/payments/captures/#{capture_id}/refund", query: query, body: body, headers: headers)
|
41
|
+
client.post("/v2/payments/captures/#{encode(capture_id)}/refund", query: query, body: body, headers: headers)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -48,7 +48,7 @@ module PaypalAPI
|
|
48
48
|
# @macro request
|
49
49
|
#
|
50
50
|
def show(product_id, query: nil, body: nil, headers: nil)
|
51
|
-
client.get("/v1/catalogs/products/#{product_id}", query: query, body: body, headers: headers)
|
51
|
+
client.get("/v1/catalogs/products/#{encode(product_id)}", query: query, body: body, headers: headers)
|
52
52
|
end
|
53
53
|
|
54
54
|
#
|
@@ -60,7 +60,7 @@ module PaypalAPI
|
|
60
60
|
# @macro request
|
61
61
|
#
|
62
62
|
def update(product_id, query: nil, body: nil, headers: nil)
|
63
|
-
client.patch("/v1/catalogs/products/#{product_id}", query: query, body: body, headers: headers)
|
63
|
+
client.patch("/v1/catalogs/products/#{encode(product_id)}", query: query, body: body, headers: headers)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|