我的Shopify的config.webhook设置正确地将ActiveJob排队,但是我没有让它将记录详细信息保存在数据库中

问题描述 投票:0回答:1

问题:OrderPaidJob未保存到数据库中。

OrderPaidJob

class OrdersPaidJob < ApplicationJob

  def perform(shop_domain:, webhook:)
    shop = Shop.find_by(shopify_domain: shop_domain)

    shop.with_shopify_session do
      webhook.each(&method(:customer_details))
    end
  end

  private

  def customer_details(record)
    payload = {
      email: record['email'],
      amount_spent: record['total_price'].to_f,
      first_name: record['customer']['first_name'],
      last_name: record['customer']['last_name'],
      point_balance: (EarningRule.order_rule.point * record['total_price'].to_f) + previous_point(record)
    }

    records = [].tap do |array|
      array << payload
    end

    customer_exists(record) ? CustomerDetail.update_all(records) : CustomerDetail.insert_all(records)
  end

  def previous_point(record)
    return 0 unless customer_exists(record)

    customer_exists(record).point_balance
  end

  def customer_exists(record)
    CustomerDetail.find_by_email(record[:email])
  end
end

Shopify_app.rb

ShopifyApp.configure do |config|
  config.application_name = 'Loyalty'
  config.api_key = ENV['SHOPIFY_API_KEY']
  config.secret = ENV['SHOPIFY_API_SECRET']
  config.old_secret = ''
  config.scope = 'read_orders'
  config.embedded_app = true
  config.after_authenticate_job = false
  config.api_version = '2019-10'
  config.session_repository = Shop
  config.webhooks = [
    {
      topic: 'orders/paid',
      address: 'https://6c62d547.ngrok.io/webhooks/orders_paid', fields: %w[email total_price customer],
      format: 'json'
    }
  ]
end

route.rb

I don't have anything in route

Log

