Sha256: f1b78fb5d029448c14084e91198c51b9532f66cde3598ab7cbf3643b8971bd09

Contents?: true

Size: 1.57 KB

Versions: 56

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factory_bot'
Spree::TestingSupport::FactoryBot.when_cherry_picked do
  Spree::TestingSupport::FactoryBot.deprecate_cherry_picking

  require 'spree/testing_support/factories/payment_method_factory'
  require 'spree/testing_support/factories/credit_card_factory'
  require 'spree/testing_support/factories/order_factory'
  require 'spree/testing_support/factories/store_credit_factory'
end

FactoryBot.define do
  factory :payment, aliases: [:credit_card_payment], class: 'Spree::Payment' do
    association(:payment_method, factory: :credit_card_payment_method)
    source { create(:credit_card, user: order.user, address: order.bill_address) }
    order
    state { 'checkout' }
    response_code { '12345' }

    trait :completed do
      state { 'completed' }
    end

    trait :failing do
      response_code { '00000' }
      association(:source, :failing, { factory: :credit_card })
    end

    factory :payment_with_refund do
      transient do
        refund_amount { 5 }
      end

      amount { refund_amount }

      state { 'completed' }

      refunds { build_list :refund, 1, amount: refund_amount }
    end

    initialize_with do
      order.payments.new(attributes)
    end
  end

  factory :check_payment, class: 'Spree::Payment' do
    association(:payment_method, factory: :check_payment_method)
    order
  end

  factory :store_credit_payment, class: 'Spree::Payment', parent: :payment do
    association(:payment_method, factory: :store_credit_payment_method)
    association(:source, factory: :store_credit)
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
solidus_core-3.4.6 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.4.5 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.4.4 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.3.4 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.2.9 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.2.8 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.3.3 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.4.3 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.4.2 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.2.7 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.3.2 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.4.1 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.4.0 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.3.1 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.2.6 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.1.9 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.3.0 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.2.5 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.2.4 lib/spree/testing_support/factories/payment_factory.rb
solidus_core-3.2.3 lib/spree/testing_support/factories/payment_factory.rb