Sha256: 3645d1a2db82ff6aead7b47a1bfbe04b7b38b304853636ad6e2e079dce61c9fa

Contents?: true

Size: 962 Bytes

Versions: 5

Compression:

Stored size: 962 Bytes

Contents

module SolidusNexio
  class PaymentsController < Spree::CheckoutController
    def create
      if update_order
        payment_method = PaymentMethod.find(params[:payment_method_id])
        result = payment_method.process_order_payment(@order) do |payment|
          capture_payment_method_payment_state_url(payment_method, payment)
        end
        render json: result
      else
        render json: { error: :invalid_order, details: @order.errors.to_h }, status: 422
      end
    end

    private

    def update_params
      massaged_params.require(:order).permit(permitted_checkout_payment_attributes)
    end

    def current_order_params
      {
        currency: current_pricing_options.currency,
        guest_token: cookies.signed[:guest_token],
        store_id: current_store.id
      }.tap do |current_order_params|
        current_order_params.merge!(user_id: spree_current_user.id) if spree_current_user.present?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_nexio-0.4.0 app/controllers/solidus_nexio/payments_controller.rb
solidus_nexio-0.3.5 app/controllers/solidus_nexio/payments_controller.rb
solidus_nexio-0.3.4 app/controllers/solidus_nexio/payments_controller.rb
solidus_nexio-0.3.3 app/controllers/solidus_nexio/payments_controller.rb
solidus_nexio-0.3.2 app/controllers/solidus_nexio/payments_controller.rb