Sha256: 2b04de90200bd4d15039efe56a44f09a44b8ff255cb460d4dbfc5684254a17c7

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Spree
  module OrderUpdateAttributesDecorator
    def assign_payments_attributes
      return if payments_attributes.empty?
      return if adding_new_stripe_payment_intents_card?

      stripe_intents_pending_payments.each(&:void_transaction!)

      super
    end

    private

    def adding_new_stripe_payment_intents_card?
      paying_with_stripe_intents? && stripe_intents_pending_payments.any?
    end

    def stripe_intents_pending_payments
      @stripe_intents_pending_payments ||= order.payments.valid.select do |payment|
        payment_method = payment.payment_method
        payment.pending? && stripe_intents?(payment_method)
      end
    end

    def paying_with_stripe_intents?
      if id = payments_attributes.first&.dig(:payment_method_id)
        stripe_intents?(Spree::PaymentMethod.find(id))
      end
    end

    def stripe_intents?(payment_method)
      payment_method.respond_to?(:v3_intents?) && payment_method.v3_intents?
    end

    ::Spree::OrderUpdateAttributes.prepend(self)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
solidus_stripe-4.4.1 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-4.4.0 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-4.3.0 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-4.2.0 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-4.1.0 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-3.2.1 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-4.0.0 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-3.2.0 app/decorators/models/spree/order_update_attributes_decorator.rb
solidus_stripe-3.1.0 app/decorators/models/spree/order_update_attributes_decorator.rb