paypal-rest-api 0.3.1 → 0.4.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 +18 -1
- data/VERSION +1 -1
- data/lib/paypal-api/api_collections/authentication.rb +1 -1
- data/lib/paypal-api/api_collections/authorized_payments.rb +1 -1
- data/lib/paypal-api/api_collections/captured_payments.rb +1 -1
- data/lib/paypal-api/api_collections/catalog_products.rb +1 -1
- data/lib/paypal-api/api_collections/disputes.rb +1 -1
- data/lib/paypal-api/api_collections/invoice_templates.rb +1 -1
- data/lib/paypal-api/api_collections/invoices.rb +1 -1
- data/lib/paypal-api/api_collections/orders.rb +1 -1
- data/lib/paypal-api/api_collections/payment_tokens.rb +70 -0
- data/lib/paypal-api/api_collections/payout_items.rb +1 -1
- data/lib/paypal-api/api_collections/payouts.rb +1 -1
- data/lib/paypal-api/api_collections/referenced_payout_items.rb +2 -2
- data/lib/paypal-api/api_collections/referenced_payouts.rb +1 -1
- data/lib/paypal-api/api_collections/refunds.rb +1 -1
- data/lib/paypal-api/api_collections/setup_tokens.rb +47 -0
- data/lib/paypal-api/api_collections/shipment_tracking.rb +1 -1
- data/lib/paypal-api/api_collections/subscription_plans.rb +1 -1
- data/lib/paypal-api/api_collections/subscriptions.rb +1 -1
- data/lib/paypal-api/api_collections/user_info.rb +1 -1
- data/lib/paypal-api/api_collections/users.rb +2 -2
- data/lib/paypal-api/api_collections/webhook_events.rb +1 -1
- data/lib/paypal-api/api_collections/webhook_lookups.rb +1 -1
- data/lib/paypal-api/api_collections/webhooks.rb +1 -1
- data/lib/paypal-api/client.rb +11 -1
- data/lib/paypal-api/error.rb +3 -1
- data/lib/paypal-api/request.rb +31 -21
- data/lib/paypal-api.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08b9e0e25c50df502751486cfeceb957be78e1951aa919faec3caf9550eec304'
|
4
|
+
data.tar.gz: 0d3894d681057c4721cf3e50a20308ad8e7a19ffb68d73ecab31ca9f112ed2c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49e4bbea2d23037f3af274dddf8fc9c0652b55b06247bf8513531bf41ca925bfc768f9bfa9a98022f3783cf64022906dec19932d8cf2380ef5c4464cff1ba66e
|
7
|
+
data.tar.gz: b8e9d53bab01f8f31da162165191bbe8ecc00b06b9a342966a3400971811d6498c71b598e2f35e7269863d82abdcfa39b92dbcf7734eb6bb79545f52a11fbb48
|
data/README.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
[](https://badge.fury.io/rb/paypal-rest-api)
|
2
|
+
[](https://github.com/aglushkov/paypal-rest-api/actions/workflows/main.yml)
|
3
|
+
[](https://codeclimate.com/github/aglushkov/paypal-rest-api/test_coverage)
|
4
|
+
[](https://codeclimate.com/github/aglushkov/paypal-rest-api/maintainability)
|
5
|
+
|
1
6
|
# PaypalAPI
|
2
7
|
|
3
8
|
## Installation
|
@@ -130,7 +135,7 @@ Retries happen on any network error, on 409, 429, 5xx response status code.
|
|
130
135
|
|
131
136
|
```ruby
|
132
137
|
client = PaypalAPI::Client.new(
|
133
|
-
retries: {count:
|
138
|
+
retries: {enabled: !Rails.env.test?, count: 5, sleep: [0, 0.25, 0.75, 1.5, 2]}
|
134
139
|
# ...
|
135
140
|
)
|
136
141
|
```
|
@@ -351,6 +356,18 @@ All API endpoints accept this parameters:
|
|
351
356
|
- `PaypalAPI::Orders.track`
|
352
357
|
- `PaypalAPI::Orders.update_tracker`
|
353
358
|
|
359
|
+
### Payment Tokens
|
360
|
+
|
361
|
+
- `PaypalAPI::PaymentTokens.create`
|
362
|
+
- `PaypalAPI::PaymentTokens.list`
|
363
|
+
- `PaypalAPI::PaymentTokens.show`
|
364
|
+
- `PaypalAPI::PaymentTokens.delete`
|
365
|
+
|
366
|
+
<!-- -->
|
367
|
+
|
368
|
+
- `PaypalAPI::SetupTokens.create`
|
369
|
+
- `PaypalAPI::SetupTokens.show`
|
370
|
+
|
354
371
|
### Payments
|
355
372
|
|
356
373
|
- `PaypalAPI::AuthorizedPayments.show`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaypalAPI
|
4
|
+
#
|
5
|
+
# Payment Method Tokens
|
6
|
+
#
|
7
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/
|
8
|
+
#
|
9
|
+
class PaymentTokens < APICollection
|
10
|
+
#
|
11
|
+
# Common methods for PaypalAPI::PaymentTokens class and client.payment_tokens instance
|
12
|
+
#
|
13
|
+
module APIs
|
14
|
+
# @!macro [new] request
|
15
|
+
# @param query [Hash, nil] Request query parameters
|
16
|
+
# @param body [Hash, nil] Request body parameters
|
17
|
+
# @param headers [Hash, nil] Request headers
|
18
|
+
# @return [Response] Response object
|
19
|
+
|
20
|
+
#
|
21
|
+
# Create payment token for a given payment source
|
22
|
+
#
|
23
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_create
|
24
|
+
#
|
25
|
+
# @macro request
|
26
|
+
#
|
27
|
+
def create(query: nil, body: nil, headers: nil)
|
28
|
+
client.post("/v3/vault/payment-tokens", query: query, body: body, headers: headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# List all payment tokens
|
33
|
+
#
|
34
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/#customer_payment-tokens_get
|
35
|
+
#
|
36
|
+
# @macro request
|
37
|
+
#
|
38
|
+
def list(query: nil, body: nil, headers: nil)
|
39
|
+
client.get("/v3/vault/payment-tokens", query: query, body: body, headers: headers)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Retrieve a payment token
|
44
|
+
#
|
45
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_get
|
46
|
+
#
|
47
|
+
# @param id [String] ID of the payment token.
|
48
|
+
# @macro request
|
49
|
+
#
|
50
|
+
def show(id, query: nil, body: nil, headers: nil)
|
51
|
+
client.get("/v3/vault/payment-tokens/#{encode(id)}", query: query, body: body, headers: headers)
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Delete payment token
|
56
|
+
#
|
57
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_delete
|
58
|
+
#
|
59
|
+
# @param id [String] ID of the payment token
|
60
|
+
# @macro request
|
61
|
+
#
|
62
|
+
def delete(id, query: nil, body: nil, headers: nil)
|
63
|
+
client.delete("/v3/vault/payment-tokens/#{encode(id)}", query: query, body: body, headers: headers)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
include APIs
|
68
|
+
extend APIs
|
69
|
+
end
|
70
|
+
end
|
@@ -4,11 +4,11 @@ module PaypalAPI
|
|
4
4
|
#
|
5
5
|
# Enables partner merchants and developers to process individual referenced payouts to recipients.
|
6
6
|
#
|
7
|
-
# @
|
7
|
+
# @see https://developer.paypal.com/docs/api/referenced-payouts/v1/
|
8
8
|
#
|
9
9
|
class ReferencedPayoutItems < APICollection
|
10
10
|
#
|
11
|
-
# Common class and instance
|
11
|
+
# Common methods for PaypalAPI::ReferencedPayoutItems class and client.referenced_payout_items instance
|
12
12
|
#
|
13
13
|
module APIs
|
14
14
|
# @!macro [new] request
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaypalAPI
|
4
|
+
#
|
5
|
+
# Payment Setup Tokens
|
6
|
+
#
|
7
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/
|
8
|
+
#
|
9
|
+
class SetupTokens < APICollection
|
10
|
+
#
|
11
|
+
# Common methods for PaypalAPI::SetupTokens class and client.setup_tokens instance
|
12
|
+
#
|
13
|
+
module APIs
|
14
|
+
# @!macro [new] request
|
15
|
+
# @param query [Hash, nil] Request query parameters
|
16
|
+
# @param body [Hash, nil] Request body parameters
|
17
|
+
# @param headers [Hash, nil] Request headers
|
18
|
+
# @return [Response] Response object
|
19
|
+
|
20
|
+
#
|
21
|
+
# Create a setup token
|
22
|
+
#
|
23
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_create
|
24
|
+
#
|
25
|
+
# @macro request
|
26
|
+
#
|
27
|
+
def create(query: nil, body: nil, headers: nil)
|
28
|
+
client.post("/v3/vault/setup-tokens", query: query, body: body, headers: headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Retrieve a setup token
|
33
|
+
#
|
34
|
+
# @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_get
|
35
|
+
#
|
36
|
+
# @param id [String] ID of the setup token.
|
37
|
+
# @macro request
|
38
|
+
#
|
39
|
+
def show(id, query: nil, body: nil, headers: nil)
|
40
|
+
client.get("/v3/vault/setup-tokens/#{encode(id)}", query: query, body: body, headers: headers)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
include APIs
|
45
|
+
extend APIs
|
46
|
+
end
|
47
|
+
end
|
@@ -4,11 +4,11 @@ module PaypalAPI
|
|
4
4
|
#
|
5
5
|
# Managing users APIs
|
6
6
|
#
|
7
|
-
# https://developer.paypal.com/docs/api/identity/v2/
|
7
|
+
# @see https://developer.paypal.com/docs/api/identity/v2/
|
8
8
|
#
|
9
9
|
class Users < APICollection
|
10
10
|
#
|
11
|
-
# Common class and instance
|
11
|
+
# Common methods for PaypalAPI::Users class and client.users instance
|
12
12
|
#
|
13
13
|
module APIs
|
14
14
|
# @!macro [new] request
|
data/lib/paypal-api/client.rb
CHANGED
@@ -241,6 +241,11 @@ module PaypalAPI
|
|
241
241
|
Orders.new(self)
|
242
242
|
end
|
243
243
|
|
244
|
+
# @return [PaymentTokens] PaymentTokens APIs collection
|
245
|
+
def payment_tokens
|
246
|
+
PaymentTokens.new(self)
|
247
|
+
end
|
248
|
+
|
244
249
|
# @return [PayoutItems] PayoutItems APIs collection
|
245
250
|
def payout_items
|
246
251
|
PayoutItems.new(self)
|
@@ -251,7 +256,7 @@ module PaypalAPI
|
|
251
256
|
Payouts.new(self)
|
252
257
|
end
|
253
258
|
|
254
|
-
# @return [
|
259
|
+
# @return [Refunds] Refunds APIs collection
|
255
260
|
def refunds
|
256
261
|
Refunds.new(self)
|
257
262
|
end
|
@@ -266,6 +271,11 @@ module PaypalAPI
|
|
266
271
|
ReferencedPayouts.new(self)
|
267
272
|
end
|
268
273
|
|
274
|
+
# @return [SetupTokens] SetupTokens APIs collection
|
275
|
+
def setup_tokens
|
276
|
+
SetupTokens.new(self)
|
277
|
+
end
|
278
|
+
|
269
279
|
# @return [ShipmentTracking] Shipment Tracking APIs collection
|
270
280
|
def shipment_tracking
|
271
281
|
ShipmentTracking.new(self)
|
data/lib/paypal-api/error.rb
CHANGED
@@ -37,7 +37,6 @@ module PaypalAPI
|
|
37
37
|
#
|
38
38
|
class FailedRequest < Error
|
39
39
|
def initialize(message = nil, request:, response:)
|
40
|
-
super(message)
|
41
40
|
@request = request
|
42
41
|
@response = response
|
43
42
|
|
@@ -48,6 +47,9 @@ module PaypalAPI
|
|
48
47
|
@error_debug_id = data[:debug_id]
|
49
48
|
@error_details = data[:details]
|
50
49
|
@paypal_request_id = request.http_request["paypal-request-id"]
|
50
|
+
|
51
|
+
message += "\n #{response.http_body}" unless data.empty?
|
52
|
+
super(message)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
data/lib/paypal-api/request.rb
CHANGED
@@ -83,27 +83,9 @@ module PaypalAPI
|
|
83
83
|
def build_http_headers(http_request, body, headers)
|
84
84
|
headers = normalize_headers(headers)
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
# We should set json content type header to not get 415 UnsupportedMediaType
|
92
|
-
# error in various APIs
|
93
|
-
#
|
94
|
-
# PayPal requires "application/json" content type even for GET requests
|
95
|
-
# and for POST requests without body.
|
96
|
-
#
|
97
|
-
# Net::HTTP sets default content-type "application/x-www-form-urlencoded"
|
98
|
-
# if not provided
|
99
|
-
#
|
100
|
-
unless headers.key?("content-type")
|
101
|
-
http_request["content-type"] = "application/json"
|
102
|
-
end
|
103
|
-
|
104
|
-
unless headers.key?("paypal-request-id")
|
105
|
-
http_request["paypal-request-id"] = SecureRandom.uuid unless http_request.is_a?(Net::HTTP::Get)
|
106
|
-
end
|
86
|
+
add_authorization_header(http_request, headers)
|
87
|
+
add_content_type_header(http_request, headers)
|
88
|
+
add_paypal_request_id_header(http_request, headers)
|
107
89
|
|
108
90
|
headers.each { |key, value| http_request[key] = value }
|
109
91
|
end
|
@@ -124,5 +106,33 @@ module PaypalAPI
|
|
124
106
|
def normalize_headers(headers)
|
125
107
|
headers.empty? ? headers : headers.transform_keys { |key| key.to_s.downcase }
|
126
108
|
end
|
109
|
+
|
110
|
+
def add_authorization_header(http_request, headers)
|
111
|
+
unless headers.key?("authorization")
|
112
|
+
http_request["authorization"] = client.access_token.authorization_string
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# We should set json content type header to not get 415 UnsupportedMediaType
|
118
|
+
# error in various APIs
|
119
|
+
#
|
120
|
+
# PayPal requires "application/json" content type even for GET requests
|
121
|
+
# and for POST requests without body.
|
122
|
+
#
|
123
|
+
# Net::HTTP sets default content-type "application/x-www-form-urlencoded"
|
124
|
+
# if not provided
|
125
|
+
#
|
126
|
+
def add_content_type_header(http_request, headers)
|
127
|
+
unless headers.key?("content-type")
|
128
|
+
http_request["content-type"] = "application/json"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def add_paypal_request_id_header(http_request, headers)
|
133
|
+
unless headers.key?("paypal-request-id")
|
134
|
+
http_request["paypal-request-id"] = SecureRandom.uuid unless http_request.is_a?(Net::HTTP::Get)
|
135
|
+
end
|
136
|
+
end
|
127
137
|
end
|
128
138
|
end
|
data/lib/paypal-api.rb
CHANGED
@@ -200,11 +200,13 @@ module PaypalAPI
|
|
200
200
|
invoice_templates
|
201
201
|
invoices
|
202
202
|
orders
|
203
|
+
payment_tokens
|
203
204
|
payout_items
|
204
205
|
payouts
|
205
206
|
refunds
|
206
207
|
referenced_payout_items
|
207
208
|
referenced_payouts
|
209
|
+
setup_tokens
|
208
210
|
shipment_tracking
|
209
211
|
subscriptions
|
210
212
|
subscription_plans
|
@@ -253,11 +255,13 @@ require_relative "paypal-api/api_collections/disputes"
|
|
253
255
|
require_relative "paypal-api/api_collections/invoice_templates"
|
254
256
|
require_relative "paypal-api/api_collections/invoices"
|
255
257
|
require_relative "paypal-api/api_collections/orders"
|
258
|
+
require_relative "paypal-api/api_collections/payment_tokens"
|
256
259
|
require_relative "paypal-api/api_collections/payout_items"
|
257
260
|
require_relative "paypal-api/api_collections/payouts"
|
258
261
|
require_relative "paypal-api/api_collections/refunds"
|
259
262
|
require_relative "paypal-api/api_collections/referenced_payout_items"
|
260
263
|
require_relative "paypal-api/api_collections/referenced_payouts"
|
264
|
+
require_relative "paypal-api/api_collections/setup_tokens"
|
261
265
|
require_relative "paypal-api/api_collections/shipment_tracking"
|
262
266
|
require_relative "paypal-api/api_collections/subscriptions"
|
263
267
|
require_relative "paypal-api/api_collections/subscription_plans"
|
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.
|
4
|
+
version: 0.4.0
|
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-09-
|
11
|
+
date: 2024-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PayPal REST API with no dependencies.
|
14
14
|
email:
|
@@ -30,11 +30,13 @@ files:
|
|
30
30
|
- lib/paypal-api/api_collections/invoice_templates.rb
|
31
31
|
- lib/paypal-api/api_collections/invoices.rb
|
32
32
|
- lib/paypal-api/api_collections/orders.rb
|
33
|
+
- lib/paypal-api/api_collections/payment_tokens.rb
|
33
34
|
- lib/paypal-api/api_collections/payout_items.rb
|
34
35
|
- lib/paypal-api/api_collections/payouts.rb
|
35
36
|
- lib/paypal-api/api_collections/referenced_payout_items.rb
|
36
37
|
- lib/paypal-api/api_collections/referenced_payouts.rb
|
37
38
|
- lib/paypal-api/api_collections/refunds.rb
|
39
|
+
- lib/paypal-api/api_collections/setup_tokens.rb
|
38
40
|
- lib/paypal-api/api_collections/shipment_tracking.rb
|
39
41
|
- lib/paypal-api/api_collections/subscription_plans.rb
|
40
42
|
- lib/paypal-api/api_collections/subscriptions.rb
|