class PayPal::SDK::Core::API::Merchant
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" })
Constants
- ContentKey
- DEFAULT_API_VERSION
- DEFAULT_END_POINTS
- DEFAULT_PARAMS
- Namespaces
- SKIP_ATTRIBUTES
- SOAP_AUTH_HEADER
- SOAP_HTTP_AUTH_HEADER
- XML_IN_OPTIONS
- XML_OUT_OPTIONS
Public Instance Methods
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.
# 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 object
Arguments¶ ↑
-
action
– Request action -
response
– Response object
Return¶ ↑
Parse the SOAP response content and return Hash object
# 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 additional information
PayPal::SDK::Core::Util::HTTPHelper#log_http_call
# 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
Get services end point
# 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
Private Instance Methods
Format Error object.
Arguments¶ ↑
-
exception
– Exception object or HTTP response object. -
message
– Readable error message.
# File lib/paypal-sdk/core/api/merchant.rb, line 147 def format_error(exception, message) { "Ack" => "Failure", "Errors" => { "ShortMessage" => message, "LongMessage" => exception.to_s } } end
Generate soap body
Arguments¶ ↑
-
action
– Request Action name -
params
– Parameters for the action.
# File lib/paypal-sdk/core/api/merchant.rb, line 115 def request_body(action, params = {}) if action and action != "" { "ns:#{action}Req" => { "ns:#{action}Request" => DEFAULT_PARAMS.merge(params) } } else params end end
Remove specified attributes from the given Hash
Arguments¶ ↑
-
hash
– Hash object -
attrs
– (Optional) Attribute list -
content_key
– (Optional) content key
# File lib/paypal-sdk/core/api/merchant.rb, line 128 def skip_attributes(hash, attrs = SKIP_ATTRIBUTES, content_key = ContentKey) hash.each do |key, value| if attrs.include? key hash.delete(key) elsif value.is_a? Hash hash[key] = skip_attributes(value, attrs, content_key) elsif value.is_a? Array and value[0].is_a? Hash value.each_with_index do |array_value, index| value[index] = skip_attributes(array_value, attrs, content_key) end end end ( hash.one? and hash[content_key] ) ? hash[content_key] : ( hash.empty? ? nil : hash ) end