Class: Spree::BilletsController

Inherits:
StoreController
  • Object
show all
Defined in:
app/controllers/spree/billets_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/spree/billets_controller.rb', line 5

def show
  if @billet.due_date.past?
    # voids the old payment
    old_payment = @billet.payment
    old_payment.void_transaction!

    # creates the new payment
    params = {order: @billet.order,
              amount: old_payment.amount,
              payment_method: @billet.payment_method,
              source_attributes: {order: @billet.order,
                                  user: @billet.user,
                                  status: 'pending'}}
    new_payment = Spree::Payment.new(params)
    new_payment.pend!
    new_payment.process!

    @billet = new_payment.source
  end
  # generate the billet document
  @document = @billet.generate_document
  send_data @document.to_pdf, filename: "boleto_#{@billet.order.number}.pdf"
end