Sha256: 30697a78fa9901e4804f5a69515b3e484cb06b4f3a50b37e7f0457714f6a6d7d

Contents?: true

Size: 1.92 KB

Versions: 81

Compression:

Stored size: 1.92 KB

Contents

module Effective
  module Providers
    module MonerisCheckout
      extend ActiveSupport::Concern

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

        @order = Order.find(params[:id])
        (EffectiveResources.authorize!(self, :update, @order) rescue false)

        payment = moneris_checkout_receipt_request(moneris_checkout_params[:ticket])
        purchased = (1..49).include?(payment['response_code'].to_i) # Must be > 0 and < 50 to be valid. Sometimes we get the string 'null'

        if purchased == false
          return order_declined(
            payment: payment,
            provider: 'moneris_checkout',
            declined_url: moneris_checkout_params[:declined_url]
          )
        end

        order_purchased(
          payment: payment,
          provider: 'moneris_checkout',
          card: payment['card_type'],
          purchased_url: moneris_checkout_params[:purchased_url]
        )
      end

      private

      def moneris_checkout_params
        params.require(:moneris_checkout).permit(:ticket, :purchased_url, :declined_url)
      end

      def moneris_checkout_receipt_request(ticket)
        params = {
          environment: EffectiveOrders.moneris_checkout.fetch(:environment),

          api_token: EffectiveOrders.moneris_checkout.fetch(:api_token),
          store_id: EffectiveOrders.moneris_checkout.fetch(:store_id),
          checkout_id: EffectiveOrders.moneris_checkout.fetch(:checkout_id),

          action: :receipt,
          ticket: ticket
        }

        response = Effective::Http.post(EffectiveOrders.moneris_request_url, params: params)
        response = response['response'] if response

        raise("moneris receipt error #{response}") unless response && response['success'].to_s == 'true'

        response.dig('receipt', 'cc') || response.dig('receipt', 'gift') || response
      end

    end
  end
end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
effective_orders-6.4.4 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.4.3 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.4.2 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.4.1 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.4.0 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.3.2 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.3.1 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.3.0 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.2.1 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.2.0 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.1.5 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.1.4 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.1.3 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.1.2 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.1.1 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.1.0 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.0.1 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-6.0.0 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-5.9.4 app/controllers/effective/providers/moneris_checkout.rb
effective_orders-5.9.3 app/controllers/effective/providers/moneris_checkout.rb