Sha256: 4c76165a2cc35d97918d01925af8731769dd71f5d0b74eb8cc56144614cfb2c9

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'json'

class Spike
  class Charge
    def initialize(client)
      @client = client
    end

    def create(params, products)
      res = @client.post(request_path: "/charges", request_params: params.merge(products: JSON.generate(products)))
      Spike::Charge::Response.new(res)
    end

    def retrieve(charge_id)
      res = @client.get(request_path: "/charges/#{charge_id}")
      Spike::Charge::Response.new(res)
    end

    class Spike::Charge::Response
      def initialize(hash)
        @attributes = Hash[hash.map{|k,v| [k.to_s, v] }]
      end

      def id
        @attributes['id']
      end

      def object
        @attributes['object']
      end

      def created_at
        Time.at(@attributes['created'])
      end

      def live_mode?
        @attributes['livemode']
      end

      def paid?
        @attributes['paid']
      end

      def captured?
        @attributes['captured']
      end

      def amount
        @attributes['amount'].to_f
      end

      def currency
        @attributes['currency']
      end

      def refunded?
        @attributes['refunded']
      end

      def amount_refunded
        @attributes['amount_refunded']
      end

      def refunds
        @attributes['refunds']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spike-ruby-0.0.3 lib/spike/charge.rb