Class: GoogleCheckout::RefundOrder

Inherits:
OrderCommand show all
Defined in:
lib/google-checkout/command.rb

Overview

Tells Google to refund the order.

Constant Summary

Constants inherited from Command

Command::PRODUCTION_REQUEST_URL, Command::SANDBOX_REQUEST_URL

Instance Attribute Summary collapse

Attributes inherited from OrderCommand

#amount, #google_order_number

Attributes inherited from Command

#currency, #merchant_id, #merchant_key

Instance Method Summary collapse

Methods inherited from Command

#post, #url, x509_store

Constructor Details

#initialize(merchant_id, merchant_key, google_order_number) ⇒ RefundOrder

Returns a new instance of RefundOrder.



201
202
203
204
205
# File 'lib/google-checkout/command.rb', line 201

def initialize(merchant_id, merchant_key, google_order_number)
  super(merchant_id, merchant_key, google_order_number)
  @reason = ''
  @comment = ''
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



199
200
201
# File 'lib/google-checkout/command.rb', line 199

def comment
  @comment
end

#reasonObject

Returns the value of attribute reason.



199
200
201
# File 'lib/google-checkout/command.rb', line 199

def reason
  @reason
end

Instance Method Details

#to_xmlObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/google-checkout/command.rb', line 207

def to_xml
  raise "Refund amount must be greater than 0!" unless @amount.to_f > 0.0
  raise "Reason must be longer than 0 characters!" unless @reason.length > 0
  raise "Reason cannot be greater than 140 characters!" if @reason.length > 140
  raise "Comment cannot be greater than 140 characters!" if @comment.length > 140

  xml = Builder::XmlMarkup.new
  xml.instruct!
  @xml = xml.tag!('refund-order', {
    :xmlns => "http://checkout.google.com/schema/2",
    "google-order-number" => @google_order_number
  }) do
    xml.tag!("amount", @amount, {:currency => @currency})
    xml.tag!("reason", @reason)
    xml.tag!("comment", @comment) unless @comment.nil? || @comment.empty?
  end
  @xml
end