Module: ActiveMerchant::Billing::Integrations::Pizza::Notification
- Included in:
- SampoEst::Notification, SebEst::Notification, SwedbankEst::Notification
- Defined in:
- lib/active_merchant/billing/integrations/pizza/notification.rb
Class Method Summary collapse
-
.get_notification(http_raw_data) ⇒ Object
A helper method to parse the raw post of the request & return the right Notification subclass based on the sender id.
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.
-
#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
-
#gross ⇒ Object
The money amount we received, string.
-
#item_id ⇒ Object
The order id we passed to the form helper.
-
#received_at ⇒ Object
When was this payment received by the client.
- #signature ⇒ Object
-
#status ⇒ Object
TODO what should be here?.
- #success? ⇒ Boolean
-
#test? ⇒ Boolean
Was this a test transaction?.
- #transaction_id ⇒ Object
Class Method Details
.get_notification(http_raw_data) ⇒ Object
A helper method to parse the raw post of the request & return the right Notification subclass based on the sender id.
9 10 11 12 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 9 def self.get_notification(http_raw_data) params = ActiveMerchant::Billing::Integrations::Notification.new(http_raw_data).params Pizza.get_class(params['VK_SND_ID'])::Notification.new(params) 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
86 87 88 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 86 def acknowledge bank_signature_valid?(signature, params['VK_SERVICE'], params) 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).
65 66 67 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 65 def automatic? params['VK_AUTO'].upcase == 'Y' end |
#bank_signature_valid?(bank_signature, service_msg_number, sigparams) ⇒ Boolean
14 15 16 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 14 def bank_signature_valid?(bank_signature, service_msg_number, sigparams) self.class.parent.get_bank_public_key.verify(OpenSSL::Digest::SHA1.new, bank_signature, generate_data_string(service_msg_number, sigparams)) end |
#complete? ⇒ Boolean
18 19 20 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 18 def complete? params['VK_SERVICE'] == '1101' end |
#currency ⇒ Object
22 23 24 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 22 def currency params['VK_CURR'] end |
#gross ⇒ Object
The money amount we received, string.
49 50 51 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 49 def gross params['VK_AMOUNT'] end |
#item_id ⇒ Object
The order id we passed to the form helper.
27 28 29 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 27 def item_id params['VK_STAMP'] end |
#received_at ⇒ Object
When was this payment received by the client. We’re expecting a dd.mm.yyyy format.
37 38 39 40 41 42 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 37 def received_at date = params['VK_T_DATE'] return nil unless date day, month, year = *date.split('.').map(&:to_i) Date.civil(year, month, day) end |
#signature ⇒ Object
44 45 46 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 44 def signature Base64.decode64(params['VK_MAC']) end |
#status ⇒ Object
TODO what should be here?
59 60 61 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 59 def status complete? ? 'Completed' : 'Failed' end |
#success? ⇒ Boolean
69 70 71 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 69 def success? acknowledge && complete? end |
#test? ⇒ Boolean
Was this a test transaction?
54 55 56 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 54 def test? params['VK_REC_ID'] == 'testvpos' end |
#transaction_id ⇒ Object
31 32 33 |
# File 'lib/active_merchant/billing/integrations/pizza/notification.rb', line 31 def transaction_id params['VK_T_NO'] end |