Class: PayPalSDK::Caller

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-paypal-extended/caller.rb

Constant Summary collapse

@@headers =

Headers for ?

{'Content-Type' => 'html/text'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile, ssl_verify_mode = false) ⇒ Caller

Creates a new Caller object.

profile - A PayPalSDK::Profile object.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby-paypal-extended/caller.rb', line 17

def initialize(profile, ssl_verify_mode=false)
  @ssl_strict = ssl_verify_mode  
    
  @profile = profile
  
  # Some short names for readability
  @pi = @profile.proxy_info
  @cre = @profile.credentials
  @ci = @profile.client_info
  @ep = @profile.endpoints
end

Instance Attribute Details

#ssl_strictObject (readonly)

Returns the value of attribute ssl_strict.



9
10
11
# File 'lib/ruby-paypal-extended/caller.rb', line 9

def ssl_strict
  @ssl_strict
end

Instance Method Details

#call(request_hash) ⇒ Object

This method uses HTTP::Net library to talk to PayPal WebServices. This is the method what merchants should mostly care about. It expects an hash arugment which has the method name and paramter values of a particular PayPal API. It assumes and uses the credentials of the merchant which is the attribute value of credentials of profile class in PayPalSDKProfiles module. It assumes and uses the client information which is the attribute value of client_info of profile class of PayPalSDKProfiles module. It will also work behind a proxy server. If the calls need be to made via a proxy sever, set USE_PROXY flag to true and specify proxy server and port information in the profile class.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby-paypal-extended/caller.rb', line 35

def call(request_hash)
  req_data = request_post_data(request_hash)
  
 if (@profile.use_proxy?)
    if( @pi["USER"].nil? || @pi["PASSWORD"].nil? )
      http = Net::HTTP::Proxy(@pi["ADDRESS"],@pi["PORT"]).new(@ep["SERVER"], 443)
    else 
      http = Net::HTTP::Proxy(@pi["ADDRESS"],@pi["PORT"],@pi["USER"], @pi["PASSWORD"]).new(@ep["SERVER"], 443)
    end        
  else 
    http = Net::HTTP.new(@ep["SERVER"], 443)                       
  end       
  http.verify_mode    = OpenSSL::SSL::VERIFY_NONE #unless ssl_strict
  http.use_ssl = true;        

  contents, unparseddata = http.post2(@ep["SERVICE"], req_data, @headers)    
  data = CGI::parse(unparseddata)          
  transaction = Transaction.new(data)         
end

#request_post_data(request_hash) ⇒ Object

Builds the post data for sending a request to PayPal, converting hash values to CGI request (NVP) format. It expects an hash arugment which has the method name and paramter values of a particular PayPal API.



58
59
60
# File 'lib/ruby-paypal-extended/caller.rb', line 58

def request_post_data(request_hash)
  "#{hash2cgiString(request_hash)}&#{hash2cgiString(@cre)}&#{hash2cgiString(@ci)}"
end