Class: Saferpay::Request
- Inherits:
-
Object
- Object
- Saferpay::Request
- Defined in:
- lib/ruby-saferpay.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#accountid ⇒ Object
readonly
Returns the value of attribute accountid.
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#back_reference ⇒ Object
readonly
Returns the value of attribute back_reference.
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#cvc ⇒ Object
readonly
Returns the value of attribute cvc.
-
#exp ⇒ Object
readonly
Returns the value of attribute exp.
-
#expiry_date ⇒ Object
readonly
Returns the value of attribute expiry_date.
-
#pan ⇒ Object
readonly
Returns the value of attribute pan.
-
#token ⇒ Object
Returns the value of attribute token.
-
#track2 ⇒ Object
readonly
Returns the value of attribute track2.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(conf_path, type = :authorization, args = {}) ⇒ Request
constructor
A new instance of Request.
- #to_hash ⇒ Object
Constructor Details
#initialize(conf_path, type = :authorization, args = {}) ⇒ Request
Returns a new instance of Request.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/ruby-saferpay.rb', line 417 def initialize(conf_path, type = :authorization, args = {}) raise ArgumentError, "No account ID was passed" unless args[:accountid] raise ArgumentError, "No configuration path." unless conf_path @conf_path = conf_path logger = Saferpay.logger opts = nil attrs = nil mess = nil case type when :authorization, :auth, :reserve op = 'exec' mess = 'Authorization' attrs = {:amount => args[:amount], :currency => args[:currency], :accountid => args[:accountid], :pan => args[:pan], :exp => args[:exp]} when :debit_card_reserve, :lastschrift op = 'exec' mess = 'Authorization' attrs = {:amount => args[:amount], :currency => args[:currency], :accountid => args[:accountid], :track2 => args[:track2]} when :capture raise ArgumentError, "#{type.to_s.capitalize}: missing required parameter \"transaction_id\"" unless args[:transaction_id] op = 'capt' opts = "-i #{args[:transaction_id]} -t \"(not used)\"" when :refund op = 'exec' mess = 'Authorization' attrs = {:action => 'Debit', :amount => args[:amount], :currency => args[:currency], :accountid => args[:accountid], :pan => args[:pan], :exp => args[:exp]} when :refund_transaction raise ArgumentError, "#{type.to_s.capitalize}: missing required parameter \"transaction_id\"" unless args[:transaction_id] op = 'capt' opts = "-i #{args[:transaction_id]} -t \"(not used)\"" when :cancel raise ArgumentError, "#{type.to_s.capitalize}: missing required parameter \"transaction_id\"" unless args[:transaction_id] op = 'capt' opts = "-i #{args[:transaction_id]} -t \"(not used)\"" attrs = {:action => 'Cancel'} when :inquiry, :details, :info op = 'exec' mess = 'Inquiry' attrs = {:type => 'Transaction', :id => args[:transaction_id]} end = mess.nil? ? '' : "-m #{mess}" # Check for missing values and complain; Compile attributes string if attrs attrs.each{|attr, value| raise AttributeError, "Saferpay::Request#initialize #{type.to_s.capitalize}: missing required parameter \"#{attr}\" (args passed: #{args.inspect})" if(value.nil? || value.to_s.empty? || (value.is_a?(Fixnum) && value == 0)) } attrs = '-a ' + attrs.map{|k,v| "#{k.to_s.upcase} #{v}" }.join(" -a ") attrs += " -a ORDERID #{args[:back_reference]} " if args[:back_reference] # Reference to calling app's record for this transaction end # TODO: fill all ivars and class_eval them to be attr_reader-able @amount = args[:amount] @pan = args[:pan] @exp = args[:exp]; @expiry_date = @exp @currency = args[:currency] @cvc = args[:cvc] @track2 = args[:track2] @accountid = args[:accountid]; @account_id = @accountid @transaction_id = args[:transaction_id] @back_reference = args[:back_reference] # Reference to calling app's record for this transaction @type = type @cmd = "#{Saferpay::BASEDIR}#{Saferpay::EXECUTABLE} -#{op} -p #{@conf_path}conf_for_#{@account_id} #{message} #{opts} #{attrs}" end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def account_id @account_id end |
#accountid ⇒ Object (readonly)
Returns the value of attribute accountid.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def accountid @accountid end |
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def amount @amount end |
#back_reference ⇒ Object (readonly)
Returns the value of attribute back_reference.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def back_reference @back_reference end |
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def cmd @cmd end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def currency @currency end |
#cvc ⇒ Object (readonly)
Returns the value of attribute cvc.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def cvc @cvc end |
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def exp @exp end |
#expiry_date ⇒ Object (readonly)
Returns the value of attribute expiry_date.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def expiry_date @expiry_date end |
#pan ⇒ Object (readonly)
Returns the value of attribute pan.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def pan @pan end |
#token ⇒ Object
Returns the value of attribute token.
415 416 417 |
# File 'lib/ruby-saferpay.rb', line 415 def token @token end |
#track2 ⇒ Object (readonly)
Returns the value of attribute track2.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def track2 @track2 end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
415 416 417 |
# File 'lib/ruby-saferpay.rb', line 415 def transaction_id @transaction_id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
414 415 416 |
# File 'lib/ruby-saferpay.rb', line 414 def type @type end |
Instance Method Details
#to_hash ⇒ Object
483 484 485 |
# File 'lib/ruby-saferpay.rb', line 483 def to_hash self.instance_variables.inject({}){|hsh,ivar| hsh.merge(ivar.gsub(/@/,'').to_sym => self.instance_variable_get(ivar))} end |