Sha256: 2f370ca9028f811748aaa2cb3a6acbf42d90d14c8fd65041e0b2cc363f584573

Contents?: true

Size: 788 Bytes

Versions: 5

Compression:

Stored size: 788 Bytes

Contents

module PagarMe
  class Subscription < TransactionCommon
    def create
      set_plan_id
      super
    end

    def save
      set_plan_id
      super
    end

    # TODO: Test it
    def postbacks
      PagarMe::Request.get( url 'postbacks' ).call
    end

    def cancel
      update PagarMe::Request.post( url 'cancel' ).run
    end

    def transactions
      PagarMe::Request.get( url 'transactions' ).call
    end

    def charge(amount, installments = 1)
      PagarMe::Request.post(url('transactions'), params: {
        amount:       amount,
        installments: installments
      }).run

      update PagarMe::Request.get(url).run
    end

    protected
    def set_plan_id
      if plan
        self.plan_id = plan.id
        self.plan    = nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pagarme-2.1.4 lib/pagarme/resources/subscription.rb
pagarme-2.1.3 lib/pagarme/resources/subscription.rb
pagarme-2.1.2 lib/pagarme/resources/subscription.rb
pagarme-2.1.1 lib/pagarme/resources/subscription.rb
pagarme-2.1.0 lib/pagarme/resources/subscription.rb