зеркало из
https://github.com/glebtv/yookassa.git
synced 2026-08-28 15:16:18 +03:00
1.6 KiB
1.6 KiB
Webhooks
Overview
The gem provides a Rails engine endpoint for YooKassa webhooks and a default controller that performs security checks before running your app-specific logic.
Default endpoint after mounting engine:
POST /yookassa/webhooks/:token
Security model
The controller accepts a webhook only if all checks pass:
- Route token matches configured
Yookassa.config.webhook_token. - Source IP from
request.remote_ipbelongs to allowed CIDRs. - Webhook object
idandstatusmatch a fresh API fetch (payments.findorrefunds.find).
This follows YooKassa webhook guidance:
Default allowed IP ranges
From YooKassa docs (source: https://yookassa.ru/developers/using-api/webhooks#ip):
185.71.76.0/27185.71.77.0/2777.75.153.0/2577.75.156.1177.75.156.3577.75.154.128/252a02:5180::/32
Configuration
Yookassa.configure do |config|
config.shop_id = ENV.fetch("YOOKASSA_SHOP_ID")
config.api_key = ENV.fetch("YOOKASSA_API_KEY")
config.webhook_token = ENV.fetch("YOOKASSA_WEBHOOK_TOKEN")
# Optional override
# config.webhook_allowed_ips = ["203.0.113.10"]
end
Overriding controller behavior
Inherit from Yookassa::WebhooksController and override process_webhook.
All security checks remain in the base controller.
class MyYookassaWebhooksController < Yookassa::WebhooksController
private
def process_webhook(payload)
event = payload["event"]
object = payload["object"]
# app-specific logic
end
end
Route example:
post "/webhooks/yookassa/:token", to: "my_yookassa_webhooks#create"