Sha256: d0430e8830bff036ec9c57cf4fc6bc61850706ad1daf301c0867307b3f1396c2

Contents?: true

Size: 908 Bytes

Versions: 2

Compression:

Stored size: 908 Bytes

Contents

# encoding: utf-8
require File.join(File.dirname(__FILE__), '..', 'pagarme')

module PagarMe
	class TransactionCommon < Model

		def initialize(response = {})
			super(response)

			self.payment_method ||= 'credit_card'
			self.installments ||= 1
			self.status ||= 'local'
		end

		def create
			check_card_object
			super
		end

		def save
			check_card_object
			super
		end

		private

		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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pagarme-2.0.2 lib/pagarme/transaction_common.rb
pagarme-2.0.1 lib/pagarme/transaction_common.rb