Sha256: 203ce7fb007c1a5a66031fad6b9b4d24e508397e0f6b8ec0aece27eb280c67ed
Contents?: true
Size: 1.78 KB
Versions: 5
Compression:
Stored size: 1.78 KB
Contents
require 'uri' require 'nokogiri' require_relative 'request' require_relative 'refund_response' module Endicia class Refund < Request # Request a refund for the given tracking number(s) # # tracking_numbers can be an array of strings or a single string # # Returns an Endicia::RefundResponse # def request_refund(tracking_numbers, options = {}) # Build the options for this method with passed in values overriding defaults options.reverse_merge!(default_options) # If we didn't get an array of tracking numbers make it one for simplicity tracking_numbers = tracking_numbers.is_a?(Array) ? tracking_numbers : [tracking_numbers] # Build the XML document builder = Nokogiri::XML::Builder.new do |xml| xml.RefundRequest do # Add the credentials recursive_build_xml_nodes!(xml, @options[:credentials]) # Add the value for Test since this API is different and wants it as a node and not attribute, apparently xml.Test(api_test_mode_value) # Add all tracking numbers xml.RefundList do |xml| tracking_numbers.collect do |tracking_number| xml.PICNumber(tracking_number) end end end end xml_body = builder.to_xml # Log the XML of the request if desired log("ENDICIA REFUND REQUEST: #{format_xml_for_logging(xml_body)}") if options[:log_requests] params = { method: 'RefundRequest', XMLInput: URI.encode(xml_body) } raw_response = self.class.get(els_service_url(params)) # Log the XML of the response if desired log("ENDICIA REFUND RESPONSE: #{format_xml_for_logging(raw_response.body)}") if options[:log_responses] Endicia::RefundResponse.new(raw_response) end end end
Version data entries
5 entries across 5 versions & 1 rubygems