Sha256: ce738d9c9f2b0e50c28e794f5c6effe97f259cfdab066ea83513357ae64967cc

Contents?: true

Size: 822 Bytes

Versions: 4

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

require 'active_model'

module SolidusBraintree
  class Transaction
    include ActiveModel::Model

    attr_accessor :nonce, :payment_method, :payment_type, :paypal_funding_source, :address, :email, :phone, :device_data

    validates :nonce, presence: true
    validates :payment_method, presence: true
    validates :payment_type, presence: true
    validates :email, presence: true

    validate do
      unless payment_method.is_a? SolidusBraintree::Gateway
        errors.add(:payment_method, 'Must be braintree')
      end
      if address&.invalid?
        address.errors.each do |error|
          errors.add(:address, error.full_message)
        end
      end
    end

    def address_attributes=(attributes)
      self.address = TransactionAddress.new attributes
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_braintree-3.3.0 app/models/solidus_braintree/transaction.rb
solidus_braintree-3.2.0 app/models/solidus_braintree/transaction.rb
solidus_braintree-3.1.0 app/models/solidus_braintree/transaction.rb
solidus_braintree-3.0.1 app/models/solidus_braintree/transaction.rb