Class: Banklink::Seb::Notification
- Inherits:
-
Object
- Object
- Banklink::Seb::Notification
- Includes:
- Common
- Defined in:
- lib/banklink/seb/notification.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#production_ips ⇒ Object
set this to an array in the subclass, to specify which IPs are allowed to send requests.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#acknowledge ⇒ Object
We don’t actually acknowledge the notification by making another request ourself, instead, we check the notification by checking the signature that came with the notification.
-
#amount ⇒ Object
This combines the gross and currency and returns a proper Money object.
-
#automatic? ⇒ Boolean
If our request was sent automatically by the bank (true) or manually by the user triggering the callback by pressing a “return” button (false).
- #bank_signature_valid?(bank_signature, service_msg_number, sigparams) ⇒ Boolean
- #complete? ⇒ Boolean
- #currency ⇒ Object
-
#empty! ⇒ Object
reset the notification.
- #failed? ⇒ Boolean
- #get_data_string ⇒ Object
-
#gross ⇒ Object
The money amount we received, string.
- #gross_cents ⇒ Object
-
#initialize(post, options = {}) ⇒ Notification
constructor
A new instance of Notification.
-
#received_at ⇒ Object
When was this payment received by the client.
- #receiver_bank_account ⇒ Object (also: #reciever_bank_account)
- #receiver_name ⇒ Object (also: #reciever_name)
- #sender_bank_account ⇒ Object
- #sender_name ⇒ Object
- #signature ⇒ Object
-
#status ⇒ Object
TODO what should be here?.
- #success? ⇒ Boolean
-
#test? ⇒ Boolean
Was this a test transaction?.
- #transaction_id ⇒ Object
-
#valid_sender?(ip) ⇒ Boolean
Check if the request comes from an official IP.
- #wait? ⇒ Boolean
Methods included from Common
#encode_to_utf8, #func_p, #generate_data_string, #generate_mac, #generate_signature, #parse
Constructor Details
#initialize(post, options = {}) ⇒ Notification
Returns a new instance of Notification.
12 13 14 15 16 |
# File 'lib/banklink/seb/notification.rb', line 12 def initialize(post, = {}) @options = empty! parse(post) end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/banklink/seb/notification.rb', line 6 def params @params end |
#production_ips ⇒ Object
set this to an array in the subclass, to specify which IPs are allowed to send requests
10 11 12 |
# File 'lib/banklink/seb/notification.rb', line 10 def production_ips @production_ips end |
#raw ⇒ Object
Returns the value of attribute raw.
7 8 9 |
# File 'lib/banklink/seb/notification.rb', line 7 def raw @raw end |
Instance Method Details
#acknowledge ⇒ Object
We don’t actually acknowledge the notification by making another request ourself, instead, we check the notification by checking the signature that came with the notification. This method has to be called when handling the notification & deciding whether to process the order. Example:
def notify
notify = Notification.new(params)
if notify.acknowledge
... process order ... if notify.complete?
else
... log possible hacking attempt ...
end
130 131 132 |
# File 'lib/banklink/seb/notification.rb', line 130 def acknowledge bank_signature_valid?(signature, params['IB_SERVICE'], params) end |
#amount ⇒ Object
This combines the gross and currency and returns a proper Money object. this requires the money library located at dist.leetsoft.com/api/money
24 25 26 |
# File 'lib/banklink/seb/notification.rb', line 24 def amount return gross_cents end |
#automatic? ⇒ Boolean
If our request was sent automatically by the bank (true) or manually by the user triggering the callback by pressing a “return” button (false).
109 110 111 |
# File 'lib/banklink/seb/notification.rb', line 109 def automatic? (params['IB_FROM_SERVER'].present? && params['IB_FROM_SERVER'].upcase == 'Y') end |
#bank_signature_valid?(bank_signature, service_msg_number, sigparams) ⇒ Boolean
138 139 140 |
# File 'lib/banklink/seb/notification.rb', line 138 def bank_signature_valid?(bank_signature, service_msg_number, sigparams) Seb.get_bank_public_key.verify(OpenSSL::Digest::SHA1.new, bank_signature, generate_data_string(service_msg_number, sigparams, Seb.required_service_params)) end |
#complete? ⇒ Boolean
40 41 42 |
# File 'lib/banklink/seb/notification.rb', line 40 def complete? params['IB_STATUS'] == 'ACCOMPLISHED' end |
#currency ⇒ Object
52 53 54 |
# File 'lib/banklink/seb/notification.rb', line 52 def currency params['IB_CURR'] end |
#empty! ⇒ Object
reset the notification.
29 30 31 32 |
# File 'lib/banklink/seb/notification.rb', line 29 def empty! @params = Hash.new @raw = "" end |
#failed? ⇒ Boolean
48 49 50 |
# File 'lib/banklink/seb/notification.rb', line 48 def failed? params['IB_SERVICE'] == '1901' end |
#get_data_string ⇒ Object
134 135 136 |
# File 'lib/banklink/seb/notification.rb', line 134 def get_data_string generate_data_string(params['IB_SERVICE'], params, Seb.required_service_params) end |
#gross ⇒ Object
The money amount we received, string.
93 94 95 |
# File 'lib/banklink/seb/notification.rb', line 93 def gross params['IB_AMOUNT'] end |
#gross_cents ⇒ Object
18 19 20 |
# File 'lib/banklink/seb/notification.rb', line 18 def gross_cents (gross.to_f * 100.0).round end |
#received_at ⇒ Object
When was this payment received by the client. We’re expecting a dd.mm.yyyy format.
80 81 82 83 84 85 86 |
# File 'lib/banklink/seb/notification.rb', line 80 def received_at require 'date' date = params['IB_T_DATE'] return nil unless date day, month, year = *date.split('.').map(&:to_i) Date.civil(year, month, day) end |
#receiver_bank_account ⇒ Object Also known as: reciever_bank_account
73 74 75 |
# File 'lib/banklink/seb/notification.rb', line 73 def receiver_bank_account params['IB_REC_ACC'] end |
#receiver_name ⇒ Object Also known as: reciever_name
68 69 70 |
# File 'lib/banklink/seb/notification.rb', line 68 def receiver_name params['IB_REC_NAME'] end |
#sender_bank_account ⇒ Object
64 65 66 |
# File 'lib/banklink/seb/notification.rb', line 64 def sender_bank_account params['IB_PAYER_ACC'] end |
#sender_name ⇒ Object
60 61 62 |
# File 'lib/banklink/seb/notification.rb', line 60 def sender_name params['IB_PAYER_NAME'] end |
#signature ⇒ Object
88 89 90 |
# File 'lib/banklink/seb/notification.rb', line 88 def signature Base64.decode64(params['IB_CRC']) end |
#status ⇒ Object
TODO what should be here?
103 104 105 |
# File 'lib/banklink/seb/notification.rb', line 103 def status complete? ? 'Completed' : 'Failed' end |
#success? ⇒ Boolean
113 114 115 |
# File 'lib/banklink/seb/notification.rb', line 113 def success? acknowledge && complete? end |
#test? ⇒ Boolean
Was this a test transaction?
98 99 100 |
# File 'lib/banklink/seb/notification.rb', line 98 def test? params['IB_REC_ID'] == 'testvpos' end |
#transaction_id ⇒ Object
56 57 58 |
# File 'lib/banklink/seb/notification.rb', line 56 def transaction_id params['IB_PAYMENT_ID'] end |
#valid_sender?(ip) ⇒ Boolean
Check if the request comes from an official IP
35 36 37 38 |
# File 'lib/banklink/seb/notification.rb', line 35 def valid_sender?(ip) return true if Rails.env == :test || production_ips.blank? production_ips.include?(ip) end |
#wait? ⇒ Boolean
44 45 46 |
# File 'lib/banklink/seb/notification.rb', line 44 def wait? params['IB_SERVICE'] == '1201' end |