Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

#4875 . work on fixing up the paypal interface code

  • Loading branch information...
commit 37a0e047af3b71b823ffd57bc681ef19c7dfb8fa 1 parent 5e92f3e
@mcr mcr authored
Showing with 62 additions and 47 deletions.
  1. +4 −0 init.rb
  2. +33 −31 lib/caller.rb
  3. +25 −16 lib/profile.rb
View
4 init.rb
@@ -0,0 +1,4 @@
+require 'caller'
+require 'profile'
+require 'utils'
+
View
64 lib/caller.rb
@@ -19,30 +19,15 @@ class Caller
# Proxy server information hash
@@pi=@@profile.proxy_info
- # merchant credentials hash
- @@cre=@@profile.headers
-
# client information such as version, source hash
@@ci=@@profile.client_info
- # endpoints of PayPal hash
- @@ep=@@profile.endpoints
-
#@@PayPalLog=PayPalSDKUtils::Logger.getLogger('PayPal.log')
# CTOR
def initialize(ssl_verify_mode=false)
@ssl_strict = ssl_verify_mode
- @@headers =@@cre
- @profile =PayPalSDKProfiles::Profile.new
- end
-
- # Condition to test whether header value "X-PAYPAL-REQUEST-SOURCE" is available
- @@headers =@@cre
- if (@@headers.has_key?("X-PAYPAL-REQUEST-SOURCE"))
- @@headers["X-PAYPAL-REQUEST-SOURCE"]="RUBY_NVP_SDK_V1.0" + "- " + @@headers["X-PAYPAL-REQUEST-SOURCE"]
- else
- @@headers["X-PAYPAL-REQUEST-SOURCE"]= "RUBY_NVP_SDK_V1.0"
+ @@profile =PayPalSDKProfiles::Profile.new
end
# This method uses HTTP::Net library to talk to PayPal
@@ -60,38 +45,55 @@ def initialize(ssl_verify_mode=false)
# made via a proxy sever, set USE_PROXY flag to true and specify
# proxy server and port information in the profile class.
+ def headers
+ @@profile.headers
+ end
+
+ def config
+ @@profile.config
+ end
def call(requesth)
req_data= "#{hash2cgiString(requesth)}"
- if (@profile.m_use_proxy)
- if( @@pi["USER"].nil? || @@pi["PASSWORD"].nil? )
- http = Net::HTTP::Proxy(@@pi["ADDRESS"],@@pi["PORT"]).new(@@ep["serverURL"], @@pi["PORT"])
- else
- http = Net::HTTP::Proxy(@@pi["ADDRESS"],@@pi["PORT"],@@pi["USER"], @@pi["PASSWORD"]).new(@@ep["SERVER"], @@pi["PORT"])
- end
+ if (@@profile.m_use_proxy)
+ #if( @@pi["USER"].nil? || @@pi["PASSWORD"].nil? )
+ # http = Net::HTTP::Proxy(@@pi["ADDRESS"],@@pi["PORT"]).new(@@profile.endpoints["serverURL"], @@pi["PORT"])
+ #else
+ # http = Net::HTTP::Proxy(@@pi["ADDRESS"],@@pi["PORT"],@@pi["USER"], @@pi["PASSWORD"]).new(@@profile.endpoints["SERVER"], @@pi["PORT"])
+ #end
else
- http = Net::HTTP.new(@@ep["SERVER"], @@ep["PORT"])
+ http = Net::HTTP.new(@@profile.endpoints["SERVER"],
+ @@profile.endpoints["PORT"])
end
http.verify_mode = OpenSSL::SSL::VERIFY_NONE #unless ssl_strict
http.use_ssl = true;
maskedrequest = mask_data(req_data)
- @@PayPalLog ||= Logger.new('log/PayPal.log')
- @@PayPalLog.info "\n"
- @@PayPalLog.info "#{Time.now.strftime("%a %m/%d/%y %H:%M %Z")}- SENT:"
- @@PayPalLog.info "#{CGI.unescape(maskedrequest)}"
+ paypallog.info "\n"
+ paypallog.info "#{Time.now.strftime("%a %m/%d/%y %H:%M %Z")}- SENT:"
+ paypallog.info "#{CGI.unescape(maskedrequest)}"
- contents,unparseddata = http.post2(@@ep["SERVICE"],req_data,@@headers)
- @@PayPalLog.info "\n"
- @@PayPalLog.info "#{Time.now.strftime("%a %m/%d/%y %H:%M %Z")}- RECEIVED:"
- @@PayPalLog.info "#{CGI.unescape(unparseddata)}"
+ contents,unparseddata = http.post2(@@profile.endpoints["SERVICE"],
+ req_data, headers)
+ paypallog.info "\n"
+ paypallog.info "#{Time.now.strftime("%a %m/%d/%y %H:%M %Z")}- RECEIVED:"
+ paypallog.info "#{CGI.unescape(unparseddata)}"
data = CGI::parse(unparseddata)
transaction = Transaction.new(data)
end
+
+ def paypallog
+ self.class.paypallog
+ end
+
+ def self.paypallog
+ @@PayPalLog ||= Logger.new('log/PayPal.log')
+ end
end
+
# Wrapper class to wrap response hash from PayPal as an object and
# to provide nice helper methods
class Transaction
View
41 lib/profile.rb
@@ -3,7 +3,6 @@
module PayPalSDKProfiles
class Profile
- cattr_accessor :headers
cattr_accessor :endpoints
cattr_accessor :client_info
cattr_accessor :proxy_info
@@ -22,21 +21,27 @@ class Profile
###############################################################################################################################
# specify the 3-token values.
- @@headers = {
- "X-PAYPAL-SERVICE-VERSION" => "1.0.0",
- "X-PAYPAL-SECURITY-USERID" =>
- "platfo_1255077030_biz_api1.gmail.com",
- "X-PAYPAL-SECURITY-PASSWORD" =>"1255077037",
- "X-PAYPAL-SECURITY-SIGNATURE" =>
- "Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf",
- "X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T",
- "X-PAYPAL-DEVICE-IPADDRESS"=>"127.0.0.1" ,
- "X-PAYPAL-REQUEST-DATA-FORMAT" => "NV" ,
- "X-PAYPAL-RESPONSE-DATA-FORMAT" => "NV"}
-
+ def headers
+ @headers ||= {
+ "X-PAYPAL-SERVICE-VERSION" => "1.0.0",
+ "X-PAYPAL-SECURITY-USERID" => config[:security_userid],
+ "X-PAYPAL-SECURITY-PASSWORD" => config[:security_password],
+ "X-PAYPAL-SECURITY-SIGNATURE"=> config[:security_signature],
+ "X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T",
+ "X-PAYPAL-DEVICE-IPADDRESS"=>"127.0.0.1" ,
+ "X-PAYPAL-REQUEST-DATA-FORMAT" => "NV" ,
+ "X-PAYPAL-RESPONSE-DATA-FORMAT" => "NV"
+ }
+ end
- # endpoint of PayPal server against which call will be made.
- @@endpoints = {"SERVER" => "svcs.sandbox.paypal.com", "PORT" => "443", "SERVICE" =>""}
+ def endpoints
+ # endpoint of PayPal server against which call will be made.
+ @@endpoints ||= {
+ "SERVER" => config[:nvp_server],
+ "PORT" => config[:nvp_port],
+ "SERVICE" => config[:nvp_service],
+ }
+ end
#Client details to be send in request
@@client_details ={"ipAddress"=>"127.0.0.1", "deviceId"=>"mydevice", "applicationId"=>"APP-80W284485P519543T"}
@@ -62,7 +67,11 @@ def initialize
end
def config
- @config ||= YAML.load_file("#{::Rails.root.to_s}/config/paypal.yml")
+ unless @config
+ yaml = YAML.load_file("#{::Rails.root.to_s}/config/paypal.yml")
+ @config = yaml[RAILS_ENV]
+ end
+ @config
end
def m_use_proxy
Please sign in to comment.
Something went wrong with that request. Please try again.