Sha256: cffdd34a2b2f5c56a9f257c09042e2b4df1b1ad55468eb663a6e1f443c0da49a

Contents?: true

Size: 1.51 KB

Versions: 10

Compression:

Stored size: 1.51 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",
          id: @order.id)
       
        pag_seguro_payment.items = @order.line_items.collect do |item|
          PagSeguro::Item.new(
            id: item.id,
            description: item.product.name,
            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

10 entries across 10 versions & 1 rubygems

Version Path
spree_pag_seguro-1.0.0.beta25 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta24 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta23 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta22 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta21 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta20 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta19 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta18 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta17 app/controllers/spree/checkout_controller_decorator.rb
spree_pag_seguro-1.0.0.beta16 app/controllers/spree/checkout_controller_decorator.rb