Class: PayPal::SDK::Core::API::Merchant

Inherits:
Base
  • Object
show all
Defined in:
lib/paypal-sdk/core/api/merchant.rb

Overview

Use SOAP protocol to communicate with the Merchant Web services

Example

api       = API::Merchant.new
response  = api.request("TransactionSearch", { "StartDate" => "2012-09-30T00:00:00+0530",
   "EndDate" => "2012-10-01T00:00:00+0530" })

Constant Summary collapse

Namespaces =
{
  "@xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/",
  "@xmlns:ns"      => "urn:ebay:api:PayPalAPI",
  "@xmlns:ebl"     => "urn:ebay:apis:eBLBaseComponents",
  "@xmlns:cc"      => "urn:ebay:apis:CoreComponentTypes",
  "@xmlns:ed"      => "urn:ebay:apis:EnhancedDataTypes"
}
ContentKey =
API::DataTypes::Base::ContentKey.to_s
DEFAULT_API_VERSION =
"94.0"
XML_OUT_OPTIONS =
{ 'RootName' => nil, 'AttrPrefix' => true, 'ContentKey' => ContentKey,
'noindent' => true, 'SuppressEmpty' => true }
XML_IN_OPTIONS =
{ 'AttrPrefix' => true, 'ForceArray' => false, 'ContentKey' => ContentKey }
DEFAULT_PARAMS =
Util::OrderedHash.new.merge!({ "ebl:Version" => DEFAULT_API_VERSION })
SKIP_ATTRIBUTES =
[ "@xmlns", "@xsi:type" ]
SOAP_HTTP_AUTH_HEADER =
{
  :authorization  => "X-PP-AUTHORIZATION"
}
SOAP_AUTH_HEADER =
{
  :username   => "ebl:Username",
  :password   => "ebl:Password",
  :signature  => "ebl:Signature",
  :subject    => "ebl:Subject"
}
DEFAULT_END_POINTS =
{
  :sandbox => {
    :three_token  => "https://api-3t.sandbox.paypal.com/2.0/",
    :certificate  => "https://api.sandbox.paypal.com/2.0/"
  },
  :live => {
    :three_token  => "https://api-3t.paypal.com/2.0/",
    :certificate  => "https://api.paypal.com/2.0/"
  },
  :tls_test => {
    :certificate => "test-api.sandbox.paypal.com",
    :three_token => "test-api-3t.sandbox.paypal.com"
  }
}

Constants inherited from Base

Base::API_MODES, Base::DEFAULT_API_MODE

Instance Attribute Summary

Attributes inherited from Base

#http, #service_name, #uri

Instance Method Summary collapse

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, #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

#config, #set_config

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_request(payload) ⇒ Object

Format the HTTP request content

Arguments

  • action – Request action

  • params – Parameters for Action in Hash format

Return

  • request_path – Soap request path. DEFAULT(“/”)

  • request_content – Request content in SOAP format.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/paypal-sdk/core/api/merchant.rb', line 65

def format_request(payload)
  credential_properties  = credential(uri.to_s).properties
  user_auth_header = map_header_value(SOAP_AUTH_HEADER, credential_properties)
  content_key      = payload[:params].keys.first.is_a?(Symbol) ? ContentKey.to_sym : ContentKey.to_s
  xml_out_options  = XML_OUT_OPTIONS.merge( 'ContentKey' => content_key )
  request_content = XmlSimple.xml_out({
    "soapenv:Envelope" => {
    content_key => (
        XmlSimple.xml_out({"soapenv:Header" => { "ns:RequesterCredentials" => {
            "ebl:Credentials" => user_auth_header
         }}}, xml_out_options) +
        XmlSimple.xml_out({"soapenv:Body"   => request_body(payload[:action], payload[:params])}, xml_out_options))
    }.merge(Namespaces)
  }, xml_out_options.merge('noescape' => true))
  header = map_header_value(SOAP_HTTP_AUTH_HEADER, credential_properties)
  payload[:header]  = header.merge(header)
  payload[:body]    = request_content
  payload
end

#format_response(payload) ⇒ Object

Format Response object

Arguments

  • action – Request action

  • response – Response object

Return

Parse the SOAP response content and return Hash object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/paypal-sdk/core/api/merchant.rb', line 91

def format_response(payload)
  payload[:data] =
    if payload[:response].code == "200"
      hash = XmlSimple.xml_in(payload[:response].body, XML_IN_OPTIONS)
      hash = skip_attributes(hash)
      hash["Body"].find{|key_val| key_val[0] =~ /^[^@]/ }[1] || {}
    else
      format_error(payload[:response], payload[:response].message)
    end
  payload
end

#log_http_call(payload) ⇒ Object

Log additional information



104
105
106
107
# File 'lib/paypal-sdk/core/api/merchant.rb', line 104

def log_http_call(payload)
  logger.info "Action: #{payload[:action]}" if payload[:action] and payload[:action] != ""
  super
end

#service_endpointObject

Get services end point



54
55
56
# File 'lib/paypal-sdk/core/api/merchant.rb', line 54

def service_endpoint
  config.merchant_endpoint || config.endpoint || DEFAULT_END_POINTS[api_mode][base_credential_type]
end