class Soofa
Constants
- LOGGER
- SUCCESSFUL
Public Class Methods
new(till_no, client_secret)
click to toggle source
# File lib/soofapay.rb, line 13 def initialize(till_no, client_secret) @till_no = till_no @client_secret = client_secret @transaction = nil @status = nil end
Public Instance Methods
find(tid)
click to toggle source
# File lib/soofapay.rb, line 20 def find(tid) @url = "https://api.soofapay.com/v1/transactions/#{tid}/" headers = {"Authorization": @client_secret, "X-TILL": @till_no} begin response = RestClient.get(@url, headers = headers) data = JSON.parse(response) _status = data["status"] if response.code == SUCCESSFUL @transaction = Transaction.new(data) return true end rescue RestClient::NotFound LOGGER.warn("The transaction %s does not exist" % tid) return false rescue RestClient::Forbidden raise SoofaPermissionError.new("Your are not allowed to perform this action. Please ensure you use your correct till number and client_secret") end end
get_balance()
click to toggle source
# File lib/soofapay.rb, line 48 def get_balance @url = "http://api.soofapay.com/v1/balance/" headers = {"Authorization": @client_secret, "X-TILL": @till_no} begin response = RestClient.get(@url, headers = headers) data = JSON.parse(response).to_json return data rescue RestClient::Forbidden raise SoofaPermissionError.new("Your are not allowed to perform this action. Please ensure you use your correct till number and client_secret") end end
get_transaction()
click to toggle source
# File lib/soofapay.rb, line 40 def get_transaction if @transaction == nil raise Exception("A transaction is not available yet. Please ensure you call find method and verify that one exists before proceeding") else return @transaction end end