Skip to content

Commit

Permalink
Mailer working
Browse files Browse the repository at this point in the history
  • Loading branch information
dylandrop committed Nov 12, 2013
1 parent 935b904 commit 40199c3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/mailers/purchased_item_mailer.rb
@@ -0,0 +1,12 @@
class PurchasedItemMailer < ActionMailer::Base
default from: "Givespend <admin@givespend.com>"
def notify_buyer txn_id
@transaction = Transaction.find(txn_id)
mail subject: "Thanks for shopping on Givespend", to: @transaction.email
end

def notify_seller txn_id
@transaction = Transaction.find(txn_id)
mail subject: "Someone has bought #{@transaction.item.name}", to: @transaction.item.user.email
end
end
8 changes: 8 additions & 0 deletions app/views/purchased_item_mailer/notify_buyer.html.erb
@@ -0,0 +1,8 @@
Thanks for shopping on Givespend. Just to review, here is what you've purchased:
<br><br>
<%= @transaction.item.name %><br>
<%= @transaction.item.description %><br>
<br>
We've notified the seller of this item via email, and they should get back to you shortly. Contact us for any help/support.
<br><br>
--Givespend Team
9 changes: 9 additions & 0 deletions app/views/purchased_item_mailer/notify_seller.html.erb
@@ -0,0 +1,9 @@
Good job! You just sold "<%= @transaction.item.name %>" on Givespend. In doing so, you've provided <%= @transaction.item.nonprofit_url %> with a little more funding. Please refer below for the delivery details:
<br><br>
<%= @transaction.email %>
<br>
<%= @transaction.shipping_info %>
<br><br>
Thanks,
<br>
Givespend Team
11 changes: 11 additions & 0 deletions config/environments/development.rb
Expand Up @@ -34,4 +34,15 @@

# Expands the lines which load the assets
config.assets.debug = true

config.action_mailer.raise_delivery_errors = true

config.action_mailer.default_url_options = { :host => 'localhost', port: '3000' }

unless ENV['MAILJET'].present?
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
else
config.action_mailer.delivery_method = :mailjet
end
end
4 changes: 4 additions & 0 deletions config/environments/production.rb
Expand Up @@ -61,6 +61,10 @@
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :mailjet
config.action_mailer.default_url_options = { :host => 'givespend.com' }

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
Expand Down
3 changes: 3 additions & 0 deletions config/environments/test.rb
Expand Up @@ -34,4 +34,7 @@

# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr

config.action_mailer.default_url_options = { :host => 'localhost', port: '3000' }

end
@@ -0,0 +1,6 @@
class AddShippingInfoAndEmailToTransactions < ActiveRecord::Migration
def change
add_column :transactions, :shipping_info, :string
add_column :transactions, :email, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20131111202033) do
ActiveRecord::Schema.define(:version => 20131112014702) do

create_table "images", :force => true do |t|
t.integer "imageable_id"
Expand Down Expand Up @@ -41,6 +41,8 @@
t.string "stripe_customer_token"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "shipping_info"
t.string "email"
end

add_index "transactions", ["item_id"], :name => "index_transactions_on_item_id"
Expand Down

0 comments on commit 40199c3

Please sign in to comment.