Class: PayPal::SDK::Core::API::Platform
- Defined in:
- lib/paypal-sdk/core/api/platform.rb
Overview
Constant Summary collapse
- NVP_AUTH_HEADER =
{ :username => "X-PAYPAL-SECURITY-USERID", :password => "X-PAYPAL-SECURITY-PASSWORD", :signature => "X-PAYPAL-SECURITY-SIGNATURE", :app_id => "X-PAYPAL-APPLICATION-ID", :authorization => "X-PAYPAL-AUTHORIZATION", :sandbox_email_address => "X-PAYPAL-SANDBOX-EMAIL-ADDRESS", :device_ipaddress => "X-PAYPAL-DEVICE-IPADDRESS" }
- DEFAULT_NVP_HTTP_HEADER =
{ "X-PAYPAL-REQUEST-DATA-FORMAT" => "JSON", "X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON" }
- DEFAULT_PARAMS =
Util::OrderedHash.new.merge!({ "requestEnvelope" => { "errorLanguage" => "en_US" } })
- DEFAULT_END_POINTS =
{ :sandbox => "https://svcs.sandbox.paypal.com/", :live => "https://svcs.paypal.com/", :tls_test => "test-svcs.sandbox.paypal.com" }
Constants inherited from Base
Base::API_MODES, Base::DEFAULT_API_MODE
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#format_error(exception, message) ⇒ Object
Format Error object.
-
#format_request(payload) ⇒ Object
Format the Request.
-
#format_response(payload) ⇒ Object
Format the Response object === Arguments *
action
– Requested action name *response
– HTTP response object === Return Parse response content using JSON and return the Hash object. -
#service_endpoint ⇒ Object
Get service end point.
Methods inherited from Base
#api_call, #api_mode, #default_http_header, #delete, #get, #initialize, #patch, #post, #put, sdk_library_details, #set_config, user_agent
Methods included from Util::HTTPHelper
#configure_ssl, #create_http_connection, #default_ca_file, #encode_www_form, #handle_response, #http_call, #log_http_call, #map_header_value, #new_http, #url_join
Methods included from PayPal::SDK::Core::Authentication
#add_certificate, #base_credential, #base_credential_type, #credential, #set_config, #third_party_credential
Methods included from Configuration
Methods included from Logging
#log_event, #logger, logger, logger=
Constructor Details
This class inherits a constructor from PayPal::SDK::Core::API::Base
Instance Method Details
#format_error(exception, message) ⇒ Object
Format Error object.
Arguments
-
exception
– Exception object or HTTP response object. -
message
– Readable error message.
77 78 79 |
# File 'lib/paypal-sdk/core/api/platform.rb', line 77 def format_error(exception, ) {"responseEnvelope" => {"ack" => "Failure"}, "error" => [{"message" => }]} end |
#format_request(payload) ⇒ Object
Format the Request.
Arguments
-
action
– Action to perform -
params
– Action parameters will be in Hash
Return
-
request_path
– Generated URL for requested action -
request_content
– Format parameters in JSON with default values.
47 48 49 50 51 52 53 54 55 |
# File 'lib/paypal-sdk/core/api/platform.rb', line 47 def format_request(payload) payload[:uri].path = url_join(payload[:uri].path, payload[:action]) credential_properties = credential(payload[:uri].to_s).properties header = map_header_value(NVP_AUTH_HEADER, credential_properties). merge(DEFAULT_NVP_HTTP_HEADER) payload[:header] = header.merge(payload[:header]) payload[:body] = MultiJson.dump(DEFAULT_PARAMS.merge(payload[:params])) payload end |
#format_response(payload) ⇒ Object
Format the Response object
Arguments
-
action
– Requested action name -
response
– HTTP response object
Return
Parse response content using JSON and return the Hash object
63 64 65 66 67 68 69 70 71 |
# File 'lib/paypal-sdk/core/api/platform.rb', line 63 def format_response(payload) payload[:data] = if payload[:response].code == "200" MultiJson.load(payload[:response].body) else format_error(payload[:response], payload[:response].) end payload end |
#service_endpoint ⇒ Object
Get service end point
36 37 38 |
# File 'lib/paypal-sdk/core/api/platform.rb', line 36 def service_endpoint config.platform_endpoint || config.endpoint || DEFAULT_END_POINTS[api_mode] end |