Class: OffsitePayments::Integrations::Migs::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/offsite_payments/integrations/migs.rb

Instance Method Summary collapse

Constructor Details

#initialize(params, options = {}) ⇒ Notification

Returns a new instance of Notification.



61
62
63
64
65
# File 'lib/offsite_payments/integrations/migs.rb', line 61

def initialize(params, options = {})
  @params = params
  @response = parse
  @options = options
end

Instance Method Details

#acknowledgeObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/offsite_payments/integrations/migs.rb', line 93

def acknowledge
  # Failures don't include a secure hash, so return directly
  return true unless success?

  # Check SecureHash only on success (not returned otherwise)
  unless @response[:SecureHash] == expected_secure_hash
    raise SecurityError, "Secure Hash mismatch, response may be tampered with"
  end

  true
end

#avs_response_codeObject



73
74
75
76
77
# File 'lib/offsite_payments/integrations/migs.rb', line 73

def avs_response_code
  avs_response_code = @response[:AVSResultCode]
  avs_response_code = 'S' if avs_response_code == "Unsupported"
  avs_response_code
end

#card_codeObject



113
114
115
116
117
118
119
# File 'lib/offsite_payments/integrations/migs.rb', line 113

def card_code
  return unless @response.key?(:Card) # Card doesn't appear on failure
  migs_code = @response[:Card]
  CARD_TYPES.detect { |ct|
    ct.migs_code == migs_code
  }.am_code
end

#cvv_result_codeObject



79
80
81
82
83
# File 'lib/offsite_payments/integrations/migs.rb', line 79

def cvv_result_code
  cvv_result_code = @response[:CSCResultCode]
  cvv_result_code = 'P' if cvv_result_code == "Unsupported"
  cvv_result_code
end

#expected_secure_hashObject



105
106
107
# File 'lib/offsite_payments/integrations/migs.rb', line 105

def expected_secure_hash
  SecureHash.calculate(@options[:secure_hash], @response)
end

#fraud_review?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/offsite_payments/integrations/migs.rb', line 89

def fraud_review?
  ISSUER_RESPONSE_CODES[@response[:AcqResponseCode]] == 'Suspected Fraud'
end

#grossObject



109
110
111
# File 'lib/offsite_payments/integrations/migs.rb', line 109

def gross
  @response[:Amount].to_d / 100.0
end

#messageObject

only when error



133
134
135
# File 'lib/offsite_payments/integrations/migs.rb', line 133

def message # only when error
  @response['Message']
end

#order_idObject



121
122
123
# File 'lib/offsite_payments/integrations/migs.rb', line 121

def order_id
  @response[:OrderInfo]
end

#parseObject



67
68
69
70
71
# File 'lib/offsite_payments/integrations/migs.rb', line 67

def parse
  @params.map.with_object({}) { |(key, value), hash|
    hash[key.gsub('vpc_', '').to_sym] = value
  }
end

#success?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/offsite_payments/integrations/migs.rb', line 85

def success?
  @response[:TxnResponseCode] == '0'
end

#transaction_idObject



129
130
131
# File 'lib/offsite_payments/integrations/migs.rb', line 129

def transaction_id
  @response[:TransactionNo]
end

#uidObject



125
126
127
# File 'lib/offsite_payments/integrations/migs.rb', line 125

def uid
  @response[:MerchTxnRef]
end