README.md in paypal-rest-api-0.0.3 vs README.md in paypal-rest-api-0.0.4

- old
+ new

@@ -14,76 +14,80 @@ - Automatically added Paypal-Request-Id header for idempotent requests if not provided; ## Usage -- All APIs accept optional `:query`, `:body` and `:headers` keyword parameters. -- Response has `#body` method to get parsed JSON body. - This body has `symbolized` hash keys. -- Response contains methods to get original HTTP response. -- Failed request error (for non `2**` status codes) contains HTTP request and - response -- Failed request error (for network errors) contains request and original error +There are two options: +- Setting global client +- Setting local client (for possibility to use multiple PayPal environments) + +### Setting global client + ```ruby -# Initiate client +# in config/initializers/paypal_rest_api.rb +PaypalAPI.client = PaypalAPI::Client.new( + client_id: ENV['PAYPAL_CLIENT_ID'], + client_secret: ENV['PAYPAL_CLIENT_SECRET'], + live: false +) + +# in your business logic +response = PaypalAPI::Orders.show(order_id) +response = PaypalAPI::Orders.create(body: body) +``` + +### Setting local client + +```ruby +# in your business logic client = PaypalAPI::Client.new( client_id: ENV['PAYPAL_CLIENT_ID'], client_secret: ENV['PAYPAL_CLIENT_SECRET'], live: false ) -# Usage example: -response = client.orders.create(body: body) response = client.orders.show(order_id) -response = client.authorized_payments.capture(authorization_id, headers: headers) -response = client.webhooks.list(query: query) +response = client.orders.create(body: body) +``` -# Client also can send requests directly, bypassing specific resources methods +### Client REST methods + +Client can call HTTP methods directly: + +```ruby response = client.post(path, query: query, body: body, headers: headers) response = client.get(path, query: query, body: body, headers: headers) response = client.patch(path, query: query, body: body, headers: headers) response = client.put(path, query: query, body: body, headers: headers) response = client.delete(path, query: query, body: body, headers: headers) -# Getting response +# Or, after setting global client: +response = PaypalAPI.post(path, query: query, body: body, headers: headers) +response = PaypalAPI.get(path, query: query, body: body, headers: headers) +response = PaypalAPI.patch(path, query: query, body: body, headers: headers) +response = PaypalAPI.put(path, query: query, body: body, headers: headers) +response = PaypalAPI.delete(path, query: query, body: body, headers: headers) +``` + +### Parsing response + +`response.body` is a main method that returns parsed JSON respoonse as a HASH. + +There are also many others helpful methods: + +``` response.body # Parsed JSON. JSON is parsed lazyly, keys are symbolized. response[:foo] # Gets :foo attribute from parsed body response.fetch(:foo) # Fetches :foo attribute from parsed body response.http_response # original Net::HTTP::Response response.http_body # original response string response.http_status # Integer http status response.http_headers # Hash with response headers (keys are strings) response.requested_at # Time when request was sent ``` -Also PaypalAPI client can be added globally and class methods can be used instead: - -```ruby -# in config/initializers/paypal_api.rb -PaypalAPI.client = PaypalAPI::Client.new( - client_id: ENV['PAYPAL_CLIENT_ID'], - client_secret: ENV['PAYPAL_CLIENT_SECRET'], - live: false -) - -# in your business logic -response = PaypalAPI.orders.create(body: body) -response = PaypalAPI.webhooks.verify(body: body) - -# same -PaypalAPI::Orders.create(body: body) -PaypalAPI::Webhooks.verify(body: body) - -# Also now PaypalAPI class can be used as a client -response = PaypalAPI.post(path, query: query, body: body, headers: headers) -response = PaypalAPI.get(path, query: query, body: body, headers: headers) -response = PaypalAPI.patch(path, query: query, body: body, headers: headers) -response = PaypalAPI.put(path, query: query, body: body, headers: headers) -response = PaypalAPI.delete(path, query: query, body: body, headers: headers) -``` - ## Configuration options PaypalAPI client accepts this additional options: `:live`, `:retries`, `:http_opts` ### Option `:live` @@ -166,15 +170,16 @@ - `#error_details` - Parsed PayPal error details found in parsed response (with symbolized keys) ```ruby begin - response = PaypalAPI.payments.capture(authorization_id, body: body) + response = PaypalAPI.authorized_payments.capture(authorization_id, body: body) rescue PaypalAPI::Error => error YourLogger.error( error, context: { + paypal_request_id: error.paypal_request_id, error_name: error.error_name, error_message: error.error_message, error_debug_id: error.error_debug_id, error_details: error.error_details } @@ -182,20 +187,186 @@ # `error.request` and `error.response` methods can be used also end ``` +## APIs + +All API endpoints accept this parameters: + +- `resource_id` - Resource ID (Unless `create`/`list` endpoint) +- `query` - Hash with request query params +- `body` - Hash with request body params +- `headers` - Hash with request headers + +### Orders + +- `PaypalAPI::Orders.create` +- `PaypalAPI::Orders.show` +- `PaypalAPI::Orders.update` +- `PaypalAPI::Orders.confirm` +- `PaypalAPI::Orders.authorize` +- `PaypalAPI::Orders.capture` +- `PaypalAPI::Orders.track` +- `PaypalAPI::Orders.update_tracker` + +### Payments + +- `PaypalAPI::AuthorizedPayment.show` +- `PaypalAPI::AuthorizedPayment.capture` +- `PaypalAPI::AuthorizedPayment.reauthorize` +- `PaypalAPI::AuthorizedPayment.void` + +<!-- --> + +- `PaypalAPI::CapturedPayment.show` +- `PaypalAPI::CapturedPayment.refund` + +<!-- --> + +- `PaypalAPI::Refunds.show` + +### Webhooks + +- `PaypalAPI::Webhooks.create` +- `PaypalAPI::Webhooks.list` +- `PaypalAPI::Webhooks.show` +- `PaypalAPI::Webhooks.update` +- `PaypalAPI::Webhooks.delete` +- `PaypalAPI::Webhooks.event_types` +- `PaypalAPI::Webhooks.verify` + +<!-- --> + +- `PaypalAPI::WebhookEvents.available` +- `PaypalAPI::WebhookEvents.list` +- `PaypalAPI::WebhookEvents.show` +- `PaypalAPI::WebhookEvents.resend` +- `PaypalAPI::WebhookEvents.simulate` + +<!-- --> + +- `PaypalAPI::WebhookLookups.create` +- `PaypalAPI::WebhookLookups.list` +- `PaypalAPI::WebhookLookups.show` +- `PaypalAPI::WebhookLookups.delete` + +### Subscriptions + +- `PaypalAPI::Subscriptions.create` +- `PaypalAPI::Subscriptions.show` +- `PaypalAPI::Subscriptions.update` +- `PaypalAPI::Subscriptions.revise` +- `PaypalAPI::Subscriptions.suspend` +- `PaypalAPI::Subscriptions.cancel` +- `PaypalAPI::Subscriptions.activate` +- `PaypalAPI::Subscriptions.capture` +- `PaypalAPI::Subscriptions.transactions` + +<!-- --> + +- `PaypalAPI::SubscriptionPlans.create` +- `PaypalAPI::SubscriptionPlans.list` +- `PaypalAPI::SubscriptionPlans.show` +- `PaypalAPI::SubscriptionPlans.update` +- `PaypalAPI::SubscriptionPlans.activate` +- `PaypalAPI::SubscriptionPlans.deactivate` +- `PaypalAPI::SubscriptionPlans.update_pricing` + +### Shipment Tracking + +- `PaypalAPI::ShipmentTracking.add` +- `PaypalAPI::ShipmentTracking.update` +- `PaypalAPI::ShipmentTracking.show` + +### Catalog Products + +- `PaypalAPI::CatalogProducts.create` +- `PaypalAPI::CatalogProducts.list` +- `PaypalAPI::CatalogProducts.show` +- `PaypalAPI::CatalogProducts.update` + +### Disputes + +- `PaypalAPI::Disputes.appeal` +- `PaypalAPI::Disputes.make_offer` +- `PaypalAPI::Disputes.show` +- `PaypalAPI::Disputes.update` +- `PaypalAPI::Disputes.send_message` +- `PaypalAPI::Disputes.provide_supporting_info` +- `PaypalAPI::Disputes.update_status` +- `PaypalAPI::Disputes.deny_offer` +- `PaypalAPI::Disputes.provide_evidence` +- `PaypalAPI::Disputes.settle` +- `PaypalAPI::Disputes.acknowledge_return_item` +- `PaypalAPI::Disputes.accept_claim` +- `PaypalAPI::Disputes.list` +- `PaypalAPI::Disputes.escalate` +- `PaypalAPI::Disputes.accept_offer` + +### UserInfo + +- `PaypalAPI::UserInfo.show` + +### Users + +- `PaypalAPI::Users.create` +- `PaypalAPI::Users.list` +- `PaypalAPI::Users.show` +- `PaypalAPI::Users.update` +- `PaypalAPI::Users.delete` + +### Invoices + +- `PaypalAPI::Invoices.create` +- `PaypalAPI::Invoices.list` +- `PaypalAPI::Invoices.show` +- `PaypalAPI::Invoices.update` +- `PaypalAPI::Invoices.delete` +- `PaypalAPI::Invoices.search` +- `PaypalAPI::Invoices.remind` +- `PaypalAPI::Invoices.delete_refund` +- `PaypalAPI::Invoices.delete_payment` +- `PaypalAPI::Invoices.record_refund` +- `PaypalAPI::Invoices.record_payment` +- `PaypalAPI::Invoices.send_invoice` +- `PaypalAPI::Invoices.cancel` +- `PaypalAPI::Invoices.generate_qr_code` +- `PaypalAPI::Invoices.generate_invoice_number` + +### InvoiceTemplates + +- `PaypalAPI::InvoiceTemplates.create` +- `PaypalAPI::InvoiceTemplates.list` +- `PaypalAPI::InvoiceTemplates.show` +- `PaypalAPI::InvoiceTemplates.update` +- `PaypalAPI::InvoiceTemplates.delete` + +### Payouts + +- `PaypalAPI::Payouts.create` +- `PaypalAPI::Payouts.show` +- `PaypalAPI::PayoutItems.show` +- `PaypalAPI::PayoutItems.cancel` + +### ReferencedPayouts + +- `PaypalAPI::ReferencedPayouts.create` +- `PaypalAPI::ReferencedPayouts.show` +- `PaypalAPI::ReferencedPayoutItems.create` +- `PaypalAPI::ReferencedPayoutItems.show` + ## Development ```bash - bundle install rubocop rspec + mdl README.md CHANGELOG.md RELEASE.md ``` ## Contributing -Bug reports and pull requests are welcome on GitHub at <https://github.com/aglushkov/paypal-api>. +Bug reports and pull requests are welcome on GitHub at <https://github.com/aglushkov/paypal-rest-api>. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).