Sha256: ece4c898ead174e93e99dc4261047ec8cacd227c86c52d92a63191039712578d

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

module Effective
  module Providers
    module DeluxeDelayed
      extend ActiveSupport::Concern

      def deluxe_delayed
        raise('deluxe provider is not available') unless EffectiveOrders.deluxe?
        raise('deluxe_delayed provider is not available') unless EffectiveOrders.deluxe_delayed?

        @order = Effective::Order.deep.find(params[:id])

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

        ## Process Payment Intent
        api = Effective::DeluxeApi.new

        # The payment_intent is set by the Deluxe HostedPaymentForm
        payment_intent_payload = deluxe_delayed_params[:payment_intent]

        if payment_intent_payload.blank?
          flash[:danger] = 'Unable to process deluxe delayed order without payment intent. please try again.'
          return order_not_processed(declined_url: deluxe_delayed_params[:declined_url])
        end

        # Decode the base64 encoded JSON object into a Hash
        # {"type"=>"Token", "status"=>"success", "data"=>{"token"=>"1983661243624242", "nameOnCard"=>"CardHolder", "expDate"=>"12/24", "maskedPan"=>"424242******4242", "cardType"=>"Visa"}}
        payment_intent = api.decode_payment_intent_payload(payment_intent_payload)
        card_info = api.card_info(payment_intent)

        valid = payment_intent['status'] == 'success'

        if valid == false
          return order_declined(payment: card_info, provider: 'deluxe_delayed', card: card_info['card'], declined_url: deluxe_delayed_params[:declined_url])
        end

        flash[:success] = EffectiveOrders.deluxe_delayed[:success]

        order_delayed(payment: card_info, payment_intent: payment_intent_payload, provider: 'deluxe_delayed', card: card_info['card'], deferred_url: deluxe_delayed_params[:deferred_url])
      end

      private

      def deluxe_delayed_params
        params.require(:deluxe_delayed).permit(:payment_intent, :deferred_url, :declined_url)
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
effective_orders-6.14.6 app/controllers/effective/providers/deluxe_delayed.rb
effective_orders-6.14.5 app/controllers/effective/providers/deluxe_delayed.rb
effective_orders-6.14.4 app/controllers/effective/providers/deluxe_delayed.rb
effective_orders-6.14.3 app/controllers/effective/providers/deluxe_delayed.rb
effective_orders-6.14.2 app/controllers/effective/providers/deluxe_delayed.rb
effective_orders-6.14.1 app/controllers/effective/providers/deluxe_delayed.rb
effective_orders-6.14.0 app/controllers/effective/providers/deluxe_delayed.rb