Sha256: 147107c81de062c94d0ecddc46bf632237ff0b84cfbf8b1a61621761ec1a0e1e

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module Mundipagg
  class CreditCard < ActiveMerchant::Billing::CreditCard
    attr_accessor :installment_count

    def brand_name
      return "" if !brand.present?

      if brand == "master"
        "Mastercard"
      else
        brand.capitalize
      end
    end

    def payload(amount)
      content = {
        amount_in_cents: amount,
        credit_card_brand_enum: brand_name,
        credit_card_number: number,
        credit_card_operation_enum: "AuthAndCapture",
        exp_month: month,
        exp_year: year,
        holder_name: name,
        installment_count: installment_count || 1,
        security_code: verification_value,
      }

      if ::ActiveMerchant::Billing::Base.test?
        content.merge!(payment_method_code: 1)
      end

      {
        amount_in_cents: amount,
        currency_iso_enum: "BRL",
        credit_card_transaction_collection: { credit_card_transaction: content }
      }
    end

    class Response < Mundipagg::Response
      def payload
        body[:create_order_response][:create_order_result]
      end

      def error_item
        {
          description: payload[:acquirer_message].split("|").last,
          error_code: payload[:acquirer_return_code]
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
better-mundipagg-0.1.2 lib/mundipagg/credit_card.rb
better-mundipagg-0.1.1 lib/mundipagg/credit_card.rb
better-mundipagg-0.1.0 lib/mundipagg/credit_card.rb