2017-11-24 10 views
1

나는 레일과 함께 Shopify 앱을 그리고 난이 있습니다작업에서 webhook 데이터에 액세스하려면 어떻게합니까? (Shopify 레일)

webhooks_controller.rb

module ShopifyApp 
    class WebhooksController < ActionController::Base 
     include ShopifyApp::WebhookVerification 

     class ShopifyApp::MissingWebhookJobError < StandardError; end 

     def receive 
     params.try(:permit!) 
     job_args = {shop_domain: shop_domain, webhook: webhook_params.to_h} 
     webhook_job_klass.perform_later(job_args) 
     head :no_content 
     end 

     private 

     def webhook_params 
     params.except(:controller, :action, :type) 
     end 

     def webhook_job_klass 
     "#{webhook_type.classify}Job".safe_constantize or raise ShopifyApp::MissingWebhookJobError 
     end 

     def webhook_type 
     params[:type] 
     end 
    end 
    end 

orders_create_job.rb을

class OrdersCreateJob < ActiveJob::Base 

    def perform(shop_domain:, webhook:) 
    shop = Shop.find_by(shopify_domain: shop_domain) 
    shop.with_shopify_session do 
     #DATA GOES HERE 
    end 
    end 
end 

"#DATA GOES HERE"에서 "shipping_l"의 "title"과 같은 webhook의 변수를 가져올 수 있습니까? ines "?

어떻게하면됩니까?

답변

1

데이터는 webhook 인수에 포함됩니다. 주문에는 제목이 없으므로 webhook [: title]은 존재하지 않지만 주문에 배송 라인이 있으므로 webhook [: shipping_lines]으로 주문할 수 있습니다.