class PayPal::SDK::Core::API::Platform

Use NVP protocol to communicate with Platform Web services

Example

api       = API::Platform.new("AdaptivePayments")
response  = client.request("ConvertCurrency", {
  "baseAmountList"        => { "currency" => [ { "code" => "USD", "amount" => "2.0"} ]},
  "convertToCurrencyList" => { "currencyCode" => ["GBP"] } })

Constants

DEFAULT_END_POINTS
DEFAULT_NVP_HTTP_HEADER
DEFAULT_PARAMS
NVP_AUTH_HEADER

Public Instance Methods

format_error(exception, message) click to toggle source

Format Error object.

Arguments

  • exception – Exception object or HTTP response object.

  • message – Readable error message.

# File lib/paypal-sdk/core/api/platform.rb, line 77
def format_error(exception, message)
  {"responseEnvelope" => {"ack" => "Failure"}, "error" => [{"message" => message}]}
end
format_request(payload) click to toggle source

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.

# 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) click to toggle source

Format the Response object

Arguments

  • action – Requested action name

  • response – HTTP response object

Return

Parse response content using JSON and return the Hash object

# 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].message)
    end
  payload
end
service_endpoint() click to toggle source

Get service end point

# File lib/paypal-sdk/core/api/platform.rb, line 36
def service_endpoint
  config.platform_endpoint || config.endpoint || DEFAULT_END_POINTS[api_mode]
end