Class: SynapseClient::Order

Inherits:
APIResource show all
Includes:
APIOperations::List
Defined in:
lib/synapse_client/order.rb

Instance Attribute Summary collapse

Attributes inherited from APIResource

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::List

included

Methods inherited from APIResource

api_resource_name, class_name, #refresh, retrieve, #successful?, #to_hash, url, #url

Constructor Details

#initialize(options = {}) ⇒ Order

Returns a new instance of Order.



20
21
22
23
24
# File 'lib/synapse_client/order.rb', line 20

def initialize(options = {})
  options = Map.new(options)

  update_attributes(options)
end

Instance Attribute Details

#account_typeObject (readonly)

Returns the value of attribute account_type.



17
18
19
# File 'lib/synapse_client/order.rb', line 17

def 
  @account_type
end

#amountObject (readonly)

Returns the value of attribute amount.



7
8
9
# File 'lib/synapse_client/order.rb', line 7

def amount
  @amount
end

#bank_idObject (readonly)

Returns the value of attribute bank_id.



11
12
13
# File 'lib/synapse_client/order.rb', line 11

def bank_id
  @bank_id
end

#bank_payObject (readonly)

Returns the value of attribute bank_pay.



10
11
12
# File 'lib/synapse_client/order.rb', line 10

def bank_pay
  @bank_pay
end

#dateObject (readonly)

Returns the value of attribute date.



14
15
16
# File 'lib/synapse_client/order.rb', line 14

def date
  @date
end

#date_settledObject (readonly)

Returns the value of attribute date_settled.



13
14
15
# File 'lib/synapse_client/order.rb', line 13

def date_settled
  @date_settled
end

#feeObject (readonly)

Returns the value of attribute fee.



18
19
20
# File 'lib/synapse_client/order.rb', line 18

def fee
  @fee
end

#noteObject (readonly)

Returns the value of attribute note.



12
13
14
# File 'lib/synapse_client/order.rb', line 12

def note
  @note
end

#resource_uriObject (readonly)

Returns the value of attribute resource_uri.



16
17
18
# File 'lib/synapse_client/order.rb', line 16

def resource_uri
  @resource_uri
end

#seller_emailObject (readonly)

Returns the value of attribute seller_email.



8
9
10
# File 'lib/synapse_client/order.rb', line 8

def seller_email
  @seller_email
end

#seller_idObject (readonly)

Returns the value of attribute seller_id.



9
10
11
# File 'lib/synapse_client/order.rb', line 9

def seller_id
  @seller_id
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/synapse_client/order.rb', line 6

def status
  @status
end

#ticket_numberObject (readonly)

Returns the value of attribute ticket_number.



15
16
17
# File 'lib/synapse_client/order.rb', line 15

def ticket_number
  @ticket_number
end

Class Method Details

.all(params = {}) ⇒ Object



26
27
28
29
# File 'lib/synapse_client/order.rb', line 26

def self.all(params={})
  orders = list(params, "recent").orders
  orders.map{|order| Order.new(order)}
end

.create(params = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/synapse_client/order.rb', line 31

def self.create(params={})
  response = SynapseClient.request(:post, url + "add", params)

  return response unless response.successful?
  Order.new(response.data.order)
end

.retrieve_endpointObject



38
39
40
# File 'lib/synapse_client/order.rb', line 38

def self.retrieve_endpoint
  "poll"
end

.status_object_for_key(key) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/synapse_client/order.rb', line 42

def self.status_object_for_key(key)
  case key
  when -1
    {status: "Queued", description: "Order has been queued by SynapsePay and we are currently investigating it."}
  when 0
    {status: "Queued", description: "Order has been queued and is waiting for merchant approval to process."}
  when 1
    {status: "Created", description: "Order created but still needs to be fetched from the bank account."}
  when 2
    {status: "In Progress", description: "The funds are being fetched from the sender’s bank account, in receiver’s Synapse account in 1-2 Business Days."}
  when 3
    {status: "Settled", description: "Transaction completed and the funds have been added to the receiver’s Synapse account."}
  when 4
    {status: "Refunded/Cancelled", description: "The order has been voided."}
  when 5
    {status: "Returned", description: "Received an ACH return from the sender’s bank account. Which means someone is in trouble."}
  else
    {status: "Unknown", description: "Unknown status key. The API may have changed."}
  end
end

Instance Method Details

#retrieve_paramsObject



70
71
72
# File 'lib/synapse_client/order.rb', line 70

def retrieve_params
  {:order_id => @id}
end

#status_descriptionObject



66
67
68
# File 'lib/synapse_client/order.rb', line 66

def status_description
  Order.status_object_for_key(status)[:description]
end

#status_labelObject



63
64
65
# File 'lib/synapse_client/order.rb', line 63

def status_label
  Order.status_object_for_key(status)[:status]
end

#update_attributes(options) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/synapse_client/order.rb', line 74

def update_attributes(options)
  @status        = options[:status]
  @amount        = options[:amount]
  @seller_email  = options[:seller_email]
  @bank_pay      = options[:bank_pay]
  @bank_id       = options[:bank_id]
  @note          = options[:note]
  @date_settled  = options[:date_settled]
  @date          = options[:date]
  @id            = options[:id]
  @ticket_number = options[:ticket_number]
  @resource_uri  = options[:resource_uri]
  @account_type  = options[:account_type]
  @fee           = options[:fee]
  @seller_id     = options[:seller_id] || options[:seller].delete("seller_id") rescue nil
end