Sha256: dd8039b8c1e14061bb492d6a0e588c13274d8faab8b48ef335ba55a27d845a8c

Contents?: true

Size: 885 Bytes

Versions: 6

Compression:

Stored size: 885 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 settle_charge
      update PagarMe::Request.post( url 'settle_charge' ).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

6 entries across 6 versions & 1 rubygems

Version Path
pagarme-2.4.0 lib/pagarme/resources/subscription.rb
pagarme-2.3.0 lib/pagarme/resources/subscription.rb
pagarme-2.2.3 lib/pagarme/resources/subscription.rb
pagarme-2.2.2 lib/pagarme/resources/subscription.rb
pagarme-2.2.1 lib/pagarme/resources/subscription.rb
pagarme-2.2.0 lib/pagarme/resources/subscription.rb