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.27 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.26 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.45 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.25 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.23 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.44 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.22 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.43 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.21 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.42 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.20 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.41 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.19 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.40 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.18 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.39 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.17 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.38 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.5.16 app/models/workarea/checkout/credit_card_params.rb
workarea-core-3.4.37 app/models/workarea/checkout/credit_card_params.rb