lib/processout/transaction.rb in processout-0.3.0 vs lib/processout/transaction.rb in processout-1.0.0

- old
+ new

@@ -7,12 +7,12 @@ module ProcessOut class Transaction attr_reader :id attr_reader :project - attr_reader :subscription attr_reader :customer + attr_reader :subscription attr_reader :token attr_reader :card attr_reader :name attr_reader :authorized_amount attr_reader :captured_amount @@ -39,28 +39,28 @@ @project = obj end end - def subscription=(val) - if val.instance_of? Subscription - @subscription = val + def customer=(val) + if val.instance_of? Customer + @customer = val else - obj = Subscription.new(@client) + obj = Customer.new(@client) obj.fill_with_data(val) - @subscription = obj + @customer = obj end end - def customer=(val) - if val.instance_of? Customer - @customer = val + def subscription=(val) + if val.instance_of? Subscription + @subscription = val else - obj = Customer.new(@client) + obj = Subscription.new(@client) obj.fill_with_data(val) - @customer = obj + @subscription = obj end end def token=(val) @@ -137,12 +137,12 @@ def initialize(client, data = {}) @client = client @id = data.fetch(:id, "") @project = data.fetch(:project, nil) - @subscription = data.fetch(:subscription, nil) @customer = data.fetch(:customer, nil) + @subscription = data.fetch(:subscription, nil) @token = data.fetch(:token, nil) @card = data.fetch(:card, nil) @name = data.fetch(:name, "") @authorized_amount = data.fetch(:authorized_amount, "") @captured_amount = data.fetch(:captured_amount, "") @@ -170,16 +170,16 @@ @id = data["id"] end if data.include? "project" @project = data["project"] end - if data.include? "subscription" - @subscription = data["subscription"] - end if data.include? "customer" @customer = data["customer"] end + if data.include? "subscription" + @subscription = data["subscription"] + end if data.include? "token" @token = data["token"] end if data.include? "card" @card = data["card"] @@ -222,11 +222,11 @@ end # Get the transaction's refunds. # Params: # +options+:: +Hash+ of options - def refunds(options = {}) + def get_refunds(options = {}) request = Request.new(@client) path = "/transactions/" + CGI.escape(@id) + "/refunds" data = { } @@ -242,9 +242,32 @@ a.push(tmp) end return_values.push(a) + + + return_values[0] + end + + # Find a transaction's refund by its ID. + # Params: + # +refund_id+:: ID of the refund + # +options+:: +Hash+ of options + def find_refund(refund_id, options = {}) + request = Request.new(@client) + path = "/transactions/" + CGI.escape(@id) + "/refunds/" + CGI.escape(refund_id) + "" + data = { + + } + + response = Response.new(request.get(path, data, options)) + return_values = Array.new + + body = response.body + body = body["refund"] + refund = Refund.new(@client) + return_values.push(refund.fill_with_data(body)) return_values[0] end