Class: Kount::RIS::Inquiry
Constant Summary collapse
- PAYMENT_TYPES =
{ 'apay' => 'Apple Pay', 'card' => 'Credit Card', 'pypl' => 'PayPal', 'chek' => 'Check', 'none' => 'None', 'gdmp' => 'Green Dot Money Pack', 'goog' => 'Google Checkout', 'blml' => 'Bill Me Later', 'gift' => 'Gift Card', 'bpay' => 'BPAY', 'netellar' => 'Netellar', 'giropay' => 'GiroPay', 'elv' => 'ELV', 'mercade_pago' => 'Mercade Pago', 'sepa' => 'Single Euro Payments Area', 'interac' => 'Interac', 'poli' => 'POLi', 'skrill' => 'Skrill/Moneybookers', 'sofort' => 'Sofort', 'token' => 'Token', }.freeze
- SHIPPING_METHODS =
{ 'sd' => 'Same Day', 'nd' => 'Next Day', '2d' => 'Second Day', 'st' => 'Standard', }.freeze
- MODES =
%w[q u p x e j w].freeze
- RESPONSE_FORMATS =
%w[sdk xml json yaml].freeze
- GENDERS =
%w[male female].freeze
- CARD_TYPES =
%w[visa mastercard amex discover]
Constants inherited from Base
Instance Attribute Summary collapse
-
#account_created_at ⇒ Object
Returns the value of attribute account_created_at.
-
#acknowledged ⇒ Object
(also: #acknowledged?)
Returns the value of attribute acknowledged.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#authorized ⇒ Object
(also: #authorized?)
Returns the value of attribute authorized.
-
#avs_code ⇒ Object
Returns the value of attribute avs_code.
-
#billing_address ⇒ Object
Returns the value of attribute billing_address.
-
#birthdate ⇒ Object
Returns the value of attribute birthdate.
-
#card_number ⇒ Object
Returns the value of attribute card_number.
-
#card_type ⇒ Object
Returns the value of attribute card_type.
-
#customer_id ⇒ Object
Returns the value of attribute customer_id.
-
#cvv_code ⇒ Object
Returns the value of attribute cvv_code.
-
#email ⇒ Object
Returns the value of attribute email.
-
#gateway_id ⇒ Object
Returns the value of attribute gateway_id.
-
#gender ⇒ Object
Returns the value of attribute gender.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#kount_id ⇒ Object
Returns the value of attribute kount_id.
-
#last_four ⇒ Object
Returns the value of attribute last_four.
-
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#order_number ⇒ Object
Returns the value of attribute order_number.
-
#products ⇒ Object
Returns the value of attribute products.
-
#recipient_email ⇒ Object
Returns the value of attribute recipient_email.
-
#recipient_name ⇒ Object
Returns the value of attribute recipient_name.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#response_format ⇒ Object
Returns the value of attribute response_format.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#shipping_address ⇒ Object
Returns the value of attribute shipping_address.
-
#shipping_method ⇒ Object
Returns the value of attribute shipping_method.
-
#site_id ⇒ Object
Returns the value of attribute site_id.
-
#total ⇒ Object
Returns the value of attribute total.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Class Method Summary collapse
- .card_types ⇒ Object
- .currency_codes ⇒ Object
- .genders ⇒ Object
- .modes ⇒ Object
- .payment_types ⇒ Object
- .response_formats ⇒ Object
- .shipping_methods ⇒ Object
Instance Method Summary collapse
- #avs_match_street ⇒ Object (also: #avs_match_street?)
- #avs_match_zip ⇒ Object (also: #avs_match_zip?)
- #card_types ⇒ Object
- #currency_code ⇒ Object
- #currency_code=(value) ⇒ Object
- #currency_codes ⇒ Object
- #cvv_match ⇒ Object (also: #cvv_match?)
- #genders ⇒ Object
-
#initialize(attrs = {}) ⇒ Inquiry
constructor
A new instance of Inquiry.
- #mode?(*modes) ⇒ Boolean
- #modes ⇒ Object
- #payment_token ⇒ Object
- #payment_type ⇒ Object
- #payment_type=(value) ⇒ Object
- #payment_types ⇒ Object
- #response_formats ⇒ Object
- #shipping_methods ⇒ Object
- #submit! ⇒ Object
- #to_query ⇒ Object
- #to_query_params ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Inquiry
Returns a new instance of Inquiry.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'app/models/kount/ris/inquiry.rb', line 208 def initialize(attrs = {}) attrs.symbolize_keys! attrs.reverse_merge!(Kount.configuration.except(:company_server_url, :salt)) attrs.reverse_merge!({ authorized: true, acknowledged: true, email: '[email protected]', ip_address: '10.0.0.1', mode: :q, }) if attrs[:mode] == 'p' attrs.reverse_merge!({ id: '0123456789' }) attrs.merge!({ ip_address: '10.0.0.1' }) end super(attrs.except(:products_attributes, :shipping_address_attributes, :billing_address_attributes)) self.products = Array(attrs[:products_attributes]).collect { |product_attributes| Product.new(product_attributes) } self.shipping_address = Address.new(attrs[:shipping_address_attributes]) if attrs.include?(:shipping_address_attributes) self.billing_address = Address.new(attrs[:billing_address_attributes]) if attrs.include?(:billing_address_attributes) self end |
Instance Attribute Details
#account_created_at ⇒ Object
Returns the value of attribute account_created_at.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def account_created_at @account_created_at end |
#acknowledged ⇒ Object Also known as: acknowledged?
Returns the value of attribute acknowledged.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def acknowledged @acknowledged end |
#amount ⇒ Object
Returns the value of attribute amount.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def amount @amount end |
#api_host ⇒ Object
Returns the value of attribute api_host.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def api_host @api_host end |
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def api_key @api_key end |
#api_version ⇒ Object
Returns the value of attribute api_version.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def api_version @api_version end |
#authorized ⇒ Object Also known as:
Returns the value of attribute authorized.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def @authorized end |
#avs_code ⇒ Object
Returns the value of attribute avs_code.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def avs_code @avs_code end |
#billing_address ⇒ Object
Returns the value of attribute billing_address.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def billing_address @billing_address end |
#birthdate ⇒ Object
Returns the value of attribute birthdate.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def birthdate @birthdate end |
#card_number ⇒ Object
Returns the value of attribute card_number.
11 12 13 |
# File 'app/models/kount/ris/inquiry.rb', line 11 def card_number @card_number end |
#card_type ⇒ Object
Returns the value of attribute card_type.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def card_type @card_type end |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def customer_id @customer_id end |
#cvv_code ⇒ Object
Returns the value of attribute cvv_code.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def cvv_code @cvv_code end |
#email ⇒ Object
Returns the value of attribute email.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def email @email end |
#gateway_id ⇒ Object
Returns the value of attribute gateway_id.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def gateway_id @gateway_id end |
#gender ⇒ Object
Returns the value of attribute gender.
11 12 13 |
# File 'app/models/kount/ris/inquiry.rb', line 11 def gender @gender end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def id @id end |
#ip_address ⇒ Object
Returns the value of attribute ip_address.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def ip_address @ip_address end |
#kount_id ⇒ Object
Returns the value of attribute kount_id.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def kount_id @kount_id end |
#last_four ⇒ Object
Returns the value of attribute last_four.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def last_four @last_four end |
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def merchant_id @merchant_id end |
#mode ⇒ Object
Returns the value of attribute mode.
11 12 13 |
# File 'app/models/kount/ris/inquiry.rb', line 11 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def name @name end |
#order_number ⇒ Object
Returns the value of attribute order_number.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def order_number @order_number end |
#products ⇒ Object
Returns the value of attribute products.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def products @products end |
#recipient_email ⇒ Object
Returns the value of attribute recipient_email.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def recipient_email @recipient_email end |
#recipient_name ⇒ Object
Returns the value of attribute recipient_name.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def recipient_name @recipient_name end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
11 12 13 |
# File 'app/models/kount/ris/inquiry.rb', line 11 def response @response end |
#response_format ⇒ Object
Returns the value of attribute response_format.
11 12 13 |
# File 'app/models/kount/ris/inquiry.rb', line 11 def response_format @response_format end |
#session_id ⇒ Object
Returns the value of attribute session_id.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def session_id @session_id end |
#shipping_address ⇒ Object
Returns the value of attribute shipping_address.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def shipping_address @shipping_address end |
#shipping_method ⇒ Object
Returns the value of attribute shipping_method.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def shipping_method @shipping_method end |
#site_id ⇒ Object
Returns the value of attribute site_id.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def site_id @site_id end |
#total ⇒ Object
Returns the value of attribute total.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def total @total end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
7 8 9 |
# File 'app/models/kount/ris/inquiry.rb', line 7 def user_agent @user_agent end |
Class Method Details
.card_types ⇒ Object
74 75 76 |
# File 'app/models/kount/ris/inquiry.rb', line 74 def card_types CARD_TYPES end |
.currency_codes ⇒ Object
50 51 52 |
# File 'app/models/kount/ris/inquiry.rb', line 50 def currency_codes Kount::RIS::Base::COUNTRY_CODES end |
.genders ⇒ Object
70 71 72 |
# File 'app/models/kount/ris/inquiry.rb', line 70 def genders GENDERS end |
.modes ⇒ Object
62 63 64 |
# File 'app/models/kount/ris/inquiry.rb', line 62 def modes MODES end |
.payment_types ⇒ Object
54 55 56 |
# File 'app/models/kount/ris/inquiry.rb', line 54 def payment_types PAYMENT_TYPES end |
.response_formats ⇒ Object
66 67 68 |
# File 'app/models/kount/ris/inquiry.rb', line 66 def response_formats RESPONSE_FORMATS end |
.shipping_methods ⇒ Object
58 59 60 |
# File 'app/models/kount/ris/inquiry.rb', line 58 def shipping_methods SHIPPING_METHODS end |
Instance Method Details
#avs_match_street ⇒ Object Also known as: avs_match_street?
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'app/models/kount/ris/inquiry.rb', line 236 def avs_match_street { a: { visa: true, mastercard: true, discover: true, amex: true }, b: { visa: true }, d: { visa: true }, f: { visa: true, amex: true }, m: { visa: true, amex: true }, n: { visa: false, mastercard: false, discover: false, amex: false }, o: { amex: true }, t: { discover: false }, w: { visa: false, mastercard: false, discover: false, amex: false }, x: { visa: true, mastercard: true, discover: true }, y: { visa: true, mastercard: true, discover: true, amex: true }, z: { visa: false, mastercard: false, discover: false, amex: false }, }.dig(avs_code.to_s.downcase.to_sym, card_type.to_sym) if avs_code.present? && card_type.present? end |
#avs_match_zip ⇒ Object Also known as: avs_match_zip?
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'app/models/kount/ris/inquiry.rb', line 254 def avs_match_zip { a: { visa: false, mastercard: true, discover: false, amex: true }, d: { visa: true }, f: { visa: true }, l: { amex: true }, m: { visa: true, amex: true }, n: { visa: false, mastercard: false, discover: false, amex: false }, p: { visa: true }, t: { discover: true }, w: { visa: true, mastercard: true, discover: true, amex: false }, x: { visa: true, mastercard: true, discover: true }, y: { visa: true, mastercard: true, discover: true, amex: true }, z: { visa: true, mastercard: true, discover: true, amex: true }, }.dig(avs_code.to_s.downcase.to_sym, card_type.to_sym) if avs_code.present? && card_type.present? end |
#card_types ⇒ Object
103 104 105 |
# File 'app/models/kount/ris/inquiry.rb', line 103 def card_types self.class.card_types end |
#currency_code ⇒ Object
145 146 147 |
# File 'app/models/kount/ris/inquiry.rb', line 145 def currency_code @currency_code.upcase if @currency_code end |
#currency_code=(value) ⇒ Object
141 142 143 |
# File 'app/models/kount/ris/inquiry.rb', line 141 def currency_code=(value) @currency_code = value.to_s.downcase end |
#currency_codes ⇒ Object
79 80 81 |
# File 'app/models/kount/ris/inquiry.rb', line 79 def currency_codes self.class.currency_codes end |
#cvv_match ⇒ Object Also known as: cvv_match?
272 273 274 275 276 277 |
# File 'app/models/kount/ris/inquiry.rb', line 272 def cvv_match case cvv_code.to_s.to_sym when :m, :y, :'0' then true when :n, :'1' then false end if cvv_code.present? end |
#genders ⇒ Object
99 100 101 |
# File 'app/models/kount/ris/inquiry.rb', line 99 def genders self.class.genders end |
#mode?(*modes) ⇒ Boolean
280 281 282 |
# File 'app/models/kount/ris/inquiry.rb', line 280 def mode?(*modes) Array(modes).collect(&:to_s).include? mode end |
#modes ⇒ Object
91 92 93 |
# File 'app/models/kount/ris/inquiry.rb', line 91 def modes self.class.modes end |
#payment_token ⇒ Object
232 233 234 |
# File 'app/models/kount/ris/inquiry.rb', line 232 def payment_token card_number =~ /x/i ? card_number : KHASH.new(card_number).to_s end |
#payment_type ⇒ Object
157 158 159 |
# File 'app/models/kount/ris/inquiry.rb', line 157 def payment_type payment_types[@payment_type] end |
#payment_type=(value) ⇒ Object
149 150 151 152 153 154 155 |
# File 'app/models/kount/ris/inquiry.rb', line 149 def payment_type=(value) return @payment_type = nil if value.nil? payment_type_value = payment_types.detect { |k,v| k if v.downcase == value.to_s.downcase }&.first || value.to_s.downcase raise ArgumentError, "'#{value}' is not a valid payment type" unless payment_types.include?(payment_type_value) @payment_type = payment_type_value end |
#payment_types ⇒ Object
83 84 85 |
# File 'app/models/kount/ris/inquiry.rb', line 83 def payment_types self.class.payment_types end |
#response_formats ⇒ Object
95 96 97 |
# File 'app/models/kount/ris/inquiry.rb', line 95 def response_formats self.class.response_formats end |
#shipping_methods ⇒ Object
87 88 89 |
# File 'app/models/kount/ris/inquiry.rb', line 87 def shipping_methods self.class.shipping_methods end |
#submit! ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'app/models/kount/ris/inquiry.rb', line 358 def submit! uri = URI.parse("https://#{api_host}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request["X-Kount-Api-Key"] = api_key request.set_form_data(to_query_params) response = http.request(request) response_params = response.body.split("\n").collect { |params| Rack::Utils.parse_nested_query(params) }.reduce({}, :merge) @response = Response.new(response_params) end |
#to_query ⇒ Object
354 355 356 |
# File 'app/models/kount/ris/inquiry.rb', line 354 def to_query to_query_params.to_query end |
#to_query_params ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'app/models/kount/ris/inquiry.rb', line 284 def to_query_params query_params = { ANID: id, AUTH: (( ? 'A' : 'D') unless .nil?), CURR: currency_code, EMAL: email, IPAD: ip_address, MACK: ('Y' if acknowledged?), MERC: merchant_id, MODE: (mode.to_s.upcase unless mode.nil?), PROD_DESC: products.collect(&:description), PROD_ITEM: products.collect(&:id), PROD_PRICE: products.collect(&:price), PROD_QUANT: products.collect(&:quantity), PROD_TYPE: products.collect(&:category), PTOK: payment_token, PTYP: @payment_type, SESS: session_id, SITE: site_id, TOTL: (total || products.sum { |product| product.price * product.quantity }), TRAN: kount_id, VERS: api_version, CUSTOMER_ID: gateway_id, AVST: (avs_match_street.nil? ? 'X' : (avs_match_street? ? 'M' : 'N')), AVSZ: (avs_match_zip.nil? ? 'X' : (avs_match_zip? ? 'M' : 'N')), CASH: amount, CVVR: (cvv_match.nil? ? 'X' : (cvv_match? ? 'M' : 'N')), S2EM: recipient_email, S2NM: recipient_name, SHTP: @shipping_method, UNIQ: customer_id, UAGT: user_agent, DOB: (birthdate.strftime('%Y-%m-%d') unless birthdate.nil?), EPOC: (account_created_at.to_i unless account_created_at.nil?), FRMT: (response_format.to_s.upcase unless response_format.nil?), GENDER: gender, LAST4: last_four, NAME: name, ORDR: order_number, } query_params.merge!({ B2A1: shipping_address.address_1, B2A2: shipping_address.address_2, B2CC: shipping_address.country_code, B2CI: shipping_address.city, B2PC: shipping_address.postal_code, B2PN: shipping_address.phone, B2ST: shipping_address.region, BPREMISE: shipping_address.premise, BSTREET: shipping_address.thoroughfare, }) if shipping_address.present? query_params.merge!({ S2A1: billing_address.address_1, S2A2: billing_address.address_2, S2CC: billing_address.country_code, S2CI: billing_address.city, S2PC: billing_address.postal_code, S2PN: billing_address.phone, S2ST: billing_address.region, SPREMISE: billing_address.premise, SSTREET: billing_address.thoroughfare, }) if billing_address.present? # validate total length of URL including domain - 4k limit query_params.compact! end |