Class: Saferpay::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-saferpay.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf_path, type = :authorization, args = {}) ⇒ Request

Returns a new instance of Request.

Raises:

  • (ArgumentError)


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
482
483
484
485
486
# File 'lib/ruby-saferpay.rb', line 422

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
	message			=	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_idObject (readonly)

Returns the value of attribute account_id.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def 
  @account_id
end

#accountidObject (readonly)

Returns the value of attribute accountid.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def accountid
  @accountid
end

#amountObject (readonly)

Returns the value of attribute amount.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def amount
  @amount
end

#back_referenceObject (readonly)

Returns the value of attribute back_reference.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def back_reference
  @back_reference
end

#cmdObject (readonly)

Returns the value of attribute cmd.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def cmd
  @cmd
end

#currencyObject (readonly)

Returns the value of attribute currency.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def currency
  @currency
end

#cvcObject (readonly)

Returns the value of attribute cvc.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def cvc
  @cvc
end

#expObject (readonly)

Returns the value of attribute exp.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def exp
  @exp
end

#expiry_dateObject (readonly)

Returns the value of attribute expiry_date.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def expiry_date
  @expiry_date
end

#panObject (readonly)

Returns the value of attribute pan.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def pan
  @pan
end

#tokenObject

Returns the value of attribute token.



420
421
422
# File 'lib/ruby-saferpay.rb', line 420

def token
  @token
end

#track2Object (readonly)

Returns the value of attribute track2.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def track2
  @track2
end

#transaction_idObject

Returns the value of attribute transaction_id.



420
421
422
# File 'lib/ruby-saferpay.rb', line 420

def transaction_id
  @transaction_id
end

#typeObject (readonly)

Returns the value of attribute type.



419
420
421
# File 'lib/ruby-saferpay.rb', line 419

def type
  @type
end

Instance Method Details

#to_hashObject



488
489
490
# File 'lib/ruby-saferpay.rb', line 488

def to_hash
	self.instance_variables.inject({}){|hsh,ivar| hsh.merge(ivar.gsub(/@/,'').to_sym => self.instance_variable_get(ivar))}
end