def confirm(): shop = Shop() shop.name = request.args['shop'].replace('.myshopify.com', '') api = ShopifyApi(shop) auth = request.args.get("code") api.confirm_installation(auth) try: token = shop.token shop = load_shop(shop.name) last_billing = shop.billing_id shop.token = token except TypeError: last_billing = None url = api.add_billing(last_billing) return redirect(url, code=302)
def load_shop(name): shop = Shop() data = ref.child(name).get() shop.name = data['name'] shop.token = data['token'] shop.button_pos = data['button_pos'] shop.button_enabled = data['button_enabled'] shop.sticky_bar_enabled = data['sticky_bar_enabled'] try: shop.phone = data['phone'] except KeyError: shop.phone = None try: shop.predefined_text = data['predefined_text'] except KeyError: shop.predefined_text = None try: shop.sticky_label_text = data['sticky_label_text'] except KeyError: shop.sticky_label_text = None try: shop.sticky_bar_color = data['sticky_bar_color'] except KeyError: shop.sticky_bar_color = '33CC33' try: shop.sticky_bar_text_color = data['sticky_bar_text_color'] except KeyError: shop.sticky_bar_text_color = 'FFFFFF' try: shop.script_tag_id = data['script_tag_id'] except KeyError: shop.script_tag_id = None try: shop.billing_id = data['billing_id'] except KeyError: shop.billing_id = None return shop