lib/pagarme/transaction_common.rb in pagarme-2.0.2 vs lib/pagarme/transaction_common.rb in pagarme-2.1.0

- old
+ new

@@ -1,44 +1,41 @@ -# encoding: utf-8 -require File.join(File.dirname(__FILE__), '..', 'pagarme') - module PagarMe - class TransactionCommon < Model + class TransactionCommon < Model - def initialize(response = {}) - super(response) + def initialize(response = {}) + super(response) - self.payment_method ||= 'credit_card' - self.installments ||= 1 - self.status ||= 'local' - end + self.payment_method ||= 'credit_card' + self.installments ||= 1 + self.status ||= 'local' + end - def create - check_card_object - super - end + def create + check_card_object + super + end - def save - check_card_object - super - end + def save + check_card_object + super + end - private + private + def check_card_object + if card + if card.id + self.card_id = self.card.id + else + self.card_number = card.card_number + self.card_holder_name = card.card_holder_name + self.card_expiration_year = card.card_expiration_year + self.card_expiration_month = card.card_expiration_month + self.card_cvv = card.card_cvv + self.card_expiration_date = "#{card_expiration_month}#{card_expiration_year}" + end + self.card = nil + end - def check_card_object - if self.card - if self.card.id - self.card_id = self.card.id - else - self.card_number = self.card.card_number - self.card_holder_name = self.card.card_holder_name - self.card_expiration_year = self.card.card_expiration_year - self.card_expiration_month = self.card.card_expiration_month - self.card_cvv = self.card.card_cvv - end - self.card = nil - end - - self.card_expiration_date ||= "#{self.card_expiration_month}#{self.card_expiration_year}" - end - end + self.card_expiration_date ||= "#{card_expiration_month}#{card_expiration_year}" + end + end end