Class: QiwiObserver::WebhookRegistration
- Inherits:
-
Object
- Object
- QiwiObserver::WebhookRegistration
- Defined in:
- lib/qiwi_observer/webhook/webhook_registration.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(url) ⇒ WebhookRegistration
constructor
A new instance of WebhookRegistration.
Constructor Details
#initialize(url) ⇒ WebhookRegistration
Returns a new instance of WebhookRegistration.
5 6 7 8 9 10 11 |
# File 'lib/qiwi_observer/webhook/webhook_registration.rb', line 5 def initialize(url) @token = QiwiObserver.config.token @url = url raise ArgumentError, "Token must be configure in QiwiObserver" if @token.nil? raise ArgumentError, "URL must be set" unless url end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/qiwi_observer/webhook/webhook_registration.rb', line 13 def call query = URI.encode_www_form({hookType: 1, param: @url, txnType: "2"}) uri = URI("https://edge.qiwi.com/payment-notifier/v1/hooks?#{query}") request = prepare_a_request(uri) http = connect_to_api(uri) response = http.request(request) return WebhookResponse.new(success: true, body: response.body) if response.is_a?(Net::HTTPOK) return WebhookResponse.new(success: false, body: [response.code, response.]) end |