Sha256: c67de2bdc4d7420934c22235887e6d8c47a4b308e0f89ed30e8b7c61d57640df

Contents?: true

Size: 852 Bytes

Versions: 9

Compression:

Stored size: 852 Bytes

Contents

# encoding: utf-8
require File.join(File.dirname(__FILE__), '..', 'pagarme')

module PagarMe
  class Subscription < TransactionCommon
    def create
      if self.plan
        self.plan_id = plan.id
      end

      self.plan = nil
      super
    end

    def save
      if self.plan
        self.plan_id = plan.id
      end

      self.plan = nil
      super
    end

    def cancel
      request = PagarMe::Request.new(self.url + '/cancel', 'POST')
      response = request.run
      update(response)
    end

    def charge(amount, installments = 1)
      request = PagarMe::Request.new(self.url + '/transactions', 'POST')
      request.parameters = {
        :amount => amount,
		:installments => installments
      }
      response = request.run

      request = PagarMe::Request.new(self.url, 'GET')
      update(request.run)
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pagarme-2.0.2 lib/pagarme/subscription.rb
pagarme-2.0.1 lib/pagarme/subscription.rb
pagarme-2.0.0 lib/pagarme/subscription.rb
pagarme-1.10.0 lib/pagarme/subscription.rb
pagarme-1.9.9 lib/pagarme/subscription.rb
pagarme-1.9.8 lib/pagarme/subscription.rb
pagarme-1.9.7 lib/pagarme/subscription.rb
pagarme-1.9.6 lib/pagarme/subscription.rb
pagarme-1.9.5 lib/pagarme/subscription.rb