Class: CatarsePagarme::TransactionBase

Inherits:
Object
  • Object
show all
Defined in:
app/models/catarse_pagarme/transaction_base.rb

Direct Known Subclasses

CreditCardTransaction, SlipTransaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, payment) ⇒ TransactionBase

Returns a new instance of TransactionBase.



6
7
8
9
10
# File 'app/models/catarse_pagarme/transaction_base.rb', line 6

def initialize(attributes, payment)
  self.attributes = attributes
  self.payment = payment
  self.user = payment.user
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'app/models/catarse_pagarme/transaction_base.rb', line 3

def attributes
  @attributes
end

#paymentObject

Returns the value of attribute payment.



3
4
5
# File 'app/models/catarse_pagarme/transaction_base.rb', line 3

def payment
  @payment
end

#transactionObject

Returns the value of attribute transaction.



3
4
5
# File 'app/models/catarse_pagarme/transaction_base.rb', line 3

def transaction
  @transaction
end

#userObject

Returns the value of attribute user.



3
4
5
# File 'app/models/catarse_pagarme/transaction_base.rb', line 3

def user
  @user
end

Instance Method Details

#attributes_to_paymentObject



24
25
26
27
28
29
30
31
32
# File 'app/models/catarse_pagarme/transaction_base.rb', line 24

def attributes_to_payment
  {
    payment_method: payment_method,
    gateway_id: self.transaction.id,
    gateway: 'Pagarme',
    gateway_data: self.transaction.to_json,
    installments: default_installments
  }
end

#change_payment_stateObject



12
13
14
15
16
17
18
# File 'app/models/catarse_pagarme/transaction_base.rb', line 12

def change_payment_state
  self.payment.update_attributes(attributes_to_payment)
  self.payment.save!
  delegator.update_transaction
  self.payment.payment_notifications.create(contribution_id: self.payment.contribution_id, extra_data: self.transaction.to_json)
  delegator.change_status_by_transaction(self.transaction.status)
end

#default_installmentsObject



34
35
36
# File 'app/models/catarse_pagarme/transaction_base.rb', line 34

def default_installments
  (self.transaction.installments || 1)
end

#delegatorObject



38
39
40
# File 'app/models/catarse_pagarme/transaction_base.rb', line 38

def delegator
  self.payment.pagarme_delegator
end

#payment_methodObject



20
21
22
# File 'app/models/catarse_pagarme/transaction_base.rb', line 20

def payment_method
  PaymentType::CREDIT_CARD
end