paypal-rest-api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01d19ac0652fbd1ee8cf49d9e5d91d2fd46071b38dfdd5524bf926d2ad9cf6b1
4
- data.tar.gz: 68eb65741710644c17b329fa4dff432671badafa4d1f325e9ba6003be934fb58
3
+ metadata.gz: 9dac5031d1b2e2fe6f58b269801cd0e818280d4ed9b54fafc948e1b758d99b87
4
+ data.tar.gz: 4992abcc8678eca0bbc31702d49e6d6a596f7e614f3e8d6966a5716004adde26
5
5
  SHA512:
6
- metadata.gz: 1728d99460680ef7b8ce8f2cb98447e00a82d7186e0fe3d84c6883e20e089fe1fa52c7041bcce96e5ee415bde6f09959b2cb08cdac55a2e4c1eb1efce7cb36cd
7
- data.tar.gz: 3bcfd687d6e0300dfb0d2463954e7706dd18cfaf176fce356050f4ae5b5ffd62f9f877299c17671ecedd5147947bc570e9d72af75901db87a7e9fd55fd6ebda7
6
+ metadata.gz: 63cc5c666b4483eb92bd6d5282173cb2841b517eb39762421c5c546b23d4c2b1e44fe689495aa75dca15f1a86ac66064e9db7fa77d4d389deb1f0e370de107aa
7
+ data.tar.gz: 2e0e52e4fb9e324017f2af0fefe410daab14b01a3f7b322a686c00fb64ca8c1987bec7ece18958eb0c85327bb25f5f20e5fefdb5111043023efa29a049c8a893
data/README.md CHANGED
@@ -16,9 +16,7 @@ bundle add paypal-rest-api
16
16
 
17
17
  ## Usage
18
18
 
19
- - All APIs accept `:query`, `:body` and `:headers` keyword parameters.
20
- - Some APIs (like show, update, delete) require positional parameters with ID of
21
- a resource.
19
+ - All APIs accept optional `:query`, `:body` and `:headers` keyword parameters.
22
20
  - Response has `#body` method to get parsed JSON body.
23
21
  This body has `symbolized` hash keys.
24
22
  - Response contains methods to get original HTTP response.
@@ -34,13 +32,13 @@ client = PaypalAPI::Client.new(
34
32
  live: false
35
33
  )
36
34
 
37
- # APIs calls examples:
35
+ # Usage example:
38
36
  response = client.orders.create(body: body)
39
37
  response = client.orders.show(order_id)
40
- response = client.payments.capture(authorization_id, headers: headers)
38
+ response = client.authorized_payments.capture(authorization_id, headers: headers)
41
39
  response = client.webhooks.list(query: query)
42
40
 
43
- # Client can be used directly to send request to any path
41
+ # Client also can send requests directly, bypassing specific resources methods
44
42
  response = client.post(path, query: query, body: body, headers: headers)
45
43
  response = client.get(path, query: query, body: body, headers: headers)
46
44
  response = client.patch(path, query: query, body: body, headers: headers)
@@ -48,7 +46,7 @@ response = client.put(path, query: query, body: body, headers: headers)
48
46
  response = client.delete(path, query: query, body: body, headers: headers)
49
47
 
50
48
  # Getting response
51
- response.body # parsed JSON. Parsed with `JSON.load(http_body, symbolyzed_keys: true)`
49
+ response.body # Parsed JSON. JSON is parsed lazyly, keys are symbolized.
52
50
  response[:foo] # Gets :foo attribute from parsed body
53
51
  response.fetch(:foo) # Fetches :foo attribute from parsed body
54
52
  response.http_response # original Net::HTTP::Response
@@ -141,24 +139,25 @@ All APIs can raise error in case of network error or non-2xx response status cod
141
139
  Errors structure:
142
140
 
143
141
  - `PaypalAPI::Error`
