Class: Order
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Order
- Includes:
- AASM
- Defined in:
- app/models/order.rb
Constant Summary collapse
- PAYPAL_CERT_PEM =
File.read("#{Rails.root}/certs/#{Rails.env.to_s}/paypal_cert.pem")
- APP_CERT_PEM =
File.read("#{Rails.root}/certs/#{Rails.env.to_s}/app_cert.pem")
- APP_KEY_PEM =
File.read("#{Rails.root}/certs/#{Rails.env.to_s}/app_key.pem")
- @@per_page =
10
Instance Method Summary collapse
- #address ⇒ Object
- #empty? ⇒ Boolean
- #encrypt_for_paypal(values) ⇒ Object
- #name ⇒ Object
- #payment_notification ⇒ Object
- #paypal_url(return_url, notify_url) ⇒ Object
- #send_paid ⇒ Object
- #send_shipped ⇒ Object
- #timestamp ⇒ Object
- #total ⇒ Object
Instance Method Details
#address ⇒ Object
32 33 34 35 36 |
# File 'app/models/order.rb', line 32 def address return "Unknown" unless payment_notification notification = payment_notification.params [notification[:address_street], notification[:address_city], notification[:address_state], notification[:address_zip], notification[:address_country]].join(" ") rescue "Unknown" end |
#empty? ⇒ Boolean
22 23 24 |
# File 'app/models/order.rb', line 22 def empty? order_items.empty? end |
#encrypt_for_paypal(values) ⇒ Object
65 66 67 68 |
# File 'app/models/order.rb', line 65 def encrypt_for_paypal(values) signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY) OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "") end |
#name ⇒ Object
26 27 28 29 30 |
# File 'app/models/order.rb', line 26 def name return "Unknown" unless payment_notification notification = payment_notification.params notification[:first_name] + " " + notification[:last_name] rescue "Unknown" end |
#payment_notification ⇒ Object
18 19 20 |
# File 'app/models/order.rb', line 18 def payment_notification payment_notifications.last end |
#paypal_url(return_url, notify_url) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/order.rb', line 38 def paypal_url(return_url, notify_url) values = { :business => APP_CONFIG[:paypal_email], :cmd => "_cart", :upload => 1, :return => return_url, :invoice => id, :notify => notify_url, :cert_id => APP_CONFIG[:paypal_cert_id], :no_shipping => 2 } order_items.each_with_index do |order_item, index| values.merge!({ "amount_#{index + 1}" => order_item.product.price, "item_name_#{index + 1}" => order_item.product.name, "item_number_#{index + 1}" => order_item.product.id, "quantity_#{index + 1}" => order_item.quantity }) end logger.info values.inspect APP_CONFIG[:paypal_url] + {:encrypted => encrypt_for_paypal(values), :cmd => "_s-xclick"}.to_query end |
#send_paid ⇒ Object
98 99 100 |
# File 'app/models/order.rb', line 98 def send_paid CartMailer.paid(self).deliver end |
#send_shipped ⇒ Object
102 103 104 |
# File 'app/models/order.rb', line 102 def send_shipped CartMailer.shipped(self).deliver end |
#timestamp ⇒ Object
94 95 96 |
# File 'app/models/order.rb', line 94 def update_attribute(:purchased_at, Time.now) end |
#total ⇒ Object
14 15 16 |
# File 'app/models/order.rb', line 14 def total order_items.map(&:sub_total).inject(:+) end |