Class: ActiveMerchant::Billing::Integrations::Sermepa::Notification

Inherits:
Notification
  • Object
show all
Includes:
PostsData
Defined in:
lib/active_merchant/billing/integrations/sermepa/notification.rb

Instance Method Summary collapse

Instance Method Details

#acknowledge(credentials = nil) ⇒ Object

Acknowledge the transaction.

Validate the details provided by the gateway by ensuring that the signature matches up with the details provided.

Optionally, a set of credentials can be provided that should contain a :secret_key instead of using the global credentials defined in the Sermepa::Helper.

Example:

def notify
  notify = Sermepa::Notification.new(request.query_parameters)

  if notify.acknowledge
    ... process order ... if notify.complete?
  else
    ... log possible hacking attempt ...
  end


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 89

def acknowledge(credentials = nil)
  return false if params['ds_signature'].blank?
  str = 
    params['ds_amount'].to_s +
    params['ds_order'].to_s +
    params['ds_merchantcode'].to_s + 
    params['ds_currency'].to_s +
    params['ds_response'].to_s
  if xml?
    str += params['ds_transactiontype'].to_s + params['ds_securepayment'].to_s
  end

  str += (credentials || Sermepa::Helper.credentials)[:secret_key]
  sig = Digest::SHA1.hexdigest(str)
  sig.upcase == params['ds_signature'].to_s.upcase
end

#complete?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 9

def complete?
  status == 'Completed'
end

#currencyObject



37
38
39
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 37

def currency
  Sermepa.currency_from_code( params['ds_currency'] ) 
end

#error_codeObject



56
57
58
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 56

def error_code
  params['ds_response']
end

#error_messageObject



60
61
62
63
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 60

def error_message
  msg = Sermepa.response_code_message(error_code)
  error_code.to_s + ' - ' + (msg.nil? ? 'OperaciĆ³n Aceptada' : msg)
end

#grossObject

the money amount we received in cents in X.2 format



28
29
30
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 28

def gross
  sprintf("%.2f", params['ds_amount'].to_f / 100)
end

#received_atObject

When was this payment received by the client.



18
19
20
21
22
23
24
25
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 18

def received_at
  if params['ds_date']
    (day, month, year) = params['ds_date'].split('/')
    Time.parse("#{year}-#{month}-#{day} #{params['ds_hour']}")
  else
    Time.now # Not provided!
  end
end

#secure_payment?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 65

def secure_payment?
  params['ds_securepayment'] == '1'
end

#statusObject

Status of transaction. List of possible values: Completed Failed Pending



45
46
47
48
49
50
51
52
53
54
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 45

def status
  case error_code.to_i
  when 0..99
    'Completed'
  when 900
    'Pending'
  else
    'Failed'
  end
end

#test?Boolean

Was this a test transaction?

Returns:

  • (Boolean)


33
34
35
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 33

def test?
  false
end

#transaction_idObject



13
14
15
# File 'lib/active_merchant/billing/integrations/sermepa/notification.rb', line 13

def transaction_id
  params['ds_order']
end