144
- - `PaypalAPI::NetworkError` - any network error
145
- - `PaypalAPI::FailedRequest` - any non-2xx code error
146
- - 400 - `PaypalAPI::BadRequestError`
147
- - 401 - `PaypalAPI::UnauthorizedError`
148
- - 403 - `PaypalAPI::ForbiddenError`
149
- - 404 - `PaypalAPI::NotFoundError`
150
- - 405 - `PaypalAPI::MethodNotAllowedError`
151
- - 406 - `PaypalAPI::NotAcceptableError`
152
- - 409 - `PaypalAPI::ConflictError`
153
- - 415 - `PaypalAPI::UnsupportedMediaTypeError`
154
- - 422 - `PaypalAPI::UnprocessableEntityError`
155
- - 429 - `PaypalAPI::TooManyRequestsError`
156
- - 5xx - `PaypalAPI::FatalError`
157
- - 500 - `PaypalAPI::InternalServerError`
158
- - 503 - `PaypalAPI::ServiceUnavailableError`
142
+ - `PaypalAPI::Errors::NetworkError` - any network error
143
+ - `PaypalAPI::Errors::FailedRequest` - any non-2xx code error
144
+ - 400 - `PaypalAPI::Errors::BadRequest`
145
+ - 401 - `PaypalAPI::Errors::Unauthorized`
146
+ - 403 - `PaypalAPI::Errors::Forbidden`
147
+ - 404 - `PaypalAPI::Errors::NotFound`
148
+ - 405 - `PaypalAPI::Errors::MethodNotAllowed`
149
+ - 406 - `PaypalAPI::Errors::NotAcceptable`
150
+ - 409 - `PaypalAPI::Errors::Conflict`
151
+ - 415 - `PaypalAPI::Errors::UnsupportedMediaType`
152
+ - 422 - `PaypalAPI::Errors::UnprocessableEntity`
153
+ - 429 - `PaypalAPI::Errors::TooManyRequests`
154
+ - 5xx - `PaypalAPI::Errors::FatalError`
155
+ - 500 - `PaypalAPI::Errors::InternalServerError`
156
+ - 503 - `PaypalAPI::Errors::ServiceUnavailable`
159
157
 
160
158
  All errors have additional methods:
161
159
 
160
+ - `#paypal_request_id` - PayPal-Request-Id header sent with request
162
161
  - `#response` - Original response object, can be nil in case of NetworkError
163
162
  - `#request` - Original request object
164
163
  - `#error_name` - Original error name
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -4,11 +4,11 @@ module PaypalAPI
4
4
  #
5
5
  # Base class for all PayPal API collections classes
6
6
  #
7
- class Collection
7
+ class APICollection
8
8
  # @return current client
9
9
  attr_reader :client
10
10
 
11
- # Initializes APIs collection
11
+ # Initializes API collection
12
12
  #
13
13
  # @param client [Client] current client
14
14
  #
@@ -6,7 +6,7 @@ module PaypalAPI
6
6
  #
7
7
  # @see https://developer.paypal.com/api/rest/authentication/
8
8
  #
9
- class Authentication < Collection
9
+ class Authentication < APICollection
10
10
  #
11
11
  # Generate access-token API request path
