Sha256: 41a8c3a23bbc890b5aa32269946a91feeaede446b7438c7ce1b2b8ed3c805943

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

require 'set'

module BMLConnect
  module Models
    class Transaction

      include BMLConnect::Crypt::Signature

      REQUIRED_FIELDS = Set[:amount, :currency]

      attr_accessor :amount, :currency, :isPreauthorization, :provider, :redirectUrl, :localId, :customerReference
      
      def initialize(fields)
        # check for required fields
        raise ArgumentError.new("Missing Required Fields: [#{REQUIRED_FIELDS.join(', ')}]") unless REQUIRED_FIELDS.subset?(fields.keys.to_set)

        #initialize transaction props
        fields.each { |k,v| public_send("#{k}=", v) }
      end

      def to_hash()
        instance_variables.each_with_object({}) { |var, hash| hash[var.to_s.delete("@")] = instance_variable_get(var) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bml_connect-0.2.0 lib/bml_connect/models/transaction.rb
bml_connect-0.1.0 lib/bml_connect/models/transaction.rb