Sha256: b9f01a3e96ef585756461c5823ff1b034c74652d07400c7573b7f10d0aea22f2

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

module MyMoip
  class CreditCardPayment
    attr_accessor :credit_card, :tranches

    def initialize(credit_card, tranches = 1)
      @credit_card, @tranches = credit_card, tranches
    end

    def to_json
      raise "No CreditCard provided" if credit_card.nil?

      json = {
        Forma:        "CartaoCredito",
        Parcelas:     @tranches,
        CartaoCredito: {
          Numero:           credit_card.card_number,
          Expiracao:        credit_card.expiration_date,
          CodigoSeguranca:  credit_card.security_code,
          Portador: {
            Nome:           credit_card.owner_name,
            DataNascimento: credit_card.owner_birthday.strftime("%d/%m/%Y"),
            Telefone:       credit_card.owner_phone,
            Identidade:     credit_card.owner_rg
          }
        }
      }

      json[:Instituicao] = {
        american_express: "American Express",
        diners:           "Diners",
        hipercard:        "Hipercard",
        mastercard:       "Mastercard",
        visa:             "Visa"
      }.fetch credit_card.logo

      if cash?
        json[:Recebimento] = "AVista"
      end

      json
    end

    def cash?
      @tranches == 1
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mymoip-0.2.2 lib/mymoip/credit_card_payment.rb
mymoip-0.2.1 lib/mymoip/credit_card_payment.rb
mymoip-0.2.0 lib/credit_card_payment.rb
mymoip-0.1.0 lib/credit_card_payment.rb