Sha256: 0177739c616e8ca383dac60e439a36b88f320da075c864ab5d267fa99828ca32

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

Spree::CheckoutController.class_eval do  
  def edit
    if ((@order.state == "payment") && @order.valid?)
      puts "valid, processing"
      if @order.payable_via_pag_seguro?
        puts "payable via pag_seguro, adding payment"
        payment = Spree::Payment.new
        payment.amount = @order.total
        payment.payment_method = Spree::Order.pag_seguro_payment_method
        @order.payments << payment
        pag_seguro_payment = PagSeguro::Payment.new(Spree::PagSeguro::Config.email, Spree::PagSeguro::Config.token, redirect_url: "#{root_url}/pag_seguro/callback")
       
        pag_seguro_payment.items = @order.line_items.collect do |item|
          PagSeguro::Item.new(
            id: item.id,
            description: item.product.description,
            amount: format("%.2f", item.price.round(2)),
            quantity: item.quantity,
            weight: item.product.weight,
          )
        end
       
        pag_seguro_payment.sender = PagSeguro::Sender.new(name: @order.name, email: @order.email, phone_number: @order.ship_address.phone)
        pag_seguro_payment.shipping = PagSeguro::Shipping.new(type: PagSeguro::Shipping::SEDEX, state: @order.ship_address.state.abbr, city: @order.ship_address.city, postal_code: @order.ship_address.zipcode, street: @order.ship_address.address1, complement: @order.ship_address.address2)
       
        @pag_seguro_url = pag_seguro_payment.checkout_payment_url
        payment.started_processing
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_pag_seguro-1.0.0.beta10 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta9 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta8 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta7 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta6 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta5 app/controllers/spree/checkout_controller_decorator.rb