Skip to content

Instantly share code, notes, and snippets.

@romulostorel
Created June 1, 2015 22:14
Show Gist options
  • Save romulostorel/f0de0cb6dda390e4701f to your computer and use it in GitHub Desktop.
Save romulostorel/f0de0cb6dda390e4701f to your computer and use it in GitHub Desktop.
if transaction.errors.empty?
# Processa a notificação. A melhor maneira de se fazer isso é realizar
# o processamento em background. Uma boa alternativa para isso é a
# biblioteca Sidekiq.
@payment = Payment.find[transaction.reference.gsub("DW", "")]
PagseguroMailer.welcome(payment).deliver
PaseguroMailer.welcome(@payment).deliver
p transaction
if @payment.present? and @payment.awainting? and @payment.value == transaction.gross_amount and transaction.code == 3
ActiveRecord::Base.transaction do
@payment.approved!
@payment.approved_at = Date.current
@payment.histories.build(status: PaymentStatus::approved)
@payment.save
@establishment = Establishment.find(@payment.establishment)
@establishment.plan = @product.plan
@establishment.due_date = Date.current + 1.year
@establishment.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment