Class: Docdata::Refund

Inherits:
Object
  • Object
show all
Defined in:
lib/docdata/refund.rb

Constant Summary collapse

@@amount =
"?"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Refund

Initializer to transform a +Hash+ into an Refund object

Parameters:

  • args (Hash) (defaults to: nil)


38
39
40
41
42
43
44
# File 'lib/docdata/refund.rb', line 38

def initialize(args=nil)
  @line_items = []
  return if args.nil?
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



28
29
30
# File 'lib/docdata/refund.rb', line 28

def amount
  @amount
end

#currencyObject

Returns the value of attribute currency.



29
30
31
# File 'lib/docdata/refund.rb', line 29

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



31
32
33
# File 'lib/docdata/refund.rb', line 31

def description
  @description
end

#errorsObject

Returns the value of attribute errors.



27
28
29
# File 'lib/docdata/refund.rb', line 27

def errors
  @errors
end

#paymentObject

Returns the value of attribute payment.



30
31
32
# File 'lib/docdata/refund.rb', line 30

def payment
  @payment
end

Instance Method Details

#perform_refundObject

This calls the 'refund' method of the SOAP API It refunds (part of) the payment and returns a Docdata::Response object



55
56
57
58
59
60
61
62
63
64
# File 'lib/docdata/refund.rb', line 55

def perform_refund
  # make the SOAP API call
  response        = Docdata.client.call(:refund, xml: refund_xml)
  response_object = Docdata::Response.parse(:refund, response)
  if response_object.success?
    return true
  else
    return false
  end
end

#refund_xmlString

Returns the xml to send in the SOAP API.

Returns:

  • (String)

    the xml to send in the SOAP API



67
68
69
70
71
72
# File 'lib/docdata/refund.rb', line 67

def refund_xml
  xml_file        = "#{File.dirname(__FILE__)}/xml/refund.xml.erb"
  template        = File.read(xml_file)      
  namespace       = OpenStruct.new(refund: self, payment: self.payment)
  xml             = ERB.new(template).result(namespace.instance_eval { binding })
end

#valid?Boolean

Returns true/false, depending if this instanciated object is valid.

Returns:

  • (Boolean)

    true/false, depending if this instanciated object is valid



47
48
49
50
# File 'lib/docdata/refund.rb', line 47

def valid?
  validator = RefundValidator.new
  validator.valid?(self)
end