Im trying to add a recurring charge to my shopify app. I followed the Shopify-Tutorial but wrote it slightly different. My root route goes to:
root 'mycontroller#charging'
the controller action is:
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
When I try to start the app, i get an error: NoMethodError (undefined method `[]=' for nil:NilClass). It concerns the @token line. This line already confused me when i wrote the code, because the variable @token is only used in this method. But nevertheless, why is it nil?
What am I missing?
When I try to start the app, i get an error: NoMethodError (undefined method `[]=' for nil:NilClass). It concerns the @token line.
I assume you mean @tokens
?
I think you're missing the first part of the tutorial here in which they set @tokens = {}
in the initialize method and then store the access tokens for each shop in there.