Class: DhanHQ::Models::Postback
- Defined in:
- lib/DhanHQ/models/postback.rb
Overview
Postback URL is configured in the Dhan web console when generating an access token. It will NOT work with localhost or 127.0.0.1.
Utility model for parsing Dhan postback (webhook) payloads.
Postback is a webhook mechanism where Dhan pushes order status updates to your configured URL. This model provides a convenient way to parse the incoming JSON payload into a typed, attribute-accessible object.
Constant Summary collapse
- HTTP_PATH =
No API endpoint — postback is pushed to the user
nil
Constants included from ResponseHelper
ResponseHelper::STATUS_ERROR_FALLBACK
Instance Attribute Summary
Attributes inherited from BaseModel
Class Method Summary collapse
-
.parse(payload) ⇒ Postback
Parse a postback webhook payload into a Postback model instance.
Instance Method Summary collapse
-
#cancelled? ⇒ Boolean
Whether the order was cancelled.
-
#pending? ⇒ Boolean
Whether the order is still pending.
-
#rejected? ⇒ Boolean
Whether the order was rejected.
-
#traded? ⇒ Boolean
Whether the order has been fully traded.
Methods inherited from BaseModel
all, api, api_type, #assign_attributes, attributes, create, #delete, #destroy, find, #id, #initialize, #new_record?, #optionchain_api?, parse_collection_response, #persisted?, resource, resource_path, #save, #save!, #to_request_params, #update, #valid?, validate_attributes, validation_contract, #validation_contract, where
Methods included from APIHelper
Methods included from AttributeHelper
#camelize_keys, #inspect, #normalize_keys, #snake_case, #titleize_keys
Methods included from ValidationHelper
#valid?, #validate!, #validate_params!
Methods included from RequestHelper
Constructor Details
This class inherits a constructor from DhanHQ::BaseModel
Class Method Details
.parse(payload) ⇒ Postback
Parse a postback webhook payload into a Postback model instance.
Accepts either a JSON string (from request body) or a Hash (from parsed params). Keys are normalized to snake_case automatically.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/DhanHQ/models/postback.rb', line 67 def parse(payload) data = case payload when String JSON.parse(payload) when Hash payload else raise ArgumentError, "Expected String or Hash, got #{payload.class}" end new(data, skip_validation: true) end |
Instance Method Details
#cancelled? ⇒ Boolean
Whether the order was cancelled.
109 110 111 |
# File 'lib/DhanHQ/models/postback.rb', line 109 def cancelled? order_status == DhanHQ::Constants::OrderStatus::CANCELLED end |
#pending? ⇒ Boolean
Whether the order is still pending.
101 102 103 |
# File 'lib/DhanHQ/models/postback.rb', line 101 def pending? order_status == DhanHQ::Constants::OrderStatus::PENDING end |
#rejected? ⇒ Boolean
Whether the order was rejected.
93 94 95 |
# File 'lib/DhanHQ/models/postback.rb', line 93 def rejected? order_status == DhanHQ::Constants::OrderStatus::REJECTED end |
#traded? ⇒ Boolean
Whether the order has been fully traded.
85 86 87 |
# File 'lib/DhanHQ/models/postback.rb', line 85 def traded? order_status == DhanHQ::Constants::OrderStatus::TRADED end |