Class: E4commerce::PagSeguroPayment
- Inherits:
-
Object
- Object
- E4commerce::PagSeguroPayment
- Defined in:
- lib/e4commerce/e4commerce_pagseguro.rb
Class Method Summary collapse
- .create_notification(notification_code_param) ⇒ Object
-
.create_payment(e4c_payment, email, token) ⇒ Object
Email and token for different profiles to authenticate paymeny e4c_payment, class must inheritate from E4commerce::E4CPayment.
Instance Method Summary collapse
Class Method Details
.create_notification(notification_code_param) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/e4commerce/e4commerce_pagseguro.rb', line 47 def self.create_notification(notification_code_param) transaction = PagSeguro::Transaction.find_by_notification_code(params[:notification_code_param]) 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. end render nothing: true, status: 200 end |
.create_payment(e4c_payment, email, token) ⇒ Object
Email and token for different profiles to authenticate paymeny e4c_payment, class must inheritate from E4commerce::E4CPayment
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/e4commerce/e4commerce_pagseguro.rb', line 9 def self.create_payment(e4c_payment, email, token) payment = PagSeguro::PaymentRequest.new payment = PagSeguro::PaymentRequest.new(email: email, token: token) payment.reference = order.id payment.notification_url = notifications_url payment.redirect_url = processing_url e4c_payment.product_list.each do |product| payment.items << { description: product.title, id: product.serial_number, amount: product.unit_price } end calculate_total(self.product_list) response = payment.register if response.errors.any? raise response.errors.join("\n") else redirect_to response.url end end |
Instance Method Details
#calculate_total(products) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/e4commerce/e4commerce_pagseguro.rb', line 38 def calculate_total(products) total = 0 self.product_list.each do |product| total += product.unit_price end total end |