Skip to content

Commit

Permalink
Remove eql and create different construct for conditional assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
brorbw committed Jan 27, 2024
1 parent a0e3f43 commit a1ca68d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/aliquot/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class TokenContract < Dry::Validation::Contract
rule(:signedMessage).validate(:json?)

rule(:intermediateSigningKey) do
key.failure('is missing') if 'ECv2'.eql?(values[:protocolVersion]) &&
key.failure('is missing') if values[:protocolVersion] == 'ECv2' &&
values[:intermediateSigningKey].nil?
end
end
Expand Down Expand Up @@ -224,28 +224,26 @@ class EncryptedMessageContract < Dry::Validation::Contract
rule(:messageExpiration).validate(:integer_string?)

rule(:paymentMethodDetails).validate do
contract = nil
if 'ECv1'.eql?(values[:protocolVersion])
if 'TOKENIZED_CARD'.eql?(values[:paymentMethod])
contract = ECv1_TokenizedPaymentMethodDetailsContract.new
if values[:protocolVersion] == 'ECv1'
if values[:paymentMethod] == 'TOKENIZED_CARD'
return ECv1_TokenizedPaymentMethodDetailsContract.new
else
contract = ECv1_PaymentMethodDetailsContract.new
return ECv1_PaymentMethodDetailsContract.new
end
else
if 'CRYPTOGRAM_3DS'.eql?(values[:authMethod])
contract = ECv2_TokenizedPaymentMethodDetailsContract.new
if values[:authMethod] == 'CRYPTOGRAM_3DS'
return ECv2_TokenizedPaymentMethodDetailsContract.new
else
contract = ECv2_PaymentMethodDetailsContract.new
return ECv2_PaymentMethodDetailsContract.new
end
end
contract
end
rule(:paymentMethod) do
if values[:paymentMethodDetails] && values[:paymentMethodDetails].is_a?(Hash)
if '3DS'.eql?(values[:paymentMethodDetails] && values[:paymentMethodDetails]['authMethod']) # Tokenized ECv1
key.failure('must be equal to TOKENIZED_CARD') unless 'TOKENIZED_CARD'.eql?(value)
key.failure('must be equal to TOKENIZED_CARD') unless value == 'TOKENIZED_CARD'
else
key.failure('must be equal to CARD') unless 'CARD'.eql?(value)
key.failure('must be equal to CARD') unless value == 'CARD'
end
end
end
Expand Down

0 comments on commit a1ca68d

Please sign in to comment.