added email notification when order arives
This commit is contained in:
@@ -22,3 +22,4 @@ gem 'puma'
|
|||||||
gem "sinatra-contrib"
|
gem "sinatra-contrib"
|
||||||
gem 'rerun'
|
gem 'rerun'
|
||||||
gem 'xxhash', '~> 0.3.0'
|
gem 'xxhash', '~> 0.3.0'
|
||||||
|
gem 'pony'
|
||||||
|
|||||||
@@ -49,10 +49,15 @@ GEM
|
|||||||
celluloid (>= 0.15.2)
|
celluloid (>= 0.15.2)
|
||||||
rb-fsevent (>= 0.9.3)
|
rb-fsevent (>= 0.9.3)
|
||||||
rb-inotify (>= 0.9)
|
rb-inotify (>= 0.9)
|
||||||
|
mail (2.6.3)
|
||||||
|
mime-types (>= 1.16, < 3)
|
||||||
|
mime-types (2.6.1)
|
||||||
minitest (5.5.0)
|
minitest (5.5.0)
|
||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
multipart-post (2.0.0)
|
multipart-post (2.0.0)
|
||||||
pg (0.17.1)
|
pg (0.17.1)
|
||||||
|
pony (1.11)
|
||||||
|
mail (>= 2.0)
|
||||||
puma (2.10.2)
|
puma (2.10.2)
|
||||||
rack (>= 1.1, < 2.0)
|
rack (>= 1.1, < 2.0)
|
||||||
puma (2.10.2-java)
|
puma (2.10.2-java)
|
||||||
@@ -102,6 +107,7 @@ DEPENDENCIES
|
|||||||
jruby-openssl
|
jruby-openssl
|
||||||
json
|
json
|
||||||
pg
|
pg
|
||||||
|
pony
|
||||||
puma
|
puma
|
||||||
rerun
|
rerun
|
||||||
sinatra
|
sinatra
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ require 'json'
|
|||||||
require 'sinatra/cookies'
|
require 'sinatra/cookies'
|
||||||
require 'elasticsearch'
|
require 'elasticsearch'
|
||||||
require 'xxhash'
|
require 'xxhash'
|
||||||
|
require 'pony'
|
||||||
|
|
||||||
|
|
||||||
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
||||||
@@ -18,7 +19,7 @@ before do
|
|||||||
# domain is allowed
|
# domain is allowed
|
||||||
|
|
||||||
headers 'Access-Control-Allow-Origin' => 'http://localhost:3001',
|
headers 'Access-Control-Allow-Origin' => 'http://localhost:3001',
|
||||||
'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST','PUT'],
|
'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST','PUT'].join(','),
|
||||||
'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept',
|
'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept',
|
||||||
'Access-Control-Expose-Headers' => 'X-Total-Count',
|
'Access-Control-Expose-Headers' => 'X-Total-Count',
|
||||||
'Access-Control-Allow-Credentials' => 'true'
|
'Access-Control-Allow-Credentials' => 'true'
|
||||||
|
|||||||
@@ -54,6 +54,26 @@ put '/cart/delivery_destination', &update_delivery_destination
|
|||||||
post '/cart/delivery_destination', &update_delivery_destination
|
post '/cart/delivery_destination', &update_delivery_destination
|
||||||
|
|
||||||
|
|
||||||
|
def send_order_email(cart)
|
||||||
|
Pony.options = {
|
||||||
|
:subject => "Nova Narudžba: #{cart.id}",
|
||||||
|
:html_body => "Mušterija naručila nešto. <br /> Pogledati https://www.ribica.ba/backoffice/carts/#{cart.id}",
|
||||||
|
:body => "Mušterija naručila nešto. Pogledati https://www.ribica.ba/backoffice/carts/#{cart.id}",
|
||||||
|
:via => :smtp,
|
||||||
|
:via_options => {
|
||||||
|
:address => 'smtp.gmail.com',
|
||||||
|
:port => '587',
|
||||||
|
:enable_starttls_auto => true,
|
||||||
|
:user_name => 'ribica.ba@gmail.com',
|
||||||
|
:password => 'pumparica*pumpa*sumpa*lumpa',
|
||||||
|
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
|
||||||
|
:domain => "localhost.localdomain"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Pony.mail(:to => "narudzbe@ribica.ba")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
post '/cart/confirmation' do
|
post '/cart/confirmation' do
|
||||||
anonymous = anonymous_id
|
anonymous = anonymous_id
|
||||||
cart = Cart.just_find(anonymous, logged_in_user_id)
|
cart = Cart.just_find(anonymous, logged_in_user_id)
|
||||||
@@ -64,5 +84,6 @@ post '/cart/confirmation' do
|
|||||||
# since there is no more ordered cart this needs to be done
|
# since there is no more ordered cart this needs to be done
|
||||||
# in order for next call of Cart#just_find to be ready
|
# in order for next call of Cart#just_find to be ready
|
||||||
Cart.find_or_create(anonymous, logged_in_user_id)
|
Cart.find_or_create(anonymous, logged_in_user_id)
|
||||||
|
send_order_email(cart)
|
||||||
"OK".to_json
|
"OK".to_json
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user