首页 文章

Shopify没有从定制CarrierService获得费率

提问于
浏览
0

我正在构建一个返回自定义运费的私人Shopify应用 . 在API docs之后,在this tutorial的帮助下,我创建了一个功能性的概念验证,在我的商店中返回一些样品运费 .

但是,这个概念验证应用程序是用PHP构建的,最终版本必须在Ruby on Rails中 . 所以我创建了一个Rails应用程序,它返回与PHP应用程序完全相同的内容 - 但由于某种原因,速率根本没有显示在Shopify后端 .

我注意到的唯一不同的是HTTP标头(我已经尝试用它们来修改它们以匹配PHP应用程序,但无济于事) . 我有什么明显的遗失吗?

以下是HTTP响应标头的比较:

PHP:

Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 186
Content-Type: text/html; charset=UTF-8
Date: Tue, 16 May 2017 13:00:30 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.18 (Ubuntu)
Vary: Accept-Encoding

扶手:

Cache-Control: max-age=0, private, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Tue, 16 May 2017 12:57:38 GMT
ETag: W/"ce885edaa10636b3b7459dca958f44dd"
Server: nginx
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Request-Id: 54e2575e-c86a-4f44-a315-d0a3fbbc13f9
X-Runtime: 0.616974

同样,Shopify处理PHP响应很好,但在Rails响应上无声地失败 . Shopify可能拒绝的那个第二个(Rails)块中有什么东西吗?

不幸的是,Shopify没有提供错误日志或方法来调试此类问题 - 他们是否从您的应用程序中提取费率 .

这是我的Rails rates_controller.rb

class RatesController < ApplicationController

  def index
    ups_rates = {
      rates: [
        {
          service_name: 'Endertech Overnight',
          service_code: 'ETON',
          total_price: '000',
          currency: 'USD',
          min_delivery_date: (DateTime.now + 1.days).strftime('%F %T %z'),
          max_delivery_date: (DateTime.now + 2.days).strftime('%F %T %z')
        },
        {
          service_name: 'Endertech Regular',
          service_code: 'ETREG',
          total_price: '000',
          currency: 'USD',
          min_delivery_date: (DateTime.now + 3.days).strftime('%F %T %z'),
          max_delivery_date: (DateTime.now + 7.days).strftime('%F %T %z')
        }
      ]
    }

    # Tested returning both application/json (default) or text/html
    #render json: ups_rates
    render body: ups_rates.to_json, content_type: "text/html"
  end

end

我怀疑Shopify可能非常积极地进行缓存,因此我也试图破坏并重新创建我的私有应用程序和运营商服务,以及更改 callback_url . 到目前为止,没有任何效果 .

谢谢!

1 回答

  • 1

    经过大量的挖掘,我找到了答案:通过 POST Shopify请求率,但我的应用只响应 GET .

    作为快速修复,我在 routes.rb 中创建了一个静态路由:

    Rails.application.routes.draw do
      post 'customrates', to: 'rates#index'
    end
    

    回想起来,这是clearly stated in the documentation,我只是没有注意到(毕竟,费率请求直观地看起来像是一个行动) .

    对于遇到此问题的其他人,请尝试通过CURL向您的 callback_url 发送 POST ,只是为了验证它是否应该返回它应该:

    curl -X POST http://yourcallbackurl.com
    

相关问题