Class: GooglePayRuby::GooglePaymentMethodTokenContext
- Inherits:
-
Object
- Object
- GooglePayRuby::GooglePaymentMethodTokenContext
- Defined in:
- lib/google_pay_ruby/google_payment_method_token_context.rb
Instance Attribute Summary collapse
-
#merchants ⇒ Object
readonly
Returns the value of attribute merchants.
Instance Method Summary collapse
- #decrypt(token) ⇒ Object
-
#initialize(options) ⇒ GooglePaymentMethodTokenContext
constructor
A new instance of GooglePaymentMethodTokenContext.
Constructor Details
#initialize(options) ⇒ GooglePaymentMethodTokenContext
Returns a new instance of GooglePaymentMethodTokenContext.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/google_pay_ruby/google_payment_method_token_context.rb', line 7 def initialize() @merchants = [:merchants] || [] if @merchants.empty? raise GooglePaymentDecryptionError.new( 'No merchant configuration provided for decryption context.' ) end validate_merchant_configurations! end |
Instance Attribute Details
#merchants ⇒ Object (readonly)
Returns the value of attribute merchants.
5 6 7 |
# File 'lib/google_pay_ruby/google_payment_method_token_context.rb', line 5 def merchants @merchants end |
Instance Method Details
#decrypt(token) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/google_pay_ruby/google_payment_method_token_context.rb', line 19 def decrypt(token) protocol_version = token['protocolVersion'] || token[:protocolVersion] unless protocol_version == 'ECv2' raise GooglePaymentDecryptionError.new( "Unsupported decryption for protocol version #{protocol_version}" ) end errors = [] = token['signedMessage'] || token[:signedMessage] @merchants.each do |merchant| begin strategy = EcV2DecryptionStrategy.new(merchant[:private_key_pem]) return strategy.decrypt() rescue StandardError => e e.define_singleton_method(:merchant_identifier) { merchant[:identifier] } errors << e end end raise GooglePaymentDecryptionError.new( 'Failed to decrypt payment data using provided merchant configuration(s).', errors ) end |