Sha256: 781926025874aeb73a5be95db23d5eb4b4980a04acfd9415ba0093883cf59298

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module SolidusNexio
  class AlternativePaymentMethod < SolidusSupport.payment_method_parent_class
    include NexioPaymentCommons

    preference(:server, :string, default: 'test')
    preference(:merchant_id, :string, default: nil)
    preference(:auth_token, :string, default: nil)
    preference(:payment_method, :string, default: nil)
    preference(:save_token, :boolean, default: false)

    def partial_name
      'nexio_apm'
    end
    alias method_type partial_name

    def generate_token(options)
      order = Spree::Order.find_by(number: options.dig(:order, :number))
      return unless order

      amount = order.respond_to?(:order_total_after_store_credit) ? order.order_total_after_store_credit : order.total
      params = {
        payment_method: preferred_payment_method,
        save_token: preferred_save_token,
        is_auth_only: !auto_capture?
      }.merge!(options)
      gateway.generate_token(amount.to_money.cents, params)
    end

    def payment_source_class
      ApmSource
    end

    private

    def gateway_class
      ActiveMerchant::Billing::NexioApmGateway
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
solidus_nexio-0.6.9 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.8 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.7 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.6 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.5 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.4 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.3 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.2 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.1 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.6.0 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.5.2 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.5.1 app/models/solidus_nexio/alternative_payment_method.rb
solidus_nexio-0.5.0 app/models/solidus_nexio/alternative_payment_method.rb