Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/controllers/webhooks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:product_updated]
skip_before_action :verify_authenticity_token, only: %i[product_updated order_cancelled]

def product_updated
data = JSON.parse(request.body.read)
Expand All @@ -18,6 +18,19 @@ def product_updated
end
end

def order_cancelled
data = JSON.parse(request.body.read)
order_id = data['id']
@order = Order.find_by(shopify_id: order_id)

if @order.present?
CanceledOrder.create(order: @order)
redirect_to orders_path
else
redirect_to @order, alert: 'Error while canceling the order'
end
end

private

def assign_product_attributes(data)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
get '/auth/callback', to: 'shopify_auth#callback'
get '/import_shopify_data', to: 'shopify_import#import'
post '/webhooks/shopify/product_updated', to: 'webhooks#product_updated'
post '/webhooks/shopify/order_cancelled', to: 'webhooks#order_cancelled'
resources :orders do
member do
post :cancel
Expand Down