Sha256: 753e4f934b704039d966efa733900eaf918bfaed4aeb39f4b2e7a9551e76ed0f

Contents?: true

Size: 1.02 KB

Versions: 62

Compression:

Stored size: 1.02 KB

Contents

module Workarea
  class Checkout::CreditCardParams
    attr_accessor :params

    def initialize(params)
      @params = params
      @card_params = params.fetch(:credit_card, {})
    end

    # Whether these params represent setting a new card as
    # payment on the order.
    #
    # @return [Boolean]
    #
    def new?
      params[:payment] == 'new_card'
    end

    # New credit card params.
    #
    # @return [Hash]
    #
    def new_card
      @card_params
    end

    # The new credit card number for these params
    #
    # @return [String]
    #
    def number
      @card_params[:number]
    end

    # Do these params represent using a saved credit card as payment?
    #
    # @return [Boolean]
    #
    def saved?
      saved_card_id.present?
    end

    # The saved card id for these params. Returns the `:payment` param
    # if it is a legal {BSON::ObjectId}
    #
    # @return [String]
    #
    def saved_card_id
      if BSON::ObjectId.legal?(params[:payment])
        params[:payment]
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.36 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.14 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.35 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.13 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.34 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.12 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.33 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.11 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.10 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.32 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.9 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.31 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.8 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.30 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.7 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.29 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.6 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.28 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.5 app/models/workarea/checkout/credit_card_params.rb