Skip to content

Instantly share code, notes, and snippets.

@mfifth
Created March 24, 2017 17:33
Show Gist options
  • Select an option

  • Save mfifth/0b91d8a953c39456a0dd8c8341e9afce to your computer and use it in GitHub Desktop.

Select an option

Save mfifth/0b91d8a953c39456a0dd8c8341e9afce to your computer and use it in GitHub Desktop.
class OrdersCreateJob < ActiveJob::Base
queue_as :default
def perform(json)
order = Order.create(order_data: json)
product_ids = []
json['line_items'].each do |line_item|
product_ids << line_item['product_id']
end
products = DesignersProduct.where(product_id: product_ids)
products.each do |product|
designer = Designer.find(product.designer_id)
OrderMailer.order_details_email(designer).deliver_now
@template = EmailTemplate.find(1)
OrderNotification.create(to: designer.name, subject: @template.subject, message: @template.body)
end
end
end
class WebhooksController < ApplicationController
def orders_create
json = ActiveSupport::JSON.decode(params.to_json)
OrdersCreateJob.perform_later(json)
head :ok
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment