Class: SolidusBraintree::TransactionsController

Inherits:
StoreController
  • Object
show all
Defined in:
lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb

Defined Under Namespace

Classes: InvalidImportError

Constant Summary collapse

PERMITTED_BRAINTREE_TRANSACTION_PARAMS =
[
  :nonce,
  :payment_type,
  :paypal_funding_source,
  :phone,
  :email,
  { address_attributes: [
    :country_code, :country_name, :name, :city, :zip, :state_code,
    :address_line_1, :address_line_2, :first_name, :last_name
  ] },
  :device_data
].freeze

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb', line 20

def create
  transaction = SolidusBraintree::Transaction.new transaction_params
  import = SolidusBraintree::TransactionImport.new(current_order, transaction)
  restart_checkout = params[:options] && params[:options][:restart_checkout] == "true"

  respond_to do |format|
    if import.valid?
      import.import!(import_state, restart_checkout: restart_checkout)

      format.html { redirect_to redirect_url(import) }
      format.json { render json: { redirectUrl: redirect_url(import) } }
    else
      status = 422
      format.html { import_error(import) }
      format.json { render json: { errors: import.errors, status: status }, status: status }
    end
  end
end