Class: NewStoreApi::CardDetails

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/card_details.rb

Overview

Card-specific payment details.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(reference = nil, card_brand = SKIP, card_last4 = SKIP, merchant_account = SKIP, origin = SKIP, terminal_receipt = SKIP, wallet = SKIP) ⇒ CardDetails

Returns a new instance of CardDetails.



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/new_store_api/models/card_details.rb', line 82

def initialize(reference = nil, card_brand = SKIP, card_last4 = SKIP,
                = SKIP, origin = SKIP,
               terminal_receipt = SKIP, wallet = SKIP)
  @card_brand = card_brand unless card_brand == SKIP
  @card_last4 = card_last4 unless card_last4 == SKIP
  @merchant_account =  unless  == SKIP
  @origin = origin unless origin == SKIP
  @reference = reference
  @terminal_receipt = terminal_receipt unless terminal_receipt == SKIP
  @wallet = wallet unless wallet == SKIP
end

Instance Attribute Details

#card_brandString

The card brand, for example Visa or Mastercard.

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/card_details.rb', line 14

def card_brand
  @card_brand
end

#card_last4String

The last four digits of the card number.

Returns:

  • (String)


18
19
20
# File 'lib/new_store_api/models/card_details.rb', line 18

def card_last4
  @card_last4
end

#merchant_accountString

The merchant account at the payment provider that settled this payment. Applies to Adyen only.

Returns:

  • (String)


23
24
25
# File 'lib/new_store_api/models/card_details.rb', line 23

def 
  @merchant_account
end

#originString

How the card payment was taken, for example terminal or apple_tap_to_pay.

Returns:

  • (String)


28
29
30
# File 'lib/new_store_api/models/card_details.rb', line 28

def origin
  @origin
end

#referenceString

The payment provider's reference for this payment, for example the PSP reference.

Returns:

  • (String)


33
34
35
# File 'lib/new_store_api/models/card_details.rb', line 33

def reference
  @reference
end

#terminal_receiptObject

Raw terminal receipt data captured at the point of sale, when available. Applies to Adyen only.

Returns:

  • (Object)


38
39
40
# File 'lib/new_store_api/models/card_details.rb', line 38

def terminal_receipt
  @terminal_receipt
end

#walletString

The wallet used to present the card, for example apple_pay or google_pay.

Returns:

  • (String)


43
44
45
# File 'lib/new_store_api/models/card_details.rb', line 43

def wallet
  @wallet
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/new_store_api/models/card_details.rb', line 95

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  reference = hash.key?('reference') ? hash['reference'] : nil
  card_brand = hash.key?('card_brand') ? hash['card_brand'] : SKIP
  card_last4 = hash.key?('card_last4') ? hash['card_last4'] : SKIP
   =
    hash.key?('merchant_account') ? hash['merchant_account'] : SKIP
  origin = hash.key?('origin') ? hash['origin'] : SKIP
  terminal_receipt =
    hash.key?('terminal_receipt') ? hash['terminal_receipt'] : SKIP
  wallet = hash.key?('wallet') ? hash['wallet'] : SKIP

  # Create object from extracted values.
  CardDetails.new(reference,
                  card_brand,
                  card_last4,
                  ,
                  origin,
                  terminal_receipt,
                  wallet)
end

.namesObject

A mapping from model property names to API property names.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/new_store_api/models/card_details.rb', line 46

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['card_brand'] = 'card_brand'
  @_hash['card_last4'] = 'card_last4'
  @_hash['merchant_account'] = 'merchant_account'
  @_hash['origin'] = 'origin'
  @_hash['reference'] = 'reference'
  @_hash['terminal_receipt'] = 'terminal_receipt'
  @_hash['wallet'] = 'wallet'
  @_hash
end

.nullablesObject

An array for nullable fields



71
72
73
74
75
76
77
78
79
80
# File 'lib/new_store_api/models/card_details.rb', line 71

def self.nullables
  %w[
    card_brand
    card_last4
    merchant_account
    origin
    terminal_receipt
    wallet
  ]
end

.optionalsObject

An array for optional fields



59
60
61
62
63
64
65
66
67
68
# File 'lib/new_store_api/models/card_details.rb', line 59

def self.optionals
  %w[
    card_brand
    card_last4
    merchant_account
    origin
    terminal_receipt
    wallet
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (CardDetails | Hash)

    value against the validation is performed.



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/new_store_api/models/card_details.rb', line 121

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.reference,
                                 ->(val) { val.instance_of? String })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['reference'],
                        ->(val) { val.instance_of? String })
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



142
143
144
145
146
147
148
# File 'lib/new_store_api/models/card_details.rb', line 142

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} card_brand: #{@card_brand.inspect}, card_last4: #{@card_last4.inspect},"\
  " merchant_account: #{@merchant_account.inspect}, origin: #{@origin.inspect}, reference:"\
  " #{@reference.inspect}, terminal_receipt: #{@terminal_receipt.inspect}, wallet:"\
  " #{@wallet.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



134
135
136
137
138
139
# File 'lib/new_store_api/models/card_details.rb', line 134

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} card_brand: #{@card_brand}, card_last4: #{@card_last4}, merchant_account:"\
  " #{@merchant_account}, origin: #{@origin}, reference: #{@reference}, terminal_receipt:"\
  " #{@terminal_receipt}, wallet: #{@wallet}>"
end