Class: Webirr::Client
- Inherits:
-
Object
- Object
- Webirr::Client
- Defined in:
- lib/webirr/client.rb
Instance Method Summary collapse
- #create_bill(bill) ⇒ Object
- #delete_bill(payment_code) ⇒ Object
- #get_payment_status(payment_code) ⇒ Object
- #get_stat(date_from: nil, date_to: nil) ⇒ Object
-
#initialize(domain = "api.webirr.com", api_key, is_test_env) ⇒ Client
constructor
A new instance of Client.
- #update_bill(bill) ⇒ Object
Constructor Details
#initialize(domain = "api.webirr.com", api_key, is_test_env) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/webirr/client.rb', line 7 def initialize(domain = "api.webirr.com", api_key, is_test_env) @api_key = api_key @client = Faraday.new( url: (is_test_env ? "https://#{domain}/" : "https://#{domain}:8080/").to_s, params: { "api_key" => @api_key }, headers: { "Content-Type" => "application/json" } ) end |
Instance Method Details
#create_bill(bill) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/webirr/client.rb', line 22 def create_bill(bill) response = @client.post("einvoice/api/postbill") { |req| req.body = bill.to_json } if response.success? JSON.parse(response.body) else { "error" => "http error #{response.status} #{response.reason_phrase}" } end end |
#delete_bill(payment_code) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/webirr/client.rb', line 42 def delete_bill(payment_code) response = @client.put("einvoice/api/deletebill?wbc_code=#{payment_code}") if response.success? JSON.parse(response.body) else { "error" => "http error #{response.status} #{response.reason_phrase}" } end end |
#get_payment_status(payment_code) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/webirr/client.rb', line 51 def get_payment_status(payment_code) response = @client.get("einvoice/api/getPaymentStatus?wbc_code=#{payment_code}") if response.success? JSON.parse(response.body) else { "error" => "http error #{response.status} #{response.reason_phrase}" } end end |
#get_stat(date_from: nil, date_to: nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/webirr/client.rb', line 61 def get_stat(date_from: nil, date_to: nil) if date_from.nil? response = @client.get("merchant/stat") else response = @client.get("merchant/stat?date_from=#{date_from}&date_to=#{date_to}") end if response.success? JSON.parse(response.body) else { "error" => "http error #{response.status} #{response.reason_phrase}" } end end |
#update_bill(bill) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/webirr/client.rb', line 32 def update_bill(bill) response = @client.put("einvoice/api/postbill") { |req| req.body = bill.to_json } if response.success? JSON.parse(response.body) else { "error" => "http error #{response.status} #{response.reason_phrase}" } end end |