lib/gameball/models/coupon.rb in alphaSDK-0.0.3 vs lib/gameball/models/coupon.rb in alphaSDK-0.1.0

- old
+ new

@@ -1,53 +1,37 @@ module Gameball - class Coupon + class Coupon def self.create_discount_coupon(body) - Gameball::Utils.validate(body, ["playerUniqueId"], ["startAt", "endsAt", "entitledCollectionIds", "entitledProductIds", - "oncePerCustomer", "prerequisiteQuantityRange", "prerequisiteShippingPriceRange", "prerequisiteSubtotalRange", - "prerequisiteCollectionIds", "prerequisiteProductIds", "code", "usageLimit", "value", "valueType", "cap"]) - - body[:transactionTime] = Time.now.utc - body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId]) - res = Gameball::Utils::request("post", "/Integrations/Coupon", 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) # use custom message - end - else - return res - end + Gameball::Utils.validate(body,['playerUniqueId','transactionTime'],['startAt','endsAt','entitledCollectionIds','entitledProductIds', + 'oncePerCustomer','prerequisiteQuantityRange','prerequisiteShippingPriceRange','prerequisiteSubtotalRange', + 'prerequisiteCollectionIds','prerequisiteProductIds','code','usageLimit','value','valueType','cap']) + body["hash"]=Gameball::Utils::hashBody(playerUniqueId:body[:playerUniqueId]) + res=Gameball::Utils::request("post","/Integrations/Coupon",body) + unless res.kind_of? Net::HTTPSuccess + raise Gameball::GameballError.new(res) # use custom message + else + return res + end end def self.validate_discount_coupon(body) - Gameball::Utils.validate(body, ["playerUniqueId", "code"]) - body[:transactionTime] = Time.now.utc - - body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId]) - res = Gameball::Utils::request("post", "/Integrations/Coupon/Validate", 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) # use custom message + Gameball::Utils.validate(body,['playerUniqueId','code','transactionTime']) + body["hash"]=Gameball::Utils::hashBody(playerUniqueId:body[:playerUniqueId]) + res=Gameball::Utils::request("post","/Integrations/Coupon/Validate",body) + unless res.kind_of? Net::HTTPSuccess + raise Gameball::GameballError.new(res) # use custom message + else + return res end - else - return res - end end def self.redeem_discount_coupon(body) - Gameball::Utils.validate(body, ["playerUniqueId", "code"]) - body[:transactionTime] = Time.now.utc - body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId]) - res = Gameball::Utils::request("post", "/Integrations/Coupon/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) # use custom message + Gameball::Utils.validate(body,['playerUniqueId','code','transactionTime']) + body["hash"]=Gameball::Utils::hashBody(playerUniqueId:body[:playerUniqueId]) + res=Gameball::Utils::request("post","/Integrations/Coupon/Redeem",body) + unless res.kind_of? Net::HTTPSuccess + raise Gameball::GameballError.new(res) # use custom message + else + return true end - else - return true - end end - end -end + + end +end \ No newline at end of file