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(type = :authorization, args = {}) ⇒ Request

Returns a new instance of Request.



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
414
# File 'lib/ruby-saferpay.rb', line 355

def initialize(type = :authorization, args = {})
	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 #{Saferpay::CONFIG} #{message} #{opts} #{attrs}"
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def 
  @account_id
end

#accountidObject (readonly)

Returns the value of attribute accountid.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def accountid
  @accountid
end

#amountObject (readonly)

Returns the value of attribute amount.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def amount
  @amount
end

#back_referenceObject (readonly)

Returns the value of attribute back_reference.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def back_reference
  @back_reference
end

#cmdObject (readonly)

Returns the value of attribute cmd.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def cmd
  @cmd
end

#currencyObject (readonly)

Returns the value of attribute currency.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def currency
  @currency
end

#cvcObject (readonly)

Returns the value of attribute cvc.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def cvc
  @cvc
end

#expObject (readonly)

Returns the value of attribute exp.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def exp
  @exp
end

#expiry_dateObject (readonly)

Returns the value of attribute expiry_date.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def expiry_date
  @expiry_date
end

#panObject (readonly)

Returns the value of attribute pan.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def pan
  @pan
end

#tokenObject

Returns the value of attribute token.



353
354
355
# File 'lib/ruby-saferpay.rb', line 353

def token
  @token
end

#track2Object (readonly)

Returns the value of attribute track2.



352
353
354
# File 'lib/ruby-saferpay.rb', line 352

def track2
  @track2
end

#transaction_idObject

Returns the value of attribute transaction_id.



353
354
355
# File 'lib/ruby-saferpay.rb', line 353

def transaction_id
  @transaction_id
end

#typeObject (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_hashObject



416
417
418
# File 'lib/ruby-saferpay.rb', line 416

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