12
12
  #
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaypalAPI
4
+ #
5
+ # Authorized payments APIs `/v2/payments/authorizations`
6
+ #
7
+ # @see https://developer.paypal.com/docs/api/payments/v2
8
+ #
9
+ class AuthorizedPayments < APICollection
10
+ #
11
+ # Common class and instance methods
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
+ # Show details for authorized payment
22
+ #
23
+ # @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_get
24
+ #
25
+ # @param authorization_id [String] Authorization ID
26
+ # @macro request
27
+ #
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)
30
+ end
31
+
32
+ #
33
+ # Capture authorized payment
34
+ #
35
+ # @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture
36
+ #
37
+ # @param authorization_id [String] Authorization ID
38
+ # @macro request
39
+ #
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)
42
+ end
43
+
44
+ # Reauthorize authorized payment
45
+ #
46
+ # @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture
47
+ #
48
+ # @param authorization_id [String] Authorization ID
49
+ # @macro request
50
+ #
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)
53
+ end
54
+
55
+ # Void authorized payment
56
+ #
57
+ # @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_void
58
+ #
59
+ # @param authorization_id [String] Authorization ID
60
+ # @macro request
61
+ #
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)
64
+ end
65
+ end
66
+
67
+ include APIs
68
+ extend APIs
69
+ end
70
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaypalAPI
4
+ #
5
+ # Captured payments APIs `/v2/payments/captures`
6
+ #
7
+ # @see https://developer.paypal.com/docs/api/payments/v2
8
+ #
9
+ class CapturedPayments < APICollection
10
+ #
11
+ # Common class and instance methods
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
+ # Show captured payment details
22
+ #
23
+ # @see https://developer.paypal.com/docs/api/payments/v2/#captures_get
24
+ #
25
+ # @param capture_id [String] Capture ID
26
+ # @macro request
27
+ #
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)
30
+ end
31
+
32
+ #
33
+ # Refund captured payment
34
+ #
35
+ # @see https://developer.paypal.com/docs/api/payments/v2/#captures_refund
36
+ #
37
+ # @param capture_id [String] Capture ID
38
+ # @macro request
39
+ #
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)
42
+ end
43
+ end
44
+
45
+ include APIs
46
+ extend APIs
47
+ end
48
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaypalAPI
4
+ #
5
+ # Merchants can use the Catalog Products API to create products, which are goods and services.
6
+ #
7
+ # @see https://developer.paypal.com/docs/api/catalog-products/v1/
8
+ #
9
+ class CatalogProducts < APICollection
10
+ #
11
+ # Common class and instance methods
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 product
22
+ #
23
+ # @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_create
24
+ #
25
+ # @macro request
26
+ #
27
+ def create(query: nil, body: nil, headers: nil)
28
+ client.post("/v1/catalogs/products", query: query, body: body, headers: headers)
29
+ end
30
+
31
+ #
32
+ # List products
33
+ #
34
+ # @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_list
35
+ #
36
+ # @macro request
37
+ #
38
+ def list(query: nil, body: nil, headers: nil)
39
+ client.get("/v1/catalogs/products", query: query, body: body, headers: headers)
40
+ end
41
+
42
+ #
43
+ # Show product details
44
+ #
45
+ # @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_get
46
+ #
47
+ # @param product_id [String] Product ID
48
+ # @macro request
49
+ #
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)
52
+ end
53
+
54
+ #
55
+ # Update product
56
+ #
57
+ # @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch
58
+ #
59
+ # @param product_id [String] Product ID
60
+ # @macro request
61
+ #
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)
64
+ end
65
+ end
66
+
67
+ include APIs
68
+ extend APIs
69
+ end
70
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaypalAPI
4
+ #
5
+ # Create, update, retrieve, authorize, and capture orders.
6
+ #
7
+ # @see https://developer.paypal.com/docs/api/orders/v2/
8
+ #
9
+ class Orders < APICollection
10
+ #
11
+ # Common class and instance methods
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 Order
22
+ #
23
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
24
+ #
25
+ # @macro request
26
+ #
27
+ def create(query: nil, body: nil, headers: nil)
28
+ client.post("/v2/checkout/orders", query: query, body: body, headers: headers)
29
+ end
30
+
31
+ #
32
+ # Show order details
33
+ #
34
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_get
35
+ #
36
+ # @param id [String] Order ID
37
+ # @macro request
38
+ #
39
+ def show(id, query: nil, body: nil, headers: nil)
40
+ client.get("/v2/checkout/orders/#{id}", query: query, body: body, headers: headers)
41
+ end
42
+
43
+ #
44
+ # Update order
45
+ #
46
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch
47
+ #
48
+ # @param id [String] Order ID
49
+ # @macro request
50
+ #
51
+ def update(id, query: nil, body: nil, headers: nil)
52
+ client.patch("/v2/checkout/orders/#{id}", query: query, body: body, headers: headers)
53
+ end
54
+
55
+ #
56
+ # Confirm the Order
57
+ #
58
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_confirm
59
+ #
60
+ # @param id [String] Order ID
61
+ # @macro request
62
+ #
63
+ def confirm(id, query: nil, body: nil, headers: nil)
64
+ client.post("/v2/checkout/orders/#{id}/confirm-payment-source", query: query, body: body, headers: headers)
65
+ end
66
+
67
+ #
68
+ # Authorize payment for order
69
+ #
70
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize
71
+ #
72
+ # @param id [String] Order ID
73
+ # @macro request
74
+ #
75
+ def authorize(id, query: nil, body: nil, headers: nil)
76
+ client.post("/v2/checkout/orders/#{id}/authorize", query: query, body: body, headers: headers)
77
+ end
78
+
79
+ #
80
+ # Capture payment for order
81
+ #
82
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
83
+ #
84
+ # @param id [String] Order ID
85
+ # @macro request
86
+ #
87
+ def capture(id, query: nil, body: nil, headers: nil)
88
+ client.post("/v2/checkout/orders/#{id}/capture", query: query, body: body, headers: headers)
89
+ end
90
+
91
+ #
92
+ # Add tracking information for an Order
93
+ #
94
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_track_create
95
+ #
96
+ # @param id [String] Order ID
97
+ # @macro request
98
+ #
99
+ def track(id, query: nil, body: nil, headers: nil)
100
+ client.post("/v2/checkout/orders/#{id}/track", query: query, body: body, headers: headers)
101
+ end
102
+
103
+ #
104
+ # Update or cancel tracking information for a PayPal order
105
+ #
106
+ # @see https://developer.paypal.com/docs/api/orders/v2/#orders_trackers_patch
107
+ #
108
+ # @param id [String] Order ID
109
+ # @param tracker_id [String] Tracker ID
110
+ # @macro request
111
+ #
112
+ def update_tracker(id, tracker_id, query: nil, body: nil, headers: nil)
113
+ client.patch("/v2/checkout/orders/#{id}/trackers/#{tracker_id}", query: query, body: body, headers: headers)
114
+ end
115
+ end
116
+
117
+ include APIs
118
+ extend APIs
119
+ end
120
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaypalAPI
4
+ #
5
+ # Refunds APIs `/v2/payments/refunds`
6
+ #
7
+ # @see https://developer.paypal.com/docs/api/payments/v2
8
+ #
9
+ class Refunds < APICollection
10
+ #
11
+ # Common class and instance methods
12
+ #
13
+ module APIs
14
+ #
15
+ # Show refund details
16
+ #
17
+ # @see https://developer.paypal.com/docs/api/payments/v2/#refunds_get
18
+ #
19
+ # @param refund_id [String]
20
+ # @macro request
21
+ #
22
+ def show(refund_id, query: nil, body: nil, headers: nil)
23
+ client.get("/v2/payments/refunds/#{refund_id}", query: query, body: body, headers: headers)
24
+ end
25
+ end
26
+
27
+ include APIs
28
+ extend APIs
29
+ end
30
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaypalAPI
4
+ #
5
+ # Manages tracking information
6
+ #
7
+ # @see https://developer.paypal.com/docs/api/tracking/v1/
8
+ #
9
+ class ShipmentTracking < APICollection
10
+ #
11
+ # Common class and instance methods
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
+ # Add tracking information for multiple PayPal transactions
22
+ #
23
+ # @see https://developer.paypal.com/docs/api/tracking/v1/#trackers-batch_post
24
+ #
25
+ # @macro request
26
+ #
27
+ def add(query: nil, body: nil, headers: nil)
28
+ client.post("/v1/shipping/trackers-batch", query: query, body: body, headers: headers)
29
+ end
30
+
31
+ #
32
+ # Update or cancel tracking information for PayPal transaction
33
+ #
34
+ # @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_put
35
+ #
36
+ # @param id [String] Tracker ID
37
+ # @macro request
38
+ #
39
+ def update(id, query: nil, body: nil, headers: nil)
40
+ client.put("/v1/shipping/trackers/#{id}", query: query, body: body, headers: headers)
41
+ end
42
+
43
+ #
44
+ # Shows tracking information, by tracker ID, for a PayPal transaction.
45
+ #
46
+ # @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_get
47
+ #
48
+ # @param id [String] Order ID
49
+ # @macro request
50
+ #
51
+ def show(id, query: nil, body: nil, headers: nil)
52
+ client.get("/v1/shipping/trackers/#{id}", query: query, body: body, headers: headers)
53
+ end
54
+ end
55
+
56
+ include APIs
57
+ extend APIs
58
+ end
59
+ end