Class: MastercardMerchantCheckout::PaymentData

Inherits:
Object
  • Object
show all
Includes:
ROXML
Defined in:
lib/mastercard_merchant_checkout/models/payment_data.rb

Overview

This class contains various methods to get paymentData response parameters returned by PaymentDataApi.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ PaymentData

Returns a new instance of PaymentData.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 65

def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}

  
  if attributes.has_key?(:card)
    self.card = attributes[:card]
  end
  
  if attributes.has_key?(:shipping_address)
    self.shipping_address = attributes[:shipping_address]
  end
  
  if attributes.has_key?(:personal_info)
    self.personal_info = attributes[:personal_info]
  end
  
  if attributes.has_key?(:tokenization)
    self.tokenization = attributes[:tokenization]
  end
  
  if attributes.has_key?(:wallet_id)
    self.wallet_id = attributes[:wallet_id]
  end
  
  if attributes.has_key?(:wallet_name)
    self.wallet_name = attributes[:wallet_name]
  end
  
  if attributes.has_key?(:authentication_options)
    self.authentication_options = attributes[:authentication_options]
  end
  
  if attributes.has_key?(:pairing_id)
    self.pairing_id = attributes[:pairing_id]
  end
  
end

Instance Attribute Details

#authentication_optionsAuthenticationOptions

Returns the authentication information.

Returns:



43
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 43

xml_accessor :authentication_options, :from =>"authenticationOptions",:as => AuthenticationOptions

#cardCard

Returns the payment card details.

Returns:

  • (Card)

    the payment card details.



19
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 19

xml_accessor :card, :from =>"card",:as => Card

#pairing_idString

Returns the new pairingId.

Returns:

  • (String)

    the new pairingId.



47
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 47

xml_accessor :pairing_id, :from =>"pairingId"

#personal_infoPersonalInfo

Returns the recipient’s personal information.

Returns:

  • (PersonalInfo)

    the recipient’s personal information.



27
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 27

xml_accessor :personal_info, :from =>"personalInfo",:as => PersonalInfo

#shipping_addressAddress

Returns the shipping address details.

Returns:

  • (Address)

    the shipping address details.



23
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 23

xml_accessor :shipping_address, :from =>"shippingAddress",:as => Address

#tokenizationTokenization

Returns the tokenized card information.

Returns:



31
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 31

xml_accessor :tokenization, :from =>"tokenization",:as => Tokenization

#wallet_idString

Returns the unique identifier for a wallet that helps identify the origin wallet for the transaction.

Returns:

  • (String)

    the unique identifier for a wallet that helps identify the origin wallet for the transaction.



35
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 35

xml_accessor :wallet_id, :from =>"walletId"

#wallet_nameString

Returns the wallet name.

Returns:

  • (String)

    the wallet name.



39
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 39

xml_accessor :wallet_name, :from =>"walletName"

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 51

def self.attribute_map
  {
    :card => :card ,
    :shipping_address => :shippingAddress ,
    :personal_info => :personalInfo ,
    :tokenization => :tokenization ,
    :wallet_id => :walletId ,
    :wallet_name => :walletName ,
    :authentication_options => :authenticationOptions ,
    :pairing_id => :pairingId 
    
  }
end

Instance Method Details

#==(o) ⇒ Object

Check equality by comparing each attribute.



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 110

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      card == o.card &&
      shipping_address == o.shipping_address &&
      personal_info == o.personal_info &&
      tokenization == o.tokenization &&
      wallet_id == o.wallet_id &&
      wallet_name == o.wallet_name &&
      authentication_options == o.authentication_options &&
      pairing_id == o.pairing_id
end

#_deserialize(type, value) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 153

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :BOOLEAN
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    _model = MastercardMerchantCheckout.const_get(type).new
    _model.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Object

Method to output non-array value in the form of hash For object, use to_hash. Otherwise, just return the value



212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 212

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map{ |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

build the object from hash



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 134

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.datatype_map.each_pair do |key, type|
    if type =~ /^Array<(.*)>/i
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
      else
        #TODO show warning in debug mode
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    else
      # data not found in attributes(hash), not an issue as the data can be optional
    end
  end

  self
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • `==` method


124
125
126
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 124

def eql?(o)
  self == o
end

#hashObject

Calculate hash code according to all attributes.



129
130
131
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 129

def hash
  [card, shipping_address, personal_info, tokenization, wallet_id, wallet_name, authentication_options, pairing_id].hash
end

#to_bodyObject

to_body is an alias to to_body (backward compatibility))



193
194
195
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 193

def to_body
  to_hash
end

#to_hash(include_root = false) ⇒ Object

return the object in the form of hash



198
199
200
201
202
203
204
205
206
207
208
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 198

def to_hash(include_root = false)
  attributes_hash = {} 
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    hash[param] = _to_hash(value)
  end
  attributes_hash = include_root ? { "PaymentData" => hash } : hash  
  return attributes_hash
end

#to_sObject



188
189
190
# File 'lib/mastercard_merchant_checkout/models/payment_data.rb', line 188

def to_s
  to_hash.to_s
end