Sha256: 7c4fee76278ced51f51e2a4b17622ac6388ad8763f945f62ecba539004fa8746

Contents?: true

Size: 1.91 KB

Versions: 16

Compression:

Stored size: 1.91 KB

Contents

module Effective
  module Providers
    module DeluxeDelayedPurchase
      extend ActiveSupport::Concern

      # Admin action
      def deluxe_delayed_purchase
        raise('deluxe_delayed_purchase provider is not available') unless EffectiveOrders.deluxe_delayed?

        @order ||= Order.deep.find(params[:id])
        @order.current_user = nil # Admin action, we don't want to assign current_user to the order

        EffectiveResources.authorize!(self, :update, @order)
        EffectiveResources.authorize!(self, :admin, :effective_orders)

        raise('expected a delayed? and deferred? order') unless @order.delayed? && @order.deferred?

        ## Purchase Order right now
        api = Effective::DeluxeApi.new

        purchased = api.purchase!(@order, @order.delayed_payment_intent)
        payment = api.payment

        if purchased == false
          flash[:danger] = "Payment was unsuccessful. The credit card payment failed with message: #{Array(payment['responseMessage']).to_sentence.presence || 'none'}. Please try again."

          return order_declined(
            payment: payment, 
            provider: 'deluxe_delayed', 
            card: payment['card'], 
            declined_url: deluxe_delayed_purchase_params[:declined_url]
          )
        end

        @order.assign_attributes(deluxe_delayed_purchase_params.except(:purchased_url, :declined_url, :id))

        order_purchased(
          payment: payment,
          provider: 'deluxe_delayed',
          card: payment['card'],
          email: @order.send_mark_as_paid_email_to_buyer?,
          skip_buyer_validations: true,
          purchased_url: effective_orders.admin_order_path(@order)
        )
      end

      def deluxe_delayed_purchase_params
        params.require(:effective_order).permit(
          :id, :note_to_buyer, :note_internal, :send_mark_as_paid_email_to_buyer,
          :purchased_url, :declined_url
        )
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
effective_orders-6.19.1 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.19.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.18.4 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.18.3 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.18.2 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.18.1 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.18.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.17.2 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.17.1 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.17.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.16.4 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.16.3 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.16.2 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.16.1 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.16.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.15.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb