-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsalesforce_endpoint.rb
63 lines (58 loc) · 2.02 KB
/
salesforce_endpoint.rb
1
2
3
4
5
6
7
8
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'sinatra'
require 'endpoint_base'
require 'salesforce_integration'
class SalesforceEndpoint < EndpointBase::Sinatra::Base
# INFO: This might cause potential security issue. It's commented out for special request from Spree Support.
# endpoint_key App.endpoint_key
enable :logging
['/add_order', '/update_order'].each do |path|
post path do
begin
SpreeService::Order.new(@payload, @config).upsert_contact_with_account!
SpreeService::Order.new(@payload, @config).upsert_order!
SpreeService::Product.new(@payload, @config).upsert_products!
SpreeService::Order.new(@payload, @config).upsert_lineitems!
SpreeService::Order.new(@payload, @config).upsert_payments!
set_summary "Contact for #{@payload["order"]["email"]} and order ##{@payload["order"]["id"]} updated (or created) in Salesforce"
result 200
rescue Exception => e
log_exception(e)
result 500, e.message
end
end
end
post '/add_returns' do
begin
SpreeService::Return.new(@payload, @config).handle_returns!
set_summary "Returns marked in Order ##{@payload["returns"].first["order_id"]} in Salesforce"
result 200
rescue Exception => e
log_exception(e)
result 500, e.message
end
end
['/add_customer', '/update_customer'].each do |path|
post path do
begin
SpreeService::Customer.new(@payload, @config).upsert_contact_with_account!
set_summary "Contact for #{@payload["customer"]["email"]} updated (or created) in Salesforce"
result 200
rescue Exception => e
log_exception(e)
result 500, e.message
end
end
end
['/add_product', '/update_product'].each do |path|
post path do
begin
SpreeService::Product.new(@payload, @config).upsert_product!
set_summary "Product #{@payload["product"]["sku"]} updated (or created) in Salesforce"
result 200
rescue Exception => e
log_exception(e)
result 500, e.message
end
end
end
end