Class: OffsitePayments::Integrations::Citrus::Notification

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

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

#empty!, #gross_cents, #iso_currency, #test?, #valid_sender?

Constructor Details

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


71
72
73
74
# File 'lib/offsite_payments/integrations/citrus.rb', line 71

def initialize(post, options = {})
  super(post, options)
  @secret_key = options[:credential2]
end

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object


180
181
182
# File 'lib/offsite_payments/integrations/citrus.rb', line 180

def acknowledge(authcode = nil)
  checksum_ok?
end

#amountObject


122
123
124
# File 'lib/offsite_payments/integrations/citrus.rb', line 122

def amount
  gross
end

#amount_ok?(order_amount) ⇒ Boolean


99
100
101
# File 'lib/offsite_payments/integrations/citrus.rb', line 99

def amount_ok?( order_amount )
  BigDecimal.new( amount ) == order_amount
end

#authidcodeObject


134
135
136
# File 'lib/offsite_payments/integrations/citrus.rb', line 134

def authidcode
  params['authIdCode']
end

#checksumObject


142
143
144
# File 'lib/offsite_payments/integrations/citrus.rb', line 142

def checksum
  params['signature']
end

#checksum_ok?Boolean


184
185
186
187
188
189
190
191
192
# File 'lib/offsite_payments/integrations/citrus.rb', line 184

def checksum_ok?
  fields = [invoice, transaction_status, amount.to_s, transaction_id, issuerrefno, authidcode, customer_first_name, customer_last_name, pgrespcode, customer_address[:zip]].join

  unless Citrus.checksum(@secret_key, fields ) == checksum
    @message = 'checksum mismatch...'
    return false
  end
  true
end

#complete?Boolean


76
77
78
# File 'lib/offsite_payments/integrations/citrus.rb', line 76

def complete?
  status == "Completed" || status == 'Canceled'
end

#currencyObject


150
151
152
# File 'lib/offsite_payments/integrations/citrus.rb', line 150

def currency
  params['currency']
end

#customer_addressObject


170
171
172
173
174
# File 'lib/offsite_payments/integrations/citrus.rb', line 170

def customer_address
  { :address1 => params['addressStreet1'], :address2 => params['addressStreet2'],
    :city => params['addressCity'], :state => params['addressState'],
    :country => params['addressCountry'], :zip => params['addressZip'] }
end

#customer_emailObject


154
155
156
# File 'lib/offsite_payments/integrations/citrus.rb', line 154

def customer_email
  params['email']
end

#customer_first_nameObject


162
163
164
# File 'lib/offsite_payments/integrations/citrus.rb', line 162

def customer_first_name
  params['firstName']
end

#customer_last_nameObject


166
167
168
# File 'lib/offsite_payments/integrations/citrus.rb', line 166

def customer_last_name
  params['lastName']
end

#customer_phoneObject


158
159
160
# File 'lib/offsite_payments/integrations/citrus.rb', line 158

def customer_phone
  params['mobileNo']
end

#grossObject


118
119
120
# File 'lib/offsite_payments/integrations/citrus.rb', line 118

def gross
  params['amount']
end

#invoiceObject


107
108
109
# File 'lib/offsite_payments/integrations/citrus.rb', line 107

def invoice
  item_id
end

#invoice_ok?(order_id) ⇒ Boolean


95
96
97
# File 'lib/offsite_payments/integrations/citrus.rb', line 95

def invoice_ok?( order_id )
  order_id.to_s == invoice.to_s
end

#issuerrefnoObject


130
131
132
# File 'lib/offsite_payments/integrations/citrus.rb', line 130

def issuerrefno
  params['issuerRefNo']
end

#item_idObject


103
104
105
# File 'lib/offsite_payments/integrations/citrus.rb', line 103

def item_id
  params['TxId']
end

#messageObject


176
177
178
# File 'lib/offsite_payments/integrations/citrus.rb', line 176

def message
  @message || params['TxMsg']
end

#paymentmodeObject


146
147
148
# File 'lib/offsite_payments/integrations/citrus.rb', line 146

def paymentmode
  params['paymentMode']
end

#pgrespcodeObject


138
139
140
# File 'lib/offsite_payments/integrations/citrus.rb', line 138

def pgrespcode
  params['pgRespCode']
end

#statusObject


80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/offsite_payments/integrations/citrus.rb', line 80

def status
  @status ||= if checksum_ok?
    if transaction_id.blank?
      'Invalid'
    else
      case transaction_status.downcase
      when 'success' then 'Completed'
      when 'canceled' then 'Cancelled'
      end
    end
  else
    'Tampered'
  end
end

#transaction_idObject


126
127
128
# File 'lib/offsite_payments/integrations/citrus.rb', line 126

def transaction_id
  params['pgTxnNo']
end

#transaction_statusObject

Status of transaction return from the Citrus. List of possible values:

SUCCESS
CANCELED

114
115
116
# File 'lib/offsite_payments/integrations/citrus.rb', line 114

def transaction_status
  params['TxStatus']
end