Class: Workarea::Checkout::CreditCardParams

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/checkout/credit_card_params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ CreditCardParams

Returns a new instance of CreditCardParams.



5
6
7
8
# File 'app/models/workarea/checkout/credit_card_params.rb', line 5

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

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'app/models/workarea/checkout/credit_card_params.rb', line 3

def params
  @params
end

Instance Method Details

#new?Boolean

Whether these params represent setting a new card as payment on the order.

Returns:

  • (Boolean)


15
16
17
# File 'app/models/workarea/checkout/credit_card_params.rb', line 15

def new?
  params[:payment] == 'new_card'
end

#new_cardHash

New credit card params.

Returns:

  • (Hash)


23
24
25
# File 'app/models/workarea/checkout/credit_card_params.rb', line 23

def new_card
  @card_params
end

#numberString

The new credit card number for these params

Returns:



31
32
33
# File 'app/models/workarea/checkout/credit_card_params.rb', line 31

def number
  @card_params[:number]
end

#saved?Boolean

Do these params represent using a saved credit card as payment?

Returns:

  • (Boolean)


39
40
41
# File 'app/models/workarea/checkout/credit_card_params.rb', line 39

def saved?
  saved_card_id.present?
end

#saved_card_idString

The saved card id for these params. Returns the ‘:payment` param if it is a legal BSON::ObjectId

Returns:



48
49
50
51
52
# File 'app/models/workarea/checkout/credit_card_params.rb', line 48

def saved_card_id
  if BSON::ObjectId.legal?(params[:payment])
    params[:payment]
  end
end