Class: Plaid::Protect::Client
- Inherits:
-
Object
- Object
- Plaid::Protect::Client
- Defined in:
- lib/plaid/protect/client.rb
Instance Method Summary collapse
-
#compute(request_options: {}, **params) ⇒ Plaid::Types::ProtectComputeResponse
Compute a Protect Trust Index score for a user.
-
#create_cash_advance_decision(request_options: {}, **params) ⇒ Plaid::Types::ProtectCashAdvanceDecisionCreateResponse
Use this endpoint to record a cash-advance decision as feedback.
-
#create_cash_advance_repayment(request_options: {}, **params) ⇒ Plaid::Types::ProtectCashAdvanceRepaymentCreateResponse
Use this endpoint to record a cash-advance repayment as feedback.
-
#create_report(request_options: {}, **params) ⇒ Plaid::Types::ProtectReportCreateResponse
Use this endpoint to create a Protect report to document fraud incidents, investigation outcomes, or other risk events.
-
#get_event(request_options: {}, **params) ⇒ Plaid::Types::ProtectEventGetResponse
Get information about a user event including Trust Index score and fraud attributes.
-
#get_user_insights(request_options: {}, **params) ⇒ Plaid::Types::ProtectUserInsightsGetResponse
Use this endpoint to get basic information about a user as it relates to their fraud profile with Protect.
- #initialize(client:) ⇒ void constructor
-
#send_event(request_options: {}, **params) ⇒ Plaid::Types::ProtectEventSendResponse
Send a new event to enrich user data and optionally get a Trust Index score for the event.
-
#upload_cash_advance_feedback(request_options: {}, **params) ⇒ Plaid::Types::ProtectCashAdvanceFeedbackUploadResponse
Upload a CSV file of cash advance decision or repayment feedback.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/plaid/protect/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#compute(request_options: {}, **params) ⇒ Plaid::Types::ProtectComputeResponse
Compute a Protect Trust Index score for a user. The model selected determines what is scored and what additional
fields the response contains. For example, ti-link-session-3-<client> scores a completed Link session for
fraud risk; cash-advance-ongoing-<client>-1.0 scores repayment risk for a cash advance, additionally
populating per-amount-bucket subscores. Cash-advance models require that the user have a Plaid Item with
Transactions enabled, or an Assets Report, before scoring.
The endpoint returns HTTP 400 with error_type = INVALID_REQUEST and error_code = FAILED_PRECONDITION
when a required precondition is not met: for link-session models, when the Link session has not completed; for
cash-advance models, when the user has not successfully linked any Item. For device-session models, the endpoint
may return retryable error_code = SESSION_NOT_READY until the Protect SDK has delivered device data for the
session.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/plaid/protect/client.rb', line 327 def compute(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/compute", body: Plaid::Protect::Types::ProtectComputeRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectComputeResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#create_cash_advance_decision(request_options: {}, **params) ⇒ Plaid::Types::ProtectCashAdvanceDecisionCreateResponse
Use this endpoint to record a cash-advance decision as feedback. A decision is a determination of whether to approve a user's requested advance and on what terms.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/plaid/protect/client.rb', line 146 def create_cash_advance_decision(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/cash_advance/decision/create", body: Plaid::Protect::Types::ProtectCashAdvanceDecisionCreateRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectCashAdvanceDecisionCreateResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#create_cash_advance_repayment(request_options: {}, **params) ⇒ Plaid::Types::ProtectCashAdvanceRepaymentCreateResponse
Use this endpoint to record a cash-advance repayment as feedback. A repayment is a record paying back all or some of a previously-taken cash-advance.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/plaid/protect/client.rb', line 207 def create_cash_advance_repayment(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/cash_advance/repayment/create", body: Plaid::Protect::Types::ProtectCashAdvanceRepaymentCreateRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectCashAdvanceRepaymentCreateResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#create_report(request_options: {}, **params) ⇒ Plaid::Types::ProtectReportCreateResponse
Use this endpoint to create a Protect report to document fraud incidents, investigation outcomes, or other risk events. This endpoint allows you to report various types of incidents including account takeovers, identity fraud, unauthorized transactions, and other security events. The reported data helps improve fraud detection models and provides valuable feedback to enhance the overall security of the Plaid network.
Reports can be created for confirmed incidents that have been fully investigated, or for suspected incidents
that require further review. You can associate reports with specific users, sessions, or transactions to provide
comprehensive context about the incident. Each report must include user_id, client_user_id, or an
incident_event with at least one supported identifier: link_session_id, idv_session_id,
protect_event_id, signal_client_transaction_id, or access_token. Context fields such as
internal_reference, time, amount, and bank_account do not satisfy this identifier requirement.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/plaid/protect/client.rb', line 91 def create_report(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/report/create", body: Plaid::Protect::Types::ProtectReportCreateRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectReportCreateResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#get_event(request_options: {}, **params) ⇒ Plaid::Types::ProtectEventGetResponse
Get information about a user event including Trust Index score and fraud attributes.
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/plaid/protect/client.rb', line 427 def get_event(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/event/get", body: Plaid::Protect::Types::ProtectEventGetRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectEventGetResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#get_user_insights(request_options: {}, **params) ⇒ Plaid::Types::ProtectUserInsightsGetResponse
Use this endpoint to get basic information about a user as it relates to their fraud profile with Protect.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/plaid/protect/client.rb', line 27 def get_user_insights(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/user/insights/get", body: Plaid::Protect::Types::ProtectUserInsightsGetRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectUserInsightsGetResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#send_event(request_options: {}, **params) ⇒ Plaid::Types::ProtectEventSendResponse
Send a new event to enrich user data and optionally get a Trust Index score for the event.
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/plaid/protect/client.rb', line 377 def send_event(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/event/send", body: Plaid::Protect::Types::ProtectEventSendRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectEventSendResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |
#upload_cash_advance_feedback(request_options: {}, **params) ⇒ Plaid::Types::ProtectCashAdvanceFeedbackUploadResponse
Upload a CSV file of cash advance decision or repayment feedback. Each row is equivalent to one call to
/protect/cash_advance/decision/create or /protect/cash_advance/repayment/create. Send the request as
multipart/form-data with client_id and secret in the PLAID-CLIENT-ID and PLAID-SECRET headers. The
file is accepted for asynchronous processing; the response contains a request_id and an upload_id that
identifies the upload.
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/plaid/protect/client.rb', line 264 def upload_cash_advance_feedback(request_options: {}, **params) params = Plaid::Internal::Types::Utils.normalize_keys(params) request = Plaid::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "protect/cash_advance/feedback/upload", body: Plaid::Protect::Types::ProtectCashAdvanceFeedbackUploadRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Plaid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) begin (response.body.to_s.empty? ? nil : Plaid::Types::ProtectCashAdvanceFeedbackUploadResponse.load(response.body)) rescue ::JSON::ParserError raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash) end else error_class = Plaid::Errors::ResponseError.subclass_for_code(code) error_types = { 400 => Plaid::Types::PlaidError, 401 => Plaid::Types::PlaidError, 429 => Plaid::Types::PlaidError, 500 => Plaid::Types::PlaidError, (400..499) => Plaid::Types::PlaidError, (500..599) => Plaid::Types::PlaidError } error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types) raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash) end end |