Class: CloudPayments::Webhooks
- Inherits:
-
Object
- Object
- CloudPayments::Webhooks
- Defined in:
- lib/cloud_payments/webhooks.rb
Defined Under Namespace
Classes: HMACError
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #data_valid?(data, hmac) ⇒ Boolean
-
#initialize(config = nil) ⇒ Webhooks
constructor
A new instance of Webhooks.
- #kassa_receipt(data) ⇒ Object
- #on_fail(data) ⇒ Object
- #on_pay(data) ⇒ Object
- #on_recurrent(data) ⇒ Object
- #validate_data!(data, hmac) ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Webhooks
Returns a new instance of Webhooks.
11 12 13 14 15 |
# File 'lib/cloud_payments/webhooks.rb', line 11 def initialize(config = nil) @config = config || CloudPayments.config @digest = OpenSSL::Digest.new('sha256') @serializer = Client::Serializer::Base.new(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/cloud_payments/webhooks.rb', line 9 def config @config end |
Instance Method Details
#data_valid?(data, hmac) ⇒ Boolean
17 18 19 |
# File 'lib/cloud_payments/webhooks.rb', line 17 def data_valid?(data, hmac) Base64.decode64(hmac) == OpenSSL::HMAC.digest(@digest, config.secret_key, data) end |
#kassa_receipt(data) ⇒ Object
26 27 28 |
# File 'lib/cloud_payments/webhooks.rb', line 26 def kassa_receipt(data) OnKassaReceipt.new(@serializer.load(data)) end |
#on_fail(data) ⇒ Object
38 39 40 |
# File 'lib/cloud_payments/webhooks.rb', line 38 def on_fail(data) OnFail.new(@serializer.load(data)) end |
#on_pay(data) ⇒ Object
34 35 36 |
# File 'lib/cloud_payments/webhooks.rb', line 34 def on_pay(data) OnPay.new(@serializer.load(data)) end |
#on_recurrent(data) ⇒ Object
30 31 32 |
# File 'lib/cloud_payments/webhooks.rb', line 30 def on_recurrent(data) OnRecurrent.new(@serializer.load(data)) end |
#validate_data!(data, hmac) ⇒ Object
21 22 23 24 |
# File 'lib/cloud_payments/webhooks.rb', line 21 def validate_data!(data, hmac) raise HMACError unless data_valid?(data, hmac) true end |