Sha256: 4df6af57251566b91a72e14e3a0e10d138fb2bf92ff6674f9effcaa96d71a5c9

Contents?: true

Size: 1.84 KB

Versions: 16

Compression:

Stored size: 1.84 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])

        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),
          current_user: nil # Admin action, we don't want to assign current_user to the 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.14.6 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.14.5 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.14.4 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.14.3 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.14.2 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.14.1 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.14.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.13.3 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.13.2 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.13.1 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.13.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.12.4 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.12.3 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.12.2 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.12.1 app/controllers/effective/providers/deluxe_delayed_purchase.rb
effective_orders-6.12.0 app/controllers/effective/providers/deluxe_delayed_purchase.rb