class Gameball::Transaction

Public Class Methods

get_player_balance(playerId) click to toggle source

include Gameball::Utils

# File lib/gameball/models/transaction.rb, line 4
def self.get_player_balance(playerId)
  hashedBody = Gameball::Utils::hashBody(playerUniqueId: playerId)
  body = { playerUniqueId: playerId,
           hash: hashedBody }
  res = Gameball::Utils::request("post", "/integrations/transaction/balance", body)
  unless res.kind_of? Net::HTTPSuccess
    raise Gameball::GameballError.new(res.body) 
  else
    return res
  end
end
hold_points(body) click to toggle source
# File lib/gameball/models/transaction.rb, line 15
def self.hold_points(body)
  # puts body
  # check if attributes are available

  Gameball::Utils.validate(body, ["playerUniqueId", "amount"], ["otp"])
  body[:transactionTime] = Time.now.utc
  body = Gameball::Utils::extractAttributesToHash(body)
  res = Gameball::Utils::request("post", "/integrations/transaction/hold", body)
  unless res.kind_of? Net::HTTPSuccess
    if res.kind_of? Net::HTTPInternalServerError
      raise Gameball::GameballError.new("An Internal Server Error has occurred")
    else
      raise Gameball::GameballError.new(res.body) 
    end
  else
    return res
  end
end
redeem_points(body) click to toggle source
# File lib/gameball/models/transaction.rb, line 33
def self.redeem_points(body)
  # check if attributes are available
  Gameball::Utils.validate(body, ["holdReference", "playerUniqueId", "transactionId"], [])
  body[:transactionTime] = Time.now.utc
  body = Gameball::Utils::extractAttributesToHash(body)
  res = Gameball::Utils::request("post", "/integrations/transaction/redeem", body)
  unless res.kind_of? Net::HTTPSuccess
    if res.kind_of? Net::HTTPInternalServerError
      raise Gameball::GameballError.new("An Internal Server Error has occurred")
    else
      raise Gameball::GameballError.new(res.body) 
    end
  else
    return res
  end
end
reverse_hold(body) click to toggle source
# File lib/gameball/models/transaction.rb, line 81
def self.reverse_hold(body)
  # check if holdReference is in body else throw error
  Gameball::Utils.validate(body, ["holdReference", "playerUniqueId"], [])
  body[:transactionTime] = Time.now.utc

  body = Gameball::Utils::extractAttributesToHash(body)
  res = Gameball::Utils::request("post", "/integrations/transaction/hold", body)
  unless res.kind_of? Net::HTTPSuccess
    if res.kind_of? Net::HTTPInternalServerError
      raise Gameball::GameballError.new("An Internal Server Error has occurred")
    else
      raise Gameball::GameballError.new(res.body) 
    end
  else
    return res
  end
end
reverse_transaction(body) click to toggle source
# File lib/gameball/models/transaction.rb, line 49
def self.reverse_transaction(body)
  Gameball::Utils.validate(body, ["reversedTransactionId", "playerUniqueId", "transactionId"], [])
  body[:transactionTime] = Time.now.utc

  body = Gameball::Utils::extractAttributesToHash(body)
  res = Gameball::Utils::request("post", "/integrations/transaction/cancel", body)
  unless res.kind_of? Net::HTTPSuccess
    if res.kind_of? Net::HTTPInternalServerError
      raise Gameball::GameballError.new("An Internal Server Error has occurred")
    else
      raise Gameball::GameballError.new(res.body) 
    end
  else
    return res
  end
end
reward_points(body) click to toggle source
# File lib/gameball/models/transaction.rb, line 65
def self.reward_points(body)
  Gameball::Utils.validate(body, ["playerUniqueId", "amount", "transactionId"], ["playerAttributes"])
  body[:transactionTime] = Time.now.utc

  body = Gameball::Utils::extractAttributesToHash(body)
  res = Gameball::Utils::request("post", "/integrations/transaction/reward", body)
  unless res.kind_of? Net::HTTPSuccess
    if res.kind_of? Net::HTTPInternalServerError
      raise Gameball::GameballError.new("An Internal Server Error has occurred")
    else
      raise Gameball::GameballError.new(res.body) 
    end
  else
    return true
  end
end