Sha256: 97a956d1e03761aa02bb6424db695fc4b8d61e32c43bdc4538a4113ee8effbd9

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 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)
      request = PagarMe::Request.new(self.url + '/transactions', 'POST')
      request.parameters = {
        :amount => amount,
      }
      response = request.run

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pagarme-1.9.3 lib/pagarme/subscription.rb