Sha256: 1b7e77ce90032e66e41fb09acdbcec28e5354abce61f7ac44b7c9803859f77b3

Contents?: true

Size: 842 Bytes

Versions: 2

Compression:

Stored size: 842 Bytes

Contents

module Paidy
  class Charge
    class << self
      def create(params)
        res = Paidy.request(:post, 'payments', params, {})

        self.new(res['id'])
      end
    end

    def initialize(id)
      @id = id
      @capture_id = nil
    end

    attr_reader :id, :capture_id, :status

    def capture
      res = Paidy.request(:post, "#{base_path}/captures", {}, {})
      @capture_id = res['captures'][0]['id']

      self
    end

    def close
      res = Paidy.request(:post, "#{base_path}/close", {}, {})

      self
    end

    def refund
      res = Paidy.request(:post, "#{base_path}/refund", { capture_id: capture_id }, {})

      self
    end

    def refund_or_close
      if capture_id.nil?
        close
      else
        refund
      end
    end

    private

    def base_path
      "payments/#{id}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paidy-0.0.2 lib/paidy/charge.rb
paidy-0.0.1 lib/paidy/charge.rb