Class: Coinsimple::Business

Inherits:
Object
  • Object
show all
Defined in:
lib/coinsimple/business.rb

Constant Summary collapse

NEW_INVOICE_URL =
"https://app.coinsimple.com/api/v1/invoice"

Instance Method Summary collapse

Constructor Details

#initialize(business_id, api_key) ⇒ Business

Returns a new instance of Business.



9
10
11
12
# File 'lib/coinsimple/business.rb', line 9

def initialize business_id , api_key
  @api_key=api_key
  @business_id=business_id
end

Instance Method Details

#send_invoice(invoice) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/coinsimple/business.rb', line 14

def send_invoice invoice
  options=invoice.data
  options[:business_id]=@business_id
  timestamp=Time.now.to_i
  hash=Hashit.sha256(timestamp,@api_key)[3..-1]
  options[:timestamp]=timestamp
  options[:hash]=hash

  res = HTTP.post NEW_INVOICE_URL, json: options
  if res.status >= 400
    {"status" => "error" , "error" => "error creating invoice"}
  else
    JSON.parse res.to_s
  end
end