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.
-
#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(type = :authorization, args = {}) ⇒ Request
constructor
A new instance of Request.
- #to_hash ⇒ Object
Constructor Details
#initialize(type = :authorization, args = {}) ⇒ Request
Returns a new instance of Request.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/ruby-saferpay.rb', line 354 def initialize(type = :authorization, args = {}) logger = Saferpay.logger # logger.debug "#{self.class}#initialize ARGS: #{args.inspect}" # logger.debug "#{self.class}#initialize #{type.to_s.capitalize}. Required attributes are:...." 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}\"" 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 ") 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] @type = type @cmd = "#{Saferpay::BASEDIR}#{Saferpay::EXECUTABLE} -#{op} -p #{Saferpay::CONFIG} #{} #{opts} #{attrs}" end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def account_id @account_id end |
#accountid ⇒ Object (readonly)
Returns the value of attribute accountid.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def accountid @accountid end |
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def amount @amount end |
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def cmd @cmd end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def currency @currency end |
#cvc ⇒ Object (readonly)
Returns the value of attribute cvc.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def cvc @cvc end |
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def exp @exp end |
#expiry_date ⇒ Object (readonly)
Returns the value of attribute expiry_date.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def expiry_date @expiry_date end |
#pan ⇒ Object (readonly)
Returns the value of attribute pan.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def pan @pan end |
#token ⇒ Object
Returns the value of attribute token.
353 354 355 |
# File 'lib/ruby-saferpay.rb', line 353 def token @token end |
#track2 ⇒ Object (readonly)
Returns the value of attribute track2.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def track2 @track2 end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
353 354 355 |
# File 'lib/ruby-saferpay.rb', line 353 def transaction_id @transaction_id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
352 353 354 |
# File 'lib/ruby-saferpay.rb', line 352 def type @type end |
Instance Method Details
#to_hash ⇒ Object
415 416 417 |
# File 'lib/ruby-saferpay.rb', line 415 def to_hash self.instance_variables.inject({}){|hsh,ivar| hsh.merge(ivar.gsub(/@/,'').to_sym => self.instance_variable_get(ivar))} end |