I, [2019-11-18T00:41:37.361206 #8576]  INFO -- : [49b5712f-fb92-448e-9ef8-34a121040843] Started POST "/webhooks/orders_paid" for 104.196.45.139 at 2019-11-18 00:41:37 +0100
I, [2019-11-18T00:41:37.371934 #8576]  INFO -- : [49b5712f-fb92-448e-9ef8-34a121040843] Processing by ShopifyApp::WebhooksController#receive as */*
I, [2019-11-18T00:41:37.372121 #8576]  INFO -- : [49b5712f-fb92-448e-9ef8-34a121040843]   Parameters: {"email"=>"[email protected]", "total_price"=>"42000.00", "customer"=>{"id"=>2730242670669, "email"=>"[email protected]", "accepts_marketing"=>true, "created_at"=>"2019-11-15T10:21:15+01:00", "updated_at"=>"2019-11-18T00:41:24+01:00", "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "orders_count"=>8, "state"=>"disabled", "total_spent"=>"378000.00", "last_order_id"=>1869178699853, "note"=>"Something", "verified_email"=>true, "multipass_identifier"=>nil, "tax_exempt"=>false, "phone"=>"+2348032", "tags"=>"Tester", "last_order_name"=>"#1010", "currency"=>"NGN", "accepts_marketing_updated_at"=>"2019-11-15T10:21:15+01:00", "marketing_opt_in_level"=>"single_opt_in", "admin_graphql_api_id"=>"gid://shopify/Customer/2730242670669", "default_address"=>{"id"=>2886602129485, "customer_id"=>2730242670669, "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "company"=>"Quidax", "address1"=>"No 4B, George Street", "address2"=>"Something", "city"=>"Ikoyi, Lagos", "province"=>"Lagos", "country"=>"Nigeria", "zip"=>"250001", "phone"=>"+2348032", "name"=>"Olaoluwa Afolabi", "province_code"=>"LA", "country_code"=>"NG", "country_name"=>"Nigeria", "default"=>true}}, "type"=>"orders_paid", "webhook"=>{"email"=>"[email protected]", "total_price"=>"42000.00", "customer"=>{"id"=>2730242670669, "email"=>"[email protected]", "accepts_marketing"=>true, "created_at"=>"2019-11-15T10:21:15+01:00", "updated_at"=>"2019-11-18T00:41:24+01:00", "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "orders_count"=>8, "state"=>"disabled", "total_spent"=>"378000.00", "last_order_id"=>1869178699853, "note"=>"Something", "verified_email"=>true, "multipass_identifier"=>nil, "tax_exempt"=>false, "phone"=>"+2348682", "tags"=>"Tester", "last_order_name"=>"#1010", "currency"=>"NGN", "accepts_marketing_updated_at"=>"2019-11-15T10:21:15+01:00", "marketing_opt_in_level"=>"single_opt_in", "admin_graphql_api_id"=>"gid://shopify/Customer/2730242670669", "default_address"=>{"id"=>2886602129485, "customer_id"=>2730242670669, "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "company"=>"Quidax", "address1"=>"No 4B, George Street", "address2"=>"Something", "city"=>"Ikoyi, Lagos", "province"=>"Lagos", "country"=>"Nigeria", "zip"=>"250001", "phone"=>"+234803382", "name"=>"Olaoluwa Afolabi", "province_code"=>"LA", "country_code"=>"NG", "country_name"=>"Nigeria", "default"=>true}}}}
I, [2019-11-18T00:41:37.587617 #8576]  INFO -- : [49b5712f-fb92-448e-9ef8-34a121040843] [ActiveJob] Enqueued OrdersPaidJob (Job ID: 953e3ef2-66d8-4422-8de6-75abef4b55e8) to Sidekiq(default) with arguments: {:shop_domain=>"shopsloyalty.myshopify.com", :webhook=>{"email"=>"[email protected]", "total_price"=>"42000.00", "customer"=>{"id"=>2730242670669, "email"=>"[email protected]", "accepts_marketing"=>true, "created_at"=>"2019-11-15T10:21:15+01:00", "updated_at"=>"2019-11-18T00:41:24+01:00", "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "orders_count"=>8, "state"=>"disabled", "total_spent"=>"378000.00", "last_order_id"=>1869178699853, "note"=>"Something", "verified_email"=>true, "multipass_identifier"=>nil, "tax_exempt"=>false, "phone"=>"+2348715682", "tags"=>"Tester", "last_order_name"=>"#1010", "currency"=>"NGN", "accepts_marketing_updated_at"=>"2019-11-15T10:21:15+01:00", "marketing_opt_in_level"=>"single_opt_in", "admin_graphql_api_id"=>"gid://shopify/Customer/2730242670669", "default_address"=>{"id"=>2886602129485, "customer_id"=>2730242670669, "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "company"=>"Quidax", "address1"=>"No 4B, George Street", "address2"=>"Something", "city"=>"Ikoyi, Lagos", "province"=>"Lagos", "country"=>"Nigeria", "zip"=>"250001", "phone"=>"+234805682", "name"=>"Olaoluwa Afolabi", "province_code"=>"LA", "country_code"=>"NG", "country_name"=>"Nigeria", "default"=>true}}, "webhook"=>{"email"=>"[email protected]", "total_price"=>"42000.00", "customer"=>{"id"=>2730242670669, "email"=>"[email protected]", "accepts_marketing"=>true, "created_at"=>"2019-11-15T10:21:15+01:00", "updated_at"=>"2019-11-18T00:41:24+01:00", "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "orders_count"=>8, "state"=>"disabled", "total_spent"=>"378000.00", "last_order_id"=>1869178699853, "note"=>"Something", "verified_email"=>true, "multipass_identifier"=>nil, "tax_exempt"=>false, "phone"=>"+234803682", "tags"=>"Tester", "last_order_name"=>"#1010", "currency"=>"NGN", "accepts_marketing_updated_at"=>"2019-11-15T10:21:15+01:00", "marketing_opt_in_level"=>"single_opt_in", "admin_graphql_api_id"=>"gid://shopify/Customer/2730242670669", "default_address"=>{"id"=>2886602129485, "customer_id"=>2730242670669, "first_name"=>"Olaoluwa", "last_name"=>"Afolabi", "company"=>"Quidax", "address1"=>"No 4B, George Street", "address2"=>"Something", "city"=>"Ikoyi, Lagos", "province"=>"Lagos", "country"=>"Nigeria", "zip"=>"250001", "phone"=>"+23480382", "name"=>"Olaoluwa Afolabi", "province_code"=>"LA", "country_code"=>"NG", "country_name"=>"Nigeria", "default"=>true}}}}}
I, [2019-11-18T00:41:37.588710 #8576]  INFO -- : [49b5712f-fb92-448e-9ef8-34a121040843] Completed 204 No Content in 216ms (Allocations: 2512)

有人可以帮我吗?我不知道我在想什么。

ruby-on-rails shopify webhooks shopify-app ruby-on-rails-6
1个回答
0
投票

您可能错过了实际完成工作的步骤。仅仅因为Shopify应用为您排队了,并不意味着您就完成了工作。根据您选择的求职者,您需要进行设置。因此,一个工人可以运行DelayedJob或Sidekiq或您选择的任何东西。那是您可能要检查设置的地方。您的Procfile是什么?死亡赠品丢失了工人项目。

© www.soinside.com 2019 - 2024. All rights reserved.