Shopify recurring charge error on Heroku

Highlighted
New Member
1 0 0

Hello there,

I'm making a rails Shopify app that will need to charge the users every month. I'm using the shopify_api rails gem to do that.

In my model shop.rb I have a method called upgrade_to_pro that looks like so

def upgrade_to_pro
    begin
      session = ShopifyAPI::Session.new(domain: self.shopify_domain, token: self.shopify_token, api_version: self.api_version)
      ShopifyAPI::Base.activate_session(session)

      unless ShopifyAPI::RecurringApplicationCharge.current
        charge = ShopifyAPI::RecurringApplicationCharge.create!({
          :name => "Pro Plan",
          :price => 9.99,
          :trial_days => 14,
          :test => true,
          :return_url => "#{ENV['HOST_URL']}/app_proxy/shop/#{self.id}/activate_charge",
        })

        self.charges.push Charge.create(
          shopify_raw_data: JSON.generate(charge.to_json),
          shopify_charge_id: charge.id,
          completed: false
        )

        charge
      end
    rescue => e
      puts "//////////////////////////////////////////////////////"
      puts e.inspect
      raise e
    end
  end

 This code works well locally also running the rails server in production mode with the -e production flag.

However, when I test this on Heroku, I get a server error that looks like so

 

2020-04-07T08:45:54.851733+00:00 app[web.1]: //////////////////////////////////////////////////////
2020-04-07T08:45:54.851749+00:00 app[web.1]: #<ActiveResource::ResourceInvalid: Failed.>
2020-04-07T08:45:54.852179+00:00 app[web.1]: I, [2020-04-07T08:45:54.852102 #4]  INFO -- : [e6caead3-5781-45c0-89f1-38c06b352061] Completed 500 Internal Server Error in 819ms (ActiveRecord: 1.8ms | Allocations: 6576)
2020-04-07T08:45:54.852866+00:00 app[web.1]: F, [2020-04-07T08:45:54.852804 #4] FATAL -- : [e6caead3-5781-45c0-89f1-38c06b352061]
2020-04-07T08:45:54.852867+00:00 app[web.1]: [e6caead3-5781-45c0-89f1-38c06b352061] ActiveResource::ResourceInvalid (Failed.):
2020-04-07T08:45:54.852868+00:00 app[web.1]: [e6caead3-5781-45c0-89f1-38c06b352061]
2020-04-07T08:45:54.852868+00:00 app[web.1]: [e6caead3-5781-45c0-89f1-38c06b352061] app/models/shop.rb:15:in `upgrade_to_pro'
2020-04-07T08:45:54.852869+00:00 app[web.1]: [e6caead3-5781-45c0-89f1-38c06b352061] app/controllers/app_proxy/shop_controller.rb:21:in `update'
2020-04-07T08:45:54.850436+00:00 heroku[router]: at=info method=PATCH path="/app_proxy/shop" host=faraday-e-commerce.herokuapp.com request_id=e6caead3-5781-45c0-89f1-38c06b352061 fwd="91.242.152.61" dyno=web.1 connect=0ms service=826ms status=500 bytes=1827 protocol=https

You can see that the e.inspect directive that I'm using simply returns this

#<ActiveResource::ResourceInvalid: Failed.>

Do you have any idea of what is going wrong?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
919 120 129

Hey @mattfaraday,

 

Are you able to capture a request ID from the response headers?

0 Likes