【问题标题】:Confirmation URL for Shopify RecurringApplicationCharge is nilShopify RecurringApplicationCharge 的确认 URL 为 nil
【发布时间】:2021-01-06 02:36:36
【问题描述】:

我正在尝试向我的 shopify 应用添加经常性费用。我关注了Shopify-Tutorial,但写的略有不同。我的根路由去:

root 'mycontroller#charging'

控制器动作是:

  def charging
    if @shop_domain != @myshop
      @shop_charging_status = @shop.charging
      unless ShopifyAPI::RecurringApplicationCharge.current
        recurring_charge = ShopifyAPI::RecurringApplicationCharge.new(
          name: "My App",
          price: "1.99",
          return_url: "https:\/\/appurl\/activated",
          trial_days: 7,
          terms: "$1.99 per month")

          if recurring_charge.save
            @tokens[:confirmation_url] = recurring_charge.confirmation_url
            @shop_charging_status = true
            @shop.save
            redirect recurring_charge.confirmation_url
          end
      end
    else
      redirect_to myindex_path
    end

当我尝试启动应用程序时,我收到一个错误:NoMethodError(未定义的方法 `[]=' for nil:NilClass)。它涉及@token 行。当我写代码的时候,这一行已经让我很困惑了,因为变量@token 只用在这个方法中。但是,为什么它是 nil 呢?

我错过了什么?

【问题讨论】:

    标签: ruby-on-rails recurring-billing shopify-api


    【解决方案1】:

    当我尝试启动应用程序时,我收到一个错误:NoMethodError(未定义的方法 `[]=' for nil:NilClass)。它涉及@token 行。

    我猜你的意思是@tokens

    我认为你错过了the tutorial here 的第一部分,他们在初始化方法中设置了@tokens = {},然后将每个商店的访问令牌存储在其中。

    【讨论】:

    • 你是对的。我有 shopify-app gem,所以没有必要。我通过简单地删除 [:confirmation_url] 并将 fullpage_redirect_to @token 来修复它。现在可以了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多