1

我正在用 rails 制作一个 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”中获取 webhook 的变量,例如“shipping_lines”的“标题”?

我怎样才能做到这一点?

4

1 回答 1

2

数据包含在 webhook 参数中。请注意,订单没有标题,因此webhook[:title]将不存在,但订单有运输线,因此您可以使用webhook[:shipping_lines]获取它们。

于 2017-11-26T15:11:01.617 回答