Class: PagSeguro::DeveloperController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/pagseguro/developer_controller.rb

Constant Summary collapse

PAGSEGURO_ORDERS_FILE =
File.join(Rails.root, "tmp", "pagseguro-#{Rails.env}.yml")

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pagseguro/developer_controller.rb', line 6

def create
  # create the orders file if doesn't exist
  FileUtils.touch(PAGSEGURO_ORDERS_FILE) unless File.exist?(PAGSEGURO_ORDERS_FILE)

  # YAML caveat: if file is empty false is returned;
  # we need to set default to an empty hash in this case
  orders = YAML.load_file(PAGSEGURO_ORDERS_FILE) || {}

  # add a new order, associating it with the order id
  orders[params[:ref_transacao]] = params.except(:controller, :action, :only_path, :authenticity_token)

  # save the file
  File.open(PAGSEGURO_ORDERS_FILE, "w+") do |file|
    file << orders.to_yaml
  end

  # redirect to the configuration url
  redirect_to PagSeguro.config["return_to"]
end