Class: PagarMe::Subscription

Inherits:
TransactionCommon show all
Defined in:
lib/pagarme/resources/subscription.rb

Constant Summary

Constants inherited from PagarMeObject

PagarMeObject::RESOURCES

Instance Attribute Summary

Attributes inherited from PagarMeObject

#attributes

Instance Method Summary collapse

Methods inherited from TransactionCommon

#initialize

Methods inherited from Model

all, class_name, create, extract_page_count_or_params, find_by, find_by_id, underscored_class_name, url, #url

Methods inherited from PagarMeObject

#==, #[]=, convert, #empty?, #initialize, #respond_to?, #to_hash, #to_s, #unsaved_attributes

Constructor Details

This class inherits a constructor from PagarMe::TransactionCommon

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PagarMe::PagarMeObject

Instance Method Details

#cancelObject



18
19
20
# File 'lib/pagarme/resources/subscription.rb', line 18

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

#charge(amount, installments = 1) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/pagarme/resources/subscription.rb', line 30

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

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

#createObject



3
4
5
6
# File 'lib/pagarme/resources/subscription.rb', line 3

def create
  set_plan_id
  super
end

#postbacksObject

TODO: Test it



14
15
16
# File 'lib/pagarme/resources/subscription.rb', line 14

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

#saveObject



8
9
10
11
# File 'lib/pagarme/resources/subscription.rb', line 8

def save
  set_plan_id
  super
end

#settle_chargeObject



22
23
24
# File 'lib/pagarme/resources/subscription.rb', line 22

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

#transactionsObject



26
27
28
# File 'lib/pagarme/resources/subscription.rb', line 26

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