Class: Peddler::Refunds::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/peddler/refunds.rb

Overview

This is a refund batch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ Batch

Returns a new instance of Batch.



7
8
9
10
# File 'lib/peddler/refunds.rb', line 7

def initialize(transport)
  @transport = transport
  @batch = []
end

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



5
6
7
# File 'lib/peddler/refunds.rb', line 5

def batch
  @batch
end

Instance Method Details

#<<(item) ⇒ Object



17
18
19
# File 'lib/peddler/refunds.rb', line 17

def <<(item)
  @batch << item
end

#file_contentObject



12
13
14
15
# File 'lib/peddler/refunds.rb', line 12

def file_content
  out = "order-id\tpayments-transaction-id\trefund-amount\treason\tmessage\r\n"
  @file_content = @batch.inject(out){ |memo, item| memo << item.to_s }
end

#uploadObject

Raises:



21
22
23
24
25
26
27
28
# File 'lib/peddler/refunds.rb', line 21

def upload
  raise PeddlerError.new("Batch already uploaded") if @completed
  @transport.legacize_request
  @transport.path << "catalog-upload/batch-refund"
  @transport.body = file_content
  res = @transport.execute_request
  @completed = true if res == "<Success>SUCCESS</Success>"
end