Class: Jet::Client::Returns

Inherits:
Object
  • Object
show all
Defined in:
lib/jet/client/returns.rb

Constant Summary collapse

STATUSES =
{
  created: 'created',
  acknowledged: 'acknowledged',
  refund_customer_without_return: 'refund%20customer%20without%20return',
  completed_by_merchant: 'completed%20by%20merchant',
}

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Returns

Returns a new instance of Returns.



13
14
15
# File 'lib/jet/client/returns.rb', line 13

def initialize(client)
  @client = client
end

Instance Method Details

#acknowledge_return(return_id, body = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/jet/client/returns.rb', line 48

def acknowledge_return(return_id, body = {})
  headers = @client.get_token
  response = RestClient.put("#{Jet::Client::API_URL}/returns/#{return_id}/acknowledge", body.to_json, headers)
  if response.code == 200
    JSON.parse(response.body)
  else
    nil
  end
end

#complete_return(return_id, body = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/jet/client/returns.rb', line 58

def complete_return(return_id, body = {})
  headers = @client.get_token
  response = RestClient.put("#{Jet::Client::API_URL}/returns/#{return_id}/complete", body.to_json, headers)
  if response.code == 200
    JSON.parse(response.body)
  else
    nil
  end
end

#get_return(return_url) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/jet/client/returns.rb', line 28

def get_return(return_url)
  headers = @client.get_token
  response = RestClient.get("#{Jet::Client::API_URL}#{return_url}", headers)
  if response.code == 200
    JSON.parse(response.body)
  else
    nil
  end
end

#get_return_by_id(return_id) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/jet/client/returns.rb', line 38

def get_return_by_id(return_id)
  headers = @client.get_token
  response = RestClient.get("#{Jet::Client::API_URL}/returns/state/#{return_id}", headers)
  if response.code == 200
    JSON.parse(response.body)
  else
    nil
  end
end

#get_returns(status = :created) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/jet/client/returns.rb', line 17

def get_returns(status = :created)
  headers = @client.get_token
  query_status = STATUSES[status]
  response = RestClient.get("#{Jet::Client::API_URL}/returns/#{query_status}", headers)
  if response.code == 200
    JSON.parse(response.body)
  else
    nil
  end
end