Created
March 24, 2017 17:33
-
-
Save mfifth/0b91d8a953c39456a0dd8c8341e9afce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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