Shopify RecurringApplicationCharge的确认URL为零

问题描述

我正在尝试向我的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(nil:NilClass的未定义方法“ [] =”)。它涉及@token行。当我编写代码时,这行已经使我感到困惑,因为变量@token仅在此方法中使用。但是,为什么它为零呢?

我想念什么?

解决方法

当我尝试启动应用程序时,出现错误:NoMethodError(nil:NilClass的未定义方法“ [] =”)。它涉及@token行。

我假设您是说@tokens

我认为您缺少the tutorial here的第一部分,其中他们在Initialize方法中设置了@tokens = {},然后在其中存储了每个商店的访问令牌。