Module: Payment3p
- Defined in:
- lib/payment_3p.rb,
lib/payment_3p/railtie.rb,
lib/payment_3p/version.rb,
lib/payment_3p/generators/config_generator.rb
Defined Under Namespace
Modules: Generators Classes: Railtie
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .config ⇒ Object
-
.configure(opts = {}) ⇒ Object
Configure through hash.
-
.configure_with(path_to_yaml_file) ⇒ Object
Configure through yaml file.
-
.gem_root ⇒ Object
Your code goes here…
-
.payment_url(parameters) ⇒ Object
vpc_MerchTxnRef, vpc_ReturnURL, vpc_OrderInfo, vpc_Amount.
-
.validate_response(response) ⇒ Object
TODO: another validation needs to be added for the transaction number and amount.
Class Method Details
.config ⇒ Object
35 36 37 |
# File 'lib/payment_3p.rb', line 35 def self.config @config end |
.configure(opts = {}) ⇒ Object
Configure through hash
18 19 20 |
# File 'lib/payment_3p.rb', line 18 def self.configure(opts = {}) opts.each {|k,v| @config[k] = v if @valid_config_keys.include? k} end |
.configure_with(path_to_yaml_file) ⇒ Object
Configure through yaml file
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/payment_3p.rb', line 23 def self.configure_with(path_to_yaml_file) begin config = HashWithIndifferentAccess.new(YAML::load(IO.read(path_to_yaml_file))) rescue Errno::ENOENT Rails.logger.warn("YAML configuration file couldn't be found. Using defaults."); return rescue Psych::SyntaxError Rails.logger.warn("YAML configuration file contains invalid syntax. Using defaults."); return end configure(config) end |
.gem_root ⇒ Object
Your code goes here…
9 10 11 |
# File 'lib/payment_3p.rb', line 9 def self.gem_root File. '../..', __FILE__ end |
.payment_url(parameters) ⇒ Object
vpc_MerchTxnRef, vpc_ReturnURL, vpc_OrderInfo, vpc_Amount
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/payment_3p.rb', line 41 def self.payment_url parameters vpcURL=@config[:payment_endpoint] md5HashData = @config[:secure_secret] vpc_parameters = {vpc_Version: "1", vpc_Command: "pay", vpc_AccessCode: @config[:vpc_AccessCode], vpc_MerchTxnRef: parameters[:vpc_MerchTxnRef], vpc_Merchant: @config[:vpc_Merchant], vpc_OrderInfo: parameters[:vpc_OrderInfo], vpc_Amount: parameters[:vpc_Amount], vpc_Locale: "en", vpc_ReturnURL: parameters[:vpc_ReturnURL]} vpc_ordered_parameters = vpc_parameters.sort_by {|key, value| key} #returns array of arrays url_params = [] vpc_ordered_parameters.each do |key, value| if value.length > 0 url_params << Rack::Utils.escape(key)+"="+Rack::Utils.escape(value) md5HashData += value end end vpcURL += url_params.join("&") if(@config[:secure_secret].length > 0) vpcURL += "&vpc_SecureHash=" + Digest::MD5.hexdigest(md5HashData).upcase end vpcURL end |
.validate_response(response) ⇒ Object
TODO: another validation needs to be added for the transaction number and amount
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/payment_3p.rb', line 66 def self.validate_response response #strip the input hash from other parameters than vpc_ parameters vpc_response = response.reject{|key,value| !(key =~ /vpc_(.*)/) } vpc_Txn_Secure_Hash = vpc_response.delete(:vpc_SecureHash) if (@config[:secure_secret].length > 0 && vpc_response[:vpc_TxnResponseCode] != "7" && vpc_response[:vpc_TxnResponseCode] != "No Value Returned") md5HashData = @config[:secure_secret] vpc_response.each do |key, value| if (key != "vpc_SecureHash" || value.length > 0) md5HashData += value end end if (vpc_Txn_Secure_Hash.upcase == Digest::MD5.hexdigest(md5HashData).upcase) true else false end else # No 'SECURE_SECRET' present. false end end |