lib/gameball/models/transaction.rb in gameball-1.0.1 vs lib/gameball/models/transaction.rb in gameball-2.0.0

- old
+ new

@@ -13,14 +13,18 @@ end end 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) + if (Gameball.api_version!="v3.0") + Gameball::Utils.validate(body, ["playerUniqueId", "amount"], ["otp"]) + body[:transactionTime] = Time.now.utc + body = Gameball::Utils::extractAttributesToHash(body) + else + Gameball::Utils.validate(body, ["playerUniqueId", "amount"], ["mobile","email"]) + body[:transactionTime] = Time.now.utc.iso8601 + end 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 @@ -30,13 +34,19 @@ return res end end 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) + if (Gameball.api_version!="v3.0") + Gameball::Utils.validate(body, ["holdReference", "playerUniqueId", "transactionId"], []) + body[:transactionTime] = Time.now.utc + body = Gameball::Utils::extractAttributesToHash(body) + else + Gameball::Utils.validate(body, ["playerUniqueId", "transactionId"], + ["mobile","email","redeemedAmount","holdReference"]) + body[:transactionTime] = Time.now.utc.iso8601 + end 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 @@ -47,11 +57,10 @@ end end 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") @@ -60,30 +69,98 @@ end else return res end end + def self.refund(body) + Gameball::Utils.validate(body, ["reverseTransactionId", "playerUniqueId", "transactionId"], + ["mobile","email","amount"]) + body[:transactionTime] = Time.now.utc.iso8601 + res = Gameball::Utils::request("post", "/integrations/transaction/refund", 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 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 + return res end end + def self.cashback(body) + Gameball::Utils.validate(body, ["playerUniqueId", "amount", "transactionId"], ["mobile","email","merchant"]) + body[:transactionTime] = Time.now.utc.iso8601 + res = Gameball::Utils::request("post", "/integrations/transaction/cashback", 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 + def self.manual_transaction(body) + Gameball::Utils.validate(body, ["playerUniqueId", "username", "transactionId","reason"], + ["mobile","email","amount","points"]) + body[:transactionTime] = Time.now.utc.iso8601 + res = Gameball::Utils::request("post", "/integrations/transaction/manual", 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 + def self.list_transactions(params={}) + Gameball::Utils.validate(params, [], ["page","limit","direction","from","to","transactionId","status"]) + res = Gameball::Utils::request("get", "/integrations/transaction/list",params:params) + 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 def self.reverse_hold(body) # check if holdReference is in body else throw error + if(Gameball.api_version=="v3.0") + # If v3.0 holReference is sent instead of body in args + res = Gameball::Utils::request("delete", "/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 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")