Class: CyberSource::Utilities::CaptureContext::CaptureContextParser
- Inherits:
-
Object
- Object
- CyberSource::Utilities::CaptureContext::CaptureContextParser
- Defined in:
- lib/cybersource_rest_client/utilities/capture_context/capture_context_parsing_utility.rb
Overview
CaptureContextParser Class
Parses and validates capture context JWT responses from CyberSource. Provides functionality to parse JWT tokens and optionally verify their signatures using public keys fetched from the CyberSource API.
Class Method Summary collapse
-
.parse_capture_context_response(jwt_value, merchant_config) ⇒ Hash
Parses a capture context JWT response and optionally verifies its signature.
Class Method Details
.parse_capture_context_response(jwt_value, merchant_config) ⇒ Hash
Parses a capture context JWT response and optionally verifies its signature
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 62 63 |
# File 'lib/cybersource_rest_client/utilities/capture_context/capture_context_parsing_utility.rb', line 32 def parse_capture_context_response(jwt_value, merchant_config) verify_jwt = true # Always validate JWT value first if jwt_value.nil? || jwt_value.strip.empty? raise CyberSource::Authentication::Util::JWT::InvalidJwtException.new('JWT value is null or undefined') end # Validate verification requirements before parsing if verify_jwt raise ArgumentError, 'merchantConfig is required' unless merchant_config run_environment = merchant_config.runEnvironment raise ArgumentError, 'Run environment not found in merchant config' if run_environment.nil? || run_environment.strip.empty? end # Parse JWT (actual operation) parsed_jwt = CyberSource::Authentication::Util::JWT::JWTUtility.parse(jwt_value) # Return early if no verification needed return parsed_jwt[:payload] unless verify_jwt # Validate kid exists in parsed JWT kid = parsed_jwt[:header]['kid'] if kid.nil? || kid.strip.empty? raise CyberSource::Authentication::Util::JWT::JwtSignatureValidationException.new( 'JWT header missing or empty key ID (kid) field' ) end # Verify signature (actual operation) verify_jwt_signature(jwt_value, parsed_jwt[:payload], kid, run_environment) end |