Quantcast
Channel: Opinion: Shopify Community - Shopify APIs & SDKs
Viewing all articles
Browse latest Browse all 25503

HunkyBill commented on When a user deletes my app?

$
0
0

Here's some simple code that works perfect.

post '/uninstall' do
  domain = request.env["HTTP_X_SHOPIFY_SHOP_DOMAIN"]
  shop = Shop.find_by_myshopify_domain(domain)
  puts "App Uninstall WebHook called. Shop ID #{domain}"
  unless shop.nil?
    request.body.rewind
    data = request.body.read
    verified = verify_webhook(data, request.env["HTTP_X_SHOPIFY_HMAC_SHA256"])
    if verified
      duration = (Time.now - shop.created_at) / 60 / 60 / 24
      shop.destroy
      AppMailer.quit_email("#{domain} quit the FizzBuzz App after #{duration.to_i} days").deliver  
    end
  end
  status 200    
end 

Set a webhook to app/uninstalled to point at the route /uninstall in your App.

TL:DR;   shop.destroy

 


Viewing all articles
Browse latest Browse all 25503

Trending Articles